Eneboo - Documentación para desarrolladores
src/qt/tools/designer/uilib/qwidgetfactory.h
Ir a la documentación de este archivo.
00001 /**********************************************************************
00002 ** Copyright (C) 2005-2007 Trolltech ASA.  All rights reserved.
00003 **
00004 ** This file is part of Qt Designer.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00012 ** licenses may use this file in accordance with the Qt Commercial License
00013 ** Agreement provided with the Software.
00014 **
00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00017 **
00018 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00019 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00020 **   information about Qt Commercial License Agreements.
00021 **
00022 ** Contact info@trolltech.com if any conditions of this licensing are
00023 ** not clear to you.
00024 **
00025 **********************************************************************/
00026 
00027 #ifndef QWIDGETFACTORY_H
00028 #define QWIDGETFACTORY_H
00029 
00030 #ifndef QT_H
00031 #include <qstring.h>
00032 #include <qptrlist.h>
00033 #include <qimage.h>
00034 #include <qpixmap.h>
00035 #include <qvaluelist.h>
00036 #include <qmap.h>
00037 #include <qaction.h>
00038 #endif // QT_H
00039 
00040 class QDomDocument;
00041 class QDomElement;
00042 class QLayout;
00043 class QListView;
00044 class QListViewItem;
00045 class QMenuBar;
00046 class QTable;
00047 class QWidget;
00048 class QWidgetFactoryPrivate;
00049 class UibStrTable;
00050 
00051 class QWidgetFactory
00052 {
00053 public:
00054     QWidgetFactory();
00055     virtual ~QWidgetFactory();
00056 
00057     static QWidget *create( const QString &uiFile, QObject *connector = 0, QWidget *parent = 0, const char *name = 0 );
00058     static QWidget *create( QIODevice *dev, QObject *connector = 0, QWidget *parent = 0, const char *name = 0 );
00059     static void addWidgetFactory( QWidgetFactory *factory );
00060     static void loadImages( const QString &dir );
00061 
00062     virtual QWidget *createWidget( const QString &className, QWidget *parent, const char *name ) const;
00063     static QStringList widgets();
00064     static bool supportsWidget( const QString &widget );
00065 
00066 private:
00067     enum LayoutType { HBox, VBox, Grid, NoLayout };
00068     void loadImageCollection( const QDomElement &e );
00069     void loadConnections( const QDomElement &e, QObject *connector );
00070     void loadTabOrder( const QDomElement &e );
00071     QWidget *createWidgetInternal( const QDomElement &e, QWidget *parent, QLayout* layout, const QString &classNameArg );
00072     QLayout *createLayout( QWidget *widget, QLayout*  layout, LayoutType type, bool isQLayoutWidget = FALSE );
00073     LayoutType layoutType( QLayout *l ) const;
00074     void setProperty( QObject* widget, const QString &prop, QVariant value );
00075     void setProperty( QObject* widget, const QString &prop, const QDomElement &e );
00076     void createSpacer( const QDomElement &e, QLayout *layout );
00077     QImage loadFromCollection( const QString &name );
00078     QPixmap loadPixmap( const QString &name );
00079     QPixmap loadPixmap( const QDomElement &e );
00080     QColorGroup loadColorGroup( const QDomElement &e );
00081     void createListViewColumn( QListView *lv, const QString& txt,
00082                                const QPixmap& pix, bool clickable,
00083                                bool resizable );
00084 #ifndef QT_NO_TABLE
00085     void createTableColumnOrRow( QTable *table, const QString& txt,
00086                                  const QPixmap& pix, const QString& field,
00087                                  bool isRow );
00088 #endif
00089     void createColumn( const QDomElement &e, QWidget *widget );
00090     void loadItem( const QDomElement &e, QPixmap &pix, QString &txt, bool &hasPixmap );
00091     void createItem( const QDomElement &e, QWidget *widget, QListViewItem *i = 0 );
00092     void loadChildAction( QObject *parent, const QDomElement &e );
00093     void loadActions( const QDomElement &e );
00094     void loadToolBars( const QDomElement &e );
00095     void loadMenuBar( const QDomElement &e );
00096     void loadPopupMenu( QPopupMenu *p, const QDomElement &e );
00097     void loadFunctions( const QDomElement &e );
00098     QAction *findAction( const QString &name );
00099     void loadExtraSource();
00100     QString translate( const char *sourceText, const char *comment = "" );
00101     QString translate( const QString& sourceText, const QString& comment = QString::null );
00102 
00103     void unpackUInt16( QDataStream& in, Q_UINT16& n );
00104     void unpackUInt32( QDataStream& in, Q_UINT32& n );
00105     void unpackByteArray( QDataStream& in, QByteArray& array );
00106     void unpackCString( const UibStrTable& strings, QDataStream& in,
00107                         QCString& cstr );
00108     void unpackString( const UibStrTable& strings, QDataStream& in,
00109                        QString& str );
00110     void unpackStringSplit( const UibStrTable& strings, QDataStream& in,
00111                             QString& str );
00112     void unpackVariant( const UibStrTable& strings, QDataStream& in,
00113                         QVariant& value );
00114     void inputSpacer( const UibStrTable& strings, QDataStream& in,
00115                       QLayout *parent );
00116     void inputColumnOrRow( const UibStrTable& strings, QDataStream& in,
00117                            QObject *parent, bool isRow );
00118     void inputItem( const UibStrTable& strings, QDataStream& in,
00119                     QObject *parent, QListViewItem *parentItem = 0 );
00120     void inputMenuItem( QObject **objects, const UibStrTable& strings,
00121                         QDataStream& in, QMenuBar *menuBar );
00122     QObject *inputObject( QObject **objects, int& numObjects,
00123                           const UibStrTable& strings, QDataStream& in,
00124                           QWidget *ancestorWidget, QObject *parent,
00125                           QCString className = "" );
00126     QWidget *createFromUiFile( QDomDocument doc, QObject *connector,
00127                                QWidget *parent, const char *name );
00128     QWidget *createFromUibFile( QDataStream& in, QObject *connector,
00129                                 QWidget *parent, const char *name );
00130 
00131 private:
00132     struct Image {
00133         QImage img;
00134         QString name;
00135         bool operator==(  const Image &i ) const {
00136             return ( i.name == name &&
00137                      i.img == img );
00138         }
00139     };
00140 
00141     struct Field {
00142         Field() {}
00143         Field( const QString &s1, const QPixmap &p, const QString &s2 ) : name( s1 ), pix( p ), field( s2 ) {}
00144         QString name;
00145         QPixmap pix;
00146         QString field;
00147         Q_DUMMY_COMPARISON_OPERATOR( Field )
00148     };
00149 
00150     struct SqlWidgetConnection {
00151         SqlWidgetConnection() {}
00152         SqlWidgetConnection( const QString &c, const QString &t )
00153                 : conn( c ), table( t ), dbControls( new QMap<QString, QString>() ) {}
00154         QString conn;
00155         QString table;
00156         QMap<QString, QString> *dbControls;
00157         Q_DUMMY_COMPARISON_OPERATOR( SqlWidgetConnection )
00158     };
00159 
00160     QValueList<Image> images;
00161     QWidget *toplevel;
00162     QWidgetFactoryPrivate *d;
00163     QMap<QString, QString> *dbControls;
00164     QMap<QString, QStringList> dbTables;
00165     QMap<QWidget*, SqlWidgetConnection> sqlWidgetConnections;
00166     QMap<QString, QString> buddies;
00167     QMap<QTable*, QValueList<Field> > fieldMaps;
00168     QPtrList<QAction> actionList;
00169     QMap<QString, QString> languageSlots;
00170     QStringList noDatabaseWidgets;
00171     bool usePixmapCollection;
00172     int defMargin;
00173     int defSpacing;
00174     QString code;
00175     QString uiFileVersion;
00176 };
00177 
00178 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'