📄 dlg2ui.cpp
字号:
QString type( propertyDefs[*p].type ); QVariant val = getValue( n.toElement(), tagName, type ); if ( type == QString("qstring") ) type = QString( "string" ); bool omit = FALSE; if ( propertyName == QString("backgroundOrigin") && val.toString() == QString("WidgetOrigin") ) omit = TRUE; if ( propertyName == QString("enabled") && val.toBool() ) omit = TRUE; if ( propertyName == QString("minimumSize") && val.toSize() == QSize(-1, -1) ) omit = TRUE; if ( propertyName == QString("maximumSize") && val.toSize() == QSize(32767, 32767) ) omit = TRUE; if ( !omit ) emitProperty( propertyName, val, type ); } } n = n.nextSibling(); } } if ( !variableName.isEmpty() ) { yyAliasMap.insert( name, variableName ); name = variableName; } if ( !name.isEmpty() ) emitProperty( QString("name"), name.latin1() ); if ( !userClassName.isEmpty() ) yyCustomWidgets.insert( userClassName, userClassHeader );}bool Dlg2Ui::checkTagName( const QDomElement& e, const QString& tagName ){ bool ok = ( e.tagName() == tagName ); if ( !ok ) syntaxError(); return ok;}QString Dlg2Ui::normalizeType( const QString& type ){ QString t = type; if ( t.isEmpty() || t == QString("enum") || t == QString( "qcstring" ) || t == QString("set") ) t = QString( "qstring" ); return t;}QVariant Dlg2Ui::getValue( const QDomElement& e, const QString& tagName, const QString& type ){ QVariant val; if ( e.tagName() != tagName ) return val; QString t = e.attributes().namedItem( "type" ).toAttr().value(); if ( normalizeType(t) != normalizeType(type) ) return val; if ( type == QString("integer") ) { return getTextValue( e ).toInt(); } else if ( type == QString("boolean") ) { return QVariant( isTrue(getTextValue(e)), 0 ); } else if ( type == QString("double") ) { return getTextValue( e ).toDouble(); } else if ( type == QString("qcstring") ) { return getTextValue( e ).latin1(); } else if ( type == QString("enum") || type == QString("qstring") || type == QString("set") ) { return getTextValue( e ); } else { QDomNodeList children = e.childNodes(); if ( type == QString("qsize") ) { int width = getValue( children, QString("Width"), QString("integer") ).toInt(); int height = getValue( children, QString("Height"), QString("integer") ).toInt(); return QSize( width, height ); } else if ( type == QString("qrect") ) { int x = getValue( children, QString("X"), QString("integer") ) .toInt(); int y = getValue( children, QString("Y"), QString("integer") ) .toInt(); int width = getValue( children, QString("Width"), QString("integer") ).toInt(); int height = getValue( children, QString("Height"), QString("integer") ).toInt(); return QRect( x, y, width, height ); } else if ( type == QString("qpoint") ) { int x = getValue( children, QString("X"), QString("integer") ) .toInt(); int y = getValue( children, QString("Y"), QString("integer") ) .toInt(); return QPoint( x, y ); } else if ( type == QString("qpalette") ) { QColorGroup active = getValue( children, QString("Active"), QString("qcolorgroup") ) .toColorGroup(); QColorGroup disabled = getValue( children, QString("Disabled"), QString("qcolorgroup") ) .toColorGroup(); QColorGroup inactive = getValue( children, QString("Inactive"), QString("qcolorgroup") ) .toColorGroup(); return QPalette( active, disabled, inactive ); } else if ( type == QString("qfont") ) { QString family = getValue( children, QString("Family"), QString("qstring") ).toString(); int pointSize = getValue( children, QString("PointSize"), QString("integer") ).toInt(); int weight = getValue( children, QString("weight"), QString("integer") ).toInt(); bool italic = getValue( children, QString("Italic"), QString("boolean") ).toBool(); bool underline = getValue( children, QString("Underline"), QString("boolean") ).toBool(); bool strikeOut = getValue( children, QString("StrikeOut"), QString("boolean") ).toBool(); int styleHint = getValue( children, QString("StyleHint"), QString("integer") ).toInt(); QFont f; if ( !family.isEmpty() ) f.setFamily( family ); if ( pointSize != 0 ) f.setPointSize( pointSize ); if ( weight != 0 ) f.setWeight( weight ); f.setItalic( italic ); f.setUnderline( underline ); f.setStrikeOut( strikeOut ); if ( styleHint != 0 ) f.setStyleHint( (QFont::StyleHint) styleHint ); return f; } else if ( type == QString("qcolor") ) { // if any component missing, zero is to be assumed int red = getValue( children, QString("Red"), QString("integer") ) .toInt(); int green = getValue( children, QString("Green"), QString("integer") ).toInt(); int blue = getValue( children, QString("Blue"), QString("integer") ) .toInt(); return QColor( red, green, blue ); } else if ( type == QString("qcolorgroup") ) { static const QColorGroup::ColorRole roles[NumColorRoles] = { QColorGroup::Foreground, QColorGroup::Button, QColorGroup::Light, QColorGroup::Midlight, QColorGroup::Dark, QColorGroup::Mid, QColorGroup::Text, QColorGroup::BrightText, QColorGroup::ButtonText, QColorGroup::Base, QColorGroup::Background, QColorGroup::Shadow, QColorGroup::Highlight, QColorGroup::HighlightedText }; static const char * const roleNames[NumColorRoles] = { "Foreground", "Button", "Light", "MidLight", "Dark", "Mid", "Text", "BrightText", "ButtonText", "Base", "Background", "Shadow", "HighLighted", "HighLightedText" }; QColorGroup group; for ( int i = 0; i < NumColorRoles; i++ ) group.setColor( roles[i], getValue(children, QString(roleNames[i]), QString("qcolor")).toColor() ); return group; } else { syntaxError(); } } return val;}void Dlg2Ui::matchDialogCommon( const QDomElement& dialogCommon ){ if ( !checkTagName(dialogCommon, QString("DialogCommon")) ) return; QString sourceDir; QString classHeader; QString classSource; QString dataHeader; QString dataSource; QString dataName; QString windowBaseClass( "QDialog" ); bool isCustom = FALSE; QString customBaseHeader; QString windowCaption; yyClassName = "Form1"; QDomNode n = dialogCommon.firstChild(); while ( !n.isNull() ) { QString tagName = n.toElement().tagName(); QString val = getTextValue( n ); if ( tagName == QString("SourceDir") ) { sourceDir = val; } else if ( tagName == QString("ClassHeader") ) { classHeader = val; } else if ( tagName == QString("ClassSource") ) { classSource = val; } else if ( tagName == QString("ClassName") ) { yyClassName = val; } else if ( tagName == QString("DataHeader") ) { dataHeader = val; } else if ( tagName == QString("DataSource") ) { dataSource = val; } else if ( tagName == QString("DataName") ) { dataName = val; } else if ( tagName == QString("WindowBaseClass") ) { if ( val == QString("Custom") ) isCustom = TRUE; else windowBaseClass = val; } else if ( tagName == QString("IsModal") ) { } else if ( tagName == QString("CustomBase") ) { windowBaseClass = val; } else if ( tagName == QString("CustomBaseHeader") ) { customBaseHeader = val; } else if ( tagName == QString("WindowCaption") ) { windowCaption = val; } n = n.nextSibling(); } emitSimpleValue( QString("class"), yyClassName ); emitOpeningWidget( windowBaseClass ); if ( windowCaption.isEmpty() ) windowCaption = yyClassName; emitProperty( QString("name"), yyClassName.latin1() ); emitProperty( QString("caption"), windowCaption ); if ( isCustom ) yyCustomWidgets.insert( windowBaseClass, customBaseHeader );}bool Dlg2Ui::needsQLayoutWidget( const QDomElement& e ){ QRegExp widgetExists( QString("WidgetLayout|Layout_Widget") ); // we should also check that the widget is not a QHBox, QVBox, or QGrid QString grandpa = e.parentNode().parentNode().toElement().tagName(); return !widgetExists.exactMatch( grandpa );}void Dlg2Ui::matchBoxLayout( const QDomElement& boxLayout ){ QString directionStr; QString prevBoxKind = yyBoxKind; int border = 5; int autoBorder = 5; QString name; bool needsWidget = needsQLayoutWidget( boxLayout ); bool opened = FALSE; QDomNode n = boxLayout.firstChild(); while ( !n.isNull() ) { QString tagName = n.toElement().tagName(); if ( tagName == QString("Children") ) { if ( !opened ) { emitOpeningLayout( needsWidget, yyBoxKind, name, border, autoBorder ); if ( !directionStr.isEmpty() ) emitProperty( QString("direction"), directionStr, QString("enum") ); opened = TRUE; } matchLayout( n.toElement() ); } else { QString val = getTextValue( n ); if ( tagName == QString("Direction") ) { if ( val == QString("LeftToRight") ) { yyBoxKind = QString( "hbox" ); } else if ( val == QString("RightToLeft") ) { directionStr = val; yyBoxKind = QString( "hbox" ); } else if ( val == QString("TopToBottom") ) { yyBoxKind = QString( "vbox" ); } else if ( val == QString("BottomToTop") ) { directionStr = val; yyBoxKind = QString( "vbox" ); } else { syntaxError(); } } else if ( tagName == QString("Border") ) { border = val.toInt(); } else if ( tagName == QString("AutoBorder") ) { autoBorder = val.toInt(); } else if ( tagName == QString("Name") ) { name = val; } } n = n.nextSibling(); } if ( opened ) { emitClosingLayout( needsWidget, yyBoxKind ); yyBoxKind = prevBoxKind; }}void Dlg2Ui::matchBoxSpacing( const QDomElement& boxSpacing ){ int spacing = 7; QDomNode n = boxSpacing.firstChild(); while ( !n.isNull() ) { QString val = getTextValue( n ); if ( n.toElement().tagName() == QString("Spacing") ) spacing = val.toInt(); n = n.nextSibling(); } emitSpacer( spacing, 0 );}void Dlg2Ui::matchBoxStretch( const QDomElement& boxStretch ){ int stretch = 1; QDomNode n = boxStretch.firstChild(); while ( !n.isNull() ) { QString val = getTextValue( n ); if ( n.toElement().tagName() == QString("Stretch") ) stretch = val.toInt(); n = n.nextSibling(); } emitSpacer( 0, stretch );}void Dlg2Ui::matchGridLayout( const QDomElement& gridLayout ){ int oldGridRow = yyGridRow; int oldGridColumn = yyGridColumn; int border = 5; int autoBorder = 5; QString name; QString menu; bool needsWidget = needsQLayoutWidget( gridLayout ); bool opened = FALSE; QDomNode n = gridLayout.firstChild(); while ( !n.isNull() ) { QString tagName = n.toElement().tagName(); if ( tagName == QString("Children") ) { if ( !opened ) { emitOpeningLayout( needsWidget, QString("grid"), name, border, autoBorder ); yyGridRow = -1; yyGridColumn = -1; opened = TRUE; } matchLayout( n.toElement() ); } else { if ( tagName == QString("Border") ) { border = getTextValue( n ).toInt(); } else if ( tagName == QString("AutoBorder") ) { autoBorder = getTextValue( n ).toInt(); } else if ( tagName == QString("Name") ) { name = getTextValue( n ); } else if ( tagName == QString("Menu") ) { menu = getTextValue( n ); } } n = n.nextSibling(); } if ( opened ) emitClosingLayout( needsWidget, QString("grid") ); yyGridRow = oldGridRow; yyGridColumn = oldGridColumn;}void Dlg2Ui::matchGridRow( const QDomElement& gridRow ){ yyGridRow++; QDomNode n = gridRow.firstChild(); while ( !n.isNull() ) { QString tagName = n.toElement().tagName(); if ( tagName == QString("Children") ) { yyGridColumn = 0; matchLayout( n.toElement() ); } n = n.nextSibling(); }}void Dlg2Ui::matchGridSpacer( const QDomElement& gridSpacer ){ if ( !gridSpacer.firstChild().isNull() ) syntaxError();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -