qwidgetfactory.cpp

来自「qt-x11-free-3.0.3.tar.gz minigui图形界面工具」· C++ 代码 · 共 1,717 行 · 第 1/4 页

CPP
1,717
字号
#ifndef QT_NO_SQL	    if ( prop == "database" && !obj->inherits( "QDataView" )		 && !obj->inherits( "QDataBrowser" ) ) {		QStringList lst = DomTool::elementToVariant( e, QVariant( QStringList() ) ).toStringList();		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" ) {		QStringList lst = DomTool::elementToVariant( e, QVariant( QStringList() ) ).toStringList();		if ( lst.count() == 2 && obj->inherits( "QWidget" ) ) {		    SqlWidgetConnection conn( lst[ 0 ], lst[ 1 ] );		    sqlWidgetConnections.insert( (QWidget*)obj, conn );		    dbControls = conn.dbControls;		}	    } else#endif		if ( prop == "buddy" ) {		buddies.insert( obj->name(), v.toCString() );	    } else if ( prop == "frameworkCode" ) {		if ( !DomTool::elementToVariant( e, QVariant( TRUE, 0 ) ).toBool() ) {		    noDatabaseWidgets << obj->name();		}	    } else if ( prop == "buttonGroupId" ) {		if ( obj->inherits( "QButton" ) && obj->parent()->inherits( "QButtonGroup" ) )		    ( (QButtonGroup*)obj->parent() )->insert( (QButton*)obj, v.toInt() );	    }	    return;	}    }    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();	}	v = QPalette( p );    } else if ( e.tagName() == "enum" && p && p->isEnumType() ) {	QString key( v.toString() );	v = QVariant( p->keyToValue( key ) );    } else if ( e.tagName() == "set" && p && p->isSetType() ) {	QString keys( v.toString() );	QStringList lst = QStringList::split( '|', keys );	QStrList l;	for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it )	    l.append( *it );	v = QVariant( p->keysToValue( l ) );    }    if ( prop == "geometry" ) {	if ( obj == toplevel ) {	    toplevel->resize( v.toRect().size() );	    return;	}    }    obj->setProperty( prop, v );}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" ) {		if ( n.firstChild().firstChild().toText().data() == "Fixed" )		    sizeType = QSizePolicy::Fixed;		else if ( n.firstChild().firstChild().toText().data() == "Minimum" )		    sizeType = QSizePolicy::Minimum;		else if ( n.firstChild().firstChild().toText().data() == "Maximum" )		    sizeType = QSizePolicy::Maximum;		else if ( n.firstChild().firstChild().toText().data() == "Preferred" )		    sizeType = QSizePolicy::Preferred;		else if ( n.firstChild().firstChild().toText().data() == "MinimumExpanding" )		    sizeType = QSizePolicy::MinimumExpanding;		else if ( n.firstChild().firstChild().toText().data() == "Expanding" )		    sizeType = QSizePolicy::Expanding;	    } 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 ){    QImage img;    QString data = n2.firstChild().toText().data();    char *ba = new char[ data.length() / 2 ];    for ( int i = 0; i < (int)data.length() / 2; ++i ) {	char h = data[ 2 * i ].latin1();	char l = data[ 2 * i  + 1 ].latin1();	uchar r = 0;	if ( h <= '9' )	    r += h - '0';	else	    r += h - 'a' + 10;	r = r << 4;	if ( l <= '9' )	    r += l - '0';	else	    r += l - 'a' + 10;	ba[ i ] = r;    }    QString format = n2.attribute( "format", "PNG" );    if ( format == "XPM.GZ" ) {	ulong len = n2.attribute( "length" ).toULong();	if ( len < data.length() * 5 )	    len = data.length() * 5;	QByteArray baunzip( len );	::uncompress( (uchar*) baunzip.data(), &len, (uchar*) ba, data.length()/2 );	img.loadFromData( (const uchar*)baunzip.data(), len, "XPM" );    }  else {	img.loadFromData( (const uchar*)ba, data.length() / 2, format );    }    delete [] ba;    return img;}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 QDomElement &e ){    QString arg = e.firstChild().toText().data();    if ( usePixmapCollection ) {	const QMimeSource *m = QMimeSourceFactory::defaultFactory()->data( arg );	if ( !m )	    return QPixmap();	QPixmap pix;	QImageDrag::decode( m, pix );	return pix;    }    QImage img = loadFromCollection( arg );    QPixmap pix;    pix.convertFromImage( img );    return pix;}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 ;    }};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;	    }	    if ( lang == "C++" ) {		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 );	    } else {		EventFunction ef = eventMap[ conn.sender ];		ef.events.append( conn.signal );		ef.functions.append( QStringList::split( ',', conn.slot ) );		eventMap.replace( conn.sender, ef );	    }	} else if ( n.tagName() == "slot" ) {	    QString s = n.firstChild().toText().data();	    languageSlots.insert( s.left( s.find( "(" ) ) , n.attribute( "language" ) );	}	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::createColumn( const QDomElement &e, QWidget *widget ){    if ( widget->inherits( "QListView" ) && e.tagName() == "column" ) {	QListView *lv = (QListView*)widget;	QDomElement n = e.firstChild().toElement();	QPixmap pix;	bool hasPixmap = FALSE;	QString txt;	bool clickable = TRUE, resizeable = TRUE;	while ( !n.isNull() ) {	    if ( n.tagName() == "property" ) {		QString attrib = n.attribute( "name" );		QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() );		if ( attrib == "text" )		    txt = v.toString();		else if ( attrib == "pixmap" ) {		    pix = loadPixmap( n.firstChild().toElement().toElement() );		    hasPixmap = !pix.isNull();		} else if ( attrib == "clickable" )		    clickable = v.toBool();		else if ( attrib == "resizeable" )		    resizeable = v.toBool();	    }	    n = n.nextSibling().toElement();	}	lv->addColumn( txt );	int i = lv->header()->count() - 1;	if ( hasPixmap ) {	    lv->header()->setLabel( i, pix, txt );	}	if ( !clickable )	    lv->header()->setClickEnabled( clickable, i );	if ( !resizeable )	    lv->header()->setResizeEnabled( resizeable, i );    }#ifndef QT_NO_TABLE    else if ( widget->inherits( "QTable" ) ) {	QTable *table = (QTable*)widget;#ifndef QT_NO_SQL	bool isSql = (widget->inherits( "QDataTable" ));#endif	bool isRow;	if ( ( isRow = e.tagName() == "row" ) )	    table->setNumRows( table->numRows() + 1 );	else {#ifndef QT_NO_SQL	    if ( !isSql )

⌨️ 快捷键说明

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