📄 widgetfactory.cpp
字号:
QWizard *wiz = new QDesignerWizard( parent, name );#if defined(QT_NON_COMMERCIAL) if ( parent && !parent->inherits("MainWindow") )#else if ( parent )#endif wiz->reparent( parent, QPoint( 0, 0 ), TRUE ); if ( init && parent && parent->inherits( "FormWindow" ) ) { QDesignerWidget *dw = new QDesignerWidget( (FormWindow*)parent, wiz, "page" ); MetaDataBase::addEntry( dw ); wiz->addPage( dw, FormWindow::tr( "Page" ) ); QTimer::singleShot( 0, wiz, SLOT( next() ) ); } return wiz; } else if ( className == "Spacer" ) { Spacer *s = new Spacer( parent, name ); MetaDataBase::addEntry( s ); MetaDataBase::setPropertyChanged( s, "orientation", TRUE ); MetaDataBase::setPropertyChanged( s, "sizeType", TRUE ); if ( !r ) return s; if ( !r->isValid() || r->width() < 2 && r->height() < 2 ) s->setOrientation( orient ); else if ( r->width() < r->height() ) s->setOrientation( Qt::Vertical ); else s->setOrientation( Qt::Horizontal ); return s; } else if ( className == "QLCDNumber" ) return new QLCDNumber( parent, name ); else if ( className == "QProgressBar" ) return new QProgressBar( parent, name ); else if ( className == "QTextView" ) return new QTextView( parent, name ); else if ( className == "QTextBrowser" ) return new QTextBrowser( parent, name ); else if ( className == "QDial" ) return new QDial( parent, name ); else if ( className == "QSlider" ) { QSlider *s = new QSlider( parent, name ); if ( !r ) return s; if ( !r->isValid() || r->width() < 2 && r->height() < 2 ) s->setOrientation( orient ); else if ( r->width() > r->height() ) s->setOrientation( Qt::Horizontal ); MetaDataBase::addEntry( s ); MetaDataBase::setPropertyChanged( s, "orientation", TRUE ); return s; } else if ( className == "QScrollBar" ) { QScrollBar *s = new QScrollBar( parent, name ); if ( !r ) return s; if ( !r->isValid() || r->width() < 2 && r->height() < 2 ) s->setOrientation( orient ); else if ( r->width() > r->height() ) s->setOrientation( Qt::Horizontal ); MetaDataBase::addEntry( s ); MetaDataBase::setPropertyChanged( s, "orientation", TRUE ); return s; } else if ( className == "QFrame" ) { if ( !init ) return new QFrame( parent, name ); QFrame *f = new QFrame( parent, name ); f->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); return f; } else if ( className == "Line" ) { Line *l = new Line( parent, name ); MetaDataBase::addEntry( l ); MetaDataBase::setPropertyChanged( l, "orientation", TRUE ); MetaDataBase::setPropertyChanged( l, "frameShadow", TRUE ); MetaDataBase::setPropertyChanged( l, "frameShape", TRUE ); if ( !r ) return l; if ( !r->isValid() || r->width() < 2 && r->height() < 2 ) l->setOrientation( orient ); else if ( r->width() < r->height() ) l->setOrientation( Qt::Vertical ); return l; } else if ( className == "QMainWindow" ) { QMainWindow *mw = new QMainWindow( parent, name, 0 ); mw->setDockEnabled( Qt::DockMinimized, FALSE ); QDesignerWidget *dw = new QDesignerWidget( (FormWindow*)parent, mw, "central widget" ); mw->setDockMenuEnabled( FALSE ); MetaDataBase::addEntry( dw ); mw->setCentralWidget( dw ); (void)mw->statusBar(); dw->show(); return mw; }#ifndef QT_NO_SQL else if ( className == "QDataBrowser" ) { QWidget *w = new QDesignerDataBrowser( parent, name ); if ( parent ) w->reparent( parent, QPoint( 0, 0 ), TRUE ); return w; } else if ( className == "QDataView" ) { QWidget *w = new QDesignerDataView( parent, name ); if ( parent ) w->reparent( parent, QPoint( 0, 0 ), TRUE ); return w; }#endif WidgetInterface *iface = 0; widgetManager()->queryInterface( className, &iface ); if ( !iface ) return 0; QWidget *w = iface->create( className, parent, name );#ifdef QT_CONTAINER_CUSTOM_WIDGETS if ( init && WidgetDatabase::isCustomPluginWidget( WidgetDatabase::idFromClassName( className ) ) ) { QWidgetContainerInterfacePrivate *iface2 = 0; iface->queryInterface( IID_QWidgetContainer, (QUnknownInterface**)&iface2 ); if ( iface2 ) { iface2->addPage( className, w, "Page", -1 ); iface2->release(); } }#endif iface->release(); return w;}/*! Find out which type the layout of the widget is. Returns \c HBox, \c VBox, \c Grid or \c NoLayout. \a layout points to this QWidget::layout() of \a w or to 0 after the function call.*/WidgetFactory::LayoutType WidgetFactory::layoutType( QWidget *w, QLayout *&layout ){ layout = 0; if ( w && w->inherits( "QTabWidget" ) ) w = ((QTabWidget*)w)->currentPage(); if ( w && w->inherits( "QWizard" ) ) w = ((QWizard*)w)->currentPage(); if ( w && w->inherits( "QMainWindow" ) ) w = ((QMainWindow*)w)->centralWidget(); if ( w && w->inherits( "QWidgetStack" ) ) w = ((QWidgetStack*)w)->visibleWidget(); if ( w && w->inherits( "QSplitter" ) ) return ( (QSplitter*)w )->orientation() == Horizontal ? HBox : VBox; if ( !w || !w->layout() ) return NoLayout; QLayout *lay = w->layout(); if ( w->inherits( "QGroupBox" ) ) { QObjectList *l = lay->queryList( "QLayout" ); if ( l && l->first() ) lay = (QLayout*)l->first(); delete l; } layout = lay; if ( lay->inherits( "QHBoxLayout" ) ) return HBox; else if ( lay->inherits( "QVBoxLayout" ) ) return VBox; else if ( lay->inherits( "QGridLayout" ) ) return Grid; return NoLayout;}/*! \overload*/WidgetFactory::LayoutType WidgetFactory::layoutType( QLayout *layout ){ if ( layout->inherits( "QHBoxLayout" ) ) return HBox; else if ( layout->inherits( "QVBoxLayout" ) ) return VBox; else if ( layout->inherits( "QGridLayout" ) ) return Grid; return NoLayout;}/*! \overload*/WidgetFactory::LayoutType WidgetFactory::layoutType( QWidget *w ){ QLayout *l = 0; return layoutType( w, l );}QWidget *WidgetFactory::layoutParent( QLayout *layout ){ QObject *o = layout; while ( o ) { if ( o->isWidgetType() ) return (QWidget*)o; o = o->parent(); } return 0;}/*! Returns the widget into which children should be inserted when \a w is a container known to the designer. Usually that is \a w itself, sometimes it is different (e.g. a tabwidget is known to the designer as a container but the child widgets should be inserted into the current page of the tabwidget. So in this case this function returns the current page of the tabwidget.) */QWidget* WidgetFactory::containerOfWidget( QWidget *w ){ if ( !w ) return w; if ( w->inherits( "QTabWidget" ) ) return ((QTabWidget*)w)->currentPage(); if ( w->inherits( "QWizard" ) ) return ((QWizard*)w)->currentPage(); if ( w->inherits( "QWidgetStack" ) ) return ((QWidgetStack*)w)->visibleWidget(); if ( w->inherits( "QMainWindow" ) ) return ((QMainWindow*)w)->centralWidget();#ifdef QT_CONTAINER_CUSTOM_WIDGETS if ( !WidgetDatabase::isCustomPluginWidget( WidgetDatabase::idFromClassName( classNameOf( w ) ) ) ) return w; WidgetInterface *iface = 0; widgetManager()->queryInterface( classNameOf( w ), &iface ); if ( !iface ) return w; QWidgetContainerInterfacePrivate *iface2 = 0; iface->queryInterface( IID_QWidgetContainer, (QUnknownInterface**)&iface2 ); if ( !iface2 ) return w; QWidget *c = iface2->containerOfWidget( w->className(), w ); iface2->release(); iface->release(); if ( c ) return c;#endif return w;}/*! Returns the actual designer widget of the container \a w. This is normally \a w itself, but might be a parent or grand parent of \a w (e.g. when working with a tabwidget and \a w is the container which contains and layouts childs, but the actual widget known to the designer is the tabwidget which is the parent of \a w. So this function returns the tabwidget then.)*/QWidget* WidgetFactory::widgetOfContainer( QWidget *w ){ if ( w->parentWidget() && w->parentWidget()->inherits( "QWidgetStack" ) ) w = w->parentWidget(); while ( w ) { int id = WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( w ) ); if ( WidgetDatabase::isContainer( id ) || w && w->parentWidget() && w->parentWidget()->inherits( "FormWindow" ) ) return w; w = w->parentWidget(); } return w;}/*! Returns whether \a o is a passive interactor or not. */bool WidgetFactory::lastWasAPassiveInteractor = FALSE;QGuardedPtr<QObject> *WidgetFactory::lastPassiveInteractor = new QGuardedPtr<QObject>();bool WidgetFactory::isPassiveInteractor( QObject* o ){ if ( lastPassiveInteractor && *lastPassiveInteractor && (QObject*)(*lastPassiveInteractor) == o ) return lastWasAPassiveInteractor; lastWasAPassiveInteractor = FALSE; (*lastPassiveInteractor) = o; if ( QApplication::activePopupWidget() ) // if a popup is open, we have to make sure that this one is closed, else X might do funny things return ( lastWasAPassiveInteractor = TRUE ); if ( o->inherits( "QTabBar" ) ) return ( lastWasAPassiveInteractor = TRUE ); else if ( o->inherits( "QSizeGrip" ) ) return ( lastWasAPassiveInteractor = TRUE ); else if ( o->inherits( "QToolButton" ) && o->parent() && o->parent()->inherits( "QTabBar" ) ) return ( lastWasAPassiveInteractor = TRUE ); else if ( o->parent() && o->parent()->inherits( "QWizard" ) && o->inherits( "QPushButton" ) ) return ( lastWasAPassiveInteractor = TRUE ); else if ( o->parent() && o->parent()->inherits( "QMainWindow" ) && o->inherits( "QMenuBar" ) ) return ( lastWasAPassiveInteractor = TRUE ); else if ( o->inherits( "QDockWindowHandle" ) ) return ( lastWasAPassiveInteractor = TRUE ); else if ( o->inherits( "QHideDock" ) ) return ( lastWasAPassiveInteractor = TRUE ); else if ( qstrcmp( o->name(), "designer_wizardstack_button" ) == 0 ) return ( lastWasAPassiveInteractor = TRUE );#ifdef QT_CONTAINER_CUSTOM_WIDGETS if ( !o->isWidgetType() ) return ( lastWasAPassiveInteractor = FALSE ); WidgetInterface *iface = 0; QWidget *w = (QWidget*)o; while ( !iface && w && !w->inherits( "FormWindow" ) ) { widgetManager()->queryInterface( classNameOf( w ), &iface ); w = w->parentWidget(); } if ( !iface ) return ( lastWasAPassiveInteractor = FALSE ); QWidgetContainerInterfacePrivate *iface2 = 0; iface->queryInterface( IID_QWidgetContainer, (QUnknownInterface**)&iface2 ); if ( !iface2 ) return ( lastWasAPassiveInteractor = FALSE ); QWidget *fw = MainWindow::self->isAFormWindowChild( (QWidget*)o ); if ( !fw ) return ( lastWasAPassiveInteractor = FALSE ); QWidget *dw = ( (FormWindow*)fw )->designerWidget( (QWidget*)o ); if ( !dw ) return ( lastWasAPassiveInteractor = FALSE ); lastWasAPassiveInteractor = iface2->isPassiveInteractor( dw->className(), (QWidget*)o ); iface2->release(); iface->release();#endif return lastWasAPassiveInteractor;}/*! Returns the class name of object \a o that should be used for externally (i.e. for saving) */const char* WidgetFactory::classNameOf( QObject* o ){ if ( o->inherits( "QDesignerTabWidget" ) ) return "QTabWidget"; else if ( o->inherits( "QDesignerWidgetStack" ) ) return "QWidgetStack"; else if ( o->inherits( "QWidgetStack" ) ) return "QWeDoNotWantToBreakTabWidget"; else if ( o->inherits( "QDesignerDialog" ) ) return "QDialog"; else if ( o->inherits( "QDesignerWidget" ) ) return "QWidget"; else if ( o->inherits( "CustomWidget" ) ) return ( (CustomWidget*)o )->realClassName().latin1(); else if ( o->inherits( "QDesignerLabel" ) ) return "QLabel"; else if ( o->inherits( "QDesignerWizard" ) ) return "QWizard"; else if ( o->inherits( "QDesignerPushButton" ) ) return "QPushButton"; else if ( o->inherits( "QDesignerToolButton" ) ) return "QToolButton"; else if ( o->inherits( "QDesignerRadioButton" ) ) return "QRadioButton"; else if ( o->inherits( "QDesignerCheckBox" ) ) return "QCheckBox"; else if ( o->inherits( "QDesignerMenuBar" ) ) return "QMenuBar"; else if ( o->inherits( "QDesignerToolBar" ) ) return "QToolBar"; else if ( o->inherits( "QDesignerAction" ) ) return "QAction"; else if ( o->inherits( "QDesignerActionGroup" ) ) return "QActionGroup"; else if ( o->inherits( "QDesignerPopupMenu" ) ) return "QPopupMenu";#ifndef QT_NO_SQL else if ( o->inherits( "QDesignerDataBrowser" ) ) return "QDataBrowser"; else if ( o->inherits( "QDesignerDataView" ) ) return "QDataView";#endif return o->className();}QString WidgetFactory::defaultSignal( QObject *w ){ if ( w->inherits( "QRadioButton" ) || w->inherits( "QCheckBox" ) ) return "toggled"; else if ( w->inherits( "QButton" ) || w->inherits( "QButtonGroup" ) ) return "clicked"; else if ( w->inherits( "QTextBrowser" ) ) return "linkClicked"; else if ( w->inherits( "QLineEdit" ) || w->inherits( "QTextEdit" ) ) return "textChanged"; else if ( w->inherits( "QListView" ) || w->inherits( "QIconView" ) || w->inherits( "QListBox" ) || w->inherits( "QTable" ) ) return "selectionChanged"; else if ( w->inherits( "QTabWidget" ) ) return "selected"; else if ( w->inherits( "QWidgetStack" ) ) return "aboutToShow"; else if ( w->inherits( "QSpinBox" ) || w->inherits( "QSlider" ) || w->inherits( "QScrollBar" ) || w->inherits( "QDateEdit" ) || w->inherits( "QTimeEdit" ) || w->inherits( "QDateTimeEdit" ) || w->inherits( "QDial" ) ) return "valueChanged"; else if ( w->inherits( "QComboBox" ) ) return "activated"; return QString::null;}/*! As some properties are set by default when creating a widget this functions markes this properties as changed. Has to be in sync with createWidget()!*/void WidgetFactory::initChangedProperties( QObject *o ){ if ( MainWindow::self && MainWindow::self->currProject() && MainWindow::self->currProject()->fakeFormFileFor( o ) ) return; MetaDataBase::setPropertyChanged( o, "name", TRUE ); if ( !o->inherits( "QDesignerToolBar" ) && !o->inherits( "QDesignerMenuBar" ) ) MetaDataBase::setPropertyChanged( o, "geometry", TRUE );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -