⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlg2ui.cpp

📁 Linux下的基于X11的图形开发环境。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
}void Dlg2Ui::matchLayoutWidget( const QDomElement& layoutWidget ){    QDomElement children;    QString widget;    QDomNode n = layoutWidget.firstChild();    while ( !n.isNull() ) {	QString tagName = n.toElement().tagName();	if ( tagName == QString("Children") )	    children = n.toElement();	else if ( tagName == QString("Widget") )	    widget = getTextValue( n );	n = n.nextSibling();    }    if ( !widget.isEmpty() ) {	QMap<QString, QDomElement>::Iterator w = yyWidgetMap.find( widget );	if ( w == yyWidgetMap.end() ) {	    syntaxError();	} else {	    QString className = widgetClassName( *w );	    if ( className == QString("QHBox") ||		 className == QString("QVBox") ) {		bool needsWidget = needsQLayoutWidget( layoutWidget );		QString prevBoxKind = yyBoxKind;		yyBoxKind = className.mid( 1 ).lower();		int spacing = getValue( (*w).childNodes(), QString("Spacing"),					QString("integer") ).toInt();		if ( spacing < 1 )		    spacing = 5;		emitOpeningLayout( needsWidget, yyBoxKind, widget, 0, spacing );		if ( !children.isNull() )		    matchLayout( children );		emitClosingLayout( needsWidget, yyBoxKind );		yyBoxKind = prevBoxKind;	    } else if ( className == QString("QGrid") ) {		bool needsWidget = needsQLayoutWidget( layoutWidget );		int n = 0;		QString direction = getValue( (*w).childNodes(),					      QString("Direction") ).toString();		int rowsCols = getValue( (*w).childNodes(), QString("RowCols"),					 QString("integer") ).toInt();		if ( rowsCols == 0 )		    rowsCols = getValue( (*w).childNodes(),					 QString("RowsCols"),					 QString("integer") ).toInt();		if ( rowsCols < 1 )		    rowsCols = 5;		int spacing = getValue( (*w).childNodes(), QString("Spacing"),					QString("integer") ).toInt();		if ( spacing < 1 )		    spacing = 5;		emitOpeningLayout( needsWidget, QString("grid"), widget, 0,				   spacing );		QDomNode child = children.firstChild();		while ( !child.isNull() ) {		    if ( direction == QString("Vertical") ) {			yyGridColumn = n / rowsCols;			yyGridRow = n % rowsCols;		    } else {			yyGridColumn = n % rowsCols;			yyGridRow = n / rowsCols;		    }		    matchBox( child.toElement() );		    n++;		    child = child.nextSibling();		}		yyGridColumn = -1;		yyGridRow = -1;		emitClosingLayout( needsWidget, QString("grid") );	    } else {		emitOpeningWidget( widgetClassName(*w) );		emitWidgetBody( *w, TRUE );		if ( !children.isNull() )		    matchLayout( children );		emitClosing( QString("widget") );	    }	    yyWidgetMap.remove( w );	}    }}void Dlg2Ui::matchBox( const QDomElement& box ){    /*      What is this jump table doing in here?    */    static const struct {	const char *tagName;	void (Dlg2Ui::*matchFunc)( const QDomElement& );    } jumpTable[] = {	{ "Box_Layout", &Dlg2Ui::matchBoxLayout },	{ "Box_Spacing", &Dlg2Ui::matchBoxSpacing },	{ "Box_Stretch", &Dlg2Ui::matchBoxStretch },	{ "Grid_Layout", &Dlg2Ui::matchGridLayout },	{ "Grid_Row", &Dlg2Ui::matchGridRow },	{ "Grid_Spacer", &Dlg2Ui::matchGridSpacer },	{ "Layout_Widget", &Dlg2Ui::matchLayoutWidget },	{ 0, 0 }    };    int i = 0;    while ( jumpTable[i].tagName != 0 ) {	if ( QString(jumpTable[i].tagName) == box.tagName() ) {	    (this->*jumpTable[i].matchFunc)( box );	    break;	}	i++;    }    if ( jumpTable[i].tagName == 0 )	syntaxError();}void Dlg2Ui::matchLayout( const QDomElement& layout ){    int column = yyGridColumn;    QDomNode n = layout.firstChild();    while ( !n.isNull() ) {	if ( column != -1 )	    yyGridColumn = column++;	matchBox( n.toElement() );	n = n.nextSibling();    }}void Dlg2Ui::matchWidgetLayoutCommon( const QDomElement& widgetLayoutCommon ){    QDomNodeList children = widgetLayoutCommon.childNodes();    /*      Since we do not respect the spacing and margins specified in      the .dlg file, the specified geometry is slightly wrong (too      small). It still seems to be better to take it in.    */#if 1    QPoint initialPos = getValue( children, QString("InitialPos"),				  QString("qpoint") ).toPoint();    QSize size = getValue( children, QString("Size"), QString("qsize") )		 .toSize();#endif    QSize minSize = getValue( children, QString("MinSize"), QString("qsize") )		    .toSize();    QSize maxSize = getValue( children, QString("MaxSize"), QString("qsize") )		    .toSize();#if 1    if ( initialPos == QPoint(-1, -1) )	initialPos = QPoint( 0, 0 );    emitProperty( QString("geometry"), QRect(initialPos, size) );#endif    if ( minSize != QSize(-1, -1) )	emitProperty( QString("minimumSize"), minSize );    if ( maxSize != QSize(32767, 32767) )	emitProperty( QString("maximumSize"), maxSize );}void Dlg2Ui::matchWidget( const QDomElement& widget ){    QString name;    QDomNode n = widget;    while ( !n.isNull() ) {	if ( isWidgetType(n.toElement()) ) {	    n = n.firstChild();	} else {	    if ( n.toElement().tagName() == QString("Name") ) {		name = getTextValue( n );		break;	    }	    n = n.nextSibling();	}    }    if ( name.isEmpty() )	name = QString( "Widget%1" ).arg( uniqueWidget++ );    if ( yyWidgetMap.contains(name) )	syntaxError();    yyWidgetMap.insert( name, widget );}void Dlg2Ui::matchWidgets( const QDomElement& widgets ){    QDomNode n = widgets.firstChild();    while ( !n.isNull() ) {	matchWidget( n.toElement() );	n = n.nextSibling();    }}void Dlg2Ui::matchTabOrder( const QDomElement& tabOrder ){    QDomNode n = tabOrder.firstChild();    while ( !n.isNull() ) {	if ( n.toElement().tagName() == QString("Widget") )	    yyTabStops.append( getTextValue(n.toElement()) );	n = n.nextSibling();    }}void Dlg2Ui::matchWidgetLayout( const QDomElement& widgetLayout ){    if ( !checkTagName(widgetLayout, QString("WidgetLayout")) )	return;    QDomNode n = widgetLayout.firstChild();    while ( !n.isNull() ) {	QString tagName = n.toElement().tagName();	if ( tagName == QString("WidgetLayoutCommon") ) {	    matchWidgetLayoutCommon( n.toElement() );	} else if ( tagName == QString("Widgets") ) {	    matchWidgets( n.toElement() );	} else if ( tagName == QString("TabOrder") ) {	    matchTabOrder( n.toElement() );	} else if ( tagName == QString("Layout") ) {	    matchLayout( n.toElement() );	}	n = n.nextSibling();    }}void Dlg2Ui::matchDialog( const QDomElement& dialog ){    if ( !checkTagName(dialog, QString("Dialog")) )	return;    QDomNodeList nodes = dialog.childNodes();    if ( nodes.count() == 2 ) {	matchDialogCommon( nodes.item(0).toElement() );	matchWidgetLayout( nodes.item(1).toElement() );	flushWidgets();	emitClosing( QString("widget") );	if ( !yyCustomWidgets.isEmpty() ) {	    emitOpening( QString("customwidgets") );	    QMap<QString, QString>::Iterator w = yyCustomWidgets.begin();	    while ( w != yyCustomWidgets.end() ) {		emitOpening( QString("customwidget") );		emitSimpleValue( QString("class"), w.key() );		if ( !(*w).isEmpty() )		    emitSimpleValue( QString("header"), *w,				     attribute(QString("location"),					       QString("local")) );		emitClosing( QString("customwidget") );		++w;	    }	    emitClosing( QString("customwidgets") );	}	if ( yyConnections.count() + yySlots.count() > 0 ) {	    emitOpening( QString("connections") );	    QValueList<DlgConnection>::Iterator c = yyConnections.begin();	    while ( c != yyConnections.end() ) {		emitOpening( QString("connection") );		emitSimpleValue( QString("sender"), alias((*c).sender) );		emitSimpleValue( QString("signal"), (*c).signal );		emitSimpleValue( QString("receiver"), yyClassName );		emitSimpleValue( QString("slot"), (*c).slot );		emitClosing( QString("connection") );		++c;	    }	    QMap<QString, QString>::Iterator s = yySlots.begin();	    while ( s != yySlots.end() ) {		AttributeMap attr;		attr.insert( QString("access"), *s );		attr.insert( QString("language"), QString("C++") );		attr.insert( QString("returntype"), QString("void") );		emitSimpleValue( QString("slot"), s.key(), attr );		++s;	    }	    emitClosing( QString("connections") );	}	if ( !yyTabStops.isEmpty() ) {	    emitOpening( QString("tabstops") );	    QStringList::ConstIterator t = yyTabStops.begin();	    while ( t != yyTabStops.end() ) {		emitSimpleValue( QString("tabstop"), alias(*t) );		++t;	    }	    emitClosing( QString("tabstops") );	}    }}QStringList Dlg2Ui::convertQtArchitectDlgFile( const QString& fileName ){    int i;    yyFileName = fileName;    yyLayoutDepth = 0;    yyGridRow = -1;    yyGridColumn = -1;    numErrors = 0;    uniqueLayout = 1;    uniqueSpacer = 1;    uniqueWidget = 1;    i = 0;    while ( widgetTypes[i] != 0 ) {	yyWidgetTypeSet.insert( QString(widgetTypes[i]), 0 );	i++;    }    i = 0;    while ( propertyDefs[i].widgetName != 0 ) {	yyPropertyMap[QString(propertyDefs[i].widgetName)]		.insert( QString(propertyDefs[i].architectName), i );	i++;    }    QDomDocument doc( QString("QtArch") );    QFile f( fileName );    if ( !f.open(IO_ReadOnly) ) {	return QStringList();    }    if ( !doc.setContent(&f) ) {	QString firstLine;	f.at( 0 );	f.readLine( firstLine, 128 );	firstLine = firstLine.stripWhiteSpace();	if ( firstLine.startsWith(QString("DlgEdit:v1")) ) {	    error( QString("This file is a Qt Architect 1.x file. Qt Designer"			   " can only read XML dialog files, as generated by Qt"			   " Architect 2.1 or above."			   "<p>To convert this file to the right format,"			   " first install Qt Architect 2.1 (available at"			   " <tt>http://qtarch.sourceforge.net/</tt>). Use the"			   " <i>update20.pl</i> Perl script to update the file"			   " to the 2.0 format. Load that file in Qt"			   " Architect and save it. The file should now be in"			   " XML format and loadable in Qt Designer.") );	} else if ( firstLine.startsWith(QString("DlgEdit::v2")) ) {	    error( QString("This file is a Qt Architect 2.0 file. Qt Designer"			   " can only read XML dialog files, as generated by Qt"			   " Architect 2.1 or above."			   "<p>To convert this file to the right format,"			   " first install Qt Architect 2.1 (available at"			   " <tt>http://qtarch.sourceforge.net/</tt>). Load the"			   " 2.0 file in Qt Architect and save it. The file"			   " should now be in XML format and loadable in Qt"			   " Designer.") );	} else {	    error( QString("The file you gave me is not an XML file, as far as"			   " I can tell.") );	}	f.close();	return QStringList();    }    f.close();    QDomElement root = doc.documentElement();    if ( root.tagName() != QString("QtArch") ||	 root.attributeNode("type").value() != QString("Dialog") ) {	error( QString("The file you gave me is not a Qt Architect dialog"		       " file.") );	return QStringList();    }    emitHeader();    QDomNode n = root.firstChild();    while ( !n.isNull() ) {	// there should be only one	matchDialog( n.toElement() );	n = n.nextSibling();    }    emitFooter();    QFile outf;    QString outFileName = yyClassName + QString( ".ui" );    outf.setName( outFileName );    if ( !outf.open(IO_WriteOnly) ) {	qWarning( "dlg2ui: Could not open output file '%s'",		  outFileName.latin1() );	return QStringList();    }    QTextStream out;    out.setEncoding( QTextStream::Latin1 );    out.setDevice( &outf );    out << yyOut;    outf.close();    return QStringList( outFileName );}

⌨️ 快捷键说明

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