📄 dlg2ui.cpp
字号:
/************************************************************************** Converts a Qt Architect 2.1+ .dlg file into a .ui file.**** Copyright (C) 2000-2001 Trolltech AS. All rights reserved.**** This file is part of Qt Designer.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "dlg2ui.h"#include <qfile.h>#include <qframe.h>#include <qmessagebox.h>#include <qregexp.h>#include <qtextstream.h>/* Possible improvements: 1. Convert layout stretch factors to size policy stretches, now that Qt Designer supports the latter.*//* These big tables could be more or less eliminated by using Qt's QMetaObject and QMetaProperty classes. However, the interface of these classes is unwieldy for an otherwise non-GUI program like this one, as we would have to create one dummy object for most QObject subclasses in Qt. Let's take the safe road.*/static const char *widgetTypes[] = { "Button", "ButtonGroup", "CheckBox", "ComboBox", "Dial", "DlgWidget", "Frame", "Grid", "GroupBox", "HBox", "HButtonGroup", "HGroupBox", "IconView", "LCDNumber", "Label", "LineEdit", "ListBox", "ListView", "MenuBar", "MultiLineEdit", "ProgressBar", "PushButton", "RadioButton", "ScrollBar", "ScrollView", "Slider", "SpinBox", "Splitter", "TabBar", "TextBrowser", "TextView", "User", "VBox", "VButtonGroup", "VGroupBox", 0};/* This table maps Qt Architect properties to Qt Designer properties. If there is no corresponding Qt Designer property, qtName is 0 and the property can be handled explicitly.*/static const struct { const char *widgetName; const char *architectName; const char *qtName; const char *type;} propertyDefs[] = { { "Button", "AutoRepeat", "autoRepeat", "boolean" }, { "Button", "AutoResize", 0, 0 }, { "Button", "Text", "text", "qstring" }, { "ButtonGroup", "Exclusive", "exclusive", "boolean" }, { "ButtonGroup", "RadioButtonExclusive", "radioButtonExclusive", "boolean" }, { "CheckBox", "Checked", "checked", "boolean" }, { "ComboBox", "AutoCompletion", "autoCompletion", "boolean" }, { "ComboBox", "AutoResize", 0, 0 }, { "ComboBox", "DuplicatesEnabled", "duplicatesEnabled", "boolean" }, { "ComboBox", "MaxCount", "maxCount", "integer" }, { "ComboBox", "Policy", "insertionPolicy", "enum" }, { "ComboBox", "SizeLimit", "sizeLimit", "integer" }, { "ComboBox", "Style", 0, 0 }, { "Dial", "Initial", "value", "integer" }, { "Dial", "LineStep", "lineStep", "integer" }, { "Dial", "MaxValue", "maxValue", "integer" }, { "Dial", "MinValue", "minValue", "integer" }, { "Dial", "NotchTarget", "notchTarget", "double" }, { "Dial", "PageStep", "pageStep", "integer" }, { "Dial", "ShowNotches", "notchesVisible", "boolean" }, { "Dial", "Tracking", "tracking", "boolean" }, { "Dial", "Wrapping", "wrapping", "boolean" }, { "DlgWidget", "AdjustSize", 0, 0 }, { "DlgWidget", "BackgroundMode", "backgroundMode", "enum" }, { "DlgWidget", "BackgroundOrigin", "backgroundOrigin", "enum" }, { "DlgWidget", "BackgroundPixmap", "backgroundPixmap", "qpixmap" }, { "DlgWidget", "DataLenName", 0, 0 }, { "DlgWidget", "DataVarName", 0, 0 }, { "DlgWidget", "Enabled", "enabled", "boolean" }, { "DlgWidget", "FocusPolicy", "focusPolicy", "enum" }, { "DlgWidget", "Font", "font", "qfont" }, { "DlgWidget", "FontPropagation", 0, 0 }, { "DlgWidget", "MaximumSize", "maximumSize", "qsize" }, { "DlgWidget", "MinimumSize", "minimumSize", "qsize" }, { "DlgWidget", "Name", 0, 0 }, { "DlgWidget", "Palette", "palette", "qpalette" }, { "DlgWidget", "PalettePropagation", 0, 0 }, { "DlgWidget", "ReadPixmapFromData", 0, 0 }, { "DlgWidget", "Rect", 0, 0 }, { "DlgWidget", "SignalConnection", 0, 0 }, { "DlgWidget", "UseBackgroudPixmap", 0, 0 }, { "DlgWidget", "Variable", 0, 0 }, { "Frame", "FrameMargin", "margin", "integer" }, { "Frame", "LineWidth", "lineWidth", "integer" }, { "Frame", "MidLineWidth", "midLineWidth", "integer" }, { "Frame", "Style", 0, 0 }, { "GroupBox", "Title", "title", "qstring" }, { "IconView", "AlignMode", 0, 0 }, { "IconView", "Aligning", 0, 0 }, { "IconView", "Arrangement", "arrangement", "enum" }, { "IconView", "AutoArrange", "autoArrange", "boolean" }, { "IconView", "EnableMoveItems", "itemsMovable", "boolean" }, { "IconView", "GridX", "gridX", "integer" }, { "IconView", "GridY", "gridY", "integer" }, { "IconView", "ItemTextPos", "itemTextPos", "enum" }, { "IconView", "ItemsMovable", "itemsMovable", "boolean" }, { "IconView", "MaxItemTextLength", "maxItemTextLength", "integer" }, { "IconView", "MaxItemWidth", "maxItemWidth", "integer" }, { "IconView", "ResizeMode", "resizeMode", "enum" }, { "IconView", "SelectionMode", "selectionMode", "enum" }, { "IconView", "ShowToolTips", "showToolTips", "boolean" }, { "IconView", "SortAscending", "sortDirection", "bool" }, { "IconView", "Spacing", "spacing", "integer" }, { "IconView", "WordWrapIconText", "wordWrapIconText", "boolean" }, { "LCDNumber", "Digits", "numDigits", "integer" }, { "LCDNumber", "Mode", "mode", "enum" }, { "LCDNumber", "SegmentStyle", "segmentStyle", "enum" }, { "LCDNumber", "SmallDecimalPoint", "smallDecimalPoint", "boolean" }, { "LCDNumber", "Value", 0, 0 }, { "Label", "AutoResize", 0, 0 }, { "Label", "Indent", "indent", "integer" }, { "Label", "Text", "text", "qstring" }, { "Label", "TextFormat", "textFormat", "enum" }, { "LineEdit", "EchoMode", "echoMode", "enum" }, { "LineEdit", "FrameShown", "frame", "boolean" }, { "LineEdit", "MaxLength", "maxLength", "integer" }, { "LineEdit", "Text", "text", "qstring" }, { "ListBox", "AutoScroll", 0, 0 }, { "ListBox", "AutoUpdate", 0, 0 }, { "ListBox", "ColumnMode", "columnMode", "enum" }, { "ListBox", "DragSelect", 0, 0 }, { "ListBox", "RowMode", "rowMode", "enum" }, { "ListBox", "SelectionMode", "selectionMode", "enum" }, { "ListBox", "SmoothScrolling", 0, 0 }, { "ListView", "AllColumnsShowFocus", "allColumnsShowFocus", "boolean" }, { "ListView", "HeaderInformation", 0, 0 }, { "ListView", "ItemMargin", "itemMargin", "integer" }, { "ListView", "MultiSelection", "multiSelection", "boolean" }, { "ListView", "RootIsDecorated", "rootIsDecorated", "boolean" }, { "ListView", "TreeStepSize", "treeStepSize", "boolean" }, { "MultiLineEdit", "AutoUpdate", 0, 0 }, { "MultiLineEdit", "EchoMode", 0, 0 }, { "MultiLineEdit", "HorizontalMargin", 0, 0 }, { "MultiLineEdit", "MaxLength", 0, 0 }, { "MultiLineEdit", "MaxLineLength", 0, 0 }, { "MultiLineEdit", "MaxLines", 0, 0 }, { "MultiLineEdit", "OverwriteMode", 0, 0 }, { "MultiLineEdit", "ReadOnly", 0, 0 }, { "MultiLineEdit", "Text", 0, 0 }, { "MultiLineEdit", "UndoDepth", "undoDepth", "integer" }, { "MultiLineEdit", "UndoEnabled", 0, 0 }, { "MultiLineEdit", "WordWrap", 0, 0 }, { "MultiLineEdit", "WrapColumnOrWidth", 0, 0 }, { "MultiLineEdit", "WrapPolicy", 0, 0 }, { "ProgressBar", "CenterIndicator", "centerIndicator", "boolean" }, { "ProgressBar", "IndicatorFollowsStyle", "indicatorFollowsStyle", "boolean" }, { "ProgressBar", "Progress", "progress", "integer" }, { "ProgressBar", "TotalSteps", "totalSteps", "integer" }, { "PushButton", "AutoDefault", "autoDefault", "boolean" }, { "PushButton", "Default", "default", "boolean" }, { "PushButton", "IsMenuButton", 0, 0 }, { "PushButton", "ToggleButton", "toggleButton", "boolean" }, { "RadioButton", "Checked", "checked", "boolean" }, { "ScrollBar", "Initial", "value", "integer" }, { "ScrollBar", "LineStep", "lineStep", "integer" }, { "ScrollBar", "MaxValue", "maxValue", "integer" }, { "ScrollBar", "MinValue", "minValue", "integer" }, { "ScrollBar", "Orientation", "orientation", "enum" }, { "ScrollBar", "PageStep", "pageStep", "integer" }, { "ScrollBar", "Tracking", "tracking", "boolean" }, { "ScrollView", "DragAutoScroll", "dragAutoScroll", "boolean" }, { "ScrollView", "HScrollBarMode", "hScrollBarMode", "enum" }, { "ScrollView", "ResizePolicy", "resizePolicy", "enum" }, { "ScrollView", "VScrollBarMode", "vScrollBarMode", "enum" }, { "Slider", "Initial", "value", "integer" }, { "Slider", "LineStep", "lineStep", "integer" }, { "Slider", "MaxValue", "maxValue", "integer" }, { "Slider", "MinValue", "minValue", "integer" }, { "Slider", "Orientation", "orientation", "enum" }, { "Slider", "PageStep", "pageStep", "integer" }, { "Slider", "TickInterval", "tickInterval", "integer" }, { "Slider", "Tickmarks", "tickmarks", "enum" }, { "Slider", "Tracking", "tracking", "boolean" }, { "SpinBox", "ButtonSymbols", "buttonSymbols", "enum" }, { "SpinBox", "MaxValue", "maxValue", "integer" }, { "SpinBox", "MinValue", "minValue", "integer" }, { "SpinBox", "Prefix", "prefix", "qstring" }, { "SpinBox", "SpecialValue", "specialValueText", "qstring" }, { "SpinBox", "Step", "lineStep", "integer" }, { "SpinBox", "Suffix", "suffix", "qstring" }, { "SpinBox", "Wrapping", "wrapping", "boolean" }, { "Splitter", "OpaqueResize", 0, 0 }, { "Splitter", "Orientation", "orientation", "enum" }, { "TabBar", "Shape", "shape", "enum" }, { "TabBar", "TabNames", 0, 0 }, { "TextView", "Context", 0, 0 }, { "TextView", "LinkUnderline", "linkUnderline", "boolean" }, { "TextView", "Text", "text", "qstring" }, { "TextView", "TextFormat", "textFormat", "enum" }, { "User", "UserClassHeader", 0, 0 }, { "User", "UserClassName", 0, 0 }, { 0, 0, 0, 0 }};/* This is the number of supported color groups in a palette, and supported color roles in a color group. Changing these constants is dangerous.*/static const int NumColorRoles = 14;static bool isTrue( const QString& val ){ return val.lower() == QString( "true" );}static AttributeMap attribute( const QString& name, const QString& val ){ AttributeMap attr; attr.insert( name, val ); return attr;}static QString entitize( const QString& str ){ QString t = str; t.replace( '&', QString("&") ); t.replace( '>', QString(">") ); t.replace( '<', QString("<") ); t.replace( '"', QString(""") ); t.replace( '\'', QString("'") ); return t;}QString Dlg2Ui::alias( const QString& name ) const{ if ( yyAliasMap.contains(name) ) return yyAliasMap[name]; else return name;}QString Dlg2Ui::opening( const QString& tag, const AttributeMap& attr ){ QString t = QChar( '<' ) + tag; AttributeMap::ConstIterator a = attr.begin(); while ( a != attr.end() ) { t += QChar( ' ' ) + a.key() + QString( "=\"" ) + entitize( *a ) + QChar( '"' ); ++a; } t += QChar( '>' ); return t;}QString Dlg2Ui::closing( const QString& tag ){ return opening( QChar('/') + tag );}void Dlg2Ui::error( const QString& message ){ if ( numErrors++ == 0 ) QMessageBox::warning( 0, yyFileName, message );}void Dlg2Ui::syntaxError(){ error( QString("Sorry, I met a random syntax error. I did what I could, but" " that was not enough." "<p>You might want to write to" " <tt>qt-bugs@trolltech.com</tt> about this incident.") );}QString Dlg2Ui::getTextValue( const QDomNode& node ){ if ( node.childNodes().count() > 1 ) { syntaxError(); return QString::null; } if ( node.childNodes().count() == 0 ) return QString::null; QDomText child = node.firstChild().toText(); if ( child.isNull() ) { syntaxError(); return QString::null; } QString t = child.data().stripWhiteSpace(); t.replace( "\\\\", "\\" ); t.replace( "\\n", "\n" ); return t;}QVariant Dlg2Ui::getValue( const QDomNodeList& children, const QString& tagName, const QString& type ){ for ( int i = 0; i < (int) children.count(); i++ ) { QDomNode n = children.item( i ); if ( n.toElement().tagName() == tagName ) return getValue( n.toElement(), tagName, type ); } return QVariant();}void Dlg2Ui::emitHeader(){ yyOut += QString( "<!DOCTYPE UI><UI version=\"3.0\" stdsetdef=\"1\">\n" );}void Dlg2Ui::emitFooter(){ yyOut += QString( "</UI>\n" );}void Dlg2Ui::emitSimpleValue( const QString& tag, const QString& value, const AttributeMap& attr ){ yyOut += yyIndentStr + opening( tag, attr ) + entitize( value ) + closing( tag ) + QChar( '\n' );}void Dlg2Ui::emitOpening( const QString& tag, const AttributeMap& attr ){ yyOut += yyIndentStr + opening( tag, attr ) + QChar( '\n' ); yyIndentStr += QString( " " );}void Dlg2Ui::emitClosing( const QString& tag ){ yyIndentStr.truncate( yyIndentStr.length() - 4 ); yyOut += yyIndentStr + closing( tag ) + QChar( '\n' );}void Dlg2Ui::emitOpeningWidget( const QString& className ){ AttributeMap attr = attribute( QString("class"), className ); if ( yyGridColumn >= 0 ) { attr.insert( QString("row"), QString::number(yyGridRow) ); attr.insert( QString("column"), QString::number(yyGridColumn) ); yyGridColumn = -1; } emitOpening( QString("widget"), attr );}QString Dlg2Ui::widgetClassName( const QDomElement& e ){ if ( e.tagName() == QString("User") ) { return getValue( e.childNodes(), QString("UserClassName") ) .toString(); } else if ( e.tagName() == QString("DlgWidget") ) { return QString( "QWidget" ); } else { return QChar( 'Q' ) + e.tagName(); }}void Dlg2Ui::emitColor( const QColor& color ){ emitOpening( QString("color") ); emitSimpleValue( QString("red"), QString::number(color.red()) ); emitSimpleValue( QString("green"), QString::number(color.green()) ); emitSimpleValue( QString("blue"), QString::number(color.blue()) ); emitClosing( QString("color") );}void Dlg2Ui::emitColorGroup( const QString& name, const QColorGroup& group ){ emitOpening( name ); for ( int i = 0; i < NumColorRoles; i++ ) emitColor( group.color((QColorGroup::ColorRole) i) ); emitClosing( name );}void Dlg2Ui::emitVariant( const QVariant& val, const QString& stringType ){ if ( val.isValid() ) { switch ( val.type() ) { case QVariant::String: emitSimpleValue( stringType, val.toString() ); break; case QVariant::CString: emitSimpleValue( QString("cstring"), val.toString() ); break; case QVariant::Bool: emitSimpleValue( QString("bool"), QString(val.toBool() ? "true" : "false") );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -