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

📄 qwidgetfactory.cpp

📁 Linux下的基于X11的图形开发环境。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	    break;	default:	    return 0;	}    }    l->setAlignment( align );    l->setMargin( margin );    l->setSpacing( spacing );    return l;}QWidgetFactory::LayoutType QWidgetFactory::layoutType( QLayout *layout ) const{    if ( layout->inherits( "QHBoxLayout" ) )	return HBox;    else if ( layout->inherits( "QVBoxLayout" ) )	return VBox;    else if ( layout->inherits( "QGridLayout" ) )	return Grid;    return NoLayout;}void QWidgetFactory::setProperty( QObject* obj, const QString &prop,				  QVariant value ){    int offset = obj->metaObject()->findProperty( prop, TRUE );    if ( offset != -1 ) {	if ( prop == "geometry" && obj == toplevel ) {	    toplevel->resize( value.toRect().size() );	} else if ( prop == "accel" ) {	    obj->setProperty( prop, value.toKeySequence() );	} else {	    if ( value.type() == QVariant::String ||		 value.type() == QVariant::CString ) {		const QMetaProperty *metaProp =			obj->metaObject()->property( offset, TRUE );		if ( metaProp != 0 && metaProp->isEnumType() ) {		    if ( metaProp->isSetType() ) {			QStrList flagsCStr;			QStringList flagsStr =			    QStringList::split( '|', value.asString() );			QStringList::ConstIterator f = flagsStr.begin();			while ( f != flagsStr.end() ) {			    flagsCStr.append( *f );			    ++f;			}			value = QVariant( metaProp->keysToValue(flagsCStr) );		    } else {			QCString key = value.toCString();			value = QVariant( metaProp->keyToValue(key) );		    }		}	    }	    obj->setProperty( prop, value );	}    } else {	if ( obj->isWidgetType() ) {	    if ( prop == "toolTip" ) {		if ( !value.toString().isEmpty() )		    QToolTip::add( (QWidget*)obj, value.toString() );	    } else if ( prop == "whatsThis" ) {		if ( !value.toString().isEmpty() )		    QWhatsThis::add( (QWidget*)obj, value.toString() );	    } else if ( prop == "buddy" ) {		buddies.insert( obj->name(), value.toCString() );	    } else if ( prop == "buttonGroupId" ) {		if ( obj->inherits( "QButton" ) && obj->parent()->inherits( "QButtonGroup" ) )		    ( (QButtonGroup*)obj->parent() )->insert( (QButton*)obj, value.toInt() );#ifndef QT_NO_SQL	    } else if ( prop == "database" && !obj->inherits( "QDataView" )		 && !obj->inherits( "QDataBrowser" ) ) {		const QStringList& lst = value.asStringList();		if ( lst.count() > 2 ) {		    if ( dbControls )			dbControls->insert( obj->name(), lst[ 2 ] );		} else if ( lst.count() == 2 ) {		    dbTables.insert( obj->name(), lst );		}	    } else if ( prop == "database" ) {		const QStringList& lst = value.asStringList();		if ( lst.count() == 2 && obj->inherits( "QWidget" ) ) {		    SqlWidgetConnection conn( lst[ 0 ], lst[ 1 ] );		    sqlWidgetConnections.insert( (QWidget*)obj, conn );		    dbControls = conn.dbControls;		}#endif	    } else if ( prop == "frameworkCode" ) {		if ( value.isValid() && !value.toBool() )		    noDatabaseWidgets << obj->name();	    }	}    }}void QWidgetFactory::setProperty( QObject* widget, const QString &prop, const QDomElement &e ){    QString comment;    QVariant value( DomTool::elementToVariant( e, QVariant(), comment ) );    if ( e.tagName() == "string" ) {	value = translate( value.asString().utf8(), comment.utf8() );    } else if ( e.tagName() == "pixmap" ) {	QPixmap pix = loadPixmap( value.toString() );	if ( !pix.isNull() )	    value = pix;    } else if ( e.tagName() == "iconset" ) {	QPixmap pix = loadPixmap( value.toString() );	if ( !pix.isNull() )	    value = QIconSet( pix );    } else if ( e.tagName() == "image" ) {	value = loadFromCollection( value.toString() );    } else if ( e.tagName() == "palette" ) {	QDomElement n = e.firstChild().toElement();	QPalette p;	while ( !n.isNull() ) {	    QColorGroup cg;	    if ( n.tagName() == "active" ) {		cg = loadColorGroup( n );		p.setActive( cg );	    } else if ( n.tagName() == "inactive" ) {		cg = loadColorGroup( n );		p.setInactive( cg );	    } else if ( n.tagName() == "disabled" ) {		cg = loadColorGroup( n );		p.setDisabled( cg );	    }	    n = n.nextSibling().toElement();	}	value = p;    }    setProperty( widget, prop, value );}void QWidgetFactory::createSpacer( const QDomElement &e, QLayout *layout ){    QDomElement n = e.firstChild().toElement();    int row = e.attribute( "row" ).toInt();    int col = e.attribute( "column" ).toInt();    int rowspan = e.attribute( "rowspan" ).toInt();    int colspan = e.attribute( "colspan" ).toInt();    Qt::Orientation orient = Qt::Horizontal;    int w = 0, h = 0;    QSizePolicy::SizeType sizeType = QSizePolicy::Preferred;    while ( !n.isNull() ) {	if ( n.tagName() == "property" ) {	    QString prop = n.attribute( "name" );	    if ( prop == "orientation" ) {		if ( n.firstChild().firstChild().toText().data() == "Horizontal" )		    orient = Qt::Horizontal;		else		    orient = Qt::Vertical;	    } else if ( prop == "sizeType" ) {		sizeType = stringToSizeType( n.firstChild().firstChild().toText().data() );	    } else if ( prop == "sizeHint" ) {		w = n.firstChild().firstChild().firstChild().toText().data().toInt();		h = n.firstChild().firstChild().nextSibling().firstChild().toText().data().toInt();	    }	}	n = n.nextSibling().toElement();    }    if ( rowspan < 1 )	rowspan = 1;    if ( colspan < 1 )	colspan = 1;    QSpacerItem *item = new QSpacerItem( w, h, orient == Qt::Horizontal ? sizeType : QSizePolicy::Minimum,					 orient == Qt::Vertical ? sizeType : QSizePolicy::Minimum );    if ( layout ) {	if ( layout->inherits( "QBoxLayout" ) )	    ( (QBoxLayout*)layout )->addItem( item );	else	    ( (QGridLayout*)layout )->addMultiCell( item, row, row + rowspan - 1, col, col + colspan - 1,						    orient == Qt::Horizontal ? Qt::AlignVCenter : Qt::AlignHCenter );    }}static QImage loadImageData( QDomElement &n2 ){    QString format = n2.attribute( "format", "PNG" );    QString hex = n2.firstChild().toText().data();    int n = hex.length() / 2;    QByteArray data( n );    for ( int i = 0; i < n; i++ )	data[i] = (char) hex.mid( 2 * i, 2 ).toUInt( 0, 16 );    return loadImageData( format, n2.attribute("length").toULong(), data );}void QWidgetFactory::loadImageCollection( const QDomElement &e ){    QDomElement n = e.firstChild().toElement();    while ( !n.isNull() ) {	if ( n.tagName() == "image" ) {	    Image img;	    img.name =  n.attribute( "name" );	    QDomElement n2 = n.firstChild().toElement();	    while ( !n2.isNull() ) {		if ( n2.tagName() == "data" )		    img.img = loadImageData( n2 );		n2 = n2.nextSibling().toElement();	    }	    images.append( img );	    n = n.nextSibling().toElement();	}    }}QImage QWidgetFactory::loadFromCollection( const QString &name ){    QValueList<Image>::Iterator it = images.begin();    for ( ; it != images.end(); ++it ) {	if ( ( *it ).name == name )	    return ( *it ).img;    }    return QImage();}QPixmap QWidgetFactory::loadPixmap( const QString& name ){    QPixmap pix;    if ( usePixmapCollection ) {	const QMimeSource *m = QMimeSourceFactory::defaultFactory()->data( name );	if ( m )	    QImageDrag::decode( m, pix );    } else {	pix.convertFromImage( loadFromCollection(name) );    }    return pix;}QPixmap QWidgetFactory::loadPixmap( const QDomElement &e ){    return loadPixmap( e.firstChild().toText().data() );}QColorGroup QWidgetFactory::loadColorGroup( const QDomElement &e ){    QColorGroup cg;    int r = -1;    QDomElement n = e.firstChild().toElement();    QColor col;    while ( !n.isNull() ) {	if ( n.tagName() == "color" ) {	    r++;	    cg.setColor( (QColorGroup::ColorRole)r, (col = DomTool::readColor( n ) ) );	} else if ( n.tagName() == "pixmap" ) {	    QPixmap pix = loadPixmap( n );	    cg.setBrush( (QColorGroup::ColorRole)r, QBrush( col, pix ) );	}	n = n.nextSibling().toElement();    }    return cg;}struct Connection{    QObject *sender, *receiver;    QCString signal, slot;    bool operator==( const Connection &c ) const {	return sender == c.sender && receiver == c.receiver &&	       signal == c.signal && slot == c.slot ;    }    Connection() : sender( 0 ), receiver( 0 ) { }};class NormalizeObject : public QObject{public:    NormalizeObject() : QObject() {}    static QCString normalizeSignalSlot( const char *signalSlot ) { return QObject::normalizeSignalSlot( signalSlot ); }};void QWidgetFactory::loadConnections( const QDomElement &e, QObject *connector ){    QDomElement n = e.firstChild().toElement();    while ( !n.isNull() ) {	if ( n.tagName() == "connection" ) {	    QString lang = n.attribute( "language", "C++" );	    QDomElement n2 = n.firstChild().toElement();	    Connection conn;	    while ( !n2.isNull() ) {		if ( n2.tagName() == "sender" ) {		    QString name = n2.firstChild().toText().data();		    if ( name == "this" || qstrcmp( toplevel->name(), name ) == 0 ) {			conn.sender = toplevel;		    } else {			if ( name == "this" )			    name = toplevel->name();			QObjectList *l = toplevel->queryList( 0, name, FALSE );			if ( l ) {			    if ( l->first() )				conn.sender = l->first();			    delete l;			}		    }		    if ( !conn.sender )			conn.sender = findAction( name );		} else if ( n2.tagName() == "signal" ) {		    conn.signal = n2.firstChild().toText().data();		} else if ( n2.tagName() == "receiver" ) {		    QString name = n2.firstChild().toText().data();		    if ( name == "this" || qstrcmp( toplevel->name(), name ) == 0 ) {			conn.receiver = toplevel;		    } else {			QObjectList *l = toplevel->queryList( 0, name, FALSE );			if ( l ) {			    if ( l->first() )				conn.receiver = l->first();			    delete l;			}		    }		} else if ( n2.tagName() == "slot" ) {		    conn.slot = n2.firstChild().toText().data();		}		n2 = n2.nextSibling().toElement();	    }	    conn.signal = NormalizeObject::normalizeSignalSlot( conn.signal );	    conn.slot = NormalizeObject::normalizeSignalSlot( conn.slot );	    QObject *sender = 0, *receiver = 0;	    QObjectList *l = toplevel->queryList( 0, conn.sender->name(), FALSE );	    if ( qstrcmp( conn.sender->name(), toplevel->name() ) == 0 ) {		sender = toplevel;	    } else {		if ( !l || !l->first() ) {		    delete l;		    n = n.nextSibling().toElement();		    continue;		}		sender = l->first();		delete l;	    }	    if ( !sender )		sender = findAction( conn.sender->name() );	    if ( qstrcmp( conn.receiver->name(), toplevel->name() ) == 0 ) {		receiver = toplevel;	    } else {		l = toplevel->queryList( 0, conn.receiver->name(), FALSE );		if ( !l || !l->first() ) {		    delete l;		    n = n.nextSibling().toElement();		    continue;		}		receiver = l->first();		delete l;	    }	    QString s = "2""%1";	    s = s.arg( conn.signal );	    QString s2 = "1""%1";	    s2 = s2.arg( conn.slot );	    QStrList signalList = sender->metaObject()->signalNames( TRUE );	    QStrList slotList = receiver->metaObject()->slotNames( TRUE );	    // if this is a connection to a custom slot and we have a connector, try this as receiver	    if ( slotList.find( conn.slot ) == -1 && receiver == toplevel && connector ) {		slotList = connector->metaObject()->slotNames( TRUE );		receiver = connector;	    }	    // avoid warnings	    if ( signalList.find( conn.signal ) == -1 ||		 slotList.find( conn.slot ) == -1 ) {		n = n.nextSibling().toElement();		continue;	    }	    QObject::connect( sender, s, receiver, s2 );	}	n = n.nextSibling().toElement();    }}void QWidgetFactory::loadTabOrder( const QDomElement &e ){    QWidget *last = 0;    QDomElement n = e.firstChild().toElement();    while ( !n.isNull() ) {	if ( n.tagName() == "tabstop" ) {	    QString name = n.firstChild().toText().data();	    QObjectList *l = toplevel->queryList( 0, name, FALSE );	    if ( l ) {		if ( l->first() ) {		    QWidget *w = (QWidget*)l->first();		    if ( last )			toplevel->setTabOrder( last, w );		    last = w;		}		delete l;	    }	}	n = n.nextSibling().toElement();    }}void QWidgetFactory::createListViewColumn( QListView *lv, const QString& txt,					   const QPixmap& pix, bool clickable,					   bool resizable ){    if ( pix.isNull() ) {	lv->addColumn( txt );    } else {	lv->addColumn( pix, txt );    }    int i = lv->header()->count() - 1;    if ( !pix.isNull() )	lv->header()->setLabel( i, pix, txt );    if ( !clickable )	lv->header()->setClickEnabled( clickable, i );    if ( !resizable )	lv->header()->setResizeEnabled( resizable, i );}#ifndef QT_NO_TABLEvoid QWidgetFactory::createTableColumnOrRow( QTable *table, const QString& txt,					     const QPixmap& pix,					     const QString& field, bool isRow ){#ifndef QT_NO_SQL    bool isSql = table->inherits( "QDataTable" );#endif    if ( isRow )	table->setNumRows( table->numRows() + 1 );    else {#ifndef QT_NO_SQL	if ( !isSql )#endif	    table->setNumCols( table->numCols() + 1 );    }    QValueList<Field> fieldMap;    if ( fieldMaps.find( table ) != fieldMaps.end() ) {	fieldMap = *fieldMaps.find( table );	fieldMaps.remove( table );    }    int i = isRow ? table->numRows() - 1 : table->numCols() - 1;    QHeader *h = !isRow ? table->horizontalHeader() : table->verticalHeader();    if ( !pix.isNull() ) {#ifndef QT_NO_SQL	if ( isSql )	    ((QDataTable*)t

⌨️ 快捷键说明

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