⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 widgetfactory.cpp

📁 Linux下的基于X11的图形开发环境。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    return title( currentPage() );}void QDesignerWizard::setPageTitle( const QString& title ){    setTitle( currentPage(), title );}void QDesignerWizard::setPageName( const QCString& name ){    if ( QWizard::currentPage() )	QWizard::currentPage()->setName( name );}QCString QDesignerWizard::pageName() const{    if ( !QWizard::currentPage() )	return 0;    return QWizard::currentPage()->name();}int QDesignerWizard::pageNum( QWidget *p ){    for ( int i = 0; i < pageCount(); ++i ) {	if ( page( i ) == p )	    return i;    }    return -1;}void QDesignerWizard::addPage( QWidget *p, const QString &t ){    QWizard::addPage( p, t );    if ( removedPages.find( p ) )	removedPages.remove( p );}void QDesignerWizard::removePage( QWidget *p ){    QWizard::removePage( p );    removedPages.insert( p, p );}void QDesignerWizard::insertPage( QWidget *p, const QString &t, int index ){    QWizard::insertPage( p, t, index );    if ( removedPages.find( p ) )	removedPages.remove( p );}QMap< int, QMap< QString, QVariant> > *defaultProperties = 0;QMap< int, QStringList > *changedProperties = 0;/*!  \class WidgetFactory widgetfactory.h  \brief Set of static functions for creating widgets, layouts and do other stuff  The widget factory offers functions to create widgets, create and  delete layouts find out other details - all based on the  WidgetDatabase's data. So the functions that use ids use the same  ids as in the WidgetDatabase.*/void WidgetFactory::saveDefaultProperties( QObject *w, int id ){    QMap< QString, QVariant> propMap;    QStrList lst = w->metaObject()->propertyNames( TRUE );    for ( uint i = 0; i < lst.count(); ++i ) {	QVariant var = w->property( lst.at( i ) );	if ( !var.isValid() && qstrcmp( "pixmap", lst.at( i ) ) == 0 )	    var = QVariant( QPixmap() );	else if ( !var.isValid() && qstrcmp( "iconSet", lst.at( i ) ) == 0 )	    var = QVariant( QIconSet() );	propMap.replace( lst.at( i ), var );    }    defaultProperties->replace( id, propMap );}void WidgetFactory::saveChangedProperties( QObject *w, int id ){    QStringList l = MetaDataBase::changedProperties( w );    changedProperties->insert( id, l );}/*!  Creates a widget of the type which is registered as \a id as  child of \a parent. The \a name is optional. If \a init is TRUE, the  widget is initialized with some defaults, else the plain widget is  created.*/QWidget *WidgetFactory::create( int id, QWidget *parent, const char *name, bool init, const QRect *r, Qt::Orientation orient ){    QString n = WidgetDatabase::className( id );    if ( n.isEmpty() )	return 0;    if ( !defaultProperties ) {	defaultProperties = new QMap< int, QMap< QString, QVariant> >();	changedProperties = new QMap< int, QStringList >();    }    QWidget *w = 0;    QString str = WidgetDatabase::createWidgetName( id );    str[0] = str[0].lower();    const char *s = str.latin1();    w = createWidget( n, parent, name ? name : s, init, r, orient );    if ( w && w->inherits( "QScrollView" ) )	( (QScrollView*)w )->disableSizeHintCaching();    if ( !w && WidgetDatabase::isCustomWidget( id ) )	w = createCustomWidget( parent, name ? name : s, MetaDataBase::customWidget( id ) );    if ( !w )	return 0;    MetaDataBase::addEntry( w );    if ( !defaultProperties->contains( id ) )	saveDefaultProperties( w, id );    if ( !changedProperties->contains( id ) )	saveChangedProperties( w, id );    return w;}/*!  Creates a layout on the widget \a widget of the type \a type  which can be \c HBox, \c VBox or \c Grid.*/QLayout *WidgetFactory::createLayout( QWidget *widget, QLayout *layout, LayoutType type ){    int spacing = MainWindow::self->currentLayoutDefaultSpacing();    int margin = 0;    int metaspacing = MetaDataBase::spacing( widget );    int metamargin = MetaDataBase::margin( widget );    if ( widget && !widget->inherits( "QLayoutWidget" ) &&	 ( WidgetDatabase::isContainer( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( widget ) ) ) ||	   widget && widget->parentWidget() && widget->parentWidget()->inherits( "FormWindow" ) ) )	margin = MainWindow::self->currentLayoutDefaultMargin();    if ( !layout && widget && widget->inherits( "QTabWidget" ) )	widget = ((QTabWidget*)widget)->currentPage();    if ( !layout && widget && widget->inherits( "QWizard" ) )	widget = ((QWizard*)widget)->currentPage();    if ( !layout && widget && widget->inherits( "QMainWindow" ) )	widget = ((QMainWindow*)widget)->centralWidget();    if ( !layout && widget && widget->inherits( "QWidgetStack" ) )	widget = ((QWidgetStack*)widget)->visibleWidget();    MetaDataBase::addEntry( widget );    QLayout *l = 0;    int align = 0;    if ( !layout && widget && widget->inherits( "QGroupBox" ) ) {	QGroupBox *gb = (QGroupBox*)widget;	gb->setColumnLayout( 0, Qt::Vertical );	layout = gb->layout();	layout->setMargin( 0 );	layout->setSpacing( 0 );	switch ( type ) {	case HBox:	    l = new QHBoxLayout( layout );	    break;	case VBox:	    l = new QVBoxLayout( layout );	    break;	case Grid:	    l = new QDesignerGridLayout( layout );	    break;	default:	    return 0;	}	align = Qt::AlignTop;	MetaDataBase::setMargin( gb, metamargin );	MetaDataBase::setSpacing( gb, metaspacing );    } else {	if ( layout ) {	    switch ( type ) {	    case HBox:		l = new QHBoxLayout( layout );		break;	    case VBox:		l = new QVBoxLayout( layout );		break;	    case Grid:		l = new QDesignerGridLayout( layout );		break;	    default:		return 0;	    }	    MetaDataBase::addEntry( l );	    l->setSpacing( spacing );	    l->setMargin( margin );	} else {	    switch ( type ) {	    case HBox:		l = new QHBoxLayout( widget );		break;	    case VBox:		l = new QVBoxLayout( widget );		break;	    case Grid:		l = new QDesignerGridLayout( widget );		break;	    default:		return 0;	    }	    MetaDataBase::addEntry( l );	    if ( widget ) {		MetaDataBase::setMargin( widget, metamargin );		MetaDataBase::setSpacing( widget, metaspacing );	    } else {		l->setMargin( margin );		l->setSpacing( spacing );	    }	}    }    l->setAlignment( align );    MetaDataBase::addEntry( l );    return l;}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( "QMainWindow" ) )	widget = ((QMainWindow*)widget)->centralWidget();    if ( widget->inherits( "QWidgetStack" ) )	widget = ((QWidgetStack*)widget)->visibleWidget();    delete widget->layout();}/*!  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 );	}	QWidget *w = find_formwindow( b );	b->setAutoDefault( w && ( (FormWindow*)w )->mainContainer()->inherits( "QDialog" ) );	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_NO_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_NO_TABLE)	if ( init )	    return new QTable( 3, 3, parent, name );	return new QTable( parent, name );#else	return 0;#endif#ifndef QT_NO_SQL    } else if ( className == "QDataTable" ) {	return new QDataTable( parent, name );#endif //QT_NO_SQL    } else if ( className == "QDateEdit" ) {	return new QDateEdit( parent, name );    } else if ( className == "QTimeEdit" ) {	return new QTimeEdit( parent, name );    } else if ( className == "QDateTimeEdit" ) {	return new QDateTimeEdit( parent, name );    }    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 == "QSplitter" )	return new QSplitter( parent, name );    else if ( className == "QMultiLineEdit" )	return new QMultiLineEdit( parent, name );    else if ( className == "QTextEdit" )	return new QTextEdit( 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( QPixmap::fromMimeSource( "qtlogo.png" ) );	    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") );	    MetaDataBase::addEntry( w );	    w = fw ? new QDesignerWidget( fw, tw, "tab" ) : new QWidget( tw, "tab" );	    tw->addTab( w, MainWindow::tr("Tab 2") );	    MetaDataBase::addEntry( tw );	    MetaDataBase::addEntry( w );	}	return tw;    } else if ( className == "QWidgetStack" ) {	QDesignerWidgetStack *ws = new QDesignerWidgetStack( parent, name );	if ( init ) {	    FormWindow *fw = find_formwindow( parent );	    QWidget *w = fw ? new QDesignerWidget( fw, ws, "page" ) : new QWidget( ws, "page" );	    ws->insertPage( w );	    MetaDataBase::addEntry( w );	    MetaDataBase::addEntry( ws );	}	return ws;    } 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" ) || parent->inherits( "QWidgetStack" ) ||	       parent->inherits( "QMainWindow" ) ) ) {	    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" ) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -