diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-11-29 00:31:00 -0600 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-11-29 00:31:00 -0600 |
commit | b388516ca2691303a076a0764fd40bf7116fe43d (patch) | |
tree | 6f1615d1f12b325f4d1cd9c25d1519303794001a /pyuic2 | |
download | pytqt-b388516ca2691303a076a0764fd40bf7116fe43d.tar.gz pytqt-b388516ca2691303a076a0764fd40bf7116fe43d.zip |
Initial import of python-qt3
Diffstat (limited to 'pyuic2')
-rw-r--r-- | pyuic2/COPYING | 280 | ||||
-rw-r--r-- | pyuic2/domtool.cpp | 260 | ||||
-rw-r--r-- | pyuic2/domtool.h | 41 | ||||
-rw-r--r-- | pyuic2/globaldefs.h | 33 | ||||
-rw-r--r-- | pyuic2/pyuic.pro.in | 24 | ||||
-rw-r--r-- | pyuic2/pyuic.sbf | 24 | ||||
-rw-r--r-- | pyuic2/uic.cpp | 1601 | ||||
-rw-r--r-- | pyuic2/uic.h | 133 | ||||
-rw-r--r-- | pyuic2/widgetdatabase.cpp | 640 | ||||
-rw-r--r-- | pyuic2/widgetdatabase.h | 75 |
10 files changed, 3111 insertions, 0 deletions
diff --git a/pyuic2/COPYING b/pyuic2/COPYING new file mode 100644 index 0000000..c7aea18 --- /dev/null +++ b/pyuic2/COPYING @@ -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/pyuic2/domtool.cpp b/pyuic2/domtool.cpp new file mode 100644 index 0000000..2b14ee6 --- /dev/null +++ b/pyuic2/domtool.cpp @@ -0,0 +1,260 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** Copyright (C) 2000, 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 "domtool.h" + +#include <qsizepolicy.h> +#include <qpalette.h> +#include <qcursor.h> +#include <qrect.h> +#include <qsize.h> +#include <qfont.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 ) +{ + 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() == "name" ) { + QString prop = n2.firstChild().toText().data(); + if ( prop == name ) + return elementToVariant( n2.nextSibling().toElement(), defValue ); + } + } + } + return defValue; +} + +/*! + 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" ) { + QDomElement n2 = n.firstChild().toElement(); + if ( n2.tagName() == "name" ) { + QString prop = n2.firstChild().toText().data(); + if ( prop == name ) + return TRUE; + } + } + } + return FALSE; +} + +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" ) { + v = QVariant( e.firstChild().toText().data().toInt() ); + } 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() ); + n3 = n3.nextSibling().toElement(); + } + v = QVariant( sp ); + } else if ( e.tagName() == "cursor" ) { + v = QVariant( QCursor( e.firstChild().toText().data().toInt() ) ); + } + + 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 ) +{ + QDomElement n; + for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { + if ( n.tagName() == "attribute" ) { + QDomElement n2 = n.firstChild().toElement(); + if ( n2.tagName() == "name" ) { + QString prop = n2.firstChild().toText().data(); + if ( prop == name ) + return elementToVariant( n2.nextSibling().toElement(), defValue ); + } + } + } + return defValue; +} + +/*! + 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" ) { + QDomElement n2 = n.firstChild().toElement(); + if ( n2.tagName() == "name" ) { + QString prop = n2.firstChild().toText().data(); + if ( prop == name ) + return TRUE; + } + } + } + return FALSE; +} diff --git a/pyuic2/domtool.h b/pyuic2/domtool.h new file mode 100644 index 0000000..7230bce --- /dev/null +++ b/pyuic2/domtool.h @@ -0,0 +1,41 @@ +/********************************************************************** +** Copyright (C) 2000 Troll Tech AS. All rights reserved. +** Copyright (C) 2000, 2001 Phil Thompson <phil@river-bank.demon.co.uk> +** +** This file is part of Qt GUI Designer. +** +** This file may be distributed under the terms of the GNU General +** Public License version 2 as published by the Free Software +** Foundation and appearing in the file COPYING included in the +** packaging of this file. If you did not get the file, send email +** to info@trolltech.com +** +** The file is provided AS IS with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. +** +**********************************************************************/ + +#ifndef DOMTOOL_H +#define DOMTOOL_H + +#include <qnamespace.h> +#include <qvariant.h> +#include <qdom.h> + + +class DomTool : public Qt +{ +public: + static QVariant readProperty( const QDomElement& e, const QString& name, const QVariant& defValue ); + static bool hasProperty( const QDomElement& e, const QString& name ); + 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 bool hasAttribute( const QDomElement& e, const QString& name ); + static QColor readColor( const QDomElement &e ); + +}; + + +#endif // DOMTOOL_H diff --git a/pyuic2/globaldefs.h b/pyuic2/globaldefs.h new file mode 100644 index 0000000..700f7d2 --- /dev/null +++ b/pyuic2/globaldefs.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 GLOBALDEFS_H +#define GLOBALDEFS_H + +#include <qcolor.h> + +#define BOXLAYOUT_DEFAULT_MARGIN 11 +#define BOXLAYOUT_DEFAULT_SPACING 6 + +static QColor backColor1( 226, 244, 216 ); +static QColor backColor2( 235, 235, 235 ); +static QColor selectedBack( 192, 192, 192 ); + +#endif diff --git a/pyuic2/pyuic.pro.in b/pyuic2/pyuic.pro.in new file mode 100644 index 0000000..8df1513 --- /dev/null +++ b/pyuic2/pyuic.pro.in @@ -0,0 +1,24 @@ +# Copyright (c) 2000, 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 v2. + + +TEMPLATE = app +CONFIG = qt console warn_on release +INCLUDEPATH = @BLX_INCLUDEPATH@ $(QTDIR)/src/3rdparty/zlib +DEFINES = UIC @BLX_DEFINES@ + +DESTDIR = @PYQT_BINDIR@ +TARGET = pyuic + +HEADERS = domtool.h \ + globaldefs.h \ + uic.h \ + widgetdatabase.h + +SOURCES = domtool.cpp \ + uic.cpp \ + widgetdatabase.cpp diff --git a/pyuic2/pyuic.sbf b/pyuic2/pyuic.sbf new file mode 100644 index 0000000..5d480ec --- /dev/null +++ b/pyuic2/pyuic.sbf @@ -0,0 +1,24 @@ +# This is the build file for pyuic for Qt v2. +# +# 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 = uic.cpp widgetdatabase.cpp domtool.cpp +headers = uic.h widgetdatabase.h domtool.h globaldefs.h diff --git a/pyuic2/uic.cpp b/pyuic2/uic.cpp new file mode 100644 index 0000000..19fb079 --- /dev/null +++ b/pyuic2/uic.cpp @@ -0,0 +1,1601 @@ +// Copyright (c) 2000 - 2001 Phil Thompson <phil@river-bank.demon.co.uk> + +/********************************************************************** +** Copyright (C) 2000 Troll Tech AS. All rights reserved. +** +** This file is part of Qt GUI Designer. +** +** This file may be distributed under the terms of the GNU General +** Public License version 2 as published by the Free Software +** Foundation and appearing in the file COPYING included in the +** packaging of this file. If you did not get the file, send email +** to info@trolltech.com +** +** The file is provided AS IS with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. +** +**********************************************************************/ + +#include "uic.h" +#include <qapplication.h> +#include <qfile.h> +#include <qfileinfo.h> +#include <stdio.h> +#include <stdlib.h> +#include <qstringlist.h> +#include <qstrlist.h> +#include <qdatetime.h> +#include <widgetdatabase.h> +#include <domtool.h> +#include <globaldefs.h> +#include <qregexp.h> +#include <zlib.h> + +static QString mkBool( bool b ) +{ + return b? "1" : "0"; +} + +static QString mkBool( const QString& s ) +{ + return mkBool( s == "true" || s == "1" ); +} + +static bool toBool( const QString& s ) +{ + return s == "true" || s.toInt() != 0; +} + + +// fixString is only used in conjunction with tr(). We need to write out the +// string in utf8 and make sure it's converted from utf8 when created. +static QString fixString( const QString &str ) +{ + QString s( str ); + s.replace( QRegExp( "\\\\" ), "\\\\" ); + s.replace( QRegExp( "\"" ), "\\\"" ); + s.replace( QRegExp( "\n" ), "\\n\"\n\"" ); + s.replace( QRegExp( "\r" ), "\\r" ); + + bool onlyAscii = TRUE; + unsigned int i; + for ( i = 0; i < s.length(); i++ ) { + if ( s.at(i).unicode() >= 0x80 ) { + onlyAscii = FALSE; + break; + } + } + if ( onlyAscii ) + s = "\"" + s + "\""; + else + s = "QString.fromUtf8(\"" + s + "\")"; + return s; +} + +static QString 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). + */ + +static QString className; + +Uic::Uic( QTextStream &outStream, QDomDocument doc, const QString &trm ) + : out( outStream ), trmacro( trm ) +{ + item_used = cg_used = pal_used = 0; + + initIndent(); + + layouts << "hbox" << "vbox" << "grid"; + tags = layouts; + tags << "widget"; + + nameOfClass = getClassName( doc.firstChild().toElement() ); + + QDomElement firstWidget = doc.firstChild().firstChild().toElement(); + while ( firstWidget.tagName() != "widget" ) + firstWidget = firstWidget.nextSibling().toElement(); + + if ( nameOfClass.isEmpty() ) + nameOfClass = getObjectName( firstWidget ); + + // This is a hack. + className = nameOfClass; + + createFormImpl( firstWidget ); +} + + +/*! Extracts a class name from \a e + */ +QString Uic::getClassName( 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; + } else if ( n.tagName() == "pixmapfunction" ) { + pixmapLoaderFunction = n.firstChild().toText().data(); + } + } + return cn; +} + +/*! Extracts an object name from \a e. It's stored in the 'name' + property. + */ +QString Uic::getObjectName( const QDomElement& e ) +{ + 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() == "name" && n2.firstChild().toText().data() == "name" ) { + return n2.nextSibling().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 tail = QString::null; + + if (getClassName(p) != "QLayoutWidget") + tail = "Layout"; + + QDomElement n; + for ( n = p.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { + if ( n.tagName() == "property" ) { + QDomElement n2 = n.firstChild().toElement(); + if ( n2.tagName() == "name" && n2.firstChild().toText().data() == "name" ) { + return n2.nextSibling().toElement().firstChild().toText().data() + tail; + } + } + } + return e.tagName(); +} + +QByteArray unzipXPM( QString data, ulong& length ) +{ + char *ba = new char[ 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; + } + if ( length < data.length() * 5 ) + length = data.length() * 5; + QByteArray baunzip( length ); + ::uncompress( (uchar*) baunzip.data(), &length, (uchar*) ba, data.length()/2 ); + return baunzip; +} + + +/*! + Creates an implementation ( cpp-file ) for the form given in \a e + + \sa createFormDecl(), createObjectImpl() + */ +void Uic::createFormImpl( const QDomElement &e ) +{ + QStringList::Iterator it; + QDomElement n; + QDomNodeList nl; + int i; + QString objClass = getClassName( e ); + if ( objClass.isEmpty() ) + return; + QString objName = getObjectName( e ); + + // Handle custom widgets. + for (n = e; !n.isNull(); n = n.nextSibling().toElement()) + { + if (n.tagName() != "customwidgets") + continue; + + QDomElement n2 = n.firstChild().toElement(); + + while (!n2.isNull()) + { + if (n2.tagName() == "customwidget") + { + QDomElement n3 = n2.firstChild().toElement(); + QString cname, header; + + while (!n3.isNull()) + { + if (n3.tagName() == "class") + cname = n3.firstChild().toText().data(); + else if (n3.tagName() == "header") + header = n3.firstChild().toText().data(); + + n3 = n3.nextSibling().toElement(); + } + + if (cname.isEmpty()) + cname = "UnnamedCustomClass"; + + int ext = header.findRev('.'); + + if (ext >= 0) + header.truncate(ext); + + if (header.isEmpty()) + header = cname.lower(); + + out << "from " << header << " import " << cname << endl; + } + + n2 = n2.nextSibling().toElement(); + } + } + + // find out what images are required + QStringList requiredImages; + nl = e.elementsByTagName( "pixmap" ); + for ( int j = 0; j < (int) nl.length(); j++ ) { + requiredImages += nl.item(j).firstChild().toText().data(); + } + + QStringList images; + QStringList xpmImages; + if ( pixmapLoaderFunction.isEmpty() ) { + // 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++ ) { + QDomElement tmp = nl.item(i).firstChild().toElement(); + QString img = registerObject( tmp.firstChild().toText().data() ); + if ( !requiredImages.contains( img ) ) + continue; + tmp = tmp.nextSibling().toElement(); + QString format = tmp.attribute("format", "PNG" ); + QString data = tmp.firstChild().toText().data(); + + out << endl; + out << endl; + + if ( format == "XPM.GZ" ) { + xpmImages += img; + ulong length = tmp.attribute("length").toULong(); + QByteArray baunzip = unzipXPM( data, length ); + 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 << "]" << endl; + break; + } + + if (ch == '\"') + ch = '\''; + + out << ch; + } + } else { + images += img; + out << indent << img << "_data = \\" << endl; + pushIndent(); + 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; + popIndent(); + } + } + } + } + } + + // register the object and unify its name + objName = registerObject( objName ); + + + // constructor + + out << endl; + out << endl; + out << indent << "class " << nameOfClass << "(" << objClass << "):" << endl; + pushIndent(); + + if ( objClass == "QDialog" || objClass == "QWizard" ) { + out << indent << "def __init__(self,parent = None,name = None,modal = 0,fl = 0):" << endl; + pushIndent(); + out << indent << objClass << ".__init__(self,parent,name,modal,fl)" << endl; + } else if ( objClass == "QWidget" ) { // standard QWidget + out << indent << "def __init__(self,parent = None,name = None,fl = 0):" << endl; + pushIndent(); + out << indent << objClass << ".__init__(self,parent,name,fl)" << endl; + } else { + out << indent << "def __init__(self,parent = None,name = None):" << endl; + pushIndent(); + 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 << (*it) << " = QPixmap()" << endl; + out << indent << (*it) << ".loadFromData(" << (*it) << "_data,'PNG')" << endl; + } + + out << endl; + } + // create pixmaps for all images + if ( !xpmImages.isEmpty() ) { + for ( it = xpmImages.begin(); it != xpmImages.end(); ++it ) { + out << indent << (*it) << " = QPixmap(" << (*it) << "_data)" << endl; + } + + out << endl; + } + + + // set the properties + for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { + if ( n.tagName() == "property" ) { + bool stdset = toBool( n.attribute( "stdset" ) ); + QDomElement n2 = n.firstChild().toElement(); + + if ( n2.tagName() == "name" ) { + QString prop = n2.firstChild().toText().data(); + QString value = setObjectProperty( objClass, QString::null, prop, n2.nextSibling().toElement(), stdset ); + + if ( value.isEmpty() ) + continue; + + if ( prop == "name" ) { + out << indent << "if name == None:" << endl; + pushIndent(); + } + + out << indent; + + if ( prop == "geometry" && n2.nextSibling().toElement().tagName() == "rect") { + QDomElement n3 = n2.nextSibling().toElement().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(); + } + + out << "self.resize(" << w << "," << h << ")" << endl; + } else { + if ( stdset ) + out << "self." << mkStdSet(prop) << "(" << value << ")" << endl; + else + out << "self.setProperty('" << prop << "',QVariant(" << value << "))" << endl; + } + + if (prop == "name") { + popIndent(); + 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 label = DomTool::readAttribute( n, "title", "" ).toString(); + out << indent << "self.addPage(" << page << ","<< trmacro << "(" << fixString( label ) << "))" << 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" ); + } + } + + // Get the list of any user defined slots. + + QStringList userSlots; + + for ( n = e; !n.isNull(); n = n.nextSibling().toElement() ) { + if ( n.tagName() == "connections" ) { + for ( QDomElement n2 = n.firstChild().toElement(); !n2.isNull(); n2 = n2.nextSibling().toElement() ) { + if ( n2.tagName() == "slot" ) { + userSlots += n2.firstChild().toText().data(); + } + } + } + } + + 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; + + sender = registeredName( sender ); + receiver = registeredName( receiver ); + + // translate formwindow name to "self" + if ( sender == objName ) + sender = "self"; + else + sender = "self." + sender; + if ( receiver == objName ) + receiver = "self"; + else + receiver = "self." + receiver; + + // Note that we never use the SLOT() macro in case we have + // custom widgets implemented in Python. + out << indent << "self.connect(" << sender + << ",SIGNAL('" << signal << "'),self." + << slot.left(slot.find('(')) << ")" << 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; + } + + } + + // end of constructor + popIndent(); + + // handle application font changes if required + nl = e.elementsByTagName( "widget" ); + bool needEventHandler = FALSE; + for ( i = 0; i < (int) nl.length(); i++ ) { + if ( DomTool::hasProperty( nl.item(i).toElement() , "font" ) ) { + needEventHandler = TRUE; + break; + } + } + if ( needEventHandler ) { + out << endl; + out << indent << "def event(self,ev):" << endl; + pushIndent(); + out << indent << "ret = " << objClass << ".event(self,ev)" << endl; + out << endl; + out << indent << "if ev.type() == QEvent.ApplicationFontChange:" << endl; + pushIndent(); + + for ( i = 0; i < (int) nl.length(); i++ ) { + n = nl.item(i).toElement(); + if ( DomTool::hasProperty( n, "font" ) ) + createExclusiveProperty( n, "font" ); + } + + out << endl; + popIndent(); + out << indent << "return ret" << endl; + popIndent(); + } + + + // Generate user defined slot hooks. + + for (it = userSlots.begin(); it != userSlots.end(); ++it) { + int astart = (*it).find('('); + + out << endl; + 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 << "):" << endl; + pushIndent(); + out << indent << "print '" << nameOfClass << "." << *it << ": not implemented yet'" << endl; + popIndent(); + } + + popIndent(); +} + + +/*! + Creates an implementation for the object given in \a e. + + Traverses recursively over all children. + + Returns the name of the generated child object. + + \sa createObjectDecl() + */ +QString Uic::createObjectImpl( const QDomElement &e, const QString& parentClass, const QString& parent, const QString& layout ) +{ + + QDomElement n; + QString objClass, objName, fullObjName; + + 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 { + // 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; + } + + lastItem = "None"; + // set the properties and insert items + for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { + if ( n.tagName() == "property" ) { + bool stdset = toBool( n.attribute( "stdset" ) ); + QDomElement n2 = n.firstChild().toElement(); + + if ( n2.tagName() == "name" ) { + QString prop = n2.firstChild().toText().data(); + QString value = setObjectProperty( objClass, objName, prop, n2.nextSibling().toElement(), stdset ); + + if ( value.isEmpty() ) + continue; + if ( prop == "name" ) + continue; + if ( prop == "buddy" && value[0] == '\'' && value[(int)value.length()-1] == '\'' ) { + buddies << Buddy( objName, value.mid(1, value.length() - 2 ) ); + continue; + } + if ( isLine && prop == "orientation" ) { + prop = "frameStyle"; + if ( value.right(10) == "Horizontal" ) + value = "QFrame.HLine | QFrame.Sunken"; + else + value = "QFrame.VLine | QFrame.Sunken"; + } + if ( prop == "buttonGroupId" ) { + if ( parentClass == "QButtonGroup" ) + out << indent << parent << ".insert(" << fullObjName << "," << value << ")" << endl; + continue; + } + if ( prop == "geometry") { + out << indent << fullObjName << ".setGeometry(" << value << ")" << endl; + } else { + if ( stdset ) + out << indent << fullObjName << "." << mkStdSet(prop) << "(" << value << ")" << endl; + else + out << indent << fullObjName << ".setProperty('" << prop << "',QVariant(" << value << "))" << endl; + } + + } + } else if ( n.tagName() == "item" ) { + if ( objClass.mid(1) == "ListBox" ) { + QString s = createListBoxItemImpl( n, fullObjName ); + if ( !s.isEmpty() ) + out << indent << s << endl; + } else if ( objClass.mid(1) == "ComboBox" ) { + QString s = createListBoxItemImpl( n, fullObjName ); + if ( !s.isEmpty() ) + out << indent << s << endl; + } else if ( objClass.mid(1) == "IconView" ) { + QString s = createIconViewItemImpl( n, fullObjName ); + if ( !s.isEmpty() ) + out << indent << s << endl; + } else if ( objClass.mid(1) == "ListView" ) { + QString s = createListViewItemImpl( n, fullObjName, QString::null ); + if ( !s.isEmpty() ) + out << s << endl; + } + } else if ( n.tagName() == "column" ) { + if ( objClass.mid(1) == "ListView" ) { + QString s = createListViewColumnImpl( n, fullObjName ); + if ( !s.isEmpty() ) + out << s; + } + } + } + + // 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 label = DomTool::readAttribute( n, "title", "" ).toString(); + out << indent << fullObjName << ".insertTab(" << page << "," << trmacro << "(" << fixString( label ) << "))" << endl; + } + } + } else { // 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 implementation of an listbox item tag. +*/ + +QString Uic::createListBoxItemImpl( const QDomElement &e, const QString &parent ) +{ + QDomElement n = e.firstChild().toElement(); + QString txt; + QString pix; + while ( !n.isNull() ) { + if ( n.tagName() == "property" ) { + QDomElement n2 = n.firstChild().toElement(); + if ( n2.tagName() == "name" ) { + QString attrib = n2.firstChild().toText().data(); + QVariant v = DomTool::elementToVariant( n2.nextSibling().toElement(), QVariant() ); + if ( attrib == "text" ) + txt = v.toString(); + else if ( attrib == "pixmap" ) { + pix = v.toString(); + if ( !pix.isEmpty() && !pixmapLoaderFunction.isEmpty() ) { + pix.prepend( pixmapLoaderFunction + "(" ); + pix.append( ")" ); + } + } + } + } + n = n.nextSibling().toElement(); + } + + return pix.isEmpty() ? + parent + ".insertItem(" + trmacro + "(" + fixString( txt ) + "))": + parent + ".insertItem(" + pix + "," + trmacro + "(" + fixString( txt ) + "))"; +} + +/*! + Creates implementation of an iconview item tag. +*/ + +QString Uic::createIconViewItemImpl( const QDomElement &e, const QString &parent ) +{ + QDomElement n = e.firstChild().toElement(); + QString txt; + QString pix; + while ( !n.isNull() ) { + if ( n.tagName() == "property" ) { + QDomElement n2 = n.firstChild().toElement(); + if ( n2.tagName() == "name" ) { + QString attrib = n2.firstChild().toText().data(); + QVariant v = DomTool::elementToVariant( n2.nextSibling().toElement(), QVariant() ); + if ( attrib == "text" ) + txt = v.toString(); + else if ( attrib == "pixmap" ) { + pix = v.toString(); + if ( !pix.isEmpty() && !pixmapLoaderFunction.isEmpty() ) { + pix.prepend( pixmapLoaderFunction + "( " ); + pix.append( " )" ); + } + } + } + } + n = n.nextSibling().toElement(); + } + + if ( pix.isEmpty() ) + return "QIconViewItem(" + parent + "," + trmacro + "(" + fixString( txt ) + "))"; + return "QIconViewItem(" + parent + "," + trmacro + "(" + fixString( txt ) + ")," + 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" ); + s = indent + item + " = "; + } else { + item = "item"; + if ( item_used ) + s = indent + item + " = "; + else + s = indent + item + " = "; + item_used = TRUE; + } + + if ( !parentItem.isEmpty() ) + s += "QListViewItem(" + parentItem + "," + lastItem + ")\n"; + else + s += "QListViewItem(" + parent + "," + lastItem + ")\n"; + + QStringList textes; + QStringList pixmaps; + while ( !n.isNull() ) { + if ( n.tagName() == "property" ) { + QDomElement n2 = n.firstChild().toElement(); + if ( n2.tagName() == "name" ) { + QString attrib = n2.firstChild().toText().data(); + QVariant v = DomTool::elementToVariant( n2.nextSibling().toElement(), QVariant() ); + if ( attrib == "text" ) + textes << v.toString(); + else if ( attrib == "pixmap" ) { + QString pix = v.toString(); + if ( !pix.isEmpty() && !pixmapLoaderFunction.isEmpty() ) { + pix.prepend( pixmapLoaderFunction + "( " ); + pix.append( " )" ); + } + pixmaps << pix; + } + } + } else if ( n.tagName() == "item" ) { + s += indent + item + ".setOpen(1)\n"; + s += createListViewItemImpl( n, parent, item ); + } + n = n.nextSibling().toElement(); + } + + for ( int i = 0; i < (int)textes.count(); ++i ) { + if ( !textes[ i ].isEmpty() ) + s += indent + item + ".setText(" + QString::number( i ) + "," + trmacro + "(" + fixString( textes[ i ] ) + "))\n"; + if ( !pixmaps[ i ].isEmpty() ) + s += indent + 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 ) +{ + QDomElement n = e.firstChild().toElement(); + QString txt; + QString pix; + bool clickable = FALSE, resizeable = FALSE; + while ( !n.isNull() ) { + if ( n.tagName() == "property" ) { + QDomElement n2 = n.firstChild().toElement(); + if ( n2.tagName() == "name" ) { + QString attrib = n2.firstChild().toText().data(); + QVariant v = DomTool::elementToVariant( n2.nextSibling().toElement(), QVariant() ); + if ( attrib == "text" ) + txt = v.toString(); + else if ( attrib == "pixmap" ) { + pix = v.toString(); + if ( !pix.isEmpty() && !pixmapLoaderFunction.isEmpty() ) { + pix.prepend( pixmapLoaderFunction + "( " ); + pix.append( " )" ); + } + } else if ( attrib == "clickable" ) + clickable = v.toBool(); + else if ( attrib == "resizeable" ) + resizeable = v.toBool(); + } + } + n = n.nextSibling().toElement(); + } + + QString s; + s = indent + parent + ".addColumn(" + trmacro + "(" + fixString( txt ) + "))\n"; + if ( !pix.isEmpty() ) + s += indent + parent + ".header().setLabel(" + parent + ".header().count() - 1," + pix + "," + trmacro + "(" + fixString( txt ) + "))\n"; + if ( !clickable ) + s += indent + parent + ".header().setClickEnabled(0," + parent + ".header().count() - 1)\n"; + if ( !resizeable ) + s += indent + parent + ".header().setResizeEnabled(0," + parent + ".header().count() - 1)\n"; + + 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; + int margin = DomTool::readProperty( e, "margin", BOXLAYOUT_DEFAULT_MARGIN ).toInt(); + int spacing = DomTool::readProperty( e, "spacing", BOXLAYOUT_DEFAULT_SPACING ).toInt(); + + 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(0)" << endl; + out << indent << parent << ".layout().setMargin(0)" << endl; + out << indent << objName << " = " << qlayout << "(" << parent << ".layout())" << endl; + out << indent << objName << ".setAlignment(Qt.AlignTop)" << endl; + } else { + if ( layout.isEmpty() ) + out << indent << objName << " = " << qlayout << "(" << parent << ")" << endl; + else + out << indent << objName << " = " << qlayout << "()" << endl; + } + + out << indent << objName << ".setSpacing(" << spacing << ")" << endl; + out << indent << objName << ".setMargin(" << margin << ")" << 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( "spacer" ); + + 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; +} + +/*! + 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 ( objClass.isEmpty() ) + return; + for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { + if ( n.tagName() == "property" ) { + bool stdset = toBool( n.attribute( "stdset" ) ); + QDomElement n2 = n.firstChild().toElement(); + if ( n2.tagName() == "name" ) { + QString prop = n2.firstChild().toText().data(); + if ( prop != exclusiveProp ) + continue; + QString value = setObjectProperty( objClass, objName, prop, n2.nextSibling().toElement(), stdset ); + if ( value.isEmpty() ) + continue; + out << indent << objName << ".setProperty('" << prop << "',QVariant(" << value << "))" << endl; + } + } + } + +} + + +const char* const ColorRole[] = { + "Foreground", "Button", "Light", "Midlight", "Dark", "Mid", + "Text", "BrightText", "ButtonText", "Base", "Background", "Shadow", + "Highlight", "HighlightedText", 0 +}; + + +/*! + Attention: this function has to be in sync with Resource::setWidgetProperty(). If you change one, change both. + */ +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 fontname = "f"; + if ( !obj.isEmpty() ) { + fontname = obj + "_font"; + out << indent << fontname << " = QFont(self." << obj << ".font())" << endl; + } else { + 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" ) { + if ( prop == "toolTip" ) { + if ( !obj.isEmpty() ) + out << indent << "QToolTip.add(self." << obj << "," + trmacro + "(" << fixString( e.firstChild().toText().data() ) << "))" << endl; + else + out << indent << "QToolTip.add(self," + trmacro + "(" << fixString( e.firstChild().toText().data() ) << "))" << endl; + } else if ( prop == "whatsThis" ) { + if ( !obj.isEmpty() ) + out << indent << "QWhatsThis.add(self." << obj << "," << trmacro << "(" << fixString( e.firstChild().toText().data() ) << "))" << endl; + else + out << indent << "QWhatsThis.add(self," << trmacro << "(" << fixString( e.firstChild().toText().data() ) << "))" << endl; + } else { + v = trmacro + "(%1)"; + v = v.arg( fixString( e.firstChild().toText().data() ) ); + } + } 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 = "%1,0"; + v = v.arg( mkBool( e.firstChild().toText().data() ) ); + } else if ( e.tagName() == "pixmap" ) { + v = e.firstChild().toText().data(); + if ( !pixmapLoaderFunction.isEmpty() ) { + v.prepend( pixmapLoaderFunction + "( " ); + v.append( " )" ); + } + } else if ( e.tagName() == "iconset" ) { + v = "QIconSet(%1)"; + v = v.arg( e.firstChild().toText().data() ); + } 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 of WithMode enum in 3.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 = ""; + for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { + v += objClass + "." + *it; + if ( it != lst.fromLast() ) + v += " | "; + } + } 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() ); + n3 = n3.nextSibling().toElement(); + } + QString tmp; + if ( !obj.isEmpty() ) + tmp = "self." + obj; + else + tmp = "self"; + v = "QSizePolicy(%1,%2," + tmp + ".sizePolicy().hasHeightForWidth())"; + v = v.arg( (int)sp.horData() ).arg( (int)sp.verData() ); + } 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() ); + } + return v; +} + + + +/*! + 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( pixmapLoaderFunction + "(" ); + pixmap.append( ")" ); + } + 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; +} + + + +/*! + 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 ) +{ + QStringList result; + if (list.isEmpty() ) + return result; + QStringList l = list; + l.sort(); + result += l.first(); + for ( QStringList::Iterator it = l.begin(); it != l.end(); ++it ) { + if ( *it != result.last() ) + 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 ); +} + + +#if defined(BLACKADDER) +#include "ba.h" + +int BA::compilePython(const QString &fileName,const QString &outputFile, + const QString &trmacro,bool execCode) +{ +#else +int main( int argc, char * argv[] ) +{ + const char *error = 0; + QString fileName; + QString outputFile; + QString trmacro; + bool execCode = FALSE; + + 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 == "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 == "x" ) { + execCode = TRUE; + } + } else { + if (!fileName.isEmpty()) // can handle only one file + error = "Too many input files specified"; + else + fileName = argv[n]; + } + } + + if ( argc < 2 || error || fileName.isEmpty() ) { + fprintf( stderr, "PyQt user interface compiler\n" ); + if ( error ) + fprintf( stderr, "pyuic: %s\n", error ); + + fprintf( stderr, "Usage: %s [options] <uifile>\n" + "\nGenerate PyQt implementation:\n" + " %s [options] <uifile>\n" + "Options:\n" + "\t-o file Write output to file rather than stdout\n" + "\t-tr func Use func(...) rather than tr(...) for i18n\n" + "\t-x Generate extra code to test the class\n" + , argv[0], argv[0]); + exit( 1 ); + } +#endif + + QFile file( fileName ); + if ( !file.open( IO_ReadOnly ) ) + qFatal( "pyuic: Could not open file '%s' ", (const char *)fileName ); + + QFile fileOut; + if (!outputFile.isEmpty()) { + fileOut.setName( outputFile ); + if (!fileOut.open( IO_WriteOnly ) ) + qFatal( "pyuic: Could not open output file '%s'", (const char *)outputFile ); + } else { + fileOut.open( IO_WriteOnly, stdout ); + } + QTextStream out( &fileOut ); + out.setEncoding( QTextStream::UnicodeUTF8 ); + + QDomDocument doc; + if ( !doc.setContent( &file ) ) + qFatal( "pyuic: Failed to parse %s\n", (const char *)fileName ); + + out << "# Form implementation generated from reading ui file '" << fileName << "'" << endl; + out << "#" << endl; + out << "# Created: " << QDateTime::currentDateTime().toString() << endl; + out << "# by: The Python 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 (execCode) + out << "import sys" << endl; + + out << "from qt import *" << endl; + + Uic( out, doc, trmacro.isEmpty() ? QString("self.tr") : trmacro ); + + if (execCode) { + out << endl; + out << endl; + out << "if __name__ == '__main__':" << endl; + out << " a = QApplication(sys.argv)" << endl; + out << " QObject.connect(a,SIGNAL('lastWindowClosed()'),a,SLOT('quit()'))" << endl; + out << " w = " << className << "()" << endl; + out << " a.setMainWidget(w)" << endl; + out << " w.show()" << endl; + out << " a.exec_loop()" << endl; + } + + return 0; +} diff --git a/pyuic2/uic.h b/pyuic2/uic.h new file mode 100644 index 0000000..c3fdde3 --- /dev/null +++ b/pyuic2/uic.h @@ -0,0 +1,133 @@ +/********************************************************************** +** Copyright (C) 2000 Troll Tech AS. All rights reserved. +** Copyright (C) 2000, 2001 Phil Thompson <phil@river-bank.demon.co.uk> +** +** This file is part of Qt GUI Designer. +** +** This file may be distributed under the terms of the GNU General +** Public License version 2 as published by the Free Software +** Foundation and appearing in the file COPYING included in the +** packaging of this file. If you did not get the file, send email +** to info@trolltech.com +** +** The file is provided AS IS with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. +** +**********************************************************************/ + +#ifndef UIC_H +#define UIC_H + +#include <qnamespace.h> +#include <qdom.h> +#include <qstring.h> +#include <qstringlist.h> +#include <qmap.h> +#include <qtextstream.h> +#include <qcolor.h> + + +#define PYQT_VERSION "3.18.1" + + +class Uic : public Qt +{ +public: + Uic( QTextStream& out, QDomDocument doc, const QString &trm ); + + void createFormImpl( const QDomElement &e ); + + 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 createIconViewItemImpl( const QDomElement &e, const QString &parent ); + QString createListViewColumnImpl( const QDomElement &e, const QString &parent ); + QString createListViewItemImpl( const QDomElement &e, const QString &parent, + const QString &parentItem ); + void createColorGroupImpl( const QString& cg, const QDomElement& e ); + QColorGroup loadColorGroup( const QDomElement &e ); + + QString getClassName( const QDomElement& e ); + QString getObjectName( const QDomElement& e ); + QString getLayoutName( const QDomElement& e ); + + 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& ); + +private: + void pushIndent() + { + ++nrindents; + setIndent(); + } + + void popIndent() + { + --nrindents; + setIndent(); + } + + void setIndent() + { + indent = ""; + + for (int i = 0; i < nrindents; ++i) + indent += newindent; + } + + void initIndent() + { + newindent = " "; + indent = ""; + nrindents = 0; + } + + QString indent, newindent; + int nrindents; + + QTextStream& out; + QStringList objectNames; + QMap<QString,QString> objectMapper; + QStringList tags; + QStringList layouts; + QString formName; + QString lastItem; + QString trmacro; + + 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; + + QString pixmapLoaderFunction; + QString nameOfClass; +}; + +#endif diff --git a/pyuic2/widgetdatabase.cpp b/pyuic2/widgetdatabase.cpp new file mode 100644 index 0000000..0733fce --- /dev/null +++ b/pyuic2/widgetdatabase.cpp @@ -0,0 +1,640 @@ +/********************************************************************** +** 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 <qvariant.h> // HP-UX compiler needs this here + +#include "widgetdatabase.h" + +#if defined(DESIGNER) +#include "../designer/formwindow.h" +#include "../designer/pixmapchooser.h" +#endif + +//#include "../integration/kdevelop/kdewidgets.h" + +#include <globaldefs.h> +#include <qstrlist.h> +#include <qdict.h> +#include <qfile.h> +#include <qtextstream.h> + +#include <qmodules.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; + + +WidgetDatabaseRecord::WidgetDatabaseRecord() +{ + isContainer = FALSE; + icon = 0; + nameCounter = 0; +} + +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. +*/ + +/*! + Creatse widget database. Does nothing +*/ + +WidgetDatabase::WidgetDatabase() +{ +} + +/*! Sets up the widget database. If the static widgetdatabase already + exists, the functions returns immediately. +*/ + +void WidgetDatabase::setupDataBase() +{ + if ( dbcount ) + return; + + 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 = "pushbutton.xpm"; + r->name = "QPushButton"; + r->group = widgetGroup( "Buttons" ); + r->toolTip = "Push Button"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "toolbutton.xpm"; + r->name = "QToolButton"; + r->group = widgetGroup( "Buttons" ); + r->toolTip = "Tool Button"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "radiobutton.xpm"; + r->name = "QRadioButton"; + r->group = widgetGroup( "Buttons" ); + r->toolTip = "Radio Button"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "checkbox.xpm"; + r->name = "QCheckBox"; + r->group = widgetGroup( "Buttons" ); + r->toolTip = "Check Box"; + + + + + append( r ); + r = new WidgetDatabaseRecord; + r->iconSet = "groupbox.xpm"; + r->name = "QGroupBox"; + r->group = widgetGroup( "Containers" ); + r->toolTip = "Group Box"; + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "buttongroup.xpm"; + r->name = "QButtonGroup"; + r->group = widgetGroup( "Containers" ); + r->toolTip = "Button Group"; + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "frame.xpm"; + r->name = "QFrame"; + r->group = widgetGroup( "Containers" ); + r->toolTip = "Frame"; + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "tabwidget.xpm"; + r->name = "QTabWidget"; + r->group = widgetGroup( "Containers" ); + r->toolTip = "Tabwidget"; + r->isContainer = TRUE; + + append( r ); + + + r = new WidgetDatabaseRecord; + r->iconSet = "listbox.xpm"; + r->name = "QListBox"; + r->group = widgetGroup( "Views" ); + r->toolTip = "List Box"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "listview.xpm"; + r->name = "QListView"; + r->group = widgetGroup( "Views" ); + r->toolTip = "List View"; + + append( r ); + +#if defined(QT_MODULE_ICONVIEW) || defined(UIC) + r = new WidgetDatabaseRecord; + r->iconSet = "iconview.xpm"; + r->name = "QIconView"; + r->group = widgetGroup( "Views" ); + r->toolTip = "Icon View"; + + append( r ); +#endif + +#if defined(QT_MODULE_TABLE) + r = new WidgetDatabaseRecord; + r->iconSet = "table.xpm"; + r->name = "QTable"; + r->group = widgetGroup( "Views" ); + r->toolTip = "Table"; + + append( r ); +#endif + + + r = new WidgetDatabaseRecord; + r->iconSet = "lineedit.xpm"; + r->name = "QLineEdit"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Line Edit"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "spinbox.xpm"; + r->name = "QSpinBox"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Spin Box"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "multilineedit.xpm"; + r->name = "QMultiLineEdit"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Multi Line Edit"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "combobox.xpm"; + r->name = "QComboBox"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Combo Box"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "slider.xpm"; + r->name = "QSlider"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Slider"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "dial.xpm"; + r->name = "QDial"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Dial"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "label.xpm"; + r->name = "QLabel"; + r->group = widgetGroup( "Temp" ); + r->toolTip = "Label"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "label.xpm"; + r->name = "TextLabel"; + r->group = widgetGroup( "Display" ); + r->toolTip = "Text Label"; + r->whatsThis = "The Text Label provides a widget to display static text."; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "pixlabel.xpm"; + 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 = "lcdnumber.xpm"; + r->name = "QLCDNumber"; + r->group = widgetGroup( "Display" ); + r->toolTip = "LCD Number"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "line.xpm"; + 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 = "progress.xpm"; + r->name = "QProgressBar"; + r->group = widgetGroup( "Display" ); + r->toolTip = "Progress Bar"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "textview.xpm"; + r->name = "QTextView"; + r->group = widgetGroup( "Display" ); + r->toolTip = "Text View"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "textbrowser.xpm"; + r->name = "QTextBrowser"; + r->group = widgetGroup( "Display" ); + r->toolTip = "Text Browser"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "spacer.xpm"; + 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 bahviour of layouts."; + + append( r ); + + r = new WidgetDatabaseRecord; + r->name = "QWidget"; + r->isContainer = FALSE; + r->group = widgetGroup( "Forms" ); + + append( r ); + + r = new WidgetDatabaseRecord; + r->name = "QDialog"; + r->group = widgetGroup( "Forms" ); + r->isContainer = FALSE; + + 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->iconSet = "tabwidget.xpm"; + r->name = "QDesignerTabWidget"; + r->group = widgetGroup( "Temp" ); + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "tabwidget.xpm"; + r->name = "QDesignerWidget"; + r->group = widgetGroup( "Temp" ); + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "tabwidget.xpm"; + r->name = "QDesignerDialog"; + r->group = widgetGroup( "Temp" ); + r->isContainer = TRUE; + + append( r ); + +// qt_init_kde_widget_database(); +} + +/*! + Returns the number of elements in the widget database. +*/ + +int WidgetDatabase::count() +{ + setupDataBase(); + return dbcount; +} + +/*! + Returns the id at which the ids of custom widgets start. +*/ + +int WidgetDatabase::startCustom() +{ + setupDataBase(); + return dbcustom; +} + +/*! Returns the iconset which represents the class registered as \a + id. +*/ + +QIconSet WidgetDatabase::iconSet( int id ) +{ + setupDataBase(); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return QIconSet(); +#if defined(DESIGNER) + if ( !r->icon ) + r->icon = new QIconSet( PixmapChooser::loadPixmap( r->iconSet, PixmapChooser::Small ), + PixmapChooser::loadPixmap( r->iconSet, PixmapChooser::Large ) ); + return *r->icon; +#endif + + return QIconSet(); +} + +/*! + Returns the classname of the widget which is registered as \a id. +*/ + +QString WidgetDatabase::className( int id ) +{ + setupDataBase(); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return QString::null; + return r->name; +} + +/*! + Returns the group to which the widget registered as \a id belongs. +*/ + +QString WidgetDatabase::group( int id ) +{ + setupDataBase(); + 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(); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return QString::null; + return r->toolTip; +} + +/*! Returns the what's this? test of the widget which is registered + as \a id. +*/ + +QString WidgetDatabase::whatsThis( int id ) +{ + setupDataBase(); + 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(); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return QString::null; + if ( r->includeFile.isNull() ) + return r->name.lower() + ".h"; + return r->includeFile; +} + +/*! Returns wheather the widget registered as \a id is a container + (can have children) or not. +*/ + +bool WidgetDatabase::isContainer( int id ) +{ + setupDataBase(); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return FALSE; + return r->isContainer; +} + +QString WidgetDatabase::createWidgetName( int id ) +{ + setupDataBase(); + QString n = className( id ); + if ( n == "QLayoutWidget" ) + n = "Layout"; + if ( n[ 0 ] == 'Q' ) + n = n.mid( 1 ); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return n; + n += QString::number( ++r->nameCounter ); + return n; +} + +/*! Returns the id for \a name or -1 if \a name is unknown. + */ +int WidgetDatabase::idFromClassName( const QString &name ) +{ + setupDataBase(); + if ( name.isEmpty() ) + return 0; + int *i = className2Id->find( name ); + if ( i ) + return *i; + if ( name == "FormWindow" ) + return idFromClassName( "QLayoutWidget" ); + return -1; +} + +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 ) +{ + insert( dbcount++, r ); +} + +QString WidgetDatabase::widgetGroup( const QString &g ) +{ + if ( wGroups->find( g ) == -1 ) + wGroups->append( g ); + return g; +} + +QString WidgetDatabase::widgetGroup( int i ) +{ + setupDataBase(); + if ( i >= 0 && i < (int)wGroups->count() ) + return wGroups->at( i ); + return QString::null; +} + +int WidgetDatabase::numWidgetGroups() +{ + setupDataBase(); + return wGroups->count(); +} + +bool WidgetDatabase::isGroupVisible( const QString &g ) +{ + setupDataBase(); + return invisibleGroups->find( g ) == -1; +} + +int WidgetDatabase::addCustomWidget( WidgetDatabaseRecord *r ) +{ + insert( dbcustomcount++, r ); + return dbcustomcount - 1; +} + +bool WidgetDatabase::isCustomWidget( int id ) +{ + if ( id >= dbcustom && id < dbcustomcount ) + return TRUE; + return FALSE; +} + +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; +} diff --git a/pyuic2/widgetdatabase.h b/pyuic2/widgetdatabase.h new file mode 100644 index 0000000..a28cd5f --- /dev/null +++ b/pyuic2/widgetdatabase.h @@ -0,0 +1,75 @@ +/********************************************************************** +** 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 WIDGETDATABASE_H +#define WIDGETDATABASE_H + +#include <qiconset.h> +#include <qstring.h> +#include <qstringlist.h> + +struct WidgetDatabaseRecord +{ + WidgetDatabaseRecord(); + ~WidgetDatabaseRecord(); + QString iconSet, name, group, toolTip, whatsThis, includeFile; + uint isContainer : 1; + QIconSet *icon; + int nameCounter; +}; + +class WidgetDatabase : public Qt +{ +public: + WidgetDatabase(); + static void setupDataBase(); + + 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 isContainer( 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 int addCustomWidget( WidgetDatabaseRecord *r ); + static bool isCustomWidget( int id ); + + static bool isWhatsThisLoaded(); + static void loadWhatsThis( const QString &docPath ); + +}; + +#endif |