Eneboo - Documentación para desarrolladores
src/qt/tools/designer/designer/widgetfactory.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 WIDGETFACTORY_H
00028 #define WIDGETFACTORY_H
00029 
00030 #include <qvariant.h>
00031 #include <qiconset.h>
00032 #include <qstring.h>
00033 #include <qintdict.h>
00034 #include <qtabwidget.h>
00035 #include <qpixmap.h>
00036 #include <qsize.h>
00037 #include <qpainter.h>
00038 #include <qevent.h>
00039 #include <qobjectlist.h>
00040 #include <qlabel.h>
00041 #include <qwizard.h>
00042 #include <qptrdict.h>
00043 #include <qpushbutton.h>
00044 #include <qtoolbutton.h>
00045 #include <qcheckbox.h>
00046 #include <qradiobutton.h>
00047 #include <qbuttongroup.h>
00048 #include <qwidgetstack.h>
00049 #include <qguardedptr.h>
00050 #include <qtoolbox.h>
00051 
00052 #include "metadatabase.h"
00053 #include "qwidgetfactory.h"
00054 
00055 class QWidget;
00056 class QLayout;
00057 class FormWindow;
00058 
00059 class CustomWidgetFactory : public QWidgetFactory
00060 {
00061 public:
00062     CustomWidgetFactory();
00063     QWidget *createWidget( const QString &className, QWidget *parent, const char *name ) const;
00064 
00065 };
00066 
00067 class WidgetFactory : public Qt
00068 {
00069     friend class CustomWidgetFactory;
00070 
00071 public:
00072     enum LayoutType {
00073         HBox,
00074         VBox,
00075         Grid,
00076         NoLayout
00077     };
00078 
00079     static QWidget *create( int id, QWidget *parent, const char *name = 0, bool init = TRUE,
00080                             const QRect *rect = 0, Qt::Orientation orient = Qt::Horizontal );
00081     static QLayout *createLayout( QWidget *widget, QLayout* layout, LayoutType type );
00082     static void deleteLayout( QWidget *widget );
00083 
00084     static LayoutType layoutType( QWidget *w );
00085     static LayoutType layoutType( QWidget *w, QLayout *&layout );
00086     static LayoutType layoutType( QLayout *layout );
00087     static QWidget *layoutParent( QLayout *layout );
00088 
00089     static QWidget* containerOfWidget( QWidget *w );
00090     static QWidget* widgetOfContainer( QWidget *w );
00091 
00092     static bool isPassiveInteractor( QObject* o );
00093     static const char* classNameOf( QObject* o );
00094 
00095     static void initChangedProperties( QObject *o );
00096 
00097     static bool hasSpecialEditor( int id, QObject *editorWidget );
00098     static bool hasItems( int id, QObject *editorWidget );
00099     static void editWidget( int id, QWidget *parent, QWidget *editWidget, FormWindow *fw );
00100 
00101     static bool canResetProperty( QObject *w, const QString &propName );
00102     static bool resetProperty( QObject *w, const QString &propName );
00103     static QVariant defaultValue( QObject *w, const QString &propName );
00104     static QString defaultCurrentItem( QObject *w, const QString &propName );
00105 
00106     static QVariant property( QObject *w, const char *name );
00107     static void saveDefaultProperties( QObject *w, int id );
00108     static void saveChangedProperties( QObject *w, int id );
00109 
00110     static QString defaultSignal( QObject *w );
00111 
00112 private:
00113     static QWidget *createWidget( const QString &className, QWidget *parent, const char *name, bool init,
00114                                   const QRect *r = 0, Qt::Orientation orient = Qt::Horizontal );
00115     static QWidget *createCustomWidget( QWidget *parent, const char *name, MetaDataBase::CustomWidget *w );
00116 
00117     static QGuardedPtr<QObject> *lastPassiveInteractor;
00118     static bool lastWasAPassiveInteractor;
00119 };
00120 
00121 
00122 class QDesignerTabWidget : public QTabWidget
00123 {
00124     Q_OBJECT
00125     Q_PROPERTY( int currentPage READ currentPage WRITE setCurrentPage STORED false DESIGNABLE true )
00126     Q_PROPERTY( QString pageTitle READ pageTitle WRITE setPageTitle STORED false DESIGNABLE true )
00127     Q_PROPERTY( QCString pageName READ pageName WRITE setPageName STORED false DESIGNABLE true )
00128 public:
00129     QDesignerTabWidget( QWidget *parent, const char *name );
00130 
00131     int currentPage() const;
00132     void setCurrentPage( int i );
00133     QString pageTitle() const;
00134     void setPageTitle( const QString& title );
00135     QCString pageName() const;
00136     void setPageName( const QCString& name );
00137 
00138     int count() const;
00139     QTabBar *tabBar() const { return QTabWidget::tabBar(); }
00140 
00141     bool eventFilter( QObject*, QEvent* );
00142 
00143 private:
00144     QPoint pressPoint;
00145     QWidget *dropIndicator;
00146     QWidget *dragPage;
00147     QString dragLabel;
00148      bool mousePressed;
00149 };
00150 
00151 class QDesignerWidgetStack : public QWidgetStack
00152 {
00153     Q_OBJECT
00154     Q_PROPERTY( int currentPage READ currentPage WRITE setCurrentPage STORED false DESIGNABLE true )
00155     Q_PROPERTY( QCString pageName READ pageName WRITE setPageName STORED false DESIGNABLE true )
00156 public:
00157     QDesignerWidgetStack( QWidget *parent, const char *name );
00158 
00159     int currentPage() const;
00160     void setCurrentPage( int i );
00161     QCString pageName() const;
00162     void setPageName( const QCString& name );
00163 
00164     int count() const;
00165     QWidget* page( int i ) const;
00166 
00167     int insertPage( QWidget *p, int i = -1 );
00168     int removePage( QWidget *p );
00169 
00170 public slots:
00171     void updateButtons();
00172 
00173 protected:
00174     void resizeEvent( QResizeEvent *e ) {
00175         QWidgetStack::resizeEvent( e );
00176         updateButtons();
00177     }
00178 
00179     void showEvent( QShowEvent *e ) {
00180         QWidgetStack::showEvent( e );
00181         updateButtons();
00182     }
00183 
00184 private slots:
00185     void prevPage();
00186     void nextPage();
00187 
00188 private:
00189     QPtrList<QWidget> pages;
00190     QToolButton *prev, *next;
00191 
00192 };
00193 
00194 class QDesignerWizard : public QWizard
00195 {
00196     Q_OBJECT
00197     Q_PROPERTY( int currentPage READ currentPageNum WRITE setCurrentPage STORED false DESIGNABLE true )
00198     Q_PROPERTY( QString pageTitle READ pageTitle WRITE setPageTitle STORED false DESIGNABLE true )
00199     Q_PROPERTY( QCString pageName READ pageName WRITE setPageName STORED false DESIGNABLE true )
00200     Q_OVERRIDE( bool modal READ isModal WRITE setModal )
00201 
00202 public:
00203     QDesignerWizard( QWidget *parent, const char *name ) 
00204         : QWizard( parent, name ), modal(FALSE) {}
00205 
00206     int currentPageNum() const;
00207     void setCurrentPage( int i );
00208     QString pageTitle() const;
00209     void setPageTitle( const QString& title );
00210     QCString pageName() const;
00211     void setPageName( const QCString& name );
00212     int pageNum( QWidget *page );
00213     void addPage( QWidget *p, const QString & );
00214     void removePage( QWidget *p );
00215     void insertPage( QWidget *p, const QString &t, int index );
00216     bool isPageRemoved( QWidget *p ) { return (removedPages.find( p ) != 0); }
00217 
00218     bool isModal() const { return modal; }
00219     void setModal(bool b) { modal = b; }
00220 
00221     void reject() {}
00222 
00223 private:
00224     struct Page
00225     {
00226         Page( QWidget *a, const QString &b ) : p( a ), t( b ) {}
00227         Page() : p( 0 ), t( QString::null ) {}
00228         QWidget *p;
00229         QString t;
00230     };
00231     QPtrDict<QWidget> removedPages;
00232     bool modal;
00233 
00234 };
00235 
00236 class QLayoutWidget : public QWidget
00237 {
00238     Q_OBJECT
00239 
00240 public:
00241     QLayoutWidget( QWidget *parent, const char *name ) : QWidget( parent, name ), sp( QWidget::sizePolicy() ) {}
00242 
00243     QSizePolicy sizePolicy() const;
00244     void updateSizePolicy();
00245 
00246 protected:
00247     void paintEvent( QPaintEvent * );
00248     bool event( QEvent * );
00249     QSizePolicy sp;
00250 
00251 };
00252 
00253 
00254 class CustomWidget : public QWidget
00255 {
00256     Q_OBJECT
00257 
00258 public:
00259     CustomWidget( QWidget *parent, const char *name, MetaDataBase::CustomWidget *cw )
00260         : QWidget( parent, name ), cusw( cw ) {
00261             alwaysExpand = parentWidget() && parentWidget()->inherits( "FormWindow" );
00262             setSizePolicy( cw->sizePolicy );
00263             if ( !alwaysExpand )
00264                 setBackgroundMode( PaletteDark );
00265     }
00266 
00267     QSize sizeHint() const {
00268         QSize sh = cusw->sizeHint;
00269         if ( sh.isValid() )
00270             return sh;
00271         return QWidget::sizeHint();
00272     }
00273 
00274     QString realClassName() { return cusw->className; }
00275     MetaDataBase::CustomWidget *customWidget() const { return cusw; }
00276 
00277 protected:
00278     void paintEvent( QPaintEvent *e );
00279 
00280     MetaDataBase::CustomWidget *cusw;
00281     bool alwaysExpand;
00282 
00283 };
00284 
00285 
00286 class Line : public QFrame
00287 {
00288     Q_OBJECT
00289 
00290     Q_PROPERTY( Orientation orientation READ orientation WRITE setOrientation )
00291     Q_OVERRIDE( int frameWidth DESIGNABLE false )
00292     Q_OVERRIDE( Shape frameShape DESIGNABLE false )
00293     Q_OVERRIDE( QRect frameRect DESIGNABLE false )
00294     Q_OVERRIDE( QRect contentsRect DESIGNABLE false )
00295 public:
00296     Line( QWidget *parent, const char *name )
00297         : QFrame( parent, name, WMouseNoMask ) {
00298             setFrameStyle( HLine | Sunken );
00299     }
00300 
00301     void setOrientation( Orientation orient ) {
00302         if ( orient == Horizontal )
00303             setFrameShape( HLine );
00304         else
00305             setFrameShape( VLine );
00306     }
00307     Orientation orientation() const {
00308         return frameShape() == HLine ? Horizontal : Vertical;
00309     }
00310 };
00311 
00312 class QDesignerLabel : public QLabel
00313 {
00314     Q_OBJECT
00315 
00316     Q_PROPERTY( QCString buddy READ buddyWidget WRITE setBuddyWidget )
00317 
00318 public:
00319     QDesignerLabel( QWidget *parent = 0, const char *name = 0 )
00320         : QLabel( parent, name ) { myBuddy = 0; }
00321 
00322     void setBuddyWidget( const QCString &b ) {
00323         myBuddy = b;
00324         updateBuddy();
00325     }
00326     QCString buddyWidget() const {
00327         return myBuddy;
00328     };
00329 
00330 protected:
00331     void showEvent( QShowEvent *e ) {
00332         QLabel::showEvent( e );
00333         updateBuddy();
00334     }
00335 
00336 
00337 private:
00338     void updateBuddy();
00339 
00340     QCString myBuddy;
00341 
00342 };
00343 
00344 class QDesignerWidget : public QWidget
00345 {
00346     Q_OBJECT
00347 
00348 public:
00349     QDesignerWidget( FormWindow *fw, QWidget *parent, const char *name )
00350         : QWidget( parent, name, WResizeNoErase ), formwindow( fw ) {
00351             need_frame = parent && parent->inherits("QDesignerWidgetStack" );
00352     }
00353 
00354 protected:
00355     void resizeEvent( QResizeEvent* e);
00356     void paintEvent( QPaintEvent *e );
00357 
00358 private:
00359     FormWindow *formwindow;
00360     uint need_frame : 1;
00361 
00362 };
00363 
00364 class QDesignerDialog : public QDialog
00365 {
00366     Q_OBJECT
00367     Q_OVERRIDE( bool modal READ isModal WRITE setModal )
00368 
00369 public:
00370     QDesignerDialog( FormWindow *fw, QWidget *parent, const char *name )
00371         : QDialog( parent, name, FALSE, WResizeNoErase ), formwindow( fw ), modal(FALSE) {}
00372 
00373     bool isModal() const { return modal; }
00374     void setModal(bool b) { modal = b; }
00375 
00376 protected:
00377     void paintEvent( QPaintEvent *e );
00378 
00379 private:
00380     FormWindow *formwindow;
00381     bool modal;
00382 
00383 };
00384 
00385 class QDesignerToolButton : public QToolButton
00386 {
00387     Q_OBJECT
00388     Q_PROPERTY( int buttonGroupId READ buttonGroupId WRITE setButtonGroupId )
00389 
00390 public:
00391     QDesignerToolButton( QWidget *parent, const char *name )
00392         : QToolButton( parent, name ) {}
00393 
00394     bool isInButtonGroup() const {
00395         return parentWidget() && parentWidget()->inherits( "QButtonGroup" );
00396     }
00397     int buttonGroupId() const {
00398         return parentWidget() && parentWidget()->inherits( "QButtonGroup" ) ? ( (QButtonGroup*)parentWidget() )->id( (QButton*)this ) : -1;
00399     }
00400     void setButtonGroupId( int id ) {
00401         if ( parentWidget() && parentWidget()->inherits( "QButtonGroup" ) ) {
00402             ( (QButtonGroup*)parentWidget() )->remove( this );
00403             ( (QButtonGroup*)parentWidget() )->insert( this, id );
00404         }
00405     }
00406 };
00407 
00408 class QDesignerRadioButton : public QRadioButton
00409 {
00410     Q_OBJECT
00411     Q_PROPERTY( int buttonGroupId READ buttonGroupId WRITE setButtonGroupId )
00412 
00413 public:
00414     QDesignerRadioButton( QWidget *parent, const char *name )
00415         : QRadioButton( parent, name ) {}
00416 
00417     bool isInButtonGroup() const {
00418         return parentWidget() && parentWidget()->inherits( "QButtonGroup" );
00419     }
00420     int buttonGroupId() const {
00421         return parentWidget() && parentWidget()->inherits( "QButtonGroup" ) ? ( (QButtonGroup*)parentWidget() )->id( (QButton*)this ) : -1;
00422     }
00423     void setButtonGroupId( int id ) {
00424         if ( parentWidget() && parentWidget()->inherits( "QButtonGroup" ) ) {
00425             ( (QButtonGroup*)parentWidget() )->remove( this );
00426             ( (QButtonGroup*)parentWidget() )->insert( this, id );
00427         }
00428     }
00429 
00430     void setFocusPolicy( FocusPolicy policy );
00431 };
00432 
00433 class QDesignerPushButton : public QPushButton
00434 {
00435     Q_OBJECT
00436     Q_PROPERTY( int buttonGroupId READ buttonGroupId WRITE setButtonGroupId )
00437 
00438 public:
00439     QDesignerPushButton( QWidget *parent, const char *name )
00440         : QPushButton( parent, name ) {}
00441 
00442     bool isInButtonGroup() const {
00443         return parentWidget() && parentWidget()->inherits( "QButtonGroup" );
00444     }
00445     int buttonGroupId() const {
00446         return parentWidget() && parentWidget()->inherits( "QButtonGroup" ) ? ( (QButtonGroup*)parentWidget() )->id( (QButton*)this ) : -1;
00447     }
00448     void setButtonGroupId( int id ) {
00449         if ( parentWidget() && parentWidget()->inherits( "QButtonGroup" ) ) {
00450             ( (QButtonGroup*)parentWidget() )->remove( this );
00451             ( (QButtonGroup*)parentWidget() )->insert( this, id );
00452         }
00453     }
00454 
00455 };
00456 
00457 class QDesignerCheckBox : public QCheckBox
00458 {
00459     Q_OBJECT
00460     Q_PROPERTY( int buttonGroupId READ buttonGroupId WRITE setButtonGroupId )
00461 
00462 public:
00463     QDesignerCheckBox( QWidget *parent, const char *name )
00464         : QCheckBox( parent, name ) {}
00465 
00466     bool isInButtonGroup() const {
00467         return parentWidget() && parentWidget()->inherits( "QButtonGroup" );
00468     }
00469     int buttonGroupId() const {
00470         return parentWidget() && parentWidget()->inherits( "QButtonGroup" ) ? ( (QButtonGroup*)parentWidget() )->id( (QButton*)this ) : -1;
00471     }
00472     void setButtonGroupId( int id ) {
00473         if ( parentWidget() && parentWidget()->inherits( "QButtonGroup" ) ) {
00474             ( (QButtonGroup*)parentWidget() )->remove( this );
00475             ( (QButtonGroup*)parentWidget() )->insert( this, id );
00476         }
00477     }
00478 
00479 };
00480 
00481 class QDesignerToolBox : public QToolBox
00482 {
00483     Q_OBJECT
00484     Q_PROPERTY( QString itemLabel READ itemLabel WRITE setItemLabel STORED false DESIGNABLE true )
00485     Q_PROPERTY( QCString itemName READ itemName WRITE setItemName STORED false DESIGNABLE true )
00486     Q_PROPERTY( BackgroundMode itemBackgroundMode READ itemBackgroundMode WRITE setItemBackgroundMode STORED false DESIGNABLE true )
00487 
00488 public:
00489     QDesignerToolBox( QWidget *parent, const char *name );
00490 
00491     QString itemLabel() const;
00492     void setItemLabel( const QString &l );
00493     QCString itemName() const;
00494     void setItemName( const QCString &n );
00495     BackgroundMode itemBackgroundMode() const;
00496     void setItemBackgroundMode( BackgroundMode );
00497 
00498 protected:
00499     void itemInserted( int index );
00500 };
00501 
00502 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'