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

📄 widgetfactory.cpp

📁 Trolltech公司发布的基于C++图形开发环境
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*!  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();    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 ) {	if ( WidgetDatabase::isContainer( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( w ) ) ) ||	     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::isPassiveInteractor( QObject* o ){    if ( o->inherits( "QTabBar" ) )	return TRUE;    else if ( o->inherits( "QSizeGrip" ) )	return TRUE;    else if ( o->inherits( "QToolButton" ) && o->parent() && o->parent()->inherits( "QTabBar" ) )	return TRUE;    else if ( o->parent() && o->parent()->inherits( "QWizard" ) && o->inherits( "QPushButton" ) )	return TRUE;    return FALSE;}/*!  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( "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";    return o->className();}/*!  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 ){    MetaDataBase::setPropertyChanged( o, "name", TRUE );    MetaDataBase::setPropertyChanged( o, "geometry", TRUE );    if ( o->inherits( "QPushButton" ) || o->inherits("QRadioButton") || o->inherits( "QCheckBox" ) || o->inherits( "QToolButton" ) )	MetaDataBase::setPropertyChanged( o, "text", TRUE );    else if ( o->inherits( "QGroupBox" ) )	MetaDataBase::setPropertyChanged( o, "title", TRUE );    else if ( o->isA( "QFrame" ) ) {	MetaDataBase::setPropertyChanged( o, "frameShadow", TRUE );	MetaDataBase::setPropertyChanged( o, "frameShape", TRUE );    } else if ( o->inherits( "QTabWidget" ) || o->inherits( "QWizard" ) ) {	MetaDataBase::setPropertyChanged( o, "pageTitle", TRUE );	MetaDataBase::setPropertyChanged( o, "pageName", TRUE );#ifndef QT_NO_TABLE    } else if ( o->inherits( "QTable" ) ) {	MetaDataBase::setPropertyChanged( o, "numRows", TRUE );	MetaDataBase::setPropertyChanged( o, "numCols", TRUE );#endif    }}bool WidgetFactory::hasSpecialEditor( int id ){    QString className = WidgetDatabase::className( id );    if ( className.mid( 1 ) == "ListBox" )	return TRUE;    if ( className.mid( 1 ) == "ComboBox" )	return TRUE;    if ( className.mid( 1 ) == "ListView" )	return TRUE;    if ( className.mid( 1 ) == "IconView" )	return TRUE;    if ( className == "QMultiLineEdit" )	return TRUE;    return FALSE;}bool WidgetFactory::hasItems( int id ){    QString className = WidgetDatabase::className( id );    if ( className.mid( 1 ) == "ListBox" || className.mid( 1 ) == "ListView" ||	 className.mid( 1 ) == "IconView" || className.mid( 1 ) == "ComboBox" )	return TRUE;    return FALSE;}void WidgetFactory::editWidget( int id, QWidget *parent, QWidget *editWidget, FormWindow *fw ){    QString className = WidgetDatabase::className( id );    if ( className.mid( 1 ) == "ListBox" ) {	if ( !editWidget->inherits( "QListBox" ) )	    return;	ListBoxEditor *e = new ListBoxEditor( parent, editWidget, fw );	e->exec();	delete e;	return;    }    if ( className.mid( 1 ) == "ComboBox" ) {	if ( !editWidget->inherits( "QComboBox" ) )	    return;	QComboBox *cb = (QComboBox*)editWidget;	ListBoxEditor *e = new ListBoxEditor( parent, cb->listBox(), fw );	e->exec();	delete e;	cb->update();	return;    }    if ( className.mid( 1 ) == "ListView" ) {	if ( !editWidget->inherits( "QListView" ) )	    return;	QListView *lv = (QListView*)editWidget;	ListViewEditor *e = new ListViewEditor( parent, lv, fw );	e->exec();	delete e;	return;    }    if ( className.mid( 1 ) == "IconView" ) {	if ( !editWidget->inherits( "QIconView" ) )	    return;	IconViewEditor *e = new IconViewEditor( parent, editWidget, fw );	e->exec();	delete e;	return;    }    if ( className == "QMultiLineEdit" ) {	MultiLineEditor *e = new MultiLineEditor( parent, editWidget, fw );	e->exec();	delete e;	return;    }}bool WidgetFactory::canResetProperty( QWidget *w, const QString &propName ){    if ( propName == "name" || propName == "geometry" )	return FALSE;    QStringList l = *changedProperties->find( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( w ) ) );    return l.findIndex( propName ) == -1;}bool WidgetFactory::resetProperty( QWidget *w, const QString &propName ){    const QMetaProperty *p = w->metaObject()->property( propName, TRUE );    if (!p || ( p->reset == 0 ) )	return FALSE;    typedef void (QObject::*ProtoVoid)() const;    ProtoVoid m = (ProtoVoid)p->reset;    (w->*m)();    return TRUE;}QVariant WidgetFactory::defaultValue( QWidget *w, const QString &propName ){    if ( propName == "wordwrap" ) {	int v = defaultValue( w, "alignment" ).toInt();	return QVariant( ( v & WordBreak ) == WordBreak, 0 );    } else if ( propName == "toolTip" || propName == "whatsThis" ) {	return QVariant( QString::fromLatin1( "" ) );    } else if ( w->inherits( "CustomWidget" ) ) {	return QVariant();    }    return *( *defaultProperties->find( WidgetDatabase::idFromClassName( classNameOf( w ) ) ) ).find( propName );}QString WidgetFactory::defaultCurrentItem( QWidget *w, const QString &propName ){    const QMetaProperty *p = w->metaObject()->property( propName, TRUE );    if ( !p ) {	int v = defaultValue( w, "alignment" ).toInt();	if ( propName == "hAlign" ) {	    if ( ( v & AlignLeft ) == AlignLeft )		return "AlignLeft";	    if ( ( v & AlignCenter ) == AlignCenter || ( v & AlignHCenter ) == AlignHCenter )		return "AlignHCenter";	    if ( ( v & AlignRight ) == AlignRight )		return "AlignRight";	} else if ( propName == "vAlign" ) {	    if ( ( v & AlignTop ) == AlignTop )		return "AlignTop";	    if ( ( v & AlignCenter ) == AlignCenter || ( v & AlignVCenter ) == AlignVCenter )		return "AlignVCenter";	    if ( ( v & AlignBottom ) == AlignBottom )		return "AlignBottom";	}	return QString::null;	    }    return p->valueToKey( defaultValue( w, propName ).toInt() );}QWidget *WidgetFactory::createCustomWidget( QWidget *parent, const char *name, MetaDataBase::CustomWidget *w ){    if ( !w )	return 0;    return new CustomWidget( parent, name, w );}QVariant WidgetFactory::property( QWidget *w, const char *name ){    QVariant v = w->property( name );    if ( v.isValid() )	return v;    return MetaDataBase::fakeProperty( w, name );}void QDesignerLabel::updateBuddy(){    if ( myBuddy.isEmpty() )	return;    QObjectList *l = topLevelWidget()->queryList( "QWidget", myBuddy, FALSE, TRUE );    if ( !l || !l->first() ) {	delete l;	return;    }    QLabel::setBuddy( (QWidget*)l->first() );    delete l;}void QDesignerWidget::paintEvent( QPaintEvent *e ){    formwindow->paintGrid( this, e );}void QDesignerDialog::paintEvent( QPaintEvent *e ){    formwindow->paintGrid( this, e );}QSizePolicy QLayoutWidget::sizePolicy() const{    return sp;}bool QLayoutWidget::event( QEvent *e ){    if ( e && ( e->type() == QEvent::ChildInserted ||		e->type() == QEvent::ChildRemoved ||		e->type() == QEvent::LayoutHint ) )	updateSizePolicy();    return QWidget::event( e );}void QLayoutWidget::updateSizePolicy(){    if ( !children() || children()->count() == 0 ) {	sp = QWidget::sizePolicy();	return;    }    QObjectListIt it( *children() );    QObject *o;    QSizePolicy::SizeType vt = QSizePolicy::Preferred;    QSizePolicy::SizeType ht = QSizePolicy::Preferred;    while ( ( o = it.current() ) ) {	++it;	if ( !o->inherits( "QWidget" ) || ( (QWidget*)o )->testWState( WState_ForceHide ) )	    continue;	QWidget *w = (QWidget*)o;	if ( w->sizePolicy().horData() == QSizePolicy::Expanding ||	     w->sizePolicy().horData() == QSizePolicy::MinimumExpanding )	    ht = QSizePolicy::Expanding;	else if ( w->sizePolicy().horData() == QSizePolicy::Fixed && ht != QSizePolicy::Expanding )	    ht = QSizePolicy::Fixed;	if ( w->sizePolicy().verData() == QSizePolicy::Expanding ||	     w->sizePolicy().verData() == QSizePolicy::MinimumExpanding )	    vt = QSizePolicy::Expanding;	else if ( w->sizePolicy().verData() == QSizePolicy::Fixed && vt != QSizePolicy::Expanding )	    vt = QSizePolicy::Fixed;    }    sp = QSizePolicy( ht, vt );    if ( layout() )	layout()->invalidate();    updateGeometry();}void CustomWidget::paintEvent( QPaintEvent *e ){    if ( parentWidget() && parentWidget()->inherits( "FormWindow" ) ) {	( (FormWindow*)parentWidget() )->paintGrid( this, e );    } else {	QPainter p( this );	p.fillRect( rect(), colorGroup().dark() );	p.drawPixmap( ( width() - cusw->pixmap->width() ) / 2,		      ( height() - cusw->pixmap->height() ) / 2,		      *cusw->pixmap );    }}

⌨️ 快捷键说明

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