/********************************************************************** ** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. ** ** This file is part of Qt GUI Designer. ** ** This file may be used under the terms of the GNU General ** Public License versions 2.0 or 3.0 as published by the Free ** Software Foundation and appearing in the files LICENSE.GPL2 ** and LICENSE.GPL3 included in the packaging of this file. ** Alternatively you may (at your option) use any later version ** of the GNU General Public License if such license has been ** publicly approved by Trolltech ASA (or its successors, if any) ** and the KDE Free Qt Foundation. ** ** Please review the following information to ensure GNU General ** Public Licensing requirements will be met: ** http://trolltech.com/products/qt/licenses/licensing/opensource/. ** If you are unsure which license is appropriate for your use, please ** review the following information: ** http://trolltech.com/products/qt/licenses/licensing/licensingoverview ** or contact the sales department at sales@trolltech.com. ** ** Licensees holding valid Qt Commercial licenses may use this file in ** accordance with the Qt Commercial License Agreement provided with ** the Software. ** ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted ** herein. ** **********************************************************************/ #include #include #include #include #include #include // STEP1: Include header files of the widgets for which a description // should be created here. If you have a widget which is defined in // the file mycustomwidget.h in /home/joedeveloper/src, write here // // #include "/home/joedeveloper/src/mycustomwidget.h" // // Now go on to STEP2! // ----------------------------- struct Widget { QWidget *w; // the widget QString include; // header file QString location; // "global" for include <...> or "local" include "..." }; static QString makeIndent( int indent ) { QString s; s.fill( ' ', indent * 4 ); return s; } static QString entitize( const QString &s ) { QString s2 = s; s2 = s2.replace( "\"", """ ); s2 = s2.replace( "&", "&" ); s2 = s2.replace( ">", ">" ); s2 = s2.replace( "<", "<" ); s2 = s2.replace( "'", "'" ); return s2; } static QString convert_type( const QString &s ) { QString str( s ); if ( str[ 0 ] == 'Q' ) str.remove( 0, 1 ); str[ 0 ] = str[ 0 ].upper(); return str; } static void createDescription( const QValueList &l, QTextStream &ts ) { int indent = 0; ts << "" << endl; ts << makeIndent( indent ) << "" << endl; indent++; for ( QValueList::ConstIterator it = l.begin(); it != l.end(); ++it ) { Widget w = *it; ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << w.w->className() << "" << endl; ts << makeIndent( indent ) << "
" << w.include << "
" << endl; ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << w.w->sizeHint().width() << "" << endl; ts << makeIndent( indent ) << "" << w.w->sizeHint().height() << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; ts << makeIndent( indent ) << "" << ( w.w->inherits( "QGroupBox" ) || w.w->inherits( "QWidgetStack" ) ) << "" << endl; ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << (int)w.w->sizePolicy().horData() << "" << endl; ts << makeIndent( indent ) << "" << (int)w.w->sizePolicy().verData() << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; QStrList sigs = w.w->metaObject()->signalNames( TRUE ); if ( !sigs.isEmpty() ) { for ( int i = 0; i < (int)sigs.count(); ++i ) ts << makeIndent( indent ) << "" << entitize( sigs.at( i ) ) << "" << endl; } QStrList slts = w.w->metaObject()->slotNames( TRUE ); if ( !slts.isEmpty() ) { for ( int i = 0; i < (int)slts.count(); ++i ) { QMetaData::Access data = w.w->metaObject()->slot( i, TRUE )->access; if ( data == QMetaData::Private ) continue; ts << makeIndent( indent ) << "" << entitize( slts.at( i ) ) << "" << endl; } } QStrList props = w.w->metaObject()->propertyNames( TRUE ); if ( !props.isEmpty() ) { for ( int i = 0; i < (int)props.count(); ++i ) { const QMetaProperty *p = w.w->metaObject()-> property( w.w->metaObject()-> findProperty( props.at( i ), TRUE ), TRUE ); if ( !p ) continue; if ( !p->writable() || !p->designable( w.w ) ) continue; ts << makeIndent( indent ) << "type() ) << "\">" << entitize( p->name() ) << "" << endl; } } indent--; ts << makeIndent( indent ) << "
" << endl; } indent--; ts << makeIndent( indent ) << "
" << endl; ts << "
" << endl; } int main( int argc, char **argv ) { if ( argc < 2 ) return -1; QString fn = argv[1]; QFile f( fn ); if ( !f.open( IO_WriteOnly ) ) return -1; QTextStream ts( &f ); QApplication a( argc, argv ); QValueList wl; // STEP2: Instantiate all widgets for which a description should // be created here and add them to the list wl. If your custom widget // is e.g. called MyCustomWidget you would write here // // Widget w; // w.w = new MyCustomWidget( 0, 0 ); // w.include = "mycustomwidget.h"; // w.location = "global"; // wl.append( w ); // // After that compile the program, link it with your custom widget // (library or object file) and run it like this: // (unix): ./createcw mywidgets.cw // (win32): createcw mywidgets.cw // // After that you can import this description file into the Qt // Designer using the Custom-Widget Dialog (See // Tools->Custom->Edit Custom Widgets... in the Qt Designer) // and use these custom widget there in your forms. // ---------------------------------------------- createDescription( wl, ts ); f.close(); return 0; }