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

📄 widgetfactory.cpp

📁 Trolltech公司发布的基于C++图形开发环境
💻 CPP
📖 第 1 页 / 共 4 页
字号:
}bool WidgetFactory::hasSpecialEditor( int id, QObject *editorWidget ){    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 ( ::qt_cast<QTable*>(editorWidget) != 0 )	return TRUE;    return FALSE;}bool WidgetFactory::hasItems( int id, QObject *editorWidget ){    QString className = WidgetDatabase::className( id );    if ( className.contains( "ListBox" ) || className.contains( "ListView" ) ||	 className.contains( "IconView" )  || className.contains( "ComboBox" ) ||	 ::qt_cast<QTable*>(editorWidget) != 0 )	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 ( !::qt_cast<QListBox*>(editWidget) )	    return;	ListBoxEditor *e = new ListBoxEditor( parent, editWidget, fw );	e->exec();	delete e;	return;    }    if ( className.contains( "ComboBox" ) ) {	if ( !::qt_cast<QComboBox*>(editWidget) )	    return;	QComboBox *cb = (QComboBox*)editWidget;        QListBox *lb = cb->listBox();        if (!lb) {            lb = new QListBox(cb);            cb->setListBox(lb);        }	ListBoxEditor *e = new ListBoxEditor( parent, lb, fw );	e->exec();	delete e;	cb->update();	return;    }    if ( className.contains( "ListView" ) ) {	if ( !::qt_cast<QListView*>(editWidget) )	    return;	QListView *lv = (QListView*)editWidget;	ListViewEditor *e = new ListViewEditor( parent, lv, fw );	e->exec();	delete e;	return;    }    if ( className.contains( "IconView" ) ) {	if ( !::qt_cast<QIconView*>(editWidget) )	    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 (::qt_cast<QTable*>(editWidget) != 0) {	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";	} else if ( propName == "resizeMode" ) {	    return "Auto";	}	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 &&		 ::qt_cast<QLayoutWidget*>(parentLayout->mainWidget()) )		parentLayout = 0;	}	QObjectListIt it( *children() );	QObject *o;	if ( ::qt_cast<QVBoxLayout*>(layout()) ) {	    if ( ::qt_cast<QHBoxLayout*>(parentLayout) )		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 ( ::qt_cast<QHBoxLayout*>(layout()) ) {	    if ( ::qt_cast<QVBoxLayout*>(parentLayout) )		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 ( ::qt_cast<QGridLayout*>(layout()) ) {	    ht = QSizePolicy::Fixed;	    vt = QSizePolicy::Fixed;	    if ( parentLayout ) {		if ( ::qt_cast<QVBoxLayout*>(parentLayout) )		    ht = QSizePolicy::Minimum;		else if ( ::qt_cast<QHBoxLayout*>(parentLayout) )		    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 ( ::qt_cast<FormWindow*>(parentWidget()) ) {	( (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 );}void QDesignerRadioButton::setFocusPolicy( FocusPolicy policy ){    // Make sure we only set a policy that has a key.    // If we set a policy that is a combination of enums, it will be imposible to save    // We need this check because QButtonGroup::buttonToggled(...) will remove TabFocus,    // making the policy StrongFocus & ~TabFocus        switch ( policy ) {    case NoFocus:    case TabFocus:    case ClickFocus:    case StrongFocus:    case WheelFocus:        QRadioButton::setFocusPolicy( policy );        return;    }    QRadioButton::setFocusPolicy( NoFocus );}QDesignerToolBox::QDesignerToolBox( QWidget *parent, const char *name )    : QToolBox( parent, name ){}QString QDesignerToolBox::itemLabel() const{    return QToolBox::itemLabel( currentIndex() );}void QDesignerToolBox::setItemLabel( const QString &l ){    QToolBox::setItemLabel( currentIndex(), l );}QCString QDesignerToolBox::itemName() const{    return currentItem() ? currentItem()->name() : 0;}void QDesignerToolBox::setItemName( const QCString &n ){    if (currentItem())	currentItem()->setName( n );}Qt::BackgroundMode QDesignerToolBox::itemBackgroundMode() const{    return (item(0) ? item(0)->backgroundMode() : PaletteBackground);}void QDesignerToolBox::setItemBackgroundMode( BackgroundMode bmode ){    for (int i = 0; i < count(); ++i) {	QWidget *w = item(i);	w->setBackgroundMode( bmode );	w->update();    }}void QDesignerToolBox::itemInserted( int index ){    if (count() > 1)	item(index)->setBackgroundMode(item(index>0?0:1)->backgroundMode());}

⌨️ 快捷键说明

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