📄 widgetfactory.cpp
字号:
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; } else if ( className == "QToolBox" ) { if ( !init ) return new QDesignerToolBox( parent, name ); QToolBox *tb = new QDesignerToolBox( parent, name ); FormWindow *fw = find_formwindow( parent ); QWidget *w = fw ? new QDesignerWidget( fw, tb, "page1" ) : new QWidget( tb, "page1" ); tb->addItem( w, MainWindow::tr("Page 1") ); MetaDataBase::addEntry( w ); w = fw ? new QDesignerWidget( fw, tb, "page2" ) : new QWidget( tb, "page2" ); tb->addItem( w, MainWindow::tr("Page 2") ); MetaDataBase::addEntry( tb ); MetaDataBase::addEntry( w ); return tb; }#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 // QT_CONTAINER_CUSTOM_WIDGETS 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 ( ::qt_cast<QTabWidget*>(w) ) w = ((QTabWidget*)w)->currentPage(); if ( ::qt_cast<QWizard*>(w) ) w = ((QWizard*)w)->currentPage(); if ( ::qt_cast<QMainWindow*>(w) ) w = ((QMainWindow*)w)->centralWidget(); if ( ::qt_cast<QWidgetStack*>(w) ) w = ((QWidgetStack*)w)->visibleWidget(); if ( ::qt_cast<QToolBox*>(w) ) w = ((QToolBox*)w)->currentItem(); if ( ::qt_cast<QSplitter*>(w) ) return ( (QSplitter*)w )->orientation() == Horizontal ? HBox : VBox; if ( !w || !w->layout() ) return NoLayout; QLayout *lay = w->layout(); if ( ::qt_cast<QGroupBox*>(w) ) { QObjectList *l = lay->queryList( "QLayout" ); if ( l && l->first() ) lay = (QLayout*)l->first(); delete l; } layout = lay; if ( ::qt_cast<QHBoxLayout*>(lay) ) return HBox; else if ( ::qt_cast<QVBoxLayout*>(lay) ) return VBox; else if ( ::qt_cast<QGridLayout*>(lay) ) return Grid; return NoLayout;}/*! \overload*/WidgetFactory::LayoutType WidgetFactory::layoutType( QLayout *layout ){ if ( ::qt_cast<QHBoxLayout*>(layout) ) return HBox; else if ( ::qt_cast<QVBoxLayout*>(layout) ) return VBox; else if ( ::qt_cast<QGridLayout*>(layout) ) 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 ( ::qt_cast<QTabWidget*>(w) ) return ((QTabWidget*)w)->currentPage(); if ( ::qt_cast<QWizard*>(w) ) return ((QWizard*)w)->currentPage(); if ( ::qt_cast<QWidgetStack*>(w) ) return ((QWidgetStack*)w)->visibleWidget(); if ( ::qt_cast<QToolBox*>(w) ) return ((QToolBox*)w)->currentItem(); if ( ::qt_cast<QMainWindow*>(w) ) 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 // QT_CONTAINER_CUSTOM_WIDGETS 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 && ::qt_cast<QWidgetStack*>(w->parentWidget()) ) w = w->parentWidget(); if ( w->parentWidget() && w->parentWidget()->parentWidget() && w->parentWidget()->parentWidget()->parentWidget() && ::qt_cast<QToolBox*>(w->parentWidget()->parentWidget()->parentWidget()) ) return w->parentWidget()->parentWidget()->parentWidget(); while ( w ) { int id = WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( w ) ); if ( WidgetDatabase::isContainer( id ) || w && ::qt_cast<FormWindow*>(w->parentWidget()) ) 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 ( ::qt_cast<QTabBar*>(o) ) return ( lastWasAPassiveInteractor = TRUE ); else if ( ::qt_cast<QSizeGrip*>(o) ) return ( lastWasAPassiveInteractor = TRUE ); else if ( ::qt_cast<QButton*>(o) && ( ::qt_cast<QTabBar*>(o->parent()) || ::qt_cast<QToolBox*>(o->parent()) ) ) return ( lastWasAPassiveInteractor = TRUE ); else if ( ::qt_cast<QPushButton*>(o) && ::qt_cast<QWizard*>(o->parent()) ) return ( lastWasAPassiveInteractor = TRUE ); else if ( ::qt_cast<QMenuBar*>(o) && ::qt_cast<QMainWindow*>(o->parent()) ) return ( lastWasAPassiveInteractor = TRUE );// else if ( ::qt_cast<QDockWindowHandle*>(o) ) else if ( o->inherits( "QDockWindowHandle" ) ) return ( lastWasAPassiveInteractor = TRUE );// else if ( ::qt_cast<QHideDock*>(o) ) 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 && !::qt_cast<FormWindow*>(w) ) { 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 // QT_CONTAINER_CUSTOM_WIDGETS 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->isA( "PropertyObject" ) ) return o->className(); if (WidgetDatabase::isCustomPluginWidget(WidgetDatabase::idFromClassName(o->className()))) return o->className(); else if ( ::qt_cast<QDesignerTabWidget*>(o) ) return "QTabWidget"; else if ( ::qt_cast<QDesignerWidgetStack*>(o) ) return "QWidgetStack"; else if ( ::qt_cast<QWidgetStack*>(o) ) return "QWeDoNotWantToBreakTabWidget"; else if ( ::qt_cast<QDesignerDialog*>(o) ) return "QDialog"; else if ( ::qt_cast<QDesignerWidget*>(o) ) return "QWidget"; else if ( o->inherits( "CustomWidget" ) ) return ( (CustomWidget*)o )->realClassName().latin1(); else if ( ::qt_cast<QDesignerLabel*>(o) ) return "QLabel"; else if ( ::qt_cast<QDesignerWizard*>(o) ) return "QWizard"; else if ( ::qt_cast<QDesignerPushButton*>(o) ) return "QPushButton"; else if ( ::qt_cast<QDesignerToolButton*>(o) ) return "QToolButton"; else if ( ::qt_cast<QDesignerRadioButton*>(o) ) return "QRadioButton"; else if ( ::qt_cast<QDesignerCheckBox*>(o) ) return "QCheckBox"; else if ( ::qt_cast<MenuBarEditor*>(o) ) return "QMenuBar"; else if ( ::qt_cast<QDesignerToolBar*>(o) ) return "QToolBar"; else if ( ::qt_cast<QDesignerAction*>(o) ) return "QAction"; else if ( ::qt_cast<QDesignerActionGroup*>(o) ) return "QActionGroup"; else if ( ::qt_cast<PopupMenuEditor*>(o) ) return "QPopupMenu"; else if ( ::qt_cast<QDesignerToolBox*>(o) ) return "QToolBox";#ifndef QT_NO_SQL else if ( ::qt_cast<QDesignerDataBrowser*>(o) ) return "QDataBrowser"; else if ( ::qt_cast<QDesignerDataView*>(o) ) return "QDataView";#endif return o->className();}QString WidgetFactory::defaultSignal( QObject *w ){ if ( ::qt_cast<QRadioButton*>(w) || ::qt_cast<QCheckBox*>(w) ) return "toggled"; else if ( ::qt_cast<QButton*>(w) || ::qt_cast<QButtonGroup*>(w) ) return "clicked"; else if ( ::qt_cast<QTextBrowser*>(w) ) return "linkClicked"; else if ( ::qt_cast<QLineEdit*>(w) || ::qt_cast<QTextEdit*>(w) ) return "textChanged"; else if ( ::qt_cast<QListView*>(w) || ::qt_cast<QIconView*>(w) || ::qt_cast<QListBox*>(w) || ::qt_cast<QTable*>(w) ) return "selectionChanged"; else if ( ::qt_cast<QTabWidget*>(w) ) return "selected"; else if ( ::qt_cast<QToolBox*>(w) ) return "currentChanged"; else if ( ::qt_cast<QWidgetStack*>(w) ) return "aboutToShow"; else if ( ::qt_cast<QSpinBox*>(w) || ::qt_cast<QSlider*>(w) || ::qt_cast<QScrollBar*>(w) || ::qt_cast<QDateEdit*>(w) || ::qt_cast<QTimeEdit*>(w) || ::qt_cast<QDateTimeEdit*>(w) || ::qt_cast<QDial*>(w) ) return "valueChanged"; else if ( ::qt_cast<QComboBox*>(w) ) 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 ( !::qt_cast<QDesignerToolBar*>(o) && !::qt_cast<MenuBarEditor*>(o) ) MetaDataBase::setPropertyChanged( o, "geometry", TRUE ); if ( ::qt_cast<QPushButton*>(o) || ::qt_cast<QRadioButton*>(o) || ::qt_cast<QCheckBox*>(o) || ::qt_cast<QToolButton*>(o) ) { if (::qt_cast<QToolButton*>(o) && ::qt_cast<QToolBox*>(widgetOfContainer((QWidget*)o->parent()))) { MetaDataBase::setPropertyChanged( o, "usesTextLabel", TRUE ); MetaDataBase::setPropertyChanged( o, "textLabel", TRUE ); MetaDataBase::setPropertyChanged( o, "autoRaise", TRUE ); MetaDataBase::setPropertyChanged( o, "textPosition", TRUE ); } else { MetaDataBase::setPropertyChanged( o, "text", TRUE ); } } else if ( ::qt_cast<QGroupBox*>(o) ) MetaDataBase::setPropertyChanged( o, "title", TRUE ); else if ( o->isA( "QFrame" ) ) { MetaDataBase::setPropertyChanged( o, "frameShadow", TRUE ); MetaDataBase::setPropertyChanged( o, "frameShape", TRUE ); } else if ( ::qt_cast<QTabWidget*>(o) || ::qt_cast<QWizard*>(o) ) { MetaDataBase::setPropertyChanged( o, "pageTitle", TRUE ); MetaDataBase::setPropertyChanged( o, "pageName", TRUE ); MetaDataBase::setPropertyChanged( o, "currentPage", TRUE ); } else if ( ::qt_cast<QWidgetStack*>(o) ) { MetaDataBase::setPropertyChanged( o, "currentPage", TRUE ); MetaDataBase::setPropertyChanged( o, "pageName", TRUE ); } else if ( ::qt_cast<QToolBox*>(o) ) { MetaDataBase::setPropertyChanged( o, "currentIndex", TRUE ); MetaDataBase::setPropertyChanged( o, "itemName", TRUE ); MetaDataBase::setPropertyChanged( o, "itemLabel", TRUE ); MetaDataBase::setPropertyChanged( o, "itemIconSet", TRUE ); MetaDataBase::setPropertyChanged( o, "itemToolTip", TRUE ); MetaDataBase::setPropertyChanged( o, "itemBackgroundMode", TRUE );#ifndef QT_NO_TABLE } else if ( ::qt_cast<QTable*>(o) ) {# ifndef QT_NO_SQL if (!::qt_cast<QDataTable*>(o) )# endif { MetaDataBase::setPropertyChanged( o, "numRows", TRUE ); MetaDataBase::setPropertyChanged( o, "numCols", TRUE ); QTable *t = (QTable*)o; for ( int i = 0; i < 3; ++i ) { t->horizontalHeader()->setLabel( i, QString::number( i + 1 ) ); t->verticalHeader()->setLabel( i, QString::number( i + 1 ) ); } }#endif } else if ( ::qt_cast<QSplitter*>(o) ) { MetaDataBase::setPropertyChanged( o, "orientation", TRUE ); } else if ( ::qt_cast<QDesignerToolBar*>(o) ) { MetaDataBase::setPropertyChanged( o, "label", TRUE ); } else if ( ::qt_cast<MenuBarEditor*>(o) ) { MetaDataBase::setPropertyChanged( o, "itemName", TRUE ); MetaDataBase::setPropertyChanged( o, "itemNumber", TRUE ); MetaDataBase::setPropertyChanged( o, "itemText", TRUE ); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -