uic.cpp
来自「Qt/Embedded是一个多平台的C++图形用户界面应用程序框架」· C++ 代码 · 共 1,993 行 · 第 1/5 页
CPP
1,993 行
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" ); QRect geom = DomTool::readProperty( e, "geometry", QRect(0,0,0,0) ).toRect(); QString sizeType = DomTool::readProperty( e, "sizeType", "Expanding" ).toString(); bool isVspacer = DomTool::readProperty( e, "orientation", "Horizontal" ) == "Vertical"; if ( isVspacer ) out << " QSpacerItem* " << objName << " = new QSpacerItem( " << geom.width() << ", " << geom.height() << ", QSizePolicy::Fixed, QSizePolicy::" << sizeType << " );" << endl; else out << " QSpacerItem* " << objName << " = new QSpacerItem( " << geom.width() << ", " << geom.height() << ", QSizePolicy::" << sizeType << ", QSizePolicy::Fixed );" << 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 << ", " + trmacro + "( \"" << fixString( e.firstChild().toText().data() ) << "\" ) );" << endl; else out << indent << "QToolTip::add( this, " + trmacro + "( \"" << fixString( e.firstChild().toText().data() ) << "\" ) );" << endl; } else if ( prop == "whatsThis" ) { if ( !obj.isEmpty() ) out << indent << "QWhatsThis::add( " << obj << ", " << trmacro << "( \"" << fixString( e.firstChild().toText().data() ) << "\" ) );" << endl; else out << indent << "QWhatsThis::add( this, " << trmacro << "( \"" << fixString( e.firstChild().toText().data() ) << "\" ) );" << endl; } else { v = trmacro + "( \"%1\" )"; v = v.arg( fixString( e.firstChild().toText().data() ) ); } } 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"; v = v.arg( objClass ).arg( e.firstChild().toText().data() ); } 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(); } v = "QSizePolicy( (QSizePolicy::SizeType)%1, (QSizePolicy::SizeType)%2 )"; 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 ); } n = n.nextSibling().toElement(); } } if ( no_pixmaps && pal == QPalette( pal.active().button(), pal.active().background() ) ) { v = "QPalette( QColor( %1, %2, %3 ), QColor( %1, %2, %3 ) )"; v = v.arg( pal.active().button().red() ).arg( pal.active().button().green() ).arg( pal.active().button().blue() ); v = v.arg( pal.active().background().red() ).arg( pal.active().background().green() ).arg( pal.active().background().blue() ); } else { QString palette = "pal"; if ( !pal_used ) { out << indent << "QPalette " << palette << ";" << endl; pal_used = TRUE; } QString cg = "cg"; if ( !cg_used ) { out << indent << "QColorGroup " << cg << ";" << endl; cg_used = TRUE; } n = e.firstChild().toElement(); while ( !n.isNull() && n.tagName() != "active") n = n.nextSibling().toElement(); createColorGroupImpl( cg, n ); out << indent << palette << ".setActive( " << cg << " );" << endl; n = e.firstChild().toElement(); while ( !n.isNull() && n.tagName() != "inactive") n = n.nextSibling().toElement(); createColorGroupImpl( cg, n ); out << indent << palette << ".setInactive( " << cg << " );" << endl; n = e.firstChild().toElement(); while ( !n.isNull() && n.tagName() != "disabled") n = n.nextSibling().toElement(); createColorGroupImpl( cg, n ); out << indent << palette << ".setDisabled( " << cg << " );" << endl; v = palette; } } else if ( e.tagName() == "cursor" ) { v = "QCursor( %1 )"; v = v.arg( e.firstChild().toText().data() ); } return v;}/*! Creates a colorgroup with name \a name from the color group \a cg */void Uic::createColorGroupImpl( const QString& name, const QDomElement& e ){ QColorGroup cg; int r = -1; QDomElement n = e.firstChild().toElement(); QString color; while ( !n.isNull() ) { if ( n.tagName() == "color" ) { r++; QColor col = DomTool::readColor( n ); color = "QColor( %1, %2, %3)"; color = color.arg( col.red() ).arg( col.green() ).arg( col.blue() ); if ( col == white ) color = "white"; else if ( col == black ) color = "black"; if ( n.nextSibling().toElement().tagName() != "pixmap" ) { out << indent << name << ".setColor( QColorGroup::" << ColorRole[r] << ", " << color << " );" << endl; } } else if ( n.tagName() == "pixmap" ) { QString pixmap = n.firstChild().toText().data(); if ( !pixmapLoaderFunction.isEmpty() ) { pixmap.prepend( pixmapLoaderFunction + "( " ); pixmap.append( " )" ); } out << indent << name << ".setBrush( QColorGroup::" << ColorRole[r] << ", QBrush( " << color << ", " << pixmap << " ) );" << endl; } n = n.nextSibling().toElement(); }}/*! Auxiliary function to load a color group. The colorgroup must not contain pixmaps. */QColorGroup Uic::loadColorGroup( const QDomElement &e ){ QColorGroup cg; int r = -1; QDomElement n = e.firstChild().toElement(); QColor col; while ( !n.isNull() ) { if ( n.tagName() == "color" ) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?