diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 114a878c64ce6f8223cfd22d76a20eb16d177e5e (patch) | |
tree | acaf47eb0fa12142d3896416a69e74cbf5a72242 /kdevdesigner/shared | |
download | tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.tar.gz tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kdevdesigner/shared')
-rw-r--r-- | kdevdesigner/shared/Makefile.am | 6 | ||||
-rw-r--r-- | kdevdesigner/shared/domtool.cpp | 453 | ||||
-rw-r--r-- | kdevdesigner/shared/domtool.h | 53 | ||||
-rw-r--r-- | kdevdesigner/shared/globaldefs.h | 62 | ||||
-rw-r--r-- | kdevdesigner/shared/parser.cpp | 72 | ||||
-rw-r--r-- | kdevdesigner/shared/parser.h | 39 | ||||
-rw-r--r-- | kdevdesigner/shared/ui2uib.cpp | 893 | ||||
-rw-r--r-- | kdevdesigner/shared/ui2uib.h | 35 | ||||
-rw-r--r-- | kdevdesigner/shared/uib.cpp | 42 | ||||
-rw-r--r-- | kdevdesigner/shared/uib.h | 152 | ||||
-rw-r--r-- | kdevdesigner/shared/widgetdatabase.cpp | 960 | ||||
-rw-r--r-- | kdevdesigner/shared/widgetdatabase.h | 96 |
12 files changed, 2863 insertions, 0 deletions
diff --git a/kdevdesigner/shared/Makefile.am b/kdevdesigner/shared/Makefile.am new file mode 100644 index 00000000..ea86ae94 --- /dev/null +++ b/kdevdesigner/shared/Makefile.am @@ -0,0 +1,6 @@ +KDE_CXXFLAGS = -UQT_NO_ASCII_CAST +INCLUDES = -I$(top_srcdir)/lib/interfaces/external $(all_includes) +METASOURCES = AUTO +libshared_la_LDFLAGS = $(all_libraries) +noinst_LTLIBRARIES = libshared.la +libshared_la_SOURCES = domtool.cpp parser.cpp ui2uib.cpp uib.cpp widgetdatabase.cpp diff --git a/kdevdesigner/shared/domtool.cpp b/kdevdesigner/shared/domtool.cpp new file mode 100644 index 00000000..492ce88e --- /dev/null +++ b/kdevdesigner/shared/domtool.cpp @@ -0,0 +1,453 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qt Designer. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include "domtool.h" + +#include <qsizepolicy.h> +#include <qcolor.h> +#include <qcursor.h> +#include <qdatetime.h> +#include <qrect.h> +#include <qsize.h> +#include <qfont.h> +#include <qdom.h> + +/*! + \class DomTool domtool.h + \brief Tools for the dom + + A collection of static functions used by Resource (part of the + designer) and Uic. + +*/ + +/*! + Returns the contents of property \a name of object \a e as + variant or the variant passed as \a defValue if the property does + not exist. + + \sa hasProperty() +*/ +QVariant DomTool::readProperty( const QDomElement& e, const QString& name, const QVariant& defValue, QString& comment ) +{ + QDomElement n; + for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { + if ( n.tagName() == "property" ) { + if ( n.attribute( "name" ) != name ) + continue; + return elementToVariant( n.firstChild().toElement(), defValue, comment ); + } + } + return defValue; +} + + +/*! + \overload + */ +QVariant DomTool::readProperty( const QDomElement& e, const QString& name, const QVariant& defValue ) +{ + QString comment; + return readProperty( e, name, defValue, comment ); +} + +/*! + Returns wheter object \a e defines property \a name or not. + + \sa readProperty() + */ +bool DomTool::hasProperty( const QDomElement& e, const QString& name ) +{ + QDomElement n; + for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { + if ( n.tagName() == "property" ) { + if ( n.attribute( "name" ) != name ) + continue; + return TRUE; + } + } + return FALSE; +} + +QStringList DomTool::propertiesOfType( const QDomElement& e, const QString& type ) +{ + QStringList result; + QDomElement n; + for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { + if ( n.tagName() == "property" ) { + QDomElement n2 = n.firstChild().toElement(); + if ( n2.tagName() == type ) + result += n.attribute( "name" ); + } + } + return result; +} + + +QVariant DomTool::elementToVariant( const QDomElement& e, const QVariant& defValue ) +{ + QString dummy; + return elementToVariant( e, defValue, dummy ); +} + +/*! + Interprets element \a e as variant and returns the result of the interpretation. + */ +QVariant DomTool::elementToVariant( const QDomElement& e, const QVariant& defValue, QString &comment ) +{ + QVariant v; + if ( e.tagName() == "rect" ) { + QDomElement n3 = e.firstChild().toElement(); + int x = 0, y = 0, w = 0, h = 0; + while ( !n3.isNull() ) { + if ( n3.tagName() == "x" ) + x = n3.firstChild().toText().data().toInt(); + else if ( n3.tagName() == "y" ) + y = n3.firstChild().toText().data().toInt(); + else if ( n3.tagName() == "width" ) + w = n3.firstChild().toText().data().toInt(); + else if ( n3.tagName() == "height" ) + h = n3.firstChild().toText().data().toInt(); + n3 = n3.nextSibling().toElement(); + } + v = QVariant( QRect( x, y, w, h ) ); + } else if ( e.tagName() == "point" ) { + QDomElement n3 = e.firstChild().toElement(); + int x = 0, y = 0; + while ( !n3.isNull() ) { + if ( n3.tagName() == "x" ) + x = n3.firstChild().toText().data().toInt(); + else if ( n3.tagName() == "y" ) + y = n3.firstChild().toText().data().toInt(); + n3 = n3.nextSibling().toElement(); + } + v = QVariant( QPoint( x, y ) ); + } else if ( e.tagName() == "size" ) { + QDomElement n3 = e.firstChild().toElement(); + int w = 0, h = 0; + while ( !n3.isNull() ) { + if ( n3.tagName() == "width" ) + w = n3.firstChild().toText().data().toInt(); + else if ( n3.tagName() == "height" ) + h = n3.firstChild().toText().data().toInt(); + n3 = n3.nextSibling().toElement(); + } + v = QVariant( QSize( w, h ) ); + } else if ( e.tagName() == "color" ) { + v = QVariant( readColor( e ) ); + } else if ( e.tagName() == "font" ) { + QDomElement n3 = e.firstChild().toElement(); + QFont f( defValue.toFont() ); + while ( !n3.isNull() ) { + if ( n3.tagName() == "family" ) + f.setFamily( n3.firstChild().toText().data() ); + else if ( n3.tagName() == "pointsize" ) + f.setPointSize( n3.firstChild().toText().data().toInt() ); + else if ( n3.tagName() == "bold" ) + f.setBold( n3.firstChild().toText().data().toInt() ); + else if ( n3.tagName() == "italic" ) + f.setItalic( n3.firstChild().toText().data().toInt() ); + else if ( n3.tagName() == "underline" ) + f.setUnderline( n3.firstChild().toText().data().toInt() ); + else if ( n3.tagName() == "strikeout" ) + f.setStrikeOut( n3.firstChild().toText().data().toInt() ); + n3 = n3.nextSibling().toElement(); + } + v = QVariant( f ); + } else if ( e.tagName() == "string" ) { + v = QVariant( e.firstChild().toText().data() ); + QDomElement n = e; + n = n.nextSibling().toElement(); + if ( n.tagName() == "comment" ) + comment = n.firstChild().toText().data(); + } else if ( e.tagName() == "cstring" ) { + v = QVariant( QCString( e.firstChild().toText().data() ) ); + } else if ( e.tagName() == "number" ) { + bool ok = TRUE; + v = QVariant( e.firstChild().toText().data().toInt( &ok ) ); + if ( !ok ) + v = QVariant( e.firstChild().toText().data().toDouble() ); + } else if ( e.tagName() == "bool" ) { + QString t = e.firstChild().toText().data(); + v = QVariant( t == "true" || t == "1", 0 ); + } else if ( e.tagName() == "pixmap" ) { + v = QVariant( e.firstChild().toText().data() ); + } else if ( e.tagName() == "iconset" ) { + v = QVariant( e.firstChild().toText().data() ); + } else if ( e.tagName() == "image" ) { + v = QVariant( e.firstChild().toText().data() ); + } else if ( e.tagName() == "enum" ) { + v = QVariant( e.firstChild().toText().data() ); + } else if ( e.tagName() == "set" ) { + v = QVariant( e.firstChild().toText().data() ); + } else if ( e.tagName() == "sizepolicy" ) { + QDomElement n3 = e.firstChild().toElement(); + QSizePolicy sp; + while ( !n3.isNull() ) { + if ( n3.tagName() == "hsizetype" ) + sp.setHorData( (QSizePolicy::SizeType)n3.firstChild().toText().data().toInt() ); + else if ( n3.tagName() == "vsizetype" ) + sp.setVerData( (QSizePolicy::SizeType)n3.firstChild().toText().data().toInt() ); + else if ( n3.tagName() == "horstretch" ) + sp.setHorStretch( n3.firstChild().toText().data().toInt() ); + else if ( n3.tagName() == "verstretch" ) + sp.setVerStretch( n3.firstChild().toText().data().toInt() ); + n3 = n3.nextSibling().toElement(); + } + v = QVariant( sp ); + } else if ( e.tagName() == "cursor" ) { + v = QVariant( QCursor( e.firstChild().toText().data().toInt() ) ); + } else if ( e.tagName() == "stringlist" ) { + QStringList lst; + QDomElement n; + for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) + lst << n.firstChild().toText().data(); + v = QVariant( lst ); + } else if ( e.tagName() == "date" ) { + QDomElement n3 = e.firstChild().toElement(); + int y, m, d; + y = m = d = 0; + while ( !n3.isNull() ) { + if ( n3.tagName() == "year" ) + y = n3.firstChild().toText().data().toInt(); + else if ( n3.tagName() == "month" ) + m = n3.firstChild().toText().data().toInt(); + else if ( n3.tagName() == "day" ) + d = n3.firstChild().toText().data().toInt(); + n3 = n3.nextSibling().toElement(); + } + v = QVariant( QDate( y, m, d ) ); + } else if ( e.tagName() == "time" ) { + QDomElement n3 = e.firstChild().toElement(); + int h, m, s; + h = m = s = 0; + while ( !n3.isNull() ) { + if ( n3.tagName() == "hour" ) + h = n3.firstChild().toText().data().toInt(); + else if ( n3.tagName() == "minute" ) + m = n3.firstChild().toText().data().toInt(); + else if ( n3.tagName() == "second" ) + s = n3.firstChild().toText().data().toInt(); + n3 = n3.nextSibling().toElement(); + } + v = QVariant( QTime( h, m, s ) ); + } else if ( e.tagName() == "datetime" ) { + QDomElement n3 = e.firstChild().toElement(); + int h, mi, s, y, mo, d ; + h = mi = s = y = mo = d = 0; + while ( !n3.isNull() ) { + if ( n3.tagName() == "hour" ) + h = n3.firstChild().toText().data().toInt(); + else if ( n3.tagName() == "minute" ) + mi = n3.firstChild().toText().data().toInt(); + else if ( n3.tagName() == "second" ) + s = n3.firstChild().toText().data().toInt(); + else if ( n3.tagName() == "year" ) + y = n3.firstChild().toText().data().toInt(); + else if ( n3.tagName() == "month" ) + mo = n3.firstChild().toText().data().toInt(); + else if ( n3.tagName() == "day" ) + d = n3.firstChild().toText().data().toInt(); + n3 = n3.nextSibling().toElement(); + } + v = QVariant( QDateTime( QDate( y, mo, d ), QTime( h, mi, s ) ) ); + } + return v; +} + + +/*! Returns the color which is returned in the dom element \a e. + */ + +QColor DomTool::readColor( const QDomElement &e ) +{ + QDomElement n = e.firstChild().toElement(); + int r= 0, g = 0, b = 0; + while ( !n.isNull() ) { + if ( n.tagName() == "red" ) + r = n.firstChild().toText().data().toInt(); + else if ( n.tagName() == "green" ) + g = n.firstChild().toText().data().toInt(); + else if ( n.tagName() == "blue" ) + b = n.firstChild().toText().data().toInt(); + n = n.nextSibling().toElement(); + } + + return QColor( r, g, b ); +} + +/*! + Returns the contents of attribute \a name of object \a e as + variant or the variant passed as \a defValue if the attribute does + not exist. + + \sa hasAttribute() + */ +QVariant DomTool::readAttribute( const QDomElement& e, const QString& name, const QVariant& defValue, QString& comment ) +{ + QDomElement n; + for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { + if ( n.tagName() == "attribute" ) { + if ( n.attribute( "name" ) != name ) + continue; + return elementToVariant( n.firstChild().toElement(), defValue, comment ); + } + } + return defValue; +} + +/*! + \overload +*/ +QVariant DomTool::readAttribute( const QDomElement& e, const QString& name, const QVariant& defValue ) +{ + QString comment; + return readAttribute( e, name, defValue, comment ); +} + +/*! + Returns wheter object \a e defines attribute \a name or not. + + \sa readAttribute() + */ +bool DomTool::hasAttribute( const QDomElement& e, const QString& name ) +{ + QDomElement n; + for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { + if ( n.tagName() == "attribute" ) { + if ( n.attribute( "name" ) != name ) + continue; + return TRUE; + } + } + return FALSE; +} + +static bool toBool( const QString& s ) +{ + return s == "true" || s.toInt() != 0; +} + +/*! + Convert Qt 2.x format to Qt 3.0 format if necessary +*/ +void DomTool::fixDocument( QDomDocument& doc ) +{ + QDomElement e; + QDomNode n; + QDomNodeList nl; + int i = 0; + + e = doc.firstChild().toElement(); + if ( e.tagName() != "UI" ) + return; + + // latest version, don't do anything + if ( e.hasAttribute("version") && e.attribute("version").toDouble() > 3.0 ) + return; + + nl = doc.elementsByTagName( "property" ); + + // in 3.0, we need to fix a spelling error + if ( e.hasAttribute("version") && e.attribute("version").toDouble() == 3.0 ) { + for ( i = 0; i < (int) nl.length(); i++ ) { + QDomElement el = nl.item(i).toElement(); + QString s = el.attribute( "name" ); + if ( s == "resizeable" ) { + el.removeAttribute( "name" ); + el.setAttribute( "name", "resizable" ); + } + } + return; + } + + + // in versions smaller than 3.0 we need to change more + e.setAttribute( "version", 3.0 ); + + e.setAttribute("stdsetdef", 1 ); + for ( i = 0; i < (int) nl.length(); i++ ) { + e = nl.item(i).toElement(); + QString name; + QDomElement n2 = e.firstChild().toElement(); + if ( n2.tagName() == "name" ) { + name = n2.firstChild().toText().data(); + if ( name == "resizeable" ) + e.setAttribute( "name", "resizable" ); + else + e.setAttribute( "name", name ); + e.removeChild( n2 ); + } + bool stdset = toBool( e.attribute( "stdset" ) ); + if ( stdset || name == "toolTip" || name == "whatsThis" || + name == "buddy" || + e.parentNode().toElement().tagName() == "item" || + e.parentNode().toElement().tagName() == "spacer" || + e.parentNode().toElement().tagName() == "column" + ) + e.removeAttribute( "stdset" ); + else + e.setAttribute( "stdset", 0 ); + } + + nl = doc.elementsByTagName( "attribute" ); + for ( i = 0; i < (int) nl.length(); i++ ) { + e = nl.item(i).toElement(); + QString name; + QDomElement n2 = e.firstChild().toElement(); + if ( n2.tagName() == "name" ) { + name = n2.firstChild().toText().data(); + e.setAttribute( "name", name ); + e.removeChild( n2 ); + } + } + + nl = doc.elementsByTagName( "image" ); + for ( i = 0; i < (int) nl.length(); i++ ) { + e = nl.item(i).toElement(); + QString name; + QDomElement n2 = e.firstChild().toElement(); + if ( n2.tagName() == "name" ) { + name = n2.firstChild().toText().data(); + e.setAttribute( "name", name ); + e.removeChild( n2 ); + } + } + + nl = doc.elementsByTagName( "widget" ); + for ( i = 0; i < (int) nl.length(); i++ ) { + e = nl.item(i).toElement(); + QString name; + QDomElement n2 = e.firstChild().toElement(); + if ( n2.tagName() == "class" ) { + name = n2.firstChild().toText().data(); + e.setAttribute( "class", name ); + e.removeChild( n2 ); + } + } + +} + diff --git a/kdevdesigner/shared/domtool.h b/kdevdesigner/shared/domtool.h new file mode 100644 index 00000000..61b4269a --- /dev/null +++ b/kdevdesigner/shared/domtool.h @@ -0,0 +1,53 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qt Designer. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef DOMTOOL_H +#define DOMTOOL_H + +#include <qvariant.h> +#include <qnamespace.h> + +class QDomElement; +class QDomDocument; + +class DomTool : public Qt +{ +public: + static QVariant readProperty( const QDomElement& e, const QString& name, const QVariant& defValue ); + static QVariant readProperty( const QDomElement& e, const QString& name, const QVariant& defValue, QString& comment ); + static bool hasProperty( const QDomElement& e, const QString& name ); + static QStringList propertiesOfType( const QDomElement& e, const QString& type ); + static QVariant elementToVariant( const QDomElement& e, const QVariant& defValue ); + static QVariant elementToVariant( const QDomElement& e, const QVariant& defValue, QString &comment ); + static QVariant readAttribute( const QDomElement& e, const QString& name, const QVariant& defValue ); + static QVariant readAttribute( const QDomElement& e, const QString& name, const QVariant& defValue, QString& comment ); + static bool hasAttribute( const QDomElement& e, const QString& name ); + static QColor readColor( const QDomElement &e ); + static void fixDocument( QDomDocument& ); +}; + + +#endif // DOMTOOL_H diff --git a/kdevdesigner/shared/globaldefs.h b/kdevdesigner/shared/globaldefs.h new file mode 100644 index 00000000..653c4fa5 --- /dev/null +++ b/kdevdesigner/shared/globaldefs.h @@ -0,0 +1,62 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qt Designer. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef GLOBALDEFS_H +#define GLOBALDEFS_H + +#include <qcolor.h> +#include <qapplication.h> + +#define BOXLAYOUT_DEFAULT_MARGIN 11 +#define BOXLAYOUT_DEFAULT_SPACING 6 + +#ifndef NO_STATIC_COLORS +static QColor *backColor1 = 0; +static QColor *backColor2 = 0; +static QColor *selectedBack = 0; + +static void init_colors() +{ + if ( backColor1 ) + return; + +#if 0 // a calculated alternative for backColor1 + QColorGroup myCg = qApp->palette().active(); + int h1, s1, v1; + int h2, s2, v2; + myCg.color( QColorGroup::Base ).hsv( &h1, &s1, &v1 ); + myCg.color( QColorGroup::Background ).hsv( &h2, &s2, &v2 ); + QColor c( h1, s1, ( v1 + v2 ) / 2, QColor::Hsv ); +#endif + + backColor1 = new QColor( 250, 248, 235 ); + backColor2 = new QColor( 255, 255, 255 ); + selectedBack = new QColor( 230, 230, 230 ); +} + +#endif + +#endif diff --git a/kdevdesigner/shared/parser.cpp b/kdevdesigner/shared/parser.cpp new file mode 100644 index 00000000..e1b54ca1 --- /dev/null +++ b/kdevdesigner/shared/parser.cpp @@ -0,0 +1,72 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qt Designer. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include "parser.h" +#include <qobject.h> +#include <qstringlist.h> + +class NormalizeObject : public QObject +{ +public: + NormalizeObject() : QObject() {} + static QCString normalizeSignalSlot( const char *signalSlot ) { return QObject::normalizeSignalSlot( signalSlot ); } +}; + +QString Parser::cleanArgs( const QString &func ) +{ + QString slot( func ); + int begin = slot.find( "(" ) + 1; + QString args = slot.mid( begin ); + args = args.left( args.find( ")" ) ); + QStringList lst = QStringList::split( ',', args ); + QString res = slot.left( begin ); + for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { + if ( it != lst.begin() ) + res += ","; + QString arg = *it; + int pos = 0; + if ( ( pos = arg.find( "&" ) ) != -1 ) { + arg = arg.left( pos + 1 ); + } else if ( ( pos = arg.find( "*" ) ) != -1 ) { + arg = arg.left( pos + 1 ); + } else { + arg = arg.simplifyWhiteSpace(); + if ( ( pos = arg.find( ':' ) ) != -1 ) + arg = arg.left( pos ).simplifyWhiteSpace() + ":" + arg.mid( pos + 1 ).simplifyWhiteSpace(); + QStringList l = QStringList::split( ' ', arg ); + if ( l.count() == 2 ) { + if ( l[ 0 ] != "const" && l[ 0 ] != "unsigned" && l[ 0 ] != "var" ) + arg = l[ 0 ]; + } else if ( l.count() == 3 ) { + arg = l[ 0 ] + " " + l[ 1 ]; + } + } + res += arg; + } + res += ")"; + + return QString::fromLatin1( NormalizeObject::normalizeSignalSlot( res.latin1() ) ); +} diff --git a/kdevdesigner/shared/parser.h b/kdevdesigner/shared/parser.h new file mode 100644 index 00000000..10d83027 --- /dev/null +++ b/kdevdesigner/shared/parser.h @@ -0,0 +1,39 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qt Designer. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef PARSER_H +#define PARSER_H + +#include <qstring.h> + +class Parser +{ +public: + static QString cleanArgs( const QString &func ); + +}; + +#endif diff --git a/kdevdesigner/shared/ui2uib.cpp b/kdevdesigner/shared/ui2uib.cpp new file mode 100644 index 00000000..72c09320 --- /dev/null +++ b/kdevdesigner/shared/ui2uib.cpp @@ -0,0 +1,893 @@ +/********************************************************************** +** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. +** +** This file is part of Qt Designer. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include "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 + QWidgetFactory; 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 + QWidgetFactory source code, with some guidance. And here's some + guidance. + + A .uib file starts with a 32-bit magic number that allows + QWidgetFactory 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 QDataStream 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. + QWidgetFactory 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. QObjects 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 QWidgetFactory as new + objects are specified. In ui2uib, the table is represented by + a UibIndexMap object; in QWidgetFactory, a plain array of + QObject pointers suffices. + + 3. The data is packed to take as little place as possible, + without slowing down QLayoutFactory 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 QString&)' is + connected to a slot 'bar(const QString&)', the string-table + will only contain 'foo', 'bar', and '(const QString&)', + instead of the longer 'foo(const QString&)' and 'bar(const + QString&)'. 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 QLayoutFactory. That information is, for now, + not taken along in the .uib file. Likewise, needless + QLayoutWidget 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 QLayoutWidget 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 QCString layoutForTag( const QString& tag ) +{ + if ( tag == "grid" ) { + return "QGridLayout"; + } else if ( tag == "hbox" ) { + return "QHBoxLayout"; + } else if ( tag == "vbox" ) { + return "QVBoxLayout"; + } else { + return "QLayout"; + } +} + +class UibHack : public QObject +{ +public: + static QString normalize( const QString& member ) { + return QString::fromUtf8( QObject::normalizeSignalSlot(member.utf8()) ); + } +}; + +class UibIndexMap +{ +public: + UibIndexMap() : next( 0 ) { } + + void insert( const QString& name ) { setName( insert(), name ); } + int insert() { return next++; } + void setName( int no, const QString& name ); + + int find( const QString& name, int deflt = -1 ) const; + int count() const { return next; } + +private: + QMap<QString, int> nameMap; + QMap<QString, int> conflicts; + int next; +}; + +void UibIndexMap::setName( int no, const QString& name ) +{ + if ( !name.isEmpty() ) { + if ( *nameMap.insert(name, no, FALSE) != no ) + conflicts.insert( name, 0 ); + } +} + +int UibIndexMap::find( const QString& name, int deflt ) const +{ + QMap<QString, int>::ConstIterator no = nameMap.find( name ); + if ( no == nameMap.end() || conflicts.contains(name) ) { + return deflt; + } else { + return *no; + } +} + +static void packUInt16( QDataStream& out, Q_UINT16 n ) +{ + if ( n < 255 ) { + out << (Q_UINT8) n; + } else { + out << (Q_UINT8) 255; + out << n; + } +} + +static void packUInt32( QDataStream& out, Q_UINT32 n ) +{ + if ( n < 65535 ) { + out << (Q_UINT16) n; + } else { + out << (Q_UINT16) 65535; + out << n; + } +} + +static void packByteArray( QDataStream& out, const QByteArray& array ) +{ + packUInt32( out, array.size() ); + out.writeRawBytes( array.data(), array.size() ); +} + +static void packCString( UibStrTable& strings, QDataStream& out, + const char *cstr ) +{ + packUInt32( out, strings.insertCString(cstr) ); +} + +static void packString( UibStrTable& strings, QDataStream& out, + const QString& str ) +{ + packUInt32( out, strings.insertString(str) ); +} + +static void packStringSplit( UibStrTable& strings, QDataStream& out, + const QString& str, QChar 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, QDataStream& out, + QVariant value, QString tag = "" ) +{ + QStringList::ConstIterator s; + + Q_UINT8 type = value.type(); + if ( tag == "pixmap" ) { + type = QVariant::Pixmap; + } else if ( tag == "image" ) { + type = QVariant::Image; + } else if ( tag == "iconset" ) { + type = QVariant::IconSet; + } + out << type; + + switch ( type ) { + case QVariant::String: + case QVariant::Pixmap: + case QVariant::Image: + case QVariant::IconSet: + packString( strings, out, value.asString() ); + break; + case QVariant::StringList: + packUInt16( out, value.asStringList().count() ); + s = value.asStringList().begin(); + while ( s != value.asStringList().end() ) { + packString( strings, out, *s ); + ++s; + } + break; + case QVariant::Font: + out << value.asFont(); + break; + case QVariant::Rect: + packUInt16( out, value.asRect().x() ); + packUInt16( out, value.asRect().y() ); + packUInt16( out, value.asRect().width() ); + packUInt16( out, value.asRect().height() ); + break; + case QVariant::Size: + packUInt16( out, value.asSize().width() ); + packUInt16( out, value.asSize().height() ); + break; + case QVariant::Color: + out << value.asColor(); + break; + case QVariant::Point: + packUInt16( out, value.asPoint().x() ); + packUInt16( out, value.asPoint().y() ); + break; + case QVariant::Int: + packUInt32( out, value.asInt() ); + break; + case QVariant::Bool: + out << (Q_UINT8) value.asBool(); + break; + case QVariant::Double: + out << value.asDouble(); + break; + case QVariant::CString: + packCString( strings, out, value.asCString() ); + break; + case QVariant::Cursor: + out << value.asCursor(); + break; + case QVariant::Date: + out << value.asDate(); + break; + case QVariant::Time: + out << value.asTime(); + break; + case QVariant::DateTime: + out << value.asDateTime(); + break; + default: + out << value; + } +} + +static void outputProperty( QMap<int, QStringList>& buddies, int objectNo, + UibStrTable& strings, QDataStream& out, + QDomElement elem ) +{ + QCString name = elem.attribute( "name" ).latin1(); + QDomElement f = elem.firstChild().toElement(); + QString tag = f.tagName(); + QString comment; + QVariant value; + + if ( name == "resizeable" ) + name = "resizable"; + + if ( tag == "font" ) { + QString family; + Q_UINT16 pointSize = 65535; + Q_UINT8 fontFlags = 0; + + QDomElement g = f.firstChild().toElement(); + while ( !g.isNull() ) { + QString 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 ); + + QDomElement g = f.firstChild().toElement(); + while ( !g.isNull() ) { + QDomElement h = g.firstChild().toElement(); + while ( !h.isNull() ) { + value = DomTool::elementToVariant( h, Qt::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( QDataStream& out, QDomElement 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( QMap<int, QStringList>& buddies, + UibIndexMap& objects, UibStrTable& strings, + QDataStream& out, QDomElement elem, + QCString className = "" ); + +static void outputLayoutWidgetsSubLayout( QMap<int, QStringList>& buddies, + UibIndexMap& objects, + UibStrTable& strings, + QDataStream& out, QDomElement elem ) +{ + int subLayoutNo = -1; + QCString name; + QDomElement nameElem; + + QDomElement f = elem.firstChild().toElement(); + while ( !f.isNull() ) { + QString 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( QMap<int, QStringList>& buddies, + UibIndexMap& objects, UibStrTable& strings, + QDataStream& out, QDomElement elem, + QCString className ) +{ + bool isQObject = !className.isEmpty(); + + if ( className == "QToolBar" ) + out << (Q_UINT8) elem.attribute( "dock", "0" ).toInt(); + if ( className == "QWidget" ) + className = elem.attribute( "class", className ).latin1(); + + int objectNo = -1; + if ( isQObject ) { + packCString( strings, out, className ); + objectNo = objects.insert(); + } + + outputGridCell( out, elem ); + + // optimization: insert '&Foo' into string-table before 'Foo' + if ( className == "QAction" || className == "QActionGroup" ) { + QVariant value = DomTool::readProperty( elem, "menuText", QVariant() ); + if ( value.asString().startsWith("&") ) + strings.insertString( value.asString() ); + } + + QDomElement f = elem.firstChild().toElement(); + while ( !f.isNull() ) { + QString tag = f.tagName(); + if ( tag == "action" ) { + if ( elem.tagName() == "item" || elem.tagName() == "toolbar" ) { + QString 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, "QAction" ); + } + } else if ( tag == "actiongroup" ) { + out << (Q_UINT8) Object_SubAction; + outputObject( buddies, objects, strings, out, f, "QActionGroup" ); + } 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, + QStringList::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") == "QLayoutWidget" && + elem.tagName() != "widget" ) { + outputLayoutWidgetsSubLayout( buddies, objects, strings, out, + f ); + } else { + out << (Q_UINT8) Object_SubWidget; + outputObject( buddies, objects, strings, out, f, "QWidget" ); + } + } + f = f.nextSibling().toElement(); + } + out << (Q_UINT8) Object_End; + if ( isQObject ) + objects.setName( objectNo, + DomTool::readProperty(elem, "name", "").asString() ); + return objectNo; +} + +static void outputBlock( QDataStream& out, BlockTag tag, + const QByteArray& data ) +{ + if ( !data.isEmpty() ) { + out << (Q_UINT8) tag; + packByteArray( out, data ); + } +} + +void convertUiToUib( QDomDocument& doc, QDataStream& out ) +{ + QByteArray introBlock; + QByteArray actionsBlock; + QByteArray buddiesBlock; + QByteArray connectionsBlock; + QByteArray functionsBlock; + QByteArray imagesBlock; + QByteArray menubarBlock; + QByteArray slotsBlock; + QByteArray tabstopsBlock; + QByteArray toolbarsBlock; + QByteArray variablesBlock; + QByteArray widgetBlock; + + QDomElement actionsElem; + QDomElement connectionsElem; + QDomElement imagesElem; + QDomElement menubarElem; + QDomElement tabstopsElem; + QDomElement toolbarsElem; + QDomElement widgetElem; + + QMap<int, QStringList> buddies; + UibStrTable strings; + UibIndexMap objects; + int widgetNo = -1; + QCString className; + Q_INT16 defaultMargin = -32768; + Q_INT16 defaultSpacing = -32768; + Q_UINT8 introFlags = 0; + + QDomElement elem = doc.firstChild().toElement().firstChild().toElement(); + while ( !elem.isNull() ) { + QString 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" ) { + QDataStream out2( functionsBlock, IO_WriteOnly ); + QDomElement 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" ) { + QDataStream out2( imagesBlock, IO_WriteOnly ); + QDomElement f = elem.firstChild().toElement(); + while ( !f.isNull() ) { + if ( f.tagName() == "image" ) { + QString name = f.attribute( "name" ); + QDomElement g = f.firstChild().toElement(); + if ( g.tagName() == "data" ) { + QString format = g.attribute( "format", "PNG" ); + QString hex = g.firstChild().toText().data(); + int n = hex.length() / 2; + QByteArray 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" ) { + QString margin = elem.attribute( "margin" ); + if ( !margin.isEmpty() ) + defaultMargin = margin.toInt(); + QString 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" ) { + QDataStream out2( slotsBlock, IO_WriteOnly ); + QDomElement f = elem.firstChild().toElement(); + while ( !f.isNull() ) { + if ( f.tagName() == "slot" ) { + QString language = f.attribute( "language", "C++" ); + QString 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" ) { + QDataStream out2( variablesBlock, IO_WriteOnly | IO_Append ); + packString( strings, out2, elem.firstChild().toText().data() ); + } else if ( tag == "variables" ) { + QDataStream out2( variablesBlock, IO_WriteOnly ); + QDomElement 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(); + } + + { + QDataStream out2( widgetBlock, IO_WriteOnly ); + widgetNo = outputObject( buddies, objects, strings, out2, widgetElem, + "QWidget" ); + } + + if ( !tabstopsElem.isNull() ) { + QDataStream out2( tabstopsBlock, IO_WriteOnly ); + QDomElement f = tabstopsElem.firstChild().toElement(); + while ( !f.isNull() ) { + if ( f.tagName() == "tabstop" ) { + QString widgetName = f.firstChild().toText().data(); + int no = objects.find( widgetName ); + if ( no != -1 ) + packUInt16( out2, no ); + } + f = f.nextSibling().toElement(); + } + } + + if ( !actionsElem.isNull() ) { + QDataStream out2( actionsBlock, IO_WriteOnly ); + outputObject( buddies, objects, strings, out2, actionsElem ); + } + + if ( !menubarElem.isNull() ) { + QDataStream out2( menubarBlock, IO_WriteOnly ); + outputObject( buddies, objects, strings, out2, menubarElem, + "QMenuBar" ); + } + + if ( !toolbarsElem.isNull() ) { + QDataStream out2( toolbarsBlock, IO_WriteOnly ); + QDomElement f = toolbarsElem.firstChild().toElement(); + while ( !f.isNull() ) { + if ( f.tagName() == "toolbar" ) + outputObject( buddies, objects, strings, out2, f, "QToolBar" ); + f = f.nextSibling().toElement(); + } + } + + if ( !buddies.isEmpty() ) { + QDataStream out2( buddiesBlock, IO_WriteOnly ); + QMap<int, QStringList>::ConstIterator a = buddies.begin(); + while ( a != buddies.end() ) { + QStringList::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() ) { + QString prevLanguage = "C++"; + int prevSenderNo = 0; + QString prevSignal = "clicked()"; + int prevReceiverNo = 0; + QString prevSlot = "accept()"; + + QDataStream out2( connectionsBlock, IO_WriteOnly ); + QDomElement f = connectionsElem.firstChild().toElement(); + while ( !f.isNull() ) { + if ( f.tagName() == "connection" ) { + QMap<QString, QString> argMap; + + QDomElement g = f.firstChild().toElement(); + while ( !g.isNull() ) { + argMap[g.tagName()] = g.firstChild().toText().data(); + g = g.nextSibling().toElement(); + } + + QString language = f.attribute( "language", "C++" ); + int senderNo = objects.find( argMap["sender"], widgetNo ); + int receiverNo = objects.find( argMap["receiver"], widgetNo ); + QString signal = UibHack::normalize( argMap["signal"] ); + QString 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(); + } + } + + { + QDataStream 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/kdevdesigner/shared/ui2uib.h b/kdevdesigner/shared/ui2uib.h new file mode 100644 index 00000000..674fd589 --- /dev/null +++ b/kdevdesigner/shared/ui2uib.h @@ -0,0 +1,35 @@ +/********************************************************************** +** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. +** +** This file is part of Qt Designer. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef UI2UIB_H +#define UI2UIB_H + +class QDataStream; +class QDomDocument; + +void convertUiToUib( QDomDocument& doc, QDataStream& out ); + +#endif diff --git a/kdevdesigner/shared/uib.cpp b/kdevdesigner/shared/uib.cpp new file mode 100644 index 00000000..72d73b45 --- /dev/null +++ b/kdevdesigner/shared/uib.cpp @@ -0,0 +1,42 @@ +/********************************************************************** +** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. +** +** This file is part of Qt Designer. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include "uib.h" + +static const char commonStrings[] = + "\0()\0(bool)\0(const QString&)\0(int)\0C++\0Layout1\0PNG\0QCheckBox\0" + "QComboBox\0QDialog\0QFrame\0QGridLayout\0QGroupBox\0QHBoxLayout\0QLabel\0" + "QLineEdit\0QListView\0QPushButton\0QRadioButton\0QVBoxLayout\0QWidget\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/kdevdesigner/shared/uib.h b/kdevdesigner/shared/uib.h new file mode 100644 index 00000000..00adac13 --- /dev/null +++ b/kdevdesigner/shared/uib.h @@ -0,0 +1,152 @@ +/********************************************************************** +** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. +** +** This file is part of Qt Designer. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#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 QString& str ); + inline void readBlock( QDataStream& in, int size ); + + inline const char *asCString( int offset ) const; + inline QString asString( int offset ) const; + inline QByteArray block() const; + +private: + QCString table; + QDataStream out; + int start; +}; + +/* + uic uses insertCString(), insertString(), and block(); + QWidgetFactory 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 = 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 QString& str ) +{ + if ( str.contains('\0') || str[0] == QChar(0x7f) ) { + int nextPos = table.size(); + out << (Q_UINT8) 0x7f; + out << str; + return nextPos; + } else { + return insertCString( str.utf8() ); + } +} + +inline void UibStrTable::readBlock( QDataStream& in, int size ) +{ + table.resize( start + size ); + in.readRawBytes( table.data() + start, size ); +} + +inline QString UibStrTable::asString( int offset ) const +{ + if ( table[offset] == 0x7f ) { + QDataStream in( table, IO_ReadOnly ); + in.device()->at( offset + 1 ); + QString str; + in >> str; + return str; + } else { + return QString::fromUtf8( asCString(offset) ); + } +} + +inline const char *UibStrTable::asCString( int offset ) const +{ + return table.data() + offset; +} + +inline QByteArray UibStrTable::block() const +{ + QByteArray block; + block.duplicate( table.data() + start, table.size() - start ); + return block; +} + +#endif diff --git a/kdevdesigner/shared/widgetdatabase.cpp b/kdevdesigner/shared/widgetdatabase.cpp new file mode 100644 index 00000000..8b80b03f --- /dev/null +++ b/kdevdesigner/shared/widgetdatabase.cpp @@ -0,0 +1,960 @@ +/********************************************************************** +** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. +** +** This file is part of Qt Designer. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include "widgetdatabase.h" +#include "../interfaces/widgetinterface.h" + +#include "../designer/kdevdesigner_part.h" + +#include <kiconloader.h> +#include <kdebug.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> + +#include <klocale.h> + +const int dbsize = 300; +const int dbcustom = 200; +const int dbdictsize = 211; +static WidgetDatabaseRecord* db[ dbsize ]; +static QDict<int> *className2Id = 0; +static int dbcount = 0; +static int dbcustomcount = 200; +static QStrList *wGroups; +static QStrList *invisibleGroups; +static bool whatsThisLoaded = FALSE; +static QPluginManager<WidgetInterface> *widgetPluginManager = 0; +static bool plugins_set_up = FALSE; +static bool was_in_setup = FALSE; + +QCleanupHandler<QPluginManager<WidgetInterface> > cleanup_manager; + +WidgetDatabaseRecord::WidgetDatabaseRecord() +{ + isForm = FALSE; + isContainer = FALSE; + icon = 0; + nameCounter = 0; + isCommon = FALSE; + isPlugin = FALSE; +} + +WidgetDatabaseRecord::~WidgetDatabaseRecord() +{ + delete icon; +} + + +/*! + \class WidgetDatabase widgetdatabase.h + \brief The WidgetDatabase class holds information about widgets + + The WidgetDatabase holds information about widgets like toolTip(), + iconSet(), ... It works Id-based, so all access functions take the + widget id as parameter. To get the id for a widget (classname), use + idFromClassName(). + + All access functions are static. Having multiple widgetdatabases in + one application doesn't make sense anyway and so you don't need more + than an instance of the widgetdatabase. + + For creating widgets, layouts, etc. see WidgetFactory. +*/ + +/*! + Creates widget database. Does nothing. +*/ + +WidgetDatabase::WidgetDatabase() +{ +} + +/*! Sets up the widget database. If the static widgetdatabase already + exists, the functions returns immediately. +*/ + +void WidgetDatabase::setupDataBase( int id ) +{ + was_in_setup = TRUE; +#ifndef UIC + Q_UNUSED( id ) + if ( dbcount ) + return; +#else + if ( dbcount && id != -2 ) + return; + if ( dbcount && !plugins_set_up ) { + setupPlugins(); + return; + } + if ( dbcount && plugins_set_up) + return; +#endif + + wGroups = new QStrList; + invisibleGroups = new QStrList; + invisibleGroups->append( "Forms" ); + invisibleGroups->append( "Temp" ); + className2Id = new QDict<int>( dbdictsize ); + className2Id->setAutoDelete( TRUE ); + + WidgetDatabaseRecord *r = 0; + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_pushbutton.png"; + r->name = "QPushButton"; + r->group = widgetGroup( "Buttons" ); + r->toolTip = "Push Button"; + r->isCommon = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_toolbutton.png"; + r->name = "QToolButton"; + r->group = widgetGroup( "Buttons" ); + r->toolTip = "Tool Button"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_radiobutton.png"; + r->name = "QRadioButton"; + r->group = widgetGroup( "Buttons" ); + r->toolTip = "Radio Button"; + r->isCommon = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_checkbox.png"; + r->name = "QCheckBox"; + r->group = widgetGroup( "Buttons" ); + r->toolTip = "Check Box"; + r->isCommon = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_groupbox.png"; + r->name = "QGroupBox"; + r->group = widgetGroup( "Containers" ); + r->toolTip = "Group Box"; + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_buttongroup.png"; + r->name = "QButtonGroup"; + r->group = widgetGroup( "Containers" ); + r->toolTip = "Button Group"; + r->isContainer = TRUE; + r->isCommon = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_frame.png"; + r->name = "QFrame"; + r->group = widgetGroup( "Containers" ); + r->toolTip = "Frame"; + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_tabwidget.png"; + r->name = "QTabWidget"; + r->group = widgetGroup( "Containers" ); + r->toolTip = "Tabwidget"; + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_widgetstack.png"; + r->name = "QWidgetStack"; + r->group = widgetGroup( "Containers" ); + r->toolTip = "Widget Stack"; + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_toolbox.png"; + r->name = "QToolBox"; + r->group = widgetGroup( "Containers" ); + r->toolTip = "Tool Box"; + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_listbox.png"; + r->name = "QListBox"; + r->group = widgetGroup( "Views" ); + r->toolTip = "List Box"; + r->isCommon = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_listview.png"; + r->name = "QListView"; + r->group = widgetGroup( "Views" ); + r->toolTip = "List View"; + + append( r ); + +#if !defined(QT_NO_ICONVIEW) || defined(UIC) + r = new WidgetDatabaseRecord; + r->iconSet = "designer_iconview.png"; + r->name = "QIconView"; + r->group = widgetGroup( "Views" ); + r->toolTip = "Icon View"; + + append( r ); +#endif + +#if !defined(QT_NO_TABLE) + r = new WidgetDatabaseRecord; + r->iconSet = "designer_table.png"; + r->name = "QTable"; + r->group = widgetGroup( "Views" ); + r->toolTip = "Table"; + + append( r ); +#endif + +#if !defined(QT_NO_SQL) + r = new WidgetDatabaseRecord; + r->iconSet = "designer_datatable.png"; + r->includeFile = "qdatatable.h"; + r->name = "QDataTable"; + r->group = widgetGroup( "Database" ); + r->toolTip = "Data Table"; + + append( r ); +#endif + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_lineedit.png"; + r->name = "QLineEdit"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Line Edit"; + r->isCommon = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_spinbox.png"; + r->name = "QSpinBox"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Spin Box"; + r->isCommon = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_dateedit.png"; + r->name = "QDateEdit"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Date Edit"; + r->includeFile = "qdatetimeedit.h"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_timeedit.png"; + r->name = "QTimeEdit"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Time Edit"; + r->includeFile = "qdatetimeedit.h"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_datetimeedit.png"; + r->name = "QDateTimeEdit"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Date-Time Edit"; + r->includeFile = "qdatetimeedit.h"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_multilineedit.png"; + r->name = "QMultiLineEdit"; + r->group = widgetGroup( "Temp" ); + r->toolTip = "Multi Line Edit"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_richtextedit.png"; + r->name = "QTextEdit"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Rich Text Edit"; + r->isCommon = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_combobox.png"; + r->name = "QComboBox"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Combo Box"; + r->isCommon = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_slider.png"; + r->name = "QSlider"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Slider"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_scrollbar.png"; + r->name = "QScrollBar"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Scrollbar"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_dial.png"; + r->name = "QDial"; + r->group = widgetGroup( "Input" ); + r->toolTip = "Dial"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_label.png"; + r->name = "QLabel"; + r->group = widgetGroup( "Temp" ); + r->toolTip = "Label"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_label.png"; + r->name = "TextLabel"; + r->group = widgetGroup( "Display" ); + r->toolTip = "Text Label"; + r->whatsThis = "The Text Label provides a widget to display static text."; + r->isCommon = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_pixlabel.png"; + r->name = "PixmapLabel"; + r->group = widgetGroup( "Display" ); + r->toolTip = "Pixmap Label"; + r->whatsThis = "The Pixmap Label provides a widget to display pixmaps."; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_lcdnumber.png"; + r->name = "QLCDNumber"; + r->group = widgetGroup( "Display" ); + r->toolTip = "LCD Number"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_line.png"; + r->name = "Line"; + r->group = widgetGroup( "Display" ); + r->toolTip = "Line"; + r->includeFile = "qframe.h"; + r->whatsThis = "The Line widget provides horizontal and vertical lines."; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_progress.png"; + r->name = "QProgressBar"; + r->group = widgetGroup( "Display" ); + r->toolTip = "Progress Bar"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_textview.png"; + r->name = "QTextView"; + r->group = widgetGroup( "Temp" ); + r->toolTip = "Text View"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_textbrowser.png"; + r->name = "QTextBrowser"; + r->group = widgetGroup( "Display" ); + r->toolTip = "Text Browser"; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_spacer.png"; + r->name = "Spacer"; + r->group = widgetGroup( "Temp" ); + r->toolTip = "Spacer"; + r->whatsThis = "The Spacer provides horizontal and vertical spacing to be able to manipulate the behaviour of layouts."; + + append( r ); + + r = new WidgetDatabaseRecord; + r->name = "QWidget"; + r->isForm = TRUE; + r->group = widgetGroup( "Forms" ); + + append( r ); + + r = new WidgetDatabaseRecord; + r->name = "QDialog"; + r->group = widgetGroup( "Forms" ); + r->isForm = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->name = "QWizard"; + r->group = widgetGroup( "Forms" ); + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->name = "QDesignerWizard"; + r->group = widgetGroup( "Forms" ); + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->name = "QLayoutWidget"; + r->group = widgetGroup( "Temp" ); + r->includeFile = ""; + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->name = "QSplitter"; + r->group = widgetGroup( "Temp" ); + r->includeFile = "qsplitter.h"; + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_tabwidget.png"; + r->name = "QDesignerTabWidget"; + r->group = widgetGroup( "Temp" ); + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_tabwidget.png"; + r->name = "QDesignerWidget"; + r->group = widgetGroup( "Temp" ); + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = "designer_tabwidget.png"; + r->name = "QDesignerDialog"; + r->group = widgetGroup( "Temp" ); + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = ""; + r->name = "QMainWindow"; + r->includeFile = "qmainwindow.h"; + r->group = widgetGroup( "Temp" ); + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = ""; + r->name = "QDesignerAction"; + r->includeFile = "qaction.h"; + r->group = widgetGroup( "Temp" ); + r->isContainer = FALSE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = ""; + r->name = "QDesignerActionGroup"; + r->includeFile = "qaction.h"; + r->group = widgetGroup( "Temp" ); + r->isContainer = FALSE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = ""; + r->name = "QScrollView"; + r->includeFile = "qscrollview.h"; + r->group = widgetGroup( "Temp" ); + r->isContainer = TRUE; + + append( r ); + +#ifndef QT_NO_SQL + r = new WidgetDatabaseRecord; + r->iconSet = ""; + r->name = "QDataBrowser"; + r->includeFile = "qdatabrowser.h"; + r->group = widgetGroup( "Database" ); + r->toolTip = "Data Browser"; + r->iconSet = "designer_databrowser.png"; + r->isContainer = TRUE; + + append( r ); + + r = new WidgetDatabaseRecord; + r->iconSet = ""; + r->name = "QDataView"; + r->includeFile = "qdataview.h"; + r->group = widgetGroup( "Database" ); + r->toolTip = "Data View"; + r->iconSet = "designer_dataview.png"; + r->isContainer = TRUE; + + append( r ); +#endif + +#ifndef UIC + setupPlugins(); +#endif +} + +void WidgetDatabase::setupPlugins() +{ + if ( plugins_set_up ) + return; + plugins_set_up = TRUE; + QStringList widgets = widgetManager()->featureList(); + for ( QStringList::Iterator it = widgets.begin(); it != widgets.end(); ++it ) { + if ( hasWidget( *it ) ) + continue; + WidgetDatabaseRecord *r = new WidgetDatabaseRecord; + WidgetInterface *iface = 0; + widgetManager()->queryInterface( *it, &iface ); + if ( !iface ) + continue; + +#ifndef UIC + QIconSet icon = iface->iconSet( *it ); + if ( !icon.pixmap().isNull() ) + r->icon = new QIconSet( icon ); +#endif + QString grp = iface->group( *it ); + if ( grp.isEmpty() ) + grp = "3rd party widgets"; + r->group = widgetGroup( grp ); + r->toolTip = iface->toolTip( *it ); + r->whatsThis = iface->whatsThis( *it ); + r->includeFile = iface->includeFile( *it ); + r->isContainer = iface->isContainer( *it ); + r->name = *it; + r->isPlugin = TRUE; + append( r ); + iface->release(); + } +} + +/*! + Returns the number of elements in the widget database. +*/ + +int WidgetDatabase::count() +{ + setupDataBase( -1 ); + return dbcount; +} + +/*! + Returns the id at which the ids of custom widgets start. +*/ + +int WidgetDatabase::startCustom() +{ + setupDataBase( -1 ); + return dbcustom; +} + +/*! + Returns the iconset which represents the class registered as \a id. +*/ + +QIconSet WidgetDatabase::iconSet( int id ) +{ + setupDataBase( id ); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return QIconSet(); +#if !defined(UIC) && !defined(RESOURCE) + if ( !r->icon ) { + if ( r->iconSet.isEmpty() ) + return QIconSet(); + QPixmap pix = BarIcon( r->iconSet, KDevDesignerPartFactory::instance() ); + if ( pix.isNull() ) + pix = QPixmap( r->iconSet ); + r->icon = new QIconSet( pix ); + } + return *r->icon; +#else + return QIconSet(); +#endif +} + +/*! + Returns the classname of the widget which is registered as \a id. +*/ + +QString WidgetDatabase::className( int id ) +{ + setupDataBase( id ); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return QString::null; + return r->name; +} + +/*! + Returns the group the widget registered as \a id belongs to. +*/ + +QString WidgetDatabase::group( int id ) +{ + setupDataBase( id ); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return QString::null; + return r->group; +} + +/*! + Returns the tooltip text of the widget which is registered as \a id. +*/ + +QString WidgetDatabase::toolTip( int id ) +{ + setupDataBase( id ); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return QString::null; + return r->toolTip; +} + +/*! + Returns the what's this? text of the widget which is registered as \a id. +*/ + +QString WidgetDatabase::whatsThis( int id ) +{ + setupDataBase( id ); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return QString::null; + return r->whatsThis; +} + +/*! + Returns the include file if the widget which is registered as \a id. +*/ + +QString WidgetDatabase::includeFile( int id ) +{ + setupDataBase( id ); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return QString::null; + if ( r->includeFile.isNull() ) + return r->name.lower() + ".h"; + return r->includeFile; +} + +/*! Returns whether the widget registered as \a id is a form. +*/ +bool WidgetDatabase::isForm( int id ) +{ + setupDataBase( id ); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return FALSE; + return r->isForm; +} + +/*! Returns whether the widget registered as \a id can have children. +*/ + +bool WidgetDatabase::isContainer( int id ) +{ + setupDataBase( id ); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return FALSE; + return r->isContainer || r->isForm; +} + +bool WidgetDatabase::isCommon( int id ) +{ + setupDataBase( id ); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return FALSE; + return r->isCommon; +} + +QString WidgetDatabase::createWidgetName( int id ) +{ + setupDataBase( id ); + QString n = className( id ); + if ( n == "QLayoutWidget" ) + n = "Layout"; + if ( n[ 0 ] == 'Q' && n[ 1 ].lower() != n[ 1 ] ) + n = n.mid( 1 ); + int colonColon = n.findRev( "::" ); + if ( colonColon != -1 ) + n = n.mid( colonColon + 2 ); + + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return n; + n += QString::number( ++r->nameCounter ); + n[0] = n[0].lower(); + return n; +} + +/*! Returns the id for \a name or -1 if \a name is unknown. + */ +int WidgetDatabase::idFromClassName( const QString &name ) +{ + setupDataBase( -1 ); + if ( name.isEmpty() ) + return 0; + int *i = className2Id->find( name ); + if ( i ) + return *i; + if ( name == "FormWindow" ) + return idFromClassName( "QLayoutWidget" ); +#ifdef UIC + setupDataBase( -2 ); + i = className2Id->find( name ); + if ( i ) + return *i; +#endif + return -1; +} + +bool WidgetDatabase::hasWidget( const QString &name ) +{ + return className2Id->find( name ) != 0; +} + +WidgetDatabaseRecord *WidgetDatabase::at( int index ) +{ + if ( index < 0 ) + return 0; + if ( index >= dbcustom && index < dbcustomcount ) + return db[ index ]; + if ( index < dbcount ) + return db[ index ]; + return 0; +} + +void WidgetDatabase::insert( int index, WidgetDatabaseRecord *r ) +{ + if ( index < 0 || index >= dbsize ) + return; + db[ index ] = r; + className2Id->insert( r->name, new int( index ) ); + if ( index < dbcustom ) + dbcount = QMAX( dbcount, index ); +} + +void WidgetDatabase::append( WidgetDatabaseRecord *r ) +{ + if ( !was_in_setup ) + setupDataBase( -1 ); + insert( dbcount++, r ); +} + +QString WidgetDatabase::widgetGroup( const QString &g ) +{ + if ( wGroups->find( g ) == -1 ) + wGroups->append( g ); + return g; +} + +bool WidgetDatabase::isGroupEmpty( const QString &grp ) +{ + WidgetDatabaseRecord *r = 0; + for ( int i = 0; i < dbcount; ++i ) { + if ( !( r = db[ i ] ) ) + continue; + if ( r->group == grp ) + return FALSE; + } + return TRUE; +} + +QString WidgetDatabase::widgetGroup( int i ) +{ + setupDataBase( -1 ); + if ( i >= 0 && i < (int)wGroups->count() ) + return wGroups->at( i ); + return QString::null; +} + +int WidgetDatabase::numWidgetGroups() +{ + setupDataBase( -1 ); + return wGroups->count(); +} + +bool WidgetDatabase::isGroupVisible( const QString &g ) +{ + setupDataBase( -1 ); + return invisibleGroups->find( g ) == -1; +} + +int WidgetDatabase::addCustomWidget( WidgetDatabaseRecord *r ) +{ + insert( dbcustomcount++, r ); + return dbcustomcount - 1; +} + +void WidgetDatabase::customWidgetClassNameChanged( const QString &oldName, + const QString &newName ) +{ + int id = idFromClassName( oldName ); + if ( id == -1 ) + return; + WidgetDatabaseRecord *r = db[ id ]; + r->name = newName; + className2Id->remove( oldName ); + className2Id->insert( newName, new int( id ) ); +} + +bool WidgetDatabase::isCustomWidget( int id ) +{ + if ( id >= dbcustom && id < dbcustomcount ) + return TRUE; + return FALSE; +} + +bool WidgetDatabase::isCustomPluginWidget( int id ) +{ + setupDataBase( id ); + WidgetDatabaseRecord *r = at( id ); + if ( !r ) + return FALSE; + return r->isPlugin; +} + +bool WidgetDatabase::isWhatsThisLoaded() +{ + return whatsThisLoaded; +} + +void WidgetDatabase::loadWhatsThis( const QString &docPath ) +{ + QString whatsthisFile = docPath + "/whatsthis"; + QFile f( whatsthisFile ); + if ( !f.open( IO_ReadOnly ) ) + return; + QTextStream ts( &f ); + while ( !ts.atEnd() ) { + QString s = ts.readLine(); + QStringList l = QStringList::split( " | ", s ); + int id = idFromClassName( l[ 1 ] ); + WidgetDatabaseRecord *r = at( id ); + if ( r ) + r->whatsThis = l[ 0 ]; + } + whatsThisLoaded = TRUE; +} + + +// ### Qt 3.1: make these publically accessible via QWidgetDatabase API +#if defined(UIC) +bool dbnounload = FALSE; +QStringList *dbpaths = 0; +#else +extern QString *qwf_plugin_dir; +#endif + + +QPluginManager<WidgetInterface> *widgetManager() +{ + if ( !widgetPluginManager ) { + QString pluginDir = "/designer"; +#if !defined(UIC) + if ( qwf_plugin_dir ) + pluginDir = *qwf_plugin_dir; +#endif + widgetPluginManager = new QPluginManager<WidgetInterface>( IID_Widget, QApplication::libraryPaths(), pluginDir ); + cleanup_manager.add( &widgetPluginManager ); +#if defined(UIC) + if ( dbnounload ) + widgetPluginManager->setAutoUnload( FALSE ); + if ( dbpaths ) { + QStringList::ConstIterator it = dbpaths->begin(); + for ( ; it != dbpaths->end(); ++it ) + widgetPluginManager->addLibraryPath( *it ); + } +#endif + } + return widgetPluginManager; +} diff --git a/kdevdesigner/shared/widgetdatabase.h b/kdevdesigner/shared/widgetdatabase.h new file mode 100644 index 00000000..03060fa3 --- /dev/null +++ b/kdevdesigner/shared/widgetdatabase.h @@ -0,0 +1,96 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qt Designer. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef WIDGETDATABASE_H +#define WIDGETDATABASE_H + +#include <qiconset.h> +#include <qstring.h> +#include "../interfaces/widgetinterface.h" // up here for GCC 2.7.* compatibility +#include <private/qpluginmanager_p.h> + + +extern QPluginManager<WidgetInterface> *widgetManager(); + +struct WidgetDatabaseRecord +{ + WidgetDatabaseRecord(); + ~WidgetDatabaseRecord(); + QString iconSet, name, group, toolTip, whatsThis, includeFile; + uint isContainer : 1; + uint isForm : 1; + uint isCommon : 1; + uint isPlugin : 1; + QIconSet *icon; + int nameCounter; +}; + +class WidgetDatabase : public Qt +{ +public: + WidgetDatabase(); + static void setupDataBase( int id ); + static void setupPlugins(); + + static int count(); + static int startCustom(); + + static QIconSet iconSet( int id ); + static QString className( int id ); + static QString group( int id ); + static QString toolTip( int id ); + static QString whatsThis( int id ); + static QString includeFile( int id ); + static bool isForm( int id ); + static bool isContainer( int id ); + static bool isCommon( int id ); + + static int idFromClassName( const QString &name ); + static QString createWidgetName( int id ); + + static WidgetDatabaseRecord *at( int index ); + static void insert( int index, WidgetDatabaseRecord *r ); + static void append( WidgetDatabaseRecord *r ); + + static QString widgetGroup( const QString &g ); + static QString widgetGroup( int i ); + static int numWidgetGroups(); + static bool isGroupVisible( const QString &g ); + static bool isGroupEmpty( const QString &grp ); + + static int addCustomWidget( WidgetDatabaseRecord *r ); + static bool isCustomWidget( int id ); + static bool isCustomPluginWidget( int id ); + + static bool isWhatsThisLoaded(); + static void loadWhatsThis( const QString &docPath ); + + static bool hasWidget( const QString &name ); + static void customWidgetClassNameChanged( const QString &oldName, const QString &newName ); + +}; + +#endif |