diff options
author | Timothy Pearson <[email protected]> | 2011-11-08 12:31:36 -0600 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2011-11-08 12:31:36 -0600 |
commit | d796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch) | |
tree | 6e3dcca4f77e20ec8966c666aac7c35bd4704053 /tools/designer/shared | |
download | tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip |
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'tools/designer/shared')
-rw-r--r-- | tools/designer/shared/domtool.cpp | 460 | ||||
-rw-r--r-- | tools/designer/shared/domtool.h | 60 | ||||
-rw-r--r-- | tools/designer/shared/globaldefs.h | 69 | ||||
-rw-r--r-- | tools/designer/shared/parser.cpp | 79 | ||||
-rw-r--r-- | tools/designer/shared/parser.h | 46 | ||||
-rw-r--r-- | tools/designer/shared/ui2uib.cpp | 900 | ||||
-rw-r--r-- | tools/designer/shared/ui2uib.h | 42 | ||||
-rw-r--r-- | tools/designer/shared/uib.cpp | 49 | ||||
-rw-r--r-- | tools/designer/shared/uib.h | 159 | ||||
-rw-r--r-- | tools/designer/shared/widgetdatabase.cpp | 964 | ||||
-rw-r--r-- | tools/designer/shared/widgetdatabase.h | 103 |
11 files changed, 2931 insertions, 0 deletions
diff --git a/tools/designer/shared/domtool.cpp b/tools/designer/shared/domtool.cpp new file mode 100644 index 000000000..7ea219aa9 --- /dev/null +++ b/tools/designer/shared/domtool.cpp @@ -0,0 +1,460 @@ +/********************************************************************** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "domtool.h" + +#include <qsizepolicy.h> +#include <qcolor.h> +#include <qcursor.h> +#include <qdatetime.h> +#include <qrect.h> +#include <qsize.h> +#include <qfont.h> +#include <qdom.h> + +/*! + \class DomTool domtool.h + \brief Tools for the dom + + A collection of static functions used by Resource (part of the + designer) and Uic. + +*/ + +/*! + Returns the contents of property \a name of object \a e as + variant or the variant passed as \a defValue if the property does + not exist. + + \sa hasProperty() +*/ +TQVariant DomTool::readProperty( const TQDomElement& e, const TQString& name, const TQVariant& defValue, TQString& comment ) +{ + TQDomElement n; + for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { + if ( n.tagName() == "property" ) { + if ( n.attribute( "name" ) != name ) + continue; + return elementToVariant( n.firstChild().toElement(), defValue, comment ); + } + } + return defValue; +} + + +/*! + \overload + */ +TQVariant DomTool::readProperty( const TQDomElement& e, const TQString& name, const TQVariant& defValue ) +{ + TQString comment; + return readProperty( e, name, defValue, comment ); +} + +/*! + Returns wheter object \a e defines property \a name or not. + + \sa readProperty() + */ +bool DomTool::hasProperty( const TQDomElement& e, const TQString& name ) +{ + TQDomElement n; + for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { + if ( n.tagName() == "property" ) { + if ( n.attribute( "name" ) != name ) + continue; + return TRUE; + } + } + return FALSE; +} + +TQStringList DomTool::propertiesOfType( const TQDomElement& e, const TQString& type ) +{ + TQStringList result; + TQDomElement n; + for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { + if ( n.tagName() == "property" ) { + TQDomElement n2 = n.firstChild().toElement(); + if ( n2.tagName() == type ) + result += n.attribute( "name" ); + } + } + return result; +} + + +TQVariant DomTool::elementToVariant( const TQDomElement& e, const TQVariant& defValue ) +{ + TQString dummy; + return elementToVariant( e, defValue, dummy ); +} + +/*! + Interprets element \a e as variant and returns the result of the interpretation. + */ +TQVariant DomTool::elementToVariant( const TQDomElement& e, const TQVariant& defValue, TQString &comment ) +{ + TQVariant v; + if ( e.tagName() == "rect" ) { + TQDomElement 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 = TQVariant( TQRect( x, y, w, h ) ); + } else if ( e.tagName() == "point" ) { + TQDomElement 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 = TQVariant( TQPoint( x, y ) ); + } else if ( e.tagName() == "size" ) { + TQDomElement 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 = TQVariant( TQSize( w, h ) ); + } else if ( e.tagName() == "color" ) { + v = TQVariant( readColor( e ) ); + } else if ( e.tagName() == "font" ) { + TQDomElement n3 = e.firstChild().toElement(); + TQFont 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 = TQVariant( f ); + } else if ( e.tagName() == "string" ) { + v = TQVariant( e.firstChild().toText().data() ); + TQDomElement n = e; + n = n.nextSibling().toElement(); + if ( n.tagName() == "comment" ) + comment = n.firstChild().toText().data(); + } else if ( e.tagName() == "cstring" ) { + v = TQVariant( TQCString( e.firstChild().toText().data() ) ); + } else if ( e.tagName() == "number" ) { + bool ok = TRUE; + v = TQVariant( e.firstChild().toText().data().toInt( &ok ) ); + if ( !ok ) + v = TQVariant( e.firstChild().toText().data().toDouble() ); + } else if ( e.tagName() == "bool" ) { + TQString t = e.firstChild().toText().data(); + v = TQVariant( t == "true" || t == "1", 0 ); + } else if ( e.tagName() == "pixmap" ) { + v = TQVariant( e.firstChild().toText().data() ); + } else if ( e.tagName() == "iconset" ) { + v = TQVariant( e.firstChild().toText().data() ); + } else if ( e.tagName() == "image" ) { + v = TQVariant( e.firstChild().toText().data() ); + } else if ( e.tagName() == "enum" ) { + v = TQVariant( e.firstChild().toText().data() ); + } else if ( e.tagName() == "set" ) { + v = TQVariant( e.firstChild().toText().data() ); + } else if ( e.tagName() == "sizepolicy" ) { + TQDomElement n3 = e.firstChild().toElement(); + TQSizePolicy sp; + while ( !n3.isNull() ) { + if ( n3.tagName() == "hsizetype" ) + sp.setHorData( (TQSizePolicy::SizeType)n3.firstChild().toText().data().toInt() ); + else if ( n3.tagName() == "vsizetype" ) + sp.setVerData( (TQSizePolicy::SizeType)n3.firstChild().toText().data().toInt() ); + else if ( n3.tagName() == "horstretch" ) + sp.setHorStretch( n3.firstChild().toText().data().toInt() ); + else if ( n3.tagName() == "verstretch" ) + sp.setVerStretch( n3.firstChild().toText().data().toInt() ); + n3 = n3.nextSibling().toElement(); + } + v = TQVariant( sp ); + } else if ( e.tagName() == "cursor" ) { + v = TQVariant( TQCursor( e.firstChild().toText().data().toInt() ) ); + } else if ( e.tagName() == "stringlist" ) { + TQStringList lst; + TQDomElement n; + for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) + lst << n.firstChild().toText().data(); + v = TQVariant( lst ); + } else if ( e.tagName() == "date" ) { + TQDomElement n3 = e.firstChild().toElement(); + int y, m, d; + y = m = d = 0; + while ( !n3.isNull() ) { + if ( n3.tagName() == "year" ) + y = n3.firstChild().toText().data().toInt(); + else if ( n3.tagName() == "month" ) + m = n3.firstChild().toText().data().toInt(); + else if ( n3.tagName() == "day" ) + d = n3.firstChild().toText().data().toInt(); + n3 = n3.nextSibling().toElement(); + } + v = TQVariant( TQDate( y, m, d ) ); + } else if ( e.tagName() == "time" ) { + TQDomElement n3 = e.firstChild().toElement(); + int h, m, s; + h = m = s = 0; + while ( !n3.isNull() ) { + if ( n3.tagName() == "hour" ) + h = n3.firstChild().toText().data().toInt(); + else if ( n3.tagName() == "minute" ) + m = n3.firstChild().toText().data().toInt(); + else if ( n3.tagName() == "second" ) + s = n3.firstChild().toText().data().toInt(); + n3 = n3.nextSibling().toElement(); + } + v = TQVariant( TQTime( h, m, s ) ); + } else if ( e.tagName() == "datetime" ) { + TQDomElement n3 = e.firstChild().toElement(); + int h, mi, s, y, mo, d ; + h = mi = s = y = mo = d = 0; + while ( !n3.isNull() ) { + if ( n3.tagName() == "hour" ) + h = n3.firstChild().toText().data().toInt(); + else if ( n3.tagName() == "minute" ) + mi = n3.firstChild().toText().data().toInt(); + else if ( n3.tagName() == "second" ) + s = n3.firstChild().toText().data().toInt(); + else if ( n3.tagName() == "year" ) + y = n3.firstChild().toText().data().toInt(); + else if ( n3.tagName() == "month" ) + mo = n3.firstChild().toText().data().toInt(); + else if ( n3.tagName() == "day" ) + d = n3.firstChild().toText().data().toInt(); + n3 = n3.nextSibling().toElement(); + } + v = TQVariant( TQDateTime( TQDate( y, mo, d ), TQTime( h, mi, s ) ) ); + } + return v; +} + + +/*! Returns the color which is returned in the dom element \a e. + */ + +TQColor DomTool::readColor( const TQDomElement &e ) +{ + TQDomElement 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 TQColor( 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() + */ +TQVariant DomTool::readAttribute( const TQDomElement& e, const TQString& name, const TQVariant& defValue, TQString& comment ) +{ + TQDomElement n; + for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { + if ( n.tagName() == "attribute" ) { + if ( n.attribute( "name" ) != name ) + continue; + return elementToVariant( n.firstChild().toElement(), defValue, comment ); + } + } + return defValue; +} + +/*! + \overload +*/ +TQVariant DomTool::readAttribute( const TQDomElement& e, const TQString& name, const TQVariant& defValue ) +{ + TQString comment; + return readAttribute( e, name, defValue, comment ); +} + +/*! + Returns wheter object \a e defines attribute \a name or not. + + \sa readAttribute() + */ +bool DomTool::hasAttribute( const TQDomElement& e, const TQString& name ) +{ + TQDomElement n; + for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { + if ( n.tagName() == "attribute" ) { + if ( n.attribute( "name" ) != name ) + continue; + return TRUE; + } + } + return FALSE; +} + +static bool toBool( const TQString& s ) +{ + return s == "true" || s.toInt() != 0; +} + +/*! + Convert TQt 2.x format to TQt 3.0 format if necessary +*/ +void DomTool::fixDocument( TQDomDocument& doc ) +{ + TQDomElement e; + TQDomNode n; + TQDomNodeList nl; + int i = 0; + + e = doc.firstChild().toElement(); + if ( e.tagName() != "UI" ) + return; + + // latest version, don't do anything + if ( e.hasAttribute("version") && e.attribute("version").toDouble() > 3.0 ) + return; + + nl = doc.elementsByTagName( "property" ); + + // in 3.0, we need to fix a spelling error + if ( e.hasAttribute("version") && e.attribute("version").toDouble() == 3.0 ) { + for ( i = 0; i < (int) nl.length(); i++ ) { + TQDomElement el = nl.item(i).toElement(); + TQString s = el.attribute( "name" ); + if ( s == "resizeable" ) { + el.removeAttribute( "name" ); + el.setAttribute( "name", "resizable" ); + } + } + return; + } + + + // in versions smaller than 3.0 we need to change more + e.setAttribute( "version", 3.0 ); + + e.setAttribute("stdsetdef", 1 ); + for ( i = 0; i < (int) nl.length(); i++ ) { + e = nl.item(i).toElement(); + TQString name; + TQDomElement n2 = e.firstChild().toElement(); + if ( n2.tagName() == "name" ) { + name = n2.firstChild().toText().data(); + if ( name == "resizeable" ) + e.setAttribute( "name", "resizable" ); + else + e.setAttribute( "name", name ); + e.removeChild( n2 ); + } + bool stdset = toBool( e.attribute( "stdset" ) ); + if ( stdset || name == "toolTip" || name == "whatsThis" || + name == "buddy" || + e.parentNode().toElement().tagName() == "item" || + e.parentNode().toElement().tagName() == "spacer" || + e.parentNode().toElement().tagName() == "column" + ) + e.removeAttribute( "stdset" ); + else + e.setAttribute( "stdset", 0 ); + } + + nl = doc.elementsByTagName( "attribute" ); + for ( i = 0; i < (int) nl.length(); i++ ) { + e = nl.item(i).toElement(); + TQString name; + TQDomElement n2 = e.firstChild().toElement(); + if ( n2.tagName() == "name" ) { + name = n2.firstChild().toText().data(); + e.setAttribute( "name", name ); + e.removeChild( n2 ); + } + } + + nl = doc.elementsByTagName( "image" ); + for ( i = 0; i < (int) nl.length(); i++ ) { + e = nl.item(i).toElement(); + TQString name; + TQDomElement n2 = e.firstChild().toElement(); + if ( n2.tagName() == "name" ) { + name = n2.firstChild().toText().data(); + e.setAttribute( "name", name ); + e.removeChild( n2 ); + } + } + + nl = doc.elementsByTagName( "widget" ); + for ( i = 0; i < (int) nl.length(); i++ ) { + e = nl.item(i).toElement(); + TQString name; + TQDomElement n2 = e.firstChild().toElement(); + if ( n2.tagName() == "class" ) { + name = n2.firstChild().toText().data(); + e.setAttribute( "class", name ); + e.removeChild( n2 ); + } + } + +} + diff --git a/tools/designer/shared/domtool.h b/tools/designer/shared/domtool.h new file mode 100644 index 000000000..b495bdfbe --- /dev/null +++ b/tools/designer/shared/domtool.h @@ -0,0 +1,60 @@ +/********************************************************************** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef DOMTOOL_H +#define DOMTOOL_H + +#include <qvariant.h> +#include <qnamespace.h> + +class TQDomElement; +class TQDomDocument; + +class DomTool : public TQt +{ +public: + static TQVariant readProperty( const TQDomElement& e, const TQString& name, const TQVariant& defValue ); + static TQVariant readProperty( const TQDomElement& e, const TQString& name, const TQVariant& defValue, TQString& comment ); + static bool hasProperty( const TQDomElement& e, const TQString& name ); + static TQStringList propertiesOfType( const TQDomElement& e, const TQString& type ); + static TQVariant elementToVariant( const TQDomElement& e, const TQVariant& defValue ); + static TQVariant elementToVariant( const TQDomElement& e, const TQVariant& defValue, TQString &comment ); + static TQVariant readAttribute( const TQDomElement& e, const TQString& name, const TQVariant& defValue ); + static TQVariant readAttribute( const TQDomElement& e, const TQString& name, const TQVariant& defValue, TQString& comment ); + static bool hasAttribute( const TQDomElement& e, const TQString& name ); + static TQColor readColor( const TQDomElement &e ); + static void fixDocument( TQDomDocument& ); +}; + + +#endif // DOMTOOL_H diff --git a/tools/designer/shared/globaldefs.h b/tools/designer/shared/globaldefs.h new file mode 100644 index 000000000..a9f25cc17 --- /dev/null +++ b/tools/designer/shared/globaldefs.h @@ -0,0 +1,69 @@ +/********************************************************************** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef GLOBALDEFS_H +#define GLOBALDEFS_H + +#include <qcolor.h> +#include <qapplication.h> + +#define BOXLAYOUT_DEFAULT_MARGIN 11 +#define BOXLAYOUT_DEFAULT_SPACING 6 + +#ifndef NO_STATIC_COLORS +static TQColor *backColor1 = 0; +static TQColor *backColor2 = 0; +static TQColor *selectedBack = 0; + +static void init_colors() +{ + if ( backColor1 ) + return; + +#if 0 // a calculated alternative for backColor1 + TQColorGroup myCg = qApp->palette().active(); + int h1, s1, v1; + int h2, s2, v2; + myCg.color( TQColorGroup::Base ).hsv( &h1, &s1, &v1 ); + myCg.color( TQColorGroup::Background ).hsv( &h2, &s2, &v2 ); + TQColor c( h1, s1, ( v1 + v2 ) / 2, TQColor::Hsv ); +#endif + + backColor1 = new TQColor( 250, 248, 235 ); + backColor2 = new TQColor( 255, 255, 255 ); + selectedBack = new TQColor( 230, 230, 230 ); +} + +#endif + +#endif diff --git a/tools/designer/shared/parser.cpp b/tools/designer/shared/parser.cpp new file mode 100644 index 000000000..21b3efec1 --- /dev/null +++ b/tools/designer/shared/parser.cpp @@ -0,0 +1,79 @@ +/********************************************************************** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "parser.h" +#include <qobject.h> +#include <qstringlist.h> + +class NormalizeObject : public TQObject +{ +public: + NormalizeObject() : TQObject() {} + static TQCString normalizeSignalSlot( const char *signalSlot ) { return TQObject::normalizeSignalSlot( signalSlot ); } +}; + +TQString Parser::cleanArgs( const TQString &func ) +{ + TQString slot( func ); + int begin = slot.find( "(" ) + 1; + TQString args = slot.mid( begin ); + args = args.left( args.find( ")" ) ); + TQStringList lst = TQStringList::split( ',', args ); + TQString res = slot.left( begin ); + for ( TQStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { + if ( it != lst.begin() ) + res += ","; + TQString arg = *it; + int pos = 0; + if ( ( pos = arg.find( "&" ) ) != -1 ) { + arg = arg.left( pos + 1 ); + } else if ( ( pos = arg.find( "*" ) ) != -1 ) { + arg = arg.left( pos + 1 ); + } else { + arg = arg.simplifyWhiteSpace(); + if ( ( pos = arg.find( ':' ) ) != -1 ) + arg = arg.left( pos ).simplifyWhiteSpace() + ":" + arg.mid( pos + 1 ).simplifyWhiteSpace(); + TQStringList l = TQStringList::split( ' ', arg ); + if ( l.count() == 2 ) { + if ( l[ 0 ] != "const" && l[ 0 ] != "unsigned" && l[ 0 ] != "var" ) + arg = l[ 0 ]; + } else if ( l.count() == 3 ) { + arg = l[ 0 ] + " " + l[ 1 ]; + } + } + res += arg; + } + res += ")"; + + return TQString::fromLatin1( NormalizeObject::normalizeSignalSlot( res.latin1() ) ); +} diff --git a/tools/designer/shared/parser.h b/tools/designer/shared/parser.h new file mode 100644 index 000000000..7b3ac0e9e --- /dev/null +++ b/tools/designer/shared/parser.h @@ -0,0 +1,46 @@ +/********************************************************************** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef PARSER_H +#define PARSER_H + +#include <qstring.h> + +class Parser +{ +public: + static TQString cleanArgs( const TQString &func ); + +}; + +#endif diff --git a/tools/designer/shared/ui2uib.cpp b/tools/designer/shared/ui2uib.cpp new file mode 100644 index 000000000..226f6bb49 --- /dev/null +++ b/tools/designer/shared/ui2uib.cpp @@ -0,0 +1,900 @@ +/********************************************************************** +** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "ui2uib.h" +#include "uib.h" + +#include <domtool.h> + +#include <qcolor.h> +#include <qcursor.h> +#include <qdatetime.h> +#include <qdom.h> +#include <qfile.h> +#include <qfont.h> +#include <qobject.h> +#include <qrect.h> +#include <qsizepolicy.h> + +/* + The .uib file format is the binary counterpart of the .ui file + format. It is generated by the ui2uib converter and understood by + TQWidgetFactory; in a future version, it might also be understood + by a uib2ui converter. Experiments show that .uib files are about + 2.5 times faster to load and 6 times smaller than .ui files. + + The .uib format, unlike the .ui format, is internal to Trolltech + and is not officially documented; it is assumed that anybody who + needs to understand the file format can read the ui2uib and + TQWidgetFactory source code, with some guidance. And here's some + guidance. + + A .uib file starts with a 32-bit magic number that allows + TQWidgetFactory to determine the file type. The magic number is + followed by '\n' (0x0a) and '\r' (0x0d), which ensure that the + file wasn't corrupted during transfer between different + platforms. For example, transferring a .ui file from Windows to + Unix using FTP with type ASCII will produce a file with '\r\n\r' + in place of '\n\r'. This is followed by the TQDataStream format + version number used. + + The rest of the file is made up of blocks, each of which starts + with a block type (Block_XXX) and a block length. Block_Intro and + Block_Widget are mandatory; the others are optional. + TQWidgetFactory makes certain assumptions about the order of the + blocks; for example, it expects Block_String before any other + block that refers to a string and Block_Images before + Block_Widget. The order generated by ui2uib is one of the orders + that make sense. Just after the last block, a Block_End marker + indicates the end of the file. + + The division of .uib files into blocks corresponds grossly to the + division of .ui files in top-level XML elements. Thus, + Block_Widget corresponds to <widget> and Block_Toolbars to + <toolbars>. The internal organization of each block also mimics + the organization of the corresponding XML elements. + + These are the major differences, all of which contribute to + making .uib files more compact: + + 1. The strings are gathered in Block_Strings, a string-table. + When a string is needed later, it is referenced by a 32-bit + index into that table. The UicStringTable class makes the + whole process of inserting and looking up strings very + simple. The advantage of this scheme is that if a string is + used more than once, it is stored only once. Also, the + string-table is preinitialized with very common strings, so + that these need not be stored along with .uib files. + + 2. TQObjects are referred to by index in a table rather than by + name. The table itself is not stored in the .uib file; it is + rather build dynamically by ui2uib and TQWidgetFactory as new + objects are specified. In ui2uib, the table is represented by + a UibIndexMap object; in TQWidgetFactory, a plain array of + TQObject pointers suffices. + + 3. The data is packed to take as little place as possible, + without slowing down TQLayoutFactory too much. For example, an + index into the string-table is a 32-bit integer, but in + practice it is rarely above 65534, so only 16 bits are used + for them; when an index above 65534 is met, the index is + saved as 65535 followed by the 32-bit index, for a total of + 48 bits. + + 4. The name of a signal or slot and its signature are saved + separately. That way, if a signal 'foo(const TQString&)' is + connected to a slot 'bar(const TQString&)', the string-table + will only contain 'foo', 'bar', and '(const TQString&)', + instead of the longer 'foo(const TQString&)' and 'bar(const + TQString&)'. The signatures are normalized beforehand to + ensure that trivial spacing problems don't result in multiple + string-table entries. + + 5. In a signal-to-slot connection, a sender, signal, receiver, + or slot is not repeated if it's the same as for the previous + connection. Bit flags indicate what is repeated and what is + specified. + + 6. Some of the information stored in a .ui file is useful only + by uic, not to TQLayoutFactory. That information is, for now, + not taken along in the .uib file. Likewise, needless + TQLayoutWidget objects are not taken along. + + The arbitrary constants related to the .uib file formats are + defined in uib.h. Constants such as Block_Actions and + Object_SubWidget are given values such as 'A' and 'W' to make + .uib files easier to read in a hexadecimal editor. + + The file format isn't designed to be extensible. Any extension + that prevents an older version of TQLayoutWidget of reading the + file correctly must have a different magic number. The plan is to + use UibMagic + 1 for version 2, UibMagic + 2 for version 3, etc. +*/ + +static TQCString layoutForTag( const TQString& tag ) +{ + if ( tag == "grid" ) { + return "TQGridLayout"; + } else if ( tag == "hbox" ) { + return "TQHBoxLayout"; + } else if ( tag == "vbox" ) { + return "TQVBoxLayout"; + } else { + return "TQLayout"; + } +} + +class UibHack : public TQObject +{ +public: + static TQString normalize( const TQString& member ) { + return TQString::fromUtf8( TQObject::normalizeSignalSlot(member.utf8()) ); + } +}; + +class UibIndexMap +{ +public: + UibIndexMap() : next( 0 ) { } + + void insert( const TQString& name ) { setName( insert(), name ); } + int insert() { return next++; } + void setName( int no, const TQString& name ); + + int find( const TQString& name, int deflt = -1 ) const; + int count() const { return next; } + +private: + TQMap<TQString, int> nameMap; + TQMap<TQString, int> conflicts; + int next; +}; + +void UibIndexMap::setName( int no, const TQString& name ) +{ + if ( !name.isEmpty() ) { + if ( *nameMap.insert(name, no, FALSE) != no ) + conflicts.insert( name, 0 ); + } +} + +int UibIndexMap::find( const TQString& name, int deflt ) const +{ + TQMap<TQString, int>::ConstIterator no = nameMap.find( name ); + if ( no == nameMap.end() || conflicts.contains(name) ) { + return deflt; + } else { + return *no; + } +} + +static void packUInt16( TQDataStream& out, Q_UINT16 n ) +{ + if ( n < 255 ) { + out << (Q_UINT8) n; + } else { + out << (Q_UINT8) 255; + out << n; + } +} + +static void packUInt32( TQDataStream& out, Q_UINT32 n ) +{ + if ( n < 65535 ) { + out << (Q_UINT16) n; + } else { + out << (Q_UINT16) 65535; + out << n; + } +} + +static void packByteArray( TQDataStream& out, const TQByteArray& array ) +{ + packUInt32( out, array.size() ); + out.writeRawBytes( array.data(), array.size() ); +} + +static void packCString( UibStrTable& strings, TQDataStream& out, + const char *cstr ) +{ + packUInt32( out, strings.insertCString(cstr) ); +} + +static void packString( UibStrTable& strings, TQDataStream& out, + const TQString& str ) +{ + packUInt32( out, strings.insertString(str) ); +} + +static void packStringSplit( UibStrTable& strings, TQDataStream& out, + const TQString& str, TQChar sep ) +{ + int pos = str.find( sep ); + if ( pos == -1 ) + pos = str.length(); + packString( strings, out, str.left(pos) ); + packString( strings, out, str.mid(pos) ); +} + +static void packVariant( UibStrTable& strings, TQDataStream& out, + TQVariant value, TQString tag = "" ) +{ + TQStringList::ConstIterator s; + + Q_UINT8 type = value.type(); + if ( tag == "pixmap" ) { + type = TQVariant::Pixmap; + } else if ( tag == "image" ) { + type = TQVariant::Image; + } else if ( tag == "iconset" ) { + type = TQVariant::IconSet; + } + out << type; + + switch ( type ) { + case TQVariant::String: + case TQVariant::Pixmap: + case TQVariant::Image: + case TQVariant::IconSet: + packString( strings, out, value.asString() ); + break; + case TQVariant::StringList: + packUInt16( out, value.asStringList().count() ); + s = value.asStringList().begin(); + while ( s != value.asStringList().end() ) { + packString( strings, out, *s ); + ++s; + } + break; + case TQVariant::Font: + out << value.asFont(); + break; + case TQVariant::Rect: + packUInt16( out, value.asRect().x() ); + packUInt16( out, value.asRect().y() ); + packUInt16( out, value.asRect().width() ); + packUInt16( out, value.asRect().height() ); + break; + case TQVariant::Size: + packUInt16( out, value.asSize().width() ); + packUInt16( out, value.asSize().height() ); + break; + case TQVariant::Color: + out << value.asColor(); + break; + case TQVariant::Point: + packUInt16( out, value.asPoint().x() ); + packUInt16( out, value.asPoint().y() ); + break; + case TQVariant::Int: + packUInt32( out, value.asInt() ); + break; + case TQVariant::Bool: + out << (Q_UINT8) value.asBool(); + break; + case TQVariant::Double: + out << value.asDouble(); + break; + case TQVariant::CString: + packCString( strings, out, value.asCString() ); + break; + case TQVariant::Cursor: + out << value.asCursor(); + break; + case TQVariant::Date: + out << value.asDate(); + break; + case TQVariant::Time: + out << value.asTime(); + break; + case TQVariant::DateTime: + out << value.asDateTime(); + break; + default: + out << value; + } +} + +static void outputProperty( TQMap<int, TQStringList>& buddies, int objectNo, + UibStrTable& strings, TQDataStream& out, + TQDomElement elem ) +{ + TQCString name = elem.attribute( "name" ).latin1(); + TQDomElement f = elem.firstChild().toElement(); + TQString tag = f.tagName(); + TQString comment; + TQVariant value; + + if ( name == "resizeable" ) + name = "resizable"; + + if ( tag == "font" ) { + TQString family; + Q_UINT16 pointSize = 65535; + Q_UINT8 fontFlags = 0; + + TQDomElement g = f.firstChild().toElement(); + while ( !g.isNull() ) { + TQString text = g.firstChild().toText().data(); + if ( g.tagName() == "family" ) { + fontFlags |= Font_Family; + family = text; + } else if ( g.tagName() == "pointsize" ) { + fontFlags |= Font_PointSize; + pointSize = (Q_UINT16) text.toUInt(); + } else { + if ( g.firstChild().toText().data().toInt() != 0 ) { + if ( g.tagName() == "bold" ) { + fontFlags |= Font_Bold; + } else if ( g.tagName() == "italic" ) { + fontFlags |= Font_Italic; + } else if ( g.tagName() == "underline" ) { + fontFlags |= Font_Underline; + } else if ( g.tagName() == "strikeout" ) { + fontFlags |= Font_StrikeOut; + } + } + } + g = g.nextSibling().toElement(); + } + + out << (Q_UINT8) Object_FontProperty; + packCString( strings, out, name ); + out << fontFlags; + if ( fontFlags & Font_Family ) + packString( strings, out, family ); + if ( fontFlags & Font_PointSize ) + packUInt16( out, pointSize ); + } else if ( tag == "palette" ) { + out << (Q_UINT8) Object_PaletteProperty; + packCString( strings, out, name ); + + TQDomElement g = f.firstChild().toElement(); + while ( !g.isNull() ) { + TQDomElement h = g.firstChild().toElement(); + while ( !h.isNull() ) { + value = DomTool::elementToVariant( h, TQt::gray ); + if ( h.tagName() == "color" ) { + out << (Q_UINT8) Palette_Color; + out << value.asColor(); + } else if ( h.tagName() == "pixmap" ) { + out << (Q_UINT8) Palette_Pixmap; + packVariant( strings, out, value, "pixmap" ); + } + h = h.nextSibling().toElement(); + } + + if ( g.tagName() == "active" ) { + out << (Q_UINT8) Palette_Active; + } else if ( g.tagName() == "inactive" ) { + out << (Q_UINT8) Palette_Inactive; + } else { + out << (Q_UINT8) Palette_Disabled; + } + g = g.nextSibling().toElement(); + } + out << (Q_UINT8) Palette_End; + } else { + value = DomTool::elementToVariant( f, value, comment ); + if ( value.isValid() ) { + if ( name == "buddy" ) { + buddies[objectNo] += value.asString(); + } else { + if ( tag == "string" ) { + out << (Q_UINT8) Object_TextProperty; + packCString( strings, out, name ); + packCString( strings, out, value.asString().utf8() ); + packCString( strings, out, comment.utf8() ); + } else { + out << (Q_UINT8) Object_VariantProperty; + packCString( strings, out, name ); + packVariant( strings, out, value, tag ); + } + } + } + } +} + +static void outputGridCell( TQDataStream& out, TQDomElement elem ) +{ + int column = elem.attribute( "column", "0" ).toInt(); + int row = elem.attribute( "row", "0" ).toInt(); + int colspan = elem.attribute( "colspan", "1" ).toInt(); + int rowspan = elem.attribute( "rowspan", "1" ).toInt(); + if ( colspan < 1 ) + colspan = 1; + if ( rowspan < 1 ) + rowspan = 1; + + if ( column != 0 || row != 0 || colspan != 1 || rowspan != 1 ) { + out << (Q_UINT8) Object_GridCell; + packUInt16( out, column ); + packUInt16( out, row ); + packUInt16( out, colspan ); + packUInt16( out, rowspan ); + } +} + +static int outputObject( TQMap<int, TQStringList>& buddies, + UibIndexMap& objects, UibStrTable& strings, + TQDataStream& out, TQDomElement elem, + TQCString className = "" ); + +static void outputLayoutWidgetsSubLayout( TQMap<int, TQStringList>& buddies, + UibIndexMap& objects, + UibStrTable& strings, + TQDataStream& out, TQDomElement elem ) +{ + int subLayoutNo = -1; + TQCString name; + TQDomElement nameElem; + + TQDomElement f = elem.firstChild().toElement(); + while ( !f.isNull() ) { + TQString tag = f.tagName(); + if ( tag == "grid" || tag == "hbox" || tag == "vbox" ) { + out << (Q_UINT8) Object_SubLayout; + subLayoutNo = outputObject( buddies, objects, strings, out, f, + layoutForTag(tag) ); + } else if ( tag == "property" ) { + if ( f.attribute("name") == "name" ) { + name = DomTool::elementToVariant( f, name ).asCString(); + nameElem = f; + } + } + f = f.nextSibling().toElement(); + } + + if ( subLayoutNo != -1 ) { + /* + Remove the sub-layout's Object_End marker, append the grid + cell and the correct name property, and put the Object_End + marker back. + */ + out.device()->at( out.device()->at() - 1 ); + outputGridCell( out, elem ); + outputProperty( buddies, subLayoutNo, strings, out, nameElem ); + out << (Q_UINT8) Object_End; + + objects.setName( subLayoutNo, name ); + } +} + +static int outputObject( TQMap<int, TQStringList>& buddies, + UibIndexMap& objects, UibStrTable& strings, + TQDataStream& out, TQDomElement elem, + TQCString className ) +{ + bool isTQObject = !className.isEmpty(); + + if ( className == "TQToolBar" ) + out << (Q_UINT8) elem.attribute( "dock", "0" ).toInt(); + if ( className == "TQWidget" ) + className = elem.attribute( "class", className ).latin1(); + + int objectNo = -1; + if ( isTQObject ) { + packCString( strings, out, className ); + objectNo = objects.insert(); + } + + outputGridCell( out, elem ); + + // optimization: insert '&Foo' into string-table before 'Foo' + if ( className == "TQAction" || className == "TQActionGroup" ) { + TQVariant value = DomTool::readProperty( elem, "menuText", TQVariant() ); + if ( value.asString().startsWith("&") ) + strings.insertString( value.asString() ); + } + + TQDomElement f = elem.firstChild().toElement(); + while ( !f.isNull() ) { + TQString tag = f.tagName(); + if ( tag == "action" ) { + if ( elem.tagName() == "item" || elem.tagName() == "toolbar" ) { + TQString actionName = f.attribute( "name" ); + int no = objects.find( actionName ); + if ( no != -1 ) { + out << (Q_UINT8) Object_ActionRef; + packUInt16( out, no ); + } + } else { + out << (Q_UINT8) Object_SubAction; + outputObject( buddies, objects, strings, out, f, "TQAction" ); + } + } else if ( tag == "actiongroup" ) { + out << (Q_UINT8) Object_SubAction; + outputObject( buddies, objects, strings, out, f, "TQActionGroup" ); + } else if ( tag == "attribute" ) { + out << (Q_UINT8) Object_Attribute; + outputProperty( buddies, objectNo, strings, out, f ); + } else if ( tag == "column" ) { + out << (Q_UINT8) Object_Column; + outputObject( buddies, objects, strings, out, f ); + } else if ( tag == "event" ) { + out << (Q_UINT8) Object_Event; + packCString( strings, out, f.attribute("name").latin1() ); + packVariant( strings, out, + TQStringList::split(',', f.attribute("functions")) ); + } else if ( tag == "grid" || tag == "hbox" || tag == "vbox" ) { + out << (Q_UINT8) Object_SubLayout; + outputObject( buddies, objects, strings, out, f, + layoutForTag(tag) ); + } else if ( tag == "item" ) { + if ( elem.tagName() == "menubar" ) { + out << (Q_UINT8) Object_MenuItem; + packCString( strings, out, f.attribute("name").latin1() ); + packCString( strings, out, f.attribute("text").utf8() ); + outputObject( buddies, objects, strings, out, f ); + } else { + out << (Q_UINT8) Object_Item; + outputObject( buddies, objects, strings, out, f ); + } + } else if ( tag == "property" ) { + outputProperty( buddies, objectNo, strings, out, f ); + } else if ( tag == "row" ) { + out << (Q_UINT8) Object_Row; + outputObject( buddies, objects, strings, out, f ); + } else if ( tag == "separator" ) { + out << (Q_UINT8) Object_Separator; + } else if ( tag == "spacer" ) { + out << (Q_UINT8) Object_Spacer; + outputObject( buddies, objects, strings, out, f ); + } else if ( tag == "widget" ) { + if ( f.attribute("class") == "TQLayoutWidget" && + elem.tagName() != "widget" ) { + outputLayoutWidgetsSubLayout( buddies, objects, strings, out, + f ); + } else { + out << (Q_UINT8) Object_SubWidget; + outputObject( buddies, objects, strings, out, f, "TQWidget" ); + } + } + f = f.nextSibling().toElement(); + } + out << (Q_UINT8) Object_End; + if ( isTQObject ) + objects.setName( objectNo, + DomTool::readProperty(elem, "name", "").asString() ); + return objectNo; +} + +static void outputBlock( TQDataStream& out, BlockTag tag, + const TQByteArray& data ) +{ + if ( !data.isEmpty() ) { + out << (Q_UINT8) tag; + packByteArray( out, data ); + } +} + +void convertUiToUib( TQDomDocument& doc, TQDataStream& out ) +{ + TQByteArray introBlock; + TQByteArray actionsBlock; + TQByteArray buddiesBlock; + TQByteArray connectionsBlock; + TQByteArray functionsBlock; + TQByteArray imagesBlock; + TQByteArray menubarBlock; + TQByteArray slotsBlock; + TQByteArray tabstopsBlock; + TQByteArray toolbarsBlock; + TQByteArray variablesBlock; + TQByteArray widgetBlock; + + TQDomElement actionsElem; + TQDomElement connectionsElem; + TQDomElement imagesElem; + TQDomElement menubarElem; + TQDomElement tabstopsElem; + TQDomElement toolbarsElem; + TQDomElement widgetElem; + + TQMap<int, TQStringList> buddies; + UibStrTable strings; + UibIndexMap objects; + int widgetNo = -1; + TQCString className; + Q_INT16 defaultMargin = -32768; + Q_INT16 defaultSpacing = -32768; + Q_UINT8 introFlags = 0; + + TQDomElement elem = doc.firstChild().toElement().firstChild().toElement(); + while ( !elem.isNull() ) { + TQString tag = elem.tagName(); + + switch ( tag[0].latin1() ) { + case 'a': + if ( tag == "actions" ) + actionsElem = elem; + break; + case 'c': + if ( tag == "class" ) { + className = elem.firstChild().toText().data().latin1(); + } else if ( tag == "connections" ) { + connectionsElem = elem; + } + break; + case 'f': + if ( tag == "functions" ) { + TQDataStream out2( functionsBlock, IO_WriteOnly ); + TQDomElement f = elem.firstChild().toElement(); + while ( !f.isNull() ) { + if ( f.tagName() == "function" ) { + packStringSplit( strings, out2, + f.attribute("name").latin1(), '(' ); + packString( strings, out2, + f.firstChild().toText().data() ); + } + f = f.nextSibling().toElement(); + } + } + break; + case 'i': + if ( tag == "images" ) { + TQDataStream out2( imagesBlock, IO_WriteOnly ); + TQDomElement f = elem.firstChild().toElement(); + while ( !f.isNull() ) { + if ( f.tagName() == "image" ) { + TQString name = f.attribute( "name" ); + TQDomElement g = f.firstChild().toElement(); + if ( g.tagName() == "data" ) { + TQString format = g.attribute( "format", "PNG" ); + TQString hex = g.firstChild().toText().data(); + int n = hex.length() / 2; + TQByteArray data( n ); + for ( int i = 0; i < n; i++ ) + data[i] = (char) hex.mid( 2 * i, 2 ) + .toUInt( 0, 16 ); + + packString( strings, out2, name ); + packString( strings, out2, format ); + packUInt32( out2, g.attribute("length").toInt() ); + packByteArray( out2, data ); + } + } + f = f.nextSibling().toElement(); + } + } + break; + case 'l': + if ( tag == "layoutdefaults" ) { + TQString margin = elem.attribute( "margin" ); + if ( !margin.isEmpty() ) + defaultMargin = margin.toInt(); + TQString spacing = elem.attribute( "spacing" ); + if ( !spacing.isEmpty() ) + defaultSpacing = spacing.toInt(); + } + break; + case 'm': + if ( tag == "menubar" ) + menubarElem = elem; + break; + case 'p': + if ( tag == "pixmapinproject" ) + introFlags |= Intro_Pixmapinproject; + break; + case 's': + if ( tag == "slots" ) { + TQDataStream out2( slotsBlock, IO_WriteOnly ); + TQDomElement f = elem.firstChild().toElement(); + while ( !f.isNull() ) { + if ( f.tagName() == "slot" ) { + TQString language = f.attribute( "language", "C++" ); + TQString slot = UibHack::normalize( + f.firstChild().toText().data() ); + packString( strings, out2, language ); + packStringSplit( strings, out2, slot, '(' ); + } + f = f.nextSibling().toElement(); + } + } + break; + case 't': + if ( tag == "tabstops" ) { + tabstopsElem = elem; + } else if ( tag == "toolbars" ) { + toolbarsElem = elem; + } + break; + case 'v': + if ( tag == "variable" ) { + TQDataStream out2( variablesBlock, IO_WriteOnly | IO_Append ); + packString( strings, out2, elem.firstChild().toText().data() ); + } else if ( tag == "variables" ) { + TQDataStream out2( variablesBlock, IO_WriteOnly ); + TQDomElement f = elem.firstChild().toElement(); + while ( !f.isNull() ) { + if ( f.tagName() == "variable" ) + packString( strings, out2, + f.firstChild().toText().data() ); + f = f.nextSibling().toElement(); + } + } + break; + case 'w': + if ( tag == "widget" ) + widgetElem = elem; + } + elem = elem.nextSibling().toElement(); + } + + { + TQDataStream out2( widgetBlock, IO_WriteOnly ); + widgetNo = outputObject( buddies, objects, strings, out2, widgetElem, + "TQWidget" ); + } + + if ( !tabstopsElem.isNull() ) { + TQDataStream out2( tabstopsBlock, IO_WriteOnly ); + TQDomElement f = tabstopsElem.firstChild().toElement(); + while ( !f.isNull() ) { + if ( f.tagName() == "tabstop" ) { + TQString widgetName = f.firstChild().toText().data(); + int no = objects.find( widgetName ); + if ( no != -1 ) + packUInt16( out2, no ); + } + f = f.nextSibling().toElement(); + } + } + + if ( !actionsElem.isNull() ) { + TQDataStream out2( actionsBlock, IO_WriteOnly ); + outputObject( buddies, objects, strings, out2, actionsElem ); + } + + if ( !menubarElem.isNull() ) { + TQDataStream out2( menubarBlock, IO_WriteOnly ); + outputObject( buddies, objects, strings, out2, menubarElem, + "TQMenuBar" ); + } + + if ( !toolbarsElem.isNull() ) { + TQDataStream out2( toolbarsBlock, IO_WriteOnly ); + TQDomElement f = toolbarsElem.firstChild().toElement(); + while ( !f.isNull() ) { + if ( f.tagName() == "toolbar" ) + outputObject( buddies, objects, strings, out2, f, "TQToolBar" ); + f = f.nextSibling().toElement(); + } + } + + if ( !buddies.isEmpty() ) { + TQDataStream out2( buddiesBlock, IO_WriteOnly ); + TQMap<int, TQStringList>::ConstIterator a = buddies.begin(); + while ( a != buddies.end() ) { + TQStringList::ConstIterator b = (*a).begin(); + while ( b != (*a).end() ) { + int no = objects.find( *b ); + if ( no != -1 ) { + packUInt16( out2, a.key() ); + packUInt16( out2, no ); + } + ++b; + } + ++a; + } + } + + if ( !connectionsElem.isNull() ) { + TQString prevLanguage = "C++"; + int prevSenderNo = 0; + TQString prevSignal = "clicked()"; + int prevReceiverNo = 0; + TQString prevSlot = "accept()"; + + TQDataStream out2( connectionsBlock, IO_WriteOnly ); + TQDomElement f = connectionsElem.firstChild().toElement(); + while ( !f.isNull() ) { + if ( f.tagName() == "connection" ) { + TQMap<TQString, TQString> argMap; + + TQDomElement g = f.firstChild().toElement(); + while ( !g.isNull() ) { + argMap[g.tagName()] = g.firstChild().toText().data(); + g = g.nextSibling().toElement(); + } + + TQString language = f.attribute( "language", "C++" ); + int senderNo = objects.find( argMap["sender"], widgetNo ); + int receiverNo = objects.find( argMap["receiver"], widgetNo ); + TQString signal = UibHack::normalize( argMap["signal"] ); + TQString slot = UibHack::normalize( argMap["slot"] ); + + Q_UINT8 connectionFlags = 0; + if ( language != prevLanguage ) + connectionFlags |= Connection_Language; + if ( senderNo != prevSenderNo ) + connectionFlags |= Connection_Sender; + if ( signal != prevSignal ) + connectionFlags |= Connection_Signal; + if ( receiverNo != prevReceiverNo ) + connectionFlags |= Connection_Receiver; + if ( slot != prevSlot ) + connectionFlags |= Connection_Slot; + out2 << connectionFlags; + + if ( connectionFlags & Connection_Language ) + packString( strings, out2, language ); + if ( connectionFlags & Connection_Sender ) + packUInt16( out2, senderNo ); + if ( connectionFlags & Connection_Signal ) + packStringSplit( strings, out2, signal, '(' ); + if ( connectionFlags & Connection_Receiver ) + packUInt16( out2, receiverNo ); + if ( connectionFlags & Connection_Slot ) + packStringSplit( strings, out2, slot, '(' ); + + prevLanguage = language; + prevSenderNo = senderNo; + prevSignal = signal; + prevReceiverNo = receiverNo; + prevSlot = slot; + } else if ( f.tagName() == "slot" ) { + // ### + } + f = f.nextSibling().toElement(); + } + } + + { + TQDataStream out2( introBlock, IO_WriteOnly ); + out2 << introFlags; + out2 << defaultMargin; + out2 << defaultSpacing; + packUInt16( out2, objects.count() ); + packCString( strings, out2, className ); + } + + out << UibMagic; + out << (Q_UINT8) '\n'; + out << (Q_UINT8) '\r'; + out << (Q_UINT8) out.version(); + outputBlock( out, Block_Strings, strings.block() ); + outputBlock( out, Block_Intro, introBlock ); + outputBlock( out, Block_Images, imagesBlock ); + outputBlock( out, Block_Widget, widgetBlock ); + outputBlock( out, Block_Slots, slotsBlock ); + outputBlock( out, Block_Tabstops, tabstopsBlock ); + outputBlock( out, Block_Actions, actionsBlock ); + outputBlock( out, Block_Menubar, menubarBlock ); + outputBlock( out, Block_Toolbars, toolbarsBlock ); + outputBlock( out, Block_Variables, variablesBlock ); + outputBlock( out, Block_Functions, functionsBlock ); + outputBlock( out, Block_Buddies, buddiesBlock ); + outputBlock( out, Block_Connections, connectionsBlock ); + out << (Q_UINT8) Block_End; +} diff --git a/tools/designer/shared/ui2uib.h b/tools/designer/shared/ui2uib.h new file mode 100644 index 000000000..30b4783f9 --- /dev/null +++ b/tools/designer/shared/ui2uib.h @@ -0,0 +1,42 @@ +/********************************************************************** +** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef UI2UIB_H +#define UI2UIB_H + +class TQDataStream; +class TQDomDocument; + +void convertUiToUib( TQDomDocument& doc, TQDataStream& out ); + +#endif diff --git a/tools/designer/shared/uib.cpp b/tools/designer/shared/uib.cpp new file mode 100644 index 000000000..83ba31efb --- /dev/null +++ b/tools/designer/shared/uib.cpp @@ -0,0 +1,49 @@ +/********************************************************************** +** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "uib.h" + +static const char commonStrings[] = + "\0()\0(bool)\0(const TQString&)\0(int)\0C++\0Layout1\0PNG\0TQCheckBox\0" + "TQComboBox\0TQDialog\0TQFrame\0TQGridLayout\0TQGroupBox\0TQHBoxLayout\0TQLabel\0" + "TQLineEdit\0TQListView\0TQPushButton\0TQRadioButton\0TQVBoxLayout\0TQWidget\0" + "TextLabel1\0XPM.GZ\0accept\0autoDefault\0buddy\0caption\0clicked\0" + "default\0destroy\0frameShadow\0frameShape\0geometry\0init\0margin\0" + "maximumSize\0minimumSize\0name\0reject\0sizePolicy\0spacing\0text\0title\0" + "toolTip\0unnamed\0whatsThis"; + +UibStrTable::UibStrTable() + : out( table, IO_WriteOnly ), start( sizeof(commonStrings) ) +{ + out.writeRawBytes( commonStrings, start ); +} diff --git a/tools/designer/shared/uib.h b/tools/designer/shared/uib.h new file mode 100644 index 000000000..b05982581 --- /dev/null +++ b/tools/designer/shared/uib.h @@ -0,0 +1,159 @@ +/********************************************************************** +** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef UIB_H +#define UIB_H + +#include <qdatastream.h> + +const Q_UINT32 UibMagic = 0xb77c61d8; + +enum BlockTag { Block_End = '$', Block_Actions = 'A', Block_Buddies = 'B', + Block_Connections = 'C', Block_Functions = 'F', + Block_Images = 'G', Block_Intro = 'I', Block_Menubar = 'M', + Block_Slots = 'S', Block_Strings = 'Z', Block_Tabstops = 'T', + Block_Toolbars = 'O', Block_Variables = 'V', + Block_Widget = 'W' }; + +enum ObjectTag { Object_End = '$', Object_ActionRef = 'X', + Object_Attribute = 'B', Object_Column = 'C', + Object_Event = 'E', Object_FontProperty = 'F', + Object_GridCell = 'G', Object_Item = 'I', + Object_MenuItem = 'M', Object_PaletteProperty = 'P', + Object_Row = 'R', Object_Separator = 'S', Object_Spacer = 'Y', + Object_SubAction = 'A', Object_SubLayout = 'L', + Object_SubWidget = 'W', Object_TextProperty = 'T', + Object_VariantProperty = 'V' }; + +enum PaletteTag { Palette_End = '$', Palette_Active = 'A', + Palette_Inactive = 'I', Palette_Disabled = 'D', + Palette_Color = 'C', Palette_Pixmap = 'P' }; + +enum IntroFlag { Intro_Pixmapinproject = 0x1 }; + +enum FontFlag { Font_Family = 0x1, Font_PointSize = 0x2, Font_Bold = 0x4, + Font_Italic = 0x8, Font_Underline = 0x10, + Font_StrikeOut = 0x20 }; + +enum ConnectionFlag { Connection_Language = 0x1, Connection_Sender = 0x2, + Connection_Signal = 0x4, Connection_Receiver = 0x8, + Connection_Slot = 0x10 }; + +class UibStrTable +{ +public: + UibStrTable(); + + inline int insertCString( const char *cstr ); + inline int insertString( const TQString& str ); + inline void readBlock( TQDataStream& in, int size ); + + inline const char *asCString( int offset ) const; + inline TQString asString( int offset ) const; + inline TQByteArray block() const; + +private: + TQCString table; + TQDataStream out; + int start; +}; + +/* + uic uses insertCString(), insertString(), and block(); + TQWidgetFactory uses readBlock(), asCString(), and asString(). By + implementing these functions inline, we ensure that the binaries + don't contain needless code. +*/ + +inline int UibStrTable::insertCString( const char *cstr ) +{ + if ( cstr == 0 || cstr[0] == 0 ) { + return 0; + } else { + int nextPos = table.size(); + int len = (int)strlen( cstr ); + int i; + for ( i = 0; i < nextPos - len; i++ ) { + if ( memcmp(table.data() + i, cstr, len + 1) == 0 ) + return i; + } + for ( i = 0; i < len + 1; i++ ) + out << (Q_UINT8) cstr[i]; + return nextPos; + } +} + +inline int UibStrTable::insertString( const TQString& str ) +{ + if ( str.contains('\0') || str[0] == TQChar(0x7f) ) { + int nextPos = table.size(); + out << (Q_UINT8) 0x7f; + out << str; + return nextPos; + } else { + return insertCString( str.utf8() ); + } +} + +inline void UibStrTable::readBlock( TQDataStream& in, int size ) +{ + table.resize( start + size ); + in.readRawBytes( table.data() + start, size ); +} + +inline TQString UibStrTable::asString( int offset ) const +{ + if ( table[offset] == 0x7f ) { + TQDataStream in( table, IO_ReadOnly ); + in.device()->at( offset + 1 ); + TQString str; + in >> str; + return str; + } else { + return TQString::fromUtf8( asCString(offset) ); + } +} + +inline const char *UibStrTable::asCString( int offset ) const +{ + return table.data() + offset; +} + +inline TQByteArray UibStrTable::block() const +{ + TQByteArray block; + block.duplicate( table.data() + start, table.size() - start ); + return block; +} + +#endif diff --git a/tools/designer/shared/widgetdatabase.cpp b/tools/designer/shared/widgetdatabase.cpp new file mode 100644 index 000000000..79a5a2eed --- /dev/null +++ b/tools/designer/shared/widgetdatabase.cpp @@ -0,0 +1,964 @@ +/********************************************************************** +** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "widgetdatabase.h" +#include "../interfaces/widgetinterface.h" + +#include <qapplication.h> +#define NO_STATIC_COLORS +#include <globaldefs.h> +#include <qstrlist.h> +#include <qdict.h> +#include <qfile.h> +#include <qtextstream.h> +#include <qcleanuphandler.h> +#include <qfeatures.h> + +#include <stdlib.h> + +const int dbsize = 300; +const int dbcustom = 200; +const int dbdictsize = 211; +static WidgetDatabaseRecord* db[ dbsize ]; +static TQDict<int> *className2Id = 0; +static int dbcount = 0; +static int dbcustomcount = 200; +static TQStrList *wGroups; +static TQStrList *invisibleGroups; +static bool whatsThisLoaded = FALSE; +static TQPluginManager<WidgetInterface> *widgetPluginManager = 0; +static bool plugins_set_up = FALSE; +static bool was_in_setup = FALSE; + +TQCleanupHandler<TQPluginManager<WidgetInterface> > cleanup_manager; + +WidgetDatabaseRecord::WidgetDatabaseRecord() +{ + isForm = FALSE; + isContainer = FALSE; + icon = 0; + nameCounter = 0; + isCommon = FALSE; + isPlugin = FALSE; +} + +WidgetDatabaseRecord::~WidgetDatabaseRecord() +{ + delete icon; +} + + +/*! + \class WidgetDatabase widgetdatabase.h + \brief The WidgetDatabase class holds information about widgets + + The WidgetDatabase holds information about widgets like toolTip(), + iconSet(), ... It works Id-based, so all access functions take the + widget id as parameter. To get the id for a widget (classname), use + idFromClassName(). + + All access functions are static. Having multiple widgetdatabases in + one application doesn't make sense anyway and so you don't need more + than an instance of the widgetdatabase. + + For creating widgets, layouts, etc. see WidgetFactory. +*/ + +/*! + Creates widget database. Does nothing. +*/ + +WidgetDatabase::WidgetDatabase() +{ +} + +/*! Sets up the widget database. If the static widgetdatabase already + exists, the functions returns immediately. +*/ + +void WidgetDatabase::setupDataBase( int id ) +{ + was_in_setup = TRUE; +#ifndef UIC + Q_UNUSED( id ) + if ( dbcount ) + return; +#else + if ( dbcount && id != -2 ) + return; + if ( dbcount && !plugins_set_up ) { + setupPlugins(); + return; + } + if ( dbcount && plugins_set_up) + return; +#endif + + wGroups = new TQStrList; + invisibleGroups = new TQStrList; + invisibleGroups->append( "Forms" ); + invisibleGroups->append( "Temp" ); + className2Id = new TQDict<int>( dbdictsize ); + className2Id->setAutoDelete( TRUE ); + + WidgetDatabaseRecord *r = 0; + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_pushbutton.png"; + r->name = "TQPushButton"; + r->group = widgetGroup( "Buttons" ); + r->toolTip = "Push Button"; + r->isCommon = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_toolbutton.png"; + r->name = "TQToolButton"; + r->group = widgetGroup( "Buttons" ); + r->toolTip = "Tool Button"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_radiobutton.png"; + r->name = "TQRadioButton"; + r->group = widgetGroup( "Buttons" ); + r->toolTip = "Radio Button"; + r->isCommon = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_checkbox.png"; + r->name = "TQCheckBox"; + r->group = widgetGroup( "Buttons" ); + r->toolTip = "Check Box"; + r->isCommon = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_groupbox.png"; + r->name = "TQGroupBox"; + r->group = widgetGroup( "Containers" ); + r->toolTip = "Group Box"; + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_buttongroup.png"; + r->name = "TQButtonGroup"; + r->group = widgetGroup( "Containers" ); + r->toolTip = "Button Group"; + r->isContainer = TRUE; + r->isCommon = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_frame.png"; + r->name = "TQFrame"; + r->group = widgetGroup( "Containers" ); + r->toolTip = "Frame"; + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_tabwidget.png"; + r->name = "TQTabWidget"; + r->group = widgetGroup( "Containers" ); + r->toolTip = "Tabwidget"; + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_widgetstack.png"; + r->name = "TQWidgetStack"; + r->group = widgetGroup( "Containers" ); + r->toolTip = "Widget Stack"; + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_toolbox.png"; + r->name = "TQToolBox"; + r->group = widgetGroup( "Containers" ); + r->toolTip = "Tool Box"; + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_listbox.png"; + r->name = "TQListBox"; + r->group = widgetGroup( "Views" ); + r->toolTip = "List Box"; + r->isCommon = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_listview.png"; + r->name = "TQListView"; + r->group = widgetGroup( "Views" ); + r->toolTip = "List View"; + + append( r ); + +#if !defined(QT_NO_ICONVIEW) || defined(UIC) + r = new WidgetDatabaseRecord; + r->iconSet = "designer_iconview.png"; + r->name = "TQIconView"; + r->group = widgetGroup( "Views" ); + r->toolTip = "Icon View"; + + append( r ); +#endif + +#if !defined(QT_NO_TABLE) + r = new WidgetDatabaseRecord; + r->iconSet = "designer_table.png"; + r->name = "TQTable"; + r->group = widgetGroup( "Views" ); + r->toolTip = "Table"; + + append( r ); +#endif + +#if !defined(QT_NO_SQL) + r = new WidgetDatabaseRecord; + r->iconSet = "designer_datatable.png"; + r->includeFile = "qdatatable.h"; + r->name = "TQDataTable"; + r->group = widgetGroup( "Database" ); + r->toolTip = "Data Table"; + + append( r ); +#endif + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_lineedit.png"; + r->name = "TQLineEdit"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Line Edit"; + r->isCommon = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_spinbox.png"; + r->name = "TQSpinBox"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Spin Box"; + r->isCommon = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_dateedit.png"; + r->name = "TQDateEdit"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Date Edit"; + r->includeFile = "qdatetimeedit.h"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_timeedit.png"; + r->name = "TQTimeEdit"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Time Edit"; + r->includeFile = "qdatetimeedit.h"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_datetimeedit.png"; + r->name = "TQDateTimeEdit"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Date-Time Edit"; + r->includeFile = "qdatetimeedit.h"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_multilineedit.png"; + r->name = "TQMultiLineEdit"; + r->group = widgetGroup( "Temp" ); + r->toolTip = "Multi Line Edit"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_richtextedit.png"; + r->name = "TQTextEdit"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Rich Text Edit"; + r->isCommon = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_combobox.png"; + r->name = "TQComboBox"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Combo Box"; + r->isCommon = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_slider.png"; + r->name = "TQSlider"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Slider"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_scrollbar.png"; + r->name = "TQScrollBar"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Scrollbar"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_dial.png"; + r->name = "TQDial"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Dial"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_label.png"; + r->name = "TQLabel"; + r->group = widgetGroup( "Temp" ); + r->toolTip = "Label"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_label.png"; + r->name = "TextLabel"; + r->group = widgetGroup( "Display" ); + r->toolTip = "Text Label"; + r->whatsThis = "The Text Label provides a widget to display static text."; + r->isCommon = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_pixlabel.png"; + r->name = "PixmapLabel"; + r->group = widgetGroup( "Display" ); + r->toolTip = "Pixmap Label"; + r->whatsThis = "The Pixmap Label provides a widget to display pixmaps."; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_lcdnumber.png"; + r->name = "TQLCDNumber"; + r->group = widgetGroup( "Display" ); + r->toolTip = "LCD Number"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_line.png"; + r->name = "Line"; + r->group = widgetGroup( "Display" ); + r->toolTip = "Line"; + r->includeFile = "qframe.h"; + r->whatsThis = "The Line widget provides horizontal and vertical lines."; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_progress.png"; + r->name = "TQProgressBar"; + r->group = widgetGroup( "Display" ); + r->toolTip = "Progress Bar"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_textview.png"; + r->name = "TQTextView"; + r->group = widgetGroup( "Temp" ); + r->toolTip = "Text View"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_textbrowser.png"; + r->name = "TQTextBrowser"; + r->group = widgetGroup( "Display" ); + r->toolTip = "Text Browser"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_spacer.png"; + r->name = "Spacer"; + r->group = widgetGroup( "Temp" ); + r->toolTip = "Spacer"; + r->whatsThis = "The Spacer provides horizontal and vertical spacing to be able to manipulate the behaviour of layouts."; + + append( r ); + + r = new WidgetDatabaseRecord; + r->name = "TQWidget"; + r->isForm = TRUE; + r->group = widgetGroup( "Forms" ); + + append( r ); + + r = new WidgetDatabaseRecord; + r->name = "TQDialog"; + r->group = widgetGroup( "Forms" ); + r->isForm = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->name = "TQWizard"; + r->group = widgetGroup( "Forms" ); + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->name = "TQDesignerWizard"; + r->group = widgetGroup( "Forms" ); + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->name = "TQLayoutWidget"; + r->group = widgetGroup( "Temp" ); + r->includeFile = ""; + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->name = "TQSplitter"; + r->group = widgetGroup( "Temp" ); + r->includeFile = "qsplitter.h"; + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_tabwidget.png"; + r->name = "TQDesignerTabWidget"; + r->group = widgetGroup( "Temp" ); + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_tabwidget.png"; + r->name = "TQDesignerWidget"; + r->group = widgetGroup( "Temp" ); + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_tabwidget.png"; + r->name = "TQDesignerDialog"; + r->group = widgetGroup( "Temp" ); + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = ""; + r->name = "TQMainWindow"; + r->includeFile = "qmainwindow.h"; + r->group = widgetGroup( "Temp" ); + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = ""; + r->name = "TQDesignerAction"; + r->includeFile = "qaction.h"; + r->group = widgetGroup( "Temp" ); + r->isContainer = FALSE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = ""; + r->name = "TQDesignerActionGroup"; + r->includeFile = "qaction.h"; + r->group = widgetGroup( "Temp" ); + r->isContainer = FALSE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = ""; + r->name = "TQScrollView"; + r->includeFile = "qscrollview.h"; + r->group = widgetGroup( "Temp" ); + r->isContainer = TRUE; + + append( r ); + +#ifndef QT_NO_SQL + r = new WidgetDatabaseRecord; + r->iconSet = ""; + r->name = "TQDataBrowser"; + r->includeFile = "qdatabrowser.h"; + r->group = widgetGroup( "Database" ); + r->toolTip = "Data Browser"; + r->iconSet = "designer_databrowser.png"; + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = ""; + r->name = "TQDataView"; + r->includeFile = "qdataview.h"; + r->group = widgetGroup( "Database" ); + r->toolTip = "Data View"; + r->iconSet = "designer_dataview.png"; + r->isContainer = TRUE; + + append( r ); +#endif + +#ifndef UIC + setupPlugins(); +#endif +} + +void WidgetDatabase::setupPlugins() +{ + if ( plugins_set_up ) + return; + plugins_set_up = TRUE; + TQStringList widgets = widgetManager()->featureList(); + for ( TQStringList::Iterator it = widgets.begin(); it != widgets.end(); ++it ) { + if ( hasWidget( *it ) ) + continue; + WidgetDatabaseRecord *r = new WidgetDatabaseRecord; + WidgetInterface *iface = 0; + widgetManager()->queryInterface( *it, &iface ); + if ( !iface ) + continue; + +#ifndef UIC + TQIconSet icon = iface->iconSet( *it ); + if ( !icon.pixmap().isNull() ) + r->icon = new TQIconSet( icon ); +#endif + TQString grp = iface->group( *it ); + if ( grp.isEmpty() ) + grp = "3rd party widgets"; + r->group = widgetGroup( grp ); + r->toolTip = iface->toolTip( *it ); + r->whatsThis = iface->whatsThis( *it ); + r->includeFile = iface->includeFile( *it ); + r->isContainer = iface->isContainer( *it ); + r->name = *it; + r->isPlugin = TRUE; + append( r ); + iface->release(); + } +} + +/*! + Returns the number of elements in the widget database. +*/ + +int WidgetDatabase::count() +{ + setupDataBase( -1 ); + return dbcount; +} + +/*! + Returns the id at which the ids of custom widgets start. +*/ + +int WidgetDatabase::startCustom() +{ + setupDataBase( -1 ); + return dbcustom; +} + +/*! + Returns the iconset which represents the class registered as \a id. +*/ + +TQIconSet WidgetDatabase::iconSet( int id ) +{ + setupDataBase( id ); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return TQIconSet(); +#if !defined(UIC) && !defined(RESOURCE) + if ( !r->icon ) { + if ( r->iconSet.isEmpty() ) + return TQIconSet(); + TQPixmap pix = TQPixmap::fromMimeSource( r->iconSet ); + if ( pix.isNull() ) + pix = TQPixmap( r->iconSet ); + r->icon = new TQIconSet( pix ); + } + return *r->icon; +#else + return TQIconSet(); +#endif +} + +/*! + Returns the classname of the widget which is registered as \a id. +*/ + +TQString WidgetDatabase::className( int id ) +{ + setupDataBase( id ); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return TQString::null; + return r->name; +} + +/*! + Returns the group the widget registered as \a id belongs to. +*/ + +TQString WidgetDatabase::group( int id ) +{ + setupDataBase( id ); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return TQString::null; + return r->group; +} + +/*! + Returns the tooltip text of the widget which is registered as \a id. +*/ + +TQString WidgetDatabase::toolTip( int id ) +{ + setupDataBase( id ); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return TQString::null; + return r->toolTip; +} + +/*! + Returns the what's this? text of the widget which is registered as \a id. +*/ + +TQString WidgetDatabase::whatsThis( int id ) +{ + setupDataBase( id ); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return TQString::null; + return r->whatsThis; +} + +/*! + Returns the include file if the widget which is registered as \a id. +*/ + +TQString WidgetDatabase::includeFile( int id ) +{ + setupDataBase( id ); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return TQString::null; + if ( r->includeFile.isNull() ) { + TQString rq = r->name; + if ( rq[ 0 ] == 'T' && rq[ 1 ] == 'Q') + rq = rq.mid(1); + return rq.lower() + ".h"; + } + return r->includeFile; +} + +/*! Returns whether the widget registered as \a id is a form. +*/ +bool WidgetDatabase::isForm( int id ) +{ + setupDataBase( id ); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return FALSE; + return r->isForm; +} + +/*! Returns whether the widget registered as \a id can have children. +*/ + +bool WidgetDatabase::isContainer( int id ) +{ + setupDataBase( id ); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return FALSE; + return r->isContainer || r->isForm; +} + +bool WidgetDatabase::isCommon( int id ) +{ + setupDataBase( id ); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return FALSE; + return r->isCommon; +} + +TQString WidgetDatabase::createWidgetName( int id ) +{ + setupDataBase( id ); + TQString n = className( id ); + if ( n == "TQLayoutWidget" ) + n = "Layout"; + if ( n[ 0 ] == 'T' && n[ 1 ] == 'Q' && n[ 2 ].lower() != n[ 2 ] ) + n = n.mid( 2 ); + int colonColon = n.findRev( "::" ); + if ( colonColon != -1 ) + n = n.mid( colonColon + 2 ); + + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return n; + n += TQString::number( ++r->nameCounter ); + n[0] = n[0].lower(); + return n; +} + +/*! Returns the id for \a name or -1 if \a name is unknown. + */ +int WidgetDatabase::idFromClassName( const TQString &name ) +{ + setupDataBase( -1 ); + if ( name.isEmpty() ) + return 0; + int *i = className2Id->find( name ); + if ( i ) + return *i; + if ( name == "FormWindow" ) + return idFromClassName( "TQLayoutWidget" ); +#ifdef UIC + setupDataBase( -2 ); + i = className2Id->find( name ); + if ( i ) + return *i; +#endif + return -1; +} + +bool WidgetDatabase::hasWidget( const TQString &name ) +{ + return className2Id->find( name ) != 0; +} + +WidgetDatabaseRecord *WidgetDatabase::at( int index ) +{ + if ( index < 0 ) + return 0; + if ( index >= dbcustom && index < dbcustomcount ) + return db[ index ]; + if ( index < dbcount ) + return db[ index ]; + return 0; +} + +void WidgetDatabase::insert( int index, WidgetDatabaseRecord *r ) +{ + if ( index < 0 || index >= dbsize ) + return; + db[ index ] = r; + className2Id->insert( r->name, new int( index ) ); + if ( index < dbcustom ) + dbcount = TQMAX( dbcount, index ); +} + +void WidgetDatabase::append( WidgetDatabaseRecord *r ) +{ + if ( !was_in_setup ) + setupDataBase( -1 ); + insert( dbcount++, r ); +} + +TQString WidgetDatabase::widgetGroup( const TQString &g ) +{ + if ( wGroups->find( g ) == -1 ) + wGroups->append( g ); + return g; +} + +bool WidgetDatabase::isGroupEmpty( const TQString &grp ) +{ + WidgetDatabaseRecord *r = 0; + for ( int i = 0; i < dbcount; ++i ) { + if ( !( r = db[ i ] ) ) + continue; + if ( r->group == grp ) + return FALSE; + } + return TRUE; +} + +TQString WidgetDatabase::widgetGroup( int i ) +{ + setupDataBase( -1 ); + if ( i >= 0 && i < (int)wGroups->count() ) + return wGroups->at( i ); + return TQString::null; +} + +int WidgetDatabase::numWidgetGroups() +{ + setupDataBase( -1 ); + return wGroups->count(); +} + +bool WidgetDatabase::isGroupVisible( const TQString &g ) +{ + setupDataBase( -1 ); + return invisibleGroups->find( g ) == -1; +} + +int WidgetDatabase::addCustomWidget( WidgetDatabaseRecord *r ) +{ + insert( dbcustomcount++, r ); + return dbcustomcount - 1; +} + +void WidgetDatabase::customWidgetClassNameChanged( const TQString &oldName, + const TQString &newName ) +{ + int id = idFromClassName( oldName ); + if ( id == -1 ) + return; + WidgetDatabaseRecord *r = db[ id ]; + r->name = newName; + className2Id->remove( oldName ); + className2Id->insert( newName, new int( id ) ); +} + +bool WidgetDatabase::isCustomWidget( int id ) +{ + if ( id >= dbcustom && id < dbcustomcount ) + return TRUE; + return FALSE; +} + +bool WidgetDatabase::isCustomPluginWidget( int id ) +{ + setupDataBase( id ); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return FALSE; + return r->isPlugin; +} + +bool WidgetDatabase::isWhatsThisLoaded() +{ + return whatsThisLoaded; +} + +void WidgetDatabase::loadWhatsThis( const TQString &docPath ) +{ + TQString whatsthisFile = docPath + "/whatsthis"; + TQFile f( whatsthisFile ); + if ( !f.open( IO_ReadOnly ) ) + return; + TQTextStream ts( &f ); + while ( !ts.atEnd() ) { + TQString s = ts.readLine(); + TQStringList l = TQStringList::split( " | ", s ); + int id = idFromClassName( l[ 1 ] ); + WidgetDatabaseRecord *r = at( id ); + if ( r ) + r->whatsThis = l[ 0 ]; + } + whatsThisLoaded = TRUE; +} + + +// ### TQt 3.1: make these publically accessible via TQWidgetDatabase API +#if defined(UIC) +bool dbnounload = FALSE; +TQStringList *dbpaths = 0; +#else +extern TQString *qwf_plugin_dir; +#endif + + +TQPluginManager<WidgetInterface> *widgetManager() +{ + if ( !widgetPluginManager ) { + TQString pluginDir = "/designer"; +#if !defined(UIC) + if ( qwf_plugin_dir ) + pluginDir = *qwf_plugin_dir; +#endif + widgetPluginManager = new TQPluginManager<WidgetInterface>( IID_Widget, TQApplication::libraryPaths(), pluginDir ); + cleanup_manager.add( &widgetPluginManager ); +#if defined(UIC) + if ( dbnounload ) + widgetPluginManager->setAutoUnload( FALSE ); + if ( dbpaths ) { + TQStringList::ConstIterator it = dbpaths->begin(); + for ( ; it != dbpaths->end(); ++it ) + widgetPluginManager->addLibraryPath( *it ); + } +#endif + } + return widgetPluginManager; +} diff --git a/tools/designer/shared/widgetdatabase.h b/tools/designer/shared/widgetdatabase.h new file mode 100644 index 000000000..d2e099a65 --- /dev/null +++ b/tools/designer/shared/widgetdatabase.h @@ -0,0 +1,103 @@ +/********************************************************************** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing retquirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at [email protected]. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef WIDGETDATABASE_H +#define WIDGETDATABASE_H + +#include <qiconset.h> +#include <qstring.h> +#include "../interfaces/widgetinterface.h" // up here for GCC 2.7.* compatibility +#include <private/qpluginmanager_p.h> + + +extern TQPluginManager<WidgetInterface> *widgetManager(); + +struct WidgetDatabaseRecord +{ + WidgetDatabaseRecord(); + ~WidgetDatabaseRecord(); + TQString iconSet, name, group, toolTip, whatsThis, includeFile; + uint isContainer : 1; + uint isForm : 1; + uint isCommon : 1; + uint isPlugin : 1; + TQIconSet *icon; + int nameCounter; +}; + +class WidgetDatabase : public TQt +{ +public: + WidgetDatabase(); + static void setupDataBase( int id ); + static void setupPlugins(); + + static int count(); + static int startCustom(); + + static TQIconSet iconSet( int id ); + static TQString className( int id ); + static TQString group( int id ); + static TQString toolTip( int id ); + static TQString whatsThis( int id ); + static TQString includeFile( int id ); + static bool isForm( int id ); + static bool isContainer( int id ); + static bool isCommon( int id ); + + static int idFromClassName( const TQString &name ); + static TQString createWidgetName( int id ); + + static WidgetDatabaseRecord *at( int index ); + static void insert( int index, WidgetDatabaseRecord *r ); + static void append( WidgetDatabaseRecord *r ); + + static TQString widgetGroup( const TQString &g ); + static TQString widgetGroup( int i ); + static int numWidgetGroups(); + static bool isGroupVisible( const TQString &g ); + static bool isGroupEmpty( const TQString &grp ); + + static int addCustomWidget( WidgetDatabaseRecord *r ); + static bool isCustomWidget( int id ); + static bool isCustomPluginWidget( int id ); + + static bool isWhatsThisLoaded(); + static void loadWhatsThis( const TQString &docPath ); + + static bool hasWidget( const TQString &name ); + static void customWidgetClassNameChanged( const TQString &oldName, const TQString &newName ); + +}; + +#endif |