uic.cpp

来自「Trolltech公司发布的基于C++图形开发环境」· C++ 代码 · 共 1,994 行 · 第 1/5 页

CPP
1,994
字号
    return s;}/*!  Creates implementation of an listview column tag.*/QString Uic::createListViewColumnImpl( const QDomElement &e, const QString &parent ){    QDomElement n = e.firstChild().toElement();    QString txt;    QString com;    QString pix;    bool clickable = FALSE, resizeable = FALSE;    while ( !n.isNull() ) {	if ( n.tagName() == "property" ) {	    QDomElement n2 = n.firstChild().toElement();	    if ( n2.tagName() == "name" ) {		com = getComment(n);		QString attrib = n2.firstChild().toText().data();		QVariant v = DomTool::elementToVariant( n2.nextSibling().toElement(), QVariant() );		if ( attrib == "text" )		    txt = v.toString();		else if ( attrib == "pixmap" ) {		    pix = v.toString();		    if ( !pix.isEmpty() && !pixmapLoaderFunction.isEmpty() ) {			pix.prepend( pixmapLoaderFunction + "( " );			pix.append( " )" );		    }		} else if ( attrib == "clickable" )		    clickable = v.toBool();		else if ( attrib == "resizeable" )		    resizeable = v.toBool();	    }	}	n = n.nextSibling().toElement();    }    QString s;    s = indent + parent + "->addColumn( " + trcall( txt, com ) + " );\n";    if ( !pix.isEmpty() )	s += indent + parent + "->header()->setLabel( " + parent + "->header()->count() - 1, " + pix + ", " + trcall( txt, com ) + " );\n";    if ( !clickable )	s += indent + parent + "->header()->setClickEnabled( FALSE, " + parent + "->header()->count() - 1 );\n";    if ( !resizeable )	s += indent + parent + "->header()->setResizeEnabled( FALSE, " + parent + "->header()->count() - 1 );\n";    return s;}/*!  Creates the implementation of a layout tag. Called from createObjectImpl(). */QString Uic::createLayoutImpl( const QDomElement &e, const QString& parentClass, const QString& parent, const QString& layout ){    QDomElement n;    QString objClass, objName;    objClass = e.tagName();    QString qlayout = "QVBoxLayout";    if ( objClass == "hbox" )	qlayout = "QHBoxLayout";    else if ( objClass == "grid" )	qlayout = "QGridLayout";    bool isGrid = e.tagName() == "grid" ;    objName = registerObject( getLayoutName( e ) );    layoutObjects += objName;    int margin = DomTool::readProperty( e, "margin", BOXLAYOUT_DEFAULT_MARGIN ).toInt();    int spacing = DomTool::readProperty( e, "spacing", BOXLAYOUT_DEFAULT_SPACING ).toInt();    if ( (parentClass == "QGroupBox" || parentClass == "QButtonGroup") && layout.isEmpty() ) {	// special case for group box	out << indent << parent << "->setColumnLayout(0, Qt::Vertical );" << endl;	out << indent << parent << "->layout()->setSpacing( 0 );" << endl;	out << indent << parent << "->layout()->setMargin( 0 );" << endl;	out << indent << objName << " = new " << qlayout << "( " << parent << "->layout() );" << endl;	out << indent << objName << "->setAlignment( Qt::AlignTop );" << endl;    } else {	if ( layout.isEmpty() )	    out << indent << objName << " = new " << qlayout << "( " << parent << " ); " << endl;	else	    out << indent << objName << " = new " << qlayout << "; " << endl;    }    out << indent << objName << "->setSpacing( " << spacing << " );" << endl;    out << indent << objName << "->setMargin( " << margin << " );" << endl;    if ( !isGrid ) {	for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {	    if ( n.tagName() == "spacer" ) {		QString child = createSpacerImpl( n, parentClass, parent, objName );		out << indent << objName << "->addItem( " << child << " );" << endl;	    } else if ( tags.contains( n.tagName() ) ) {		QString child = createObjectImpl( n, parentClass, parent, objName );		if ( isLayout( child ) )		    out << indent << objName << "->addLayout( " << child << " );" << endl;		else		    out << indent << objName << "->addWidget( " << child << " );" << endl;	    }	}    } else {	for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {	    QDomElement ae = n;	    int row = ae.attribute( "row" ).toInt();	    int col = ae.attribute( "column" ).toInt();	    int rowspan = ae.attribute( "rowspan" ).toInt();	    int colspan = ae.attribute( "colspan" ).toInt();	    if ( rowspan < 1 )		rowspan = 1;	    if ( colspan < 1 )		colspan = 1;	    if ( n.tagName() == "spacer" ) {		QString child = createSpacerImpl( n, parentClass, parent, objName );		if ( rowspan * colspan != 1 )		    out << indent << objName << "->addMultiCell( " << child << ", "			<< row << ", " << row + rowspan - 1 << ", " << col << ", " << col  + colspan - 1 << " );" << endl;		else		    out << indent << objName << "->addItem( " << child << ", "			<< row << ", " << col << " );" << endl;	    } else if ( tags.contains( n.tagName() ) ) {		QString child = createObjectImpl( n, parentClass, parent, objName );		out << endl;		QString o = "Widget";		if ( isLayout( child ) )		    o = "Layout";		if ( rowspan * colspan != 1 )		    out << indent << objName << "->addMultiCell" << o << "( " << child << ", "			<< row << ", " << row + rowspan - 1 << ", " << col << ", " << col  + colspan - 1 << " );" << endl;		else		    out << indent << objName << "->add" << o << "( " << child << ", "			<< row << ", " << col << " );" << endl;	    }	}    }    return objName;}QString Uic::createSpacerImpl( const QDomElement &e, const QString& /*parentClass*/, const QString& /*parent*/, const QString& /*layout*/){    QDomElement n;    QString objClass, objName;    objClass = e.tagName();    objName = registerObject( "spacer" );    QSize size = DomTool::readProperty( e, "sizeHint", QSize( 0, 0 ) ).toSize();    QString sizeType = DomTool::readProperty( e, "sizeType", "Expanding" ).toString();    bool isVspacer = DomTool::readProperty( e, "orientation", "Horizontal" ) == "Vertical";    if ( sizeType != "Expanding" && sizeType != "MinimumExpanding" &&	 DomTool::hasProperty( e, "geometry" ) ) { // compatibility Qt 2.2	QRect geom = DomTool::readProperty( e, "geometry", QRect(0,0,0,0) ).toRect();	size = geom.size();    }    if ( isVspacer )	out << "    QSpacerItem* " << objName << " = new QSpacerItem( "	    << size.width() << ", " << size.height()	    << ", QSizePolicy::Minimum, QSizePolicy::" << sizeType << " );" << endl;    else	out << "    QSpacerItem* " << objName << " = new QSpacerItem( "	    << size.width() << ", " << size.height()	    << ", QSizePolicy::" << sizeType << ", QSizePolicy::Minimum );" << endl;    return objName;}/*!  Creates a set-call for property \a exclusiveProp of the object  given in \a e.  If the object does not have this property, the function does nothing.  Exclusive properties are used to generate the implementation of  application font or palette change handlers in createFormImpl(). */void Uic::createExclusiveProperty( const QDomElement & e, const QString& exclusiveProp ){    QDomElement n;    QString objClass = getClassName( e );    if ( objClass.isEmpty() )	return;    QString objName = getObjectName( e );    if ( objClass.isEmpty() )	return;    for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {	if ( n.tagName() == "property" ) {	    bool stdset = toBool( n.attribute( "stdset" ) );	    QDomElement n2 = n.firstChild().toElement();	    if ( n2.tagName() == "name" ) {		QString prop = n2.firstChild().toText().data();		if ( prop != exclusiveProp )		    continue;		QString value = setObjectProperty( objClass, objName, prop, n2.nextSibling().toElement(), stdset );		if ( value.isEmpty() )		    continue;		out << indent << objName << "->setProperty( \"" << prop << "\", " << value << " );" << endl;	    }	}    }}const char* const ColorRole[] = {    "Foreground", "Button", "Light", "Midlight", "Dark", "Mid",    "Text", "BrightText", "ButtonText", "Base", "Background", "Shadow",    "Highlight", "HighlightedText", 0};/*!  Attention: this function has to be in sync with Resource::setWidgetProperty(). If you change one, change both. */QString Uic::setObjectProperty( const QString& objClass, const QString& obj, const QString &prop, const QDomElement &e, bool stdset ){    QString v;    if ( e.tagName() == "rect" ) {	QDomElement n3 = e.firstChild().toElement();	int x = 0, y = 0, w = 0, h = 0;	while ( !n3.isNull() ) {	    if ( n3.tagName() == "x" )		x = n3.firstChild().toText().data().toInt();	    else if ( n3.tagName() == "y" )		y = n3.firstChild().toText().data().toInt();	    else if ( n3.tagName() == "width" )		w = n3.firstChild().toText().data().toInt();	    else if ( n3.tagName() == "height" )		h = n3.firstChild().toText().data().toInt();	    n3 = n3.nextSibling().toElement();	}	v = "QRect( %1, %2, %3, %4 )";	v = v.arg(x).arg(y).arg(w).arg(h);    } else if ( e.tagName() == "point" ) {	QDomElement n3 = e.firstChild().toElement();	int x = 0, y = 0;	while ( !n3.isNull() ) {	    if ( n3.tagName() == "x" )		x = n3.firstChild().toText().data().toInt();	    else if ( n3.tagName() == "y" )		y = n3.firstChild().toText().data().toInt();	    n3 = n3.nextSibling().toElement();	}	v = "QPoint( %1, %2 )";	v = v.arg(x).arg(y);    } else if ( e.tagName() == "size" ) {	QDomElement n3 = e.firstChild().toElement();	int w = 0, h = 0;	while ( !n3.isNull() ) {	    if ( n3.tagName() == "width" )		w = n3.firstChild().toText().data().toInt();	    else if ( n3.tagName() == "height" )		h = n3.firstChild().toText().data().toInt();	    n3 = n3.nextSibling().toElement();	}	v = "QSize( %1, %2 )";	v = v.arg(w).arg(h);    } else if ( e.tagName() == "color" ) {	QDomElement n3 = e.firstChild().toElement();	int r= 0, g = 0, b = 0;	while ( !n3.isNull() ) {	    if ( n3.tagName() == "red" )		r = n3.firstChild().toText().data().toInt();	    else if ( n3.tagName() == "green" )		g = n3.firstChild().toText().data().toInt();	    else if ( n3.tagName() == "blue" )		b = n3.firstChild().toText().data().toInt();	    n3 = n3.nextSibling().toElement();	}	v = "QColor( %1, %2, %3 )";	v = v.arg(r).arg(g).arg(b);    } else if ( e.tagName() == "font" ) {	QDomElement n3 = e.firstChild().toElement();	QString fontname = "f";	if ( !obj.isEmpty() ) {	    fontname = obj + "_font";	    out << indent << "QFont "  << fontname << "(  " << obj << "->font() );" << endl;	} else {	    out << indent << "QFont "  << fontname << "( font() );" << endl;	}	while ( !n3.isNull() ) {	    if ( n3.tagName() == "family" )		out << indent << fontname << ".setFamily( \"" << n3.firstChild().toText().data() << "\" );" << endl;	    else if ( n3.tagName() == "pointsize" )		out << indent << fontname << ".setPointSize( " << n3.firstChild().toText().data() << " );" << endl;	    else if ( n3.tagName() == "bold" )		out << indent << fontname << ".setBold( " << mkBool( n3.firstChild().toText().data() ) << " );" << endl;	    else if ( n3.tagName() == "italic" )		out << indent << fontname << ".setItalic( " << mkBool( n3.firstChild().toText().data() ) << " );" << endl;	    else if ( n3.tagName() == "underline" )		out << indent << fontname << ".setUnderline( " << mkBool( n3.firstChild().toText().data() ) << " );" << endl;	    else if ( n3.tagName() == "strikeout" )		out << indent << fontname << ".setStrikeOut( " << mkBool( n3.firstChild().toText().data() ) << " );" << endl;	    n3 = n3.nextSibling().toElement();	}	if ( prop == "font" ) {	    if ( !obj.isEmpty() )		out << indent << obj << "->setFont( " << fontname << " ); " << endl;	    else		out << indent << "setFont( " << fontname << " ); " << endl;	} else {	    v = fontname;	}    } else if ( e.tagName() == "string" ) {	if ( prop == "toolTip" ) {	    if ( !obj.isEmpty() )		out << indent << "QToolTip::add(  " << obj << ", " + trcall( e.firstChild().toText().data(), getComment(e.parentNode()) ) << " );" << endl;	    else		out << indent << "QToolTip::add(  this, " + trcall( e.firstChild().toText().data(), getComment(e.parentNode()) ) << " );" << endl;	} else if ( prop == "whatsThis" ) {	    if ( !obj.isEmpty() )		out << indent << "QWhatsThis::add(  " << obj << ", " << trcall( e.firstChild().toText().data(), getComment(e.parentNode()) ) << " );" << endl;	    else		out << indent << "QWhatsThis::add(  this, " << trcall( e.firstChild().toText().data(), getComment(e.parentNode()) ) << " );" << endl;	} else {	    v = trcall(e.firstChild().toText().data(), getComment(e.parentNode()));	}    } else if ( e.tagName() == "cstring" ) {	    v = "\"%1\"";	    v = v.arg( e.firstChild().toText().data() );    } else if ( e.tagName() == "number" ) {	v = "%1";	v = v.arg( e.firstChild().toText().data() );    } else if ( e.tagName() == "bool" ) {	if ( stdset )	    v = "%1";	else	    v = "QVariant( %1, 0 )";	v = v.arg( mkBool( e.firstChild().toText().data() ) );    } else if ( e.tagName() == "pixmap" ) {	v = e.firstChild().toText().data();	if ( !pixmapLoaderFunction.isEmpty() ) {	    v.prepend( pixmapLoaderFunction + "( " );	    v.append( " )" );	}    } else if ( e.tagName() == "iconset" ) {	v = "QIconSet( %1 )";	v = v.arg( e.firstChild().toText().data() );    } else if ( e.tagName() == "image" ) {	v = e.firstChild().toText().data() + ".convertToImage()";    } else if ( e.tagName() == "enum" ) {	if ( stdset )	    v = "%1::%2";	else	    v = "(int)%1::%2";	QString oc = objClass;	QString ev = e.firstChild().toText().data();	if ( oc == "QListView" && ev == "Manual" ) // #### workaround, rename QListView::Manual of WithMode enum in 3.0	    oc = "QScrollView";	v = v.arg( oc ).arg( ev );    } else if ( e.tagName() == "set" ) {	QString keys( e.firstChild().toText().data() );	QStringList lst = QStringList::split( '|', keys );	v = "int( ";	for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) {	    v += objClass + "::" + *it;	    if ( it != lst.fromLast() )		v += " | ";	}	v += " )";    } else if ( e.tagName() == "sizepolicy" ) {	QDomElement n3 = e.firstChild().toElement();	QSizePolicy sp;	while ( !n3.isNull() ) {	    if ( n3.tagName() == "hsizetype" )		sp.setHorData( (QSizePolicy::SizeType)n3.firstChild().toText().data().toInt() );	    else if ( n3.tagName() == "vsizetype" )		sp.setVerData( (QSizePolicy::SizeType)n3.firstChild().toText().data().toInt() );	    n3 = n3.nextSibling().toElement();	}	QString tmp;	if ( !obj.isEmpty() )	    tmp = obj + "->";	v = "QSizePolicy( (QSizePolicy::SizeType)%1, (QSizePolicy::SizeType)%2, " +tmp + "sizePolicy().hasHeightForWidth() )";	v = v.arg( (int)sp.horData() ).arg( (int)sp.verData() );    } else if ( e.tagName() == "palette" ) {	QPalette pal;	bool no_pixmaps = e.elementsByTagName( "pixmap" ).count() == 0;	QDomElement n;	if ( no_pixmaps ) {	    n = e.firstChild().toElement();	    while ( !n.isNull() ) {		QColorGroup cg;		if ( n.tagName() == "active" ) {		    cg = loadColorGroup( n );		    pal.setActive( cg );		} else if ( n.tagName() == "inactive" ) {		    cg = loadColorGroup( n );		    pal.setInactive( cg );		} else if ( n.tagName() == "disabled" ) {		    cg = loadColorGroup( n );		    pal.setDisabled( cg );		}

⌨️ 快捷键说明

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