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

📄 widgetfactory.cpp

📁 Linux下的基于X11的图形开发环境。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    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 );	MetaDataBase::setPropertyChanged( o, "currentPage", TRUE );    } else if ( o->inherits( "QWidgetStack" ) ) {	MetaDataBase::setPropertyChanged( o, "currentPage", TRUE );	MetaDataBase::setPropertyChanged( o, "pageName", TRUE );#ifndef QT_NO_TABLE    } else if ( o->inherits( "QTable" ) && !o->inherits( "QDataTable" ) ) {	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 ( o->inherits( "QSplitter" )  ) {	MetaDataBase::setPropertyChanged( o, "orientation", TRUE );    } else if ( o->inherits( "QDesignerToolBar" )  ) {	MetaDataBase::setPropertyChanged( o, "label", TRUE );    } else if ( o->inherits( "QDesignerMenuBar" )  ) {	MetaDataBase::setPropertyChanged( o, "itemName", TRUE );	MetaDataBase::setPropertyChanged( o, "itemNumber", TRUE );	MetaDataBase::setPropertyChanged( o, "itemText", TRUE );    }}bool WidgetFactory::hasSpecialEditor( int id ){    QString className = WidgetDatabase::className( id );    if ( className.contains( "ListBox" ) )	return TRUE;    if ( className.contains( "ComboBox" ) )	return TRUE;    if ( className.contains( "ListView" ) )	return TRUE;    if ( className.contains( "IconView" ) )	return TRUE;    if ( className == "QTextEdit" || className == "QMultiLineEdit" )	return TRUE;    if ( className.contains( "Table" ) )	return TRUE;    return FALSE;}bool WidgetFactory::hasItems( int id ){    QString className = WidgetDatabase::className( id );    if ( className.contains( "ListBox" ) || className.contains( "ListView" ) ||	 className.contains( "IconView" )  || className.contains( "ComboBox" ) ||	 className.contains( "Table" ) )	return TRUE;    return FALSE;}void WidgetFactory::editWidget( int id, QWidget *parent, QWidget *editWidget, FormWindow *fw ){    QString className = WidgetDatabase::className( id );    if ( className.contains( "ListBox" ) ) {	if ( !editWidget->inherits( "QListBox" ) )	    return;	ListBoxEditor *e = new ListBoxEditor( parent, editWidget, fw );	e->exec();	delete e;	return;    }    if ( className.contains( "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.contains( "ListView" ) ) {	if ( !editWidget->inherits( "QListView" ) )	    return;	QListView *lv = (QListView*)editWidget;	ListViewEditor *e = new ListViewEditor( parent, lv, fw );	e->exec();	delete e;	return;    }    if ( className.contains( "IconView" ) ) {	if ( !editWidget->inherits( "QIconView" ) )	    return;	IconViewEditor *e = new IconViewEditor( parent, editWidget, fw );	e->exec();	delete e;	return;    }    if ( className == "QMultiLineEdit" || className == "QTextEdit" ) {	MultiLineEditor *e = new MultiLineEditor( FALSE, TRUE, parent, editWidget, fw );	e->exec();	delete e;	return;    }#ifndef QT_NO_TABLE    if ( className.contains( "Table" ) ) {	TableEditor *e = new TableEditor( parent, editWidget, fw );	e->exec();	delete e;	return;    }#endif}bool WidgetFactory::canResetProperty( QObject *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( QObject *w, const QString &propName ){    const QMetaProperty *p = w->metaObject()->property( w->metaObject()->							findProperty( propName, TRUE ), TRUE );    if (!p )	return FALSE;    return p->reset( w );}QVariant WidgetFactory::defaultValue( QObject *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();    } else if ( propName == "frameworkCode" ) {	return QVariant( TRUE, 0 );    } else if ( propName == "layoutMargin" || propName == "layoutSpacing" ) {	return QVariant( -1 );    }    return *( *defaultProperties->find( WidgetDatabase::idFromClassName( classNameOf( w ) ) ) ).find( propName );}QString WidgetFactory::defaultCurrentItem( QObject *w, const QString &propName ){    const QMetaProperty *p = w->metaObject()->			     property( w->metaObject()->findProperty( propName, TRUE ), TRUE );    if ( !p ) {	int v = defaultValue( w, "alignment" ).toInt();	if ( propName == "hAlign" ) {	    if ( ( v & AlignAuto ) == AlignAuto )		return "AlignAuto";	    if ( ( v & AlignLeft ) == AlignLeft )		return "AlignLeft";	    if ( ( v & AlignCenter ) == AlignCenter || ( v & AlignHCenter ) == AlignHCenter )		return "AlignHCenter";	    if ( ( v & AlignRight ) == AlignRight )		return "AlignRight";	    if ( ( v & AlignJustify ) == AlignJustify )		return "AlignJustify";	} 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( QObject *w, const char *name ){    int id = w->metaObject()->findProperty( name, TRUE );    const QMetaProperty* p = w->metaObject()->property( id, TRUE );    if ( !p || !p->isValid() )	return MetaDataBase::fakeProperty( w, name );    return w->property( 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::resizeEvent( QResizeEvent* e){    if ( need_frame ) {	QPainter p(this);	p.setPen( backgroundColor() );	p.drawRect( QRect( QPoint(0,0), e->oldSize() ) );    }}void QDesignerWidget::paintEvent( QPaintEvent *e ){    if ( need_frame ) {	QPainter p(this);	p.setPen( backgroundColor().dark() );	p.drawRect( rect() );    }    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 ||		e->type() == QEvent::Reparent ) )	updateSizePolicy();    return QWidget::event( e );}/*  This function must be called on QLayoutWidget creation and whenever  the QLayoutWidget's parent layout changes (e.g., from a QHBoxLayout  to a QVBoxLayout), because of the (illogical) way layouting works.*/void QLayoutWidget::updateSizePolicy(){    if ( !children() || children()->count() == 0 ) {	sp = QWidget::sizePolicy();	return;    }    /*      QSizePolicy::MayShrink & friends are private. Here we assume the      following:	  Fixed = 0	  Maximum = MayShrink	  Minimum = MayGrow	  Preferred = MayShrink | MayGrow    */    int ht = (int) QSizePolicy::Preferred;    int vt = (int) QSizePolicy::Preferred;    if ( layout() ) {	/*	  parentLayout is set to the parent layout if there is one and if it is	  top level, in which case layouting is illogical.	*/	QLayout *parentLayout = 0;	if ( parent() && parent()->isWidgetType() ) {	    parentLayout = ((QWidget *)parent())->layout();	    if ( parentLayout && parentLayout->mainWidget()->inherits("QLayoutWidget") )		parentLayout = 0;	}	QObjectListIt it( *children() );	QObject *o;	if ( layout()->inherits("QVBoxLayout") ) {	    if ( parentLayout && parentLayout->inherits("QHBoxLayout") )		vt = QSizePolicy::Minimum;	    else		vt = QSizePolicy::Fixed;	    while ( ( o = it.current() ) ) {		++it;		if ( !o->isWidgetType() || ( (QWidget*)o )->testWState( WState_ForceHide ) )		    continue;		QWidget *w = (QWidget*)o;		if ( !w->sizePolicy().mayGrowHorizontally() )		    ht &= ~QSizePolicy::Minimum;		if ( !w->sizePolicy().mayShrinkHorizontally() )		    ht &= ~QSizePolicy::Maximum;		if ( w->sizePolicy().mayGrowVertically() )		    vt |= QSizePolicy::Minimum;		if ( w->sizePolicy().mayShrinkVertically() )		    vt |= QSizePolicy::Maximum;	    }	} else if ( layout()->inherits("QHBoxLayout") ) {	    if ( parentLayout && parentLayout->inherits("QVBoxLayout") )		ht = QSizePolicy::Minimum;	    else		ht = QSizePolicy::Fixed;	    while ( ( o = it.current() ) ) {		++it;		if ( !o->isWidgetType() || ( (QWidget*)o )->testWState( WState_ForceHide ) )		    continue;		QWidget *w = (QWidget*)o;		if ( w->sizePolicy().mayGrowHorizontally() )		    ht |= QSizePolicy::Minimum;		if ( w->sizePolicy().mayShrinkHorizontally() )		    ht |= QSizePolicy::Maximum;		if ( !w->sizePolicy().mayGrowVertically() )		    vt &= ~QSizePolicy::Minimum;		if ( !w->sizePolicy().mayShrinkVertically() )		    vt &= ~QSizePolicy::Maximum;	    }	} else if ( layout()->inherits("QGridLayout") ) {	    ht = QSizePolicy::Fixed;	    vt = QSizePolicy::Fixed;	    if ( parentLayout ) {		if ( parentLayout->inherits("QVBoxLayout") )		    ht = QSizePolicy::Minimum;		else if ( parentLayout->inherits("QHBoxLayout") )		    vt = QSizePolicy::Minimum;	    }	    while ( ( o = it.current() ) ) {		++it;		if ( !o->isWidgetType() || ( (QWidget*)o )->testWState( WState_ForceHide ) )		    continue;		QWidget *w = (QWidget*)o;		if ( w->sizePolicy().mayGrowHorizontally() )		    ht |= QSizePolicy::Minimum;		if ( w->sizePolicy().mayShrinkHorizontally() )		    ht |= QSizePolicy::Maximum;		if ( w->sizePolicy().mayGrowVertically() )		    vt |= QSizePolicy::Minimum;		if ( w->sizePolicy().mayShrinkVertically() )		    vt |= QSizePolicy::Maximum;	    }	}	if ( layout()->expanding() & QSizePolicy::Horizontally )	    ht = QSizePolicy::Expanding;	if ( layout()->expanding() & QSizePolicy::Vertically )	    vt = QSizePolicy::Expanding;	layout()->invalidate();    }    sp = QSizePolicy( (QSizePolicy::SizeType) ht, (QSizePolicy::SizeType) vt );    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.setPen( colorGroup().light() );	p.drawText( 2, 2, width() - 4, height() - 4, Qt::AlignAuto | Qt::AlignTop, cusw->className );	p.drawPixmap( ( width() - cusw->pixmap->width() ) / 2,		      ( height() - cusw->pixmap->height() ) / 2,		      *cusw->pixmap );    }}CustomWidgetFactory::CustomWidgetFactory(){}QWidget *CustomWidgetFactory::createWidget( const QString &className, QWidget *parent, const char *name ) const{    MetaDataBase::CustomWidget *w = MetaDataBase::customWidget( WidgetDatabase::idFromClassName( className ) );    if ( !w )	return 0;    return WidgetFactory::createCustomWidget( parent, name, w );}

⌨️ 快捷键说明

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