📄 widgetfactory.cpp
字号:
} else { QLayout *l; switch ( type ) { case HBox: l = new QHBoxLayout( widget ); if ( widget ) { MetaDataBase::setMargin( widget, margin ); MetaDataBase::setSpacing( widget, spacing ); } else { l->setMargin( margin ); l->setSpacing( margin ); } return l; case VBox: l = new QVBoxLayout( widget ); if ( widget ) { MetaDataBase::setMargin( widget, margin ); MetaDataBase::setSpacing( widget, spacing ); } else { l->setMargin( margin ); l->setSpacing( margin ); } return l; case Grid: { l = new QDesignerGridLayout( widget ); if ( widget ) { MetaDataBase::setMargin( widget, margin ); MetaDataBase::setSpacing( widget, spacing ); } else { l->setMargin( margin ); l->setSpacing( margin ); } return l; } default: return 0; } } } return 0;}void WidgetFactory::deleteLayout( QWidget *widget ){ if ( !widget ) return; if ( widget->inherits( "QTabWidget" ) ) widget = ((QTabWidget*)widget)->currentPage(); if ( widget->inherits( "QWizard" ) ) widget = ((QWizard*)widget)->currentPage(); if ( widget->inherits( "QWidgetStack" ) ) widget = ((QWidgetStack*)widget)->visibleWidget(); delete widget->layout();}FormWindow *find_formwindow( QWidget *w ){ if ( !w ) return 0; while ( w ) { if ( w->inherits( "FormWindow" ) ) return (FormWindow*)w; w = w->parentWidget(); } return 0;}/*! Factory functions for creating a widget of the type \a className as child of \a parent with the name \a name. If \a init is TRUE, some initial default properties are set. This has to be in sync with the initChangedProperties() function!*/QWidget *WidgetFactory::createWidget( const QString &className, QWidget *parent, const char *name, bool init, const QRect *r, Qt::Orientation orient ){ if ( className == "QPushButton" ) { QPushButton *b = 0; if ( init ) { b = new QDesignerPushButton( parent, name ); b->setText( QString::fromLatin1( name ) ); } else { b = new QDesignerPushButton( parent, name ); } b->setAutoDefault( TRUE ); return b; } else if ( className == "QToolButton" ) { if ( init ) { QDesignerToolButton *tb = new QDesignerToolButton( parent, name ); tb->setText( "..." ); return tb; } return new QDesignerToolButton( parent, name ); } else if ( className == "QCheckBox" ) { if ( init ) { QDesignerCheckBox *cb = new QDesignerCheckBox( parent, name ); cb->setText( QString::fromLatin1( name ) ); return cb; } return new QDesignerCheckBox( parent, name ); } else if ( className == "QRadioButton" ) { if ( init ) { QDesignerRadioButton *rb = new QDesignerRadioButton( parent, name ); rb->setText( QString::fromLatin1( name ) ); return rb; } return new QDesignerRadioButton( parent, name ); } else if ( className == "QGroupBox" ) { if ( init ) return new QGroupBox( QString::fromLatin1( name ), parent, name ); return new QGroupBox( parent, name ); } else if ( className == "QButtonGroup" ) { if ( init ) return new QButtonGroup( QString::fromLatin1( name ), parent, name ); return new QButtonGroup( parent, name ); } else if ( className == "QIconView" ) {#if defined(QT_MODULE_ICONVIEW) QIconView* iv = new QIconView( parent, name ); if ( init ) (void) new QIconViewItem( iv, MainWindow::tr( "New Item" ) ); return iv;#else return 0;#endif } else if ( className == "QTable" ) {#if defined(QT_MODULE_TABLE) return new QTable( 3, 3, parent, name );#else return 0;#endif } else if ( className == "QListBox" ) { QListBox* lb = new QListBox( parent, name ); if ( init ) { lb->insertItem( MainWindow::tr( "New Item" ) ); lb->setCurrentItem( 0 ); } return lb; } else if ( className == "QListView" ) { QListView *lv = new QListView( parent, name ); lv->setSorting( -1 ); if ( init ) { lv->addColumn( MainWindow::tr( "Column 1" ) ); lv->setCurrentItem( new QListViewItem( lv, MainWindow::tr( "New Item" ) ) ); } return lv; } else if ( className == "QLineEdit" ) return new QLineEdit( parent, name ); else if ( className == "QSpinBox" ) return new QSpinBox( parent, name ); else if ( className == "QMultiLineEdit" ) return new QMultiLineEdit( parent, name ); else if ( className == "QLabel" || className == "TextLabel" ) { QDesignerLabel *l = new QDesignerLabel( parent, name ); if ( init ) { l->setText( QString::fromLatin1( name ) ); MetaDataBase::addEntry( l ); MetaDataBase::setPropertyChanged( l, "text", TRUE ); } return l; } else if ( className == "PixmapLabel" ) { QDesignerLabel *l = new QDesignerLabel( parent, name ); if ( init ) { l->setPixmap( PixmapChooser::loadPixmap( "qtlogo.png", PixmapChooser::NoSize ) ); l->setScaledContents( TRUE ); MetaDataBase::addEntry( l ); MetaDataBase::setPropertyChanged( l, "pixmap", TRUE ); MetaDataBase::setPropertyChanged( l, "scaledContents", TRUE ); } return l; } else if ( className == "QLayoutWidget" ) return new QLayoutWidget( parent, name ); else if ( className == "QTabWidget" ) { QTabWidget *tw = new QDesignerTabWidget( parent, name ); if ( init ) { FormWindow *fw = find_formwindow( parent ); QWidget *w = fw ? new QDesignerWidget( fw, tw, "tab" ) : new QWidget( tw, "tab" ); tw->addTab( w, MainWindow::tr("Tab 1") ); w = fw ? new QDesignerWidget( fw, tw, "tab" ) : new QWidget( tw, "tab" ); MetaDataBase::addEntry( tw ); tw->addTab( w, MainWindow::tr("Tab 2") ); MetaDataBase::addEntry( tw ); MetaDataBase::addEntry( w ); } return tw; } else if ( className == "QComboBox" ) { return new QComboBox( FALSE, parent, name ); } else if ( className == "QWidget" ) { if ( parent && ( parent->inherits( "FormWindow" ) || parent->inherits( "QWizard" ) || parent->inherits( "QTabWidget" ) ) ) { FormWindow *fw = find_formwindow( parent ); if ( fw ) { QDesignerWidget *dw = new QDesignerWidget( fw, parent, name ); MetaDataBase::addEntry( dw ); return dw; } } return new QWidget( parent, name ); } else if ( className == "QDialog" ) { QDialog *dia = 0; if ( parent && parent->inherits( "FormWindow" ) ) dia = new QDesignerDialog( (FormWindow*)parent, parent, name ); else dia = new QDialog( parent, name );#if defined(QT_NON_COMMERCIAL) if ( parent && !parent->inherits("MainWindow") )#else if ( parent )#endif dia->reparent( parent, QPoint( 0, 0 ), TRUE ); return dia; } else if ( className == "QWizard" ) { 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 == "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 ); 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; } QWidget *w = qt_create_kde_widget( className, parent, name, init ); if ( w ) return w; return 0;}/*! 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( "QWidgetStack" ) ) w = ((QWidgetStack*)w)->visibleWidget(); 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;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -