summaryrefslogtreecommitdiffstats
path: root/python/pyqt/pyuic3
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit90825e2392b2d70e43c7a25b8a3752299a933894 (patch)
treee33aa27f02b74604afbfd0ea4f1cfca8833d882a /python/pyqt/pyuic3
downloadtdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.tar.gz
tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'python/pyqt/pyuic3')
-rw-r--r--python/pyqt/pyuic3/LICENSE.GPL280
-rw-r--r--python/pyqt/pyuic3/domtool.cpp447
-rw-r--r--python/pyqt/pyuic3/domtool.h47
-rw-r--r--python/pyqt/pyuic3/embed.cpp323
-rw-r--r--python/pyqt/pyuic3/form.cpp938
-rw-r--r--python/pyqt/pyuic3/globaldefs.h56
-rw-r--r--python/pyqt/pyuic3/main.cpp245
-rw-r--r--python/pyqt/pyuic3/object.cpp704
-rw-r--r--python/pyqt/pyuic3/parser.cpp66
-rw-r--r--python/pyqt/pyuic3/parser.h33
-rw-r--r--python/pyqt/pyuic3/pyuic-prof.sbf24
-rw-r--r--python/pyqt/pyuic3/pyuic.pro.in36
-rw-r--r--python/pyqt/pyuic3/pyuic.sbf24
-rw-r--r--python/pyqt/pyuic3/subclassing.cpp185
-rw-r--r--python/pyqt/pyuic3/uic.cpp1145
-rw-r--r--python/pyqt/pyuic3/uic.h183
-rw-r--r--python/pyqt/pyuic3/widgetdatabase.cpp953
-rw-r--r--python/pyqt/pyuic3/widgetdatabase.h96
-rw-r--r--python/pyqt/pyuic3/widgetinterface.h29
19 files changed, 5814 insertions, 0 deletions
diff --git a/python/pyqt/pyuic3/LICENSE.GPL b/python/pyqt/pyuic3/LICENSE.GPL
new file mode 100644
index 00000000..c7aea189
--- /dev/null
+++ b/python/pyqt/pyuic3/LICENSE.GPL
@@ -0,0 +1,280 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 675 Mass Ave, Cambridge, MA 02139, USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
diff --git a/python/pyqt/pyuic3/domtool.cpp b/python/pyqt/pyuic3/domtool.cpp
new file mode 100644
index 00000000..b3514a06
--- /dev/null
+++ b/python/pyqt/pyuic3/domtool.cpp
@@ -0,0 +1,447 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+**
+** This file is part of Qt Designer.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#include "domtool.h"
+
+#include <qsizepolicy.h>
+#include <qcolor.h>
+#include <qcursor.h>
+#include <qdatetime.h>
+#include <qrect.h>
+#include <qsize.h>
+#include <qfont.h>
+#include <qdom.h>
+
+/*!
+ \class DomTool domtool.h
+ \brief Tools for the dom
+
+ A collection of static functions used by Resource (part of the
+ designer) and Uic.
+
+*/
+
+/*!
+ Returns the contents of property \a name of object \a e as
+ variant or the variant passed as \a defValue if the property does
+ not exist.
+
+ \sa hasProperty()
+*/
+QVariant DomTool::readProperty( const QDomElement& e, const QString& name, const QVariant& defValue, QString& comment )
+{
+ QDomElement n;
+ for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( n.tagName() == "property" ) {
+ if ( n.attribute( "name" ) != name )
+ continue;
+ return elementToVariant( n.firstChild().toElement(), defValue, comment );
+ }
+ }
+ return defValue;
+}
+
+
+/*!
+ \overload
+ */
+QVariant DomTool::readProperty( const QDomElement& e, const QString& name, const QVariant& defValue )
+{
+ QString comment;
+ return readProperty( e, name, defValue, comment );
+}
+
+/*!
+ Returns wheter object \a e defines property \a name or not.
+
+ \sa readProperty()
+ */
+bool DomTool::hasProperty( const QDomElement& e, const QString& name )
+{
+ QDomElement n;
+ for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( n.tagName() == "property" ) {
+ if ( n.attribute( "name" ) != name )
+ continue;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+QStringList DomTool::propertiesOfType( const QDomElement& e, const QString& type )
+{
+ QStringList result;
+ QDomElement n;
+ for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( n.tagName() == "property" ) {
+ QDomElement n2 = n.firstChild().toElement();
+ if ( n2.tagName() == type )
+ result += n.attribute( "name" );
+ }
+ }
+ return result;
+}
+
+
+QVariant DomTool::elementToVariant( const QDomElement& e, const QVariant& defValue )
+{
+ QString dummy;
+ return elementToVariant( e, defValue, dummy );
+}
+
+/*!
+ Interprets element \a e as variant and returns the result of the interpretation.
+ */
+QVariant DomTool::elementToVariant( const QDomElement& e, const QVariant& defValue, QString &comment )
+{
+ QVariant v;
+ if ( e.tagName() == "rect" ) {
+ QDomElement n3 = e.firstChild().toElement();
+ int x = 0, y = 0, w = 0, h = 0;
+ while ( !n3.isNull() ) {
+ if ( n3.tagName() == "x" )
+ x = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "y" )
+ y = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "width" )
+ w = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "height" )
+ h = n3.firstChild().toText().data().toInt();
+ n3 = n3.nextSibling().toElement();
+ }
+ v = QVariant( QRect( x, y, w, h ) );
+ } else if ( e.tagName() == "point" ) {
+ QDomElement n3 = e.firstChild().toElement();
+ int x = 0, y = 0;
+ while ( !n3.isNull() ) {
+ if ( n3.tagName() == "x" )
+ x = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "y" )
+ y = n3.firstChild().toText().data().toInt();
+ n3 = n3.nextSibling().toElement();
+ }
+ v = QVariant( QPoint( x, y ) );
+ } else if ( e.tagName() == "size" ) {
+ QDomElement n3 = e.firstChild().toElement();
+ int w = 0, h = 0;
+ while ( !n3.isNull() ) {
+ if ( n3.tagName() == "width" )
+ w = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "height" )
+ h = n3.firstChild().toText().data().toInt();
+ n3 = n3.nextSibling().toElement();
+ }
+ v = QVariant( QSize( w, h ) );
+ } else if ( e.tagName() == "color" ) {
+ v = QVariant( readColor( e ) );
+ } else if ( e.tagName() == "font" ) {
+ QDomElement n3 = e.firstChild().toElement();
+ QFont f( defValue.toFont() );
+ while ( !n3.isNull() ) {
+ if ( n3.tagName() == "family" )
+ f.setFamily( n3.firstChild().toText().data() );
+ else if ( n3.tagName() == "pointsize" )
+ f.setPointSize( n3.firstChild().toText().data().toInt() );
+ else if ( n3.tagName() == "bold" )
+ f.setBold( n3.firstChild().toText().data().toInt() );
+ else if ( n3.tagName() == "italic" )
+ f.setItalic( n3.firstChild().toText().data().toInt() );
+ else if ( n3.tagName() == "underline" )
+ f.setUnderline( n3.firstChild().toText().data().toInt() );
+ else if ( n3.tagName() == "strikeout" )
+ f.setStrikeOut( n3.firstChild().toText().data().toInt() );
+ n3 = n3.nextSibling().toElement();
+ }
+ v = QVariant( f );
+ } else if ( e.tagName() == "string" ) {
+ v = QVariant( e.firstChild().toText().data() );
+ QDomElement n = e;
+ n = n.nextSibling().toElement();
+ if ( n.tagName() == "comment" )
+ comment = n.firstChild().toText().data();
+ } else if ( e.tagName() == "cstring" ) {
+ v = QVariant( QCString( e.firstChild().toText().data() ) );
+ } else if ( e.tagName() == "number" ) {
+ bool ok = TRUE;
+ v = QVariant( e.firstChild().toText().data().toInt( &ok ) );
+ if ( !ok )
+ v = QVariant( e.firstChild().toText().data().toDouble() );
+ } else if ( e.tagName() == "bool" ) {
+ QString t = e.firstChild().toText().data();
+ v = QVariant( t == "true" || t == "1", 0 );
+ } else if ( e.tagName() == "pixmap" ) {
+ v = QVariant( e.firstChild().toText().data() );
+ } else if ( e.tagName() == "iconset" ) {
+ v = QVariant( e.firstChild().toText().data() );
+ } else if ( e.tagName() == "image" ) {
+ v = QVariant( e.firstChild().toText().data() );
+ } else if ( e.tagName() == "enum" ) {
+ v = QVariant( e.firstChild().toText().data() );
+ } else if ( e.tagName() == "set" ) {
+ v = QVariant( e.firstChild().toText().data() );
+ } else if ( e.tagName() == "sizepolicy" ) {
+ QDomElement n3 = e.firstChild().toElement();
+ QSizePolicy sp;
+ while ( !n3.isNull() ) {
+ if ( n3.tagName() == "hsizetype" )
+ sp.setHorData( (QSizePolicy::SizeType)n3.firstChild().toText().data().toInt() );
+ else if ( n3.tagName() == "vsizetype" )
+ sp.setVerData( (QSizePolicy::SizeType)n3.firstChild().toText().data().toInt() );
+ else if ( n3.tagName() == "horstretch" )
+ sp.setHorStretch( n3.firstChild().toText().data().toInt() );
+ else if ( n3.tagName() == "verstretch" )
+ sp.setVerStretch( n3.firstChild().toText().data().toInt() );
+ n3 = n3.nextSibling().toElement();
+ }
+ v = QVariant( sp );
+ } else if ( e.tagName() == "cursor" ) {
+ v = QVariant( QCursor( e.firstChild().toText().data().toInt() ) );
+ } else if ( e.tagName() == "stringlist" ) {
+ QStringList lst;
+ QDomElement n;
+ for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() )
+ lst << n.firstChild().toText().data();
+ v = QVariant( lst );
+ } else if ( e.tagName() == "date" ) {
+ QDomElement n3 = e.firstChild().toElement();
+ int y, m, d;
+ y = m = d = 0;
+ while ( !n3.isNull() ) {
+ if ( n3.tagName() == "year" )
+ y = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "month" )
+ m = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "day" )
+ d = n3.firstChild().toText().data().toInt();
+ n3 = n3.nextSibling().toElement();
+ }
+ v = QVariant( QDate( y, m, d ) );
+ } else if ( e.tagName() == "time" ) {
+ QDomElement n3 = e.firstChild().toElement();
+ int h, m, s;
+ h = m = s = 0;
+ while ( !n3.isNull() ) {
+ if ( n3.tagName() == "hour" )
+ h = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "minute" )
+ m = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "second" )
+ s = n3.firstChild().toText().data().toInt();
+ n3 = n3.nextSibling().toElement();
+ }
+ v = QVariant( QTime( h, m, s ) );
+ } else if ( e.tagName() == "datetime" ) {
+ QDomElement n3 = e.firstChild().toElement();
+ int h, mi, s, y, mo, d ;
+ h = mi = s = y = mo = d = 0;
+ while ( !n3.isNull() ) {
+ if ( n3.tagName() == "hour" )
+ h = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "minute" )
+ mi = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "second" )
+ s = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "year" )
+ y = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "month" )
+ mo = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "day" )
+ d = n3.firstChild().toText().data().toInt();
+ n3 = n3.nextSibling().toElement();
+ }
+ v = QVariant( QDateTime( QDate( y, mo, d ), QTime( h, mi, s ) ) );
+ }
+ return v;
+}
+
+
+/*! Returns the color which is returned in the dom element \a e.
+ */
+
+QColor DomTool::readColor( const QDomElement &e )
+{
+ QDomElement n = e.firstChild().toElement();
+ int r= 0, g = 0, b = 0;
+ while ( !n.isNull() ) {
+ if ( n.tagName() == "red" )
+ r = n.firstChild().toText().data().toInt();
+ else if ( n.tagName() == "green" )
+ g = n.firstChild().toText().data().toInt();
+ else if ( n.tagName() == "blue" )
+ b = n.firstChild().toText().data().toInt();
+ n = n.nextSibling().toElement();
+ }
+
+ return QColor( r, g, b );
+}
+
+/*!
+ Returns the contents of attribute \a name of object \a e as
+ variant or the variant passed as \a defValue if the attribute does
+ not exist.
+
+ \sa hasAttribute()
+ */
+QVariant DomTool::readAttribute( const QDomElement& e, const QString& name, const QVariant& defValue, QString& comment )
+{
+ QDomElement n;
+ for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( n.tagName() == "attribute" ) {
+ if ( n.attribute( "name" ) != name )
+ continue;
+ return elementToVariant( n.firstChild().toElement(), defValue, comment );
+ }
+ }
+ return defValue;
+}
+
+/*!
+ \overload
+*/
+QVariant DomTool::readAttribute( const QDomElement& e, const QString& name, const QVariant& defValue )
+{
+ QString comment;
+ return readAttribute( e, name, defValue, comment );
+}
+
+/*!
+ Returns wheter object \a e defines attribute \a name or not.
+
+ \sa readAttribute()
+ */
+bool DomTool::hasAttribute( const QDomElement& e, const QString& name )
+{
+ QDomElement n;
+ for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( n.tagName() == "attribute" ) {
+ if ( n.attribute( "name" ) != name )
+ continue;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+static bool toBool( const QString& s )
+{
+ return s == "true" || s.toInt() != 0;
+}
+
+/*!
+ Convert Qt 2.x format to Qt 3.0 format if necessary
+*/
+void DomTool::fixDocument( QDomDocument& doc )
+{
+ QDomElement e;
+ QDomNode n;
+ QDomNodeList nl;
+ int i = 0;
+
+ e = doc.firstChild().toElement();
+ if ( e.tagName() != "UI" )
+ return;
+
+ // latest version, don't do anything
+ if ( e.hasAttribute("version") && e.attribute("version").toDouble() > 3.0 )
+ return;
+
+ nl = doc.elementsByTagName( "property" );
+
+ // in 3.0, we need to fix a spelling error
+ if ( e.hasAttribute("version") && e.attribute("version").toDouble() == 3.0 ) {
+ for ( i = 0; i < (int) nl.length(); i++ ) {
+ QDomElement el = nl.item(i).toElement();
+ QString s = el.attribute( "name" );
+ if ( s == "resizeable" ) {
+ el.removeAttribute( "name" );
+ el.setAttribute( "name", "resizable" );
+ }
+ }
+ return;
+ }
+
+
+ // in versions smaller than 3.0 we need to change more
+ e.setAttribute( "version", 3.0 );
+
+ e.setAttribute("stdsetdef", 1 );
+ for ( i = 0; i < (int) nl.length(); i++ ) {
+ e = nl.item(i).toElement();
+ QString name;
+ QDomElement n2 = e.firstChild().toElement();
+ if ( n2.tagName() == "name" ) {
+ name = n2.firstChild().toText().data();
+ if ( name == "resizeable" )
+ e.setAttribute( "name", "resizable" );
+ else
+ e.setAttribute( "name", name );
+ e.removeChild( n2 );
+ }
+ bool stdset = toBool( e.attribute( "stdset" ) );
+ if ( stdset || name == "toolTip" || name == "whatsThis" ||
+ name == "buddy" ||
+ e.parentNode().toElement().tagName() == "item" ||
+ e.parentNode().toElement().tagName() == "spacer" ||
+ e.parentNode().toElement().tagName() == "column"
+ )
+ e.removeAttribute( "stdset" );
+ else
+ e.setAttribute( "stdset", 0 );
+ }
+
+ nl = doc.elementsByTagName( "attribute" );
+ for ( i = 0; i < (int) nl.length(); i++ ) {
+ e = nl.item(i).toElement();
+ QString name;
+ QDomElement n2 = e.firstChild().toElement();
+ if ( n2.tagName() == "name" ) {
+ name = n2.firstChild().toText().data();
+ e.setAttribute( "name", name );
+ e.removeChild( n2 );
+ }
+ }
+
+ nl = doc.elementsByTagName( "image" );
+ for ( i = 0; i < (int) nl.length(); i++ ) {
+ e = nl.item(i).toElement();
+ QString name;
+ QDomElement n2 = e.firstChild().toElement();
+ if ( n2.tagName() == "name" ) {
+ name = n2.firstChild().toText().data();
+ e.setAttribute( "name", name );
+ e.removeChild( n2 );
+ }
+ }
+
+ nl = doc.elementsByTagName( "widget" );
+ for ( i = 0; i < (int) nl.length(); i++ ) {
+ e = nl.item(i).toElement();
+ QString name;
+ QDomElement n2 = e.firstChild().toElement();
+ if ( n2.tagName() == "class" ) {
+ name = n2.firstChild().toText().data();
+ e.setAttribute( "class", name );
+ e.removeChild( n2 );
+ }
+ }
+
+}
+
diff --git a/python/pyqt/pyuic3/domtool.h b/python/pyqt/pyuic3/domtool.h
new file mode 100644
index 00000000..25b795d3
--- /dev/null
+++ b/python/pyqt/pyuic3/domtool.h
@@ -0,0 +1,47 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+**
+** This file is part of Qt Designer.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#ifndef DOMTOOL_H
+#define DOMTOOL_H
+
+#include <qvariant.h>
+#include <qnamespace.h>
+
+class QDomElement;
+class QDomDocument;
+
+class DomTool : public Qt
+{
+public:
+ static QVariant readProperty( const QDomElement& e, const QString& name, const QVariant& defValue );
+ static QVariant readProperty( const QDomElement& e, const QString& name, const QVariant& defValue, QString& comment );
+ static bool hasProperty( const QDomElement& e, const QString& name );
+ static QStringList propertiesOfType( const QDomElement& e, const QString& type );
+ static QVariant elementToVariant( const QDomElement& e, const QVariant& defValue );
+ static QVariant elementToVariant( const QDomElement& e, const QVariant& defValue, QString &comment );
+ static QVariant readAttribute( const QDomElement& e, const QString& name, const QVariant& defValue );
+ static QVariant readAttribute( const QDomElement& e, const QString& name, const QVariant& defValue, QString& comment );
+ static bool hasAttribute( const QDomElement& e, const QString& name );
+ static QColor readColor( const QDomElement &e );
+ static void fixDocument( QDomDocument& );
+};
+
+
+#endif // DOMTOOL_H
diff --git a/python/pyqt/pyuic3/embed.cpp b/python/pyqt/pyuic3/embed.cpp
new file mode 100644
index 00000000..04f6494c
--- /dev/null
+++ b/python/pyqt/pyuic3/embed.cpp
@@ -0,0 +1,323 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (c) 2001 Phil Thompson <phil@river-bank.demon.co.uk>
+** Copyright (c) 2002 Riverbank Computing Limited <info@riverbankcomputing.co.uk>
+**
+** This file is part of Qt Designer.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#include "uic.h"
+#include <qfile.h>
+#include <qimage.h>
+#include <qstringlist.h>
+#include <qdatetime.h>
+#include <qfileinfo.h>
+#include <stdio.h>
+#include <ctype.h>
+
+// on embedded, we do not compress image data. Rationale: by mapping
+// the ready-only data directly into memory we are both faster and
+// more memory efficient
+#if (QT_VERSION < 0x030100 || defined(Q_WS_QWS)) && !defined(QT_NO_IMAGE_COLLECTION_COMPRESSION)
+#define QT_NO_IMAGE_COLLECTION_COMPRESSION
+#endif
+
+struct EmbedImage
+{
+ ~EmbedImage() { delete[] colorTable; }
+ int width, height, depth;
+ int numColors;
+ QRgb* colorTable;
+ QString name;
+ QString cname;
+ bool alpha;
+#ifndef QT_NO_IMAGE_COLLECTION_COMPRESSION
+ ulong compressed;
+#endif
+};
+
+static QString convertToCIdentifier( const char *s )
+{
+ QString r = s;
+ int len = r.length();
+ if ( len > 0 && !isalpha( (char)r[0].latin1() ) )
+ r[0] = '_';
+ for ( int i=1; i<len; i++ ) {
+ if ( !isalnum( (char)r[i].latin1() ) )
+ r[i] = '_';
+ }
+ return r;
+}
+
+
+static ulong embedData( QTextStream& out, const uchar* input, int nbytes )
+{
+#ifndef QT_NO_IMAGE_COLLECTION_COMPRESSION
+ QByteArray bazip( qCompress( input, nbytes ) );
+ uint len = bazip.size();
+#else
+ uint len = (uint)nbytes;
+#endif
+ static const char hexdigits[] = "0123456789abcdef";
+ QString s;
+ for ( uint i=0; i<len; i++ ) {
+ if ( (i%14) == 0 ) {
+ if (i)
+ s += '"';
+
+ s += " \\\n \"";
+ out << (const char*)s;
+ s.truncate( 0 );
+ }
+ uint v = (uchar)
+#ifndef QT_NO_IMAGE_COLLECTION_COMPRESSION
+ bazip
+#else
+ input
+#endif
+ [(int)i];
+ s += "\\x";
+ s += hexdigits[(v >> 4) & 15];
+ s += hexdigits[v & 15];
+ if ( i == len-1 )
+ s += "\"\n";
+ }
+ if ( s.length() )
+ out << (const char*)s;
+ return (ulong)len;
+}
+
+static void embedData( QTextStream& out, const QRgb* input, int n )
+{
+ out << hex;
+ const QRgb *v = input;
+ for ( int i=0; i<n; i++ ) {
+ if ( (i%14) == 0 )
+ out << "\n ";
+ out << "0x";
+ out << hex << *v++;
+ if ( i < n-1 )
+ out << ',';
+ }
+ out << dec; // back to decimal mode
+}
+
+void Uic::embed( QTextStream& out, const char* project, const QStringList& images )
+{
+
+ QString cProject = convertToCIdentifier( project );
+
+ QStringList::ConstIterator it;
+ out << "# Image collection for project '" << project << "'.\n";
+ out << "#\n";
+ out << "# Generated from reading image files: \n";
+ for ( it = images.begin(); it != images.end(); ++it )
+ out << "# " << *it << "\n";
+ out << "#\n";
+ out << "# Created: " << QDateTime::currentDateTime().toString() << "\n";
+ out << "# by: The PyQt User Interface Compiler (pyuic) " << PYQT_VERSION << "\n";
+ out << "#\n";
+ out << "# WARNING! All changes made in this file will be lost!\n";
+
+ out << "\n";
+ out << "\n";
+ out << "from qt import QImage, QMimeSourceFactory";
+#ifndef QT_NO_IMAGE_COLLECTION_COMPRESSION
+ out << ", qUncompress";
+#endif
+ out << "\n";
+ out << "\n";
+ out << "\n";
+
+
+ QPtrList<EmbedImage> list_image;
+ list_image.setAutoDelete( TRUE );
+ int image_count = 0;
+ for ( it = images.begin(); it != images.end(); ++it ) {
+ QImage img;
+ if ( !img.load( *it ) ) {
+ fprintf( stderr, "pyuic: cannot load image file %s\n", (*it).latin1() );
+ continue;
+ }
+ EmbedImage *e = new EmbedImage;
+ e->width = img.width();
+ e->height = img.height();
+ e->depth = img.depth();
+ e->numColors = img.numColors();
+ e->colorTable = new QRgb[e->numColors];
+ e->alpha = img.hasAlphaBuffer();
+ memcpy(e->colorTable, img.colorTable(), e->numColors*sizeof(QRgb));
+ QFileInfo fi( *it );
+ e->name = fi.fileName();
+ e->cname = QString("image_%1").arg( image_count++);
+ list_image.append( e );
+ out << "# " << *it << "\n";
+ QString s;
+ if ( e->depth == 1 )
+ img = img.convertBitOrder(QImage::BigEndian);
+ out << s.sprintf( "%s_data =",
+ (const char *)e->cname );
+#ifndef QT_NO_IMAGE_COLLECTION_COMPRESSION
+ e->compressed =
+#endif
+ embedData( out, img.bits(), img.numBytes() );
+ out << "\n";
+ if ( e->numColors ) {
+ out << s.sprintf( "%s_ctable = [",
+ (const char *)e->cname );
+ embedData( out, e->colorTable, e->numColors );
+ out << "\n]\n\n";
+ }
+ }
+
+ if ( !list_image.isEmpty() ) {
+ out << indent << "embed_image_vec = [\n";
+ ++indent;
+ EmbedImage *e = list_image.first();
+ while ( e ) {
+ out << indent << "["
+ << e->width << ","
+ << e->height << ","
+ << e->depth << ","
+ << e->cname << "_data,"
+#ifndef QT_NO_IMAGE_COLLECTION_COMPRESSION
+ << e->compressed << ","
+#endif
+ << e->numColors << ",";
+ if ( e->numColors )
+ out << e->cname << "_ctable,";
+ else
+ out << "None,";
+ if ( e->alpha )
+ out << "1,";
+ else
+ out << "0,";
+ out << "\"" << e->name << "\"],\n";
+ e = list_image.next();
+ }
+ --indent;
+ out << indent << "]\n";
+
+ out << "\n"
+ "\n"
+ "def uic_findImage(name):\n";
+ ++indent;
+ out << indent << "global embed_image_vec\n";
+ out << "\n";
+#ifndef QT_NO_IMAGE_COLLECTION_COMPRESSION
+ out << indent << "for (w,h,depth,data,comp,nrCol,colTab,alpha,iname) in embed_image_vec:" << endl;
+#else
+ out << indent << "for (w,h,depth,data,nrCol,colTab,alpha,iname) in embed_image_vec:" << endl;
+#endif
+ ++indent;
+ out << indent << "if iname == str(name):" << endl;
+ ++indent;
+#ifndef QT_NO_IMAGE_COLLECTION_COMPRESSION
+ // Keep the data object alive until we have a deep copy of the image.
+ out << indent << "data = qUncompress(data).data()\n";
+#endif
+ out << indent << "img = QImage(data,w,h,depth,colTab,nrCol,QImage.BigEndian).copy()\n";
+ out << "\n";
+ out << indent << "if alpha:\n";
+ ++indent;
+ out << indent << "img.setAlphaBuffer(1)\n";
+ --indent;
+ out << "\n";
+ out << indent << "return img\n";
+ --indent;
+ --indent;
+ out << endl;
+ out << indent << "return QImage()\n";
+ --indent;
+ out << "\n";
+ out << "\n";
+
+ out << indent << "class MimeSourceFactory_" << cProject << "(QMimeSourceFactory):\n";
+ ++indent;
+ out << indent << "def __init__(self):\n";
+ ++indent;
+ out << indent << "QMimeSourceFactory.__init__(self)\n";
+ out << "\n";
+ --indent;
+ out << indent << "def data(self,abs_name):\n";
+ ++indent;
+ out << indent << "d = QMimeSourceFactory.data(self,abs_name)\n";
+ out << indent << "if d or abs_name.isNull():\n";
+ ++indent;
+ out << indent << "return d\n";
+ --indent;
+ out << "\n";
+ out << indent << "img = uic_findImage(abs_name)\n";
+ out << indent << "if not img.isNull():\n";
+ ++indent;
+ out << indent << "self.setImage(abs_name,img)\n";
+ --indent;
+ out << "\n";
+ out << indent << "return QMimeSourceFactory.data(self,abs_name)\n";
+ --indent;
+ --indent;
+ out << "\n";
+ out << "\n";
+
+ out << indent << "factory = None\n";
+ out << "\n";
+
+ out << indent << "def qInitImages_" << cProject << "():\n";
+ ++indent;
+ out << indent << "global factory\n";
+ out << "\n";
+ out << indent << "if factory is None:\n";
+ ++indent;
+ out << indent << "factory = MimeSourceFactory_" << cProject << "()\n";
+ out << indent << "QMimeSourceFactory.defaultFactory().addFactory(factory)\n";
+ --indent;
+ --indent;
+ out << "\n";
+ out << "\n";
+
+ out << indent << "def qCleanupImages_" << cProject << "():\n";
+ ++indent;
+ out << indent << "global factory\n";
+ out << "\n";
+ out << indent << "if factory is not None:\n";
+ ++indent;
+ out << indent << "QMimeSourceFactory.defaultFactory().removeFactory(factory)\n";
+ out << indent << "factory = None\n";
+ --indent;
+ --indent;
+ out << "\n";
+ out << "\n";
+
+ out << indent << "class StaticInitImages_" << cProject << ":\n";
+ ++indent;
+ out << indent << "def __init__(self):\n";
+ ++indent;
+ out << indent << "self.cleanup = qCleanupImages_" << cProject << "\n";
+ out << indent << "qInitImages_" << cProject << "()\n";
+ --indent;
+ out << "\n";
+ out << indent << "def __del__(self):\n";
+ ++indent;
+ out << indent << "self.cleanup()\n";
+ --indent;
+ --indent;
+ out << "\n";
+ out << "\n";
+
+ out << "staticImages = StaticInitImages_" << cProject << "()\n";
+ }
+}
diff --git a/python/pyqt/pyuic3/form.cpp b/python/pyqt/pyuic3/form.cpp
new file mode 100644
index 00000000..aedb4ac2
--- /dev/null
+++ b/python/pyqt/pyuic3/form.cpp
@@ -0,0 +1,938 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+**
+** This file is part of Qt Designer.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#include <stdio.h>
+#include "uic.h"
+#include "parser.h"
+#include "widgetdatabase.h"
+#include "domtool.h"
+#include <qstringlist.h>
+#include <qfile.h>
+#include <qfileinfo.h>
+#include <qregexp.h>
+#define NO_STATIC_COLORS
+#include <globaldefs.h>
+
+#if QT_VERSION < 0x030100
+#include <zlib.h>
+#endif
+
+static QByteArray unzipXPM( QString data, ulong& length )
+{
+#if QT_VERSION >= 0x030100
+ const int lengthOffset = 4;
+ int baSize = data.length() / 2 + lengthOffset;
+ uchar *ba = new uchar[ baSize ];
+ for ( int i = lengthOffset; i < baSize; ++i ) {
+ char h = data[ 2 * (i-lengthOffset) ].latin1();
+ char l = data[ 2 * (i-lengthOffset) + 1 ].latin1();
+ uchar r = 0;
+ if ( h <= '9' )
+ r += h - '0';
+ else
+ r += h - 'a' + 10;
+ r = r << 4;
+ if ( l <= '9' )
+ r += l - '0';
+ else
+ r += l - 'a' + 10;
+ ba[ i ] = r;
+ }
+ // qUncompress() expects the first 4 bytes to be the expected length of the
+ // uncompressed data
+ ba[0] = ( length & 0xff000000 ) >> 24;
+ ba[1] = ( length & 0x00ff0000 ) >> 16;
+ ba[2] = ( length & 0x0000ff00 ) >> 8;
+ ba[3] = ( length & 0x000000ff );
+ QByteArray baunzip = qUncompress( ba, baSize );
+ delete[] ba;
+ return baunzip;
+#else
+ uchar *ba = new uchar[ data.length() / 2 ];
+ for ( int i = 0; i < (int)data.length() / 2; ++i ) {
+ char h = data[ 2 * i ].latin1();
+ char l = data[ 2 * i + 1 ].latin1();
+ uchar r = 0;
+ if ( h <= '9' )
+ r += h - '0';
+ else
+ r += h - 'a' + 10;
+ r = r << 4;
+ if ( l <= '9' )
+ r += l - '0';
+ else
+ r += l - 'a' + 10;
+ ba[ i ] = r;
+ }
+ // I'm not sure this makes sense. Why couldn't the compressed data be
+ // less than 20% of the original data? Maybe it's enough to trust the
+ // `length' passed as an argument. Quoting the zlib header:
+ // Upon entry, destLen is the total size of the destination
+ // buffer, which must be large enough to hold the entire
+ // uncompressed data. (The size of the uncompressed data must
+ // have been saved previously by the compressor and transmitted
+ // to the decompressor by some mechanism outside the scope of
+ // this compression library.)
+ // Which is the role of `length'. On the other hand this could prevent
+ // crashes in some cases of slightly corrupt UIC files.
+ if ( length < data.length() * 5 )
+ length = data.length() * 5;
+ QByteArray baunzip( length );
+ ::uncompress( (uchar*) baunzip.data(), &length, ba, data.length()/2 );
+ delete[] ba;
+ return baunzip;
+#endif
+}
+
+
+
+/*!
+ Creates an implementation ( cpp-file ) for the form given in \a e
+
+ \sa createFormDecl(), createObjectImpl()
+ */
+void Uic::createFormImpl( const QDomElement &e )
+{
+ QDomElement n;
+ QDomNodeList nl;
+ int i;
+ QString objClass = getClassName( e );
+ if ( objClass.isEmpty() )
+ return;
+ QString objName = getObjectName( e );
+
+ // generate local and local includes required
+ QStringList globalIncludes;
+ QStringList::Iterator it;
+ QStringList sqlClasses;
+ QStringList axwidgets, databrowsers;
+
+ QMap<QString, CustomInclude> customWidgetIncludes;
+ QMap<QString, QString> functionImpls;
+ // find additional slots and functions
+ QStringList extraSlots;
+ QStringList extraSlotTypes;
+ nl = e.parentNode().toElement().elementsByTagName( "slot" );
+ for ( i = 0; i < (int) nl.length(); i++ ) {
+ n = nl.item(i).toElement();
+ if ( n.parentNode().toElement().tagName() != "slots"
+ && n.parentNode().toElement().tagName() != "connections" )
+ continue;
+ if ( n.attribute( "language", "C++" ) != "C++" )
+ continue;
+ QString slotName = n.firstChild().toText().data().stripWhiteSpace();
+ if ( slotName.endsWith( ";" ) )
+ slotName = slotName.left( slotName.length() - 1 );
+
+ extraSlots += Parser::cleanArgs(slotName);
+ extraSlotTypes += n.attribute( "returnType", "void" );
+ }
+
+ for ( n = e; !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( n.tagName() == "functions" ) { // compatibility
+ for ( QDomElement n2 = n.firstChild().toElement(); !n2.isNull(); n2 = n2.nextSibling().toElement() ) {
+ if ( n2.tagName() == "function" ) {
+ QString fname = n2.attribute( "name" );
+ fname = Parser::cleanArgs( fname );
+ functionImpls.insert( fname, n2.firstChild().toText().data() );
+ }
+ }
+ }
+ }
+
+ // additional includes (local or global ) and forward declaractions
+ nl = e.parentNode().toElement().elementsByTagName( "include" );
+ for ( i = 0; i < (int) nl.length(); i++ ) {
+ QDomElement n2 = nl.item(i).toElement();
+
+ QString s = n2.firstChild().toText().data();
+ if ( n2.attribute( "location" ) != "local" ) {
+ if ( s.right( 5 ) == ".ui.h" && !QFile::exists( s ) )
+ continue;
+ if ( n2.attribute( "impldecl", "in implementation" ) != "in implementation" )
+ continue;
+ globalIncludes += s;
+ }
+ }
+
+ // do the local includes afterwards, since global includes have priority on clashes
+ QFileInfo fi(fileName);
+
+ for ( i = 0; i < (int) nl.length(); i++ ) {
+ QDomElement n2 = nl.item(i).toElement();
+ QString s = n2.firstChild().toText().data();
+ if ( n2.attribute( "location" ) == "local" &&!globalIncludes.contains( s ) ) {
+ if ( s.right( 5 ) != ".ui.h" )
+ continue;
+
+ if ( !QFile::exists( s ) )
+ {
+ s = fi.dirPath() + "/" + s;
+
+ if ( !QFile::exists( s ) )
+ continue;
+ }
+
+ if ( QFile::exists( s ) )
+ {
+ QFile f(s);
+ f.open(IO_ReadOnly);
+ QTextStream headerStream(&f);
+ QString line;
+ QString functionText;
+ QString functionName;
+ QRegExp rx("void .*::(.*\\(.*\\))");
+ int pos, inFunction = 0;
+
+ while (line = headerStream.readLine())
+ {
+ pos = rx.search(line);
+
+ if (pos > -1)
+ {
+ if (inFunction)
+ functionImpls.insert(Parser::cleanArgs(functionName),functionText);
+
+ functionName = rx.cap(1);
+ functionText = "";
+ inFunction = 1;
+ }
+ functionText += line + "\n";
+ }
+
+ if (inFunction)
+ functionImpls.insert(Parser::cleanArgs(functionName),functionText);
+ }
+ }
+ }
+
+ // additional custom widget headers
+ nl = e.parentNode().toElement().elementsByTagName( "header" );
+ for ( i = 0; i < (int) nl.length(); i++ ) {
+ QDomElement n2 = nl.item(i).toElement();
+ QString s = n2.firstChild().toText().data();
+ if ( n2.attribute( "location" ) != "local" )
+ globalIncludes += s;
+ }
+
+ // includes for child widgets
+ for ( it = tags.begin(); it != tags.end(); ++it ) {
+ nl = e.parentNode().toElement().elementsByTagName( *it );
+ for ( i = 1; i < (int) nl.length(); i++ ) { // start at 1, 0 is the toplevel widget
+ QString name = getClassName( nl.item(i).toElement() );
+ if ( name == "Spacer" ) {
+ globalIncludes += "qlayout.h";
+ globalIncludes += "qapplication.h";
+ continue;
+ }
+ if ( name.mid( 1 ) == "ListView" )
+ globalIncludes += "qheader.h";
+ else if ( name == "QAxWidget" )
+ axwidgets += getObjectName(nl.item(i).toElement());
+ else if ( name == "QDataBrowser" )
+ databrowsers += getObjectName(nl.item(i).toElement());
+ if ( name != objClass ) {
+ int wid = WidgetDatabase::idFromClassName( name );
+ QMap<QString, CustomInclude>::Iterator it = customWidgetIncludes.find( name );
+ if ( it == customWidgetIncludes.end() )
+ globalIncludes += WidgetDatabase::includeFile( wid );
+ }
+ }
+ }
+
+ if (globalIncludes.findIndex("qtable.h") >= 0)
+ out << indent << "from qttable import QTable" << endl;
+
+ if (!axwidgets.empty())
+ out << indent << "from qtaxcontainer import QAxWidget" << endl;
+
+ if (globalIncludes.findIndex("qextscintilla.h") >= 0)
+ out << indent << "from qtext import QextScintilla" << endl;
+
+ registerDatabases( e );
+ dbConnections = unique( dbConnections );
+ if ( dbConnections.count() )
+ sqlClasses += "QSqlDatabase";
+ if ( dbCursors.count() )
+ sqlClasses += "QSqlCursor";
+ bool dbForm = FALSE;
+ if ( dbForms[ "(default)" ].count() )
+ dbForm = TRUE;
+ bool subDbForms = FALSE;
+ for ( it = dbConnections.begin(); it != dbConnections.end(); ++it ) {
+ if ( !(*it).isEmpty() && (*it) != "(default)" ) {
+ if ( dbForms[ (*it) ].count() ) {
+ subDbForms = TRUE;
+ break;
+ }
+ }
+ }
+ if ( dbForm || subDbForms ) {
+ sqlClasses += "QSqlForm";
+ sqlClasses += "QSqlRecord";
+ }
+
+ if (globalIncludes.findIndex("qdatatable.h") >= 0)
+ sqlClasses += "QDataTable";
+
+ if (globalIncludes.findIndex("qtableview.h") >= 0)
+ sqlClasses += "QTableView";
+
+ if (globalIncludes.findIndex("qdatabrowser.h") >= 0)
+ sqlClasses += "QDataBrowser";
+
+ if (globalIncludes.findIndex("qdataview.h") >= 0)
+ sqlClasses += "QDataView";
+
+ if ( !sqlClasses.empty() ) {
+ out << indent << "from qtsql import";
+ const char *sep = " ";
+
+ for ( it = sqlClasses.begin(); it != sqlClasses.end(); ++it ) {
+ out << sep << (*it);
+ sep = ", ";
+ }
+
+ out << endl;
+ }
+
+ // Add any code from the comments.
+ if (!pyCode.isEmpty())
+ out << pyCode;
+
+ out << endl;
+
+ // find out what images are required
+ QStringList requiredImages;
+ static const char *imgTags[] = { "pixmap", "iconset", 0 };
+ for ( i = 0; imgTags[i] != 0; i++ ) {
+ nl = e.parentNode().toElement().elementsByTagName( imgTags[i] );
+ for ( int j = 0; j < (int) nl.length(); j++ ) {
+ QDomNode nn = nl.item(j);
+ while ( nn.parentNode() != e.parentNode() )
+ nn = nn.parentNode();
+ if ( nn.nodeName() != "customwidgets" )
+ requiredImages += nl.item(j).firstChild().toText().data();
+ }
+ }
+
+ // register the object and unify its name
+ objName = registerObject( objName );
+
+ QStringList images;
+ QStringList xpmImages;
+ if ( pixmapLoaderFunction.isEmpty() && !externPixmaps ) {
+ // create images
+ for ( n = e; !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( n.tagName() == "images" ) {
+ nl = n.elementsByTagName( "image" );
+ for ( i = 0; i < (int) nl.length(); i++ ) {
+ QString img = registerObject( nl.item(i).toElement().attribute( "name" ) );
+ if ( !requiredImages.contains( img ) )
+ continue;
+ QDomElement tmp = nl.item(i).firstChild().toElement();
+ if ( tmp.tagName() != "data" )
+ continue;
+ QString format = tmp.attribute("format", "PNG" );
+ QString data = tmp.firstChild().toText().data();
+ if ( format == "XPM.GZ" ) {
+ xpmImages += img;
+ ulong length = tmp.attribute("length").toULong();
+ QByteArray baunzip = unzipXPM( data, length );
+ length = baunzip.size();
+ // shouldn't we test the initial `length' against the
+ // resulting `length' to catch corrupt UIC files?
+ int a = 0;
+ out << indent << img << "_data = [" << endl;
+ while ( baunzip[a] != '\"' )
+ a++;
+ for ( ; a < (int) length; a++ )
+ {
+ char ch;
+
+ if ((ch = baunzip[a]) == '}')
+ {
+ out << endl << "]";
+ break;
+ }
+
+ out << ch;
+ }
+ out << endl;
+ } else {
+ images += img;
+ out << indent << img << "_data = \\" << endl;
+ ++indent;
+ out << indent << "\"";
+ int a ;
+ for ( a = 0; a < (int) (data.length()/2)-1; a++ ) {
+ out << "\\x" << QString(data[2*a]) << QString(data[2*a+1]);
+ if ( a % 12 == 11 )
+ out << "\" \\" << endl << indent << "\"";
+ }
+ out << "\\x" << QString(data[2*a]) << QString(data[2*a+1]) << "\"" << endl;
+ --indent;
+ }
+ }
+ }
+ }
+ out << endl;
+ } else if ( externPixmaps ) {
+#if QT_VERSION >= 0x030100
+ pixmapLoaderFunction = "QPixmap.fromMimeSource";
+#else
+ out << indent << "def uic_load_pixmap_" << objName << "(name):" << endl;
+ ++indent;
+ out << indent << "pix = QPixmap()" << endl;
+ out << indent << "m = QMimeSourceFactory.defaultFactory().data(name)" << endl;
+ out << endl;
+ out << indent << "if m:" << endl;
+ ++indent;
+ out << indent << "QImageDrag.decode(m,pix)" << endl;
+ --indent;
+ out << endl;
+ out << indent << "return pix" << endl;
+ --indent;
+ out << endl;
+ out << endl;
+ pixmapLoaderFunction = "uic_load_pixmap_" + objName;
+#endif
+ }
+
+
+ // constructor(s)
+
+ out << indent << "class " << nameOfClass << "(" << objClass << "):" << endl;
+ ++indent;
+
+ if ( objClass == "QDialog" || objClass == "QWizard" ) {
+ out << indent << "def __init__(self,parent = None,name = None,modal = 0,fl = 0):" << endl;
+ ++indent;
+ out << indent << objClass << ".__init__(self,parent,name,modal,fl)" << endl;
+ } else if ( objClass == "QWidget" ) {
+ out << indent << "def __init__(self,parent = None,name = None,fl = 0):" << endl;
+ ++indent;
+ out << indent << objClass << ".__init__(self,parent,name,fl)" << endl;
+ } else if ( objClass == "QMainWindow" ) {
+ out << indent << "def __init__(self,parent = None,name = None,fl = 0):" << endl;
+ ++indent;
+ out << indent << objClass << ".__init__(self,parent,name,fl)" << endl;
+ out << indent << "self.statusBar()" << endl;
+ isMainWindow = TRUE;
+ } else {
+ out << indent << "def __init__(self,parent = None,name = None):" << endl;
+ ++indent;
+ out << indent << objClass << ".__init__(self,parent,name)" << endl;
+ }
+
+ out << endl;
+
+ // create pixmaps for all images
+ if ( !images.isEmpty() ) {
+ QStringList::Iterator it;
+ for ( it = images.begin(); it != images.end(); ++it ) {
+ out << indent << "self." << (*it) << " = QPixmap()" << endl;
+ out << indent << "self." << (*it) << ".loadFromData(" << (*it) << "_data,\"PNG\")" << endl;
+ }
+ }
+ // create pixmaps for all images
+ if ( !xpmImages.isEmpty() ) {
+ for ( it = xpmImages.begin(); it != xpmImages.end(); ++it ) {
+ out << indent << "self." << (*it) << " = QPixmap(" << (*it) << "_data)" << endl;
+ }
+ out << endl;
+ }
+
+
+ // set the properties
+ QSize geometry( 0, 0 );
+
+ for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( n.tagName() == "property" ) {
+ bool stdset = stdsetdef;
+ if ( n.hasAttribute( "stdset" ) )
+ stdset = toBool( n.attribute( "stdset" ) );
+ QString prop = n.attribute("name");
+ QDomElement n2 = n.firstChild().toElement();
+ QString value = setObjectProperty( objClass, QString::null, prop, n2, stdset );
+ if ( value.isEmpty() )
+ continue;
+
+ if ( prop == "geometry" && n2.tagName() == "rect") {
+ QDomElement n3 = n2.firstChild().toElement();
+ while ( !n3.isNull() ) {
+ if ( n3.tagName() == "width" )
+ geometry.setWidth( n3.firstChild().toText().data().toInt() );
+ else if ( n3.tagName() == "height" )
+ geometry.setHeight( n3.firstChild().toText().data().toInt() );
+ n3 = n3.nextSibling().toElement();
+ }
+ } else {
+ QString call;
+ if ( stdset )
+ call = "self." + mkStdSet( prop ) + "(" + value + ")";
+ else
+ call = "self.setProperty(\"" + prop + "\",QVariant(" + value + "))";
+
+ if ( n2.tagName() == "string" ) {
+ trout << trindent << call << endl;
+ } else if ( prop == "name" ) {
+ out << indent << "if not name:" << endl;
+ ++indent;
+ out << indent << call << endl;
+ --indent;
+ out << endl;
+ } else {
+ out << indent << call << endl;
+ }
+ }
+ }
+ }
+
+ out << endl;
+
+ // create all children, some forms have special requirements
+
+ if ( objClass == "QWizard" ) {
+ for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( tags.contains( n.tagName() ) ) {
+ QString page = createObjectImpl( n, objClass, "self" );
+ QString comment;
+ QString label = DomTool::readAttribute( n, "title", "", comment ).toString();
+ out << indent << "self.addPage(" << page << ",QString(\"\"))" << endl;
+ trout << trindent << "self.setTitle(" << page << ","<< trcall( label, comment ) << ")" << endl;
+ QVariant def( FALSE, 0 );
+ if ( DomTool::hasAttribute( n, "backEnabled" ) )
+ out << indent << "self.setBackEnabled(" << page << "," << mkBool( DomTool::readAttribute( n, "backEnabled", def).toBool() ) << ")" << endl;
+ if ( DomTool::hasAttribute( n, "nextEnabled" ) )
+ out << indent << "self.setNextEnabled(" << page << "," << mkBool( DomTool::readAttribute( n, "nextEnabled", def).toBool() ) << ")" << endl;
+ if ( DomTool::hasAttribute( n, "finishEnabled" ) )
+ out << indent << "self.setFinishEnabled(" << page << "," << mkBool( DomTool::readAttribute( n, "finishEnabled", def).toBool() ) << ")" << endl;
+ if ( DomTool::hasAttribute( n, "helpEnabled" ) )
+ out << indent << "self.setHelpEnabled(" << page << "," << mkBool( DomTool::readAttribute( n, "helpEnabled", def).toBool() ) << ")" << endl;
+ if ( DomTool::hasAttribute( n, "finish" ) )
+ out << indent << "self.setFinish( " << page << "," << mkBool( DomTool::readAttribute( n, "finish", def).toBool() ) << ")" << endl;
+ }
+ }
+ } else { // standard widgets
+ for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( tags.contains( n.tagName() ) )
+ createObjectImpl( n, objName, "self" );
+ }
+ }
+
+ // database support
+ dbConnections = unique( dbConnections );
+ if ( dbConnections.count() )
+ out << endl;
+ for ( it = dbConnections.begin(); it != dbConnections.end(); ++it ) {
+ if ( !(*it).isEmpty() && (*it) != "(default)") {
+ out << indent << "self." << (*it) << "Connection = QSqlDatabase.database(\"" <<(*it) << "\")" << endl;
+ }
+ }
+
+ nl = e.parentNode().toElement().elementsByTagName( "widget" );
+ for ( i = 1; i < (int) nl.length(); i++ ) { // start at 1, 0 is the toplevel widget
+ n = nl.item(i).toElement();
+ QString s = getClassName( n );
+ if ( (dbForm || subDbForms) && (s == "QDataBrowser" || s == "QDataView") ) {
+ QString objName = getObjectName( n );
+ QString tab = getDatabaseInfo( n, "table" );
+ QString con = getDatabaseInfo( n, "connection" );
+ out << indent << objName << "Form = QSqlForm(self,\"" << objName << "Form\")" << endl;
+ QDomElement n2;
+ for ( n2 = n.firstChild().toElement(); !n2.isNull(); n2 = n2.nextSibling().toElement() )
+ createFormImpl( n2, objName, con, tab );
+ out << indent << "self." << objName << ".setForm(" << objName << "Form)" << endl;
+ }
+ }
+
+ // actions, toolbars, menubar
+ bool needEndl = FALSE;
+ for ( n = e; !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( n.tagName() == "actions" ) {
+ if ( !needEndl )
+ out << endl;
+ createActionImpl( n.firstChild().toElement(), "self" );
+ needEndl = TRUE;
+ }
+ }
+ if ( needEndl )
+ out << endl;
+ needEndl = FALSE;
+ for ( n = e; !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( n.tagName() == "toolbars" ) {
+ if ( !needEndl )
+ out << endl;
+ createToolbarImpl( n, objClass, objName );
+ needEndl = TRUE;
+ }
+ }
+ if ( needEndl )
+ out << endl;
+ needEndl = FALSE;
+ for ( n = e; !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( n.tagName() == "menubar" ) {
+ if ( !needEndl )
+ out << endl;
+ createMenuBarImpl( n, objClass, objName );
+ needEndl = TRUE;
+ }
+ }
+ if ( needEndl )
+ out << endl;
+
+ out << endl;
+ out << indent << "self.languageChange()" << endl;
+ out << endl;
+
+ // take minimumSizeHint() into account, for height-for-width widgets
+ if ( !geometry.isNull() ) {
+ out << indent << "self.resize(QSize(" << geometry.width() << ","
+ << geometry.height() <<").expandedTo(self.minimumSizeHint()))" << endl;
+ out << indent << "self.clearWState(Qt.WState_Polished)" << endl;
+ }
+
+ for ( n = e; !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( n.tagName() == "connections" ) {
+ // setup signals and slots connections
+ out << endl;
+ nl = n.elementsByTagName( "connection" );
+ for ( i = 0; i < (int) nl.length(); i++ ) {
+ QString sender, receiver, signal, slot;
+ for ( QDomElement n2 = nl.item(i).firstChild().toElement(); !n2.isNull(); n2 = n2.nextSibling().toElement() ) {
+ if ( n2.tagName() == "sender" )
+ sender = n2.firstChild().toText().data();
+ else if ( n2.tagName() == "receiver" )
+ receiver = n2.firstChild().toText().data();
+ else if ( n2.tagName() == "signal" )
+ signal = n2.firstChild().toText().data();
+ else if ( n2.tagName() == "slot" )
+ slot = n2.firstChild().toText().data();
+ }
+ if ( sender.isEmpty() ||
+ receiver.isEmpty() ||
+ signal.isEmpty() ||
+ slot.isEmpty() )
+ continue;
+ if ( sender[0] == '<' ||
+ receiver[0] == '<' ||
+ signal[0] == '<' ||
+ slot[0] == '<' )
+ continue;
+
+ sender = registeredName( sender );
+ receiver = registeredName( receiver );
+
+ // translate formwindow name to "self"
+ if ( sender == objName )
+ sender = "self";
+ else
+ sender = "self." + sender;
+
+ bool isaxwidget = (axwidgets.findIndex(receiver) >= 0);
+ bool isdatabrowser = (databrowsers.findIndex(receiver) >= 0);
+
+ if ( receiver == objName )
+ receiver = "self";
+ else
+ receiver = "self." + receiver;
+
+ out << indent << "self.connect(" << sender
+ << ",SIGNAL(\"" << signal << "\")," << receiver;
+
+ // Normally we never use the SLOT() macro in case the
+ // connection is to a method of a Python custom widget. The
+ // exception is if the receiver is a QAxWidget where it must be
+ // used because the slots are dynamic.
+ if (isaxwidget)
+ out << ",SLOT(\"" << slot << "\")";
+ else
+ {
+ QString mname = slot.left(slot.find('('));
+
+ // Rename slots that have different names in PyQt.
+ if (isdatabrowser && mname == "del")
+ mname = "delOnCursor";
+
+ out << "." << mname;
+ }
+
+ out << ")" << endl;
+ }
+ } else if ( n.tagName() == "tabstops" ) {
+ // setup tab order
+ out << endl;
+ QString lastName;
+ QDomElement n2 = n.firstChild().toElement();
+ while ( !n2.isNull() ) {
+ if ( n2.tagName() == "tabstop" ) {
+ QString name = n2.firstChild().toText().data();
+ name = registeredName( name );
+ if ( !lastName.isEmpty() )
+ out << indent << "self.setTabOrder(self." << lastName << ",self." << name << ")" << endl;
+ lastName = name;
+ }
+ n2 = n2.nextSibling().toElement();
+ }
+ }
+ }
+
+ // buddies
+ bool firstBuddy = TRUE;
+ for ( QValueList<Buddy>::Iterator buddy = buddies.begin(); buddy != buddies.end(); ++buddy ) {
+ if ( isObjectRegistered( (*buddy).buddy ) ) {
+ if ( firstBuddy ) {
+ out << endl;
+ }
+ out << indent << "self." << (*buddy).key << ".setBuddy(self." << registeredName( (*buddy).buddy ) << ")" << endl;
+ firstBuddy = FALSE;
+ }
+
+ }
+
+ if ( extraSlots.find( "init()" ) != extraSlots.end() )
+ out << endl << indent << "self.init()" << endl;
+
+ // end of constructor
+ --indent;
+
+ // destructor
+ if ( extraSlots.find( "destroy()" ) != extraSlots.end() ) {
+ out << endl;
+ out << indent << "def __del__(self):" << endl;
+ ++indent;
+ out << indent << "self.destroy()" << endl;
+ --indent;
+ }
+
+ // handle application events if required
+ bool needFontEventHandler = FALSE;
+ bool needSqlTableEventHandler = FALSE;
+ bool needSqlDataBrowserEventHandler = FALSE;
+ nl = e.elementsByTagName( "widget" );
+ for ( i = 0; i < (int) nl.length(); i++ ) {
+ if ( !DomTool::propertiesOfType( nl.item(i).toElement() , "font" ).isEmpty() )
+ needFontEventHandler = TRUE;
+ QString s = getClassName( nl.item(i).toElement() );
+ if ( s == "QDataTable" || s == "QDataBrowser" ) {
+ if ( !isFrameworkCodeGenerated( nl.item(i).toElement() ) )
+ continue;
+ if ( s == "QDataTable" )
+ needSqlTableEventHandler = TRUE;
+ if ( s == "QDataBrowser" )
+ needSqlDataBrowserEventHandler = TRUE;
+ }
+ if ( needFontEventHandler && needSqlTableEventHandler && needSqlDataBrowserEventHandler )
+ break;
+ }
+ if ( needFontEventHandler && FALSE ) {
+ // indent = "\t"; // increase indentation for if-clause below
+ out << "/* " << endl;
+ out << " * Main event handler. Reimplemented to handle" << endl;
+ out << " * application font changes";
+ out << " */" << endl;
+ out << "bool " << nameOfClass << "::event( QEvent* ev )" << endl;
+ out << "{" << endl;
+ out << " bool ret = " << objClass << "::event( ev ); " << endl;
+ if ( needFontEventHandler ) {
+ ++indent;
+ out << " if ( ev->type() == QEvent::ApplicationFontChange ) {" << endl;
+ for ( i = 0; i < (int) nl.length(); i++ ) {
+ n = nl.item(i).toElement();
+ QStringList list = DomTool::propertiesOfType( n, "font" );
+ for ( it = list.begin(); it != list.end(); ++it )
+ createExclusiveProperty( n, *it );
+ }
+ out << " }" << endl;
+ --indent;
+ }
+ out << "}" << endl;
+ out << endl;
+ }
+
+ if ( needSqlTableEventHandler || needSqlDataBrowserEventHandler ) {
+ out << endl;
+ out << indent << "# Widget polish. Reimplemented to handle default data" << endl;
+ if ( needSqlTableEventHandler )
+ out << indent << "# table initialization." << endl;
+ if ( needSqlDataBrowserEventHandler )
+ out << indent << "# browser initialization." << endl;
+ out << indent << "def polish(self):" << endl;
+ ++indent;
+ if ( needSqlTableEventHandler ) {
+ for ( i = 0; i < (int) nl.length(); i++ ) {
+ QString s = getClassName( nl.item(i).toElement() );
+ if ( s == "QDataTable" ) {
+ n = nl.item(i).toElement();
+ QString c = getObjectName( n );
+ QString conn = getDatabaseInfo( n, "connection" );
+ QString tab = getDatabaseInfo( n, "table" );
+ if ( !( conn.isEmpty() || tab.isEmpty() || !isFrameworkCodeGenerated( nl.item(i).toElement() ) ) ) {
+ out << indent << "if self." << c << ":" << endl;
+ ++indent;
+ out << indent << "cursor = self." << c << ".sqlCursor()" << endl;
+ out << endl;
+ out << indent << "if not cursor:" << endl;
+ ++indent;
+ if ( conn == "(default)" )
+ out << indent << "cursor = QSqlCursor(\"" << tab << "\")" << endl;
+ else
+ out << indent << "cursor = QSqlCursor(\"" << tab << "\",1,self." << conn << "Connection)" << endl;
+ out << indent << "if self." << c << ".isReadOnly():" << endl;
+ ++indent;
+ out << indent << "cursor.setMode(QSqlCursor.ReadOnly)" << endl;
+ --indent;
+ out << indent << "self." << c << ".setSqlCursor(cursor,0,1)" << endl;
+ --indent;
+ out << endl;
+ out << indent << "if not cursor.isActive():" << endl;
+ ++indent;
+ out << indent << "self." << c << ".refresh(QDataTable.RefreshAll)" << endl;
+ --indent;
+ --indent;
+ }
+ }
+ }
+ }
+ if ( needSqlDataBrowserEventHandler ) {
+ nl = e.elementsByTagName( "widget" );
+ for ( i = 0; i < (int) nl.length(); i++ ) {
+ QString s = getClassName( nl.item(i).toElement() );
+ if ( s == "QDataBrowser" ) {
+ QString obj = getObjectName( nl.item(i).toElement() );
+ QString tab = getDatabaseInfo( nl.item(i).toElement(),
+ "table" );
+ QString conn = getDatabaseInfo( nl.item(i).toElement(),
+ "connection" );
+ if ( !(tab.isEmpty() || !isFrameworkCodeGenerated( nl.item(i).toElement() ) ) ) {
+ out << indent << "if self." << obj << ":" << endl;
+ ++indent;
+ out << indent << "if not self." << obj << ".sqlCursor():" << endl;
+ ++indent;
+ if ( conn == "(default)" )
+ out << indent << "cursor = QSqlCursor(\"" << tab << "\")" << endl;
+ else
+ out << indent << "cursor = QSqlCursor(\"" << tab << "\",1,self." << conn << "Connection)" << endl;
+ out << indent << "self." << obj << ".setSqlCursor(cursor,1)" << endl;
+ out << indent << "self." << obj << ".refresh()" << endl;
+ out << indent << "self." << obj << ".first()" << endl;
+ --indent;
+ --indent;
+ }
+ }
+ }
+ }
+ out << indent << objClass << ".polish(self)" << endl;
+ --indent;
+ }
+
+ out << endl;
+ out << endl;
+ out << indent << "def languageChange(self):" << endl;
+ uint old = indent.setIndent(0);
+ out << languageChangeBody << endl;
+ indent.setIndent(old);
+
+ // create stubs for additional slots if necessary
+ if ( !extraSlots.isEmpty() && writeFunctImpl ) {
+ QStringList::ConstIterator cit;
+
+ for ( cit = extraSlots.begin(); cit != extraSlots.end(); ++cit ) {
+ pySlot(cit);
+
+ bool createWarning = TRUE;
+ QString fname = Parser::cleanArgs( *cit );
+ QMap<QString, QString>::Iterator fit = functionImpls.find( fname );
+ if ( fit != functionImpls.end() ) {
+ int begin = (*fit).find( "{" );
+ QString body = (*fit).mid( begin + 1, (*fit).findRev( "}" ) - begin - 1 );
+ createWarning = body.simplifyWhiteSpace().isEmpty();
+ if ( !createWarning )
+ {
+ ++indent;
+ QString formatted_body = body.replace(QRegExp("\n"), QString("\n") + QString(indent));
+ out << formatted_body << endl;
+ --indent;
+ }
+ }
+ if ( createWarning ) {
+ out << endl;
+ ++indent;
+ if ( *cit != "init()" && *cit != "destroy()" )
+ out << indent << "print \"" << nameOfClass << "." << (*cit) << ": Not implemented yet\"" << endl;
+ else
+ out << indent << "pass" << endl;
+ --indent;
+ }
+ }
+ }
+
+ --indent;
+}
+
+
+/*! Creates form support implementation code for the widgets given
+ in \a e.
+
+ Traverses recursively over all children.
+ */
+
+void Uic::createFormImpl( const QDomElement& e, const QString& form, const QString& connection, const QString& table )
+{
+ if ( e.tagName() == "widget" &&
+ e.attribute( "class" ) != "QDataTable" ) {
+ QString field = getDatabaseInfo( e, "field" );
+ if ( !field.isEmpty() ) {
+ if ( isWidgetInTable( e, connection, table ) )
+ out << indent << form << "Form.insert(self." << getObjectName( e ) << "," << fixString( field ) << ")" << endl;
+ }
+ }
+ QDomElement n;
+ for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
+ createFormImpl( n, form, connection, table );
+ }
+}
+
+
+// Generate a Python slot definition.
+
+void Uic::pySlot(QStringList::ConstIterator &it)
+{
+ out << endl;
+
+ int astart = (*it).find('(');
+ out << indent << "def " << (*it).left(astart) << "(self";
+
+ // We don't reproduce the argument names (if any) because we would have to
+ // remove the types - too complicated for the moment, so we just count them
+ // and give them names based on their position.
+
+ QString args = (*it).mid(astart + 1,(*it).find(')') - astart - 1).stripWhiteSpace();
+
+ if (!args.isEmpty()) {
+ int nrargs = args.contains(',') + 1;
+
+ for (int i = 0; i < nrargs; ++i)
+ out << ",a" << i;
+ }
+
+ out << "):";
+}
diff --git a/python/pyqt/pyuic3/globaldefs.h b/python/pyqt/pyuic3/globaldefs.h
new file mode 100644
index 00000000..4ae0cd83
--- /dev/null
+++ b/python/pyqt/pyuic3/globaldefs.h
@@ -0,0 +1,56 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+**
+** This file is part of Qt Designer.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#ifndef GLOBALDEFS_H
+#define GLOBALDEFS_H
+
+#include <qcolor.h>
+#include <qapplication.h>
+
+#define BOXLAYOUT_DEFAULT_MARGIN 11
+#define BOXLAYOUT_DEFAULT_SPACING 6
+
+#ifndef NO_STATIC_COLORS
+static QColor *backColor1 = 0;
+static QColor *backColor2 = 0;
+static QColor *selectedBack = 0;
+
+static void init_colors()
+{
+ if ( backColor1 )
+ return;
+
+#if 0 // a calculated alternative for backColor1
+ QColorGroup myCg = qApp->palette().active();
+ int h1, s1, v1;
+ int h2, s2, v2;
+ myCg.color( QColorGroup::Base ).hsv( &h1, &s1, &v1 );
+ myCg.color( QColorGroup::Background ).hsv( &h2, &s2, &v2 );
+ QColor c( h1, s1, ( v1 + v2 ) / 2, QColor::Hsv );
+#endif
+
+ backColor1 = new QColor( 250, 248, 235 );
+ backColor2 = new QColor( 255, 255, 255 );
+ selectedBack = new QColor( 230, 230, 230 );
+}
+
+#endif
+
+#endif
diff --git a/python/pyqt/pyuic3/main.cpp b/python/pyqt/pyuic3/main.cpp
new file mode 100644
index 00000000..265a536c
--- /dev/null
+++ b/python/pyqt/pyuic3/main.cpp
@@ -0,0 +1,245 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (c) 2001 Phil Thompson <phil@river-bank.demon.co.uk>
+**
+** This file is part of Qt Designer.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#include "uic.h"
+#include "parser.h"
+#include "widgetdatabase.h"
+#include "domtool.h"
+#include <qapplication.h>
+#include <qfile.h>
+#include <qstringlist.h>
+#include <qdatetime.h>
+#define NO_STATIC_COLORS
+#include <globaldefs.h>
+#include <qregexp.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main( int argc, char * argv[] )
+{
+ PyIndent indent;
+ bool testCode = FALSE, execCode = FALSE;
+ bool subcl = FALSE;
+ bool imagecollection = FALSE;
+ QStringList images;
+ const char *error = 0;
+ const char* fileName = 0;
+ QCString outputFile;
+ const char* projectName = 0;
+ const char* trmacro = 0;
+ bool fix = FALSE;
+ QApplication app(argc, argv, FALSE);
+ QString className, uicClass;
+
+ for ( int n = 1; n < argc && error == 0; n++ ) {
+ QCString arg = argv[n];
+ if ( arg[0] == '-' ) { // option
+ QCString opt = &arg[1];
+ if ( opt[0] == 'o' ) { // output redirection
+ if ( opt[1] == '\0' ) {
+ if ( !(n < argc-1) ) {
+ error = "Missing output-file name";
+ break;
+ }
+ outputFile = argv[++n];
+ } else
+ outputFile = &opt[1];
+ } else if ( opt[0] == 'e' || opt == "embed" ) {
+ imagecollection = TRUE;
+ if ( opt == "embed" || opt[1] == '\0' ) {
+ if ( !(n < argc-1) ) {
+ error = "Missing name of project";
+ break;
+ }
+ projectName = argv[++n];
+ } else
+ projectName = &opt[1];
+ } else if ( opt == "subimpl" ) {
+ subcl = TRUE;
+ if ( !(n < argc-1) ) {
+ error = "Missing class name";
+ break;
+ }
+ className = argv[++n];
+ } else if ( opt == "tr" ) {
+ if ( opt == "tr" || opt[1] == '\0' ) {
+ if ( !(n < argc-1) ) {
+ error = "Missing tr macro";
+ break;
+ }
+ trmacro = argv[++n];
+ } else {
+ trmacro = &opt[1];
+ }
+ } else if ( opt == "version" ) {
+ fprintf( stderr,
+ "Python User Interface Compiler %s for Qt version %s\n",
+ PYQT_VERSION, QT_VERSION_STR );
+ return 1;
+ } else if ( opt == "help" ) {
+ break;
+ } else if ( opt == "fix" ) {
+ fix = TRUE;
+ } else if ( opt[0] == 'p' ) {
+ uint tabstop;
+ bool ok;
+
+ if ( opt[1] == '\0' ) {
+ if ( !(n < argc-1) ) {
+ error = "Missing Python indent";
+ break;
+ }
+ tabstop = QCString(argv[++n]).toUInt(&ok);
+ } else
+ tabstop = opt.mid(1).toUInt(&ok);
+
+ if (ok)
+ indent.setTabStop(tabstop);
+ else
+ error = "Invalid Python indent";
+ } else if ( opt == "test" ) {
+ testCode = TRUE;
+ } else if ( opt == "x" ) {
+ execCode = TRUE;
+ } else {
+ error = "Unrecognized option";
+ }
+ } else {
+ if ( imagecollection )
+ images << argv[n];
+ else if ( fileName ) // can handle only one file
+ error = "Too many input files specified";
+ else
+ fileName = argv[n];
+ }
+ }
+
+ if ( argc < 2 || error || (!fileName && !imagecollection ) ) {
+ fprintf( stderr, "PyQt user interface compiler.\n" );
+ if ( error )
+ fprintf( stderr, "pyuic: %s\n", error );
+
+ fprintf( stderr, "Usage: %s [options] [mode] <uifile>\n"
+ "\nGenerate implementation:\n"
+ " %s [options] <uifile>\n"
+ "Generate image collection:\n"
+ " %s [options] -embed <project> <image1> <image2> <image3> ...\n"
+ "\t<project>\tproject name\n"
+ "\t<image[0..n]>\timage files\n"
+ "Generate subclass implementation:\n"
+ " %s [options] -subimpl <classname> <uifile>\n"
+ "\t<classname>\tname of the subclass to generate\n"
+ "Options:\n"
+ "\t-o file\t\tWrite output to file rather than stdout\n"
+ "\t-p indent\tSet the Python indent in spaces (0 to use a tab)\n"
+ "\t-tr func\tUse func() rather than QApplication.translate() for i18n\n"
+ "\t-x\t\tGenerate extra code to test and display the class\n"
+ "\t-test\t\tGenerate extra code to test but not display the class\n"
+ "\t-version\tDisplay version of pyuic\n"
+ "\t-help\t\tDisplay this information\n"
+ , argv[0], argv[0], argv[0], argv[0]);
+ return 1;
+ }
+
+ Uic::setIndent(indent);
+
+ QFile fileOut;
+ if ( !outputFile.isEmpty() ) {
+ fileOut.setName( outputFile );
+ if (!fileOut.open( IO_WriteOnly ) )
+ qFatal( "pyuic: Could not open output file '%s'", outputFile.data() );
+ } else {
+ fileOut.open( IO_WriteOnly, stdout );
+ }
+ QTextStream out( &fileOut );
+
+ if ( imagecollection ) {
+ out.setEncoding( QTextStream::Latin1 );
+ out << "# -*- coding: latin-1 -*-\n\n";
+ Uic::embed( out, projectName, images );
+ return 0;
+ }
+
+
+ out.setEncoding( QTextStream::UnicodeUTF8 );
+ QFile file( fileName );
+ if ( !file.open( IO_ReadOnly ) )
+ qFatal( "pyuic: Could not open file '%s' ", fileName );
+
+ QDomDocument doc;
+ QString errMsg;
+ int errLine;
+ if ( !doc.setContent( &file, &errMsg, &errLine ) )
+ qFatal( QString("pyuic: Failed to parse %s: ") + errMsg + QString (" in line %d\n"), fileName, errLine );
+
+ QDomElement e = doc.firstChild().toElement();
+ if ( e.hasAttribute("version") && e.attribute("version").toDouble() > 3.3 ) {
+ qWarning( QString("pyuic: File generated with too recent version of Qt Designer (%s vs. %s)"),
+ e.attribute("version").latin1(), QT_VERSION_STR );
+ return 1;
+ }
+
+ DomTool::fixDocument( doc );
+
+ if ( fix ) {
+ out << doc.toString();
+ return 0;
+ }
+
+ out << "# -*- coding: utf-8 -*-\n\n";
+
+ if ( !subcl ) {
+ out << "# Form implementation generated from reading ui file '" << fileName << "'" << endl;
+ out << "#" << endl;
+ out << "# Created: " << QDateTime::currentDateTime().toString() << endl;
+ out << "# by: The PyQt User Interface Compiler (pyuic) " << PYQT_VERSION << endl;
+ out << "#" << endl;
+ out << "# WARNING! All changes made in this file will be lost!" << endl;
+ out << endl;
+ out << endl;
+ }
+
+ if (testCode || execCode)
+ out << "import sys" << endl;
+
+ out << "from qt import *" << endl;
+
+ Uic( fileName, outputFile, out, doc, subcl, trmacro, className, uicClass );
+
+ if (testCode || execCode) {
+ out << endl;
+ out << indent << "if __name__ == \"__main__\":" << endl;
+ ++indent;
+ out << indent << "a = QApplication(sys.argv)" << endl;
+ out << indent << "QObject.connect(a,SIGNAL(\"lastWindowClosed()\"),a,SLOT(\"quit()\"))" << endl;
+ out << indent << "w = " << (subcl ? className : uicClass) << "()" << endl;
+ out << indent << "a.setMainWidget(w)" << endl;
+
+ if (execCode) {
+ out << indent << "w.show()" << endl;
+ out << indent << "a.exec_loop()" << endl;
+ }
+
+ --indent;
+ }
+
+ return 0;
+}
diff --git a/python/pyqt/pyuic3/object.cpp b/python/pyqt/pyuic3/object.cpp
new file mode 100644
index 00000000..834427f5
--- /dev/null
+++ b/python/pyqt/pyuic3/object.cpp
@@ -0,0 +1,704 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+**
+** This file is part of Qt Designer.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#include "uic.h"
+#include "parser.h"
+#include "domtool.h"
+#include <qregexp.h>
+#include <qsizepolicy.h>
+#include <qstringlist.h>
+#define NO_STATIC_COLORS
+#include <globaldefs.h>
+
+
+/*!
+ Creates an implementation for the object given in \a e.
+
+ Traverses recursively over all children.
+
+ Returns the name of the generated child object.
+ */
+
+static bool createdCentralWidget = FALSE;
+
+QString Uic::createObjectImpl( const QDomElement &e, const QString& parentClass, const QString& par, const QString& layout )
+{
+ QString parent( par );
+ if ( parent == "self" && isMainWindow ) {
+ if ( !createdCentralWidget )
+ out << indent << "self.setCentralWidget(QWidget(self,\"qt_central_widget\"))" << endl;
+ createdCentralWidget = TRUE;
+ parent = "self.centralWidget()";
+ }
+ QDomElement n;
+ QString objClass, objName, fullObjName;
+ int numItems = 0;
+ int numColumns = 0;
+ int numRows = 0;
+
+ if ( layouts.contains( e.tagName() ) )
+ return createLayoutImpl( e, parentClass, parent, layout );
+
+ objClass = getClassName( e );
+ if ( objClass.isEmpty() )
+ return objName;
+ objName = getObjectName( e );
+
+ QString definedName = objName;
+ bool isTmpObject = objName.isEmpty() || objClass == "QLayoutWidget";
+ if ( isTmpObject ) {
+ if ( objClass[0] == 'Q' )
+ objName = objClass.mid(1);
+ else
+ objName = objClass.lower();
+ }
+
+ bool isLine = objClass == "Line";
+ if ( isLine )
+ objClass = "QFrame";
+
+ out << endl;
+ if ( objClass == "QLayoutWidget" ) {
+ if ( layout.isEmpty() ) {
+ // register the object and unify its name
+ objName = registerObject( objName );
+ out << indent << objName << " = QWidget(" << parent << ",\"" << definedName << "\")" << endl;
+ } else {
+ // the layout widget is not necessary, hide it by creating its child in the parent
+ QString result;
+ for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
+ if (tags.contains( n.tagName() ) )
+ result = createObjectImpl( n, parentClass, parent, layout );
+ }
+ return result;
+ }
+
+ // Layouts don't go into the class instance dictionary.
+ fullObjName = objName;
+ } else if ( objClass != "QToolBar" && objClass != "QMenuBar" ) {
+ // register the object and unify its name
+ objName = registerObject( objName );
+
+ // Temporary objects don't go into the class instance dictionary.
+ fullObjName = isTmpObject ? objName : "self." + objName;
+
+ out << indent << fullObjName << " = " << createObjectInstance( objClass, parent, objName ) << endl;
+ }
+ else
+ fullObjName = "self." + objName;
+
+ if ( objClass == "QAxWidget" ) {
+ QString controlId;
+ for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( n.tagName() == "property" && n.attribute( "name" ) == "control" ) {
+ controlId = n.firstChild().toElement().text();
+ }
+ }
+ out << indent << fullObjName << ".setControl(\"" << controlId << "\")" << endl;
+ }
+
+ lastItem = "None";
+ // set the properties and insert items
+ bool hadFrameShadow = FALSE;
+ for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( n.tagName() == "property" ) {
+ bool stdset = stdsetdef;
+ if ( n.hasAttribute( "stdset" ) )
+ stdset = toBool( n.attribute( "stdset" ) );
+ QString prop = n.attribute( "name" );
+ if ( prop == "database" )
+ continue;
+ QString value = setObjectProperty( objClass, objName, prop, n.firstChild().toElement(), stdset );
+ if ( value.isEmpty() )
+ continue;
+ if ( prop == "name" )
+ continue;
+ if ( isLine && prop == "frameShadow" )
+ hadFrameShadow = TRUE;
+ if ( prop == "buddy" && value.startsWith("\"") && value.endsWith("\"") ) {
+ buddies << Buddy( objName, value.mid(1, value.length() - 2 ) );
+ continue;
+ }
+ if ( isLine && prop == "orientation" ) {
+ prop = "frameShape";
+ if ( value.right(10) == "Horizontal" )
+ value = "QFrame.HLine";
+ else
+ value = "QFrame.VLine";
+ if ( !hadFrameShadow ) {
+ prop = "frameStyle";
+ value += " | QFrame.Sunken";
+ }
+ }
+ if ( prop == "buttonGroupId" ) {
+ if ( parentClass == "QButtonGroup" )
+ out << indent << parent << ".insert( " << fullObjName << "," << value << ")" << endl;
+ continue;
+ }
+ if ( prop == "frameworkCode" )
+ continue;
+ if ( objClass == "QMultiLineEdit" &&
+ QRegExp("echoMode|hMargin|maxLength|maxLines|undoEnabled").exactMatch(prop) )
+ continue;
+ QString call = fullObjName + ".";
+ QString tail;
+ if ( stdset ) {
+ call += mkStdSet( prop ) + "(";
+ tail = ")";
+ } else {
+ call += "setProperty(\"" + prop + "\",QVariant(";
+ tail = "))";
+ }
+ if ( prop == "accel" ) {
+ call += "QKeySequence(";
+ tail += ")";
+ }
+ call += value + tail;
+
+ if ( n.firstChild().toElement().tagName() == "string" ||
+ prop == "currentItem" ) {
+ trout << trindent << call << endl;
+ } else {
+ out << indent << call << endl;
+ }
+ } else if ( n.tagName() == "item" ) {
+ QString call;
+ QString value;
+
+ if ( objClass.contains( "ListBox" ) ) {
+ call = createListBoxItemImpl( n, fullObjName );
+ if ( !call.isEmpty() ) {
+ if ( numItems == 0 )
+ trout << trindent << fullObjName << ".clear()" << endl;
+ trout << trindent << call << endl;
+ }
+ } else if ( objClass.contains( "ComboBox" ) ) {
+ call = createListBoxItemImpl( n, fullObjName, &value );
+ if ( !call.isEmpty() ) {
+ if ( numItems == 0 )
+ trout << trindent << fullObjName << ".clear()" << endl;
+ trout << trindent << call << endl;
+ }
+ } else if ( objClass.contains( "IconView" ) ) {
+ call = createIconViewItemImpl( n, fullObjName );
+ if ( !call.isEmpty() ) {
+ if ( numItems == 0 )
+ trout << trindent << fullObjName << ".clear()" << endl;
+ trout << trindent << call << endl;
+ }
+ } else if ( objClass.contains( "ListView" ) ) {
+ call = createListViewItemImpl( n, fullObjName, QString::null );
+ if ( !call.isEmpty() ) {
+ if ( numItems == 0 )
+ trout << trindent << fullObjName << ".clear()" << endl;
+ trout << call << endl;
+ }
+ }
+ if ( !call.isEmpty() )
+ numItems++;
+ } else if ( n.tagName() == "column" || n.tagName() == "row" ) {
+ QString call;
+ QString value;
+
+ if ( objClass.contains( "ListView" ) ) {
+ call = createListViewColumnImpl( n, fullObjName, &value );
+ if ( !call.isEmpty() ) {
+ out << call;
+ trout << trindent << fullObjName << ".header().setLabel("
+ << numColumns++ << "," << value << ")\n";
+ }
+ } else if ( objClass == "QTable" || objClass == "QDataTable" ) {
+ bool isCols = ( n.tagName() == "column" );
+ call = createTableRowColumnImpl( n, fullObjName, &value );
+ if ( !call.isEmpty() ) {
+ out << call;
+ trout << trindent << fullObjName << "."
+ << ( isCols ? "horizontalHeader" : "verticalHeader" )
+ << "().setLabel("
+ << ( isCols ? numColumns++ : numRows++ )
+ << "," << value << ")\n";
+ }
+ }
+ }
+ }
+
+ // create all children, some widgets have special requirements
+
+ if ( objClass == "QTabWidget" ) {
+ for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( tags.contains( n.tagName() ) ) {
+ QString page = createObjectImpl( n, objClass, fullObjName );
+ QString comment;
+ QString label = DomTool::readAttribute( n, "title", "", comment ).toString();
+ out << indent << fullObjName << ".insertTab(" << page << ",QString.fromLatin1(\"\"))" << endl;
+ trout << trindent << fullObjName << ".changeTab(" << page << "," << trcall( label, comment ) << ")" << endl;
+ }
+ }
+ } else if ( objClass == "QWidgetStack" ) {
+ for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( tags.contains( n.tagName() ) ) {
+ QString page = createObjectImpl( n, objClass, fullObjName );
+ int id = DomTool::readAttribute( n, "id", "" ).toInt();
+ out << indent << fullObjName << ".addWidget(" << page << "," << id << ")" << endl;
+ }
+ }
+ } else if ( objClass == "QToolBox" ) {
+ for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( tags.contains( n.tagName() ) ) {
+ QString page = createObjectImpl( n, objClass, fullObjName );
+ QString comment;
+ QString label = DomTool::readAttribute( n, "label", "", comment ).toString();
+ out << indent << fullObjName << ".addItem(" << page << ",QString.fromLatin1(\"\"))" << endl;
+ trout << trindent << fullObjName << ".setItemLabel(" << fullObjName
+ << ".indexOf(" << page << ")," << trcall( label, comment )
+ << ")" << endl;
+ }
+ }
+ } else if ( objClass != "QToolBar" && objClass != "QMenuBar" ) { // standard widgets
+ for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( tags.contains( n.tagName() ) )
+ createObjectImpl( n, objClass, fullObjName );
+ }
+ }
+
+ return fullObjName;
+}
+
+
+
+/*!
+ Creates a set-call for property \a exclusiveProp of the object
+ given in \a e.
+
+ If the object does not have this property, the function does nothing.
+
+ Exclusive properties are used to generate the implementation of
+ application font or palette change handlers in createFormImpl().
+
+ */
+void Uic::createExclusiveProperty( const QDomElement & e, const QString& exclusiveProp )
+{
+ QDomElement n;
+ QString objClass = getClassName( e );
+ if ( objClass.isEmpty() )
+ return;
+ QString objName = getObjectName( e );
+#if 0 // it's not clear whether this check should be here or not
+ if ( objName.isEmpty() )
+ return;
+#endif
+ for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( n.tagName() == "property" ) {
+ bool stdset = stdsetdef;
+ if ( n.hasAttribute( "stdset" ) )
+ stdset = toBool( n.attribute( "stdset" ) );
+ QString prop = n.attribute( "name" );
+ if ( prop != exclusiveProp )
+ continue;
+ QString value = setObjectProperty( objClass, objName, prop, n.firstChild().toElement(), stdset );
+ if ( value.isEmpty() )
+ continue;
+ out << indent << indent << objName << ".setProperty(\"" << prop << "\",QVariant(" << value << "))" << endl;
+ }
+ }
+}
+
+
+/* Convert a QSizePolicy::SizeType to text. */
+static QString mapSizeType(QSizePolicy::SizeType st)
+{
+ const char *txt;
+
+ switch (st)
+ {
+ case QSizePolicy::Fixed:
+ txt = "QSizePolicy.Fixed";
+ break;
+
+ case QSizePolicy::Minimum:
+ txt = "QSizePolicy.Minimum";
+ break;
+
+ case QSizePolicy::Maximum:
+ txt = "QSizePolicy.Maximum";
+ break;
+
+ case QSizePolicy::Preferred:
+ txt = "QSizePolicy.Preferred";
+ break;
+
+ case QSizePolicy::MinimumExpanding:
+ txt = "QSizePolicy.MinimumExpanding";
+ break;
+
+ case QSizePolicy::Expanding:
+ txt = "QSizePolicy.Expanding";
+ break;
+
+ case QSizePolicy::Ignored:
+ txt = "QSizePolicy.Ignored";
+ break;
+
+ default:
+ txt = "Invalid QSizePolicy::SizeType";
+ }
+
+ return txt;
+}
+
+
+/*! Attention: this function has to be in sync with
+ Resource::saveProperty() and DomTool::elementToVariant. If you
+ change one, change all.
+ */
+QString Uic::setObjectProperty( const QString& objClass, const QString& obj, const QString &prop, const QDomElement &e, bool stdset )
+{
+ QString v;
+ if ( e.tagName() == "rect" ) {
+ QDomElement n3 = e.firstChild().toElement();
+ int x = 0, y = 0, w = 0, h = 0;
+ while ( !n3.isNull() ) {
+ if ( n3.tagName() == "x" )
+ x = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "y" )
+ y = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "width" )
+ w = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "height" )
+ h = n3.firstChild().toText().data().toInt();
+ n3 = n3.nextSibling().toElement();
+ }
+ v = "QRect(%1,%2,%3,%4)";
+ v = v.arg(x).arg(y).arg(w).arg(h);
+
+ } else if ( e.tagName() == "point" ) {
+ QDomElement n3 = e.firstChild().toElement();
+ int x = 0, y = 0;
+ while ( !n3.isNull() ) {
+ if ( n3.tagName() == "x" )
+ x = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "y" )
+ y = n3.firstChild().toText().data().toInt();
+ n3 = n3.nextSibling().toElement();
+ }
+ v = "QPoint(%1,%2)";
+ v = v.arg(x).arg(y);
+ } else if ( e.tagName() == "size" ) {
+ QDomElement n3 = e.firstChild().toElement();
+ int w = 0, h = 0;
+ while ( !n3.isNull() ) {
+ if ( n3.tagName() == "width" )
+ w = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "height" )
+ h = n3.firstChild().toText().data().toInt();
+ n3 = n3.nextSibling().toElement();
+ }
+ v = "QSize(%1,%2)";
+ v = v.arg(w).arg(h);
+ } else if ( e.tagName() == "color" ) {
+ QDomElement n3 = e.firstChild().toElement();
+ int r = 0, g = 0, b = 0;
+ while ( !n3.isNull() ) {
+ if ( n3.tagName() == "red" )
+ r = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "green" )
+ g = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "blue" )
+ b = n3.firstChild().toText().data().toInt();
+ n3 = n3.nextSibling().toElement();
+ }
+ v = "QColor(%1,%2,%3)";
+ v = v.arg(r).arg(g).arg(b);
+ } else if ( e.tagName() == "font" ) {
+ QDomElement n3 = e.firstChild().toElement();
+ QString attrname = e.parentNode().toElement().attribute( "name", "font" );
+ QString fontname;
+ if ( !obj.isEmpty() ) {
+ fontname = registerObject( obj + "_" + attrname );
+ out << indent << fontname << " = QFont(self." << obj << ".font())" << endl;
+ } else {
+ fontname = registerObject( "f" );
+ out << indent << fontname << " = QFont(self.font())" << endl;
+ }
+ while ( !n3.isNull() ) {
+ if ( n3.tagName() == "family" )
+ out << indent << fontname << ".setFamily(\"" << n3.firstChild().toText().data() << "\")" << endl;
+ else if ( n3.tagName() == "pointsize" )
+ out << indent << fontname << ".setPointSize(" << n3.firstChild().toText().data() << ")" << endl;
+ else if ( n3.tagName() == "bold" )
+ out << indent << fontname << ".setBold(" << mkBool( n3.firstChild().toText().data() ) << ")" << endl;
+ else if ( n3.tagName() == "italic" )
+ out << indent << fontname << ".setItalic(" << mkBool( n3.firstChild().toText().data() ) << ")" << endl;
+ else if ( n3.tagName() == "underline" )
+ out << indent << fontname << ".setUnderline(" << mkBool( n3.firstChild().toText().data() ) << ")" << endl;
+ else if ( n3.tagName() == "strikeout" )
+ out << indent << fontname << ".setStrikeOut(" << mkBool( n3.firstChild().toText().data() ) << ")" << endl;
+ n3 = n3.nextSibling().toElement();
+ }
+
+ if ( prop == "font" ) {
+ if ( !obj.isEmpty() )
+ out << indent << "self." << obj << ".setFont(" << fontname << ")" << endl;
+ else
+ out << indent << "self.setFont(" << fontname << ")" << endl;
+ } else {
+ v = fontname;
+ }
+ } else if ( e.tagName() == "string" ) {
+ QString txt = e.firstChild().toText().data();
+ QString com = getComment( e.parentNode() );
+
+ if ( prop == "toolTip" && objClass != "QAction" && objClass != "QActionGroup" ) {
+ if ( !obj.isEmpty() )
+ trout << trindent << "QToolTip.add(self." << obj << ","
+ << trcall( txt, com ) << ")" << endl;
+ else
+ trout << trindent << "QToolTip.add(self,"
+ << trcall( txt, com ) << ")" << endl;
+ } else if ( prop == "whatsThis" && objClass != "QAction" && objClass != "QActionGroup" ) {
+ if ( !obj.isEmpty() )
+ trout << trindent << "QWhatsThis.add(self." << obj << ","
+ << trcall( txt, com ) << ")" << endl;
+ else
+ trout << trindent << "QWhatsThis.add(self,"
+ << trcall( txt, com ) << ")" << endl;
+ } else {
+ v = trcall( txt, com );
+ }
+ } else if ( e.tagName() == "cstring" ) {
+ v = "\"%1\"";
+ v = v.arg( e.firstChild().toText().data() );
+ } else if ( e.tagName() == "number" ) {
+ v = "%1";
+ v = v.arg( e.firstChild().toText().data() );
+ } else if ( e.tagName() == "bool" ) {
+ if ( stdset )
+ v = "%1";
+ else
+ v = "QVariant(%1,0)";
+ v = v.arg( mkBool( e.firstChild().toText().data() ) );
+ } else if ( e.tagName() == "pixmap" ) {
+ v = e.firstChild().toText().data();
+ if ( !v.isEmpty() ) {
+ if ( pixmapLoaderFunction.isEmpty() ) {
+ v.prepend( "self." );
+ } else {
+ v.prepend( pixmapLoaderFunction + "(" + QString( externPixmaps ? "\"" : "" ) );
+ v.append( QString( externPixmaps ? "\"" : "" ) + ")" );
+ }
+ }
+ } else if ( e.tagName() == "iconset" ) {
+ v = "QIconSet(%1)";
+ QString s = e.firstChild().toText().data();
+ if ( !s.isEmpty() ) {
+ if ( pixmapLoaderFunction.isEmpty() ) {
+ s.prepend( "self." );
+ } else {
+ s.prepend( pixmapLoaderFunction + "(" + QString( externPixmaps ? "\"" : "" ) );
+ s.append( QString( externPixmaps ? "\"" : "" ) + ")" );
+ }
+ }
+ v = v.arg( s );
+ } else if ( e.tagName() == "image" ) {
+ v = e.firstChild().toText().data() + ".convertToImage()";
+ } else if ( e.tagName() == "enum" ) {
+ v = "%1.%2";
+ QString oc = objClass;
+ QString ev = e.firstChild().toText().data();
+ if ( oc == "QListView" && ev == "Manual" ) // #### workaround, rename QListView::Manual in 4.0
+ oc = "QScrollView";
+ v = v.arg( oc ).arg( ev );
+ } else if ( e.tagName() == "set" ) {
+ QString keys( e.firstChild().toText().data() );
+ QStringList lst = QStringList::split( '|', keys );
+ v = "";
+ QStringList::Iterator it = lst.begin();
+ while ( it != lst.end() ) {
+ v += objClass + "." + *it;
+ if ( it != lst.fromLast() )
+ v += " | ";
+ ++it;
+ }
+ } else if ( e.tagName() == "sizepolicy" ) {
+ QDomElement n3 = e.firstChild().toElement();
+ QSizePolicy sp;
+ while ( !n3.isNull() ) {
+ if ( n3.tagName() == "hsizetype" )
+ sp.setHorData( (QSizePolicy::SizeType)n3.firstChild().toText().data().toInt() );
+ else if ( n3.tagName() == "vsizetype" )
+ sp.setVerData( (QSizePolicy::SizeType)n3.firstChild().toText().data().toInt() );
+ else if ( n3.tagName() == "horstretch" )
+ sp.setHorStretch( n3.firstChild().toText().data().toInt() );
+ else if ( n3.tagName() == "verstretch" )
+ sp.setVerStretch( n3.firstChild().toText().data().toInt() );
+ n3 = n3.nextSibling().toElement();
+ }
+ QString tmp = "self.";
+ if ( !obj.isEmpty() )
+ tmp += obj + ".";
+ v = "QSizePolicy(%1,%2,%3,%4," + tmp + "sizePolicy().hasHeightForWidth())";
+ v = v.arg( mapSizeType(sp.horData()) ).arg( mapSizeType(sp.verData()) ).arg( sp.horStretch() ).arg( sp.verStretch() );
+ } else if ( e.tagName() == "palette" ) {
+ QPalette pal;
+ bool no_pixmaps = e.elementsByTagName( "pixmap" ).count() == 0;
+ QDomElement n;
+ if ( no_pixmaps ) {
+ n = e.firstChild().toElement();
+ while ( !n.isNull() ) {
+ QColorGroup cg;
+ if ( n.tagName() == "active" ) {
+ cg = loadColorGroup( n );
+ pal.setActive( cg );
+ } else if ( n.tagName() == "inactive" ) {
+ cg = loadColorGroup( n );
+ pal.setInactive( cg );
+ } else if ( n.tagName() == "disabled" ) {
+ cg = loadColorGroup( n );
+ pal.setDisabled( cg );
+ }
+ n = n.nextSibling().toElement();
+ }
+ }
+ if ( no_pixmaps && pal == QPalette( pal.active().button(), pal.active().background() ) ) {
+ v = "QPalette(QColor(%1,%2,%3),QColor(%1,%2,%3))";
+ v = v.arg( pal.active().button().red() ).arg( pal.active().button().green() ).arg( pal.active().button().blue() );
+ v = v.arg( pal.active().background().red() ).arg( pal.active().background().green() ).arg( pal.active().background().blue() );
+ } else {
+ QString palette = "pal";
+ if ( !pal_used ) {
+ out << indent << palette << " = QPalette()" << endl;
+ pal_used = TRUE;
+ }
+ QString cg = "cg";
+ if ( !cg_used ) {
+ out << indent << cg << " = QColorGroup()" << endl;
+ cg_used = TRUE;
+ }
+ n = e.firstChild().toElement();
+ while ( !n.isNull() && n.tagName() != "active" )
+ n = n.nextSibling().toElement();
+ createColorGroupImpl( cg, n );
+ out << indent << palette << ".setActive(" << cg << ")" << endl;
+
+ n = e.firstChild().toElement();
+ while ( !n.isNull() && n.tagName() != "inactive" )
+ n = n.nextSibling().toElement();
+ createColorGroupImpl( cg, n );
+ out << indent << palette << ".setInactive(" << cg << ")" << endl;
+
+ n = e.firstChild().toElement();
+ while ( !n.isNull() && n.tagName() != "disabled" )
+ n = n.nextSibling().toElement();
+ createColorGroupImpl( cg, n );
+ out << indent << palette << ".setDisabled(" << cg << ")" << endl;
+ v = palette;
+ }
+ } else if ( e.tagName() == "cursor" ) {
+ v = "QCursor(%1)";
+ v = v.arg( e.firstChild().toText().data() );
+ } else if ( e.tagName() == "date" ) {
+ QDomElement n3 = e.firstChild().toElement();
+ int y, m, d;
+ y = m = d = 0;
+ while ( !n3.isNull() ) {
+ if ( n3.tagName() == "year" )
+ y = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "month" )
+ m = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "day" )
+ d = n3.firstChild().toText().data().toInt();
+ n3 = n3.nextSibling().toElement();
+ }
+ v = "QDate(%1,%2,%3)";
+ v = v.arg(y).arg(m).arg(d);
+ } else if ( e.tagName() == "time" ) {
+ QDomElement n3 = e.firstChild().toElement();
+ int h, m, s;
+ h = m = s = 0;
+ while ( !n3.isNull() ) {
+ if ( n3.tagName() == "hour" )
+ h = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "minute" )
+ m = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "second" )
+ s = n3.firstChild().toText().data().toInt();
+ n3 = n3.nextSibling().toElement();
+ }
+ v = "QTime(%1,%2,%3)";
+ v = v.arg(h).arg(m).arg(s);
+ } else if ( e.tagName() == "datetime" ) {
+ QDomElement n3 = e.firstChild().toElement();
+ int h, mi, s, y, mo, d;
+ h = mi = s = y = mo = d = 0;
+ while ( !n3.isNull() ) {
+ if ( n3.tagName() == "hour" )
+ h = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "minute" )
+ mi = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "second" )
+ s = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "year" )
+ y = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "month" )
+ mo = n3.firstChild().toText().data().toInt();
+ else if ( n3.tagName() == "day" )
+ d = n3.firstChild().toText().data().toInt();
+ n3 = n3.nextSibling().toElement();
+ }
+ v = "QDateTime(QDate(%1,%2,%3),QTime(%4,%5,%6))";
+ v = v.arg(y).arg(mo).arg(d).arg(h).arg(mi).arg(s);
+ } else if ( e.tagName() == "stringlist" ) {
+ QStringList l;
+ QDomElement n3 = e.firstChild().toElement();
+ QString listname = "l";
+ if ( !obj.isEmpty() ) {
+ listname = obj + "_stringlist";
+ listname = registerObject( listname );
+ out << indent << listname << " = QStringList()" << endl;
+ } else {
+ out << indent << listname << " = QStringList()" << endl;
+ }
+ while ( !n3.isNull() ) {
+ if ( n3.tagName() == "string" )
+ out << indent << listname << ".append(\"" << n3.firstChild().toText().data().simplifyWhiteSpace() << "\")" << endl;
+ n3 = n3.nextSibling().toElement();
+ }
+ v = listname;
+ }
+ return v;
+}
+
+
+
+
+/*! Extracts a named object property from \a e.
+ */
+QDomElement Uic::getObjectProperty( const QDomElement& e, const QString& name )
+{
+ QDomElement n;
+ for ( n = e.firstChild().toElement();
+ !n.isNull();
+ n = n.nextSibling().toElement() ) {
+ if ( n.tagName() == "property" && n.toElement().attribute("name") == name )
+ return n;
+ }
+ return n;
+}
+
diff --git a/python/pyqt/pyuic3/parser.cpp b/python/pyqt/pyuic3/parser.cpp
new file mode 100644
index 00000000..4fc13c5f
--- /dev/null
+++ b/python/pyqt/pyuic3/parser.cpp
@@ -0,0 +1,66 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+**
+** This file is part of Qt Designer.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#include "parser.h"
+#include <qobject.h>
+#include <qstringlist.h>
+
+class NormalizeObject : public QObject
+{
+public:
+ NormalizeObject() : QObject() {}
+ static QCString normalizeSignalSlot( const char *signalSlot ) { return QObject::normalizeSignalSlot( signalSlot ); }
+};
+
+QString Parser::cleanArgs( const QString &func )
+{
+ QString slot( func );
+ int begin = slot.find( "(" ) + 1;
+ QString args = slot.mid( begin );
+ args = args.left( args.find( ")" ) );
+ QStringList lst = QStringList::split( ',', args );
+ QString res = slot.left( begin );
+ for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) {
+ if ( it != lst.begin() )
+ res += ",";
+ QString arg = *it;
+ int pos = 0;
+ if ( ( pos = arg.find( "&" ) ) != -1 ) {
+ arg = arg.left( pos + 1 );
+ } else if ( ( pos = arg.find( "*" ) ) != -1 ) {
+ arg = arg.left( pos + 1 );
+ } else {
+ arg = arg.simplifyWhiteSpace();
+ if ( ( pos = arg.find( ':' ) ) != -1 )
+ arg = arg.left( pos ).simplifyWhiteSpace() + ":" + arg.mid( pos + 1 ).simplifyWhiteSpace();
+ QStringList l = QStringList::split( ' ', arg );
+ if ( l.count() == 2 ) {
+ if ( l[ 0 ] != "const" && l[ 0 ] != "unsigned" && l[ 0 ] != "var" )
+ arg = l[ 0 ];
+ } else if ( l.count() == 3 ) {
+ arg = l[ 0 ] + " " + l[ 1 ];
+ }
+ }
+ res += arg;
+ }
+ res += ")";
+
+ return QString::fromLatin1( NormalizeObject::normalizeSignalSlot( res.latin1() ) );
+}
diff --git a/python/pyqt/pyuic3/parser.h b/python/pyqt/pyuic3/parser.h
new file mode 100644
index 00000000..5a5671ad
--- /dev/null
+++ b/python/pyqt/pyuic3/parser.h
@@ -0,0 +1,33 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+**
+** This file is part of Qt Designer.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#ifndef PARSER_H
+#define PARSER_H
+
+#include <qstring.h>
+
+class Parser
+{
+public:
+ static QString cleanArgs( const QString &func );
+
+};
+
+#endif
diff --git a/python/pyqt/pyuic3/pyuic-prof.sbf b/python/pyqt/pyuic3/pyuic-prof.sbf
new file mode 100644
index 00000000..25013493
--- /dev/null
+++ b/python/pyqt/pyuic3/pyuic-prof.sbf
@@ -0,0 +1,24 @@
+# This is the build file for pyuic for Qt v3 Professional Edition.
+#
+# Copyright (c) 2007
+# Riverbank Computing Limited <info@riverbankcomputing.co.uk>
+#
+# This file is part of PyQt.
+#
+# This copy of PyQt is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 2, or (at your option) any later
+# version.
+#
+# PyQt is supplied in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# PyQt; see the file LICENSE. If not, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+target = pyuic
+sources = main.cpp uic.cpp form.cpp object.cpp subclassing.cpp embed.cpp widgetdatabase.cpp domtool.cpp parser.cpp qdom.cpp qxml.cpp
+headers = domtool.h globaldefs.h parser.h uic.h widgetdatabase.h widgetinterface.h
diff --git a/python/pyqt/pyuic3/pyuic.pro.in b/python/pyqt/pyuic3/pyuic.pro.in
new file mode 100644
index 00000000..faebbd6f
--- /dev/null
+++ b/python/pyqt/pyuic3/pyuic.pro.in
@@ -0,0 +1,36 @@
+# Copyright (c) 2001
+# Phil Thompson <phil@river-bank.demon.co.uk>
+# Copyright (c) 2002, 2003
+# Riverbank Computing Limited <info@riverbankcomputing.co.uk>
+#
+# The project file for pyuic for Qt v3.
+
+
+TEMPLATE = app
+CONFIG += qt console warn_on release @PYQT_RBPROF@
+INCLUDEPATH += @BLX_INCLUDEPATH@ $(QTDIR)/src/3rdparty/zlib
+DEFINES += UIC QT_INTERNAL_XML @BLX_DEFINES@
+
+DESTDIR = @PYQT_BINDIR@
+TARGET = pyuic
+
+HEADERS = uic.h \
+ widgetdatabase.h \
+ domtool.h \
+ parser.h \
+ widgetinterface.h
+
+SOURCES = main.cpp \
+ uic.cpp \
+ form.cpp \
+ object.cpp \
+ subclassing.cpp \
+ embed.cpp \
+ widgetdatabase.cpp \
+ domtool.cpp \
+ parser.cpp
+
+rbprof:exists($(QTDIR)/src/qt_professional.pri) {
+ QT_SOURCE_TREE = $(QTDIR)
+ include($(QTDIR)/src/qt_professional.pri)
+}
diff --git a/python/pyqt/pyuic3/pyuic.sbf b/python/pyqt/pyuic3/pyuic.sbf
new file mode 100644
index 00000000..a40245de
--- /dev/null
+++ b/python/pyqt/pyuic3/pyuic.sbf
@@ -0,0 +1,24 @@
+# This is the build file for pyuic for Qt v3.
+#
+# Copyright (c) 2007
+# Riverbank Computing Limited <info@riverbankcomputing.co.uk>
+#
+# This file is part of PyQt.
+#
+# This copy of PyQt is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 2, or (at your option) any later
+# version.
+#
+# PyQt is supplied in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# PyQt; see the file LICENSE. If not, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+target = pyuic
+sources = main.cpp uic.cpp form.cpp object.cpp subclassing.cpp embed.cpp widgetdatabase.cpp domtool.cpp parser.cpp
+headers = domtool.h globaldefs.h parser.h uic.h widgetdatabase.h widgetinterface.h
diff --git a/python/pyqt/pyuic3/subclassing.cpp b/python/pyqt/pyuic3/subclassing.cpp
new file mode 100644
index 00000000..299e0449
--- /dev/null
+++ b/python/pyqt/pyuic3/subclassing.cpp
@@ -0,0 +1,185 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+**
+** This file is part of Qt Designer.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#include "uic.h"
+#include "parser.h"
+#include "widgetdatabase.h"
+#include "domtool.h"
+#include <qfile.h>
+#include <qstringlist.h>
+#include <qdatetime.h>
+#define NO_STATIC_COLORS
+#include <globaldefs.h>
+#include <qregexp.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+/*!
+ Creates an implementation for a subclass \a subClass of the form
+ given in \a e
+
+ \sa createSubDecl()
+ */
+void Uic::createSubImpl( const QDomElement &e, const QString& subClass )
+{
+ QDomElement n;
+ QDomNodeList nl;
+ int i;
+
+ QString objClass = getClassName( e );
+ if ( objClass.isEmpty() )
+ return;
+
+ QString supClsMod = fileName;
+ int tail = supClsMod.findRev('.',-1);
+ if (tail >= 0)
+ supClsMod.truncate(tail);
+
+ out << indent << "from " << supClsMod << " import " << nameOfClass << endl;
+ out << endl;
+ out << endl;
+
+ out << indent << "class " << subClass << "(" << nameOfClass << "):" << endl;
+ ++indent;
+ out << endl;
+
+ // constructor
+ if ( objClass == "QDialog" || objClass == "QWizard" ) {
+ out << indent << "def __init__(self,parent = None,name = None,modal = 0,fl = 0):" << endl;
+ ++indent;
+ out << indent << nameOfClass << ".__init__(self,parent,name,modal,fl)" << endl;
+ } else { // standard QWidget
+ out << indent << "def __init__(self,parent = None,name = None,fl = 0):" << endl;
+ ++indent;
+ out << indent << nameOfClass << ".__init__(self,parent,name,fl)" << endl;
+ }
+ --indent;
+
+ // find additional functions
+ QStringList publicSlots, protectedSlots, privateSlots;
+ QStringList publicSlotTypes, protectedSlotTypes, privateSlotTypes;
+ QStringList publicSlotSpecifier, protectedSlotSpecifier, privateSlotSpecifier;
+ QStringList publicFuncts, protectedFuncts, privateFuncts;
+ QStringList publicFunctRetTyp, protectedFunctRetTyp, privateFunctRetTyp;
+ QStringList publicFunctSpec, protectedFunctSpec, privateFunctSpec;
+
+ nl = e.parentNode().toElement().elementsByTagName( "slot" );
+ for ( i = 0; i < (int) nl.length(); i++ ) {
+ n = nl.item(i).toElement();
+ if ( n.parentNode().toElement().tagName() != "slots"
+ && n.parentNode().toElement().tagName() != "connections" )
+ continue;
+ if ( n.attribute( "language", "C++" ) != "C++" )
+ continue;
+ QString returnType = n.attribute( "returnType", "void" );
+ QString functionName = n.firstChild().toText().data().stripWhiteSpace();
+ if ( functionName.endsWith( ";" ) )
+ functionName = functionName.left( functionName.length() - 1 );
+ QString specifier = n.attribute( "specifier" );
+ QString access = n.attribute( "access" );
+ if ( access == "protected" ) {
+ protectedSlots += functionName;
+ protectedSlotTypes += returnType;
+ protectedSlotSpecifier += specifier;
+ } else if ( access == "private" ) {
+ privateSlots += functionName;
+ privateSlotTypes += returnType;
+ privateSlotSpecifier += specifier;
+ } else {
+ publicSlots += functionName;
+ publicSlotTypes += returnType;
+ publicSlotSpecifier += specifier;
+ }
+ }
+
+ nl = e.parentNode().toElement().elementsByTagName( "function" );
+ for ( i = 0; i < (int) nl.length(); i++ ) {
+ n = nl.item(i).toElement();
+ if ( n.parentNode().toElement().tagName() != "functions" )
+ continue;
+ if ( n.attribute( "language", "C++" ) != "C++" )
+ continue;
+ QString returnType = n.attribute( "returnType", "void" );
+ QString functionName = n.firstChild().toText().data().stripWhiteSpace();
+ if ( functionName.endsWith( ";" ) )
+ functionName = functionName.left( functionName.length() - 1 );
+ QString specifier = n.attribute( "specifier" );
+ QString access = n.attribute( "access" );
+ if ( access == "protected" ) {
+ protectedFuncts += functionName;
+ protectedFunctRetTyp += returnType;
+ protectedFunctSpec += specifier;
+ } else if ( access == "private" ) {
+ privateFuncts += functionName;
+ privateFunctRetTyp += returnType;
+ privateFunctSpec += specifier;
+ } else {
+ publicFuncts += functionName;
+ publicFunctRetTyp += returnType;
+ publicFunctSpec += specifier;
+ }
+ }
+
+ if ( !publicFuncts.isEmpty() )
+ writeFunctionsSubImpl( publicFuncts, publicFunctRetTyp, publicFunctSpec, subClass, "public function" );
+
+ // create stubs for public additional slots
+ if ( !publicSlots.isEmpty() )
+ writeFunctionsSubImpl( publicSlots, publicSlotTypes, publicSlotSpecifier, subClass, "public slot" );
+
+ if ( !protectedFuncts.isEmpty() )
+ writeFunctionsSubImpl( protectedFuncts, protectedFunctRetTyp, protectedFunctSpec, subClass, "protected function" );
+
+ // create stubs for protected additional slots
+ if ( !protectedSlots.isEmpty() )
+ writeFunctionsSubImpl( protectedSlots, protectedSlotTypes, protectedSlotSpecifier, subClass, "protected slot" );
+
+ if ( !privateFuncts.isEmpty() )
+ writeFunctionsSubImpl( privateFuncts, privateFunctRetTyp, privateFunctSpec, subClass, "private function" );
+
+ // create stubs for private additional slots
+ if ( !privateSlots.isEmpty() )
+ writeFunctionsSubImpl( privateSlots, privateSlotTypes, privateSlotSpecifier, subClass, "private slot" );
+
+ --indent;
+}
+
+void Uic::writeFunctionsSubImpl( const QStringList &fuLst, const QStringList &typLst, const QStringList &specLst,
+ const QString &subClass, const QString &descr )
+{
+ QValueListConstIterator<QString> it, it2, it3;
+ for ( it = fuLst.begin(), it2 = typLst.begin(), it3 = specLst.begin();
+ it != fuLst.end(); ++it, ++it2, ++it3 ) {
+ QString type = *it2;
+ if ( type.isEmpty() )
+ type = "void";
+ if ( *it3 == "non virtual" )
+ continue;
+ out << endl;
+ out << indent << "# " << descr << endl;
+ pySlot(it);
+ ++indent;
+ out << endl;
+ out << indent << "print \"" << subClass << "." << (*it) << ": Not implemented yet\"" << endl;
+ --indent;
+ }
+ out << endl;
+}
diff --git a/python/pyqt/pyuic3/uic.cpp b/python/pyqt/pyuic3/uic.cpp
new file mode 100644
index 00000000..d3593020
--- /dev/null
+++ b/python/pyqt/pyuic3/uic.cpp
@@ -0,0 +1,1145 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (c) 2004 Phil Thompson <phil@riverbankcomputing.co.uk>
+**
+** This file is part of Qt Designer.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#include "uic.h"
+#include "parser.h"
+#include "widgetdatabase.h"
+#include "domtool.h"
+#include <qfile.h>
+#include <qstringlist.h>
+#include <qdatetime.h>
+#define NO_STATIC_COLORS
+#include <globaldefs.h>
+#include <qregexp.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+bool Uic::isMainWindow = FALSE;
+PyIndent Uic::indent;
+PyIndent Uic::trindent;
+
+
+// Re-calculate the indent string based on the current number and nature of the
+// indent.
+void PyIndent::calc()
+{
+ indstr.truncate(0);
+
+ for (uint i = current; i > 0; --i)
+ if (tabStop == 0)
+ indstr += '\t';
+ else
+ for (uint t = 0; t < tabStop; ++t)
+ indstr += ' ';
+}
+
+
+QString Uic::getComment( const QDomNode& n )
+{
+ QDomNode child = n.firstChild();
+ while ( !child.isNull() ) {
+ if ( child.toElement().tagName() == "comment" )
+ return child.toElement().firstChild().toText().data();
+ child = child.nextSibling();
+ }
+ return QString::null;
+}
+
+QString Uic::mkBool( bool b )
+{
+ return b? "1" : "0";
+}
+
+QString Uic::mkBool( const QString& s )
+{
+ return mkBool( s == "true" || s == "1" );
+}
+
+bool Uic::toBool( const QString& s )
+{
+ return s == "true" || s.toInt() != 0;
+}
+
+QString Uic::fixString( const QString &str, bool encode )
+{
+#if QT_VERSION >= 0x030100
+ QString s;
+ if ( !encode ) {
+ s = str;
+ s.replace( "\\", "\\\\" );
+ s.replace( "\"", "\\\"" );
+ s.replace( "\r", "" );
+ s.replace( "\n", "\\n\"\n\"" );
+ } else {
+ QCString utf8 = str.utf8();
+ const int l = utf8.length();
+
+ for ( int i = 0; i < l; ++i ) {
+ uchar ch = (uchar)utf8[i];
+
+ if (ch != 0x0d) { // skip \r
+ s += "\\x";
+
+ if (ch <= 0x0f)
+ s += "0";
+
+ s += QString::number( ch, 16 );
+ }
+ }
+ }
+#else
+ QString s( str );
+ s.replace( QRegExp( "\\\\" ), "\\\\" );
+ s.replace( QRegExp( "\"" ), "\\\"" );
+ s.replace( QRegExp( "\r?\n" ), "\\n\"\n\"" );
+#endif
+ return "\"" + s + "\"";
+}
+
+QString Uic::trcall( const QString& sourceText, const QString& comment )
+{
+ if ( sourceText.isEmpty() && comment.isEmpty() )
+ return "QString.null";
+
+ QString t = trmacro;
+ bool encode = FALSE;
+ if ( t.isNull() ) {
+ t = "self.__tr";
+ for ( int i = 0; i < (int) sourceText.length(); i++ ) {
+ if ( sourceText[i].unicode() >= 0x80 ) {
+ t = "self.__trUtf8";
+ encode = TRUE;
+ break;
+ }
+ }
+
+ if (encode)
+ pyNeedTrUtf8 = TRUE;
+ else
+ pyNeedTr = TRUE;
+ }
+
+ if ( comment.isEmpty() ) {
+ return t + "(" + fixString( sourceText, encode ) + ")";
+ } else {
+ return t + "(" + fixString( sourceText, encode ) + "," +
+ fixString( comment, encode ) + ")";
+ }
+}
+
+QString Uic::mkStdSet( const QString& prop )
+{
+ return QString( "set" ) + prop[0].upper() + prop.mid(1);
+}
+
+
+
+/*!
+ \class Uic uic.h
+ \brief User Interface Compiler
+
+ The class Uic encapsulates the user interface compiler (uic).
+ */
+Uic::Uic( const QString &fn, const char *outputFn, QTextStream &outStream,
+ QDomDocument doc, bool subcl, const QString &trm,
+ const QString& subClass, QString &uicClass )
+ : out( outStream ), trout (&languageChangeBody ),
+ outputFileName( outputFn ), trmacro( trm ),
+ pyNeedTr(FALSE), pyNeedTrUtf8(FALSE)
+{
+ fileName = fn;
+ writeFunctImpl = TRUE;
+ defMargin = BOXLAYOUT_DEFAULT_MARGIN;
+ defSpacing = BOXLAYOUT_DEFAULT_SPACING;
+ externPixmaps = FALSE;
+
+ trindent.setIndent(2);
+
+ item_used = cg_used = pal_used = 0;
+
+ layouts << "hbox" << "vbox" << "grid";
+ tags = layouts;
+ tags << "widget";
+
+ pixmapLoaderFunction = getPixmapLoaderFunction( doc.firstChild().toElement() );
+ nameOfClass = getFormClassName( doc.firstChild().toElement() );
+
+#if QT_VERSION >= 0x030300
+ uiFileVersion = doc.firstChild().toElement().attribute("version");
+#endif
+ stdsetdef = toBool( doc.firstChild().toElement().attribute("stdsetdef") );
+
+ if ( doc.firstChild().isNull() || doc.firstChild().firstChild().isNull() )
+ return;
+
+ // Extract any Python code in the comments.
+ QStringList comm = QStringList::split('\n',getComment(doc.firstChild()));
+
+ for (QStringList::Iterator it = comm.begin(); it != comm.end(); ++it)
+ if ((*it).startsWith("Python:"))
+ pyCode += (*it).mid(7) + "\n";
+
+ QDomElement e = doc.firstChild().firstChild().toElement();
+ QDomElement widget;
+ while ( !e.isNull() ) {
+ if ( e.tagName() == "widget" ) {
+ widget = e;
+ } else if ( e.tagName() == "pixmapinproject" ) {
+ externPixmaps = TRUE;
+ } else if ( e.tagName() == "layoutdefaults" ) {
+ defSpacing = e.attribute( "spacing", defSpacing.toString() );
+ defMargin = e.attribute( "margin", defMargin.toString() );
+ } else if ( e.tagName() == "layoutfunctions" ) {
+ defSpacing = e.attribute( "spacing", defSpacing.toString() );
+
+ bool ok;
+ defSpacing.toInt( &ok );
+ if ( !ok ) {
+ QString buf = defSpacing.toString();
+ defSpacing = buf.append( "()" );
+ }
+ defMargin = e.attribute( "margin", defMargin.toString() );
+ defMargin.toInt( &ok );
+ if ( !ok ) {
+ QString buf = defMargin.toString();
+ defMargin = buf.append( "()" );
+ }
+ }
+ e = e.nextSibling().toElement();
+ }
+ e = widget;
+
+ if ( nameOfClass.isEmpty() )
+ nameOfClass = getObjectName( e );
+
+ uicClass = nameOfClass;
+
+ namespaces = QStringList::split( "::", nameOfClass );
+ bareNameOfClass = namespaces.last();
+ namespaces.remove( namespaces.fromLast() );
+
+ if ( subcl ) {
+ createSubImpl( e, subClass );
+ } else {
+ createFormImpl( e );
+ }
+
+ ++indent;
+
+ if (pyNeedTr)
+ {
+ out << "\n";
+ out << indent << "def __tr(self,s,c = None):\n";
+ ++indent;
+ out << indent << "return qApp.translate(\"" << nameOfClass << "\",s,c)\n";
+ --indent;
+ }
+
+ if (pyNeedTrUtf8)
+ {
+ out << "\n";
+ out << indent << "def __trUtf8(self,s,c = None):\n";
+ ++indent;
+ out << indent << "return qApp.translate(\"" << nameOfClass << "\",s,c,QApplication.UnicodeUTF8)\n";
+ --indent;
+ }
+
+ --indent;
+}
+
+/*! Extracts a pixmap loader function from \a e
+ */
+QString Uic::getPixmapLoaderFunction( const QDomElement& e )
+{
+ QDomElement n;
+ for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( n.tagName() == "pixmapfunction" )
+ return n.firstChild().toText().data();
+ }
+ return QString::null;
+}
+
+
+/*! Extracts the forms class name from \a e
+ */
+QString Uic::getFormClassName( const QDomElement& e )
+{
+ QDomElement n;
+ QString cn;
+ for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( n.tagName() == "class" ) {
+ QString s = n.firstChild().toText().data();
+ int i;
+ while ( ( i = s.find(' ' )) != -1 )
+ s[i] = '_';
+ cn = s;
+ }
+ }
+ return cn;
+}
+
+/*! Extracts a class name from \a e.
+ */
+QString Uic::getClassName( const QDomElement& e )
+{
+ QString s = e.attribute( "class" );
+ if ( s.isEmpty() && e.tagName() == "toolbar" )
+ s = "QToolBar";
+ else if ( s.isEmpty() && e.tagName() == "menubar" )
+ s = "QMenuBar";
+ return s;
+}
+
+/*! Returns TRUE if database framework code is generated, else FALSE.
+*/
+
+bool Uic::isFrameworkCodeGenerated( const QDomElement& e )
+{
+ QDomElement n = getObjectProperty( e, "frameworkCode" );
+ if ( n.attribute("name") == "frameworkCode" &&
+ !DomTool::elementToVariant( n.firstChild().toElement(), QVariant( TRUE, 0 ) ).toBool() )
+ return FALSE;
+ return TRUE;
+}
+
+/*! Extracts an object name from \a e. It's stored in the 'name'
+ property.
+ */
+QString Uic::getObjectName( const QDomElement& e )
+{
+ QDomElement n = getObjectProperty( e, "name" );
+ if ( n.firstChild().toElement().tagName() == "cstring" )
+ return n.firstChild().toElement().firstChild().toText().data();
+ return QString::null;
+}
+
+/*! Extracts an layout name from \a e. It's stored in the 'name'
+ property of the preceeding sibling (the first child of a QLayoutWidget).
+ */
+QString Uic::getLayoutName( const QDomElement& e )
+{
+ QDomElement p = e.parentNode().toElement();
+ QString name;
+
+ if ( getClassName(p) != "QLayoutWidget" )
+ name = "Layout";
+
+ QDomElement n = getObjectProperty( p, "name" );
+ if ( n.firstChild().toElement().tagName() == "cstring" ) {
+ name.prepend( n.firstChild().toElement().firstChild().toText().data() );
+ return QStringList::split( "::", name ).last();
+ }
+ return e.tagName();
+}
+
+
+QString Uic::getDatabaseInfo( const QDomElement& e, const QString& tag )
+{
+ QDomElement n;
+ QDomElement n1;
+ int child = 0;
+ // database info is a stringlist stored in this order
+ if ( tag == "connection" )
+ child = 0;
+ else if ( tag == "table" )
+ child = 1;
+ else if ( tag == "field" )
+ child = 2;
+ else
+ return QString::null;
+ n = getObjectProperty( e, "database" );
+ if ( n.firstChild().toElement().tagName() == "stringlist" ) {
+ // find correct stringlist entry
+ QDomElement n1 = n.firstChild().firstChild().toElement();
+ for ( int i = 0; i < child && !n1.isNull(); ++i )
+ n1 = n1.nextSibling().toElement();
+ if ( n1.isNull() )
+ return QString::null;
+ return n1.firstChild().toText().data();
+ }
+ return QString::null;
+}
+
+
+/*!
+ Returns include file for class \a className or a null string.
+ */
+QString Uic::getInclude( const QString& className )
+{
+ int wid = WidgetDatabase::idFromClassName( className );
+ if ( wid != -1 )
+ return WidgetDatabase::includeFile( wid );
+ return QString::null;
+}
+
+
+void Uic::createActionImpl( const QDomElement &n, const QString &parent )
+{
+ for ( QDomElement ae = n; !ae.isNull(); ae = ae.nextSibling().toElement() ) {
+ QString objName = registerObject( getObjectName( ae ) );
+ if ( ae.tagName() == "action" )
+ out << indent << "self." << objName << " = QAction(" << parent << ",\"" << objName << "\")" << endl;
+ else if ( ae.tagName() == "actiongroup" )
+ out << indent << "self." << objName << " = QActionGroup(" << parent << ",\"" << objName << "\")" << endl;
+ else
+ continue;
+ bool subActionsDone = FALSE;
+#if QT_VERSION >= 0x030300
+ bool hasMenuText = FALSE;
+ QString actionText;
+#endif
+ for ( QDomElement n2 = ae.firstChild().toElement(); !n2.isNull(); n2 = n2.nextSibling().toElement() ) {
+ if ( n2.tagName() == "property" ) {
+ bool stdset = stdsetdef;
+ if ( n2.hasAttribute( "stdset" ) )
+ stdset = toBool( n2.attribute( "stdset" ) );
+ QString prop = n2.attribute("name");
+ if ( prop == "name" )
+ continue;
+ QString value = setObjectProperty( "QAction", objName, prop, n2.firstChild().toElement(), stdset );
+ if ( value.isEmpty() )
+ continue;
+
+ QString call = "self." + objName + ".";
+ if ( stdset )
+ call += mkStdSet( prop ) + "(" + value + ")";
+ else
+ call += "setProperty(\"" + prop + "\",QVariant(" + value + "))";
+
+#if QT_VERSION >= 0x030300
+ if (prop == "menuText")
+ hasMenuText = TRUE;
+ else if (prop == "text")
+ actionText = value;
+#endif
+
+ if ( n2.firstChild().toElement().tagName() == "string" ) {
+ trout << trindent << call << endl;
+ } else {
+ out << indent << call << endl;
+ }
+ } else if ( !subActionsDone && ( n2.tagName() == "actiongroup" || n2.tagName() == "action" ) ) {
+ createActionImpl( n2, "self." + objName );
+ subActionsDone = TRUE;
+ }
+ }
+#if QT_VERSION >= 0x030300
+ // workaround for loading pre-3.3 files expecting bogus QAction behavior
+ if (!hasMenuText && !actionText.isEmpty() && uiFileVersion < "3.3")
+ trout << indent << "self." << objName << ".setMenuText(" << actionText << ")" << endl;
+#endif
+ }
+}
+
+QString get_dock( const QString &d )
+{
+ if ( d == "0" )
+ return "Qt.DockUnmanaged";
+ if ( d == "1" )
+ return "Qt.DockTornOff";
+ if ( d == "2" )
+ return "Qt.DockTop";
+ if ( d == "3" )
+ return "Qt.DockBottom";
+ if ( d == "4" )
+ return "Qt.DockRight";
+ if ( d == "5" )
+ return "Qt.DockLeft";
+ if ( d == "6" )
+ return "Qt.DockMinimized";
+ return "";
+}
+
+void Uic::createToolbarImpl( const QDomElement &n, const QString &parentClass, const QString &parent )
+{
+ QDomNodeList nl = n.elementsByTagName( "toolbar" );
+ for ( int i = 0; i < (int) nl.length(); i++ ) {
+ QDomElement ae = nl.item( i ).toElement();
+ QString dock = get_dock( ae.attribute( "dock" ) );
+ QString objName = getObjectName( ae );
+ out << indent << "self." << objName << " = QToolBar(QString(\"\"),self," << dock << ")" << endl;
+ createObjectImpl( ae, parentClass, parent );
+ for ( QDomElement n2 = ae.firstChild().toElement(); !n2.isNull(); n2 = n2.nextSibling().toElement() ) {
+ if ( n2.tagName() == "action" ) {
+ out << indent << "self." << n2.attribute( "name" ) << ".addTo(self." << objName << ")" << endl;
+ } else if ( n2.tagName() == "separator" ) {
+ out << indent << "self." << objName << ".addSeparator()" << endl;
+ } else if ( n2.tagName() == "widget" ) {
+ if ( n2.attribute( "class" ) != "Spacer" ) {
+ createObjectImpl( n2, "QToolBar", "self." + objName );
+ } else {
+ QString child = createSpacerImpl( n2, parentClass, parent, objName );
+ out << indent << "QApplication.sendPostedEvents(self." << objName
+ << ",QEvent.ChildInserted)" << endl;
+ out << indent << "self." << objName << ".boxLayout().addItem(" << child << ")" << endl;
+ }
+ }
+ }
+ }
+}
+
+void Uic::createMenuBarImpl( const QDomElement &n, const QString &parentClass, const QString &parent )
+{
+ QString objName = getObjectName( n );
+ out << indent << "self." << objName << " = QMenuBar(self,\"" << objName << "\")" << endl;
+ createObjectImpl( n, parentClass, parent );
+
+ int i = 0;
+ QDomElement c = n.firstChild().toElement();
+ while ( !c.isNull() ) {
+ if ( c.tagName() == "item" ) {
+ QString itemName = "self." + c.attribute( "name" );
+ out << endl;
+ out << indent << itemName << " = QPopupMenu(self)" << endl;
+ createPopupMenuImpl( c, parentClass, itemName );
+ out << indent << "self." << objName << ".insertItem(QString(\"\")," << itemName << "," << i << ")" << endl;
+ QString findItem("self." + objName + ".findItem(%1)");
+ findItem = findItem.arg(i);
+ trout << indent << "if " << findItem << ":" << endl;
+ ++indent;
+ trout << indent << findItem << ".setText(" << trcall( c.attribute( "text" ) ) << ")" << endl;
+ --indent;
+ } else if ( c.tagName() == "separator" ) {
+ out << endl;
+ out << indent << "self." << objName << ".insertSeparator(" << i << ")" << endl;
+ }
+ c = c.nextSibling().toElement();
+ i++;
+ }
+}
+
+void Uic::createPopupMenuImpl( const QDomElement &e, const QString &parentClass, const QString &parent )
+{
+ int i = 0;
+ for ( QDomElement n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( n.tagName() == "action" || n.tagName() == "actiongroup" ) {
+ QDomElement n2 = n.nextSibling().toElement();
+ if ( n2.tagName() == "item" ) { // the action has a sub menu
+ QString itemName = "self." + n2.attribute( "name" );
+ QString itemText = n2.attribute( "text" );
+ out << indent << itemName << " = QPopupMenu(self)" << endl;
+ out << indent << parent << ".setAccel(" << trcall( n2.attribute( "accel" ) ) << ",";
+ out << parent << ".insertItem(" << "self." << n.attribute( "name" ) << ".iconSet(),";
+ out << trcall( itemText ) << "," << itemName << "))" << endl;
+ trout << indent << parent << ".changeItem(" << parent << ".idAt(" << i << "),";
+ trout << trcall( itemText ) << ")" << endl;
+ createPopupMenuImpl( n2, parentClass, itemName );
+ n = n2;
+ } else {
+ out << indent << "self." << n.attribute( "name" ) << ".addTo(" << parent << ")" << endl;
+ }
+ } else if ( n.tagName() == "separator" ) {
+ out << indent << parent << ".insertSeparator()" << endl;
+ }
+ ++i;
+ }
+}
+
+/*!
+ Creates implementation of an listbox item tag.
+*/
+
+QString Uic::createListBoxItemImpl( const QDomElement &e, const QString &parent ,
+ QString *value )
+{
+ QDomElement n = e.firstChild().toElement();
+ QString txt;
+ QString com;
+ QString pix;
+ while ( !n.isNull() ) {
+ if ( n.tagName() == "property" ) {
+ QString attrib = n.attribute( "name" );
+ QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() );
+ if ( attrib == "text" ) {
+ txt = v.toString();
+ com = getComment( n );
+ } else if ( attrib == "pixmap" ) {
+ pix = v.toString();
+ if ( !pix.isEmpty() ) {
+ if ( pixmapLoaderFunction.isEmpty() ) {
+ pix.prepend( "self." );
+ } else {
+ pix.prepend( pixmapLoaderFunction + "( " + QString( externPixmaps ? "\"" : "self." ) );
+ pix.append( QString( externPixmaps ? "\"" : "" ) + ")" );
+ }
+ }
+ }
+ }
+ n = n.nextSibling().toElement();
+ }
+
+ if ( value )
+ *value = trcall( txt, com );
+
+ if ( pix.isEmpty() )
+ return parent + ".insertItem(" + trcall( txt, com ) + ")";
+
+ return parent + ".insertItem(" + pix + "," + trcall( txt, com ) + ")";
+}
+
+/*!
+ Creates implementation of an iconview item tag.
+*/
+
+QString Uic::createIconViewItemImpl( const QDomElement &e, const QString &parent )
+{
+ QDomElement n = e.firstChild().toElement();
+ QString txt;
+ QString com;
+ QString pix;
+ while ( !n.isNull() ) {
+ if ( n.tagName() == "property" ) {
+ QString attrib = n.attribute( "name" );
+ QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() );
+ if ( attrib == "text" ) {
+ txt = v.toString();
+ com = getComment( n );
+ } else if ( attrib == "pixmap" ) {
+ pix = v.toString();
+ if ( !pix.isEmpty() ) {
+ if ( pixmapLoaderFunction.isEmpty() ) {
+ pix.prepend( "self." );
+ } else {
+ pix.prepend( pixmapLoaderFunction + "( " + QString( externPixmaps ? "\"" : "self." ) );
+ pix.append( QString( externPixmaps ? "\"" : "" ) + ")" );
+ }
+ }
+ }
+ }
+ n = n.nextSibling().toElement();
+ }
+
+ if ( pix.isEmpty() )
+ return "QIconViewItem(" + parent + "," + trcall( txt, com ) + ")";
+ else
+ return "QIconViewItem(" + parent + "," + trcall( txt, com ) + "," + pix + ")";
+}
+
+/*!
+ Creates implementation of an listview item tag.
+*/
+
+QString Uic::createListViewItemImpl( const QDomElement &e, const QString &parent,
+ const QString &parentItem )
+{
+ QString s;
+
+ QDomElement n = e.firstChild().toElement();
+
+ bool hasChildren = e.elementsByTagName( "item" ).count() > 0;
+ QString item;
+
+ if ( hasChildren ) {
+ item = registerObject( "item" );
+ } else {
+ item = "item";
+ item_used = TRUE;
+ }
+ s = trindent + item + " = ";
+
+ if ( !parentItem.isEmpty() )
+ s += "QListViewItem(" + parentItem + "," + lastItem + ")\n";
+ else
+ s += "QListViewItem(" + parent + "," + lastItem + ")\n";
+
+ QStringList texts;
+ QStringList pixmaps;
+ while ( !n.isNull() ) {
+ if ( n.tagName() == "property" ) {
+ QString attrib = n.attribute("name");
+ QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() );
+ if ( attrib == "text" )
+ texts << v.toString();
+ else if ( attrib == "pixmap" ) {
+ QString pix = v.toString();
+ if ( !pix.isEmpty() ) {
+ if ( pixmapLoaderFunction.isEmpty() ) {
+ pix.prepend( "self." );
+ } else {
+ pix.prepend( pixmapLoaderFunction + "( " + QString( externPixmaps ? "\"" : "self." ) );
+ pix.append( QString( externPixmaps ? "\"" : "" ) + ")" );
+ }
+ }
+ pixmaps << pix;
+ }
+ } else if ( n.tagName() == "item" ) {
+ s += trindent + item + ".setOpen(1)\n";
+ s += createListViewItemImpl( n, parent, item );
+ }
+ n = n.nextSibling().toElement();
+ }
+
+ for ( int i = 0; i < (int)texts.count(); ++i ) {
+ if ( !texts[ i ].isEmpty() )
+ s += trindent + item + ".setText(" + QString::number( i ) + "," + trcall( texts[ i ] ) + ")\n";
+ if ( !pixmaps[ i ].isEmpty() )
+ s += trindent + item + ".setPixmap(" + QString::number( i ) + "," + pixmaps[ i ] + ")\n";
+ }
+
+ lastItem = item;
+ return s;
+}
+
+/*!
+ Creates implementation of an listview column tag.
+*/
+
+QString Uic::createListViewColumnImpl( const QDomElement &e, const QString &parent,
+ QString *value )
+{
+ QDomElement n = e.firstChild().toElement();
+ QString txt;
+ QString com;
+ QString pix;
+ bool clickable = FALSE, resizable = FALSE;
+ while ( !n.isNull() ) {
+ if ( n.tagName() == "property" ) {
+ QString attrib = n.attribute("name");
+ QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() );
+ if ( attrib == "text" ) {
+ txt = v.toString();
+ com = getComment( n );
+ } else if ( attrib == "pixmap" ) {
+ pix = v.toString();
+ if ( !pix.isEmpty() ) {
+ if ( pixmapLoaderFunction.isEmpty() ) {
+ pix.prepend( "self." );
+ } else {
+ pix.prepend( pixmapLoaderFunction + "( " + QString( externPixmaps ? "\"" : "self." ) );
+ pix.append( QString( externPixmaps ? "\"" : "" ) + ")" );
+ }
+ }
+ } else if ( attrib == "clickable" )
+ clickable = v.toBool();
+ else if ( attrib == "resizable" || attrib == "resizeable" )
+ resizable = v.toBool();
+ }
+ n = n.nextSibling().toElement();
+ }
+
+ if ( value )
+ *value = trcall( txt, com );
+
+ QString s;
+ s = indent + parent + ".addColumn(" + trcall( txt, com ) + ")\n";
+ if ( !pix.isEmpty() )
+ s += indent + parent + ".header().setLabel(" + parent + ".header().count() - 1,QIconSet(" + pix + ")," + trcall( txt, com ) + ")\n";
+ if ( !clickable )
+ s += indent + parent + ".header().setClickEnabled(0," + parent + ".header().count() - 1)\n";
+ if ( !resizable )
+ s += indent + parent + ".header().setResizeEnabled(0," + parent + ".header().count() - 1)\n";
+ return s;
+}
+
+QString Uic::createTableRowColumnImpl( const QDomElement &e, const QString &parent,
+ QString *value )
+{
+ QString objClass = getClassName( e.parentNode().toElement() );
+ QDomElement n = e.firstChild().toElement();
+ QString txt;
+ QString com;
+ QString pix;
+ QString field;
+ bool isRow = e.tagName() == "row";
+ while ( !n.isNull() ) {
+ if ( n.tagName() == "property" ) {
+ QString attrib = n.attribute("name");
+ QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() );
+ if ( attrib == "text" ) {
+ txt = v.toString();
+ com = getComment( n );
+ } else if ( attrib == "pixmap" ) {
+ pix = v.toString();
+ if ( !pix.isEmpty() ) {
+ if ( pixmapLoaderFunction.isEmpty() ) {
+ pix.prepend( "self." );
+ } else {
+ pix.prepend( pixmapLoaderFunction + "( " + QString( externPixmaps ? "\"" : "self." ) );
+ pix.append( QString( externPixmaps ? "\"" : "" ) + ")" );
+ }
+ }
+ } else if ( attrib == "field" )
+ field = v.toString();
+ }
+ n = n.nextSibling().toElement();
+ }
+
+ if ( value )
+ *value = trcall( txt, com );
+
+ // ### This generated code sucks! We have to set the number of
+ // rows/cols before and then only do setLabel/()
+ // ### careful, though, since QDataTable has an API which makes this code pretty good
+
+ QString s;
+ if ( isRow ) {
+ s = indent + parent + ".setNumRows(" + parent + ".numRows() + 1)\n";
+ if ( pix.isEmpty() )
+ s += indent + parent + ".verticalHeader().setLabel(" + parent + ".numRows() - 1,"
+ + trcall( txt, com ) + ")\n";
+ else
+ s += indent + parent + ".verticalHeader().setLabel(" + parent + ".numRows() - 1,QIconSet("
+ + pix + ")," + trcall( txt, com ) + ")\n";
+ } else {
+ if ( objClass == "QTable" ) {
+ s = indent + parent + ".setNumCols(" + parent + ".numCols() + 1)\n";
+ if ( pix.isEmpty() )
+ s += indent + parent + ".horizontalHeader().setLabel(" + parent + ".numCols() - 1,"
+ + trcall( txt, com ) + ")\n";
+ else
+ s += indent + parent + ".horizontalHeader().setLabel(" + parent + ".numCols() - 1,QIconSet("
+ + pix + ")," + trcall( txt, com ) + ")\n";
+ } else if ( objClass == "QDataTable" ) {
+ if ( !txt.isEmpty() && !field.isEmpty() ) {
+ if ( pix.isEmpty() )
+ out << indent << parent << ".addColumn(" << fixString( field ) << "," << trcall( txt, com ) << ")" << endl;
+ else
+ out << indent << parent << ".addColumn(" << fixString( field ) << "," << trcall( txt, com ) << ",QIconSet(" << pix << "))" << endl;
+ }
+ }
+ }
+ return s;
+}
+
+/*!
+ Creates the implementation of a layout tag. Called from createObjectImpl().
+ */
+QString Uic::createLayoutImpl( const QDomElement &e, const QString& parentClass, const QString& parent, const QString& layout )
+{
+ QDomElement n;
+ QString objClass, objName;
+ objClass = e.tagName();
+
+ QString qlayout = "QVBoxLayout";
+ if ( objClass == "hbox" )
+ qlayout = "QHBoxLayout";
+ else if ( objClass == "grid" )
+ qlayout = "QGridLayout";
+
+ bool isGrid = e.tagName() == "grid" ;
+ objName = registerObject( getLayoutName( e ) );
+ layoutObjects += objName;
+
+ QString margin = DomTool::readProperty( e, "margin", defMargin ).toString();
+ QString spacing = DomTool::readProperty( e, "spacing", defSpacing ).toString();
+ QString resizeMode = DomTool::readProperty( e, "resizeMode", QString::null ).toString();
+
+ QString optcells;
+ if ( isGrid )
+ optcells = "1,1,";
+ if ( (parentClass == "QGroupBox" || parentClass == "QButtonGroup") && layout.isEmpty() ) {
+ // special case for group box
+ out << indent << parent << ".setColumnLayout(0,Qt.Vertical)" << endl;
+ out << indent << parent << ".layout().setSpacing(" << spacing << ")" << endl;
+ out << indent << parent << ".layout().setMargin(" << margin << ")" << endl;
+ out << indent << objName << " = " << qlayout << "(" << parent << ".layout())" << endl;
+ out << indent << objName << ".setAlignment(Qt.AlignTop)" << endl;
+ } else {
+ out << indent << objName << " = " << qlayout << "(";
+ if ( layout.isEmpty() )
+ out << parent;
+ else {
+ out << "None";
+ if ( !DomTool::hasProperty( e, "margin" ) )
+ margin = "0";
+ }
+ out << "," << optcells << margin << "," << spacing << ",\"" << objName << "\")" << endl;
+ }
+ if ( !resizeMode.isEmpty() )
+ out << indent << objName << ".setResizeMode(QLayout." << resizeMode << ")" << endl;
+
+ if ( !isGrid ) {
+ for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
+ if ( n.tagName() == "spacer" ) {
+ QString child = createSpacerImpl( n, parentClass, parent, objName );
+ out << indent << objName << ".addItem(" << child << ")" << endl;
+ } else if ( tags.contains( n.tagName() ) ) {
+ QString child = createObjectImpl( n, parentClass, parent, objName );
+ if ( isLayout( child ) )
+ out << indent << objName << ".addLayout(" << child << ")" << endl;
+ else
+ out << indent << objName << ".addWidget(" << child << ")" << endl;
+ }
+ }
+ } else {
+ for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
+ QDomElement ae = n;
+ int row = ae.attribute( "row" ).toInt();
+ int col = ae.attribute( "column" ).toInt();
+ int rowspan = ae.attribute( "rowspan" ).toInt();
+ int colspan = ae.attribute( "colspan" ).toInt();
+ if ( rowspan < 1 )
+ rowspan = 1;
+ if ( colspan < 1 )
+ colspan = 1;
+ if ( n.tagName() == "spacer" ) {
+ QString child = createSpacerImpl( n, parentClass, parent, objName );
+ if ( rowspan * colspan != 1 )
+ out << indent << objName << ".addMultiCell(" << child << ","
+ << row << "," << ( row + rowspan - 1 ) << "," << col << "," << ( col + colspan - 1 ) << ")" << endl;
+ else
+ out << indent << objName << ".addItem(" << child << ","
+ << row << "," << col << ")" << endl;
+ } else if ( tags.contains( n.tagName() ) ) {
+ QString child = createObjectImpl( n, parentClass, parent, objName );
+ out << endl;
+ QString o = "Widget";
+ if ( isLayout( child ) )
+ o = "Layout";
+ if ( rowspan * colspan != 1 )
+ out << indent << objName << ".addMultiCell" << o << "(" << child << ","
+ << row << "," << ( row + rowspan - 1 ) << "," << col << "," << ( col + colspan - 1 ) << ")" << endl;
+ else
+ out << indent << objName << ".add" << o << "(" << child << ","
+ << row << "," << col << ")" << endl;
+ }
+ }
+ }
+
+ return objName;
+}
+
+
+
+QString Uic::createSpacerImpl( const QDomElement &e, const QString& /*parentClass*/, const QString& /*parent*/, const QString& /*layout*/)
+{
+ QDomElement n;
+ QString objClass, objName;
+ objClass = e.tagName();
+ objName = registerObject( getObjectName( e ) );
+
+ QSize size = DomTool::readProperty( e, "sizeHint", QSize( 0, 0 ) ).toSize();
+ QString sizeType = DomTool::readProperty( e, "sizeType", "Expanding" ).toString();
+ bool isVspacer = DomTool::readProperty( e, "orientation", "Horizontal" ) == "Vertical";
+
+ if ( sizeType != "Expanding" && sizeType != "MinimumExpanding" &&
+ DomTool::hasProperty( e, "geometry" ) ) { // compatibility Qt 2.2
+ QRect geom = DomTool::readProperty( e, "geometry", QRect(0,0,0,0) ).toRect();
+ size = geom.size();
+ }
+
+ if ( isVspacer )
+ out << indent << objName << " = QSpacerItem("
+ << size.width() << "," << size.height()
+ << ",QSizePolicy.Minimum,QSizePolicy." << sizeType << ")" << endl;
+ else
+ out << indent << objName << " = QSpacerItem("
+ << size.width() << "," << size.height()
+ << ",QSizePolicy." << sizeType << ",QSizePolicy.Minimum)" << endl;
+
+ return objName;
+}
+
+static const char* const ColorRole[] = {
+ "Foreground", "Button", "Light", "Midlight", "Dark", "Mid",
+ "Text", "BrightText", "ButtonText", "Base", "Background", "Shadow",
+ "Highlight", "HighlightedText", "Link", "LinkVisited", 0
+};
+
+
+/*!
+ Creates a colorgroup with name \a name from the color group \a cg
+ */
+void Uic::createColorGroupImpl( const QString& name, const QDomElement& e )
+{
+ QColorGroup cg;
+ int r = -1;
+ QDomElement n = e.firstChild().toElement();
+ QString color;
+ while ( !n.isNull() ) {
+ if ( n.tagName() == "color" ) {
+ r++;
+ QColor col = DomTool::readColor( n );
+ color = "QColor(%1,%2,%3)";
+ color = color.arg( col.red() ).arg( col.green() ).arg( col.blue() );
+ if ( col == white )
+ color = "Qt.white";
+ else if ( col == black )
+ color = "Qt.black";
+ if ( n.nextSibling().toElement().tagName() != "pixmap" ) {
+ out << indent << name << ".setColor(QColorGroup." << ColorRole[r] << "," << color << ")" << endl;
+ }
+ } else if ( n.tagName() == "pixmap" ) {
+ QString pixmap = n.firstChild().toText().data();
+ if ( pixmapLoaderFunction.isEmpty() ) {
+ pixmap.prepend( "self." );
+ } else {
+ pixmap.prepend( pixmapLoaderFunction + "(" + QString( externPixmaps ? "\"" : "self." ) );
+ pixmap.append( QString( externPixmaps ? "\"" : "" ) + ")" );
+ }
+ out << indent << name << ".setBrush(QColorGroup."
+ << ColorRole[r] << ",QBrush(" << color << "," << pixmap << "))" << endl;
+ }
+ n = n.nextSibling().toElement();
+ }
+}
+
+/*!
+ Auxiliary function to load a color group. The colorgroup must not
+ contain pixmaps.
+ */
+QColorGroup Uic::loadColorGroup( const QDomElement &e )
+{
+ QColorGroup cg;
+ int r = -1;
+ QDomElement n = e.firstChild().toElement();
+ QColor col;
+ while ( !n.isNull() ) {
+ if ( n.tagName() == "color" ) {
+ r++;
+ cg.setColor( (QColorGroup::ColorRole)r, (col = DomTool::readColor( n ) ) );
+ }
+ n = n.nextSibling().toElement();
+ }
+ return cg;
+}
+
+/*! Returns TRUE if the widget properties specify that it belongs to
+ the database \a connection and \a table.
+*/
+
+bool Uic::isWidgetInTable( const QDomElement& e, const QString& connection, const QString& table )
+{
+ QString conn = getDatabaseInfo( e, "connection" );
+ QString tab = getDatabaseInfo( e, "table" );
+ if ( conn == connection && tab == table )
+ return TRUE;
+ return FALSE;
+}
+
+/*!
+ Registers all database connections, cursors and forms.
+*/
+
+void Uic::registerDatabases( const QDomElement& e )
+{
+ QDomElement n;
+ QDomNodeList nl;
+ int i;
+ nl = e.parentNode().toElement().elementsByTagName( "widget" );
+ for ( i = 0; i < (int) nl.length(); ++i ) {
+ n = nl.item(i).toElement();
+ QString conn = getDatabaseInfo( n, "connection" );
+ QString tab = getDatabaseInfo( n, "table" );
+ QString fld = getDatabaseInfo( n, "field" );
+ if ( !conn.isNull() ) {
+ dbConnections += conn;
+ if ( !tab.isNull() ) {
+ dbCursors[conn] += tab;
+ if ( !fld.isNull() )
+ dbForms[conn] += tab;
+ }
+ }
+ }
+}
+
+/*!
+ Registers an object with name \a name.
+
+ The returned name is a valid variable identifier, as similar to \a
+ name as possible and guaranteed to be unique within the form.
+
+ \sa registeredName(), isObjectRegistered()
+ */
+QString Uic::registerObject( const QString& name )
+{
+ if ( objectNames.isEmpty() ) {
+ // some temporary variables we need
+ objectNames += "img";
+ objectNames += "item";
+ objectNames += "cg";
+ objectNames += "pal";
+ }
+
+ QString result = name;
+ int i;
+ while ( ( i = result.find(' ' )) != -1 ) {
+ result[i] = '_';
+ }
+
+ if ( objectNames.contains( result ) ) {
+ int i = 2;
+ while ( objectNames.contains( result + "_" + QString::number(i) ) )
+ i++;
+ result += "_";
+ result += QString::number(i);
+ }
+ objectNames += result;
+ objectMapper.insert( name, result );
+ return result;
+}
+
+/*!
+ Returns the registered name for the original name \a name
+ or \a name if \a name wasn't registered.
+
+ \sa registerObject(), isObjectRegistered()
+ */
+QString Uic::registeredName( const QString& name )
+{
+ if ( !objectMapper.contains( name ) )
+ return name;
+ return objectMapper[name];
+}
+
+/*!
+ Returns whether the object \a name was registered yet or not.
+ */
+bool Uic::isObjectRegistered( const QString& name )
+{
+ return objectMapper.contains( name );
+}
+
+
+/*!
+ Unifies the entries in stringlist \a list. Should really be a QStringList feature.
+ */
+QStringList Uic::unique( const QStringList& list )
+{
+ if ( list.isEmpty() )
+ return list;
+
+ QStringList result;
+ for ( QStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
+ if ( !result.contains(*it) )
+ result += *it;
+ }
+ return result;
+}
+
+
+
+/*!
+ Creates an instance of class \a objClass, with parent \a parent and name \a objName
+ */
+QString Uic::createObjectInstance( const QString& objClass, const QString& parent, const QString& objName )
+{
+
+ if ( objClass.mid( 1 ) == "ComboBox" ) {
+ return objClass + "(0," + parent + ",\"" + objName + "\")";
+ }
+ return objClass + "(" + parent + ",\"" + objName + "\")";
+}
+
+bool Uic::isLayout( const QString& name ) const
+{
+ return layoutObjects.contains( name );
+}
diff --git a/python/pyqt/pyuic3/uic.h b/python/pyqt/pyuic3/uic.h
new file mode 100644
index 00000000..ea52ac34
--- /dev/null
+++ b/python/pyqt/pyuic3/uic.h
@@ -0,0 +1,183 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (c) 2001 Phil Thompson <phil@river-bank.demon.co.uk>
+**
+** This file is part of Qt Designer.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#ifndef UIC_H
+#define UIC_H
+#include <qdom.h>
+#include <qstring.h>
+#include <qstringlist.h>
+#include <qmap.h>
+#include <qtextstream.h>
+#include <qpalette.h>
+#include <qvariant.h>
+
+
+#define PYQT_VERSION "3.17.2"
+
+
+class PyIndent
+{
+public:
+ PyIndent() : tabStop(4), current(0) {calc();}
+
+ void setTabStop(uint n) {tabStop = n; calc();}
+ uint setIndent(uint i) {uint old = current; current = i; calc(); return old;}
+ void operator++() {++current; calc();}
+ void operator--() {--current; calc();}
+ operator QString() {return indstr;}
+
+private:
+ uint tabStop;
+ uint current;
+ QString indstr;
+
+ void calc();
+};
+
+
+class Uic : public Qt
+{
+public:
+ Uic( const QString &fn, const char *outputFn, QTextStream& out,
+ QDomDocument doc, bool subcl, const QString &trm,
+ const QString& subclname, QString &uicClass );
+
+ static void setIndent(const PyIndent &pyind) {indent = pyind; trindent = pyind;}
+
+ void createFormImpl( const QDomElement &e );
+
+ void createSubImpl( const QDomElement &e, const QString& subclname );
+
+ void createActionImpl( const QDomElement& e, const QString &parent );
+ void createToolbarImpl( const QDomElement &e, const QString &parentClass, const QString &parent );
+ void createMenuBarImpl( const QDomElement &e, const QString &parentClass, const QString &parent );
+ void createPopupMenuImpl( const QDomElement &e, const QString &parentClass, const QString &parent );
+ QString createObjectImpl( const QDomElement &e, const QString& parentClass, const QString& parent, const QString& layout = QString::null );
+ QString createLayoutImpl( const QDomElement &e, const QString& parentClass, const QString& parent, const QString& layout = QString::null );
+ QString createObjectInstance( const QString& objClass, const QString& parent, const QString& objName );
+ QString createSpacerImpl( const QDomElement &e, const QString& parentClass, const QString& parent, const QString& layout = QString::null );
+ void createExclusiveProperty( const QDomElement & e, const QString& exclusiveProp );
+ QString createListBoxItemImpl( const QDomElement &e, const QString &parent, QString *value = 0 );
+ QString createIconViewItemImpl( const QDomElement &e, const QString &parent );
+ QString createListViewColumnImpl( const QDomElement &e, const QString &parent, QString *value = 0 );
+ QString createTableRowColumnImpl( const QDomElement &e, const QString &parent, QString *value = 0 );
+ QString createListViewItemImpl( const QDomElement &e, const QString &parent,
+ const QString &parentItem );
+ void createColorGroupImpl( const QString& cg, const QDomElement& e );
+ QColorGroup loadColorGroup( const QDomElement &e );
+
+ QDomElement getObjectProperty( const QDomElement& e, const QString& name );
+ QString getPixmapLoaderFunction( const QDomElement& e );
+ QString getFormClassName( const QDomElement& e );
+ QString getClassName( const QDomElement& e );
+ QString getObjectName( const QDomElement& e );
+ QString getLayoutName( const QDomElement& e );
+ QString getInclude( const QString& className );
+
+ QString setObjectProperty( const QString& objClass, const QString& obj, const QString &prop, const QDomElement &e, bool stdset );
+
+ QString registerObject( const QString& name );
+ QString registeredName( const QString& name );
+ bool isObjectRegistered( const QString& name );
+ QStringList unique( const QStringList& );
+
+ QString trcall( const QString& sourceText, const QString& comment = "" );
+
+ static void embed( QTextStream& out, const char* project, const QStringList& images );
+
+private:
+ QTextStream& out;
+ QTextOStream trout;
+ QString languageChangeBody;
+ QCString outputFileName;
+ QStringList objectNames;
+ QMap<QString,QString> objectMapper;
+ QStringList tags;
+ QStringList layouts;
+ QString formName;
+ QString lastItem;
+ QString trmacro;
+ static PyIndent indent, trindent;
+
+ struct Buddy
+ {
+ Buddy( const QString& k, const QString& b )
+ : key( k ), buddy( b ) {}
+ Buddy(){} // for valuelist
+ QString key;
+ QString buddy;
+ bool operator==( const Buddy& other ) const
+ { return (key == other.key); }
+ };
+ struct CustomInclude
+ {
+ QString header;
+ QString location;
+ };
+ QValueList<Buddy> buddies;
+
+ QStringList layoutObjects;
+ bool isLayout( const QString& name ) const;
+
+ uint item_used : 1;
+ uint cg_used : 1;
+ uint pal_used : 1;
+ uint stdsetdef : 1;
+ uint externPixmaps : 1;
+
+#if QT_VERSION >= 0x030300
+ QString uiFileVersion;
+#endif
+ QString nameOfClass;
+ QStringList namespaces;
+ QString bareNameOfClass;
+ QString pixmapLoaderFunction;
+
+ void registerDatabases( const QDomElement& e );
+ bool isWidgetInTable( const QDomElement& e, const QString& connection, const QString& table );
+ bool isFrameworkCodeGenerated( const QDomElement& e );
+ QString getDatabaseInfo( const QDomElement& e, const QString& tag );
+ void createFormImpl( const QDomElement& e, const QString& form, const QString& connection, const QString& table );
+ void writeFunctionsSubImpl( const QStringList &fuLst, const QStringList &typLst, const QStringList &specLst,
+ const QString &subClass, const QString &descr );
+ QStringList dbConnections;
+ QMap< QString, QStringList > dbCursors;
+ QMap< QString, QStringList > dbForms;
+
+ static bool isMainWindow;
+ static QString mkBool( bool b );
+ static QString mkBool( const QString& s );
+ bool toBool( const QString& s );
+ static QString fixString( const QString &str, bool encode = FALSE );
+ static bool onlyAscii;
+ static QString mkStdSet( const QString& prop );
+ static QString getComment( const QDomNode& n );
+ QVariant defSpacing, defMargin;
+ QString fileName;
+ bool writeFunctImpl;
+
+ void pySlot(QStringList::ConstIterator &it);
+
+ QString pyCode;
+ bool pyNeedTr, pyNeedTrUtf8;
+};
+
+#endif
diff --git a/python/pyqt/pyuic3/widgetdatabase.cpp b/python/pyqt/pyuic3/widgetdatabase.cpp
new file mode 100644
index 00000000..6c447d5b
--- /dev/null
+++ b/python/pyqt/pyuic3/widgetdatabase.cpp
@@ -0,0 +1,953 @@
+/**********************************************************************
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
+**
+** This file is part of Qt Designer.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
+** licenses may use this file in accordance with the Qt Commercial License
+** Agreement provided with the Software.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
+** information about Qt Commercial License Agreements.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#include "widgetdatabase.h"
+#include "widgetinterface.h"
+
+#include <qapplication.h>
+#define NO_STATIC_COLORS
+#include <globaldefs.h>
+#include <qstrlist.h>
+#include <qdict.h>
+#include <qfile.h>
+#include <qtextstream.h>
+#include <qcleanuphandler.h>
+#include <qfeatures.h>
+
+#include <stdlib.h>
+
+const int dbsize = 300;
+const int dbcustom = 200;
+const int dbdictsize = 211;
+static WidgetDatabaseRecord* db[ dbsize ];
+static QDict<int> *className2Id = 0;
+static int dbcount = 0;
+static int dbcustomcount = 200;
+static QStrList *wGroups;
+static QStrList *invisibleGroups;
+static bool whatsThisLoaded = FALSE;
+static QPluginManager<WidgetInterface> *widgetPluginManager = 0;
+static bool plugins_set_up = FALSE;
+static bool was_in_setup = FALSE;
+
+QCleanupHandler<QPluginManager<WidgetInterface> > cleanup_manager;
+
+WidgetDatabaseRecord::WidgetDatabaseRecord()
+{
+ isForm = FALSE;
+ isContainer = FALSE;
+ icon = 0;
+ nameCounter = 0;
+ isCommon = FALSE;
+ isPlugin = FALSE;
+}
+
+WidgetDatabaseRecord::~WidgetDatabaseRecord()
+{
+ delete icon;
+}
+
+
+/*!
+ \class WidgetDatabase widgetdatabase.h
+ \brief The WidgetDatabase class holds information about widgets
+
+ The WidgetDatabase holds information about widgets like toolTip(),
+ iconSet(), ... It works Id-based, so all access functions take the
+ widget id as parameter. To get the id for a widget (classname), use
+ idFromClassName().
+
+ All access functions are static. Having multiple widgetdatabases in
+ one application doesn't make sense anyway and so you don't need more
+ than an instance of the widgetdatabase.
+
+ For creating widgets, layouts, etc. see WidgetFactory.
+*/
+
+/*!
+ Creates widget database. Does nothing.
+*/
+
+WidgetDatabase::WidgetDatabase()
+{
+}
+
+/*! Sets up the widget database. If the static widgetdatabase already
+ exists, the functions returns immediately.
+*/
+
+void WidgetDatabase::setupDataBase( int id )
+{
+ was_in_setup = TRUE;
+#ifndef UIC
+ Q_UNUSED( id )
+ if ( dbcount )
+ return;
+#else
+ if ( dbcount && id != -2 )
+ return;
+ if ( dbcount && !plugins_set_up ) {
+ setupPlugins();
+ return;
+ }
+ if ( dbcount && plugins_set_up)
+ return;
+#endif
+
+ wGroups = new QStrList;
+ invisibleGroups = new QStrList;
+ invisibleGroups->append( "Forms" );
+ invisibleGroups->append( "Temp" );
+ className2Id = new QDict<int>( dbdictsize );
+ className2Id->setAutoDelete( TRUE );
+
+ WidgetDatabaseRecord *r = 0;
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_pushbutton.png";
+ r->name = "QPushButton";
+ r->group = widgetGroup( "Buttons" );
+ r->toolTip = "Push Button";
+ r->isCommon = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_toolbutton.png";
+ r->name = "QToolButton";
+ r->group = widgetGroup( "Buttons" );
+ r->toolTip = "Tool Button";
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_radiobutton.png";
+ r->name = "QRadioButton";
+ r->group = widgetGroup( "Buttons" );
+ r->toolTip = "Radio Button";
+ r->isCommon = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_checkbox.png";
+ r->name = "QCheckBox";
+ r->group = widgetGroup( "Buttons" );
+ r->toolTip = "Check Box";
+ r->isCommon = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_groupbox.png";
+ r->name = "QGroupBox";
+ r->group = widgetGroup( "Containers" );
+ r->toolTip = "Group Box";
+ r->isContainer = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_buttongroup.png";
+ r->name = "QButtonGroup";
+ r->group = widgetGroup( "Containers" );
+ r->toolTip = "Button Group";
+ r->isContainer = TRUE;
+ r->isCommon = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_frame.png";
+ r->name = "QFrame";
+ r->group = widgetGroup( "Containers" );
+ r->toolTip = "Frame";
+ r->isContainer = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_tabwidget.png";
+ r->name = "QTabWidget";
+ r->group = widgetGroup( "Containers" );
+ r->toolTip = "Tabwidget";
+ r->isContainer = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_widgetstack.png";
+ r->name = "QWidgetStack";
+ r->group = widgetGroup( "Containers" );
+ r->toolTip = "Widget Stack";
+ r->isContainer = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_toolbox.png";
+ r->name = "QToolBox";
+ r->group = widgetGroup( "Containers" );
+ r->toolTip = "Tool Box";
+ r->isContainer = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_listbox.png";
+ r->name = "QListBox";
+ r->group = widgetGroup( "Views" );
+ r->toolTip = "List Box";
+ r->isCommon = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_listview.png";
+ r->name = "QListView";
+ r->group = widgetGroup( "Views" );
+ r->toolTip = "List View";
+
+ append( r );
+
+#if !defined(QT_NO_ICONVIEW) || defined(UIC)
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_iconview.png";
+ r->name = "QIconView";
+ r->group = widgetGroup( "Views" );
+ r->toolTip = "Icon View";
+
+ append( r );
+#endif
+
+#if !defined(QT_NO_TABLE)
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_table.png";
+ r->name = "QTable";
+ r->group = widgetGroup( "Views" );
+ r->toolTip = "Table";
+
+ append( r );
+#endif
+
+#if !defined(QT_NO_SQL)
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_datatable.png";
+ r->includeFile = "qdatatable.h";
+ r->name = "QDataTable";
+ r->group = widgetGroup( "Database" );
+ r->toolTip = "Data Table";
+
+ append( r );
+#endif
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_lineedit.png";
+ r->name = "QLineEdit";
+ r->group = widgetGroup( "Input" );
+ r->toolTip = "Line Edit";
+ r->isCommon = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_spinbox.png";
+ r->name = "QSpinBox";
+ r->group = widgetGroup( "Input" );
+ r->toolTip = "Spin Box";
+ r->isCommon = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_dateedit.png";
+ r->name = "QDateEdit";
+ r->group = widgetGroup( "Input" );
+ r->toolTip = "Date Edit";
+ r->includeFile = "qdatetimeedit.h";
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_timeedit.png";
+ r->name = "QTimeEdit";
+ r->group = widgetGroup( "Input" );
+ r->toolTip = "Time Edit";
+ r->includeFile = "qdatetimeedit.h";
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_datetimeedit.png";
+ r->name = "QDateTimeEdit";
+ r->group = widgetGroup( "Input" );
+ r->toolTip = "Date-Time Edit";
+ r->includeFile = "qdatetimeedit.h";
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_multilineedit.png";
+ r->name = "QMultiLineEdit";
+ r->group = widgetGroup( "Temp" );
+ r->toolTip = "Multi Line Edit";
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_richtextedit.png";
+ r->name = "QTextEdit";
+ r->group = widgetGroup( "Input" );
+ r->toolTip = "Rich Text Edit";
+ r->isCommon = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_combobox.png";
+ r->name = "QComboBox";
+ r->group = widgetGroup( "Input" );
+ r->toolTip = "Combo Box";
+ r->isCommon = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_slider.png";
+ r->name = "QSlider";
+ r->group = widgetGroup( "Input" );
+ r->toolTip = "Slider";
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_scrollbar.png";
+ r->name = "QScrollBar";
+ r->group = widgetGroup( "Input" );
+ r->toolTip = "Scrollbar";
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_dial.png";
+ r->name = "QDial";
+ r->group = widgetGroup( "Input" );
+ r->toolTip = "Dial";
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_label.png";
+ r->name = "QLabel";
+ r->group = widgetGroup( "Temp" );
+ r->toolTip = "Label";
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_label.png";
+ r->name = "TextLabel";
+ r->group = widgetGroup( "Display" );
+ r->toolTip = "Text Label";
+ r->whatsThis = "The Text Label provides a widget to display static text.";
+ r->isCommon = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_pixlabel.png";
+ r->name = "PixmapLabel";
+ r->group = widgetGroup( "Display" );
+ r->toolTip = "Pixmap Label";
+ r->whatsThis = "The Pixmap Label provides a widget to display pixmaps.";
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_lcdnumber.png";
+ r->name = "QLCDNumber";
+ r->group = widgetGroup( "Display" );
+ r->toolTip = "LCD Number";
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_line.png";
+ r->name = "Line";
+ r->group = widgetGroup( "Display" );
+ r->toolTip = "Line";
+ r->includeFile = "qframe.h";
+ r->whatsThis = "The Line widget provides horizontal and vertical lines.";
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_progress.png";
+ r->name = "QProgressBar";
+ r->group = widgetGroup( "Display" );
+ r->toolTip = "Progress Bar";
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_textview.png";
+ r->name = "QTextView";
+ r->group = widgetGroup( "Temp" );
+ r->toolTip = "Text View";
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_textbrowser.png";
+ r->name = "QTextBrowser";
+ r->group = widgetGroup( "Display" );
+ r->toolTip = "Text Browser";
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_spacer.png";
+ r->name = "Spacer";
+ r->group = widgetGroup( "Temp" );
+ r->toolTip = "Spacer";
+ r->whatsThis = "The Spacer provides horizontal and vertical spacing to be able to manipulate the behaviour of layouts.";
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->name = "QWidget";
+ r->isForm = TRUE;
+ r->group = widgetGroup( "Forms" );
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->name = "QDialog";
+ r->group = widgetGroup( "Forms" );
+ r->isForm = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->name = "QWizard";
+ r->group = widgetGroup( "Forms" );
+ r->isContainer = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->name = "QDesignerWizard";
+ r->group = widgetGroup( "Forms" );
+ r->isContainer = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->name = "QLayoutWidget";
+ r->group = widgetGroup( "Temp" );
+ r->includeFile = "";
+ r->isContainer = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->name = "QSplitter";
+ r->group = widgetGroup( "Temp" );
+ r->includeFile = "qsplitter.h";
+ r->isContainer = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_tabwidget.png";
+ r->name = "QDesignerTabWidget";
+ r->group = widgetGroup( "Temp" );
+ r->isContainer = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_tabwidget.png";
+ r->name = "QDesignerWidget";
+ r->group = widgetGroup( "Temp" );
+ r->isContainer = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "designer_tabwidget.png";
+ r->name = "QDesignerDialog";
+ r->group = widgetGroup( "Temp" );
+ r->isContainer = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "";
+ r->name = "QMainWindow";
+ r->includeFile = "qmainwindow.h";
+ r->group = widgetGroup( "Temp" );
+ r->isContainer = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "";
+ r->name = "QDesignerAction";
+ r->includeFile = "qaction.h";
+ r->group = widgetGroup( "Temp" );
+ r->isContainer = FALSE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "";
+ r->name = "QDesignerActionGroup";
+ r->includeFile = "qaction.h";
+ r->group = widgetGroup( "Temp" );
+ r->isContainer = FALSE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "";
+ r->name = "QScrollView";
+ r->includeFile = "qscrollview.h";
+ r->group = widgetGroup( "Temp" );
+ r->isContainer = TRUE;
+
+ append( r );
+
+#ifndef QT_NO_SQL
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "";
+ r->name = "QDataBrowser";
+ r->includeFile = "qdatabrowser.h";
+ r->group = widgetGroup( "Database" );
+ r->toolTip = "Data Browser";
+ r->iconSet = "designer_databrowser.png";
+ r->isContainer = TRUE;
+
+ append( r );
+
+ r = new WidgetDatabaseRecord;
+ r->iconSet = "";
+ r->name = "QDataView";
+ r->includeFile = "qdataview.h";
+ r->group = widgetGroup( "Database" );
+ r->toolTip = "Data View";
+ r->iconSet = "designer_dataview.png";
+ r->isContainer = TRUE;
+
+ append( r );
+#endif
+
+#ifndef UIC
+ setupPlugins();
+#endif
+}
+
+void WidgetDatabase::setupPlugins()
+{
+ if ( plugins_set_up )
+ return;
+ plugins_set_up = TRUE;
+ QStringList widgets = widgetManager()->featureList();
+ for ( QStringList::Iterator it = widgets.begin(); it != widgets.end(); ++it ) {
+ if ( hasWidget( *it ) )
+ continue;
+ WidgetDatabaseRecord *r = new WidgetDatabaseRecord;
+ WidgetInterface *iface = 0;
+ widgetManager()->queryInterface( *it, &iface );
+ if ( !iface )
+ continue;
+
+#ifndef UIC
+ QIconSet icon = iface->iconSet( *it );
+ if ( !icon.pixmap().isNull() )
+ r->icon = new QIconSet( icon );
+#endif
+ QString grp = iface->group( *it );
+ if ( grp.isEmpty() )
+ grp = "3rd party widgets";
+ r->group = widgetGroup( grp );
+ r->toolTip = iface->toolTip( *it );
+ r->whatsThis = iface->whatsThis( *it );
+ r->includeFile = iface->includeFile( *it );
+ r->isContainer = iface->isContainer( *it );
+ r->name = *it;
+ r->isPlugin = TRUE;
+ append( r );
+ iface->release();
+ }
+}
+
+/*!
+ Returns the number of elements in the widget database.
+*/
+
+int WidgetDatabase::count()
+{
+ setupDataBase( -1 );
+ return dbcount;
+}
+
+/*!
+ Returns the id at which the ids of custom widgets start.
+*/
+
+int WidgetDatabase::startCustom()
+{
+ setupDataBase( -1 );
+ return dbcustom;
+}
+
+/*!
+ Returns the iconset which represents the class registered as \a id.
+*/
+
+QIconSet WidgetDatabase::iconSet( int id )
+{
+ setupDataBase( id );
+ WidgetDatabaseRecord *r = at( id );
+ if ( !r )
+ return QIconSet();
+#if !defined(UIC) && !defined(RESOURCE)
+ if ( !r->icon ) {
+ if ( r->iconSet.isEmpty() )
+ return QIconSet();
+ QPixmap pix = QPixmap::fromMimeSource( r->iconSet );
+ if ( pix.isNull() )
+ pix = QPixmap( r->iconSet );
+ r->icon = new QIconSet( pix );
+ }
+ return *r->icon;
+#else
+ return QIconSet();
+#endif
+}
+
+/*!
+ Returns the classname of the widget which is registered as \a id.
+*/
+
+QString WidgetDatabase::className( int id )
+{
+ setupDataBase( id );
+ WidgetDatabaseRecord *r = at( id );
+ if ( !r )
+ return QString::null;
+ return r->name;
+}
+
+/*!
+ Returns the group the widget registered as \a id belongs to.
+*/
+
+QString WidgetDatabase::group( int id )
+{
+ setupDataBase( id );
+ WidgetDatabaseRecord *r = at( id );
+ if ( !r )
+ return QString::null;
+ return r->group;
+}
+
+/*!
+ Returns the tooltip text of the widget which is registered as \a id.
+*/
+
+QString WidgetDatabase::toolTip( int id )
+{
+ setupDataBase( id );
+ WidgetDatabaseRecord *r = at( id );
+ if ( !r )
+ return QString::null;
+ return r->toolTip;
+}
+
+/*!
+ Returns the what's this? text of the widget which is registered as \a id.
+*/
+
+QString WidgetDatabase::whatsThis( int id )
+{
+ setupDataBase( id );
+ WidgetDatabaseRecord *r = at( id );
+ if ( !r )
+ return QString::null;
+ return r->whatsThis;
+}
+
+/*!
+ Returns the include file if the widget which is registered as \a id.
+*/
+
+QString WidgetDatabase::includeFile( int id )
+{
+ setupDataBase( id );
+ WidgetDatabaseRecord *r = at( id );
+ if ( !r )
+ return QString::null;
+ if ( r->includeFile.isNull() )
+ return r->name.lower() + ".h";
+ return r->includeFile;
+}
+
+/*! Returns whether the widget registered as \a id is a form.
+*/
+bool WidgetDatabase::isForm( int id )
+{
+ setupDataBase( id );
+ WidgetDatabaseRecord *r = at( id );
+ if ( !r )
+ return FALSE;
+ return r->isForm;
+}
+
+/*! Returns whether the widget registered as \a id can have children.
+*/
+
+bool WidgetDatabase::isContainer( int id )
+{
+ setupDataBase( id );
+ WidgetDatabaseRecord *r = at( id );
+ if ( !r )
+ return FALSE;
+ return r->isContainer || r->isForm;
+}
+
+bool WidgetDatabase::isCommon( int id )
+{
+ setupDataBase( id );
+ WidgetDatabaseRecord *r = at( id );
+ if ( !r )
+ return FALSE;
+ return r->isCommon;
+}
+
+QString WidgetDatabase::createWidgetName( int id )
+{
+ setupDataBase( id );
+ QString n = className( id );
+ if ( n == "QLayoutWidget" )
+ n = "Layout";
+ if ( n[ 0 ] == 'Q' && n[ 1 ].lower() != n[ 1 ] )
+ n = n.mid( 1 );
+ int colonColon = n.findRev( "::" );
+ if ( colonColon != -1 )
+ n = n.mid( colonColon + 2 );
+
+ WidgetDatabaseRecord *r = at( id );
+ if ( !r )
+ return n;
+ n += QString::number( ++r->nameCounter );
+ n[0] = n[0].lower();
+ return n;
+}
+
+/*! Returns the id for \a name or -1 if \a name is unknown.
+ */
+int WidgetDatabase::idFromClassName( const QString &name )
+{
+ setupDataBase( -1 );
+ if ( name.isEmpty() )
+ return 0;
+ int *i = className2Id->find( name );
+ if ( i )
+ return *i;
+ if ( name == "FormWindow" )
+ return idFromClassName( "QLayoutWidget" );
+#ifdef UIC
+ setupDataBase( -2 );
+ i = className2Id->find( name );
+ if ( i )
+ return *i;
+#endif
+ return -1;
+}
+
+bool WidgetDatabase::hasWidget( const QString &name )
+{
+ return className2Id->find( name ) != 0;
+}
+
+WidgetDatabaseRecord *WidgetDatabase::at( int index )
+{
+ if ( index < 0 )
+ return 0;
+ if ( index >= dbcustom && index < dbcustomcount )
+ return db[ index ];
+ if ( index < dbcount )
+ return db[ index ];
+ return 0;
+}
+
+void WidgetDatabase::insert( int index, WidgetDatabaseRecord *r )
+{
+ if ( index < 0 || index >= dbsize )
+ return;
+ db[ index ] = r;
+ className2Id->insert( r->name, new int( index ) );
+ if ( index < dbcustom )
+ dbcount = QMAX( dbcount, index );
+}
+
+void WidgetDatabase::append( WidgetDatabaseRecord *r )
+{
+ if ( !was_in_setup )
+ setupDataBase( -1 );
+ insert( dbcount++, r );
+}
+
+QString WidgetDatabase::widgetGroup( const QString &g )
+{
+ if ( wGroups->find( g ) == -1 )
+ wGroups->append( g );
+ return g;
+}
+
+bool WidgetDatabase::isGroupEmpty( const QString &grp )
+{
+ WidgetDatabaseRecord *r = 0;
+ for ( int i = 0; i < dbcount; ++i ) {
+ if ( !( r = db[ i ] ) )
+ continue;
+ if ( r->group == grp )
+ return FALSE;
+ }
+ return TRUE;
+}
+
+QString WidgetDatabase::widgetGroup( int i )
+{
+ setupDataBase( -1 );
+ if ( i >= 0 && i < (int)wGroups->count() )
+ return wGroups->at( i );
+ return QString::null;
+}
+
+int WidgetDatabase::numWidgetGroups()
+{
+ setupDataBase( -1 );
+ return wGroups->count();
+}
+
+bool WidgetDatabase::isGroupVisible( const QString &g )
+{
+ setupDataBase( -1 );
+ return invisibleGroups->find( g ) == -1;
+}
+
+int WidgetDatabase::addCustomWidget( WidgetDatabaseRecord *r )
+{
+ insert( dbcustomcount++, r );
+ return dbcustomcount - 1;
+}
+
+void WidgetDatabase::customWidgetClassNameChanged( const QString &oldName,
+ const QString &newName )
+{
+ int id = idFromClassName( oldName );
+ if ( id == -1 )
+ return;
+ WidgetDatabaseRecord *r = db[ id ];
+ r->name = newName;
+ className2Id->remove( oldName );
+ className2Id->insert( newName, new int( id ) );
+}
+
+bool WidgetDatabase::isCustomWidget( int id )
+{
+ if ( id >= dbcustom && id < dbcustomcount )
+ return TRUE;
+ return FALSE;
+}
+
+bool WidgetDatabase::isCustomPluginWidget( int id )
+{
+ setupDataBase( id );
+ WidgetDatabaseRecord *r = at( id );
+ if ( !r )
+ return FALSE;
+ return r->isPlugin;
+}
+
+bool WidgetDatabase::isWhatsThisLoaded()
+{
+ return whatsThisLoaded;
+}
+
+void WidgetDatabase::loadWhatsThis( const QString &docPath )
+{
+ QString whatsthisFile = docPath + "/whatsthis";
+ QFile f( whatsthisFile );
+ if ( !f.open( IO_ReadOnly ) )
+ return;
+ QTextStream ts( &f );
+ while ( !ts.atEnd() ) {
+ QString s = ts.readLine();
+ QStringList l = QStringList::split( " | ", s );
+ int id = idFromClassName( l[ 1 ] );
+ WidgetDatabaseRecord *r = at( id );
+ if ( r )
+ r->whatsThis = l[ 0 ];
+ }
+ whatsThisLoaded = TRUE;
+}
+
+
+// ### Qt 3.1: make these publically accessible via QWidgetDatabase API
+#if defined(UIC)
+bool dbnounload = FALSE;
+QStringList *dbpaths = 0;
+#else
+extern QString *qwf_plugin_dir;
+#endif
+
+
+QPluginManager<WidgetInterface> *widgetManager()
+{
+ if ( !widgetPluginManager ) {
+ QString pluginDir = "/designer";
+#if !defined(UIC)
+ if ( qwf_plugin_dir )
+ pluginDir = *qwf_plugin_dir;
+#endif
+ widgetPluginManager = new QPluginManager<WidgetInterface>( IID_Widget, QApplication::libraryPaths(), pluginDir );
+ cleanup_manager.add( &widgetPluginManager );
+#if defined(UIC)
+ if ( dbnounload )
+ widgetPluginManager->setAutoUnload( FALSE );
+ if ( dbpaths ) {
+ QStringList::ConstIterator it = dbpaths->begin();
+ for ( ; it != dbpaths->end(); ++it )
+ widgetPluginManager->addLibraryPath( *it );
+ }
+#endif
+ }
+ return widgetPluginManager;
+}
diff --git a/python/pyqt/pyuic3/widgetdatabase.h b/python/pyqt/pyuic3/widgetdatabase.h
new file mode 100644
index 00000000..b44ef885
--- /dev/null
+++ b/python/pyqt/pyuic3/widgetdatabase.h
@@ -0,0 +1,96 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+**
+** This file is part of Qt Designer.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
+** licenses may use this file in accordance with the Qt Commercial License
+** Agreement provided with the Software.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
+** information about Qt Commercial License Agreements.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#ifndef WIDGETDATABASE_H
+#define WIDGETDATABASE_H
+
+#include <qiconset.h>
+#include <qstring.h>
+#include "widgetinterface.h" // up here for GCC 2.7.* compatibility
+#include <private/qpluginmanager_p.h>
+
+
+extern QPluginManager<WidgetInterface> *widgetManager();
+
+struct WidgetDatabaseRecord
+{
+ WidgetDatabaseRecord();
+ ~WidgetDatabaseRecord();
+ QString iconSet, name, group, toolTip, whatsThis, includeFile;
+ uint isContainer : 1;
+ uint isForm : 1;
+ uint isCommon : 1;
+ uint isPlugin : 1;
+ QIconSet *icon;
+ int nameCounter;
+};
+
+class WidgetDatabase : public Qt
+{
+public:
+ WidgetDatabase();
+ static void setupDataBase( int id );
+ static void setupPlugins();
+
+ static int count();
+ static int startCustom();
+
+ static QIconSet iconSet( int id );
+ static QString className( int id );
+ static QString group( int id );
+ static QString toolTip( int id );
+ static QString whatsThis( int id );
+ static QString includeFile( int id );
+ static bool isForm( int id );
+ static bool isContainer( int id );
+ static bool isCommon( int id );
+
+ static int idFromClassName( const QString &name );
+ static QString createWidgetName( int id );
+
+ static WidgetDatabaseRecord *at( int index );
+ static void insert( int index, WidgetDatabaseRecord *r );
+ static void append( WidgetDatabaseRecord *r );
+
+ static QString widgetGroup( const QString &g );
+ static QString widgetGroup( int i );
+ static int numWidgetGroups();
+ static bool isGroupVisible( const QString &g );
+ static bool isGroupEmpty( const QString &grp );
+
+ static int addCustomWidget( WidgetDatabaseRecord *r );
+ static bool isCustomWidget( int id );
+ static bool isCustomPluginWidget( int id );
+
+ static bool isWhatsThisLoaded();
+ static void loadWhatsThis( const QString &docPath );
+
+ static bool hasWidget( const QString &name );
+ static void customWidgetClassNameChanged( const QString &oldName, const QString &newName );
+
+};
+
+#endif
diff --git a/python/pyqt/pyuic3/widgetinterface.h b/python/pyqt/pyuic3/widgetinterface.h
new file mode 100644
index 00000000..bf6bcd55
--- /dev/null
+++ b/python/pyqt/pyuic3/widgetinterface.h
@@ -0,0 +1,29 @@
+ /**********************************************************************
+** Copyright (C) 2000-2001 Trolltech AS. All rights reserved.
+**
+** This file is part of Qt Designer.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#ifndef WIDGETINTERFACE_H
+#define WIDGETINTERFACE_H
+
+#include <private/qwidgetinterface_p.h>
+
+#define WidgetInterface QWidgetFactoryInterface
+#define IID_Widget IID_QWidgetFactory
+
+#endif