📄 uic.cpp
字号:
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" ) { r++; cg.setColor( (QColorGroup::ColorRole)r, (col = DomTool::readColor( n ) ) ); } n = n.nextSibling().toElement(); } return cg;}/*! Registers an object with name \a name. The returned name is a valid variable identifier, as similar to \a name as possible and guaranteed to be unique within the form. \sa registeredName(), isObjectRegistered() */QString Uic::registerObject( const QString& name ){ if ( objectNames.isEmpty() ) { // some temporary variables we need objectNames += "img"; objectNames += "item"; objectNames += "cg"; objectNames += "pal"; } QString result = name; int i; while ( ( i = result.find(' ' )) != -1 ) { result[i] = '_'; } if ( objectNames.contains( result ) ) { int i = 2; while ( objectNames.contains( result + "_" + QString::number(i) ) ) i++; result += "_"; result += QString::number(i); } objectNames += result; objectMapper.insert( name, result ); return result;}/*! Returns the registered name for the original name \a name or \a name if \a name wasn't registered. \sa registerObject(), isObjectRegistered() */QString Uic::registeredName( const QString& name ){ if ( !objectMapper.contains( name ) ) return name; return objectMapper[name];}/*! Returns whether the object \a name was registered yet or not. */bool Uic::isObjectRegistered( const QString& name ){ return objectMapper.contains( name );}/*! Unifies the entries in stringlist \a list. Should really be a QStringList feature. */QStringList Uic::unique( const QStringList& list ){ QStringList result; if (list.isEmpty() ) return result; QStringList l = list; l.sort(); result += l.first(); for ( QStringList::Iterator it = l.begin(); it != l.end(); ++it ) { if ( *it != result.last() ) result += *it; } return result;}/*! Creates an instance of class \a objClass, with parent \a parent and name \a objName */QString Uic::createObjectInstance( const QString& objClass, const QString& parent, const QString& objName ){ if ( objClass.mid( 1 ) == "ComboBox" ) { return objClass + "( FALSE, " + parent + ", \"" + objName + "\" )"; } return objClass + "( " + parent + ", \"" + objName + "\" )";}bool Uic::isLayout( const QString& name ) const{ return layoutObjects.contains( name );}/*! Creates a declaration ( headerfile ) for a subclass \a subClass of the form given in \a e \sa createSubImpl() */void Uic::createSubDecl( const QDomElement &e, const QString& subClass ){ QDomElement n; QStringList::Iterator it; QString objClass = getClassName( e ); if ( objClass.isEmpty() ) return; out << "class " << subClass << " : public " << nameOfClass << endl; out << "{ " << endl;/* tmake ignore Q_OBJECT */ out << " Q_OBJECT" << endl; out << endl; out << "public:" << endl; // constructor if ( objClass == "QDialog" || objClass == "QWizard" ) { out << " " << subClass << "( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );" << endl; } else { // standard QWidget out << " " << subClass << "( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );" << endl; } // destructor out << " ~" << subClass << "();" << 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() ) { out << "public slots:" << endl; for ( it = publicSlots.begin(); it != publicSlots.end(); ++it ) out << " void " << (*it) << ";" << endl; out << endl; } // create protected additional slots as pure-virtual functions if ( !protectedSlots.isEmpty() ) { out << "protected slots:" << endl; for ( it = protectedSlots.begin(); it != protectedSlots.end(); ++it ) out << " void " << (*it) << ";" << endl; out << endl; } out << "};" << endl;}/*! Creates an implementation for a subclass \a subClass of the form given in \a e \sa createSubDecl() */void Uic::createSubImpl( const QDomElement &e, const QString& subClass ){ QDomElement n; QStringList::Iterator it; QString objClass = getClassName( e ); if ( objClass.isEmpty() ) return; // constructor if ( objClass == "QDialog" || objClass == "QWizard" ) { out << "/* " << endl; out << " * Constructs a " << subClass << " which is a child of 'parent', with the " << endl; out << " * name 'name' and widget flags set to 'f' " << endl; out << " *" << endl; out << " * The " << objClass.mid(1).lower() << " will by default be modeless, unless you set 'modal' to" << endl; out << " * TRUE to construct a modal " << objClass.mid(1).lower() << "." << endl; out << " */" << endl; out << subClass << "::" << subClass << "( QWidget* parent, const char* name, bool modal, WFlags fl )" << endl; out << " : " << nameOfClass << "( parent, name, modal, fl )" << endl; } else { // standard QWidget out << "/* " << endl; out << " * Constructs a " << subClass << " which is a child of 'parent', with the " << endl; out << " * name 'name' and widget flags set to 'f' " << endl; out << " */" << endl; out << subClass << "::" << subClass << "( QWidget* parent, const char* name, WFlags fl )" << endl; out << " : " << nameOfClass << "( parent, name, fl )" << endl; } out << "{" << endl; out << "}" << endl; out << endl; // destructor out << "/* " << endl; out << " * Destroys the object and frees any allocated resources" << endl; out << " */" << endl; out << subClass << "::~" << subClass << "()" << endl; out << "{" << endl; out << " // no need to delete child widgets, Qt does it all for us" << 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 stubs for public additional slots if ( !publicSlots.isEmpty() ) { for ( it = publicSlots.begin(); it != publicSlots.end(); ++it ) { out << "/* " << endl; out << " * public slot" << endl; out << " */" << endl; out << "void " << subClass << "::" << (*it) << endl; out << "{" << endl; out << " qWarning( \"" << subClass << "::" << (*it) << " not yet implemented!\" ); " << endl; out << "}" << endl; } out << endl; } // create stubs for protected additional slots if ( !protectedSlots.isEmpty() ) { for ( it = protectedSlots.begin(); it != protectedSlots.end(); ++it ) { out << "/* " << endl; out << " * protected slot" << endl; out << " */" << endl; out << "void " << subClass << "::" << (*it) << endl; out << "{" << endl; out << " qWarning( \"" << subClass << "::" << (*it) << " not yet implemented!\" ); " << endl; out << "}" << endl; } out << endl; }}int main( int argc, char * argv[] ){ bool impl = FALSE; bool subcl = FALSE; const char *error = 0; const char* fileName = 0; const char* className = 0; const char* headerFile = 0; const char* outputFile = 0; const char* trmacro = 0; for ( int n = 1; n < argc && error == 0; n++ ) { QCString arg = argv[n]; if ( arg[0] == '-' ) { // option QCString opt = &arg[1]; if ( opt[0] == 'o' ) { // output redirection if ( opt[1] == '\0' ) { if ( !(n < argc-1) ) { error = "Missing output-file name"; break; } outputFile = argv[++n]; } else outputFile = &opt[1]; } else if ( opt[0] == 'i' || opt == "impl" ) { impl = TRUE; if ( opt == "impl" || opt[1] == '\0' ) { if ( !(n < argc-1) ) { error = "Missing name of header file."; break; } headerFile = argv[++n]; } else headerFile = &opt[1]; } else i
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -