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

📄 uic.cpp

📁 Trolltech公司发布的基于C++图形开发环境
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    }    if ( needEventHandler ) {	indent = "\t"; // increase indentation for if-clause below	out << "/*  " << endl;	out << " *  Main event handler. Reimplemented to handle application" << endl;	out << " *  font changes" << endl;	out << " */" << endl;	out << "bool " << nameOfClass  << "::event( QEvent* ev )" << endl;	out << "{" << endl;	out << "    bool ret = " << objClass << "::event( ev ); " << endl;	out << "    if ( ev->type() == QEvent::ApplicationFontChange ) {" << endl;	for ( i = 0; i < (int) nl.length(); i++ ) {	    n = nl.item(i).toElement();	    if ( DomTool::hasProperty( n, "font" ) )		createExclusiveProperty( n, "font" );	}	out << "    }" << endl;	out << "    return ret;" << endl;	out << "}" << endl;	out << endl;    }    // find additional slots    QStringList publicSlots, protectedSlots;    for ( n = e; !n.isNull(); n = n.nextSibling().toElement() ) {	if ( n.tagName()  == "connections" ) {	    for ( QDomElement n2 = n.firstChild().toElement(); !n2.isNull(); n2 = n2.nextSibling().toElement() ) {		if ( n2.tagName() == "slot" ) {		    QString access = n2.attribute( "access" );		    if ( access == "protected" )			protectedSlots += n2.firstChild().toText().data();		    else			publicSlots += n2.firstChild().toText().data();		}	    }	}    }    // create public additional slots as pure-virtual functions    if ( !publicSlots.isEmpty() ) {	for ( it = publicSlots.begin(); it != publicSlots.end(); ++it ) {	    out << "void " << nameOfClass << "::" << (*it) << endl;	    out << "{" << endl;	    out << "    qWarning( \"" << nameOfClass << "::" << (*it) << ": Not implemented yet!\" );" << endl;	    out << "}" << endl;	    out << endl;	}    }    // create protected additional slots as pure-virtual functions    if ( !protectedSlots.isEmpty() ) {	for ( it = protectedSlots.begin(); it != protectedSlots.end(); ++it ) {	    out << "void " << nameOfClass << "::" << (*it) << endl;	    out << "{" << endl;	    out << "    qWarning( \"" << nameOfClass << "::" << (*it) << ": Not implemented yet!\" );" << endl;	    out << "}" << endl;	    out << endl;	}    }}/*!  Returns include file for class \a className or a null string. */QString Uic::getInclude( const QString& className ){    int wid = WidgetDatabase::idFromClassName( className );    if ( wid != -1 )	return WidgetDatabase::includeFile( wid );    return QString::null;}/*!  Creates a declaration for the object given in \a e.  Any children are ignored, this function does _not_ travesere  recursively.  \sa createObjectImpl() */void Uic::createObjectDecl( const QDomElement& e ){    if ( e.tagName() == "vbox" ) {	out << "    QVBoxLayout* " << registerObject(getLayoutName(e) ) << ";" << endl;    } else if ( e.tagName() == "hbox" ) {	out << "    QHBoxLayout* " << registerObject(getLayoutName(e) ) << ";" << endl;    } else if ( e.tagName() == "grid" ) {	out << "    QGridLayout* " << registerObject(getLayoutName(e) ) << ";" << endl;    } else {	QString objClass = getClassName( e );	if ( objClass.isEmpty() )	    return;	QString objName = getObjectName( e );	if ( objName.isEmpty() )	    return;		// ignore QLayoutWidgets	if ( objClass == "QLayoutWidget" )	    return;	// register the object and unify its name	objName = registerObject( objName );	if ( objClass == "Line" )	    objClass = "QFrame";	out << "    " << objClass << "* " << objName << ";" << endl;    }}/*!  Creates an implementation for the object given in \a e.  Traverses recursively over all children.  Returns the name of the generated child object.  \sa createObjectDecl() */QString Uic::createObjectImpl( const QDomElement &e, const QString& parentClass, const QString& parent, const QString& layout ){    QDomElement n;    QString objClass, objName;    if ( layouts.contains( e.tagName() ) )	return createLayoutImpl( e, parentClass, parent, layout );    objClass = getClassName( e );    if ( objClass.isEmpty() )	return objName;    objName = getObjectName( e );    QString definedName = objName;    bool isTmpObject = objName.isEmpty() || objClass == "QLayoutWidget";    if ( isTmpObject ) {	if ( objClass[0] == 'Q' )	    objName = objClass.mid(1);	else	    objName = objClass.lower();	objName.prepend( "private" );    }    bool isLine = objClass == "Line";    if ( isLine )	objClass = "QFrame";    out << endl;    if ( objClass == "QLayoutWidget" ) {	if ( layout.isEmpty() ) {	    // register the object and unify its name	    objName = registerObject( objName );	    out << "    QWidget* " << objName << " = new QWidget( " << parent << ", \"" << definedName << "\" );" << endl;	} else {	    // the layout widget is not necessary, hide it by creating its child in the parent	    QString result;	    for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {		if (tags.contains( n.tagName()  ) )		    result = createObjectImpl( n, parentClass, parent, layout );	    }	    return result;	}    }   else {	// register the object and unify its name	objName = registerObject( objName );	out << "    ";	if ( isTmpObject )	    out << objClass << "* ";	out << objName << " = new " << createObjectInstance( objClass, parent, objName ) << ";" << endl;    }    lastItem = "0";    // set the properties and insert items    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();		QString value = setObjectProperty( objClass, objName, prop, n2.nextSibling().toElement(), stdset );		if ( value.isEmpty() )		    continue;		if ( prop == "name" )		    continue;		if ( prop == "buddy" && value[0] == '\"' && value[(int)value.length()-1] == '\"' ) {		    buddies << Buddy( objName, value.mid(1, value.length() - 2 ) );		    continue;		}		if ( isLine && prop == "orientation" ) {		    prop = "frameStyle";		    if ( value.right(10)  == "Horizontal" )			value = "QFrame::HLine | QFrame::Sunken";		    else			value = "QFrame::VLine | QFrame::Sunken";		}		if ( prop == "buttonGroupId" ) {		    if ( parentClass == "QButtonGroup" )			out << indent << parent << "->insert( " << objName << ", " << value << " );" << endl;		    continue;		}		if ( prop == "geometry") {			out << indent << objName << "->setGeometry( " << value << " ); " << endl;		} else {		    if ( stdset )			out << indent << objName << "->" << mkStdSet(prop ) << "( " << value << " );" << endl;		    else			out << indent << objName << "->setProperty( \"" << prop << "\", " << value << " );" << endl;		}	    }	} else if ( n.tagName() == "item" ) {	    if ( objClass.mid( 1 ) == "ListBox" ) {		QString s = createListBoxItemImpl( n, objName );		if ( !s.isEmpty() )		    out << indent << s << endl;	    } else if ( objClass.mid( 1 ) == "ComboBox" ) {		QString s = createListBoxItemImpl( n, objName );		if ( !s.isEmpty() )		    out << indent << s << endl;	    } else if ( objClass.mid( 1 ) == "IconView" ) {		QString s = createIconViewItemImpl( n, objName );		if ( !s.isEmpty() )		    out << indent << s << endl;	    } else if ( objClass.mid( 1 ) == "ListView" ) {		QString s = createListViewItemImpl( n, objName, QString::null );		if ( !s.isEmpty() )		    out << s << endl;	    }	} else if ( n.tagName() == "column" ) {	    if ( objClass.mid( 1 ) == "ListView" ) {		QString s = createListViewColumnImpl( n, objName );		if ( !s.isEmpty() )		    out << s;	    }	}    }    // create all children, some widgets have special requirements    if ( objClass == "QTabWidget" ) {	for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {	    if ( tags.contains( n.tagName()  ) ) {		QString page = createObjectImpl( n, objClass, objName );		QString comment;		QString label = DomTool::readAttribute( n, "title", "", &comment ).toString();		out << indent << objName << "->insertTab( " << page << ", " << trcall( label, comment ) << " );" << endl;	    }	}     } else { // standard widgets	for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {	    if ( tags.contains( n.tagName()  ) )		createObjectImpl( n, objClass, objName );	}    }    return objName;}/*!  Creates implementation of an listbox item tag.*/QString Uic::createListBoxItemImpl( const QDomElement &e, const QString &parent ){    QDomElement n = e.firstChild().toElement();    QString txt;    QString com;    QString pix;    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( " )" );		    }		}	    }	}	n = n.nextSibling().toElement();    }    return pix.isEmpty() ?      parent + "->insertItem( " + trcall( txt, com ) + " );":      parent + "->insertItem( " + pix + ", " + trcall( txt, com ) + " );";}/*!  Creates implementation of an iconview item tag.*/QString Uic::createIconViewItemImpl( const QDomElement &e, const QString &parent ){    QDomElement n = e.firstChild().toElement();    QString txt;    QString com;    QString pix;    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( " )" );		    }		}	    }	}	n = n.nextSibling().toElement();    }    if ( pix.isEmpty() )	return "(void) new QIconViewItem( " + parent + ", " + trcall( txt, com ) + " );";    return "(void) new QIconViewItem( " + parent + ", " + trcall( txt, com ) + ", " + pix + " );";}/*!  Creates implementation of an listview item tag.*/QString Uic::createListViewItemImpl( const QDomElement &e, const QString &parent,				     const QString &parentItem ){    QString s;    QDomElement n = e.firstChild().toElement();    bool hasChildren = e.elementsByTagName( "item" ).count() > 0;    QString item;    if ( hasChildren ) {	item = registerObject( "item" );	s = indent + "QListViewItem * " + item + " = ";    } else {	item = "item";	if ( item_used )	    s = indent + item + " = ";	else	    s = indent + "QListViewItem * " + item + " = ";	item_used = TRUE;    }    if ( !parentItem.isEmpty() )	s += "new QListViewItem( " + parentItem + ", " + lastItem + " );\n";    else	s += "new QListViewItem( " + parent + ", " + lastItem + " );\n";    QStringList textes;    QStringList coms;    QStringList pixmaps;    while ( !n.isNull() ) {	if ( n.tagName() == "property" ) {	    QDomElement n2 = n.firstChild().toElement();	    if ( n2.tagName() == "name" ) {		coms.append(getComment(n));		QString attrib = n2.firstChild().toText().data();		QVariant v = DomTool::elementToVariant( n2.nextSibling().toElement(), QVariant() );		if ( attrib == "text" )		    textes << v.toString();		else if ( attrib == "pixmap" ) {		    QString pix = v.toString();		    if ( !pix.isEmpty() && !pixmapLoaderFunction.isEmpty() ) {			pix.prepend( pixmapLoaderFunction + "( " );			pix.append( " )" );		    }		    pixmaps << pix;		}	    }	} else if ( n.tagName() == "item" ) {	    s += indent + item + "->setOpen( TRUE );\n";	    s += createListViewItemImpl( n, parent, item );	}	n = n.nextSibling().toElement();    }    for ( int i = 0; i < (int)textes.count(); ++i ) {	if ( !textes[ i ].isEmpty() )	    s += indent + item + "->setText( " + QString::number( i ) + ", " + trcall( textes[ i ], coms[ i ] ) + " );\n";	if ( !pixmaps[ i ].isEmpty() )	    s += indent + item + "->setPixmap( " + QString::number( i ) + ", " + pixmaps[ i ] + " );\n";    }    lastItem = item;

⌨️ 快捷键说明

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