/********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of TQt 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. ** ** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition ** licenses may use this file in accordance with the TQt Commercial License ** Agreement provided with the Software. ** ** 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. ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for ** information about TQt Commercial License Agreements. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "actiondnd.h" #include "command.h" #ifndef TQT_NO_SQL #include "database.h" #endif #include "formfile.h" #include "formwindow.h" #include "mainwindow.h" #include "menubareditor.h" #include "metadatabase.h" #include "pixmapcollection.h" #include "popupmenueditor.h" #include "project.h" #include "resource.h" #include "widgetfactory.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef TQT_NO_TABLE #include #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kdevdesigner_part.h" static TQString makeIndent( int indent ) { TQString s; s.fill( ' ', indent * 4 ); return s; } static TQString entitize( const TQString &s, bool attribute = FALSE ) { TQString s2 = s; s2 = s2.replace( "&", "&" ); s2 = s2.replace( ">", ">" ); s2 = s2.replace( "<", "<" ); if ( attribute ) { s2 = s2.replace( "\"", """ ); s2 = s2.replace( "'", "'" ); } return s2; } #ifdef TQ_WS_MACX static struct { int key; const char* name; } keyname[] = { { TQt::Key_Space, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Space" ) }, { TQt::Key_Escape, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Esc" ) }, { TQt::Key_Tab, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Tab" ) }, { TQt::Key_Backtab, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Backtab" ) }, { TQt::Key_Backspace, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Backspace" ) }, { TQt::Key_Return, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Return" ) }, { TQt::Key_Enter, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Enter" ) }, { TQt::Key_Insert, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Ins" ) }, { TQt::Key_Delete, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Del" ) }, { TQt::Key_Pause, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Pause" ) }, { TQt::Key_Print, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Print" ) }, { TQt::Key_SysReq, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "SysReq" ) }, { TQt::Key_Home, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Home" ) }, { TQt::Key_End, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "End" ) }, { TQt::Key_Left, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Left" ) }, { TQt::Key_Up, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Up" ) }, { TQt::Key_Right, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Right" ) }, { TQt::Key_Down, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Down" ) }, { TQt::Key_Prior, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "PgUp" ) }, { TQt::Key_Next, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "PgDown" ) }, { TQt::Key_CapsLock, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "CapsLock" ) }, { TQt::Key_NumLock, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "NumLock" ) }, { TQt::Key_ScrollLock, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "ScrollLock" ) }, { TQt::Key_Menu, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Menu" ) }, { TQt::Key_Help, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Help" ) }, // Multimedia keys { TQt::Key_Back, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Back" ) }, { TQt::Key_Forward, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Forward" ) }, { TQt::Key_Stop, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Stop" ) }, { TQt::Key_Refresh, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Refresh" ) }, { TQt::Key_VolumeDown, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Volume Down" ) }, { TQt::Key_VolumeMute, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Volume Mute" ) }, { TQt::Key_VolumeUp, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Volume Up" ) }, { TQt::Key_BassBoost, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Bass Boost" ) }, { TQt::Key_BassUp, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Bass Up" ) }, { TQt::Key_BassDown, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Bass Down" ) }, { TQt::Key_TrebleUp, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Treble Up" ) }, { TQt::Key_TrebleDown, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Treble Down" ) }, { TQt::Key_MediaPlay, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Media Play" ) }, { TQt::Key_MediaStop, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Media Stop" ) }, { TQt::Key_MediaPrev, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Media Previous" ) }, { TQt::Key_MediaNext, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Media Next" ) }, { TQt::Key_MediaRecord, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Media Record" ) }, { TQt::Key_HomePage, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Home" ) }, { TQt::Key_Favorites, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Favorites" ) }, { TQt::Key_Search, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Search" ) }, { TQt::Key_Standby, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Standby" ) }, { TQt::Key_OpenUrl, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Open URL" ) }, { TQt::Key_LaunchMail, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Launch Mail" ) }, { TQt::Key_LaunchMedia, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Launch Media" ) }, { TQt::Key_Launch0, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Launch (0)" ) }, { TQt::Key_Launch1, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Launch (1)" ) }, { TQt::Key_Launch2, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Launch (2)" ) }, { TQt::Key_Launch3, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Launch (3)" ) }, { TQt::Key_Launch4, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Launch (4)" ) }, { TQt::Key_Launch5, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Launch (5)" ) }, { TQt::Key_Launch6, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Launch (6)" ) }, { TQt::Key_Launch7, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Launch (7)" ) }, { TQt::Key_Launch8, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Launch (8)" ) }, { TQt::Key_Launch9, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Launch (9)" ) }, { TQt::Key_LaunchA, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Launch (A)" ) }, { TQt::Key_LaunchB, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Launch (B)" ) }, { TQt::Key_LaunchC, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Launch (C)" ) }, { TQt::Key_LaunchD, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Launch (D)" ) }, { TQt::Key_LaunchE, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Launch (E)" ) }, { TQt::Key_LaunchF, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Launch (F)" ) }, // -------------------------------------------------------------- // More consistent namings { TQt::Key_Print, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Print Screen" ) }, { TQt::Key_Prior, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Page Up" ) }, { TQt::Key_Next, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Page Down" ) }, { TQt::Key_CapsLock, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Caps Lock" ) }, { TQt::Key_NumLock, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Num Lock" ) }, { TQt::Key_NumLock, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Number Lock" ) }, { TQt::Key_ScrollLock, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Scroll Lock" ) }, { TQt::Key_Insert, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Insert" ) }, { TQt::Key_Delete, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Delete" ) }, { TQt::Key_Escape, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "Escape" ) }, { TQt::Key_SysReq, TQT_TRANSLATE_NOOP( TQACCEL_OBJECT_NAME_STRING, "System Request" ) }, { 0, 0 } }; #endif static TQString platformNeutralKeySequence(const TQKeySequence &ks) { #ifndef TQ_WS_MACX return TQString(ks); #else uint k; TQString str; TQString p; for (k = 0; k < ks.count(); ++k) { int keycombo = ks[k]; int basekey = keycombo & ~(TQt::SHIFT | TQt::CTRL | TQt::ALT | TQt::META); if (keycombo & TQt::CTRL) str += "Ctrl+"; if (keycombo & TQt::ALT) str += "Alt+"; if (keycombo & TQt::META) str += "Meta+"; if (keycombo & TQt::SHIFT) str += "Shift+"; // begin copy and paste from TQKeySequence :( if (basekey & TQt::UNICODE_ACCEL) { // Note: This character should NOT be upper()'ed, since // the encoded string should indicate EXACTLY what the // key represents! Hence a 'Ctrl+Shift+c' is posible to // represent, but is clearly impossible to trigger... p = TQChar(basekey & 0xffff); } else if ( basekey >= TQt::Key_F1 && basekey <= TQt::Key_F35 ) { p = TQAccel::tr( "F%1" ).tqarg(basekey - TQt::Key_F1 + 1); } else if ( basekey > TQt::Key_Space && basekey <= TQt::Key_AsciiTilde ) { p.sprintf( "%c", basekey ); } else { int i = 0; while (keyname[i].name) { if (basekey == keyname[i].key) { p = TQAccel::tr(keyname[i].name); break; } ++i; } // If we can't find the actual translatable keyname, // fall back on the tqunicode representation of it... // Or else characters like Key_aring may not get displayed // ( Really depends on you locale ) if ( !keyname[i].name ) // Note: This character should NOT be upper()'ed, see above! p = TQChar(basekey & 0xffff); } // end copy... str += p + ", "; } str.truncate(str.length() - 2); return str; #endif } static TQString mkBool( bool b ) { return b? "true" : "false"; } /*! \class Resource resource.h \brief Class for saving/loading, etc. forms This class is used for saving and loading forms, code generation, transferring data of widgets over the clipboard, etc.. */ Resource::Resource() { mainwindow = 0; formwindow = 0; toplevel = 0; copying = FALSE; pasting = FALSE; hadGeometry = FALSE; langIface = 0; hasFunctions = FALSE; } Resource::Resource( MainWindow* mw ) : mainwindow( mw ) { formwindow = 0; toplevel = 0; copying = FALSE; pasting = FALSE; hadGeometry = FALSE; langIface = 0; hasFunctions = FALSE; } Resource::~Resource() { if ( langIface ) langIface->release(); } void Resource::setWidget( FormWindow *w ) { formwindow = w; toplevel = w; } TQWidget *Resource::widget() const { return toplevel; } bool Resource::load( FormFile *ff, Project *defProject ) { if ( !ff || ff->absFileName().isEmpty() ) return FALSE; currFileName = ff->absFileName(); mainContainerSet = FALSE; TQFile f( ff->absFileName() ); f.open( IO_ReadOnly | IO_Translate ); bool b = load( ff, TQT_TQIODEVICE(&f), defProject ); f.close(); return b; } #undef signals #undef slots bool Resource::load( FormFile *ff, TQIODevice* dev, Project *defProject ) { TQDomDocument doc; TQString errMsg; int errLine; if ( !doc.setContent( dev, &errMsg, &errLine ) ) { return FALSE; } DomTool::fixDocument( doc ); TQWidget *p = mainwindow ? mainwindow->qWorkspace() : 0; toplevel = formwindow = new FormWindow( ff, p, 0 ); if ( defProject ) formwindow->setProject( defProject ); else if ( MainWindow::self ) formwindow->setProject( MainWindow::self->currProject() ); if ( mainwindow ) formwindow->setMainWindow( mainwindow ); MetaDataBase::addEntry( TQT_TQOBJECT(formwindow) ); if ( !langIface ) { TQString lang = "TQt Script"; if ( mainwindow ) lang = mainwindow->currProject()->language(); langIface = MetaDataBase::languageInterface( lang ); if ( langIface ) langIface->addRef(); } uiFileVersion = doc.firstChild().toElement().attribute("version"); TQDomElement e = doc.firstChild().toElement().firstChild().toElement(); TQDomElement forwards = e; while ( forwards.tagName() != "forwards" && !forwards.isNull() ) forwards = forwards.nextSibling().toElement(); TQDomElement includes = e; while ( includes.tagName() != "includes" && !includes.isNull() ) includes = includes.nextSibling().toElement(); TQDomElement variables = e; while ( variables.tagName() != "variables" && !variables.isNull() ) variables = variables.nextSibling().toElement(); TQDomElement signals = e; while ( signals.tagName() != "signals" && !signals.isNull() ) signals = signals.nextSibling().toElement(); TQDomElement slots = e; while ( slots.tagName() != "slots" && !slots.isNull() ) slots = slots.nextSibling().toElement(); TQDomElement functions = e; while ( functions.tagName() != "functions" && !functions.isNull() ) functions = functions.nextSibling().toElement(); TQDomElement connections = e; while ( connections.tagName() != "connections" && !connections.isNull() ) connections = connections.nextSibling().toElement(); TQDomElement imageCollection = e; images.clear(); while ( imageCollection.tagName() != "images" && !imageCollection.isNull() ) imageCollection = imageCollection.nextSibling().toElement(); TQDomElement customWidgets = e; while ( customWidgets.tagName() != "customwidgets" && !customWidgets.isNull() ) customWidgets = customWidgets.nextSibling().toElement(); TQDomElement tabOrder = e; while ( tabOrder.tagName() != "tabstops" && !tabOrder.isNull() ) tabOrder = tabOrder.nextSibling().toElement(); TQDomElement actions = e; while ( actions.tagName() != "actions" && !actions.isNull() ) actions = actions.nextSibling().toElement(); TQDomElement toolbars = e; while ( toolbars.tagName() != "toolbars" && !toolbars.isNull() ) toolbars = toolbars.nextSibling().toElement(); TQDomElement menubar = e; while ( menubar.tagName() != "menubar" && !menubar.isNull() ) menubar = menubar.nextSibling().toElement(); TQDomElement widget; while ( !e.isNull() ) { if ( e.tagName() == "widget" ) { widgets.clear(); widget = e; } else if ( e.tagName() == "include" ) { // compatibility with 2.x MetaDataBase::Include inc; inc.location = "global"; if ( e.attribute( "location" ) == "local" ) inc.location = "local"; inc.implDecl = "in declaration"; if ( e.attribute( "impldecl" ) == "in implementation" ) inc.implDecl = "in implementation"; inc.header = e.firstChild().toText().data(); if ( inc.header.right( 5 ) != ".ui.h" ) { metaIncludes.append( inc ); } else { if ( formwindow->formFile() ) formwindow->formFile()->setCodeFileState( FormFile::Ok ); } } else if ( e.tagName() == "comment" ) { metaInfo.comment = e.firstChild().toText().data(); } else if ( e.tagName() == "forward" ) { // compatibility with old betas metaForwards << e.firstChild().toText().data(); } else if ( e.tagName() == "variable" ) { // compatibility with old betas MetaDataBase::Variable v; v.varName = e.firstChild().toText().data(); v.varAccess = "protected"; metaVariables << v; } else if ( e.tagName() == "author" ) { metaInfo.author = e.firstChild().toText().data(); } else if ( e.tagName() == "class" ) { metaInfo.className = e.firstChild().toText().data(); } else if ( e.tagName() == "pixmapfunction" ) { if ( formwindow ) { formwindow->setSavePixmapInline( FALSE ); formwindow->setSavePixmapInProject( FALSE ); formwindow->setPixmapLoaderFunction( e.firstChild().toText().data() ); } } else if ( e.tagName() == "pixmapinproject" ) { if ( formwindow ) { formwindow->setSavePixmapInline( FALSE ); formwindow->setSavePixmapInProject( TRUE ); } } else if ( e.tagName() == "exportmacro" ) { exportMacro = e.firstChild().toText().data(); } else if ( e.tagName() == "layoutdefaults" ) { formwindow->setLayoutDefaultSpacing( e.attribute( "spacing", TQString::number( formwindow->layoutDefaultSpacing() ) ).toInt() ); formwindow->setLayoutDefaultMargin( e.attribute( "margin", TQString::number( formwindow->layoutDefaultMargin() ) ).toInt() ); } else if ( e.tagName() == "layoutfunctions" ) { formwindow->setSpacingFunction( e.attribute( "spacing" ) ); formwindow->setMarginFunction( e.attribute( "margin" ) ); if ( !formwindow->marginFunction().isEmpty() || !formwindow->spacingFunction().isEmpty() ) formwindow->hasLayoutFunctions( TRUE ); } e = e.nextSibling().toElement(); } if ( !imageCollection.isNull() ) loadImageCollection( imageCollection ); if ( !customWidgets.isNull() ) loadCustomWidgets( customWidgets, this ); #if defined (TQT_NON_COMMERCIAL) bool previewMode = MainWindow::self ? MainWindow::self->isPreviewing() : FALSE; TQWidget *w = (TQWidget*)createObject( widget, !previewMode ? (TQWidget*)formwindow : MainWindow::self ); if ( !w ) return FALSE; if ( previewMode ) w->reparent( MainWindow::self, TQt::WType_TopLevel, w->pos(), TRUE ); #else if ( !createObject( widget, formwindow) ) return FALSE; #endif if ( !forwards.isNull() ) { for ( TQDomElement n = forwards.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) if ( n.tagName() == "forward" ) metaForwards << n.firstChild().toText().data(); } if ( !includes.isNull() ) { for ( TQDomElement n = includes.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) if ( n.tagName() == "include" ) { if ( n.tagName() == "include" ) { MetaDataBase::Include inc; inc.location = "global"; if ( n.attribute( "location" ) == "local" ) inc.location = "local"; inc.implDecl = "in declaration"; if ( n.attribute( "impldecl" ) == "in implementation" ) inc.implDecl = "in implementation"; inc.header = n.firstChild().toText().data(); if ( inc.header.right( 5 ) != ".ui.h" ) { metaIncludes.append( inc ); } else { if ( formwindow->formFile() ) formwindow->formFile()->setCodeFileState( FormFile::Ok ); } } } } if ( !variables.isNull() ) { for ( TQDomElement n = variables.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { if ( n.tagName() == "variable" ) { MetaDataBase::Variable v; v.varName = n.firstChild().toText().data(); v.varAccess = n.attribute( "access", "protected" ); if ( v.varAccess.isEmpty() ) v.varAccess = "protected"; metaVariables << v; } } } if ( !signals.isNull() ) { for ( TQDomElement n = signals.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) if ( n.tagName() == "signal" ) metaSignals << n.firstChild().toText().data(); } if ( !slots.isNull() ) { for ( TQDomElement n = slots.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) if ( n.tagName() == "slot" ) { MetaDataBase::Function function; function.specifier = n.attribute( "specifier", "virtual" ); if ( function.specifier.isEmpty() ) function.specifier = "virtual"; function.access = n.attribute( "access", "public" ); if ( function.access.isEmpty() ) function.access = "public"; function.language = n.attribute( "language", "C++" ); function.returnType = n.attribute( "returnType", "void" ); if ( function.returnType.isEmpty() ) function.returnType = "void"; function.type = "slot"; function.function = n.firstChild().toText().data(); if ( !MetaDataBase::hasFunction( TQT_TQOBJECT(formwindow), function.function, TRUE ) ) MetaDataBase::addFunction( TQT_TQOBJECT(formwindow), function.function, function.specifier, function.access, "slot", function.language, function.returnType ); else MetaDataBase::changeFunctionAttributes( TQT_TQOBJECT(formwindow), function.function, function.function, function.specifier, function.access, "slot", function.language, function.returnType ); } } if ( !functions.isNull() ) { for ( TQDomElement n = functions.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { if ( n.tagName() == "function" ) { MetaDataBase::Function function; function.specifier = n.attribute( "specifier", "virtual" ); if ( function.specifier.isEmpty() ) function.specifier = "virtual"; function.access = n.attribute( "access", "public" ); if ( function.access.isEmpty() ) function.access = "public"; function.type = n.attribute( "type", "function" ); function.type = "function"; function.language = n.attribute( "language", "C++" ); function.returnType = n.attribute( "returnType", "void" ); if ( function.returnType.isEmpty() ) function.returnType = "void"; function.function = n.firstChild().toText().data(); if ( !MetaDataBase::hasFunction( TQT_TQOBJECT(formwindow), function.function, TRUE ) ) MetaDataBase::addFunction( TQT_TQOBJECT(formwindow), function.function, function.specifier, function.access, function.type, function.language, function.returnType ); else MetaDataBase::changeFunctionAttributes( TQT_TQOBJECT(formwindow), function.function, function.function, function.specifier, function.access, function.type, function.language, function.returnType ); } } } if ( !actions.isNull() ) loadActions( actions ); if ( !toolbars.isNull() ) loadToolBars( toolbars ); if ( !menubar.isNull() ) loadMenuBar( menubar ); if ( !connections.isNull() ) loadConnections( connections ); if ( !tabOrder.isNull() ) loadTabOrder( tabOrder ); if ( formwindow ) { MetaDataBase::setIncludes( TQT_TQOBJECT(formwindow), metaIncludes ); MetaDataBase::setForwards( TQT_TQOBJECT(formwindow), metaForwards ); MetaDataBase::setVariables( TQT_TQOBJECT(formwindow), metaVariables ); MetaDataBase::setSignalList( TQT_TQOBJECT(formwindow), metaSignals ); metaInfo.classNameChanged = metaInfo.className != TQString( formwindow->name() ); MetaDataBase::setMetaInfo( TQT_TQOBJECT(formwindow), metaInfo ); MetaDataBase::setExportMacro( TQT_TQOBJECT(formwindow->mainContainer()), exportMacro ); } loadExtraSource( formwindow->formFile(), currFileName, langIface, hasFunctions ); if ( mainwindow && formwindow ) mainwindow->insertFormWindow( formwindow ); if ( formwindow ) { formwindow->killAccels( TQT_TQOBJECT(formwindow) ); if ( formwindow->tqlayout() ) formwindow->tqlayout()->activate(); if ( hadGeometry ) formwindow->resize( formwindow->size().expandedTo( formwindow->tqminimumSize(). expandedTo( formwindow->tqminimumSizeHint() ) ) ); else formwindow->resize( formwindow->size().expandedTo( formwindow->tqsizeHint() ) ); } return TRUE; } static bool saveCode( const TQString &filename, const TQString &code ) { TQFile f( filename ); if ( f.open(IO_WriteOnly | IO_Translate) ) { TQTextStream ts( &f ); ts << code; return TRUE; } return FALSE; } bool Resource::save( const TQString& filename, bool formCodeOnly ) { if ( !formwindow || filename.isEmpty() ) return FALSE; if (!langIface) { TQString lang = "TQt Script"; if ( mainwindow ) lang = mainwindow->currProject()->language(); langIface = MetaDataBase::languageInterface( lang ); if ( langIface ) langIface->addRef(); } if ( formCodeOnly && langIface ) { if ( saveFormCode(formwindow->formFile(), langIface) ) return TRUE; bool breakout = FALSE; FormFile *ff = formwindow->formFile(); TQString codeFile = ff->project()->makeAbsolute( ff->codeFile() ); TQString filter = langIface->fileFilterList().join("\n"); while ( !breakout ) { TQString fn = KFileDialog::getSaveFileName( codeFile, filter ); breakout = fn.isEmpty(); if ( !breakout ) { if ( saveCode(fn, ff->code()) ) return TRUE; } } } currFileName = filename; TQFile f( filename ); if ( !f.open( IO_WriteOnly | IO_Translate ) ) return FALSE; bool b = save( TQT_TQIODEVICE(&f) ); f.close(); return b; } bool Resource::save( TQIODevice* dev ) { if ( !formwindow ) return FALSE; if ( !langIface ) { TQString lang = "C++"; if ( mainwindow ) lang = mainwindow->currProject()->language(); langIface = MetaDataBase::languageInterface( lang ); if ( langIface ) langIface->addRef(); } TQTextStream ts( dev ); ts.setCodec( TQTextCodec::codecForName( "UTF-8" ) ); ts << "" << endl; saveMetaInfoBefore( ts, 0 ); saveObject( TQT_TQOBJECT(formwindow->mainContainer()), 0, ts, 0 ); if ( ::tqqt_cast(formwindow->mainContainer()) ) { saveMenuBar( (TQMainWindow*)formwindow->mainContainer(), ts, 0 ); saveToolBars( (TQMainWindow*)formwindow->mainContainer(), ts, 0 ); } if ( !MetaDataBase::customWidgets()->isEmpty() && !usedCustomWidgets.isEmpty() ) saveCustomWidgets( ts, 0 ); if ( ::tqqt_cast(formwindow->mainContainer()) ) saveActions( formwindow->actionList(), ts, 0 ); if ( !images.isEmpty() ) saveImageCollection( ts, 0 ); if ( !MetaDataBase::connections( TQT_TQOBJECT(formwindow) ).isEmpty() || !MetaDataBase::slotList( TQT_TQOBJECT(formwindow) ).isEmpty() ) saveConnections( ts, 0 ); saveTabOrder( ts, 0 ); saveMetaInfoAfter( ts, 0 ); saveIncludeHints( ts, 0 ); ts << "" << endl; bool ok = saveFormCode( formwindow->formFile(), langIface ); images.clear(); return ok; } TQString Resource::copy() { if ( !formwindow ) return TQString(); copying = TRUE; TQString s; TQTextOStream ts( &s ); ts << "" << endl; TQWidgetList widgets = formwindow->selectedWidgets(); TQWidgetList tmp( widgets ); for ( TQWidget *w = widgets.first(); w; w = widgets.next() ) { TQWidget *p = w->parentWidget(); bool save = TRUE; while ( p ) { if ( tmp.findRef( p ) != -1 ) { save = FALSE; break; } p = p->parentWidget(); } if ( save ) saveObject( TQT_TQOBJECT(w), 0, ts, 0 ); } if ( !MetaDataBase::customWidgets()->isEmpty() && !usedCustomWidgets.isEmpty() ) saveCustomWidgets( ts, 0 ); if ( !images.isEmpty() ) saveImageCollection( ts, 0 ); ts << "" << endl; return s; } void Resource::paste( const TQString &cb, TQWidget *tqparent ) { if ( !formwindow ) return; mainContainerSet = TRUE; pasting = TRUE; TQDomDocument doc; TQString errMsg; int errLine; doc.setContent( cb, &errMsg, &errLine ); TQDomElement firstWidget = doc.firstChild().toElement().firstChild().toElement(); TQDomElement imageCollection = firstWidget; images.clear(); while ( imageCollection.tagName() != "images" && !imageCollection.isNull() ) imageCollection = imageCollection.nextSibling().toElement(); TQDomElement customWidgets = firstWidget; while ( customWidgets.tagName() != "customwidgets" && !customWidgets.isNull() ) customWidgets = customWidgets.nextSibling().toElement(); if ( !imageCollection.isNull() ) loadImageCollection( imageCollection ); if ( !customWidgets.isNull() ) loadCustomWidgets( customWidgets, this ); TQWidgetList widgets; formwindow->clearSelection( FALSE ); formwindow->setPropertyShowingBlocked( TRUE ); formwindow->clearSelection( FALSE ); while ( !firstWidget.isNull() ) { if ( firstWidget.tagName() == "widget" ) { TQWidget *w = (TQWidget*)createObject( firstWidget, tqparent, 0 ); if ( !w ) continue; widgets.append( w ); int x = w->x() + formwindow->grid().x(); int y = w->y() + formwindow->grid().y(); if ( w->x() + w->width() > tqparent->width() ) x = TQMAX( 0, tqparent->width() - w->width() ); if ( w->y() + w->height() > tqparent->height() ) y = TQMAX( 0, tqparent->height() - w->height() ); if ( x != w->x() || y != w->y() ) w->move( x, y ); formwindow->selectWidget( TQT_TQOBJECT(w) ); } else if ( firstWidget.tagName() == "spacer" ) { TQWidget *w = createSpacer( firstWidget, tqparent, 0, firstWidget.tagName() == "vspacer" ? Qt::Vertical : Qt::Horizontal ); if ( !w ) continue; widgets.append( w ); int x = w->x() + formwindow->grid().x(); int y = w->y() + formwindow->grid().y(); if ( w->x() + w->width() > tqparent->width() ) x = TQMAX( 0, tqparent->width() - w->width() ); if ( w->y() + w->height() > tqparent->height() ) y = TQMAX( 0, tqparent->height() - w->height() ); if ( x != w->x() || y != w->y() ) w->move( x, y ); formwindow->selectWidget( TQT_TQOBJECT(w) ); } firstWidget = firstWidget.nextSibling().toElement(); } formwindow->setPropertyShowingBlocked( FALSE ); formwindow->emitShowProperties(); PasteCommand *cmd = new PasteCommand( i18n( "Paste" ), formwindow, widgets ); formwindow->commandHistory()->addCommand( cmd ); } void Resource::saveObject( TQObject *obj, QDesignerGridLayout* grid, TQTextStream &ts, int indent ) { if ( obj && obj->isWidgetType() && ( (TQWidget*)obj )->isHidden() ) return; TQString closeTag; const char* className = WidgetFactory::classNameOf( obj ); int classID = WidgetDatabase::idFromClassName( className ); bool isPlugin = WidgetDatabase::isCustomPluginWidget( classID ); if ( obj->isWidgetType() ) { if ( obj->isA("CustomWidget") || isPlugin ) { usedCustomWidgets << TQString( className ); includeHints << WidgetDatabase::includeFile( classID ); } if ( TQT_BASE_OBJECT(obj) != TQT_BASE_OBJECT(formwindow) && !formwindow->widgets()->find( (TQWidget*)obj ) ) return; // we don't know anything about this thing TQString attributes; if ( grid ) { QDesignerGridLayout::Item item = grid->items[ (TQWidget*)obj ]; attributes += TQString(" row=\"") + TQString::number(item.row) + "\""; attributes += TQString(" column=\"") + TQString::number(item.column) + "\""; if ( item.rowspan * item.colspan != 1 ) { attributes += TQString(" rowspan=\"") + TQString::number(item.rowspan) + "\""; attributes += TQString(" colspan=\"") + TQString::number(item.colspan) + "\""; } } if ( qstrcmp( className, "Spacer" ) == 0 ) { closeTag = makeIndent( indent ) + "\n"; ts << makeIndent( indent ) << "" << endl; ++indent; } else { closeTag = makeIndent( indent ) + "\n"; ts << makeIndent( indent ) << "" << endl; ++indent; } if ( WidgetFactory::hasItems(classID, obj) ) saveItems( obj, ts, indent ); saveObjectProperties( obj, ts, indent ); } else { // test for other objects we created. Nothing so far. return; } QDesignerWidgetStack* ws = 0; if ( ::tqqt_cast(obj) ) { TQTabWidget* tw = (TQTabWidget*) obj; TQObjectList* tmpl = tw->queryList( TQWIDGETSTACK_OBJECT_NAME_STRING ); TQWidgetStack *ws = (TQWidgetStack*)tmpl->first(); TQTabBar *tb = ( (QDesignerTabWidget*)obj )->tabBar(); for ( int i = 0; i < tb->count(); ++i ) { TQTab *t = tb->tabAt( i ); if ( !t ) continue; TQWidget *w = ws->widget( t->identifier() ); if ( !w ) continue; if ( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf(TQT_TQOBJECT(w)) ) == -1 ) continue; // we don't know this widget ts << makeIndent( indent ) << "" << endl; ++indent; ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << entitize( w->name() ) << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << entitize( t->text() ) << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; saveChildrenOf( TQT_TQOBJECT(w), ts, indent ); --indent; ts << makeIndent( indent ) << "" << endl; } delete tmpl; } else if ( (ws = ::tqqt_cast(obj)) != 0 ) { for ( int i = 0; i < ws->count(); ++i ) { TQWidget *w = ws->page( i ); if ( !w ) continue; if ( WidgetDatabase::idFromClassName(WidgetFactory::classNameOf(TQT_TQOBJECT(w))) == -1 ) continue; // we don't know this widget ts << makeIndent( indent ) << "" << endl; ++indent; ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << entitize( w->name() ) << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << TQString::number(i) << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; saveChildrenOf( TQT_TQOBJECT(w), ts, indent ); --indent; ts << makeIndent( indent ) << "" << endl; } } else if ( ::tqqt_cast(obj) ) { TQToolBox* tb = (TQToolBox*)obj; for ( int i = 0; i < tb->count(); ++i ) { TQWidget *w = tb->item( i ); if ( !w ) continue; if ( WidgetDatabase::idFromClassName(WidgetFactory::classNameOf(TQT_TQOBJECT(w))) == -1 ) continue; // we don't know this widget ts << makeIndent( indent ) << "" << endl; ++indent; ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << entitize( w->name() ) << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; ts << makeIndent( indent ) << "" << endl; indent++; saveEnumProperty( TQT_TQOBJECT(w), "backgroundMode", TQVariant::Invalid, ts, indent ); indent--; ts << makeIndent( indent ) << "" << endl; ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << entitize( tb->itemLabel( tb->indexOf(w) ) ) << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; saveChildrenOf( TQT_TQOBJECT(w), ts, indent ); --indent; ts << makeIndent( indent ) << "" << endl; } } else if ( ::tqqt_cast(obj) ) { TQWizard* wiz = (TQWizard*)obj; for ( int i = 0; i < wiz->pageCount(); ++i ) { TQWidget *w = wiz->page( i ); if ( !w ) continue; if ( WidgetDatabase::idFromClassName(WidgetFactory::classNameOf(TQT_TQOBJECT(w))) == -1 ) continue; // we don't know this widget ts << makeIndent( indent ) << "" << endl; ++indent; ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << entitize( w->name() ) << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << entitize( wiz->title( w ) ) << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; saveChildrenOf( TQT_TQOBJECT(w), ts, indent ); --indent; ts << makeIndent( indent ) << "" << endl; } } else if ( ::tqqt_cast(obj) ) { saveChildrenOf( TQT_TQOBJECT(( (TQMainWindow*)obj )->centralWidget()), ts, indent ); } else { bool saved = FALSE; #ifdef TQT_CONTAINER_CUSTOM_WIDGETS if ( isPlugin ) { WidgetInterface *iface = 0; widgetManager()->queryInterface( className, &iface ); if ( iface ) { TQWidgetContainerInterfacePrivate *iface2 = 0; iface->queryInterface( IID_TQWidgetContainer, (TQUnknownInterface**)&iface2 ); if ( iface2 ) { if ( iface2->supportsPages( className ) ) { TQWidgetList containers = iface2->pages( className, (TQWidget*)obj ); if ( !containers.isEmpty() ) { saved = TRUE; int i = 0; for ( TQWidget *w = containers.first(); w; w = containers.next(), ++i ) { if ( WidgetDatabase:: idFromClassName( WidgetFactory::classNameOf( TQT_TQOBJECT(w) ) ) == -1 ) continue; // we don't know this widget ts << makeIndent( indent ) << "" << endl; ++indent; ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << entitize( w->name() ) << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << entitize( iface2->pageLabel( className, (TQWidget*)obj, i ) ) << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; saveChildrenOf( w, ts, indent ); --indent; ts << makeIndent( indent ) << "" << endl; } } } else { saved = TRUE; TQWidget *w = iface2->containerOfWidget( className, (TQWidget*)obj ); if ( obj != w ) { ts << makeIndent( indent ) << "" << endl; ++indent; ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << entitize( w->name() ) << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; saveChildrenOf( w, ts, indent ); --indent; ts << makeIndent( indent ) << "" << endl; } // Create a custom widget and then store it in the database // so we can save the custom widgets. MetaDataBase::CustomWidget *cw = new MetaDataBase::CustomWidget; cw->className = className; cw->includeFile = WidgetDatabase::includeFile( classID ); TQStrList lst = w->tqmetaObject()->signalNames( TRUE ); for ( TQPtrListIterator it(lst); it.current(); ++it ) cw->lstSignals.append(it.current()); int i; int total = w->tqmetaObject()->numProperties( TRUE ); for ( i = 0; i < total; i++ ) { const TQMetaProperty *p = w->tqmetaObject()->property( i, TRUE ); if ( p->designable(w) ) { MetaDataBase::Property prop; prop.property = p->name(); TQString pType = p->type(); // *sigh* designer types are not normal types // Handle most cases, the ones it misses are // probably too difficult to deal with anyway... if ( pType.startsWith("Q") ) { pType = pType.right( pType.length() - 1 ); } else { pType[0] = pType[0].upper(); } prop.type = pType; cw->lstProperties.append( prop ); } } total = w->tqmetaObject()->numSlots( TRUE ); for ( i = 0; i < total; i++ ) { const TQMetaData *md = w->tqmetaObject()->slot( i, TRUE ); MetaDataBase::Function funky; // Find out if we have a return type. if ( md->method->count > 0 ) { const TQUParameter p = md->method->parameters[0]; if ( p.inOut == TQUParameter::InOut ) funky.returnType = p.type->desc(); } funky.function = md->name; funky.language = "C++"; switch ( md->access ) { case TQMetaData::Public: funky.access = "public"; break; case TQMetaData::Protected: funky.access = "protected"; break; case TQMetaData::Private: funky.access = "private"; break; } cw->lstSlots.append( funky ); } MetaDataBase::addCustomWidget( cw ); } iface2->release(); } iface->release(); } } #endif // TQT_CONTAINER_CUSTOM_WIDGETS if ( !saved ) saveChildrenOf( obj, ts, indent ); } indent--; ts << closeTag; } void Resource::saveItems( TQObject *obj, TQTextStream &ts, int indent ) { if ( ::tqqt_cast(obj) || ::tqqt_cast(obj) ) { TQListBox *lb = 0; if ( ::tqqt_cast(obj) ) lb = (TQListBox*)obj; else lb = ( (TQComboBox*)obj )->listBox(); TQListBoxItem *i = lb->firstItem(); for ( ; i; i = i->next() ) { ts << makeIndent( indent ) << "" << endl; indent++; TQStringList text; text << i->text(); TQPtrList pixmaps; if ( i->pixmap() ) pixmaps.append( i->pixmap() ); saveItem( text, pixmaps, ts, indent ); indent--; ts << makeIndent( indent ) << "" << endl; } } else if ( ::tqqt_cast(obj) ) { TQIconView *iv = (TQIconView*)obj; TQIconViewItem *i = iv->firstItem(); for ( ; i; i = i->nextItem() ) { ts << makeIndent( indent ) << "" << endl; indent++; TQStringList text; text << i->text(); TQPtrList pixmaps; if ( i->pixmap() ) pixmaps.append( i->pixmap() ); saveItem( text, pixmaps, ts, indent ); indent--; ts << makeIndent( indent ) << "" << endl; } } else if ( ::tqqt_cast(obj) ) { TQListView *lv = (TQListView*)obj; int i; for ( i = 0; i < lv->header()->count(); ++i ) { ts << makeIndent( indent ) << "" << endl; indent++; TQStringList l; l << lv->header()->label( i ); TQPtrList pix; pix.setAutoDelete( TRUE ); if ( lv->header()->iconSet( i ) ) pix.append( new TQPixmap( lv->header()->iconSet( i )->pixmap() ) ); saveItem( l, pix, ts, indent ); ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << mkBool( lv->header()->isClickEnabled( i ) )<< "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << mkBool( lv->header()->isResizeEnabled( i ) ) << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; } saveItem( lv->firstChild(), ts, indent - 1 ); } #if !defined (TQT_NO_TABLE) else if ( ::tqqt_cast(obj) ) { TQTable *table = (TQTable*)obj; int i; TQMap columnFields = MetaDataBase::columnFields( TQT_TQOBJECT(table) ); # ifndef TQT_NO_SQL bool isDataTable = ::tqqt_cast(table); # else bool isDataTable = false; # endif for ( i = 0; i < table->horizontalHeader()->count(); ++i ) { if ( !table->horizontalHeader()->label( i ).isNull() && table->horizontalHeader()->label( i ).toInt() != i + 1 || table->horizontalHeader()->iconSet( i ) || isDataTable ) { ts << makeIndent( indent ) << "" << endl; indent++; TQStringList l; l << table->horizontalHeader()->label( i ); TQPtrList pix; pix.setAutoDelete( TRUE ); if ( table->horizontalHeader()->iconSet( i ) ) pix.append( new TQPixmap( table->horizontalHeader()->iconSet( i )->pixmap() ) ); saveItem( l, pix, ts, indent ); if ( isDataTable && !columnFields.isEmpty() ) { ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << entitize( *columnFields.find( l[ 0 ] ) ) << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; } indent--; ts << makeIndent( indent ) << "" << endl; } } for ( i = 0; i < table->verticalHeader()->count(); ++i ) { if ( !table->verticalHeader()->label( i ).isNull() && table->verticalHeader()->label( i ).toInt() != i + 1 || table->verticalHeader()->iconSet( i ) ) { ts << makeIndent( indent ) << "" << endl; indent++; TQStringList l; l << table->verticalHeader()->label( i ); TQPtrList pix; pix.setAutoDelete( TRUE ); if ( table->verticalHeader()->iconSet( i ) ) pix.append( new TQPixmap( table->verticalHeader()->iconSet( i )->pixmap() ) ); saveItem( l, pix, ts, indent ); indent--; ts << makeIndent( indent ) << "" << endl; } } } #endif } void Resource::saveItem( TQListViewItem *i, TQTextStream &ts, int indent ) { TQListView *lv = i->listView(); while ( i ) { ts << makeIndent( indent ) << "" << endl; indent++; TQPtrList pixmaps; TQStringList textes; for ( int c = 0; c < lv->columns(); ++c ) { pixmaps.append( i->pixmap( c ) ); textes << i->text( c ); } saveItem( textes, pixmaps, ts, indent ); if ( i->firstChild() ) saveItem( i->firstChild(), ts, indent ); indent--; ts << makeIndent( indent ) << "" << endl; i = i->nextSibling(); } } void Resource::savePixmap( const TQPixmap &p, TQTextStream &ts, int indent, const TQString &tagname ) { if ( p.isNull() ) { ts << makeIndent( indent ) << "<" << tagname << ">" << endl; return; } if ( formwindow && formwindow->savePixmapInline() ) ts << makeIndent( indent ) << "<" << tagname << ">" << saveInCollection( p ) << "" << endl; else if ( formwindow && formwindow->savePixmapInProject() ) ts << makeIndent( indent ) << "<" << tagname << ">" << MetaDataBase::pixmapKey( TQT_TQOBJECT(formwindow), p.serialNumber() ) << "" << endl; else ts << makeIndent( indent ) << "<" << tagname << ">" << MetaDataBase::pixmapArgument( TQT_TQOBJECT(formwindow), p.serialNumber() ) << "" << endl; } TQPixmap Resource::loadPixmap( const TQDomElement &e, const TQString &/*tagname*/ ) { TQString arg = e.firstChild().toText().data(); if ( formwindow && formwindow->savePixmapInline() ) { TQImage img = loadFromCollection( arg ); TQPixmap pix; pix.convertFromImage( img ); MetaDataBase::setPixmapArgument( TQT_TQOBJECT(formwindow), pix.serialNumber(), arg ); return pix; } else if ( formwindow && formwindow->savePixmapInProject() ) { TQPixmap pix; if ( mainwindow && mainwindow->currProject() ) { pix = mainwindow->currProject()->pixmapCollection()->pixmap( arg ); } else { pix = BarIcon( "designer_image.png", KDevDesignerPartFactory::instance() ); // we have to force the pixmap to get a new and unique serial number. Unfortunately detatch() doesn't do that pix.convertFromImage( pix.convertToImage() ); } MetaDataBase::setPixmapKey( TQT_TQOBJECT(formwindow), pix.serialNumber(), arg ); return pix; } TQPixmap pix = BarIcon( "designer_image.png", KDevDesignerPartFactory::instance() ); // we have to force the pixmap to get a new and unique serial number. Unfortunately detatch() doesn't do that pix.convertFromImage( pix.convertToImage() ); MetaDataBase::setPixmapArgument( TQT_TQOBJECT(formwindow), pix.serialNumber(), arg ); return pix; } void Resource::saveItem( const TQStringList &text, const TQPtrList &pixmaps, TQTextStream &ts, int indent ) { TQStringList::ConstIterator it = text.begin(); for ( ; it != text.end(); ++it ) { ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << entitize( *it ) << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; } for ( int i = 0; i < (int)pixmaps.count(); ++i ) { TQPixmap *p = ( (TQPtrList)pixmaps ).at( i ); ts << makeIndent( indent ) << "" << endl; indent++; if ( p ) savePixmap( *p, ts, indent ); else savePixmap( TQPixmap(), ts, indent ); indent--; ts << makeIndent( indent ) << "" << endl; } } void Resource::saveChildrenOf( TQObject* obj, TQTextStream &ts, int indent ) { const TQObjectList l = obj->childrenListObject(); if ( l.isEmpty() ) return; // no tqchildren to save TQString closeTag; // if the widget has a tqlayout we pretend that all widget's childs are childs of the tqlayout - makes the structure nicer TQLayout *tqlayout = 0; QDesignerGridLayout* grid = 0; if ( !::tqqt_cast(obj) && WidgetDatabase::isContainer( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( obj ) ) ) && obj->isWidgetType() && WidgetFactory::layoutType( (TQWidget*)obj, tqlayout ) != WidgetFactory::NoLayout ) { WidgetFactory::LayoutType lay = WidgetFactory::layoutType( (TQWidget*)obj, tqlayout ); switch ( lay ) { case WidgetFactory::HBox: closeTag = makeIndent( indent ) + ""; ts << makeIndent( indent ) << "" << endl; ++indent; break; case WidgetFactory::VBox: closeTag = makeIndent( indent ) + ""; ts << makeIndent( indent ) << "" << endl; ++indent; break; case WidgetFactory::Grid: closeTag = makeIndent( indent ) + ""; ts << makeIndent( indent ) << "" << endl; ++indent; grid = (QDesignerGridLayout*) tqlayout; break; default: break; } // save properties of tqlayout if ( lay != WidgetFactory::NoLayout ) saveObjectProperties( TQT_TQOBJECT(tqlayout), ts, indent ); } TQObject *o = 0; for ( TQPtrListIterator it ( l ); ( o = it.current() ); ++it ) if ( !TQString( o->name() ).startsWith( "qt_dead_widget_" ) ) saveObject( o, grid, ts, indent ); if ( !closeTag.isEmpty() ) { indent--; ts << closeTag << endl; } } void Resource::saveObjectProperties( TQObject *w, TQTextStream &ts, int indent ) { TQStringList saved; TQStringList changed; changed = MetaDataBase::changedProperties( w ); if ( w->isWidgetType() ) { if ( ::tqqt_cast(w) ) { if ( !changed.contains( "tqsizeHint" ) ) changed << "tqsizeHint"; if ( !changed.contains( "geometry" ) ) changed << "geometry"; } else { TQToolButton *tb = ::tqqt_cast(w); if ( tb && !tb->iconSet().isNull() ) { changed << "iconSet"; } } } else if ( ::tqqt_cast(w) ) { if ( MetaDataBase::spacing( TQT_TQOBJECT( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (TQLayout*)(w) ) ) ) ) > -1 ) changed << "spacing"; if ( MetaDataBase::margin( TQT_TQOBJECT( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (TQLayout*)(w) ) ) ) ) > -1 ) changed << "margin"; if ( MetaDataBase::resizeMode( TQT_TQOBJECT( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (TQLayout*)(w) ) ) ) ) != "Auto" && !MetaDataBase::resizeMode( TQT_TQOBJECT( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (TQLayout*)(w) ) ) ) ).isEmpty() ) changed << "resizeMode"; } if ( TQT_BASE_OBJECT(w) == TQT_BASE_OBJECT(formwindow->mainContainer()) ) { if ( changed.findIndex( "geometry" ) == -1 ) changed << "geometry"; if ( changed.findIndex( "caption" ) == -1 ) changed << "caption"; } if ( changed.isEmpty() ) return; bool inLayout = TQT_BASE_OBJECT(w) != TQT_BASE_OBJECT(formwindow->mainContainer()) && !copying && w->isWidgetType() && ( (TQWidget*)w )->parentWidget() && WidgetFactory::layoutType( ( (TQWidget*)w )->parentWidget() ) != WidgetFactory::NoLayout; TQStrList lst = w->tqmetaObject()->propertyNames( !::tqqt_cast(w) ); for ( TQPtrListIterator it( lst ); it.current(); ++it ) { if ( changed.find( TQString::tqfromLatin1( it.current() ) ) == changed.end() ) continue; if ( saved.find( TQString::tqfromLatin1( it.current() ) ) != saved.end() ) continue; saved << TQString::tqfromLatin1( it.current() ); const TQMetaProperty* p = w->tqmetaObject()-> property( w->tqmetaObject()->findProperty( it.current(), TRUE ), TRUE ); if ( !p || !p->stored( w ) || ( inLayout && qstrcmp( p->name(), "geometry" ) == 0 ) ) continue; if ( ::tqqt_cast(w) && qstrcmp( p->name(), "pixmap" ) == 0 && ( !( (TQLabel*)w )->pixmap() || ( (TQLabel*)w )->pixmap()->isNull() ) ) continue; if ( ::tqqt_cast(w) && ( qstrcmp( p->name(), "itemName" ) == 0 || qstrcmp( p->name(), "itemNumber" ) == 0 || qstrcmp( p->name(), "itemText" ) == 0 ) ) continue; if ( qstrcmp( p->name(), "name" ) == 0 ) knownNames << w->property( "name" ).toString(); if ( !p->isSetType() && !p->isEnumType() && !w->property( p->name() ).isValid() ) continue; ts << makeIndent( indent ) << "stdSet() ) ts << " stdset=\"0\""; ts << ">" << endl; indent++; if ( strcmp( it.current(), "resizeMode" ) == 0 && ::tqqt_cast(w) ) { saveProperty( w, it.current(), "", TQVariant::String, ts, indent ); } else if ( p->isSetType() ) { saveSetProperty( w, it.current(), TQVariant::nameToType( p->type() ), ts, indent ); } else if ( p->isEnumType() ) { saveEnumProperty( w, it.current(), TQVariant::nameToType( p->type() ), ts, indent ); } else { saveProperty( w, it.current(), w->property( p->name() ), TQVariant::nameToType( p->type() ), ts, indent ); } indent--; ts << makeIndent( indent ) << "" << endl; } if ( w->isWidgetType() && MetaDataBase::fakeProperties( w ) ) { TQMap* fakeProperties = MetaDataBase::fakeProperties( w ); for ( TQMap::Iterator fake = fakeProperties->begin(); fake != fakeProperties->end(); ++fake ) { if ( MetaDataBase::isPropertyChanged( w, fake.key() ) ) { if ( w->inherits("CustomWidget") ) { MetaDataBase::CustomWidget *cw = ( (CustomWidget*)w )->customWidget(); if ( cw && !cw->hasProperty( fake.key().latin1() ) && fake.key() != "toolTip" && fake.key() != "whatsThis" ) continue; } ts << makeIndent( indent ) << "" << endl; indent++; saveProperty( w, fake.key(), *fake, (*fake).type(), ts, indent ); indent--; ts << makeIndent( indent ) << "" << endl; } } } } void Resource::saveSetProperty( TQObject *w, const TQString &name, TQVariant::Type, TQTextStream &ts, int indent ) { const TQMetaProperty *p = w->tqmetaObject()->property( w->tqmetaObject()->findProperty( name, TRUE ), TRUE ); TQStrList l( p->valueToKeys( w->property( name ).toInt() ) ); TQString v; for ( uint i = 0; i < l.count(); ++i ) { v += l.at( i ); if ( i < l.count() - 1 ) v += "|"; } ts << makeIndent( indent ) << "" << v << "" << endl; } void Resource::saveEnumProperty( TQObject *w, const TQString &name, TQVariant::Type, TQTextStream &ts, int indent ) { const TQMetaProperty *p = w->tqmetaObject()->property( w->tqmetaObject()->findProperty( name, TRUE ), TRUE ); ts << makeIndent( indent ) << "" << p->valueToKey( w->property( name ).toInt() ) << "" << endl; } void Resource::saveProperty( TQObject *w, const TQString &name, const TQVariant &value, TQVariant::Type t, TQTextStream &ts, int indent ) { if ( name == "hAlign" || name =="vAlign" || name == "wordwrap" || name == "layoutMargin" || name =="layoutSpacing" ) return; int num; uint unum; double dob; TQString comment; if ( w && formwindow->widgets()->find( (TQWidget*)w ) || formwindow->actionList().find( (TQAction*)w ) ) comment = MetaDataBase::propertyComment( w, name ); switch ( t ) { case TQVariant::String: if ( name == "resizeMode" ) { TQString resmod = MetaDataBase::resizeMode( TQT_TQOBJECT( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (TQLayout*)(w) ) ) ) ); if ( !resmod.isNull() && resmod != "Auto" ) { ts << makeIndent( indent ) << ""; ts << resmod; ts << "" << endl; } } else { ts << makeIndent( indent ) << "" << entitize( value.toString() ) << "" << endl; if ( !comment.isEmpty() ) ts << makeIndent( indent ) << "" << entitize( comment ) << "" << endl; } break; case TQVariant::CString: ts << makeIndent( indent ) << "" << entitize( value.toCString() ).latin1() << "" << endl; break; case TQVariant::Bool: ts << makeIndent( indent ) << "" << mkBool( value.toBool() ) << "" << endl; break; case TQVariant::Int: if ( ::tqqt_cast(w) ) { num = -1; if ( name == "spacing" ) num = MetaDataBase::spacing( TQT_TQOBJECT( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (TQLayout*)(w) ) ) ) ); else if ( name == "margin" ) num = MetaDataBase::margin( TQT_TQOBJECT( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (TQLayout*)(w) ) ) ) ); if ( num != -1 ) ts << makeIndent( indent ) << "" << TQString::number( num ) << "" << endl; } else { num = value.toInt(); ts << makeIndent( indent ) << "" << TQString::number( num ) << "" << endl; } break; case TQVariant::Double: dob = value.toDouble(); ts << makeIndent( indent ) << "" << TQString::number( dob ) << "" << endl; break; case TQVariant::KeySequence: ts << makeIndent( indent ) << "" << entitize(platformNeutralKeySequence(value.toKeySequence())) << "" << endl; break; case TQVariant::UInt: unum = value.toUInt(); ts << makeIndent( indent ) << "" << TQString::number( unum ) << "" << endl; break; case TQVariant::Rect: { TQVariant v( value ); ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << TQString::number( v.toRect().x() ) << "" << endl; ts << makeIndent( indent ) << "" << TQString::number( v.toRect().y() ) << "" << endl; ts << makeIndent( indent ) << "" << TQString::number( v.toRect().width() ) << "" << endl; ts << makeIndent( indent ) << "" << TQString::number( v.toRect().height() ) << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; } break; case TQVariant::Point: { TQVariant v( value ); ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << TQString::number( v.toPoint().x() ) << "" << endl; ts << makeIndent( indent ) << "" << TQString::number( v.toPoint().y() ) << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; } break; case TQVariant::Size: { TQVariant v( value ); ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << TQString::number( v.toSize().width() ) << "" << endl; ts << makeIndent( indent ) << "" << TQString::number( v.toSize().height() ) << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; } break; case TQVariant::Color: { TQVariant v( value ); ts << makeIndent( indent ) << "" << endl; indent++; saveColor( ts, indent, v.toColor() ); indent--; ts << makeIndent( indent ) << "" << endl; } break; case TQVariant::Font: { TQVariant v( value ); ts << makeIndent( indent ) << "" << endl; TQFont f( tqApp->font() ); if ( w && w->isWidgetType() && ((TQWidget*)w)->parentWidget() ) f = ((TQWidget*)w)->parentWidget()->font(); TQFont f2( v.toFont() ); indent++; if ( f.family() != f2.family() ) ts << makeIndent( indent ) << "" << f2.family() << "" << endl; if ( f.pointSize() != f2.pointSize() ) ts << makeIndent( indent ) << "" << TQString::number( f2.pointSize() ) << "" << endl; if ( f.bold() != f2.bold() ) ts << makeIndent( indent ) << "" << TQString::number( (int)f2.bold() ) << "" << endl; if ( f.italic() != f2.italic() ) ts << makeIndent( indent ) << "" << TQString::number( (int)f2.italic() ) << "" << endl; if ( f.underline() != f2.underline() ) ts << makeIndent( indent ) << "" << TQString::number( (int)f2.underline() ) << "" << endl; if ( f.strikeOut() != f2.strikeOut() ) ts << makeIndent( indent ) << "" << TQString::number( (int)f2.strikeOut() ) << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; } break; case TQVariant::SizePolicy: { TQSizePolicy sp( value.toSizePolicy() ); ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << (int)sp.horData() << "" << endl; ts << makeIndent( indent ) << "" << (int)sp.verData() << "" << endl; ts << makeIndent( indent ) << "" << (int)sp.horStretch() << "" << endl; ts << makeIndent( indent ) << "" << (int)sp.verStretch() << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; break; } case TQVariant::Pixmap: savePixmap( value.toPixmap(), ts, indent ); break; case TQVariant::IconSet: savePixmap( value.toIconSet().pixmap(), ts, indent, "iconset" ); break; case TQVariant::Image: ts << makeIndent( indent ) << "" << saveInCollection( value.toImage() ) << "" << endl; break; case TQVariant::Palette: { TQPalette p( value.toPalette() ); ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << endl; indent++; saveColorGroup( ts, indent, p.active() ); indent--; ts << makeIndent( indent ) << "" << endl; ts << makeIndent( indent ) << "" << endl; indent++; saveColorGroup( ts, indent, p.disabled() ); indent--; ts << makeIndent( indent ) << "" << endl; ts << makeIndent( indent ) << "" << endl; indent++; saveColorGroup( ts, indent, p.inactive() ); indent--; ts << makeIndent( indent ) << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; } break; case TQVariant::Cursor: ts << makeIndent( indent ) << "" << value.toCursor().tqshape() << "" << endl; break; case TQVariant::StringList: { TQStringList lst = value.toStringList(); uint i = 0; ts << makeIndent( indent ) << "" << endl; indent++; if ( !lst.isEmpty() ) { for ( i = 0; i < lst.count(); ++i ) ts << makeIndent( indent ) << "" << entitize( lst[ i ] ) << "" << endl; } indent--; ts << makeIndent( indent ) << "" << endl; } break; case TQVariant::Date: { TQDate d = value.toDate(); ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << d.year() << "" << endl; ts << makeIndent( indent ) << "" << d.month() << "" << endl; ts << makeIndent( indent ) << "" << d.day() << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; break; } case TQVariant::Time: { TQTime t = value.toTime(); ts << makeIndent( indent ) << "" << endl; break; } case TQVariant::DateTime: { TQDateTime dt = value.toDateTime(); ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << dt.date().year() << "" << endl; ts << makeIndent( indent ) << "" << dt.date().month() << "" << endl; ts << makeIndent( indent ) << "" << dt.date().day() << "" << endl; ts << makeIndent( indent ) << "" << dt.time().hour() << "" << endl; ts << makeIndent( indent ) << "" << dt.time().minute() << "" << endl; ts << makeIndent( indent ) << "" << dt.time().second() << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; break; } default: qWarning( "saving the property %s of type %d not supported yet", name.latin1(), (int)t ); } } void Resource::saveColorGroup( TQTextStream &ts, int indent, const TQColorGroup &cg ) { for( int r = 0 ; r < TQColorGroup::NColorRoles ; r++ ) { ts << makeIndent( indent ) << "" << endl; indent++; saveColor( ts, indent, cg.color( (TQColorGroup::ColorRole)r ) ); indent--; ts << makeIndent( indent ) << "" << endl; TQPixmap* pm = cg.tqbrush( (TQColorGroup::ColorRole)r ).pixmap(); if ( pm && !pm->isNull() ) savePixmap( *pm, ts, indent ); } } void Resource::saveColor( TQTextStream &ts, int indent, const TQColor &c ) { ts << makeIndent( indent ) << "" << TQString::number( c.red() ) << "" << endl; ts << makeIndent( indent ) << "" << TQString::number( c.green() ) << "" << endl; ts << makeIndent( indent ) << "" << TQString::number( c.blue() ) << "" << endl; } TQObject *Resource::createObject( const TQDomElement &e, TQWidget *tqparent, TQLayout* tqlayout ) { lastItem = 0; TQDomElement n = e.firstChild().toElement(); TQWidget *w = 0; // the widget that got created TQObject *obj = 0; // gets the properties int row = e.attribute( "row" ).toInt(); int col = e.attribute( "column" ).toInt(); int rowspan = e.attribute( "rowspan" ).toInt(); int colspan = e.attribute( "colspan" ).toInt(); if ( rowspan < 1 ) rowspan = 1; if ( colspan < 1 ) colspan = 1; TQString className = e.attribute( "class", TQWIDGET_OBJECT_NAME_STRING ); #ifdef TQT_CONTAINER_CUSTOM_WIDGETS TQString parentClassName = WidgetFactory::classNameOf( tqparent ); bool isPlugin = WidgetDatabase::isCustomPluginWidget( WidgetDatabase::idFromClassName( parentClassName ) ); if ( isPlugin ) qWarning( "####### loading custom container widgets without page support not implemented!" ); // ### TODO loading for custom container widgets without pages #endif if ( !className.isNull() ) { obj = TQT_TQOBJECT(WidgetFactory::create( WidgetDatabase::idFromClassName( className ), tqparent, 0, FALSE )); if ( !obj ) { TQMessageBox::critical( MainWindow::self, i18n( "Loading File" ), i18n( "Error loading %1.\n" "The widget %2 could not be created." ). tqarg( currFileName ).tqarg( className ) ); return 0; } if ( !mainContainerSet ) { if ( formwindow ) formwindow->setMainContainer( (TQWidget*)obj ); mainContainerSet = TRUE; } w = (TQWidget*)obj; if ( ::tqqt_cast(w) ) w = ( (TQMainWindow*)w )->centralWidget(); if ( tqlayout ) { switch ( WidgetFactory::layoutType( tqlayout ) ) { case WidgetFactory::HBox: ( (TQHBoxLayout*)tqlayout )->addWidget( w ); break; case WidgetFactory::VBox: ( (TQVBoxLayout*)tqlayout )->addWidget( w ); break; case WidgetFactory::Grid: ( (QDesignerGridLayout*)tqlayout )->addMultiCellWidget( w, row, row + rowspan - 1, col, col + colspan - 1 ); break; default: break; } } if ( !toplevel ) toplevel = w; tqlayout = 0; if ( w && formwindow ) { if ( !tqparent || ( !::tqqt_cast(tqparent) && !::tqqt_cast(tqparent) && !::tqqt_cast(tqparent) && !::tqqt_cast(tqparent) #ifdef TQT_CONTAINER_CUSTOM_WIDGETS && !isPlugin #endif ) ) formwindow->insertWidget( w, pasting ); else if ( tqparent && ( ::tqqt_cast(tqparent) || ::tqqt_cast(tqparent) || ::tqqt_cast(tqparent) || ::tqqt_cast(tqparent) #ifdef TQT_CONTAINER_CUSTOM_WIDGETS || isPlugin #endif ) ) MetaDataBase::addEntry( TQT_TQOBJECT(w) ); } } TQDomElement sizePolicyElement; TQObject *sizePolicyObject = 0; while ( !n.isNull() ) { if ( n.tagName() == "spacer" ) { createSpacer( n, w, tqlayout, Qt::Horizontal ); } else if ( n.tagName() == "widget" ) { createObject( n, w, tqlayout ); } else if ( n.tagName() == "hbox" ) { tqlayout = WidgetFactory::createLayout( w, tqlayout, WidgetFactory::HBox ); obj = TQT_TQOBJECT(tqlayout); n = n.firstChild().toElement(); continue; } else if ( n.tagName() == "grid" ) { tqlayout = WidgetFactory::createLayout( w, tqlayout, WidgetFactory::Grid ); obj = TQT_TQOBJECT(tqlayout); n = n.firstChild().toElement(); continue; } else if ( n.tagName() == "vbox" ) { tqlayout = WidgetFactory::createLayout( w, tqlayout, WidgetFactory::VBox ); obj = TQT_TQOBJECT(tqlayout); n = n.firstChild().toElement(); continue; } else if ( n.tagName() == "property" && obj ) { if ( n.attribute( "name" ) == "sizePolicy" ) { // ### Evil hack ### Delay setting sizePolicy so it won't be overridden by other properties. sizePolicyElement = n; sizePolicyObject = obj; } else { setObjectProperty( obj, n.attribute( "name" ), n.firstChild().toElement() ); } } else if ( n.tagName() == "attribute" && w ) { TQString attrib = n.attribute( "name" ); TQVariant v = DomTool::elementToVariant( n.firstChild().toElement(), TQVariant() ); if ( ::tqqt_cast(tqparent) ) { if ( attrib == "title" ) ( (TQTabWidget*)tqparent )->insertTab( w, v.toString() ); } else if ( ::tqqt_cast(tqparent) ) { if ( attrib == "id" ) ( (QDesignerWidgetStack*)tqparent )->insertPage( w, v.toInt() ); } else if ( ::tqqt_cast(tqparent) ) { if ( attrib == "label" ) ( (TQToolBox*)tqparent )->addItem( w, v.toString() ); } else if ( ::tqqt_cast(tqparent) ) { if ( attrib == "title" ) ( (TQWizard*)tqparent )->addPage( w, v.toString() ); #ifdef TQT_CONTAINER_CUSTOM_WIDGETS } else if ( isPlugin ) { if ( attrib == "label" ) { WidgetInterface *iface = 0; widgetManager()->queryInterface( parentClassName, &iface ); if ( iface ) { TQWidgetContainerInterfacePrivate *iface2 = 0; iface->queryInterface( IID_TQWidgetContainer, (TQUnknownInterface**)&iface2 ); if ( iface2 ) { iface2->insertPage( parentClassName, (TQWidget*)tqparent, v.toString(), -1, w ); iface2->release(); } iface->release(); } } #endif // TQT_CONTAINER_CUSTOM_WIDGETS } } else if ( n.tagName() == "item" ) { createItem( n, w ); } else if ( n.tagName() == "column" || n.tagName() =="row" ) { createColumn( n, w ); } n = n.nextSibling().toElement(); } // ### Evil hack ### See description above. if ( !sizePolicyElement.isNull() ) { setObjectProperty( sizePolicyObject, sizePolicyElement.attribute( "name" ), sizePolicyElement.firstChild().toElement() ); } if ( w->isWidgetType() ) widgets.insert( w->name(), w ); return TQT_TQOBJECT(w); } void Resource::createColumn( const TQDomElement &e, TQWidget *widget ) { if ( !widget ) return; if ( ::tqqt_cast(widget) && e.tagName() == "column" ) { TQListView *lv = (TQListView*)widget; TQDomElement n = e.firstChild().toElement(); TQPixmap pix; bool hasPixmap = FALSE; TQString txt; bool clickable = TRUE, resizable = TRUE; while ( !n.isNull() ) { if ( n.tagName() == "property" ) { TQString attrib = n.attribute( "name" ); TQVariant v = DomTool::elementToVariant( n.firstChild().toElement(), TQVariant() ); if ( attrib == "text" ) txt = v.toString(); else if ( attrib == "pixmap" ) { pix = loadPixmap( n.firstChild().toElement().toElement() ); hasPixmap = !pix.isNull(); } else if ( attrib == "clickable" ) clickable = v.toBool(); else if ( attrib == "resizable" ) resizable = v.toBool(); } n = n.nextSibling().toElement(); } lv->addColumn( txt ); int i = lv->header()->count() - 1; if ( hasPixmap ) { lv->header()->setLabel( i, pix, txt ); } if ( !clickable ) lv->header()->setClickEnabled( clickable, i ); if ( !resizable ) lv->header()->setResizeEnabled( resizable, i ); } #ifndef TQT_NO_TABLE else if ( ::tqqt_cast(widget) ) { TQTable *table = (TQTable*)widget; bool isRow; if ( ( isRow = e.tagName() == "row" ) ) table->setNumRows( table->numRows() + 1 ); else table->setNumCols( table->numCols() + 1 ); TQDomElement n = e.firstChild().toElement(); TQPixmap pix; bool hasPixmap = FALSE; TQString txt; TQString field; TQMap fieldMap = MetaDataBase::columnFields( TQT_TQOBJECT(table) ); while ( !n.isNull() ) { if ( n.tagName() == "property" ) { TQString attrib = n.attribute( "name" ); TQVariant v = DomTool::elementToVariant( n.firstChild().toElement(), TQVariant() ); if ( attrib == "text" ) txt = v.toString(); else if ( attrib == "pixmap" ) { hasPixmap = !n.firstChild().firstChild().toText().data().isEmpty(); if ( hasPixmap ) pix = loadPixmap( n.firstChild().toElement() ); } else if ( attrib == "field" ) field = v.toString(); } n = n.nextSibling().toElement(); } int i = isRow ? table->numRows() - 1 : table->numCols() - 1; TQHeader *h = !isRow ? table->horizontalHeader() : table->verticalHeader(); if ( hasPixmap ) h->setLabel( i, pix, txt ); else h->setLabel( i, txt ); if ( !isRow && !field.isEmpty() ) fieldMap.insert( txt, field ); MetaDataBase::setColumnFields( TQT_TQOBJECT(table), fieldMap ); } #endif } void Resource::loadItem( const TQDomElement &e, TQPixmap &pix, TQString &txt, bool &hasPixmap ) { TQDomElement n = e; hasPixmap = FALSE; while ( !n.isNull() ) { if ( n.tagName() == "property" ) { TQString attrib = n.attribute( "name" ); TQVariant v = DomTool::elementToVariant( n.firstChild().toElement(), TQVariant() ); if ( attrib == "text" ) txt = v.toString(); else if ( attrib == "pixmap" ) { pix = loadPixmap( n.firstChild().toElement() ); hasPixmap = !pix.isNull(); } } n = n.nextSibling().toElement(); } } void Resource::createItem( const TQDomElement &e, TQWidget *widget, TQListViewItem *i ) { if ( !widget || !WidgetFactory::hasItems( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( TQT_TQOBJECT(widget) ) ), TQT_TQOBJECT(widget) ) ) return; if ( ::tqqt_cast(widget) || ::tqqt_cast(widget) ) { TQDomElement n = e.firstChild().toElement(); TQPixmap pix; bool hasPixmap = FALSE; TQString txt; loadItem( n, pix, txt, hasPixmap ); TQListBox *lb = 0; if ( ::tqqt_cast(widget) ) lb = (TQListBox*)widget; else lb = ( (TQComboBox*)widget)->listBox(); if ( hasPixmap ) { new TQListBoxPixmap( lb, pix, txt ); } else { new TQListBoxText( lb, txt ); } } else if ( ::tqqt_cast(widget) ) { TQDomElement n = e.firstChild().toElement(); TQPixmap pix; bool hasPixmap = FALSE; TQString txt; loadItem( n, pix, txt, hasPixmap ); TQIconView *iv = (TQIconView*)widget; if ( hasPixmap ) new TQIconViewItem( iv, txt, pix ); else new TQIconViewItem( iv, txt ); } else if ( ::tqqt_cast(widget) ) { TQDomElement n = e.firstChild().toElement(); TQPixmap pix; TQValueList pixmaps; TQStringList textes; TQListViewItem *item = 0; TQListView *lv = (TQListView*)widget; if ( i ) item = new TQListViewItem( i, lastItem ); else item = new TQListViewItem( lv, lastItem ); while ( !n.isNull() ) { if ( n.tagName() == "property" ) { TQString attrib = n.attribute( "name" ); TQVariant v = DomTool::elementToVariant( n.firstChild().toElement(), TQVariant() ); if ( attrib == "text" ) textes << v.toString(); else if ( attrib == "pixmap" ) { TQString s = v.toString(); if ( s.isEmpty() ) { pixmaps << TQPixmap(); } else { pix = loadPixmap( n.firstChild().toElement() ); pixmaps << pix; } } } else if ( n.tagName() == "item" ) { item->setOpen( TRUE ); createItem( n, widget, item ); } n = n.nextSibling().toElement(); } for ( int i = 0; i < lv->columns(); ++i ) { item->setText( i, textes[ i ] ); item->setPixmap( i, pixmaps[ i ] ); } lastItem = item; } } TQWidget *Resource::createSpacer( const TQDomElement &e, TQWidget *tqparent, TQLayout *tqlayout, Qt::Orientation o ) { TQDomElement n = e.firstChild().toElement(); int row = e.attribute( "row" ).toInt(); int col = e.attribute( "column" ).toInt(); int rowspan = e.attribute( "rowspan" ).toInt(); int colspan = e.attribute( "colspan" ).toInt(); if ( rowspan < 1 ) rowspan = 1; if ( colspan < 1 ) colspan = 1; Spacer *spacer = (Spacer*) WidgetFactory::create( WidgetDatabase::idFromClassName("Spacer"), tqparent, "spacer", FALSE); spacer->setOrientation( o ); spacer->setInteraciveMode( FALSE ); while ( !n.isNull() ) { if ( n.tagName() == "property" ) setObjectProperty( TQT_TQOBJECT(spacer), n.attribute( "name" ), n.firstChild().toElement() ); n = n.nextSibling().toElement(); } spacer->setInteraciveMode( TRUE ); if ( formwindow ) formwindow->insertWidget( spacer, pasting ); if ( tqlayout ) { if ( ::tqqt_cast(tqlayout) ) ( (TQBoxLayout*)tqlayout )->addWidget( spacer, 0, spacer->tqalignment() ); else ( (QDesignerGridLayout*)tqlayout )->addMultiCellWidget( spacer, row, row + rowspan - 1, col, col + colspan - 1, spacer->tqalignment() ); } return spacer; } /*! Attention: this function has to be in sync with Uic::setObjectProperty(). If you change one, change both. */ void Resource::setObjectProperty( TQObject* obj, const TQString &prop, const TQDomElement &e ) { const TQMetaProperty *p = obj->tqmetaObject()->property( obj->tqmetaObject()->findProperty( prop, TRUE ), TRUE ); if ( !::tqqt_cast(obj) ) {// no layouts in metadatabase... (RS) if ( obj->inherits( "CustomWidget" ) ) { MetaDataBase::CustomWidget *cw = ( (CustomWidget*)obj )->customWidget(); if ( cw && !cw->hasProperty( prop.latin1() ) && !p && prop != "toolTip" && prop != "whatsThis" ) return; } MetaDataBase::setPropertyChanged( obj, prop, TRUE ); } TQVariant defVarient; if ( e.tagName() == "font" ) { TQFont f( tqApp->font() ); if ( obj->isWidgetType() && ( (TQWidget*)obj )->parentWidget() ) f = ( (TQWidget*)obj )->parentWidget()->font(); defVarient = TQVariant( f ); } TQString comment; TQVariant v( DomTool::elementToVariant( e, defVarient, comment ) ); if ( !comment.isEmpty() ) { MetaDataBase::addEntry( obj ); MetaDataBase::setPropertyComment( obj, prop, comment ); } if ( e.tagName() == "pixmap" ) { TQPixmap pix = loadPixmap( e ); if ( pix.isNull() ) return; v = TQVariant( pix ); } else if ( e.tagName() == "iconset" ) { TQPixmap pix = loadPixmap( e, "iconset" ); if ( pix.isNull() ) return; v = TQVariant( TQIconSet( pix ) ); } else if ( e.tagName() == "image" ) { v = TQVariant( loadFromCollection( v.toString() ) ); } if ( !p ) { MetaDataBase::setFakeProperty( obj, prop, v ); if ( obj->isWidgetType() ) { if ( prop == "database" && TQT_TQOBJECT(obj) != TQT_TQOBJECT(toplevel) ) { TQStringList lst = MetaDataBase::fakeProperty( obj, "database" ).toStringList(); if ( lst.count() > 2 ) dbControls.insert( obj->name(), lst[ 2 ] ); else if ( lst.count() == 2 ) dbTables.insert( obj->name(), lst ); } return; } } if ( e.tagName() == "palette" ) { TQDomElement n = e.firstChild().toElement(); TQPalette p; while ( !n.isNull() ) { TQColorGroup cg; if ( n.tagName() == "active" ) { cg = loadColorGroup( n ); p.setActive( cg ); } else if ( n.tagName() == "inactive" ) { cg = loadColorGroup( n ); p.setInactive( cg ); } else if ( n.tagName() == "disabled" ) { cg = loadColorGroup( n ); p.setDisabled( cg ); } n = n.nextSibling().toElement(); } v = TQPalette( p ); } else if ( e.tagName() == "enum" && p && p->isEnumType() && prop != "resizeMode" ) { TQString key( v.toString() ); int vi = p->keyToValue( key ); if ( p->valueToKey( vi ) != key ) return; // ignore invalid properties v = TQVariant( vi ); } else if ( e.tagName() == "set" && p && p->isSetType() ) { TQString keys( v.toString() ); TQStringList lst = TQStringList::split( '|', keys ); TQStrList l; for ( TQStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) l.append( *it ); v = TQVariant( p->keysToValue( l ) ); } if ( prop == "caption" ) { TQCString s1 = v.toCString(); TQString s2 = v.toString(); if ( !s2.isEmpty() ) formwindow->setCaption( s2 ); else if ( !s1.isEmpty() ) formwindow->setCaption( s1 ); } if ( prop == "icon" ) { formwindow->setIcon( v.toPixmap() ); TQString pmk = MetaDataBase::pixmapKey( TQT_TQOBJECT(formwindow), v.toPixmap().serialNumber() ); MetaDataBase::setPixmapKey( TQT_TQOBJECT(formwindow), formwindow->icon()->serialNumber(), pmk ); } if ( prop == "geometry" ) { if ( TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(toplevel) ) { hadGeometry = TRUE; toplevel->resize( v.toRect().size() ); return; } else if ( TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(formwindow->mainContainer()) ) { hadGeometry = TRUE; formwindow->resize( v.toRect().size() ); return; } } if ( ::tqqt_cast(obj) ) { if ( prop == "spacing" ) { MetaDataBase::setSpacing( TQT_TQOBJECT( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (TQLayout*)(obj) ) ) ), v.toInt() ); return; } else if ( prop == "margin" ) { MetaDataBase::setMargin( TQT_TQOBJECT( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (TQLayout*)(obj) ) ) ), v.toInt() ); return; } else if ( e.tagName() == "enum" && prop == "resizeMode" ) { MetaDataBase::setResizeMode( TQT_TQOBJECT( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (TQLayout*)(obj) ) ) ), v.toString() ); return; } } if ( prop == "name" ) { if ( pasting ) { TQString s = v.toString(); formwindow->unify( TQT_TQOBJECT(obj), s, TRUE ); obj->setName( s ); return; } else if ( formwindow && TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(formwindow->mainContainer()) ) { formwindow->setName( v.toCString() ); } } if ( prop == "sizePolicy" ) { TQSizePolicy sp = v.toSizePolicy(); sp.setHeightForWidth( ( (TQWidget*)obj )->sizePolicy().hasHeightForWidth() ); } if ( prop == "cursor" ) MetaDataBase::setCursor( (TQWidget*)obj, v.toCursor() ); obj->setProperty( prop, v ); } TQString Resource::saveInCollection( const TQImage &img ) { TQString imgName = "none"; TQValueList::Iterator it = images.begin(); for ( ; it != images.end(); ++it ) { if ( img == ( *it ).img ) { imgName = ( *it ).name; break; } } if ( imgName == "none" ) { Image i; imgName = "image" + TQString::number( images.count() ); i.name = imgName; i.img = img; images.append( i ); } return imgName; } void Resource::saveImageData( const TQImage &img, TQTextStream &ts, int indent ) { TQByteArray ba; TQBuffer buf( ba ); buf.open( IO_WriteOnly | IO_Translate ); TQString format; bool compress = FALSE; if (img.hasAlphaBuffer()) { format = "PNG"; } else { format = img.depth() > 1 ? "XPM" : "XBM"; compress = TRUE; } TQImageIO iio( &buf, format ); iio.setImage( img ); iio.write(); buf.close(); TQByteArray bazip = ba; int i = 0; if (compress) { bazip = tqCompress( ba ); format += ".GZ"; // The first 4 bytes in tqCompress() are the length of the unzipped // format. The XPM.GZ format does not use these. i = 4; } ulong len = bazip.size(); ts << makeIndent( indent ) << ""; static const char hexchars[] = "0123456789abcdef"; for (; i < (int)len; ++i ) { uchar s = (uchar) bazip[i]; ts << hexchars[s >> 4]; ts << hexchars[s & 0x0f]; } ts << "" << endl; } void Resource::saveImageCollection( TQTextStream &ts, int indent ) { ts << makeIndent( indent ) << "" << endl; indent++; TQValueList::Iterator it = images.begin(); for ( ; it != images.end(); ++it ) { ts << makeIndent( indent ) << "" << endl; indent++; saveImageData( (*it).img, ts, indent ); indent--; ts << makeIndent( indent ) << "" << endl; } indent--; ts << makeIndent( indent ) << "" << endl; } static TQImage loadImageData( TQDomElement &n2 ) { TQImage img; TQString data = n2.firstChild().toText().data(); const int lengthOffset = 4; int baSize = data.length() / 2 + lengthOffset; uchar *ba = new uchar[ baSize ]; for ( int i = lengthOffset; i < baSize; ++i ) { char h = data[ 2 * (i-lengthOffset) ].latin1(); char l = data[ 2 * (i-lengthOffset) + 1 ].latin1(); uchar r = 0; if ( h <= '9' ) r += h - '0'; else r += h - 'a' + 10; r = r << 4; if ( l <= '9' ) r += l - '0'; else r += l - 'a' + 10; ba[ i ] = r; } TQString format = n2.attribute( "format", "PNG" ); if ( format == "XPM.GZ" || format == "XBM.GZ" ) { ulong len = n2.attribute( "length" ).toULong(); if ( len < data.length() * 5 ) len = data.length() * 5; // tqUncompress() expects the first 4 bytes to be the expected length of // the uncompressed data ba[0] = ( len & 0xff000000 ) >> 24; ba[1] = ( len & 0x00ff0000 ) >> 16; ba[2] = ( len & 0x0000ff00 ) >> 8; ba[3] = ( len & 0x000000ff ); TQByteArray baunzip = tqUncompress( ba, baSize ); img.loadFromData( (const uchar*)baunzip.data(), baunzip.size(), format.left(format.find('.')) ); } else { img.loadFromData( (const uchar*)ba+lengthOffset, baSize-lengthOffset, format ); } delete [] ba; return img; } void Resource::loadImageCollection( const TQDomElement &e ) { TQDomElement n = e.firstChild().toElement(); while ( !n.isNull() ) { if ( n.tagName() == "image" ) { Image img; img.name = n.attribute( "name" ); TQDomElement n2 = n.firstChild().toElement(); while ( !n2.isNull() ) { if ( n2.tagName() == "data" ) img.img = loadImageData( n2 ); n2 = n2.nextSibling().toElement(); } images.append( img ); n = n.nextSibling().toElement(); } } } TQImage Resource::loadFromCollection( const TQString &name ) { TQValueList::Iterator it = images.begin(); for ( ; it != images.end(); ++it ) { if ( ( *it ).name == name ) return ( *it ).img; } return TQImage(); } void Resource::saveConnections( TQTextStream &ts, int indent ) { TQValueList connections = MetaDataBase::connections( TQT_TQOBJECT(formwindow) ); if ( connections.isEmpty() ) return; ts << makeIndent( indent ) << "" << endl; indent++; TQValueList::Iterator it = connections.begin(); for ( ; it != connections.end(); ++it ) { MetaDataBase::Connection conn = *it; if ( ( knownNames.findIndex( TQString( conn.sender->name() ) ) == -1 && qstrcmp( conn.sender->name(), "this" ) != 0 ) || ( knownNames.findIndex( TQString( conn.receiver->name() ) ) == -1 && qstrcmp( conn.receiver->name(), "this" ) != 0 ) ) continue; if ( formwindow->isMainContainer( TQT_TQOBJECT((*it).receiver) ) && !MetaDataBase::hasSlot( TQT_TQOBJECT(formwindow), MetaDataBase::normalizeFunction( (*it).slot ).latin1() ) ) continue; if ( conn.sender->inherits( "CustomWidget" ) ) { MetaDataBase::CustomWidget *cw = ( (CustomWidget*)conn.sender )->customWidget(); if ( cw && !cw->hasSignal( conn.signal ) ) continue; } if ( conn.receiver->inherits( "CustomWidget" ) && !formwindow->isMainContainer( conn.receiver ) ) { MetaDataBase::CustomWidget *cw = ( (CustomWidget*)conn.receiver )->customWidget(); if ( cw && !cw->hasSlot( MetaDataBase::normalizeFunction( conn.slot ).latin1() ) ) continue; } ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << entitize( conn.sender->name() ) << "" << endl; ts << makeIndent( indent ) << "" << entitize( conn.signal ) << "" << endl; ts << makeIndent( indent ) << "" << entitize( conn.receiver->name() ) << "" << endl; ts << makeIndent( indent ) << "" << entitize( MetaDataBase::normalizeFunction( conn.slot ) ) << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; } TQString lang = formwindow->project()->language(); indent--; ts << makeIndent( indent ) << "" << endl; } void Resource::loadConnections( const TQDomElement &e ) { TQDomElement n = e.firstChild().toElement(); while ( !n.isNull() ) { if ( n.tagName() == "connection" ) { TQString lang = n.attribute( "language", "C++" ); TQDomElement n2 = n.firstChild().toElement(); MetaDataBase::Connection conn; while ( !n2.isNull() ) { if ( n2.tagName() == "sender" ) { conn.sender = 0; TQString name = n2.firstChild().toText().data(); if ( name == "this" || qstrcmp( toplevel->name(), name ) == 0 ) { conn.sender = TQT_TQOBJECT(toplevel); } else { if ( name == "this" ) name = toplevel->name(); TQObjectList *l = toplevel->queryList( 0, name, FALSE ); if ( l ) { if ( l->first() ) conn.sender = l->first(); delete l; l = 0; } if ( !conn.sender ) conn.sender = formwindow->findAction( name ); } } else if ( n2.tagName() == "signal" ) { conn.signal = n2.firstChild().toText().data(); } else if ( n2.tagName() == "receiver" ) { conn.receiver = 0; TQString name = n2.firstChild().toText().data(); if ( name == "this" || qstrcmp( toplevel->name(), name ) == 0 ) { conn.receiver = TQT_TQOBJECT(toplevel); } else { TQObjectList *l = toplevel->queryList( 0, name, FALSE ); if ( l ) { if ( l->first() ) conn.receiver = l->first(); delete l; l = 0; } if ( !conn.receiver ) conn.receiver = formwindow->findAction( name ); } } else if ( n2.tagName() == "slot" ) { conn.slot = n2.firstChild().toText().data(); } n2 = n2.nextSibling().toElement(); } if ( formwindow ) { if ( TQT_BASE_OBJECT(conn.sender) == TQT_BASE_OBJECT(formwindow) ) conn.sender = TQT_TQOBJECT(formwindow->mainContainer()); if ( TQT_BASE_OBJECT(conn.receiver) == TQT_BASE_OBJECT(formwindow) ) conn.receiver = TQT_TQOBJECT(formwindow->mainContainer()); } if ( conn.sender && conn.receiver ) { if ( lang == "C++" ) { MetaDataBase::addConnection( TQT_TQOBJECT(formwindow ? formwindow : toplevel), conn.sender, conn.signal, conn.receiver, conn.slot ); } } } else if ( n.tagName() == "slot" ) { // compatibility with 2.x MetaDataBase::Function slot; slot.specifier = n.attribute( "specifier", "virtual" ); if ( slot.specifier.isEmpty() ) slot.specifier = "virtual"; slot.access = n.attribute( "access", "public" ); if ( slot.access.isEmpty() ) slot.access = "public"; slot.language = n.attribute( "language", "C++" ); slot.returnType = n.attribute( "returnType", "void" ); if ( slot.returnType.isEmpty() ) slot.returnType = "void"; slot.function = n.firstChild().toText().data(); if ( !MetaDataBase::hasFunction( TQT_TQOBJECT(formwindow), slot.function, TRUE ) ) MetaDataBase::addFunction( TQT_TQOBJECT(formwindow), slot.function, slot.specifier, slot.access, "slot", slot.language, slot.returnType ); else MetaDataBase::changeFunctionAttributes( TQT_TQOBJECT(formwindow), slot.function, slot.function, slot.specifier, slot.access, "slot", slot.language, slot.returnType ); } n = n.nextSibling().toElement(); } } void Resource::saveCustomWidgets( TQTextStream &ts, int indent ) { ts << makeIndent( indent ) << "" << endl; indent++; TQPtrList *lst = MetaDataBase::customWidgets(); for ( MetaDataBase::CustomWidget *w = lst->first(); w; w = lst->next() ) { if ( usedCustomWidgets.findIndex( w->className ) == -1 ) continue; ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << w->className << "" << endl; ts << makeIndent( indent ) << "
includePolicy == MetaDataBase::CustomWidget::Local ? "local" : "global" ) << "\">" << w->includeFile << "
" << endl; ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << w->tqsizeHint.width() << "" << endl; ts << makeIndent( indent ) << "" << w->tqsizeHint.height() << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; ts << makeIndent( indent ) << "" << (int)w->isContainer << "" << endl; ts << makeIndent( indent ) << "" << endl; indent++; ts << makeIndent( indent ) << "" << (int)w->sizePolicy.horData() << "" << endl; ts << makeIndent( indent ) << "" << (int)w->sizePolicy.verData() << "" << endl; ts << makeIndent( indent ) << "" << (int)w->sizePolicy.horStretch() << "" << endl; ts << makeIndent( indent ) << "" << (int)w->sizePolicy.verStretch() << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; ts << makeIndent( indent ) << "" << saveInCollection( w->pixmap->convertToImage() ) << "" << endl; if ( !w->lstSignals.isEmpty() ) { for ( TQValueList::Iterator it = w->lstSignals.begin(); it != w->lstSignals.end(); ++it ) ts << makeIndent( indent ) << "" << entitize( *it ) << "" << endl; } if ( !w->lstSlots.isEmpty() ) { for ( TQValueList::Iterator it = w->lstSlots.begin(); it != w->lstSlots.end(); ++it ) ts << makeIndent( indent ) << "" << entitize( (*it).function ) << "" << endl; } if ( !w->lstProperties.isEmpty() ) { for ( TQValueList::Iterator it = w->lstProperties.begin(); it != w->lstProperties.end(); ++it ) ts << makeIndent( indent ) << "" << entitize( (*it).property ) << "" << endl; } indent--; ts << makeIndent( indent ) << "
" << endl; } indent--; ts << makeIndent( indent ) << "
" << endl; } void Resource::loadCustomWidgets( const TQDomElement &e, Resource *r ) { TQDomElement n = e.firstChild().toElement(); while ( !n.isNull() ) { if ( n.tagName() == "customwidget" ) { TQDomElement n2 = n.firstChild().toElement(); MetaDataBase::CustomWidget *w = new MetaDataBase::CustomWidget; while ( !n2.isNull() ) { if ( n2.tagName() == "class" ) { w->className = n2.firstChild().toText().data(); } else if ( n2.tagName() == "header" ) { w->includeFile = n2.firstChild().toText().data(); TQString s = n2.attribute( "location" ); if ( s != "local" ) w->includePolicy = MetaDataBase::CustomWidget::Global; else w->includePolicy = MetaDataBase::CustomWidget::Local; } else if ( n2.tagName() == "sizehint" ) { TQDomElement n3 = n2.firstChild().toElement(); while ( !n3.isNull() ) { if ( n3.tagName() == "width" ) w->tqsizeHint.setWidth( n3.firstChild().toText().data().toInt() ); else if ( n3.tagName() == "height" ) w->tqsizeHint.setHeight( n3.firstChild().toText().data().toInt() ); n3 = n3.nextSibling().toElement(); } } else if ( n2.tagName() == "sizepolicy" ) { TQDomElement n3 = n2.firstChild().toElement(); while ( !n3.isNull() ) { if ( n3.tagName() == "hordata" ) w->sizePolicy.setHorData( (TQSizePolicy::SizeType)n3.firstChild().toText().data().toInt() ); else if ( n3.tagName() == "verdata" ) w->sizePolicy.setVerData( (TQSizePolicy::SizeType)n3.firstChild().toText().data().toInt() ); else if ( n3.tagName() == "horstretch" ) w->sizePolicy.setHorStretch( n3.firstChild().toText().data().toInt() ); else if ( n3.tagName() == "verstretch" ) w->sizePolicy.setVerStretch( n3.firstChild().toText().data().toInt() ); n3 = n3.nextSibling().toElement(); } } else if ( n2.tagName() == "pixmap" ) { TQPixmap pix; if ( r ) { pix = r->loadPixmap( n2 ); } else { TQDomElement n3 = n2.firstChild().toElement(); TQImage img; while ( !n3.isNull() ) { if ( n3.tagName() == "data" ) { img = loadImageData( n3 ); } n3 = n3.nextSibling().toElement(); } pix.convertFromImage( img ); } w->pixmap = new TQPixmap( pix ); } else if ( n2.tagName() == "signal" ) { w->lstSignals.append( n2.firstChild().toText().data().latin1() ); } else if ( n2.tagName() == "container" ) { w->isContainer = (bool)n2.firstChild().toText().data().toInt(); } else if ( n2.tagName() == "slot" ) { MetaDataBase::Function function; function.function = n2.firstChild().toText().data().latin1(); function.access = n2.attribute( "access" ); function.type = "slot"; w->lstSlots.append( function ); } else if ( n2.tagName() == "property" ) { MetaDataBase::Property property; property.property = n2.firstChild().toText().data().latin1(); property.type = n2.attribute( "type" ); w->lstProperties.append( property ); } n2 = n2.nextSibling().toElement(); } MetaDataBase::addCustomWidget( w ); } n = n.nextSibling().toElement(); } } void Resource::saveTabOrder( TQTextStream &ts, int indent ) { TQWidgetList l = MetaDataBase::tabOrder( toplevel ); if ( l.isEmpty() ) return; ts << makeIndent( indent ) << "" << endl; indent++; for ( TQWidget *w = l.first(); w; w = l.next() ) { if ( w->testWState( TQt::WState_ForceHide ) || knownNames.findIndex( w->name() ) == -1 ) continue; ts << makeIndent( indent ) << "" << w->name() << "" << endl; } indent--; ts << makeIndent( indent ) << "" << endl; } void Resource::loadTabOrder( const TQDomElement &e ) { TQWidget *last = 0; TQDomElement n = e.firstChild().toElement(); TQWidgetList widgets; while ( !n.isNull() ) { if ( n.tagName() == "tabstop" ) { TQString name = n.firstChild().toText().data(); if ( name.isEmpty() ) continue; TQObjectList *l = toplevel->queryList( 0, name, FALSE ); if ( l ) { if ( l->first() ) { TQWidget *w = (TQWidget*)l->first(); widgets.append( w ); if ( last ) toplevel->setTabOrder( last, w ); last = w; } delete l; } } n = n.nextSibling().toElement(); } if ( !widgets.isEmpty() ) MetaDataBase::setTabOrder( toplevel, widgets ); } void Resource::saveMetaInfoBefore( TQTextStream &ts, int indent ) { MetaDataBase::MetaInfo info = MetaDataBase::metaInfo( TQT_TQOBJECT(formwindow) ); TQString cn; if ( info.classNameChanged && !info.className.isEmpty() ) cn = info.className; else cn = formwindow->name(); ts << makeIndent( indent ) << "" << entitize( cn ) << "" << endl; if ( !info.comment.isEmpty() ) ts << makeIndent( indent ) << "" << entitize( info.comment ) << "" << endl; if ( !info.author.isEmpty() ) ts << makeIndent( indent ) << "" << entitize( info.author ) << "" << endl; } void Resource::saveMetaInfoAfter( TQTextStream &ts, int indent ) { MetaDataBase::MetaInfo info = MetaDataBase::metaInfo( TQT_TQOBJECT(formwindow) ); if ( !langIface || formwindow->project()->isCpp() ) { TQValueList includes = MetaDataBase::includes( TQT_TQOBJECT(formwindow) ); TQString extensionInclude; bool needExtensionInclude = FALSE; if ( langIface && formwindow->formFile()->hasFormCode() && formwindow->formFile()->codeFileState() != FormFile::Deleted ) { extensionInclude = TQFileInfo( currFileName ).fileName() + langIface->formCodeExtension(); needExtensionInclude = TRUE; } if ( !includes.isEmpty() || needExtensionInclude ) { ts << makeIndent( indent ) << "" << endl; indent++; for ( TQValueList::Iterator it = includes.begin(); it != includes.end(); ++it ) { ts << makeIndent( indent ) << "" << (*it).header << "" << endl; if ( needExtensionInclude ) needExtensionInclude = (*it).header != extensionInclude; } if ( needExtensionInclude ) ts << makeIndent( indent ) << "" << extensionInclude << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; } TQStringList forwards = MetaDataBase::forwards( TQT_TQOBJECT(formwindow) ); if ( !forwards.isEmpty() ) { ts << makeIndent( indent ) << "" << endl; indent++; for ( TQStringList::Iterator it2 = forwards.begin(); it2 != forwards.end(); ++it2 ) ts << makeIndent( indent ) << "" << entitize( *it2 ) << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; } TQValueList varLst = MetaDataBase::variables( TQT_TQOBJECT(formwindow) ); if ( !varLst.isEmpty() ) { ts << makeIndent( indent ) << "" << endl; indent++; TQValueList::Iterator it = varLst.begin(); for ( ; it != varLst.end(); ++it ) { ts << makeIndent( indent ) << "" << entitize( (*it).varName ) << "" << endl; } indent--; ts << makeIndent( indent ) << "" << endl; } TQStringList sigs = MetaDataBase::signalList( TQT_TQOBJECT(formwindow) ); if ( !sigs.isEmpty() ) { ts << makeIndent( indent ) << "" << endl; indent++; for ( TQStringList::Iterator it3 = sigs.begin(); it3 != sigs.end(); ++it3 ) ts << makeIndent( indent ) << "" << entitize( *it3 ) << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; } TQValueList slotList = MetaDataBase::slotList( TQT_TQOBJECT(formwindow) ); if ( !slotList.isEmpty() ) { ts << makeIndent( indent ) << "" << endl; indent++; TQString lang = formwindow->project()->language(); TQValueList::Iterator it = slotList.begin(); for ( ; it != slotList.end(); ++it ) { MetaDataBase::Function function = *it; ts << makeIndent( indent ) << "" << entitize( function.function ) << "" << endl; } indent--; ts << makeIndent( indent ) << "" << endl; } TQValueList functionList = MetaDataBase::functionList( TQT_TQOBJECT(formwindow), TRUE ); if ( !functionList.isEmpty() ) { ts << makeIndent( indent ) << "" << endl; indent++; TQString lang = formwindow->project()->language(); TQValueList::Iterator it = functionList.begin(); for ( ; it != functionList.end(); ++it ) { MetaDataBase::Function function = *it; ts << makeIndent( indent ) << "" << entitize( function.function ) << "" << endl; } indent--; ts << makeIndent( indent ) << "" << endl; } } if ( formwindow && formwindow->savePixmapInline() ) ; else if ( formwindow && formwindow->savePixmapInProject() ) ts << makeIndent( indent ) << "" << endl; else ts << makeIndent( indent ) << "" << formwindow->pixmapLoaderFunction() << "" << endl; if ( !( exportMacro = MetaDataBase::exportMacro( TQT_TQOBJECT(formwindow->mainContainer()) ) ).isEmpty() ) ts << makeIndent( indent ) << "" << exportMacro << "" << endl; if ( formwindow ) { ts << makeIndent( indent ) << "layoutDefaultSpacing() << "\" margin=\"" << formwindow->layoutDefaultMargin() << "\"/>" << endl; if ( formwindow->hasLayoutFunctions() ) { TQString s = ""; TQString m = ""; if ( !formwindow->spacingFunction().isEmpty() ) s = TQString( " spacing=\"%1\"" ).tqarg( formwindow->spacingFunction() ); if ( !formwindow->marginFunction().isEmpty() ) m = TQString( " margin=\"%1\"" ).tqarg( formwindow->marginFunction() ); ts << makeIndent( indent ) << "" << endl; } } } void Resource::saveIncludeHints( TQTextStream &ts, int indent ) { if ( includeHints.isEmpty() ) return; ts << makeIndent( indent ) << "" << endl; indent++; for ( TQStringList::Iterator it = includeHints.begin(); it != includeHints.end(); ++it ) ts << makeIndent( indent ) << "" << *it << "" << endl; indent--; ts << makeIndent( indent ) << "" << endl; } TQColorGroup Resource::loadColorGroup( const TQDomElement &e ) { TQColorGroup cg; int r = -1; TQDomElement n = e.firstChild().toElement(); TQColor col; while ( !n.isNull() ) { if ( n.tagName() == "color" ) { r++; cg.setColor( (TQColorGroup::ColorRole)r, (col = DomTool::readColor( n ) ) ); } else if ( n.tagName() == "pixmap" ) { TQPixmap pix = loadPixmap( n ); cg.setBrush( (TQColorGroup::ColorRole)r, TQBrush( col, pix ) ); } n = n.nextSibling().toElement(); } return cg; } void Resource::saveChildActions( TQAction *a, TQTextStream &ts, int indent ) { TQObjectList clo = a->childrenListObject(); if ( clo.isEmpty() ) return; TQObjectListIt it( clo ); while ( it.current() ) { TQObject *o = it.current(); ++it; if ( !::tqqt_cast(o) ) continue; TQAction *ac = (TQAction*)o; bool isGroup = ::tqqt_cast(ac); if ( isGroup ) ts << makeIndent( indent ) << "" << endl; else ts << makeIndent( indent ) << "" << endl; indent++; saveObjectProperties( ac, ts, indent ); indent--; if ( isGroup ) { indent++; saveChildActions( ac, ts, indent ); indent--; } if ( isGroup ) ts << makeIndent( indent ) << "" << endl; else ts << makeIndent( indent ) << "" << endl; } } void Resource::saveActions( const TQPtrList &actions, TQTextStream &ts, int indent ) { if ( actions.isEmpty() ) return; ts << makeIndent( indent ) << "" << endl; indent++; TQPtrListIterator it( actions ); while ( it.current() ) { TQAction *a = it.current(); bool isGroup = ::tqqt_cast(a); if ( isGroup ) ts << makeIndent( indent ) << "" << endl; else ts << makeIndent( indent ) << "" << endl; indent++; saveObjectProperties( a, ts, indent ); indent--; if ( isGroup ) { indent++; saveChildActions( a, ts, indent ); indent--; } if ( isGroup ) ts << makeIndent( indent ) << "" << endl; else ts << makeIndent( indent ) << "" << endl; ++it; } indent--; ts << makeIndent( indent ) << "" << endl; } void Resource::loadChildAction( TQObject *tqparent, const TQDomElement &e ) { TQDomElement n = e; TQAction *a = 0; if ( n.tagName() == "action" ) { a = new QDesignerAction( tqparent ); MetaDataBase::addEntry( a ); TQDomElement n2 = n.firstChild().toElement(); bool hasMenuText = FALSE; while ( !n2.isNull() ) { if ( n2.tagName() == "property" ) { TQDomElement n3(n2); // don't modify n2 TQString prop = n3.attribute( "name" ); if (prop == "menuText") hasMenuText = TRUE; TQDomElement value(n3.firstChild().toElement()); setObjectProperty( a, prop, value ); if (!hasMenuText && uiFileVersion < "3.3" && prop == "text") setObjectProperty( a, "menuText", value ); } n2 = n2.nextSibling().toElement(); } if ( !::tqqt_cast(tqparent) ) formwindow->actionList().append( a ); } else if ( n.tagName() == "actiongroup" ) { a = new QDesignerActionGroup( tqparent ); MetaDataBase::addEntry( a ); TQDomElement n2 = n.firstChild().toElement(); bool hasMenuText = FALSE; while ( !n2.isNull() ) { if ( n2.tagName() == "property" ) { TQDomElement n3(n2); // don't modify n2 TQString prop = n3.attribute( "name" ); if (prop == "menuText") hasMenuText = TRUE; TQDomElement value = n3.firstChild().toElement(); setObjectProperty( a, prop, value ); if (!hasMenuText && uiFileVersion < "3.3" && prop == "text") setObjectProperty( a, "menuText", value ); } else if ( n2.tagName() == "action" || n2.tagName() == "actiongroup" ) { loadChildAction( a, n2 ); } n2 = n2.nextSibling().toElement(); } if ( !::tqqt_cast(tqparent) ) formwindow->actionList().append( a ); } } void Resource::loadActions( const TQDomElement &e ) { TQDomElement n = e.firstChild().toElement(); while ( !n.isNull() ) { if ( n.tagName() == "action" ) { loadChildAction( TQT_TQOBJECT(formwindow), n ); } else if ( n.tagName() == "actiongroup" ) { loadChildAction( TQT_TQOBJECT(formwindow), n ); } n = n.nextSibling().toElement(); } } void Resource::saveToolBars( TQMainWindow *mw, TQTextStream &ts, int indent ) { ts << makeIndent( indent ) << "" << endl; indent++; TQPtrList tbList; for ( int i = 0; i <= (int)TQt::DockMinimized; ++i ) { tbList = mw->toolBars( (TQt::Dock)i ); if ( tbList.isEmpty() ) continue; for ( TQToolBar *tb = tbList.first(); tb; tb = tbList.next() ) { if ( tb->isHidden() ) continue; ts << makeIndent( indent ) << "" << endl; indent++; saveObjectProperties( TQT_TQOBJECT(tb), ts, indent ); TQPtrList actionList = ( (QDesignerToolBar*)tb )->insertedActions(); for ( TQAction *a = actionList.first(); a; a = actionList.next() ) { if ( ::tqqt_cast(a) ) { ts << makeIndent( indent ) << "" << endl; } else { if ( ::tqqt_cast(a) && !( (QDesignerAction*)a )->supportsMenu() ) { TQWidget *w = ( (QDesignerAction*)a )->widget(); ts << makeIndent( indent ) << "" << endl; indent++; const char *className = WidgetFactory::classNameOf( TQT_TQOBJECT(w) ); if ( w->isA( "CustomWidget" ) ) usedCustomWidgets << TQString( className ); if ( WidgetFactory::hasItems( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( TQT_TQOBJECT(w) ) ), TQT_TQOBJECT(w) ) ) saveItems( TQT_TQOBJECT(w), ts, indent ); saveObjectProperties( TQT_TQOBJECT(w), ts, indent ); indent--; ts << makeIndent( indent ) << "" << endl; } else { ts << makeIndent( indent ) << "name() << "\"/>" << endl; } } } indent--; ts << makeIndent( indent ) << "" << endl; } } indent--; ts << makeIndent( indent ) << "" << endl; } void Resource::saveMenuBar( TQMainWindow *mw, TQTextStream &ts, int indent ) { MenuBarEditor *mb = (MenuBarEditor *)mw->child( 0, "MenuBarEditor" ); if ( !mb ) return; ts << makeIndent( indent ) << "" << endl; indent++; MetaDataBase::setPropertyChanged( TQT_TQOBJECT(mb), "name", TRUE ); // FIXME: remove saveObjectProperties( TQT_TQOBJECT(mb), ts, indent ); for ( int i = 0; i < (int)mb->count(); ++i ) { MenuBarEditorItem *m = mb->item( i ); if ( !m ) continue; if ( m->isSeparator() ) { ts << makeIndent( indent ) << "" << endl; } else { ts << makeIndent( indent ) << "menuText() ) << "\" name=\"" << entitize( m->menu()->name() ) << "\">" << endl; indent++; savePopupMenu( m->menu(), mw, ts, indent ); indent--; ts << makeIndent( indent ) << "" << endl; } } indent--; ts << makeIndent( indent ) << "" << endl; } void Resource::savePopupMenu( PopupMenuEditor *pm, TQMainWindow *mw, TQTextStream &ts, int indent ) { for ( PopupMenuEditorItem *i = pm->items()->first(); i; i = pm->items()->next() ) { TQAction *a = i->action(); if ( ::tqqt_cast(a) ) ts << makeIndent( indent ) << "" << endl; else if ( ::tqqt_cast(a) ) ts << makeIndent( indent ) << "name() << "\"/>" << endl; else if ( ::tqqt_cast(a) ) ts << makeIndent( indent ) << "name() << "\"/>" << endl; PopupMenuEditor *s = i->subMenu(); if ( s && s->count() ) { TQString n = s->name(); ts << makeIndent( indent ) << "menuText() ) << "\" name=\"" << entitize( n ) << "\" accel=\"" << entitize( a->accel() ) << "\">" << endl; indent++; savePopupMenu( s, mw, ts, indent ); indent--; ts << makeIndent( indent ) << "" << endl; } } } void Resource::loadToolBars( const TQDomElement &e ) { TQDomElement n = e.firstChild().toElement(); TQMainWindow *mw = ( (TQMainWindow*)formwindow->mainContainer() ); QDesignerToolBar *tb = 0; while ( !n.isNull() ) { if ( n.tagName() == "toolbar" ) { TQt::Dock dock = (TQt::Dock)n.attribute( "dock" ).toInt(); tb = new QDesignerToolBar( mw, dock ); TQDomElement n2 = n.firstChild().toElement(); while ( !n2.isNull() ) { if ( n2.tagName() == "action" ) { TQAction *a = formwindow->findAction( n2.attribute( "name" ) ); if ( a ) { a->addTo( tb ); tb->addAction( a ); } } else if ( n2.tagName() == "separator" ) { TQAction *a = new QSeparatorAction( 0 ); a->addTo( tb ); tb->addAction( a ); } else if ( n2.tagName() == "widget" ) { TQWidget *w = (TQWidget*)createObject( n2, tb ); QDesignerAction *a = new QDesignerAction( w, TQT_TQOBJECT(tb) ); a->addTo( tb ); tb->addAction( a ); tb->installEventFilters( w ); } else if ( n2.tagName() == "property" ) { setObjectProperty( TQT_TQOBJECT(tb), n2.attribute( "name" ), n2.firstChild().toElement() ); } n2 = n2.nextSibling().toElement(); } } n = n.nextSibling().toElement(); } } void Resource::loadMenuBar( const TQDomElement &e ) { TQDomElement n = e.firstChild().toElement(); TQMainWindow *mw = (TQMainWindow*)formwindow->mainContainer(); MenuBarEditor *mb = new MenuBarEditor( formwindow, mw ); MetaDataBase::addEntry( TQT_TQOBJECT(mb) ); while ( !n.isNull() ) { if ( n.tagName() == "item" ) { PopupMenuEditor * popup = new PopupMenuEditor( formwindow, mw ); loadPopupMenu( popup, n ); popup->setName( n.attribute( "name" ) ); mb->insertItem( n.attribute( "text" ), popup ); MetaDataBase::addEntry( TQT_TQOBJECT(popup) ); } else if ( n.tagName() == "property" ) { setObjectProperty( TQT_TQOBJECT(mb), n.attribute( "name" ), n.firstChild().toElement() ); } else if ( n.tagName() == "separator" ) { mb->insertSeparator(); } n = n.nextSibling().toElement(); } } void Resource::loadPopupMenu( PopupMenuEditor *p, const TQDomElement &e ) { MetaDataBase::addEntry( TQT_TQOBJECT(p) ); TQDomElement n = e.firstChild().toElement(); TQAction *a = 0; while ( !n.isNull() ) { if ( n.tagName() == "action" || n.tagName() == "actiongroup") { a = formwindow->findAction( n.attribute( "name" ) ); if ( a ) p->insert( a ); } if ( n.tagName() == "item" ) { PopupMenuEditorItem *i = p->at( p->find( a ) ); if ( i ) { TQString name = n.attribute( "name" ); formwindow->unify( i, name, TRUE ); i->setName( name ); MetaDataBase::addEntry( i ); loadPopupMenu( i->subMenu(), n ); } } else if ( n.tagName() == "separator" ) { a = new QSeparatorAction( 0 ); p->insert( a ); } n = n.nextSibling().toElement(); } } bool Resource::saveFormCode( FormFile *formfile, LanguageInterface * /*langIface*/ ) { TQString lang = formfile->project()->language(); if ( formfile->hasTempFileName() || formfile->code().isEmpty() || !formfile->hasFormCode() || !formfile->isModified(FormFile::WFormCode) ) return TRUE; // There is no code to be saved. return saveCode( formfile->project()->makeAbsolute(formfile->codeFile()), formfile->code() ); } void Resource::loadExtraSource( FormFile *formfile, const TQString &currFileName, LanguageInterface *langIface, bool hasFunctions ) { TQString lang = "TQt Script"; if ( MainWindow::self ) lang = MainWindow::self->currProject()->language(); LanguageInterface *iface = langIface; if ( hasFunctions || !iface ) return; TQValueList functions; TQStringList forwards; TQStringList includesImpl; TQStringList includesDecl; TQStringList vars; TQValueList connections; iface->loadFormCode( formfile->formName(), currFileName + iface->formCodeExtension(), functions, vars, connections ); TQFile f( formfile->project()->makeAbsolute( formfile->codeFile() ) ); TQString code; if ( f.open( IO_ReadOnly ) ) { TQTextStream ts( &f ); code = ts.read(); } formfile->setCode( code ); if ( !MainWindow::self || !MainWindow::self->currProject()->isCpp() ) MetaDataBase::setupConnections( formfile, connections ); for ( TQValueList::Iterator fit = functions.begin(); fit != functions.end(); ++fit ) { if ( MetaDataBase::hasFunction( formfile->formWindow() ? (TQObject*)formfile->formWindow() : (TQObject*)formfile, (*fit).name.latin1() ) ) { TQString access = (*fit).access; if ( !MainWindow::self || !MainWindow::self->currProject()->isCpp() ) MetaDataBase::changeFunction( formfile->formWindow() ? (TQObject*)formfile->formWindow() : (TQObject*)formfile, (*fit).name, (*fit).name, TQString() ); } else { TQString access = (*fit).access; if ( access.isEmpty() ) access = "protected"; TQString type = "function"; if ( (*fit).returnType == "void" ) type = "slot"; MetaDataBase::addFunction( formfile->formWindow() ? (TQObject*)formfile->formWindow() : (TQObject*)formfile, (*fit).name.latin1(), "virtual", (*fit).access, type, lang, (*fit).returnType ); } } }