source: trunk/tools/designer/designer/resource.cpp

Last change on this file was 197, checked in by rudi, 14 years ago

Added QtDesigner

File size: 119.6 KB
Line 
1/**********************************************************************
2** Copyright (C) 2000-2007 Trolltech ASA. All rights reserved.
3**
4** This file is part of Qt Designer.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
12** licenses may use this file in accordance with the Qt Commercial License
13** Agreement provided with the Software.
14**
15** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17**
18** See http://www.trolltech.com/gpl/ for GPL licensing information.
19** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
20** information about Qt Commercial License Agreements.
21**
22** Contact info@trolltech.com if any conditions of this licensing are
23** not clear to you.
24**
25**********************************************************************/
26
27#include "actiondnd.h"
28#include "command.h"
29#ifndef QT_NO_SQL
30#include "database.h"
31#endif
32#include "formfile.h"
33#include "formwindow.h"
34#include "mainwindow.h"
35#include "menubareditor.h"
36#include "metadatabase.h"
37#include "pixmapcollection.h"
38#include "popupmenueditor.h"
39#include "project.h"
40#include "resource.h"
41#include "widgetfactory.h"
42
43#include <domtool.h>
44#include <widgetdatabase.h>
45
46#include <qaccel.h>
47#include <qapplication.h>
48#include <qbuffer.h>
49#include <qcombobox.h>
50#include <qdatetime.h>
51#include <qdom.h>
52#include <qfeatures.h>
53#include <qfile.h>
54#include <qheader.h>
55#include <qiconview.h>
56#include <qlabel.h>
57#include <qlayout.h>
58#include <qlistbox.h>
59#include <qlistview.h>
60#include <qmenudata.h>
61#include <qmessagebox.h>
62#include <qmetaobject.h>
63#include <qobject.h>
64#include <qobjectlist.h>
65#include <qtabbar.h>
66#ifndef QT_NO_TABLE
67#include <qtable.h>
68#include <qdatatable.h>
69#endif
70#include <qtabwidget.h>
71#include <qtabwidget.h>
72#include <qtextcodec.h>
73#include <qtextstream.h>
74#include <qtooltip.h>
75#include <qwhatsthis.h>
76#include <qwidget.h>
77#include <qwidgetstack.h>
78#include <qwizard.h>
79#include <qworkspace.h>
80#include <qworkspace.h>
81#include <qsplitter.h>
82#include <private/qucom_p.h>
83
84static QString makeIndent( int indent )
85{
86 QString s;
87 s.fill( ' ', indent * 4 );
88 return s;
89}
90
91static QString entitize( const QString &s, bool attribute = FALSE )
92{
93 QString s2 = s;
94 s2 = s2.replace( "&", "&amp;" );
95 s2 = s2.replace( ">", "&gt;" );
96 s2 = s2.replace( "<", "&lt;" );
97 if ( attribute ) {
98 s2 = s2.replace( "\"", "&quot;" );
99 s2 = s2.replace( "'", "&apos;" );
100 }
101 return s2;
102}
103
104#ifdef Q_WS_MACX
105static struct {
106 int key;
107 const char* name;
108} keyname[] = {
109 { Qt::Key_Space, QT_TRANSLATE_NOOP( "QAccel", "Space" ) },
110 { Qt::Key_Escape, QT_TRANSLATE_NOOP( "QAccel", "Esc" ) },
111 { Qt::Key_Tab, QT_TRANSLATE_NOOP( "QAccel", "Tab" ) },
112 { Qt::Key_Backtab, QT_TRANSLATE_NOOP( "QAccel", "Backtab" ) },
113 { Qt::Key_Backspace, QT_TRANSLATE_NOOP( "QAccel", "Backspace" ) },
114 { Qt::Key_Return, QT_TRANSLATE_NOOP( "QAccel", "Return" ) },
115 { Qt::Key_Enter, QT_TRANSLATE_NOOP( "QAccel", "Enter" ) },
116 { Qt::Key_Insert, QT_TRANSLATE_NOOP( "QAccel", "Ins" ) },
117 { Qt::Key_Delete, QT_TRANSLATE_NOOP( "QAccel", "Del" ) },
118 { Qt::Key_Pause, QT_TRANSLATE_NOOP( "QAccel", "Pause" ) },
119 { Qt::Key_Print, QT_TRANSLATE_NOOP( "QAccel", "Print" ) },
120 { Qt::Key_SysReq, QT_TRANSLATE_NOOP( "QAccel", "SysReq" ) },
121 { Qt::Key_Home, QT_TRANSLATE_NOOP( "QAccel", "Home" ) },
122 { Qt::Key_End, QT_TRANSLATE_NOOP( "QAccel", "End" ) },
123 { Qt::Key_Left, QT_TRANSLATE_NOOP( "QAccel", "Left" ) },
124 { Qt::Key_Up, QT_TRANSLATE_NOOP( "QAccel", "Up" ) },
125 { Qt::Key_Right, QT_TRANSLATE_NOOP( "QAccel", "Right" ) },
126 { Qt::Key_Down, QT_TRANSLATE_NOOP( "QAccel", "Down" ) },
127 { Qt::Key_Prior, QT_TRANSLATE_NOOP( "QAccel", "PgUp" ) },
128 { Qt::Key_Next, QT_TRANSLATE_NOOP( "QAccel", "PgDown" ) },
129 { Qt::Key_CapsLock, QT_TRANSLATE_NOOP( "QAccel", "CapsLock" ) },
130 { Qt::Key_NumLock, QT_TRANSLATE_NOOP( "QAccel", "NumLock" ) },
131 { Qt::Key_ScrollLock, QT_TRANSLATE_NOOP( "QAccel", "ScrollLock" ) },
132 { Qt::Key_Menu, QT_TRANSLATE_NOOP( "QAccel", "Menu" ) },
133 { Qt::Key_Help, QT_TRANSLATE_NOOP( "QAccel", "Help" ) },
134
135 // Multimedia keys
136 { Qt::Key_Back, QT_TRANSLATE_NOOP( "QAccel", "Back" ) },
137 { Qt::Key_Forward, QT_TRANSLATE_NOOP( "QAccel", "Forward" ) },
138 { Qt::Key_Stop, QT_TRANSLATE_NOOP( "QAccel", "Stop" ) },
139 { Qt::Key_Refresh, QT_TRANSLATE_NOOP( "QAccel", "Refresh" ) },
140 { Qt::Key_VolumeDown, QT_TRANSLATE_NOOP( "QAccel", "Volume Down" ) },
141 { Qt::Key_VolumeMute, QT_TRANSLATE_NOOP( "QAccel", "Volume Mute" ) },
142 { Qt::Key_VolumeUp, QT_TRANSLATE_NOOP( "QAccel", "Volume Up" ) },
143 { Qt::Key_BassBoost, QT_TRANSLATE_NOOP( "QAccel", "Bass Boost" ) },
144 { Qt::Key_BassUp, QT_TRANSLATE_NOOP( "QAccel", "Bass Up" ) },
145 { Qt::Key_BassDown, QT_TRANSLATE_NOOP( "QAccel", "Bass Down" ) },
146 { Qt::Key_TrebleUp, QT_TRANSLATE_NOOP( "QAccel", "Treble Up" ) },
147 { Qt::Key_TrebleDown, QT_TRANSLATE_NOOP( "QAccel", "Treble Down" ) },
148 { Qt::Key_MediaPlay, QT_TRANSLATE_NOOP( "QAccel", "Media Play" ) },
149 { Qt::Key_MediaStop, QT_TRANSLATE_NOOP( "QAccel", "Media Stop" ) },
150 { Qt::Key_MediaPrev, QT_TRANSLATE_NOOP( "QAccel", "Media Previous" ) },
151 { Qt::Key_MediaNext, QT_TRANSLATE_NOOP( "QAccel", "Media Next" ) },
152 { Qt::Key_MediaRecord, QT_TRANSLATE_NOOP( "QAccel", "Media Record" ) },
153 { Qt::Key_HomePage, QT_TRANSLATE_NOOP( "QAccel", "Home" ) },
154 { Qt::Key_Favorites, QT_TRANSLATE_NOOP( "QAccel", "Favorites" ) },
155 { Qt::Key_Search, QT_TRANSLATE_NOOP( "QAccel", "Search" ) },
156 { Qt::Key_Standby, QT_TRANSLATE_NOOP( "QAccel", "Standby" ) },
157 { Qt::Key_OpenUrl, QT_TRANSLATE_NOOP( "QAccel", "Open URL" ) },
158 { Qt::Key_LaunchMail, QT_TRANSLATE_NOOP( "QAccel", "Launch Mail" ) },
159 { Qt::Key_LaunchMedia, QT_TRANSLATE_NOOP( "QAccel", "Launch Media" ) },
160 { Qt::Key_Launch0, QT_TRANSLATE_NOOP( "QAccel", "Launch (0)" ) },
161 { Qt::Key_Launch1, QT_TRANSLATE_NOOP( "QAccel", "Launch (1)" ) },
162 { Qt::Key_Launch2, QT_TRANSLATE_NOOP( "QAccel", "Launch (2)" ) },
163 { Qt::Key_Launch3, QT_TRANSLATE_NOOP( "QAccel", "Launch (3)" ) },
164 { Qt::Key_Launch4, QT_TRANSLATE_NOOP( "QAccel", "Launch (4)" ) },
165 { Qt::Key_Launch5, QT_TRANSLATE_NOOP( "QAccel", "Launch (5)" ) },
166 { Qt::Key_Launch6, QT_TRANSLATE_NOOP( "QAccel", "Launch (6)" ) },
167 { Qt::Key_Launch7, QT_TRANSLATE_NOOP( "QAccel", "Launch (7)" ) },
168 { Qt::Key_Launch8, QT_TRANSLATE_NOOP( "QAccel", "Launch (8)" ) },
169 { Qt::Key_Launch9, QT_TRANSLATE_NOOP( "QAccel", "Launch (9)" ) },
170 { Qt::Key_LaunchA, QT_TRANSLATE_NOOP( "QAccel", "Launch (A)" ) },
171 { Qt::Key_LaunchB, QT_TRANSLATE_NOOP( "QAccel", "Launch (B)" ) },
172 { Qt::Key_LaunchC, QT_TRANSLATE_NOOP( "QAccel", "Launch (C)" ) },
173 { Qt::Key_LaunchD, QT_TRANSLATE_NOOP( "QAccel", "Launch (D)" ) },
174 { Qt::Key_LaunchE, QT_TRANSLATE_NOOP( "QAccel", "Launch (E)" ) },
175 { Qt::Key_LaunchF, QT_TRANSLATE_NOOP( "QAccel", "Launch (F)" ) },
176
177 // --------------------------------------------------------------
178 // More consistent namings
179 { Qt::Key_Print, QT_TRANSLATE_NOOP( "QAccel", "Print Screen" ) },
180 { Qt::Key_Prior, QT_TRANSLATE_NOOP( "QAccel", "Page Up" ) },
181 { Qt::Key_Next, QT_TRANSLATE_NOOP( "QAccel", "Page Down" ) },
182 { Qt::Key_CapsLock, QT_TRANSLATE_NOOP( "QAccel", "Caps Lock" ) },
183 { Qt::Key_NumLock, QT_TRANSLATE_NOOP( "QAccel", "Num Lock" ) },
184 { Qt::Key_NumLock, QT_TRANSLATE_NOOP( "QAccel", "Number Lock" ) },
185 { Qt::Key_ScrollLock, QT_TRANSLATE_NOOP( "QAccel", "Scroll Lock" ) },
186 { Qt::Key_Insert, QT_TRANSLATE_NOOP( "QAccel", "Insert" ) },
187 { Qt::Key_Delete, QT_TRANSLATE_NOOP( "QAccel", "Delete" ) },
188 { Qt::Key_Escape, QT_TRANSLATE_NOOP( "QAccel", "Escape" ) },
189 { Qt::Key_SysReq, QT_TRANSLATE_NOOP( "QAccel", "System Request" ) },
190
191 { 0, 0 }
192};
193#endif
194static QString platformNeutralKeySequence(const QKeySequence &ks)
195{
196#ifndef Q_WS_MACX
197 return QString(ks);
198#else
199 uint k;
200 QString str;
201 QString p;
202 for (k = 0; k < ks.count(); ++k) {
203 int keycombo = ks[k];
204 int basekey = keycombo & ~(Qt::SHIFT | Qt::CTRL | Qt::ALT | Qt::META);
205 if (keycombo & Qt::CTRL)
206 str += "Ctrl+";
207 if (keycombo & Qt::ALT)
208 str += "Alt+";
209 if (keycombo & Qt::META)
210 str += "Meta+";
211 if (keycombo & Qt::SHIFT)
212 str += "Shift+";
213
214 // begin copy and paste from QKeySequence :(
215 if (basekey & Qt::UNICODE_ACCEL) {
216 // Note: This character should NOT be upper()'ed, since
217 // the encoded string should indicate EXACTLY what the
218 // key represents! Hence a 'Ctrl+Shift+c' is posible to
219 // represent, but is clearly impossible to trigger...
220 p = QChar(basekey & 0xffff);
221 } else if ( basekey >= Qt::Key_F1 && basekey <= Qt::Key_F35 ) {
222 p = QAccel::tr( "F%1" ).arg(basekey - Qt::Key_F1 + 1);
223 } else if ( basekey > Qt::Key_Space && basekey <= Qt::Key_AsciiTilde ) {
224 p.sprintf( "%c", basekey );
225 } else {
226 int i = 0;
227 while (keyname[i].name) {
228 if (basekey == keyname[i].key) {
229 p = QAccel::tr(keyname[i].name);
230 break;
231 }
232 ++i;
233 }
234 // If we can't find the actual translatable keyname,
235 // fall back on the unicode representation of it...
236 // Or else characters like Key_aring may not get displayed
237 // ( Really depends on you locale )
238 if ( !keyname[i].name )
239 // Note: This character should NOT be upper()'ed, see above!
240 p = QChar(basekey & 0xffff);
241 }
242 // end copy...
243 str += p + ", ";
244 }
245 str.truncate(str.length() - 2);
246 return str;
247#endif
248}
249
250static QString mkBool( bool b )
251{
252 return b? "true" : "false";
253}
254
255/*!
256 \class Resource resource.h
257 \brief Class for saving/loading, etc. forms
258
259 This class is used for saving and loading forms, code generation,
260 transferring data of widgets over the clipboard, etc..
261
262*/
263
264
265Resource::Resource()
266{
267 mainwindow = 0;
268 formwindow = 0;
269 toplevel = 0;
270 copying = FALSE;
271 pasting = FALSE;
272 hadGeometry = FALSE;
273 langIface = 0;
274 hasFunctions = FALSE;
275}
276
277Resource::Resource( MainWindow* mw )
278 : mainwindow( mw )
279{
280 formwindow = 0;
281 toplevel = 0;
282 copying = FALSE;
283 pasting = FALSE;
284 hadGeometry = FALSE;
285 langIface = 0;
286 hasFunctions = FALSE;
287}
288
289Resource::~Resource()
290{
291 if ( langIface )
292 langIface->release();
293}
294
295void Resource::setWidget( FormWindow *w )
296{
297 formwindow = w;
298 toplevel = w;
299}
300
301QWidget *Resource::widget() const
302{
303 return toplevel;
304}
305
306bool Resource::load( FormFile *ff, Project *defProject )
307{
308 if ( !ff || ff->absFileName().isEmpty() )
309 return FALSE;
310 currFileName = ff->absFileName();
311 mainContainerSet = FALSE;
312
313 QFile f( ff->absFileName() );
314 f.open( IO_ReadOnly | IO_Translate );
315
316 bool b = load( ff, &f, defProject );
317 f.close();
318
319 return b;
320}
321
322#undef signals
323#undef slots
324
325bool Resource::load( FormFile *ff, QIODevice* dev, Project *defProject )
326{
327 QDomDocument doc;
328 QString errMsg;
329 int errLine;
330 if ( !doc.setContent( dev, &errMsg, &errLine ) ) {
331 return FALSE;
332 }
333
334 DomTool::fixDocument( doc );
335
336 QWidget *p = mainwindow ? mainwindow->qWorkspace() : 0;
337 toplevel = formwindow = new FormWindow( ff, p, 0 );
338 if ( defProject )
339 formwindow->setProject( defProject );
340 else if ( MainWindow::self )
341 formwindow->setProject( MainWindow::self->currProject() );
342 if ( mainwindow )
343 formwindow->setMainWindow( mainwindow );
344 MetaDataBase::addEntry( formwindow );
345
346 if ( !langIface ) {
347 QString lang = "Qt Script";
348 if ( mainwindow )
349 lang = mainwindow->currProject()->language();
350 langIface = MetaDataBase::languageInterface( lang );
351 if ( langIface )
352 langIface->addRef();
353 }
354
355 uiFileVersion = doc.firstChild().toElement().attribute("version");
356 QDomElement e = doc.firstChild().toElement().firstChild().toElement();
357
358 QDomElement forwards = e;
359 while ( forwards.tagName() != "forwards" && !forwards.isNull() )
360 forwards = forwards.nextSibling().toElement();
361
362 QDomElement includes = e;
363 while ( includes.tagName() != "includes" && !includes.isNull() )
364 includes = includes.nextSibling().toElement();
365
366 QDomElement variables = e;
367 while ( variables.tagName() != "variables" && !variables.isNull() )
368 variables = variables.nextSibling().toElement();
369
370 QDomElement signals = e;
371 while ( signals.tagName() != "signals" && !signals.isNull() )
372 signals = signals.nextSibling().toElement();
373
374 QDomElement slots = e;
375 while ( slots.tagName() != "slots" && !slots.isNull() )
376 slots = slots.nextSibling().toElement();
377
378 QDomElement functions = e;
379 while ( functions.tagName() != "functions" && !functions.isNull() )
380 functions = functions.nextSibling().toElement();
381
382 QDomElement connections = e;
383 while ( connections.tagName() != "connections" && !connections.isNull() )
384 connections = connections.nextSibling().toElement();
385
386 QDomElement imageCollection = e;
387 images.clear();
388 while ( imageCollection.tagName() != "images" && !imageCollection.isNull() )
389 imageCollection = imageCollection.nextSibling().toElement();
390
391 QDomElement customWidgets = e;
392 while ( customWidgets.tagName() != "customwidgets" && !customWidgets.isNull() )
393 customWidgets = customWidgets.nextSibling().toElement();
394
395 QDomElement tabOrder = e;
396 while ( tabOrder.tagName() != "tabstops" && !tabOrder.isNull() )
397 tabOrder = tabOrder.nextSibling().toElement();
398
399 QDomElement actions = e;
400 while ( actions.tagName() != "actions" && !actions.isNull() )
401 actions = actions.nextSibling().toElement();
402
403 QDomElement toolbars = e;
404 while ( toolbars.tagName() != "toolbars" && !toolbars.isNull() )
405 toolbars = toolbars.nextSibling().toElement();
406
407 QDomElement menubar = e;
408 while ( menubar.tagName() != "menubar" && !menubar.isNull() )
409 menubar = menubar.nextSibling().toElement();
410
411 QDomElement widget;
412 while ( !e.isNull() ) {
413 if ( e.tagName() == "widget" ) {
414 widgets.clear();
415 widget = e;
416 } else if ( e.tagName() == "include" ) { // compatibility with 2.x
417 MetaDataBase::Include inc;
418 inc.location = "global";
419 if ( e.attribute( "location" ) == "local" )
420 inc.location = "local";
421 inc.implDecl = "in declaration";
422 if ( e.attribute( "impldecl" ) == "in implementation" )
423 inc.implDecl = "in implementation";
424 inc.header = e.firstChild().toText().data();
425 if ( inc.header.right( 5 ) != ".ui.h" ) {
426 metaIncludes.append( inc );
427 } else {
428 if ( formwindow->formFile() )
429 formwindow->formFile()->setCodeFileState( FormFile::Ok );
430 }
431 } else if ( e.tagName() == "comment" ) {
432 metaInfo.comment = e.firstChild().toText().data();
433 } else if ( e.tagName() == "forward" ) { // compatibility with old betas
434 metaForwards << e.firstChild().toText().data();
435 } else if ( e.tagName() == "variable" ) { // compatibility with old betas
436 MetaDataBase::Variable v;
437 v.varName = e.firstChild().toText().data();
438 v.varAccess = "protected";
439 metaVariables << v;
440 } else if ( e.tagName() == "author" ) {
441 metaInfo.author = e.firstChild().toText().data();
442 } else if ( e.tagName() == "class" ) {
443 metaInfo.className = e.firstChild().toText().data();
444 } else if ( e.tagName() == "pixmapfunction" ) {
445 if ( formwindow ) {
446 formwindow->setSavePixmapInline( FALSE );
447 formwindow->setSavePixmapInProject( FALSE );
448 formwindow->setPixmapLoaderFunction( e.firstChild().toText().data() );
449 }
450 } else if ( e.tagName() == "pixmapinproject" ) {
451 if ( formwindow ) {
452 formwindow->setSavePixmapInline( FALSE );
453 formwindow->setSavePixmapInProject( TRUE );
454 }
455 } else if ( e.tagName() == "exportmacro" ) {
456 exportMacro = e.firstChild().toText().data();
457 } else if ( e.tagName() == "layoutdefaults" ) {
458 formwindow->setLayoutDefaultSpacing( e.attribute( "spacing", QString::number( formwindow->layoutDefaultSpacing() ) ).toInt() );
459 formwindow->setLayoutDefaultMargin( e.attribute( "margin", QString::number( formwindow->layoutDefaultMargin() ) ).toInt() );
460 } else if ( e.tagName() == "layoutfunctions" ) {
461 formwindow->setSpacingFunction( e.attribute( "spacing" ) );
462 formwindow->setMarginFunction( e.attribute( "margin" ) );
463 if ( !formwindow->marginFunction().isEmpty() || !formwindow->spacingFunction().isEmpty() )
464 formwindow->hasLayoutFunctions( TRUE );
465 }
466
467 e = e.nextSibling().toElement();
468 }
469
470 if ( !imageCollection.isNull() )
471 loadImageCollection( imageCollection );
472 if ( !customWidgets.isNull() )
473 loadCustomWidgets( customWidgets, this );
474
475#if defined (QT_NON_COMMERCIAL)
476 bool previewMode = MainWindow::self ? MainWindow::self->isPreviewing() : FALSE;
477 QWidget *w = (QWidget*)createObject( widget, !previewMode ? (QWidget*)formwindow : MainWindow::self );
478 if ( !w )
479 return FALSE;
480 if ( previewMode )
481 w->reparent( MainWindow::self, Qt::WType_TopLevel, w->pos(), TRUE );
482#else
483 if ( !createObject( widget, formwindow) )
484 return FALSE;
485#endif
486
487 if ( !forwards.isNull() ) {
488 for ( QDomElement n = forwards.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() )
489 if ( n.tagName() == "forward" )
490 metaForwards << n.firstChild().toText().data();
491 }
492
493 if ( !includes.isNull() ) {
494 for ( QDomElement n = includes.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() )
495 if ( n.tagName() == "include" ) {
496 if ( n.tagName() == "include" ) {
497 MetaDataBase::Include inc;
498 inc.location = "global";
499 if ( n.attribute( "location" ) == "local" )
500 inc.location = "local";
501 inc.implDecl = "in declaration";
502 if ( n.attribute( "impldecl" ) == "in implementation" )
503 inc.implDecl = "in implementation";
504 inc.header = n.firstChild().toText().data();
505 if ( inc.header.right( 5 ) != ".ui.h" ) {
506 metaIncludes.append( inc );
507 } else {
508 if ( formwindow->formFile() )
509 formwindow->formFile()->setCodeFileState( FormFile::Ok );
510 }
511 }
512 }
513 }
514
515 if ( !variables.isNull() ) {
516 for ( QDomElement n = variables.firstChild().toElement(); !n.isNull();
517 n = n.nextSibling().toElement() ) {
518 if ( n.tagName() == "variable" ) {
519 MetaDataBase::Variable v;
520 v.varName = n.firstChild().toText().data();
521 v.varAccess = n.attribute( "access", "protected" );
522 if ( v.varAccess.isEmpty() )
523 v.varAccess = "protected";
524 metaVariables << v;
525 }
526 }
527 }
528 if ( !signals.isNull() ) {
529 for ( QDomElement n = signals.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() )
530 if ( n.tagName() == "signal" )
531 metaSignals << n.firstChild().toText().data();
532 }
533 if ( !slots.isNull() ) {
534 for ( QDomElement n = slots.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() )
535 if ( n.tagName() == "slot" ) {
536 MetaDataBase::Function function;
537 function.specifier = n.attribute( "specifier", "virtual" );
538 if ( function.specifier.isEmpty() )
539 function.specifier = "virtual";
540 function.access = n.attribute( "access", "public" );
541 if ( function.access.isEmpty() )
542 function.access = "public";
543 function.language = n.attribute( "language", "C++" );
544 function.returnType = n.attribute( "returnType", "void" );
545 if ( function.returnType.isEmpty() )
546 function.returnType = "void";
547 function.type = "slot";
548 function.function = n.firstChild().toText().data();
549 if ( !MetaDataBase::hasFunction( formwindow, function.function, TRUE ) )
550 MetaDataBase::addFunction( formwindow, function.function, function.specifier,
551 function.access, "slot", function.language, function.returnType );
552 else
553 MetaDataBase::changeFunctionAttributes( formwindow, function.function, function.function,
554 function.specifier, function.access,
555 "slot", function.language,
556 function.returnType );
557 }
558 }
559
560 if ( !functions.isNull() ) {
561 for ( QDomElement n = functions.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
562 if ( n.tagName() == "function" ) {
563 MetaDataBase::Function function;
564 function.specifier = n.attribute( "specifier", "virtual" );
565 if ( function.specifier.isEmpty() )
566 function.specifier = "virtual";
567 function.access = n.attribute( "access", "public" );
568 if ( function.access.isEmpty() )
569 function.access = "public";
570 function.type = n.attribute( "type", "function" );
571 function.type = "function";
572 function.language = n.attribute( "language", "C++" );
573 function.returnType = n.attribute( "returnType", "void" );
574 if ( function.returnType.isEmpty() )
575 function.returnType = "void";
576 function.function = n.firstChild().toText().data();
577 if ( !MetaDataBase::hasFunction( formwindow, function.function, TRUE ) )
578 MetaDataBase::addFunction( formwindow, function.function, function.specifier,
579 function.access, function.type, function.language,
580 function.returnType );
581 else
582 MetaDataBase::changeFunctionAttributes( formwindow, function.function, function.function,
583 function.specifier, function.access,
584 function.type, function.language, function.returnType );
585 }
586 }
587 }
588
589 if ( !actions.isNull() )
590 loadActions( actions );
591 if ( !toolbars.isNull() )
592 loadToolBars( toolbars );
593 if ( !menubar.isNull() )
594 loadMenuBar( menubar );
595
596 if ( !connections.isNull() )
597 loadConnections( connections );
598
599 if ( !tabOrder.isNull() )
600 loadTabOrder( tabOrder );
601
602 if ( formwindow ) {
603 MetaDataBase::setIncludes( formwindow, metaIncludes );
604 MetaDataBase::setForwards( formwindow, metaForwards );
605 MetaDataBase::setVariables( formwindow, metaVariables );
606 MetaDataBase::setSignalList( formwindow, metaSignals );
607 metaInfo.classNameChanged = metaInfo.className != QString( formwindow->name() );
608 MetaDataBase::setMetaInfo( formwindow, metaInfo );
609 MetaDataBase::setExportMacro( formwindow->mainContainer(), exportMacro );
610 }
611
612 loadExtraSource( formwindow->formFile(), currFileName, langIface, hasFunctions );
613
614 if ( mainwindow && formwindow )
615 mainwindow->insertFormWindow( formwindow );
616
617 if ( formwindow ) {
618 formwindow->killAccels( formwindow );
619 if ( formwindow->layout() )
620 formwindow->layout()->activate();
621 if ( hadGeometry )
622 formwindow->resize( formwindow->size().expandedTo( formwindow->minimumSize().
623 expandedTo( formwindow->minimumSizeHint() ) ) );
624 else
625 formwindow->resize( formwindow->size().expandedTo( formwindow->sizeHint() ) );
626 }
627
628 return TRUE;
629}
630
631static bool saveCode( const QString &filename, const QString &code )
632{
633 QFile f( filename );
634 if ( f.open(IO_WriteOnly | IO_Translate) ) {
635 QTextStream ts( &f );
636 ts << code;
637 return TRUE;
638 }
639 return FALSE;
640}
641
642bool Resource::save( const QString& filename, bool formCodeOnly )
643{
644 if ( !formwindow || filename.isEmpty() )
645 return FALSE;
646 if (!langIface) {
647 QString lang = "Qt Script";
648 if ( mainwindow )
649 lang = mainwindow->currProject()->language();
650 langIface = MetaDataBase::languageInterface( lang );
651 if ( langIface )
652 langIface->addRef();
653 }
654 if ( formCodeOnly && langIface ) {
655 if ( saveFormCode(formwindow->formFile(), langIface) )
656 return TRUE;
657 bool breakout = FALSE;
658 FormFile *ff = formwindow->formFile();
659 QString codeFile = ff->project()->makeAbsolute( ff->codeFile() );
660 QString filter = langIface->fileFilterList().join(";;");
661 while ( !breakout ) {
662 QString fn = QFileDialog::getSaveFileName( codeFile, filter );
663 breakout = fn.isEmpty();
664 if ( !breakout ) {
665 if ( saveCode(fn, ff->code()) )
666 return TRUE;
667 }
668 }
669 }
670 currFileName = filename;
671
672 QFile f( filename );
673 if ( !f.open( IO_WriteOnly | IO_Translate ) )
674 return FALSE;
675 bool b = save( &f );
676 f.close();
677 return b;
678}
679
680bool Resource::save( QIODevice* dev )
681{
682 if ( !formwindow )
683 return FALSE;
684
685 if ( !langIface ) {
686 QString lang = "C++";
687 if ( mainwindow )
688 lang = mainwindow->currProject()->language();
689 langIface = MetaDataBase::languageInterface( lang );
690 if ( langIface )
691 langIface->addRef();
692 }
693
694 QTextStream ts( dev );
695 ts.setCodec( QTextCodec::codecForName( "UTF-8" ) );
696
697 ts << "<!DOCTYPE UI><UI version=\"3.3\" stdsetdef=\"1\">" << endl;
698 saveMetaInfoBefore( ts, 0 );
699 saveObject( formwindow->mainContainer(), 0, ts, 0 );
700 if ( ::qt_cast<QMainWindow*>(formwindow->mainContainer()) ) {
701 saveMenuBar( (QMainWindow*)formwindow->mainContainer(), ts, 0 );
702 saveToolBars( (QMainWindow*)formwindow->mainContainer(), ts, 0 );
703 }
704 if ( !MetaDataBase::customWidgets()->isEmpty() && !usedCustomWidgets.isEmpty() )
705 saveCustomWidgets( ts, 0 );
706 if ( ::qt_cast<QMainWindow*>(formwindow->mainContainer()) )
707 saveActions( formwindow->actionList(), ts, 0 );
708 if ( !images.isEmpty() )
709 saveImageCollection( ts, 0 );
710 if ( !MetaDataBase::connections( formwindow ).isEmpty() ||
711 !MetaDataBase::slotList( formwindow ).isEmpty() )
712 saveConnections( ts, 0 );
713 saveTabOrder( ts, 0 );
714 saveMetaInfoAfter( ts, 0 );
715 saveIncludeHints( ts, 0 );
716 ts << "</UI>" << endl;
717 bool ok = saveFormCode( formwindow->formFile(), langIface );
718 images.clear();
719
720 return ok;
721}
722
723QString Resource::copy()
724{
725 if ( !formwindow )
726 return QString::null;
727
728 copying = TRUE;
729 QString s;
730 QTextOStream ts( &s );
731
732 ts << "<!DOCTYPE UI-SELECTION><UI-SELECTION>" << endl;
733 QWidgetList widgets = formwindow->selectedWidgets();
734 QWidgetList tmp( widgets );
735 for ( QWidget *w = widgets.first(); w; w = widgets.next() ) {
736 QWidget *p = w->parentWidget();
737 bool save = TRUE;
738 while ( p ) {
739 if ( tmp.findRef( p ) != -1 ) {
740 save = FALSE;
741 break;
742 }
743 p = p->parentWidget();
744 }
745 if ( save )
746 saveObject( w, 0, ts, 0 );
747 }
748 if ( !MetaDataBase::customWidgets()->isEmpty() && !usedCustomWidgets.isEmpty() )
749 saveCustomWidgets( ts, 0 );
750 if ( !images.isEmpty() )
751 saveImageCollection( ts, 0 );
752 ts << "</UI-SELECTION>" << endl;
753
754 return s;
755}
756
757
758void Resource::paste( const QString &cb, QWidget *parent )
759{
760 if ( !formwindow )
761 return;
762 mainContainerSet = TRUE;
763
764 pasting = TRUE;
765 QDomDocument doc;
766 QString errMsg;
767 int errLine;
768 doc.setContent( cb, &errMsg, &errLine );
769
770 QDomElement firstWidget = doc.firstChild().toElement().firstChild().toElement();
771
772 QDomElement imageCollection = firstWidget;
773 images.clear();
774 while ( imageCollection.tagName() != "images" && !imageCollection.isNull() )
775 imageCollection = imageCollection.nextSibling().toElement();
776
777 QDomElement customWidgets = firstWidget;
778 while ( customWidgets.tagName() != "customwidgets" && !customWidgets.isNull() )
779 customWidgets = customWidgets.nextSibling().toElement();
780
781 if ( !imageCollection.isNull() )
782 loadImageCollection( imageCollection );
783 if ( !customWidgets.isNull() )
784 loadCustomWidgets( customWidgets, this );
785
786 QWidgetList widgets;
787 formwindow->clearSelection( FALSE );
788 formwindow->setPropertyShowingBlocked( TRUE );
789 formwindow->clearSelection( FALSE );
790 while ( !firstWidget.isNull() ) {
791 if ( firstWidget.tagName() == "widget" ) {
792 QWidget *w = (QWidget*)createObject( firstWidget, parent, 0 );
793 if ( !w )
794 continue;
795 widgets.append( w );
796 int x = w->x() + formwindow->grid().x();
797 int y = w->y() + formwindow->grid().y();
798 if ( w->x() + w->width() > parent->width() )
799 x = QMAX( 0, parent->width() - w->width() );
800 if ( w->y() + w->height() > parent->height() )
801 y = QMAX( 0, parent->height() - w->height() );
802 if ( x != w->x() || y != w->y() )
803 w->move( x, y );
804 formwindow->selectWidget( w );
805 } else if ( firstWidget.tagName() == "spacer" ) {
806 QWidget *w = createSpacer( firstWidget, parent, 0, firstWidget.tagName() == "vspacer" ? Qt::Vertical : Qt::Horizontal );
807 if ( !w )
808 continue;
809 widgets.append( w );
810 int x = w->x() + formwindow->grid().x();
811 int y = w->y() + formwindow->grid().y();
812 if ( w->x() + w->width() > parent->width() )
813 x = QMAX( 0, parent->width() - w->width() );
814 if ( w->y() + w->height() > parent->height() )
815 y = QMAX( 0, parent->height() - w->height() );
816 if ( x != w->x() || y != w->y() )
817 w->move( x, y );
818 formwindow->selectWidget( w );
819 }
820 firstWidget = firstWidget.nextSibling().toElement();
821 }
822 formwindow->setPropertyShowingBlocked( FALSE );
823 formwindow->emitShowProperties();
824
825 PasteCommand *cmd = new PasteCommand( FormWindow::tr( "Paste" ), formwindow, widgets );
826 formwindow->commandHistory()->addCommand( cmd );
827}
828
829void Resource::saveObject( QObject *obj, QDesignerGridLayout* grid, QTextStream &ts, int indent )
830{
831 if ( obj && obj->isWidgetType() && ( (QWidget*)obj )->isHidden() )
832 return;
833 QString closeTag;
834 const char* className = WidgetFactory::classNameOf( obj );
835 int classID = WidgetDatabase::idFromClassName( className );
836 bool isPlugin = WidgetDatabase::isCustomPluginWidget( classID );
837 if ( obj->isWidgetType() ) {
838 if ( obj->isA("CustomWidget") || isPlugin ) {
839 usedCustomWidgets << QString( className );
840 includeHints << WidgetDatabase::includeFile( classID );
841 }
842
843 if ( obj != formwindow && !formwindow->widgets()->find( (QWidget*)obj ) )
844 return; // we don't know anything about this thing
845
846 QString attributes;
847 if ( grid ) {
848 QDesignerGridLayout::Item item = grid->items[ (QWidget*)obj ];
849 attributes += QString(" row=\"") + QString::number(item.row) + "\"";
850 attributes += QString(" column=\"") + QString::number(item.column) + "\"";
851 if ( item.rowspan * item.colspan != 1 ) {
852 attributes += QString(" rowspan=\"") + QString::number(item.rowspan) + "\"";
853 attributes += QString(" colspan=\"") + QString::number(item.colspan) + "\"";
854 }
855 }
856
857 if ( qstrcmp( className, "Spacer" ) == 0 ) {
858 closeTag = makeIndent( indent ) + "</spacer>\n";
859 ts << makeIndent( indent ) << "<spacer" << attributes << ">" << endl;
860 ++indent;
861 } else {
862 closeTag = makeIndent( indent ) + "</widget>\n";
863 ts << makeIndent( indent ) << "<widget class=\"" << className << "\"" << attributes << ">" << endl;
864 ++indent;
865 }
866 if ( WidgetFactory::hasItems(classID, obj) )
867 saveItems( obj, ts, indent );
868 saveObjectProperties( obj, ts, indent );
869 } else {
870 // test for other objects we created. Nothing so far.
871 return;
872 }
873
874 QDesignerWidgetStack* ws = 0;
875
876 if ( ::qt_cast<QTabWidget*>(obj) ) {
877 QTabWidget* tw = (QTabWidget*) obj;
878 QObjectList* tmpl = tw->queryList( "QWidgetStack" );
879 QWidgetStack *ws = (QWidgetStack*)tmpl->first();
880 QTabBar *tb = ( (QDesignerTabWidget*)obj )->tabBar();
881 for ( int i = 0; i < tb->count(); ++i ) {
882 QTab *t = tb->tabAt( i );
883 if ( !t )
884 continue;
885 QWidget *w = ws->widget( t->identifier() );
886 if ( !w )
887 continue;
888 if ( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf(w) ) == -1 )
889 continue; // we don't know this widget
890 ts << makeIndent( indent ) << "<widget class=\"QWidget\">" << endl;
891 ++indent;
892 ts << makeIndent( indent ) << "<property name=\"name\">" << endl;
893 indent++;
894 ts << makeIndent( indent ) << "<cstring>" << entitize( w->name() ) << "</cstring>" << endl;
895 indent--;
896 ts << makeIndent( indent ) << "</property>" << endl;
897
898 ts << makeIndent( indent ) << "<attribute name=\"title\">" << endl;
899 indent++;
900 ts << makeIndent( indent ) << "<string>" << entitize( t->text() ) << "</string>" << endl;
901 indent--;
902 ts << makeIndent( indent ) << "</attribute>" << endl;
903 saveChildrenOf( w, ts, indent );
904 --indent;
905 ts << makeIndent( indent ) << "</widget>" << endl;
906 }
907 delete tmpl;
908 } else if ( (ws = ::qt_cast<QDesignerWidgetStack*>(obj)) != 0 ) {
909 for ( int i = 0; i < ws->count(); ++i ) {
910 QWidget *w = ws->page( i );
911 if ( !w )
912 continue;
913 if ( WidgetDatabase::idFromClassName(WidgetFactory::classNameOf(w)) == -1 )
914 continue; // we don't know this widget
915 ts << makeIndent( indent ) << "<widget class=\"QWidget\">" << endl;
916 ++indent;
917 ts << makeIndent( indent ) << "<property name=\"name\">" << endl;
918 indent++;
919 ts << makeIndent( indent ) << "<cstring>" << entitize( w->name() ) << "</cstring>" << endl;
920 indent--;
921 ts << makeIndent( indent ) << "</property>" << endl;
922 ts << makeIndent( indent ) << "<attribute name=\"id\">" << endl;
923 indent++;
924 ts << makeIndent( indent ) << "<number>" << QString::number(i) << "</number>" << endl;
925 indent--;
926 ts << makeIndent( indent ) << "</attribute>" << endl;
927 saveChildrenOf( w, ts, indent );
928 --indent;
929 ts << makeIndent( indent ) << "</widget>" << endl;
930 }
931 } else if ( ::qt_cast<QToolBox*>(obj) ) {
932 QToolBox* tb = (QToolBox*)obj;
933 for ( int i = 0; i < tb->count(); ++i ) {
934 QWidget *w = tb->item( i );
935 if ( !w )
936 continue;
937 if ( WidgetDatabase::idFromClassName(WidgetFactory::classNameOf(w)) == -1 )
938 continue; // we don't know this widget
939 ts << makeIndent( indent ) << "<widget class=\"QWidget\">" << endl;
940 ++indent;
941 ts << makeIndent( indent ) << "<property name=\"name\">" << endl;
942 indent++;
943 ts << makeIndent( indent ) << "<cstring>" << entitize( w->name() ) << "</cstring>" << endl;
944 indent--;
945 ts << makeIndent( indent ) << "</property>" << endl;
946 ts << makeIndent( indent ) << "<property name=\"backgroundMode\">" << endl;
947 indent++;
948 saveEnumProperty( w, "backgroundMode", QVariant::Invalid, ts, indent );
949 indent--;
950 ts << makeIndent( indent ) << "</property>" << endl;
951 ts << makeIndent( indent ) << "<attribute name=\"label\">" << endl;
952 indent++;
953 ts << makeIndent( indent ) << "<string>" << entitize( tb->itemLabel( tb->indexOf(w) ) ) << "</string>" << endl;
954 indent--;
955 ts << makeIndent( indent ) << "</attribute>" << endl;
956 saveChildrenOf( w, ts, indent );
957 --indent;
958 ts << makeIndent( indent ) << "</widget>" << endl;
959 }
960 } else if ( ::qt_cast<QWizard*>(obj) ) {
961 QWizard* wiz = (QWizard*)obj;
962 for ( int i = 0; i < wiz->pageCount(); ++i ) {
963 QWidget *w = wiz->page( i );
964 if ( !w )
965 continue;
966 if ( WidgetDatabase::idFromClassName(WidgetFactory::classNameOf(w)) == -1 )
967 continue; // we don't know this widget
968 ts << makeIndent( indent ) << "<widget class=\"QWidget\">" << endl;
969 ++indent;
970 ts << makeIndent( indent ) << "<property name=\"name\">" << endl;
971 indent++;
972 ts << makeIndent( indent ) << "<cstring>" << entitize( w->name() ) << "</cstring>" << endl;
973 indent--;
974 ts << makeIndent( indent ) << "</property>" << endl;
975
976 ts << makeIndent( indent ) << "<attribute name=\"title\">" << endl;
977 indent++;
978 ts << makeIndent( indent ) << "<string>" << entitize( wiz->title( w ) ) << "</string>" << endl;
979 indent--;
980 ts << makeIndent( indent ) << "</attribute>" << endl;
981 saveChildrenOf( w, ts, indent );
982 --indent;
983 ts << makeIndent( indent ) << "</widget>" << endl;
984 }
985 } else if ( ::qt_cast<QMainWindow*>(obj) ) {
986 saveChildrenOf( ( (QMainWindow*)obj )->centralWidget(), ts, indent );
987 } else {
988 bool saved = FALSE;
989#ifdef QT_CONTAINER_CUSTOM_WIDGETS
990 if ( isPlugin ) {
991 WidgetInterface *iface = 0;
992 widgetManager()->queryInterface( className, &iface );
993 if ( iface ) {
994 QWidgetContainerInterfacePrivate *iface2 = 0;
995 iface->queryInterface( IID_QWidgetContainer, (QUnknownInterface**)&iface2 );
996 if ( iface2 ) {
997 if ( iface2->supportsPages( className ) ) {
998 QWidgetList containers = iface2->pages( className, (QWidget*)obj );
999 if ( !containers.isEmpty() ) {
1000 saved = TRUE;
1001 int i = 0;
1002 for ( QWidget *w = containers.first(); w; w = containers.next(), ++i ) {
1003 if ( WidgetDatabase::
1004 idFromClassName( WidgetFactory::classNameOf( w ) ) == -1 )
1005 continue; // we don't know this widget
1006 ts << makeIndent( indent ) << "<widget class=\""
1007 << WidgetFactory::classNameOf( w )
1008 << "\">" << endl;
1009 ++indent;
1010 ts << makeIndent( indent ) << "<property name=\"name\">" << endl;
1011 indent++;
1012 ts << makeIndent( indent ) << "<cstring>" << entitize( w->name() )
1013 << "</cstring>" << endl;
1014 indent--;
1015 ts << makeIndent( indent ) << "</property>" << endl;
1016 ts << makeIndent( indent ) << "<attribute name=\"label\">" << endl;
1017 indent++;
1018 ts << makeIndent( indent ) << "<cstring>"
1019 << entitize( iface2->pageLabel( className, (QWidget*)obj, i ) )
1020 << "</cstring>" << endl;
1021 indent--;
1022 ts << makeIndent( indent ) << "</attribute>" << endl;
1023 saveChildrenOf( w, ts, indent );
1024 --indent;
1025 ts << makeIndent( indent ) << "</widget>" << endl;
1026 }
1027 }
1028 } else {
1029 saved = TRUE;
1030 QWidget *w = iface2->containerOfWidget( className, (QWidget*)obj );
1031 if ( obj != w ) {
1032 ts << makeIndent( indent ) << "<widget class=\""
1033 << WidgetFactory::classNameOf( w )
1034 << "\">" << endl;
1035 ++indent;
1036 ts << makeIndent( indent ) << "<property name=\"name\">" << endl;
1037 indent++;
1038 ts << makeIndent( indent ) << "<cstring>" << entitize( w->name() )
1039 << "</cstring>" << endl;
1040 indent--;
1041 ts << makeIndent( indent ) << "</property>" << endl;
1042 saveChildrenOf( w, ts, indent );
1043 --indent;
1044 ts << makeIndent( indent ) << "</widget>" << endl;
1045 }
1046 // Create a custom widget and then store it in the database
1047 // so we can save the custom widgets.
1048 MetaDataBase::CustomWidget *cw = new MetaDataBase::CustomWidget;
1049 cw->className = className;
1050 cw->includeFile = WidgetDatabase::includeFile( classID );
1051 QStrList lst = w->metaObject()->signalNames( TRUE );
1052 for ( QPtrListIterator<char> it(lst); it.current(); ++it )
1053 cw->lstSignals.append(it.current());
1054
1055 int i;
1056 int total = w->metaObject()->numProperties( TRUE );
1057 for ( i = 0; i < total; i++ ) {
1058 const QMetaProperty *p = w->metaObject()->property( i, TRUE );
1059 if ( p->designable(w) ) {
1060 MetaDataBase::Property prop;
1061 prop.property = p->name();
1062 QString pType = p->type();
1063 // *sigh* designer types are not normal types
1064 // Handle most cases, the ones it misses are
1065 // probably too difficult to deal with anyway...
1066 if ( pType.startsWith("Q") ) {
1067 pType = pType.right( pType.length() - 1 );
1068 } else {
1069 pType[0] = pType[0].upper();
1070 }
1071 prop.type = pType;
1072 cw->lstProperties.append( prop );
1073 }
1074 }
1075
1076 total = w->metaObject()->numSlots( TRUE );
1077 for ( i = 0; i < total; i++ ) {
1078 const QMetaData *md = w->metaObject()->slot( i, TRUE );
1079 MetaDataBase::Function funky;
1080 // Find out if we have a return type.
1081 if ( md->method->count > 0 ) {
1082 const QUParameter p = md->method->parameters[0];
1083 if ( p.inOut == QUParameter::InOut )
1084 funky.returnType = p.type->desc();
1085 }
1086
1087 funky.function = md->name;
1088 funky.language = "C++";
1089 switch ( md->access ) {
1090 case QMetaData::Public:
1091 funky.access = "public";
1092 break;
1093 case QMetaData::Protected:
1094 funky.access = "protected";
1095 break;
1096 case QMetaData::Private:
1097 funky.access = "private";
1098 break;
1099 }
1100 cw->lstSlots.append( funky );
1101 }
1102 MetaDataBase::addCustomWidget( cw );
1103 }
1104 iface2->release();
1105 }
1106 iface->release();
1107 }
1108 }
1109#endif // QT_CONTAINER_CUSTOM_WIDGETS
1110 if ( !saved )
1111 saveChildrenOf( obj, ts, indent );
1112 }
1113
1114 indent--;
1115 ts << closeTag;
1116}
1117
1118void Resource::saveItems( QObject *obj, QTextStream &ts, int indent )
1119{
1120 if ( ::qt_cast<QListBox*>(obj) || ::qt_cast<QComboBox*>(obj) ) {
1121 QListBox *lb = 0;
1122 if ( ::qt_cast<QListBox*>(obj) ) {
1123 lb = (QListBox*)obj;
1124 } else {
1125 QComboBox *cb = (QComboBox*)obj;
1126 lb = cb->listBox();
1127 if (!lb) {
1128 QPopupMenu *popup = (QPopupMenu*)cb->child( 0, "QPopupMenu" );
1129 Q_ASSERT(popup);
1130 for ( int id = 0; id < (int)popup->count(); ++id ) {
1131 ts << makeIndent( indent ) << "<item>" << endl;
1132 indent++;
1133 QStringList text;
1134 text << popup->text(id);
1135 QPtrList<QPixmap> pixmaps;
1136 if ( popup->pixmap(id) )
1137 pixmaps.append( popup->pixmap(id) );
1138 saveItem( text, pixmaps, ts, indent );
1139 indent--;
1140 ts << makeIndent( indent ) << "</item>" << endl;
1141 }
1142 }
1143 }
1144
1145 if (lb) {
1146 QListBoxItem *i = lb->firstItem();
1147 for ( ; i; i = i->next() ) {
1148 ts << makeIndent( indent ) << "<item>" << endl;
1149 indent++;
1150 QStringList text;
1151 text << i->text();
1152 QPtrList<QPixmap> pixmaps;
1153 if ( i->pixmap() )
1154 pixmaps.append( i->pixmap() );
1155 saveItem( text, pixmaps, ts, indent );
1156 indent--;
1157 ts << makeIndent( indent ) << "</item>" << endl;
1158 }
1159 }
1160
1161 } else if ( ::qt_cast<QIconView*>(obj) ) {
1162 QIconView *iv = (QIconView*)obj;
1163
1164 QIconViewItem *i = iv->firstItem();
1165 for ( ; i; i = i->nextItem() ) {
1166 ts << makeIndent( indent ) << "<item>" << endl;
1167 indent++;
1168 QStringList text;
1169 text << i->text();
1170 QPtrList<QPixmap> pixmaps;
1171 if ( i->pixmap() )
1172 pixmaps.append( i->pixmap() );
1173 saveItem( text, pixmaps, ts, indent );
1174 indent--;
1175 ts << makeIndent( indent ) << "</item>" << endl;
1176 }
1177 } else if ( ::qt_cast<QListView*>(obj) ) {
1178 QListView *lv = (QListView*)obj;
1179 int i;
1180 for ( i = 0; i < lv->header()->count(); ++i ) {
1181 ts << makeIndent( indent ) << "<column>" << endl;
1182 indent++;
1183 QStringList l;
1184 l << lv->header()->label( i );
1185 QPtrList<QPixmap> pix;
1186 pix.setAutoDelete( TRUE );
1187 if ( lv->header()->iconSet( i ) )
1188 pix.append( new QPixmap( lv->header()->iconSet( i )->pixmap() ) );
1189 saveItem( l, pix, ts, indent );
1190 ts << makeIndent( indent ) << "<property name=\"clickable\">" << endl;
1191 indent++;
1192 ts << makeIndent( indent ) << "<bool>" << mkBool( lv->header()->isClickEnabled( i ) )<< "</bool>" << endl;
1193 indent--;
1194 ts << makeIndent( indent ) << "</property>" << endl;
1195 ts << makeIndent( indent ) << "<property name=\"resizable\">" << endl;
1196 indent++;
1197 ts << makeIndent( indent ) << "<bool>" << mkBool( lv->header()->isResizeEnabled( i ) ) << "</bool>" << endl;
1198 indent--;
1199 ts << makeIndent( indent ) << "</property>" << endl;
1200 indent--;
1201 ts << makeIndent( indent ) << "</column>" << endl;
1202 }
1203 saveItem( lv->firstChild(), ts, indent - 1 );
1204 }
1205#if !defined (QT_NO_TABLE)
1206 else if ( ::qt_cast<QTable*>(obj) ) {
1207 QTable *table = (QTable*)obj;
1208 int i;
1209 QMap<QString, QString> columnFields = MetaDataBase::columnFields( table );
1210# ifndef QT_NO_SQL
1211 bool isDataTable = ::qt_cast<QDataTable*>(table);
1212# else
1213 bool isDataTable = false;
1214# endif
1215 for ( i = 0; i < table->horizontalHeader()->count(); ++i ) {
1216 if ( !table->horizontalHeader()->label( i ).isNull() &&
1217 table->horizontalHeader()->label( i ).toInt() != i + 1 ||
1218 table->horizontalHeader()->iconSet( i ) ||
1219 isDataTable ) {
1220 ts << makeIndent( indent ) << "<column>" << endl;
1221 indent++;
1222 QStringList l;
1223 l << table->horizontalHeader()->label( i );
1224 QPtrList<QPixmap> pix;
1225 pix.setAutoDelete( TRUE );
1226 if ( table->horizontalHeader()->iconSet( i ) )
1227 pix.append( new QPixmap( table->horizontalHeader()->iconSet( i )->pixmap() ) );
1228 saveItem( l, pix, ts, indent );
1229 if ( isDataTable && !columnFields.isEmpty() ) {
1230 ts << makeIndent( indent ) << "<property name=\"field\">" << endl;
1231 indent++;
1232 ts << makeIndent( indent ) << "<string>" << entitize( *columnFields.find( l[ 0 ] ) ) << "</string>" << endl;
1233 indent--;
1234 ts << makeIndent( indent ) << "</property>" << endl;
1235 }
1236 indent--;
1237 ts << makeIndent( indent ) << "</column>" << endl;
1238 }
1239 }
1240 for ( i = 0; i < table->verticalHeader()->count(); ++i ) {
1241 if ( !table->verticalHeader()->label( i ).isNull() &&
1242 table->verticalHeader()->label( i ).toInt() != i + 1 ||
1243 table->verticalHeader()->iconSet( i ) ) {
1244 ts << makeIndent( indent ) << "<row>" << endl;
1245 indent++;
1246 QStringList l;
1247 l << table->verticalHeader()->label( i );
1248 QPtrList<QPixmap> pix;
1249 pix.setAutoDelete( TRUE );
1250 if ( table->verticalHeader()->iconSet( i ) )
1251 pix.append( new QPixmap( table->verticalHeader()->iconSet( i )->pixmap() ) );
1252 saveItem( l, pix, ts, indent );
1253 indent--;
1254 ts << makeIndent( indent ) << "</row>" << endl;
1255 }
1256 }
1257 }
1258#endif
1259}
1260
1261void Resource::saveItem( QListViewItem *i, QTextStream &ts, int indent )
1262{
1263 QListView *lv = i->listView();
1264 while ( i ) {
1265 ts << makeIndent( indent ) << "<item>" << endl;
1266 indent++;
1267
1268 QPtrList<QPixmap> pixmaps;
1269 QStringList textes;
1270 for ( int c = 0; c < lv->columns(); ++c ) {
1271 pixmaps.append( i->pixmap( c ) );
1272 textes << i->text( c );
1273 }
1274 saveItem( textes, pixmaps, ts, indent );
1275
1276 if ( i->firstChild() )
1277 saveItem( i->firstChild(), ts, indent );
1278
1279 indent--;
1280 ts << makeIndent( indent ) << "</item>" << endl;
1281 i = i->nextSibling();
1282 }
1283}
1284
1285void Resource::savePixmap( const QPixmap &p, QTextStream &ts, int indent, const QString &tagname )
1286{
1287 if ( p.isNull() ) {
1288 ts << makeIndent( indent ) << "<" << tagname << "></" << tagname << ">" << endl;
1289 return;
1290 }
1291
1292 if ( formwindow && formwindow->savePixmapInline() )
1293 ts << makeIndent( indent ) << "<" << tagname << ">" << saveInCollection( p ) << "</" << tagname << ">" << endl;
1294 else if ( formwindow && formwindow->savePixmapInProject() )
1295 ts << makeIndent( indent ) << "<" << tagname << ">" << MetaDataBase::pixmapKey( formwindow, p.serialNumber() )
1296 << "</" << tagname << ">" << endl;
1297 else
1298 ts << makeIndent( indent ) << "<" << tagname << ">" << MetaDataBase::pixmapArgument( formwindow, p.serialNumber() )
1299 << "</" << tagname << ">" << endl;
1300}
1301
1302QPixmap Resource::loadPixmap( const QDomElement &e, const QString &/*tagname*/ )
1303{
1304 QString arg = e.firstChild().toText().data();
1305
1306 if ( formwindow && formwindow->savePixmapInline() ) {
1307 QImage img = loadFromCollection( arg );
1308 QPixmap pix;
1309 pix.convertFromImage( img );
1310 MetaDataBase::setPixmapArgument( formwindow, pix.serialNumber(), arg );
1311 return pix;
1312 } else if ( formwindow && formwindow->savePixmapInProject() ) {
1313 QPixmap pix;
1314 if ( mainwindow && mainwindow->currProject() ) {
1315 pix = mainwindow->currProject()->pixmapCollection()->pixmap( arg );
1316 } else {
1317 pix = QPixmap::fromMimeSource( "designer_image.png" );
1318 // we have to force the pixmap to get a new and unique serial number. Unfortunately detatch() doesn't do that
1319 pix.convertFromImage( pix.convertToImage() );
1320 }
1321
1322 MetaDataBase::setPixmapKey( formwindow, pix.serialNumber(), arg );
1323 return pix;
1324 }
1325 QPixmap pix = QPixmap::fromMimeSource( "designer_image.png" );
1326 // we have to force the pixmap to get a new and unique serial number. Unfortunately detatch() doesn't do that
1327 pix.convertFromImage( pix.convertToImage() );
1328 MetaDataBase::setPixmapArgument( formwindow, pix.serialNumber(), arg );
1329 return pix;
1330}
1331
1332void Resource::saveItem( const QStringList &text,
1333 const QPtrList<QPixmap> &pixmaps, QTextStream &ts,
1334 int indent )
1335{
1336 QStringList::ConstIterator it = text.begin();
1337 for ( ; it != text.end(); ++it ) {
1338 ts << makeIndent( indent ) << "<property name=\"text\">" << endl;
1339 indent++;
1340 ts << makeIndent( indent ) << "<string>" << entitize( *it ) << "</string>" << endl;
1341 indent--;
1342 ts << makeIndent( indent ) << "</property>" << endl;
1343 }
1344
1345 for ( int i = 0; i < (int)pixmaps.count(); ++i ) {
1346 QPixmap *p = ( (QPtrList<QPixmap>)pixmaps ).at( i );
1347 ts << makeIndent( indent ) << "<property name=\"pixmap\">" << endl;
1348 indent++;
1349 if ( p )
1350 savePixmap( *p, ts, indent );
1351 else
1352 savePixmap( QPixmap(), ts, indent );
1353 indent--;
1354 ts << makeIndent( indent ) << "</property>" << endl;
1355 }
1356}
1357
1358void Resource::saveChildrenOf( QObject* obj, QTextStream &ts, int indent )
1359{
1360 const QObjectList *l = obj->children();
1361 if ( !l )
1362 return; // no children to save
1363
1364 QString closeTag;
1365 // if the widget has a layout we pretend that all widget's childs are childs of the layout - makes the structure nicer
1366 QLayout *layout = 0;
1367 QDesignerGridLayout* grid = 0;
1368 if ( !::qt_cast<QSplitter*>(obj) &&
1369 WidgetDatabase::isContainer( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( obj ) ) ) &&
1370 obj->isWidgetType() &&
1371 WidgetFactory::layoutType( (QWidget*)obj, layout ) != WidgetFactory::NoLayout ) {
1372 WidgetFactory::LayoutType lay = WidgetFactory::layoutType( (QWidget*)obj, layout );
1373 switch ( lay ) {
1374 case WidgetFactory::HBox:
1375 closeTag = makeIndent( indent ) + "</hbox>";
1376 ts << makeIndent( indent ) << "<hbox>" << endl;
1377 ++indent;
1378 break;
1379 case WidgetFactory::VBox:
1380 closeTag = makeIndent( indent ) + "</vbox>";
1381 ts << makeIndent( indent ) << "<vbox>" << endl;
1382 ++indent;
1383 break;
1384 case WidgetFactory::Grid:
1385 closeTag = makeIndent( indent ) + "</grid>";
1386 ts << makeIndent( indent ) << "<grid>" << endl;
1387 ++indent;
1388 grid = (QDesignerGridLayout*) layout;
1389 break;
1390 default:
1391 break;
1392 }
1393
1394 // save properties of layout
1395 if ( lay != WidgetFactory::NoLayout )
1396 saveObjectProperties( layout, ts, indent );
1397
1398 }
1399
1400 QObject *o = 0;
1401 for ( QPtrListIterator<QObject> it ( *l ); ( o = it.current() ); ++it )
1402 if ( !QString( o->name() ).startsWith( "qt_dead_widget_" ) )
1403 saveObject( o, grid, ts, indent );
1404 if ( !closeTag.isEmpty() ) {
1405 indent--;
1406 ts << closeTag << endl;
1407 }
1408}
1409
1410void Resource::saveObjectProperties( QObject *w, QTextStream &ts, int indent )
1411{
1412 QStringList saved;
1413 QStringList changed;
1414 changed = MetaDataBase::changedProperties( w );
1415 if ( w->isWidgetType() ) {
1416 if ( ::qt_cast<Spacer*>(w) ) {
1417 if ( !changed.contains( "sizeHint" ) )
1418 changed << "sizeHint";
1419 if ( !changed.contains( "geometry" ) )
1420 changed << "geometry";
1421 } else {
1422 QToolButton *tb = ::qt_cast<QToolButton*>(w);
1423 if ( tb && !tb->iconSet().isNull() ) {
1424 changed << "iconSet";
1425 }
1426 }
1427 } else if ( ::qt_cast<QLayout*>(w) ) {
1428 if ( MetaDataBase::spacing( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (QLayout*)w ) ) ) > -1 )
1429 changed << "spacing";
1430 if ( MetaDataBase::margin( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (QLayout*)w ) ) ) > -1 )
1431 changed << "margin";
1432 if ( MetaDataBase::resizeMode( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (QLayout*)w ) ) ) != "Auto"
1433 && !MetaDataBase::resizeMode( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (QLayout*)w ) ) ).isEmpty() )
1434 changed << "resizeMode";
1435 }
1436
1437 if ( w == formwindow->mainContainer() ) {
1438 if ( changed.findIndex( "geometry" ) == -1 )
1439 changed << "geometry";
1440 if ( changed.findIndex( "caption" ) == -1 )
1441 changed << "caption";
1442 }
1443
1444 if ( changed.isEmpty() )
1445 return;
1446
1447 bool inLayout = w != formwindow->mainContainer() && !copying && w->isWidgetType() && ( (QWidget*)w )->parentWidget() &&
1448 WidgetFactory::layoutType( ( (QWidget*)w )->parentWidget() ) != WidgetFactory::NoLayout;
1449
1450 QStrList lst = w->metaObject()->propertyNames( !::qt_cast<Spacer*>(w) );
1451 for ( QPtrListIterator<char> it( lst ); it.current(); ++it ) {
1452 if ( changed.find( QString::fromLatin1( it.current() ) ) == changed.end() )
1453 continue;
1454 if ( saved.find( QString::fromLatin1( it.current() ) ) != saved.end() )
1455 continue;
1456 saved << QString::fromLatin1( it.current() );
1457 const QMetaProperty* p = w->metaObject()->
1458 property( w->metaObject()->findProperty( it.current(), TRUE ), TRUE );
1459 if ( !p || !p->stored( w ) || ( inLayout && qstrcmp( p->name(), "geometry" ) == 0 ) )
1460 continue;
1461 if ( ::qt_cast<QLabel*>(w) && qstrcmp( p->name(), "pixmap" ) == 0 &&
1462 ( !( (QLabel*)w )->pixmap() || ( (QLabel*)w )->pixmap()->isNull() ) )
1463 continue;
1464 if ( ::qt_cast<MenuBarEditor*>(w) &&
1465 ( qstrcmp( p->name(), "itemName" ) == 0 || qstrcmp( p->name(), "itemNumber" ) == 0 ||
1466 qstrcmp( p->name(), "itemText" ) == 0 ) )
1467 continue;
1468 if ( qstrcmp( p->name(), "name" ) == 0 )
1469 knownNames << w->property( "name" ).toString();
1470 if ( !p->isSetType() && !p->isEnumType() && !w->property( p->name() ).isValid() )
1471 continue;
1472 ts << makeIndent( indent ) << "<property";
1473 ts << " name=\"" << it.current() << "\"";
1474 if ( !p->stdSet() )
1475 ts << " stdset=\"0\"";
1476 ts << ">" << endl;
1477 indent++;
1478 if ( strcmp( it.current(), "resizeMode" ) == 0 && ::qt_cast<QLayout*>(w) ) {
1479 saveProperty( w, it.current(), "", QVariant::String, ts, indent );
1480 } else if ( p->isSetType() ) {
1481 saveSetProperty( w, it.current(), QVariant::nameToType( p->type() ), ts, indent );
1482 } else if ( p->isEnumType() ) {
1483 saveEnumProperty( w, it.current(), QVariant::nameToType( p->type() ), ts, indent );
1484 } else {
1485 saveProperty( w, it.current(), w->property( p->name() ), QVariant::nameToType( p->type() ), ts, indent );
1486 }
1487 indent--;
1488 ts << makeIndent( indent ) << "</property>" << endl;
1489 }
1490
1491 if ( w->isWidgetType() && MetaDataBase::fakeProperties( w ) ) {
1492 QMap<QString, QVariant>* fakeProperties = MetaDataBase::fakeProperties( w );
1493 for ( QMap<QString, QVariant>::Iterator fake = fakeProperties->begin();
1494 fake != fakeProperties->end(); ++fake ) {
1495 if ( MetaDataBase::isPropertyChanged( w, fake.key() ) ) {
1496 if ( w->inherits("CustomWidget") ) {
1497 MetaDataBase::CustomWidget *cw = ( (CustomWidget*)w )->customWidget();
1498 if ( cw && !cw->hasProperty( fake.key().latin1() ) && fake.key() != "toolTip" && fake.key() != "whatsThis" )
1499 continue;
1500 }
1501
1502 ts << makeIndent( indent ) << "<property name=\"" << fake.key() << "\" stdset=\"0\">" << endl;
1503 indent++;
1504 saveProperty( w, fake.key(), *fake, (*fake).type(), ts, indent );
1505 indent--;
1506 ts << makeIndent( indent ) << "</property>" << endl;
1507 }
1508 }
1509 }
1510}
1511
1512void Resource::saveSetProperty( QObject *w, const QString &name, QVariant::Type, QTextStream &ts, int indent )
1513{
1514 const QMetaProperty *p = w->metaObject()->property( w->metaObject()->findProperty( name, TRUE ), TRUE );
1515 QStrList l( p->valueToKeys( w->property( name ).toInt() ) );
1516 QString v;
1517 for ( uint i = 0; i < l.count(); ++i ) {
1518 v += l.at( i );
1519 if ( i < l.count() - 1 )
1520 v += "|";
1521 }
1522 ts << makeIndent( indent ) << "<set>" << v << "</set>" << endl;
1523}
1524
1525void Resource::saveEnumProperty( QObject *w, const QString &name, QVariant::Type, QTextStream &ts, int indent )
1526{
1527 const QMetaProperty *p = w->metaObject()->property( w->metaObject()->findProperty( name, TRUE ), TRUE );
1528 int value = w->property( name ).toInt();
1529 const char* key = p->valueToKey( value );
1530 if (key)
1531 ts << makeIndent( indent ) << "<enum>" << key << "</enum>" << endl;
1532}
1533
1534void Resource::saveProperty( QObject *w, const QString &name, const QVariant &value, QVariant::Type t, QTextStream &ts, int indent )
1535{
1536 if ( name == "hAlign" || name =="vAlign" || name == "wordwrap" ||
1537 name == "layoutMargin" || name =="layoutSpacing" )
1538 return;
1539 int num;
1540 uint unum;
1541 double dob;
1542 QString comment;
1543 if ( w && formwindow->widgets()->find( (QWidget*)w ) || formwindow->actionList().find( (QAction*)w ) )
1544 comment = MetaDataBase::propertyComment( w, name );
1545 switch ( t ) {
1546 case QVariant::String:
1547 if ( name == "resizeMode" ) {
1548 QString resmod = MetaDataBase::resizeMode( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (QLayout*)w ) ) );
1549 if ( !resmod.isNull() && resmod != "Auto" ) {
1550 ts << makeIndent( indent ) << "<enum>";
1551 ts << resmod;
1552 ts << "</enum>" << endl;
1553 }
1554
1555 } else {
1556 ts << makeIndent( indent ) << "<string>" << entitize( value.toString() ) << "</string>" << endl;
1557 if ( !comment.isEmpty() )
1558 ts << makeIndent( indent ) << "<comment>" << entitize( comment ) << "</comment>" << endl;
1559 }
1560 break;
1561 case QVariant::CString:
1562 ts << makeIndent( indent ) << "<cstring>" << entitize( value.toCString() ).latin1() << "</cstring>" << endl;
1563 break;
1564 case QVariant::Bool:
1565 ts << makeIndent( indent ) << "<bool>" << mkBool( value.toBool() ) << "</bool>" << endl;
1566 break;
1567 case QVariant::Int:
1568 if ( ::qt_cast<QLayout*>(w) ) {
1569 num = -1;
1570 if ( name == "spacing" )
1571 num = MetaDataBase::spacing( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (QLayout*)w ) ) );
1572 else if ( name == "margin" )
1573 num = MetaDataBase::margin( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (QLayout*)w ) ) );
1574 if ( num != -1 )
1575 ts << makeIndent( indent ) << "<number>" << QString::number( num ) << "</number>" << endl;
1576 } else {
1577 num = value.toInt();
1578 ts << makeIndent( indent ) << "<number>" << QString::number( num ) << "</number>" << endl;
1579 }
1580 break;
1581 case QVariant::Double:
1582 dob = value.toDouble();
1583 ts << makeIndent( indent ) << "<number>" << QString::number( dob ) << "</number>" << endl;
1584 break;
1585 case QVariant::KeySequence:
1586 ts << makeIndent( indent ) << "<string>"
1587 << entitize(platformNeutralKeySequence(value.toKeySequence())) << "</string>" << endl;
1588 break;
1589 case QVariant::UInt:
1590 unum = value.toUInt();
1591 ts << makeIndent( indent ) << "<number>" << QString::number( unum ) << "</number>" << endl;
1592 break;
1593 case QVariant::Rect: {
1594 QVariant v( value );
1595 ts << makeIndent( indent ) << "<rect>" << endl;
1596 indent++;
1597 ts << makeIndent( indent ) << "<x>" << QString::number( v.toRect().x() ) << "</x>" << endl;
1598 ts << makeIndent( indent ) << "<y>" << QString::number( v.toRect().y() ) << "</y>" << endl;
1599 ts << makeIndent( indent ) << "<width>" << QString::number( v.toRect().width() ) << "</width>" << endl;
1600 ts << makeIndent( indent ) << "<height>" << QString::number( v.toRect().height() ) << "</height>" << endl;
1601 indent--;
1602 ts << makeIndent( indent ) << "</rect>" << endl;
1603 } break;
1604 case QVariant::Point: {
1605 QVariant v( value );
1606 ts << makeIndent( indent ) << "<point>" << endl;
1607 indent++;
1608 ts << makeIndent( indent ) << "<x>" << QString::number( v.toPoint().x() ) << "</x>" << endl;
1609 ts << makeIndent( indent ) << "<y>" << QString::number( v.toPoint().y() ) << "</y>" << endl;
1610 indent--;
1611 ts << makeIndent( indent ) << "</point>" << endl;
1612 } break;
1613 case QVariant::Size: {
1614 QVariant v( value );
1615 ts << makeIndent( indent ) << "<size>" << endl;
1616 indent++;
1617 ts << makeIndent( indent ) << "<width>" << QString::number( v.toSize().width() ) << "</width>" << endl;
1618 ts << makeIndent( indent ) << "<height>" << QString::number( v.toSize().height() ) << "</height>" << endl;
1619 indent--;
1620 ts << makeIndent( indent ) << "</size>" << endl;
1621 } break;
1622 case QVariant::Color: {
1623 QVariant v( value );
1624 ts << makeIndent( indent ) << "<color>" << endl;
1625 indent++;
1626 saveColor( ts, indent, v.toColor() );
1627 indent--;
1628 ts << makeIndent( indent ) << "</color>" << endl;
1629 } break;
1630 case QVariant::Font: {
1631 QVariant v( value );
1632 ts << makeIndent( indent ) << "<font>" << endl;
1633 QFont f( qApp->font() );
1634 if ( w && w->isWidgetType() && ((QWidget*)w)->parentWidget() )
1635 f = ((QWidget*)w)->parentWidget()->font();
1636 QFont f2( v.toFont() );
1637 indent++;
1638 if ( f.family() != f2.family() )
1639 ts << makeIndent( indent ) << "<family>" << f2.family() << "</family>" << endl;
1640 if ( f.pointSize() != f2.pointSize() )
1641 ts << makeIndent( indent ) << "<pointsize>" << QString::number( f2.pointSize() ) << "</pointsize>" << endl;
1642 if ( f.bold() != f2.bold() )
1643 ts << makeIndent( indent ) << "<bold>" << QString::number( (int)f2.bold() ) << "</bold>" << endl;
1644 if ( f.italic() != f2.italic() )
1645 ts << makeIndent( indent ) << "<italic>" << QString::number( (int)f2.italic() ) << "</italic>" << endl;
1646 if ( f.underline() != f2.underline() )
1647 ts << makeIndent( indent ) << "<underline>" << QString::number( (int)f2.underline() ) << "</underline>" << endl;
1648 if ( f.strikeOut() != f2.strikeOut() )
1649 ts << makeIndent( indent ) << "<strikeout>" << QString::number( (int)f2.strikeOut() ) << "</strikeout>" << endl;
1650 indent--;
1651 ts << makeIndent( indent ) << "</font>" << endl;
1652 } break;
1653 case QVariant::SizePolicy: {
1654 QSizePolicy sp( value.toSizePolicy() );
1655 ts << makeIndent( indent ) << "<sizepolicy>" << endl;
1656 indent++;
1657 ts << makeIndent( indent ) << "<hsizetype>" << (int)sp.horData() << "</hsizetype>" << endl;
1658 ts << makeIndent( indent ) << "<vsizetype>" << (int)sp.verData() << "</vsizetype>" << endl;
1659 ts << makeIndent( indent ) << "<horstretch>" << (int)sp.horStretch() << "</horstretch>" << endl;
1660 ts << makeIndent( indent ) << "<verstretch>" << (int)sp.verStretch() << "</verstretch>" << endl;
1661 indent--;
1662 ts << makeIndent( indent ) << "</sizepolicy>" << endl;
1663 break;
1664 }
1665 case QVariant::Pixmap:
1666 savePixmap( value.toPixmap(), ts, indent );
1667 break;
1668 case QVariant::IconSet:
1669 savePixmap( value.toIconSet().pixmap(), ts, indent, "iconset" );
1670 break;
1671 case QVariant::Image:
1672 ts << makeIndent( indent ) << "<image>" << saveInCollection( value.toImage() ) << "</image>" << endl;
1673 break;
1674 case QVariant::Palette: {
1675 QPalette p( value.toPalette() );
1676 ts << makeIndent( indent ) << "<palette>" << endl;
1677 indent++;
1678
1679 ts << makeIndent( indent ) << "<active>" << endl;
1680 indent++;
1681 saveColorGroup( ts, indent, p.active() );
1682 indent--;
1683 ts << makeIndent( indent ) << "</active>" << endl;
1684
1685 ts << makeIndent( indent ) << "<disabled>" << endl;
1686 indent++;
1687 saveColorGroup( ts, indent, p.disabled() );
1688 indent--;
1689 ts << makeIndent( indent ) << "</disabled>" << endl;
1690
1691 ts << makeIndent( indent ) << "<inactive>" << endl;
1692 indent++;
1693 saveColorGroup( ts, indent, p.inactive() );
1694 indent--;
1695 ts << makeIndent( indent ) << "</inactive>" << endl;
1696
1697 indent--;
1698 ts << makeIndent( indent ) << "</palette>" << endl;
1699 } break;
1700 case QVariant::Cursor:
1701 ts << makeIndent( indent ) << "<cursor>" << value.toCursor().shape() << "</cursor>" << endl;
1702 break;
1703 case QVariant::StringList: {
1704 QStringList lst = value.toStringList();
1705 uint i = 0;
1706 ts << makeIndent( indent ) << "<stringlist>" << endl;
1707 indent++;
1708 if ( !lst.isEmpty() ) {
1709 for ( i = 0; i < lst.count(); ++i )
1710 ts << makeIndent( indent ) << "<string>" << entitize( lst[ i ] ) << "</string>" << endl;
1711 }
1712 indent--;
1713 ts << makeIndent( indent ) << "</stringlist>" << endl;
1714 } break;
1715 case QVariant::Date: {
1716 QDate d = value.toDate();
1717 ts << makeIndent( indent ) << "<date>" << endl;
1718 indent++;
1719 ts << makeIndent( indent ) << "<year>" << d.year() << "</year>" << endl;
1720 ts << makeIndent( indent ) << "<month>" << d.month() << "</month>" << endl;
1721 ts << makeIndent( indent ) << "<day>" << d.day() << "</day>" << endl;
1722 indent--;
1723 ts << makeIndent( indent ) << "</date>" << endl;
1724 break;
1725 }
1726 case QVariant::Time: {
1727 QTime t = value.toTime();
1728 ts << makeIndent( indent ) << "<time>" << endl;
1729 indent++;
1730 ts << makeIndent( indent ) << "<hour>" << t.hour() << "</hour>" << endl;
1731 ts << makeIndent( indent ) << "<minute>" << t.minute() << "</minute>" << endl;
1732 ts << makeIndent( indent ) << "<second>" << t.second() << "</second>" << endl;
1733 indent--;
1734 ts << makeIndent( indent ) << "</time>" << endl;
1735 break;
1736 }
1737 case QVariant::DateTime: {
1738 QDateTime dt = value.toDateTime();
1739 ts << makeIndent( indent ) << "<datetime>" << endl;
1740 indent++;
1741 ts << makeIndent( indent ) << "<year>" << dt.date().year() << "</year>" << endl;
1742 ts << makeIndent( indent ) << "<month>" << dt.date().month() << "</month>" << endl;
1743 ts << makeIndent( indent ) << "<day>" << dt.date().day() << "</day>" << endl;
1744 ts << makeIndent( indent ) << "<hour>" << dt.time().hour() << "</hour>" << endl;
1745 ts << makeIndent( indent ) << "<minute>" << dt.time().minute() << "</minute>" << endl;
1746 ts << makeIndent( indent ) << "<second>" << dt.time().second() << "</second>" << endl;
1747 indent--;
1748 ts << makeIndent( indent ) << "</datetime>" << endl;
1749 break;
1750 }
1751 default:
1752 qWarning( "saving the property %s of type %d not supported yet", name.latin1(), (int)t );
1753 }
1754}
1755
1756void Resource::saveColorGroup( QTextStream &ts, int indent, const QColorGroup &cg )
1757{
1758 for( int r = 0 ; r < QColorGroup::NColorRoles ; r++ ) {
1759 ts << makeIndent( indent ) << "<color>" << endl;
1760 indent++;
1761 saveColor( ts, indent, cg.color( (QColorGroup::ColorRole)r ) );
1762 indent--;
1763 ts << makeIndent( indent ) << "</color>" << endl;
1764 QPixmap* pm = cg.brush( (QColorGroup::ColorRole)r ).pixmap();
1765 if ( pm && !pm->isNull() )
1766 savePixmap( *pm, ts, indent );
1767 }
1768}
1769
1770void Resource::saveColor( QTextStream &ts, int indent, const QColor &c )
1771{
1772 ts << makeIndent( indent ) << "<red>" << QString::number( c.red() ) << "</red>" << endl;
1773 ts << makeIndent( indent ) << "<green>" << QString::number( c.green() ) << "</green>" << endl;
1774 ts << makeIndent( indent ) << "<blue>" << QString::number( c.blue() ) << "</blue>" << endl;
1775}
1776
1777QObject *Resource::createObject( const QDomElement &e, QWidget *parent, QLayout* layout )
1778{
1779 lastItem = 0;
1780 QDomElement n = e.firstChild().toElement();
1781 QWidget *w = 0; // the widget that got created
1782 QObject *obj = 0; // gets the properties
1783
1784 int row = e.attribute( "row" ).toInt();
1785 int col = e.attribute( "column" ).toInt();
1786 int rowspan = e.attribute( "rowspan" ).toInt();
1787 int colspan = e.attribute( "colspan" ).toInt();
1788 if ( rowspan < 1 )
1789 rowspan = 1;
1790 if ( colspan < 1 )
1791 colspan = 1;
1792
1793 QString className = e.attribute( "class", "QWidget" );
1794#ifdef QT_CONTAINER_CUSTOM_WIDGETS
1795 QString parentClassName = WidgetFactory::classNameOf( parent );
1796 bool isPlugin =
1797 WidgetDatabase::isCustomPluginWidget( WidgetDatabase::idFromClassName( parentClassName ) );
1798 if ( isPlugin )
1799 qWarning( "####### loading custom container widgets without page support not implemented!" );
1800 // ### TODO loading for custom container widgets without pages
1801#endif
1802 if ( !className.isNull() ) {
1803 obj = WidgetFactory::create( WidgetDatabase::idFromClassName( className ), parent, 0, FALSE );
1804 if ( !obj ) {
1805 QMessageBox::critical( MainWindow::self, MainWindow::tr( "Loading File" ),
1806 MainWindow::tr( "Error loading %1.\n"
1807 "The widget %2 couldn't be created.\n"
1808 "Information may be lost if this form is saved." ).
1809 arg( currFileName ).arg( className ) );
1810 return 0;
1811 }
1812 if ( !mainContainerSet ) {
1813 if ( formwindow )
1814 formwindow->setMainContainer( (QWidget*)obj );
1815 mainContainerSet = TRUE;
1816 }
1817 w = (QWidget*)obj;
1818 if ( ::qt_cast<QMainWindow*>(w) )
1819 w = ( (QMainWindow*)w )->centralWidget();
1820 if ( layout ) {
1821 switch ( WidgetFactory::layoutType( layout ) ) {
1822 case WidgetFactory::HBox:
1823 ( (QHBoxLayout*)layout )->addWidget( w );
1824 break;
1825 case WidgetFactory::VBox:
1826 ( (QVBoxLayout*)layout )->addWidget( w );
1827 break;
1828 case WidgetFactory::Grid:
1829 ( (QDesignerGridLayout*)layout )->addMultiCellWidget( w, row, row + rowspan - 1,
1830 col, col + colspan - 1 );
1831 break;
1832 default:
1833 break;
1834 }
1835 }
1836
1837 if ( !toplevel )
1838 toplevel = w;
1839 layout = 0;
1840
1841 if ( w && formwindow ) {
1842 if ( !parent ||
1843 ( !::qt_cast<QTabWidget*>(parent) &&
1844 !::qt_cast<QWidgetStack*>(parent) &&
1845 !::qt_cast<QToolBox*>(parent) &&
1846 !::qt_cast<QWizard*>(parent)
1847#ifdef QT_CONTAINER_CUSTOM_WIDGETS
1848 && !isPlugin
1849#endif
1850 ) )
1851 formwindow->insertWidget( w, pasting );
1852 else if ( parent &&
1853 ( ::qt_cast<QTabWidget*>(parent) ||
1854 ::qt_cast<QWidgetStack*>(parent) ||
1855 ::qt_cast<QToolBox*>(parent) ||
1856 ::qt_cast<QWizard*>(parent)
1857#ifdef QT_CONTAINER_CUSTOM_WIDGETS
1858 || isPlugin
1859#endif
1860 ) )
1861 MetaDataBase::addEntry( w );
1862 }
1863 }
1864
1865 QDomElement sizePolicyElement;
1866 QObject *sizePolicyObject = 0;
1867
1868 while ( !n.isNull() ) {
1869 if ( n.tagName() == "spacer" ) {
1870 createSpacer( n, w, layout, Qt::Horizontal );
1871 } else if ( n.tagName() == "widget" ) {
1872 createObject( n, w, layout );
1873 } else if ( n.tagName() == "hbox" ) {
1874 layout = WidgetFactory::createLayout( w, layout, WidgetFactory::HBox );
1875 obj = layout;
1876 n = n.firstChild().toElement();
1877 continue;
1878 } else if ( n.tagName() == "grid" ) {
1879 layout = WidgetFactory::createLayout( w, layout, WidgetFactory::Grid );
1880 obj = layout;
1881 n = n.firstChild().toElement();
1882 continue;
1883 } else if ( n.tagName() == "vbox" ) {
1884 layout = WidgetFactory::createLayout( w, layout, WidgetFactory::VBox );
1885 obj = layout;
1886 n = n.firstChild().toElement();
1887 continue;
1888 } else if ( n.tagName() == "property" && obj ) {
1889 if ( n.attribute( "name" ) == "sizePolicy" ) {
1890 // ### Evil hack ### Delay setting sizePolicy so it won't be overridden by other properties.
1891 sizePolicyElement = n;
1892 sizePolicyObject = obj;
1893 } else {
1894 setObjectProperty( obj, n.attribute( "name" ), n.firstChild().toElement() );
1895 }
1896 } else if ( n.tagName() == "attribute" && w ) {
1897 QString attrib = n.attribute( "name" );
1898 QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() );
1899 if ( ::qt_cast<QTabWidget*>(parent) ) {
1900 if ( attrib == "title" )
1901 ( (QTabWidget*)parent )->insertTab( w, v.toString() );
1902 } else if ( ::qt_cast<QWidgetStack*>(parent) ) {
1903 if ( attrib == "id" )
1904 ( (QDesignerWidgetStack*)parent )->insertPage( w, v.toInt() );
1905 } else if ( ::qt_cast<QToolBox*>(parent) ) {
1906 if ( attrib == "label" )
1907 ( (QToolBox*)parent )->addItem( w, v.toString() );
1908 } else if ( ::qt_cast<QWizard*>(parent) ) {
1909 if ( attrib == "title" )
1910 ( (QWizard*)parent )->addPage( w, v.toString() );
1911#ifdef QT_CONTAINER_CUSTOM_WIDGETS
1912 } else if ( isPlugin ) {
1913 if ( attrib == "label" ) {
1914 WidgetInterface *iface = 0;
1915 widgetManager()->queryInterface( parentClassName, &iface );
1916 if ( iface ) {
1917 QWidgetContainerInterfacePrivate *iface2 = 0;
1918 iface->queryInterface( IID_QWidgetContainer, (QUnknownInterface**)&iface2 );
1919 if ( iface2 ) {
1920 iface2->insertPage( parentClassName,
1921 (QWidget*)parent, v.toString(), -1, w );
1922 iface2->release();
1923 }
1924 iface->release();
1925 }
1926 }
1927#endif // QT_CONTAINER_CUSTOM_WIDGETS
1928 }
1929 } else if ( n.tagName() == "item" ) {
1930 createItem( n, w );
1931 } else if ( n.tagName() == "column" || n.tagName() =="row" ) {
1932 createColumn( n, w );
1933 }
1934
1935 n = n.nextSibling().toElement();
1936 }
1937
1938 // ### Evil hack ### See description above.
1939 if ( !sizePolicyElement.isNull() ) {
1940 setObjectProperty( sizePolicyObject,
1941 sizePolicyElement.attribute( "name" ),
1942 sizePolicyElement.firstChild().toElement() );
1943 }
1944
1945 if ( w->isWidgetType() )
1946 widgets.insert( w->name(), w );
1947
1948 return w;
1949}
1950
1951void Resource::createColumn( const QDomElement &e, QWidget *widget )
1952{
1953 if ( !widget )
1954 return;
1955
1956 if ( ::qt_cast<QListView*>(widget) && e.tagName() == "column" ) {
1957 QListView *lv = (QListView*)widget;
1958 QDomElement n = e.firstChild().toElement();
1959 QPixmap pix;
1960 bool hasPixmap = FALSE;
1961 QString txt;
1962 bool clickable = TRUE, resizable = TRUE;
1963 while ( !n.isNull() ) {
1964 if ( n.tagName() == "property" ) {
1965 QString attrib = n.attribute( "name" );
1966 QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() );
1967 if ( attrib == "text" )
1968 txt = v.toString();
1969 else if ( attrib == "pixmap" ) {
1970 pix = loadPixmap( n.firstChild().toElement().toElement() );
1971 hasPixmap = !pix.isNull();
1972 } else if ( attrib == "clickable" )
1973 clickable = v.toBool();
1974 else if ( attrib == "resizable" )
1975 resizable = v.toBool();
1976 }
1977 n = n.nextSibling().toElement();
1978 }
1979 lv->addColumn( txt );
1980 int i = lv->header()->count() - 1;
1981 if ( hasPixmap ) {
1982 lv->header()->setLabel( i, pix, txt );
1983 }
1984 if ( !clickable )
1985 lv->header()->setClickEnabled( clickable, i );
1986 if ( !resizable )
1987 lv->header()->setResizeEnabled( resizable, i );
1988 }
1989#ifndef QT_NO_TABLE
1990 else if ( ::qt_cast<QTable*>(widget) ) {
1991 QTable *table = (QTable*)widget;
1992 bool isRow;
1993 if ( ( isRow = e.tagName() == "row" ) )
1994 table->setNumRows( table->numRows() + 1 );
1995 else
1996 table->setNumCols( table->numCols() + 1 );
1997
1998 QDomElement n = e.firstChild().toElement();
1999 QPixmap pix;
2000 bool hasPixmap = FALSE;
2001 QString txt;
2002 QString field;
2003 QMap<QString, QString> fieldMap = MetaDataBase::columnFields( table );
2004 while ( !n.isNull() ) {
2005 if ( n.tagName() == "property" ) {
2006 QString attrib = n.attribute( "name" );
2007 QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() );
2008 if ( attrib == "text" )
2009 txt = v.toString();
2010 else if ( attrib == "pixmap" ) {
2011 hasPixmap = !n.firstChild().firstChild().toText().data().isEmpty();
2012 if ( hasPixmap )
2013 pix = loadPixmap( n.firstChild().toElement() );
2014 } else if ( attrib == "field" )
2015 field = v.toString();
2016 }
2017 n = n.nextSibling().toElement();
2018 }
2019
2020 int i = isRow ? table->numRows() - 1 : table->numCols() - 1;
2021 QHeader *h = !isRow ? table->horizontalHeader() : table->verticalHeader();
2022 if ( hasPixmap )
2023 h->setLabel( i, pix, txt );
2024 else
2025 h->setLabel( i, txt );
2026 if ( !isRow && !field.isEmpty() )
2027 fieldMap.insert( txt, field );
2028 MetaDataBase::setColumnFields( table, fieldMap );
2029 }
2030#endif
2031}
2032
2033void Resource::loadItem( const QDomElement &e, QPixmap &pix, QString &txt, bool &hasPixmap )
2034{
2035 QDomElement n = e;
2036 hasPixmap = FALSE;
2037 while ( !n.isNull() ) {
2038 if ( n.tagName() == "property" ) {
2039 QString attrib = n.attribute( "name" );
2040 QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() );
2041 if ( attrib == "text" )
2042 txt = v.toString();
2043 else if ( attrib == "pixmap" ) {
2044 pix = loadPixmap( n.firstChild().toElement() );
2045 hasPixmap = !pix.isNull();
2046 }
2047 }
2048 n = n.nextSibling().toElement();
2049 }
2050}
2051
2052void Resource::createItem( const QDomElement &e, QWidget *widget, QListViewItem *i )
2053{
2054 if ( !widget || !WidgetFactory::hasItems( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( widget ) ), widget ) )
2055 return;
2056
2057 if ( ::qt_cast<QListBox*>(widget) || ::qt_cast<QComboBox*>(widget) ) {
2058 QDomElement n = e.firstChild().toElement();
2059 QPixmap pix;
2060 bool hasPixmap = FALSE;
2061 QString txt;
2062 loadItem( n, pix, txt, hasPixmap );
2063 QListBox *lb = 0;
2064 if ( ::qt_cast<QListBox*>(widget) ) {
2065 lb = (QListBox*)widget;
2066 } else {
2067 QComboBox *cb = (QComboBox*)widget;
2068 lb = cb->listBox();
2069 if (!lb) {
2070 lb = new QListBox(cb);
2071 cb->setListBox(lb);
2072 }
2073 }
2074 if ( hasPixmap ) {
2075 new QListBoxPixmap( lb, pix, txt );
2076 } else {
2077 new QListBoxText( lb, txt );
2078 }
2079 } else if ( ::qt_cast<QIconView*>(widget) ) {
2080 QDomElement n = e.firstChild().toElement();
2081 QPixmap pix;
2082 bool hasPixmap = FALSE;
2083 QString txt;
2084 loadItem( n, pix, txt, hasPixmap );
2085 QIconView *iv = (QIconView*)widget;
2086 if ( hasPixmap )
2087 new QIconViewItem( iv, txt, pix );
2088 else
2089 new QIconViewItem( iv, txt );
2090 } else if ( ::qt_cast<QListView*>(widget) ) {
2091 QDomElement n = e.firstChild().toElement();
2092 QPixmap pix;
2093 QValueList<QPixmap> pixmaps;
2094 QStringList textes;
2095 QListViewItem *item = 0;
2096 QListView *lv = (QListView*)widget;
2097 if ( i )
2098 item = new QListViewItem( i, lastItem );
2099 else
2100 item = new QListViewItem( lv, lastItem );
2101 while ( !n.isNull() ) {
2102 if ( n.tagName() == "property" ) {
2103 QString attrib = n.attribute( "name" );
2104 QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() );
2105 if ( attrib == "text" )
2106 textes << v.toString();
2107 else if ( attrib == "pixmap" ) {
2108 QString s = v.toString();
2109 if ( s.isEmpty() ) {
2110 pixmaps << QPixmap();
2111 } else {
2112 pix = loadPixmap( n.firstChild().toElement() );
2113 pixmaps << pix;
2114 }
2115 }
2116 } else if ( n.tagName() == "item" ) {
2117 item->setOpen( TRUE );
2118 createItem( n, widget, item );
2119 }
2120
2121 n = n.nextSibling().toElement();
2122 }
2123
2124 for ( int i = 0; i < lv->columns(); ++i ) {
2125 item->setText( i, textes[ i ] );
2126 item->setPixmap( i, pixmaps[ i ] );
2127 }
2128 lastItem = item;
2129 }
2130}
2131
2132QWidget *Resource::createSpacer( const QDomElement &e, QWidget *parent, QLayout *layout, Qt::Orientation o )
2133{
2134 QDomElement n = e.firstChild().toElement();
2135 int row = e.attribute( "row" ).toInt();
2136 int col = e.attribute( "column" ).toInt();
2137 int rowspan = e.attribute( "rowspan" ).toInt();
2138 int colspan = e.attribute( "colspan" ).toInt();
2139 if ( rowspan < 1 )
2140 rowspan = 1;
2141 if ( colspan < 1 )
2142 colspan = 1;
2143
2144 Spacer *spacer = (Spacer*) WidgetFactory::create( WidgetDatabase::idFromClassName("Spacer"),
2145 parent, "spacer", FALSE);
2146 spacer->setOrientation( o );
2147 spacer->setInteraciveMode( FALSE );
2148 while ( !n.isNull() ) {
2149 if ( n.tagName() == "property" )
2150 setObjectProperty( spacer, n.attribute( "name" ), n.firstChild().toElement() );
2151 n = n.nextSibling().toElement();
2152 }
2153 spacer->setInteraciveMode( TRUE );
2154 if ( formwindow )
2155 formwindow->insertWidget( spacer, pasting );
2156 if ( layout ) {
2157 if ( ::qt_cast<QBoxLayout*>(layout) )
2158 ( (QBoxLayout*)layout )->addWidget( spacer, 0, spacer->alignment() );
2159 else
2160 ( (QDesignerGridLayout*)layout )->addMultiCellWidget( spacer, row, row + rowspan - 1, col, col + colspan - 1,
2161 spacer->alignment() );
2162 }
2163 return spacer;
2164}
2165
2166/*!
2167 Attention: this function has to be in sync with Uic::setObjectProperty(). If you change one, change both.
2168*/
2169void Resource::setObjectProperty( QObject* obj, const QString &prop, const QDomElement &e )
2170{
2171 const QMetaProperty *p = obj->metaObject()->property( obj->metaObject()->findProperty( prop, TRUE ), TRUE );
2172
2173 if ( !::qt_cast<QLayout*>(obj) ) {// no layouts in metadatabase... (RS)
2174 if ( obj->inherits( "CustomWidget" ) ) {
2175 MetaDataBase::CustomWidget *cw = ( (CustomWidget*)obj )->customWidget();
2176 if ( cw && !cw->hasProperty( prop.latin1() ) && !p && prop != "toolTip" && prop != "whatsThis" )
2177 return;
2178 }
2179 MetaDataBase::setPropertyChanged( obj, prop, TRUE );
2180 }
2181
2182 QVariant defVarient;
2183 if ( e.tagName() == "font" ) {
2184 QFont f( qApp->font() );
2185 if ( obj->isWidgetType() && ( (QWidget*)obj )->parentWidget() )
2186 f = ( (QWidget*)obj )->parentWidget()->font();
2187 defVarient = QVariant( f );
2188 }
2189
2190 QString comment;
2191 QVariant v( DomTool::elementToVariant( e, defVarient, comment ) );
2192
2193 if ( !comment.isEmpty() ) {
2194 MetaDataBase::addEntry( obj );
2195 MetaDataBase::setPropertyComment( obj, prop, comment );
2196 }
2197
2198 if ( e.tagName() == "pixmap" ) {
2199 QPixmap pix = loadPixmap( e );
2200 if ( pix.isNull() )
2201 return;
2202 v = QVariant( pix );
2203 } else if ( e.tagName() == "iconset" ) {
2204 QPixmap pix = loadPixmap( e, "iconset" );
2205 if ( pix.isNull() )
2206 return;
2207 v = QVariant( QIconSet( pix ) );
2208 } else if ( e.tagName() == "image" ) {
2209 v = QVariant( loadFromCollection( v.toString() ) );
2210 }
2211
2212 if ( !p ) {
2213 MetaDataBase::setFakeProperty( obj, prop, v );
2214 if ( obj->isWidgetType() ) {
2215 if ( prop == "database" && obj != toplevel ) {
2216 QStringList lst = MetaDataBase::fakeProperty( obj, "database" ).toStringList();
2217 if ( lst.count() > 2 )
2218 dbControls.insert( obj->name(), lst[ 2 ] );
2219 else if ( lst.count() == 2 )
2220 dbTables.insert( obj->name(), lst );
2221 }
2222 return;
2223 }
2224 }
2225
2226 if ( e.tagName() == "palette" ) {
2227 QDomElement n = e.firstChild().toElement();
2228 QPalette p;
2229 while ( !n.isNull() ) {
2230 QColorGroup cg;
2231 if ( n.tagName() == "active" ) {
2232 cg = loadColorGroup( n );
2233 p.setActive( cg );
2234 } else if ( n.tagName() == "inactive" ) {
2235 cg = loadColorGroup( n );
2236 p.setInactive( cg );
2237 } else if ( n.tagName() == "disabled" ) {
2238 cg = loadColorGroup( n );
2239 p.setDisabled( cg );
2240 }
2241 n = n.nextSibling().toElement();
2242 }
2243 v = QPalette( p );
2244 } else if ( e.tagName() == "enum" && p && p->isEnumType() && prop != "resizeMode" ) {
2245 QString key( v.toString() );
2246 int vi = p->keyToValue( key );
2247 if ( vi == -1 )
2248 return; // ignore invalid properties
2249 v = QVariant( vi );
2250 } else if ( e.tagName() == "set" && p && p->isSetType() ) {
2251 QString keys( v.toString() );
2252 QStringList lst = QStringList::split( '|', keys );
2253 QStrList l;
2254 for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it )
2255 l.append( *it );
2256 v = QVariant( p->keysToValue( l ) );
2257 }
2258
2259 if ( prop == "caption" ) {
2260 QCString s1 = v.toCString();
2261 QString s2 = v.toString();
2262 if ( !s2.isEmpty() )
2263 formwindow->setCaption( s2 );
2264 else if ( !s1.isEmpty() )
2265 formwindow->setCaption( s1 );
2266 }
2267 if ( prop == "icon" ) {
2268 formwindow->setIcon( v.toPixmap() );
2269 QString pmk = MetaDataBase::pixmapKey( formwindow, v.toPixmap().serialNumber() );
2270 MetaDataBase::setPixmapKey( formwindow,
2271 formwindow->icon()->serialNumber(), pmk );
2272 }
2273
2274 if ( prop == "geometry" ) {
2275 if ( obj == toplevel ) {
2276 hadGeometry = TRUE;
2277 toplevel->resize( v.toRect().size() );
2278 return;
2279 } else if ( obj == formwindow->mainContainer() ) {
2280 hadGeometry = TRUE;
2281 formwindow->resize( v.toRect().size() );
2282 return;
2283 }
2284 }
2285
2286 if ( ::qt_cast<QLayout*>(obj) ) {
2287 if ( prop == "spacing" ) {
2288 MetaDataBase::setSpacing( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (QLayout*)obj ) ), v.toInt() );
2289 return;
2290 } else if ( prop == "margin" ) {
2291 MetaDataBase::setMargin( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (QLayout*)obj ) ), v.toInt() );
2292 return;
2293 } else if ( e.tagName() == "enum" && prop == "resizeMode" ) {
2294 MetaDataBase::setResizeMode( WidgetFactory::containerOfWidget( WidgetFactory::layoutParent( (QLayout*)obj ) ), v.toString() );
2295 return;
2296 }
2297 }
2298
2299 if ( prop == "name" ) {
2300 if ( pasting ) {
2301 QString s = v.toString();
2302 formwindow->unify( (QWidget*)obj, s, TRUE );
2303 obj->setName( s );
2304 return;
2305 } else if ( formwindow && obj == formwindow->mainContainer() ) {
2306 formwindow->setName( v.toCString() );
2307 }
2308 }
2309
2310 if ( prop == "sizePolicy" ) {
2311 QSizePolicy sp = v.toSizePolicy();
2312 sp.setHeightForWidth( ( (QWidget*)obj )->sizePolicy().hasHeightForWidth() );
2313 }
2314
2315 if ( prop == "cursor" )
2316 MetaDataBase::setCursor( (QWidget*)obj, v.toCursor() );
2317
2318 obj->setProperty( prop, v );
2319}
2320
2321
2322QString Resource::saveInCollection( const QImage &img )
2323{
2324 QString imgName = "none";
2325 QValueList<Image>::Iterator it = images.begin();
2326 for ( ; it != images.end(); ++it ) {
2327 if ( img == ( *it ).img ) {
2328 imgName = ( *it ).name;
2329 break;
2330 }
2331 }
2332
2333 if ( imgName == "none" ) {
2334 Image i;
2335 imgName = "image" + QString::number( images.count() );
2336 i.name = imgName;
2337 i.img = img;
2338 images.append( i );
2339 }
2340 return imgName;
2341}
2342
2343void Resource::saveImageData( const QImage &img, QTextStream &ts, int indent )
2344{
2345 QByteArray ba;
2346 QBuffer buf( ba );
2347 buf.open( IO_WriteOnly | IO_Translate );
2348 QString format;
2349 bool compress = FALSE;
2350 if (img.hasAlphaBuffer()) {
2351 format = "PNG";
2352 } else {
2353 format = img.depth() > 1 ? "XPM" : "XBM";
2354 compress = TRUE;
2355 }
2356 QImageIO iio( &buf, format );
2357 iio.setImage( img );
2358 iio.write();
2359 buf.close();
2360 QByteArray bazip = ba;
2361 int i = 0;
2362 if (compress) {
2363 bazip = qCompress( ba );
2364 format += ".GZ";
2365 // The first 4 bytes in qCompress() are the length of the unzipped
2366 // format. The XPM.GZ format does not use these.
2367 i = 4;
2368 }
2369 ulong len = bazip.size();
2370 ts << makeIndent( indent ) << "<data format=\"" + format + "\" length=\"" << ba.size() << "\">";
2371 static const char hexchars[] = "0123456789abcdef";
2372 for (; i < (int)len; ++i ) {
2373 uchar s = (uchar) bazip[i];
2374 ts << hexchars[s >> 4];
2375 ts << hexchars[s & 0x0f];
2376 }
2377 ts << "</data>" << endl;
2378}
2379
2380void Resource::saveImageCollection( QTextStream &ts, int indent )
2381{
2382 ts << makeIndent( indent ) << "<images>" << endl;
2383 indent++;
2384
2385 QValueList<Image>::Iterator it = images.begin();
2386 for ( ; it != images.end(); ++it ) {
2387 ts << makeIndent( indent ) << "<image name=\"" << (*it).name << "\">" << endl;
2388 indent++;
2389 saveImageData( (*it).img, ts, indent );
2390 indent--;
2391 ts << makeIndent( indent ) << "</image>" << endl;
2392 }
2393
2394 indent--;
2395 ts << makeIndent( indent ) << "</images>" << endl;
2396}
2397
2398static QImage loadImageData( QDomElement &n2 )
2399{
2400 QImage img;
2401 QString data = n2.firstChild().toText().data();
2402 const int lengthOffset = 4;
2403 int baSize = data.length() / 2 + lengthOffset;
2404 uchar *ba = new uchar[ baSize ];
2405 for ( int i = lengthOffset; i < baSize; ++i ) {
2406 char h = data[ 2 * (i-lengthOffset) ].latin1();
2407 char l = data[ 2 * (i-lengthOffset) + 1 ].latin1();
2408 uchar r = 0;
2409 if ( h <= '9' )
2410 r += h - '0';
2411 else
2412 r += h - 'a' + 10;
2413 r = r << 4;
2414 if ( l <= '9' )
2415 r += l - '0';
2416 else
2417 r += l - 'a' + 10;
2418 ba[ i ] = r;
2419 }
2420 QString format = n2.attribute( "format", "PNG" );
2421 if ( format == "XPM.GZ" || format == "XBM.GZ" ) {
2422 ulong len = n2.attribute( "length" ).toULong();
2423 if ( len < data.length() * 5 )
2424 len = data.length() * 5;
2425 // qUncompress() expects the first 4 bytes to be the expected length of
2426 // the uncompressed data
2427 ba[0] = ( len & 0xff000000 ) >> 24;
2428 ba[1] = ( len & 0x00ff0000 ) >> 16;
2429 ba[2] = ( len & 0x0000ff00 ) >> 8;
2430 ba[3] = ( len & 0x000000ff );
2431 QByteArray baunzip = qUncompress( ba, baSize );
2432 img.loadFromData( (const uchar*)baunzip.data(), baunzip.size(), format.left(format.find('.')) );
2433 } else {
2434 img.loadFromData( (const uchar*)ba+lengthOffset, baSize-lengthOffset, format );
2435 }
2436 delete [] ba;
2437 return img;
2438}
2439
2440void Resource::loadImageCollection( const QDomElement &e )
2441{
2442 QDomElement n = e.firstChild().toElement();
2443 while ( !n.isNull() ) {
2444 if ( n.tagName() == "image" ) {
2445 Image img;
2446 img.name = n.attribute( "name" );
2447 QDomElement n2 = n.firstChild().toElement();
2448 while ( !n2.isNull() ) {
2449 if ( n2.tagName() == "data" )
2450 img.img = loadImageData( n2 );
2451 n2 = n2.nextSibling().toElement();
2452 }
2453 images.append( img );
2454 n = n.nextSibling().toElement();
2455 }
2456 }
2457}
2458
2459QImage Resource::loadFromCollection( const QString &name )
2460{
2461 QValueList<Image>::Iterator it = images.begin();
2462 for ( ; it != images.end(); ++it ) {
2463 if ( ( *it ).name == name )
2464 return ( *it ).img;
2465 }
2466 return QImage();
2467}
2468
2469void Resource::saveConnections( QTextStream &ts, int indent )
2470{
2471 QValueList<MetaDataBase::Connection> connections = MetaDataBase::connections( formwindow );
2472 if ( connections.isEmpty() )
2473 return;
2474 ts << makeIndent( indent ) << "<connections>" << endl;
2475 indent++;
2476 QValueList<MetaDataBase::Connection>::Iterator it = connections.begin();
2477 for ( ; it != connections.end(); ++it ) {
2478 MetaDataBase::Connection conn = *it;
2479 if ( ( knownNames.findIndex( QString( conn.sender->name() ) ) == -1 &&
2480 qstrcmp( conn.sender->name(), "this" ) != 0 ) ||
2481 ( knownNames.findIndex( QString( conn.receiver->name() ) ) == -1 &&
2482 qstrcmp( conn.receiver->name(), "this" ) != 0 ) )
2483 continue;
2484 if ( formwindow->isMainContainer( (QWidget*)(*it).receiver ) &&
2485 !MetaDataBase::hasSlot( formwindow, MetaDataBase::normalizeFunction( (*it).slot ).latin1() ) )
2486 continue;
2487
2488 if ( conn.sender->inherits( "CustomWidget" ) ) {
2489 MetaDataBase::CustomWidget *cw = ( (CustomWidget*)conn.sender )->customWidget();
2490 if ( cw && !cw->hasSignal( conn.signal ) )
2491 continue;
2492 }
2493
2494 if ( conn.receiver->inherits( "CustomWidget" ) && !formwindow->isMainContainer( conn.receiver ) ) {
2495 MetaDataBase::CustomWidget *cw = ( (CustomWidget*)conn.receiver )->customWidget();
2496 if ( cw && !cw->hasSlot( MetaDataBase::normalizeFunction( conn.slot ).latin1() ) )
2497 continue;
2498 }
2499
2500 ts << makeIndent( indent ) << "<connection>" << endl;
2501 indent++;
2502 ts << makeIndent( indent ) << "<sender>" << entitize( conn.sender->name() ) << "</sender>" << endl;
2503 ts << makeIndent( indent ) << "<signal>" << entitize( conn.signal ) << "</signal>" << endl;
2504 ts << makeIndent( indent ) << "<receiver>" << entitize( conn.receiver->name() ) << "</receiver>" << endl;
2505 ts << makeIndent( indent ) << "<slot>" << entitize( MetaDataBase::normalizeFunction( conn.slot ) ) << "</slot>" << endl;
2506 indent--;
2507 ts << makeIndent( indent ) << "</connection>" << endl;
2508 }
2509
2510 QString lang = formwindow->project()->language();
2511 indent--;
2512 ts << makeIndent( indent ) << "</connections>" << endl;
2513}
2514
2515void Resource::loadConnections( const QDomElement &e )
2516{
2517 QDomElement n = e.firstChild().toElement();
2518 while ( !n.isNull() ) {
2519 if ( n.tagName() == "connection" ) {
2520 QString lang = n.attribute( "language", "C++" );
2521 QDomElement n2 = n.firstChild().toElement();
2522 MetaDataBase::Connection conn;
2523 while ( !n2.isNull() ) {
2524 if ( n2.tagName() == "sender" ) {
2525 conn.sender = 0;
2526 QString name = n2.firstChild().toText().data();
2527 if ( name == "this" || qstrcmp( toplevel->name(), name ) == 0 ) {
2528 conn.sender = toplevel;
2529 } else {
2530 if ( name == "this" )
2531 name = toplevel->name();
2532 QObjectList *l = toplevel->queryList( 0, name, FALSE );
2533 if ( l ) {
2534 if ( l->first() )
2535 conn.sender = l->first();
2536 delete l;
2537 l = 0;
2538 }
2539 if ( !conn.sender )
2540 conn.sender = formwindow->findAction( name );
2541 }
2542 } else if ( n2.tagName() == "signal" ) {
2543 conn.signal = n2.firstChild().toText().data();
2544 } else if ( n2.tagName() == "receiver" ) {
2545 conn.receiver = 0;
2546 QString name = n2.firstChild().toText().data();
2547 if ( name == "this" || qstrcmp( toplevel->name(), name ) == 0 ) {
2548 conn.receiver = toplevel;
2549 } else {
2550 QObjectList *l = toplevel->queryList( 0, name, FALSE );
2551 if ( l ) {
2552 if ( l->first() )
2553 conn.receiver = l->first();
2554 delete l;
2555 l = 0;
2556 }
2557 if ( !conn.receiver )
2558 conn.receiver = formwindow->findAction( name );
2559 }
2560 } else if ( n2.tagName() == "slot" ) {
2561 conn.slot = n2.firstChild().toText().data();
2562 }
2563 n2 = n2.nextSibling().toElement();
2564 }
2565 if ( formwindow ) {
2566 if ( conn.sender == formwindow )
2567 conn.sender = formwindow->mainContainer();
2568 if ( conn.receiver == formwindow )
2569 conn.receiver = formwindow->mainContainer();
2570 }
2571 if ( conn.sender && conn.receiver ) {
2572 if ( lang == "C++" ) {
2573 MetaDataBase::addConnection( formwindow ? formwindow : toplevel,
2574 conn.sender, conn.signal, conn.receiver, conn.slot );
2575 }
2576 }
2577 } else if ( n.tagName() == "slot" ) { // compatibility with 2.x
2578 MetaDataBase::Function slot;
2579 slot.specifier = n.attribute( "specifier", "virtual" );
2580 if ( slot.specifier.isEmpty() )
2581 slot.specifier = "virtual";
2582 slot.access = n.attribute( "access", "public" );
2583 if ( slot.access.isEmpty() )
2584 slot.access = "public";
2585 slot.language = n.attribute( "language", "C++" );
2586 slot.returnType = n.attribute( "returnType", "void" );
2587 if ( slot.returnType.isEmpty() )
2588 slot.returnType = "void";
2589 slot.function = n.firstChild().toText().data();
2590 if ( !MetaDataBase::hasFunction( formwindow, slot.function, TRUE ) )
2591 MetaDataBase::addFunction( formwindow, slot.function, slot.specifier,
2592 slot.access, "slot", slot.language, slot.returnType );
2593 else
2594 MetaDataBase::changeFunctionAttributes( formwindow, slot.function, slot.function,
2595 slot.specifier, slot.access,
2596 "slot", slot.language, slot.returnType );
2597 }
2598 n = n.nextSibling().toElement();
2599 }
2600}
2601
2602void Resource::saveCustomWidgets( QTextStream &ts, int indent )
2603{
2604 ts << makeIndent( indent ) << "<customwidgets>" << endl;
2605 indent++;
2606
2607 QPtrList<MetaDataBase::CustomWidget> *lst = MetaDataBase::customWidgets();
2608 for ( MetaDataBase::CustomWidget *w = lst->first(); w; w = lst->next() ) {
2609 if ( usedCustomWidgets.findIndex( w->className ) == -1 )
2610 continue;
2611 ts << makeIndent( indent ) << "<customwidget>" << endl;
2612 indent++;
2613 ts << makeIndent( indent ) << "<class>" << w->className << "</class>" << endl;
2614 ts << makeIndent( indent ) << "<header location=\""
2615 << ( w->includePolicy == MetaDataBase::CustomWidget::Local ? "local" : "global" )
2616 << "\">" << w->includeFile << "</header>" << endl;
2617 ts << makeIndent( indent ) << "<sizehint>" << endl;
2618 indent++;
2619 ts << makeIndent( indent ) << "<width>" << w->sizeHint.width() << "</width>" << endl;
2620 ts << makeIndent( indent ) << "<height>" << w->sizeHint.height() << "</height>" << endl;
2621 indent--;
2622 ts << makeIndent( indent ) << "</sizehint>" << endl;
2623 ts << makeIndent( indent ) << "<container>" << (int)w->isContainer << "</container>" << endl;
2624 ts << makeIndent( indent ) << "<sizepolicy>" << endl;
2625 indent++;
2626 ts << makeIndent( indent ) << "<hordata>" << (int)w->sizePolicy.horData() << "</hordata>" << endl;
2627 ts << makeIndent( indent ) << "<verdata>" << (int)w->sizePolicy.verData() << "</verdata>" << endl;
2628 ts << makeIndent( indent ) << "<horstretch>" << (int)w->sizePolicy.horStretch() << "</horstretch>" << endl;
2629 ts << makeIndent( indent ) << "<verstretch>" << (int)w->sizePolicy.verStretch() << "</verstretch>" << endl;
2630 indent--;
2631 ts << makeIndent( indent ) << "</sizepolicy>" << endl;
2632 ts << makeIndent( indent ) << "<pixmap>" << saveInCollection( w->pixmap->convertToImage() ) << "</pixmap>" << endl;
2633 if ( !w->lstSignals.isEmpty() ) {
2634 for ( QValueList<QCString>::Iterator it = w->lstSignals.begin(); it != w->lstSignals.end(); ++it )
2635 ts << makeIndent( indent ) << "<signal>" << entitize( *it ) << "</signal>" << endl;
2636 }
2637 if ( !w->lstSlots.isEmpty() ) {
2638 for ( QValueList<MetaDataBase::Function>::Iterator it = w->lstSlots.begin(); it != w->lstSlots.end(); ++it )
2639 ts << makeIndent( indent ) << "<slot access=\"" << (*it).access << "\" specifier=\""
2640 << (*it).specifier << "\">" << entitize( (*it).function ) << "</slot>" << endl;
2641 }
2642 if ( !w->lstProperties.isEmpty() ) {
2643 for ( QValueList<MetaDataBase::Property>::Iterator it = w->lstProperties.begin(); it != w->lstProperties.end(); ++it )
2644 ts << makeIndent( indent ) << "<property type=\"" << (*it).type << "\">" << entitize( (*it).property ) << "</property>" << endl;
2645 }
2646 indent--;
2647 ts << makeIndent( indent ) << "</customwidget>" << endl;
2648 }
2649
2650
2651 indent--;
2652 ts << makeIndent( indent ) << "</customwidgets>" << endl;
2653}
2654
2655void Resource::loadCustomWidgets( const QDomElement &e, Resource *r )
2656{
2657 QDomElement n = e.firstChild().toElement();
2658 while ( !n.isNull() ) {
2659 if ( n.tagName() == "customwidget" ) {
2660 QDomElement n2 = n.firstChild().toElement();
2661 MetaDataBase::CustomWidget *w = new MetaDataBase::CustomWidget;
2662 while ( !n2.isNull() ) {
2663 if ( n2.tagName() == "class" ) {
2664 w->className = n2.firstChild().toText().data();
2665 } else if ( n2.tagName() == "header" ) {
2666 w->includeFile = n2.firstChild().toText().data();
2667 QString s = n2.attribute( "location" );
2668 if ( s != "local" )
2669 w->includePolicy = MetaDataBase::CustomWidget::Global;
2670 else
2671 w->includePolicy = MetaDataBase::CustomWidget::Local;
2672 } else if ( n2.tagName() == "sizehint" ) {
2673 QDomElement n3 = n2.firstChild().toElement();
2674 while ( !n3.isNull() ) {
2675 if ( n3.tagName() == "width" )
2676 w->sizeHint.setWidth( n3.firstChild().toText().data().toInt() );
2677 else if ( n3.tagName() == "height" )
2678 w->sizeHint.setHeight( n3.firstChild().toText().data().toInt() );
2679 n3 = n3.nextSibling().toElement();
2680 }
2681 } else if ( n2.tagName() == "sizepolicy" ) {
2682 QDomElement n3 = n2.firstChild().toElement();
2683 while ( !n3.isNull() ) {
2684 if ( n3.tagName() == "hordata" )
2685 w->sizePolicy.setHorData( (QSizePolicy::SizeType)n3.firstChild().toText().data().toInt() );
2686 else if ( n3.tagName() == "verdata" )
2687 w->sizePolicy.setVerData( (QSizePolicy::SizeType)n3.firstChild().toText().data().toInt() );
2688 else if ( n3.tagName() == "horstretch" )
2689 w->sizePolicy.setHorStretch( n3.firstChild().toText().data().toInt() );
2690 else if ( n3.tagName() == "verstretch" )
2691 w->sizePolicy.setVerStretch( n3.firstChild().toText().data().toInt() );
2692 n3 = n3.nextSibling().toElement();
2693 }
2694 } else if ( n2.tagName() == "pixmap" ) {
2695 QPixmap pix;
2696 if ( r ) {
2697 pix = r->loadPixmap( n2 );
2698 } else {
2699 QDomElement n3 = n2.firstChild().toElement();
2700 QImage img;
2701 while ( !n3.isNull() ) {
2702 if ( n3.tagName() == "data" ) {
2703 img = loadImageData( n3 );
2704 }
2705 n3 = n3.nextSibling().toElement();
2706 }
2707 pix.convertFromImage( img );
2708 }
2709 w->pixmap = new QPixmap( pix );
2710 } else if ( n2.tagName() == "signal" ) {
2711 w->lstSignals.append( n2.firstChild().toText().data().latin1() );
2712 } else if ( n2.tagName() == "container" ) {
2713 w->isContainer = (bool)n2.firstChild().toText().data().toInt();
2714 } else if ( n2.tagName() == "slot" ) {
2715 MetaDataBase::Function function;
2716 function.function = n2.firstChild().toText().data().latin1();
2717 function.access = n2.attribute( "access" );
2718 function.type = "slot";
2719 w->lstSlots.append( function );
2720 } else if ( n2.tagName() == "property" ) {
2721 MetaDataBase::Property property;
2722 property.property = n2.firstChild().toText().data().latin1();
2723 property.type = n2.attribute( "type" );
2724 w->lstProperties.append( property );
2725 }
2726 n2 = n2.nextSibling().toElement();
2727 }
2728 MetaDataBase::addCustomWidget( w );
2729 }
2730 n = n.nextSibling().toElement();
2731 }
2732}
2733
2734void Resource::saveTabOrder( QTextStream &ts, int indent )
2735{
2736 QWidgetList l = MetaDataBase::tabOrder( toplevel );
2737 if ( l.isEmpty() )
2738 return;
2739
2740 ts << makeIndent( indent ) << "<tabstops>" << endl;
2741 indent++;
2742
2743 for ( QWidget *w = l.first(); w; w = l.next() ) {
2744 if ( w->testWState( Qt::WState_ForceHide ) || knownNames.findIndex( w->name() ) == -1 )
2745 continue;
2746 ts << makeIndent( indent ) << "<tabstop>" << w->name() << "</tabstop>" << endl;
2747 }
2748
2749 indent--;
2750 ts << makeIndent( indent ) << "</tabstops>" << endl;
2751}
2752
2753void Resource::loadTabOrder( const QDomElement &e )
2754{
2755 QWidget *last = 0;
2756 QDomElement n = e.firstChild().toElement();
2757 QWidgetList widgets;
2758 while ( !n.isNull() ) {
2759 if ( n.tagName() == "tabstop" ) {
2760 QString name = n.firstChild().toText().data();
2761 if ( name.isEmpty() )
2762 continue;
2763 QObjectList *l = toplevel->queryList( 0, name, FALSE );
2764 if ( l ) {
2765 if ( l->first() ) {
2766 QWidget *w = (QWidget*)l->first();
2767 widgets.append( w );
2768 if ( last )
2769 toplevel->setTabOrder( last, w );
2770 last = w;
2771 }
2772 delete l;
2773 }
2774 }
2775 n = n.nextSibling().toElement();
2776 }
2777
2778 if ( !widgets.isEmpty() )
2779 MetaDataBase::setTabOrder( toplevel, widgets );
2780}
2781
2782void Resource::saveMetaInfoBefore( QTextStream &ts, int indent )
2783{
2784 MetaDataBase::MetaInfo info = MetaDataBase::metaInfo( formwindow );
2785 QString cn;
2786 if ( info.classNameChanged && !info.className.isEmpty() )
2787 cn = info.className;
2788 else
2789 cn = formwindow->name();
2790 ts << makeIndent( indent ) << "<class>" << entitize( cn ) << "</class>" << endl;
2791 if ( !info.comment.isEmpty() )
2792 ts << makeIndent( indent ) << "<comment>" << entitize( info.comment ) << "</comment>" << endl;
2793 if ( !info.author.isEmpty() )
2794 ts << makeIndent( indent ) << "<author>" << entitize( info.author ) << "</author>" << endl;
2795}
2796
2797void Resource::saveMetaInfoAfter( QTextStream &ts, int indent )
2798{
2799 MetaDataBase::MetaInfo info = MetaDataBase::metaInfo( formwindow );
2800 if ( !langIface || formwindow->project()->isCpp() ) {
2801 QValueList<MetaDataBase::Include> includes = MetaDataBase::includes( formwindow );
2802 QString extensionInclude;
2803 bool needExtensionInclude = FALSE;
2804 if ( langIface &&
2805 formwindow->formFile()->hasFormCode() &&
2806 formwindow->formFile()->codeFileState() != FormFile::Deleted ) {
2807 extensionInclude = QFileInfo( currFileName ).fileName() + langIface->formCodeExtension();
2808 needExtensionInclude = TRUE;
2809 }
2810 if ( !includes.isEmpty() || needExtensionInclude ) {
2811 ts << makeIndent( indent ) << "<includes>" << endl;
2812 indent++;
2813
2814 for ( QValueList<MetaDataBase::Include>::Iterator it = includes.begin(); it != includes.end(); ++it ) {
2815 ts << makeIndent( indent ) << "<include location=\"" << (*it).location
2816 << "\" impldecl=\"" << (*it).implDecl << "\">" << (*it).header << "</include>" << endl;
2817 if ( needExtensionInclude )
2818 needExtensionInclude = (*it).header != extensionInclude;
2819 }
2820
2821 if ( needExtensionInclude )
2822 ts << makeIndent( indent ) << "<include location=\"local\" impldecl=\"in implementation\">"
2823 << extensionInclude << "</include>" << endl;
2824 indent--;
2825 ts << makeIndent( indent ) << "</includes>" << endl;
2826 }
2827
2828 QStringList forwards = MetaDataBase::forwards( formwindow );
2829 if ( !forwards.isEmpty() ) {
2830 ts << makeIndent( indent ) << "<forwards>" << endl;
2831 indent++;
2832 for ( QStringList::Iterator it2 = forwards.begin(); it2 != forwards.end(); ++it2 )
2833 ts << makeIndent( indent ) << "<forward>" << entitize( *it2 ) << "</forward>" << endl;
2834 indent--;
2835 ts << makeIndent( indent ) << "</forwards>" << endl;
2836 }
2837 QValueList<MetaDataBase::Variable> varLst = MetaDataBase::variables( formwindow );
2838 if ( !varLst.isEmpty() ) {
2839 ts << makeIndent( indent ) << "<variables>" << endl;
2840 indent++;
2841
2842 QValueList<MetaDataBase::Variable>::Iterator it = varLst.begin();
2843 for ( ; it != varLst.end(); ++it ) {
2844 ts << makeIndent( indent ) << "<variable";
2845 if ( (*it).varAccess != "protected" )
2846 ts << " access=\"" << (*it).varAccess << "\"";
2847
2848 ts << ">" << entitize( (*it).varName ) << "</variable>" << endl;
2849 }
2850 indent--;
2851 ts << makeIndent( indent ) << "</variables>" << endl;
2852 }
2853 QStringList sigs = MetaDataBase::signalList( formwindow );
2854 if ( !sigs.isEmpty() ) {
2855 ts << makeIndent( indent ) << "<signals>" << endl;
2856 indent++;
2857 for ( QStringList::Iterator it3 = sigs.begin(); it3 != sigs.end(); ++it3 )
2858 ts << makeIndent( indent ) << "<signal>" << entitize( *it3 ) << "</signal>" << endl;
2859 indent--;
2860 ts << makeIndent( indent ) << "</signals>" << endl;
2861 }
2862
2863 QValueList<MetaDataBase::Function> slotList = MetaDataBase::slotList( formwindow );
2864 if ( !slotList.isEmpty() ) {
2865 ts << makeIndent( indent ) << "<slots>" << endl;
2866 indent++;
2867 QString lang = formwindow->project()->language();
2868 QValueList<MetaDataBase::Function>::Iterator it = slotList.begin();
2869 for ( ; it != slotList.end(); ++it ) {
2870 MetaDataBase::Function function = *it;
2871 ts << makeIndent( indent ) << "<slot";
2872 if ( function.access != "public" )
2873 ts << " access=\"" << function.access << "\"";
2874 if ( function.specifier != "virtual" )
2875 ts << " specifier=\"" << function.specifier << "\"";
2876 if ( function.language != "C++" )
2877 ts << " language=\"" << function.language<< "\"";
2878 if ( function.returnType != "void" )
2879 ts << " returnType=\"" << entitize( function.returnType ) << "\"";
2880 ts << ">" << entitize( function.function ) << "</slot>" << endl;
2881 }
2882 indent--;
2883 ts << makeIndent( indent ) << "</slots>" << endl;
2884 }
2885
2886 QValueList<MetaDataBase::Function> functionList = MetaDataBase::functionList( formwindow, TRUE );
2887 if ( !functionList.isEmpty() ) {
2888 ts << makeIndent( indent ) << "<functions>" << endl;
2889 indent++;
2890 QString lang = formwindow->project()->language();
2891 QValueList<MetaDataBase::Function>::Iterator it = functionList.begin();
2892 for ( ; it != functionList.end(); ++it ) {
2893 MetaDataBase::Function function = *it;
2894 ts << makeIndent( indent ) << "<function";
2895 if ( function.access != "public" )
2896 ts << " access=\"" << function.access << "\"";
2897 if ( function.specifier != "virtual" )
2898 ts << " specifier=\"" << function.specifier << "\"";
2899 if ( function.language != "C++" )
2900 ts << " language=\"" << function.language<< "\"";
2901 if ( function.returnType != "void" )
2902 ts << " returnType=\"" << entitize( function.returnType ) << "\"";
2903 ts << ">" << entitize( function.function ) << "</function>" << endl;
2904 }
2905 indent--;
2906 ts << makeIndent( indent ) << "</functions>" << endl;
2907 }
2908 }
2909
2910 if ( formwindow && formwindow->savePixmapInline() )
2911 ;
2912 else if ( formwindow && formwindow->savePixmapInProject() )
2913 ts << makeIndent( indent ) << "<pixmapinproject/>" << endl;
2914 else
2915 ts << makeIndent( indent ) << "<pixmapfunction>" << formwindow->pixmapLoaderFunction() << "</pixmapfunction>" << endl;
2916 if ( !( exportMacro = MetaDataBase::exportMacro( formwindow->mainContainer() ) ).isEmpty() )
2917 ts << makeIndent( indent ) << "<exportmacro>" << exportMacro << "</exportmacro>" << endl;
2918 if ( formwindow ) {
2919 ts << makeIndent( indent ) << "<layoutdefaults spacing=\"" << formwindow->layoutDefaultSpacing()
2920 << "\" margin=\"" << formwindow->layoutDefaultMargin() << "\"/>" << endl;
2921 if ( formwindow->hasLayoutFunctions() ) {
2922 QString s = "";
2923 QString m = "";
2924 if ( !formwindow->spacingFunction().isEmpty() )
2925 s = QString( " spacing=\"%1\"" ).arg( formwindow->spacingFunction() );
2926 if ( !formwindow->marginFunction().isEmpty() )
2927 m = QString( " margin=\"%1\"" ).arg( formwindow->marginFunction() );
2928 ts << makeIndent( indent ) << "<layoutfunctions" << s << m << "/>" << endl;
2929 }
2930 }
2931}
2932
2933void Resource::saveIncludeHints( QTextStream &ts, int indent )
2934{
2935 if ( includeHints.isEmpty() )
2936 return;
2937 ts << makeIndent( indent ) << "<includehints>" << endl;
2938 indent++;
2939 for ( QStringList::Iterator it = includeHints.begin(); it != includeHints.end(); ++it )
2940 ts << makeIndent( indent ) << "<includehint>" << *it << "</includehint>" << endl;
2941 indent--;
2942 ts << makeIndent( indent ) << "</includehints>" << endl;
2943}
2944
2945QColorGroup Resource::loadColorGroup( const QDomElement &e )
2946{
2947 QColorGroup cg;
2948 int r = -1;
2949 QDomElement n = e.firstChild().toElement();
2950 QColor col;
2951 while ( !n.isNull() ) {
2952 if ( n.tagName() == "color" ) {
2953 r++;
2954 cg.setColor( (QColorGroup::ColorRole)r, (col = DomTool::readColor( n ) ) );
2955 } else if ( n.tagName() == "pixmap" ) {
2956 QPixmap pix = loadPixmap( n );
2957 cg.setBrush( (QColorGroup::ColorRole)r, QBrush( col, pix ) );
2958 }
2959 n = n.nextSibling().toElement();
2960 }
2961 return cg;
2962}
2963
2964void Resource::saveChildActions( QAction *a, QTextStream &ts, int indent )
2965{
2966 if ( !a->children() )
2967 return;
2968 QObjectListIt it( *a->children() );
2969 while ( it.current() ) {
2970 QObject *o = it.current();
2971 ++it;
2972 if ( !::qt_cast<QAction*>(o) )
2973 continue;
2974 QAction *ac = (QAction*)o;
2975 bool isGroup = ::qt_cast<QActionGroup*>(ac);
2976 if ( isGroup )
2977 ts << makeIndent( indent ) << "<actiongroup>" << endl;
2978 else
2979 ts << makeIndent( indent ) << "<action>" << endl;
2980 indent++;
2981 saveObjectProperties( ac, ts, indent );
2982 indent--;
2983 if ( isGroup ) {
2984 indent++;
2985 saveChildActions( ac, ts, indent );
2986 indent--;
2987 }
2988 if ( isGroup )
2989 ts << makeIndent( indent ) << "</actiongroup>" << endl;
2990 else
2991 ts << makeIndent( indent ) << "</action>" << endl;
2992 }
2993}
2994
2995void Resource::saveActions( const QPtrList<QAction> &actions, QTextStream &ts, int indent )
2996{
2997 if ( actions.isEmpty() )
2998 return;
2999 ts << makeIndent( indent ) << "<actions>" << endl;
3000 indent++;
3001 QPtrListIterator<QAction> it( actions );
3002 while ( it.current() ) {
3003 QAction *a = it.current();
3004 bool isGroup = ::qt_cast<QActionGroup*>(a);
3005 if ( isGroup )
3006 ts << makeIndent( indent ) << "<actiongroup>" << endl;
3007 else
3008 ts << makeIndent( indent ) << "<action>" << endl;
3009 indent++;
3010 saveObjectProperties( a, ts, indent );
3011 indent--;
3012 if ( isGroup ) {
3013 indent++;
3014 saveChildActions( a, ts, indent );
3015 indent--;
3016 }
3017 if ( isGroup )
3018 ts << makeIndent( indent ) << "</actiongroup>" << endl;
3019 else
3020 ts << makeIndent( indent ) << "</action>" << endl;
3021 ++it;
3022 }
3023 indent--;
3024 ts << makeIndent( indent ) << "</actions>" << endl;
3025}
3026
3027void Resource::loadChildAction( QObject *parent, const QDomElement &e )
3028{
3029 QDomElement n = e;
3030 QAction *a = 0;
3031 if ( n.tagName() == "action" ) {
3032 a = new QDesignerAction( parent );
3033 MetaDataBase::addEntry( a );
3034 QDomElement n2 = n.firstChild().toElement();
3035 bool hasMenuText = FALSE;
3036 while ( !n2.isNull() ) {
3037 if ( n2.tagName() == "property" ) {
3038 QDomElement n3(n2); // don't modify n2
3039 QString prop = n3.attribute( "name" );
3040 if (prop == "menuText")
3041 hasMenuText = TRUE;
3042 QDomElement value(n3.firstChild().toElement());
3043 setObjectProperty( a, prop, value );
3044 if (!hasMenuText && uiFileVersion < "3.3" && prop == "text")
3045 setObjectProperty( a, "menuText", value );
3046 }
3047 n2 = n2.nextSibling().toElement();
3048 }
3049 if ( !::qt_cast<QAction*>(parent) )
3050 formwindow->actionList().append( a );
3051 } else if ( n.tagName() == "actiongroup" ) {
3052 a = new QDesignerActionGroup( parent );
3053 MetaDataBase::addEntry( a );
3054 QDomElement n2 = n.firstChild().toElement();
3055 bool hasMenuText = FALSE;
3056 while ( !n2.isNull() ) {
3057 if ( n2.tagName() == "property" ) {
3058 QDomElement n3(n2); // don't modify n2
3059 QString prop = n3.attribute( "name" );
3060 if (prop == "menuText")
3061 hasMenuText = TRUE;
3062 QDomElement value = n3.firstChild().toElement();
3063 setObjectProperty( a, prop, value );
3064 if (!hasMenuText && uiFileVersion < "3.3" && prop == "text")
3065 setObjectProperty( a, "menuText", value );
3066 } else if ( n2.tagName() == "action" ||
3067 n2.tagName() == "actiongroup" ) {
3068 loadChildAction( a, n2 );
3069 }
3070 n2 = n2.nextSibling().toElement();
3071 }
3072 if ( !::qt_cast<QAction*>(parent) )
3073 formwindow->actionList().append( a );
3074 }
3075}
3076
3077void Resource::loadActions( const QDomElement &e )
3078{
3079 QDomElement n = e.firstChild().toElement();
3080 while ( !n.isNull() ) {
3081 if ( n.tagName() == "action" ) {
3082 loadChildAction( formwindow, n );
3083 } else if ( n.tagName() == "actiongroup" ) {
3084 loadChildAction( formwindow, n );
3085 }
3086 n = n.nextSibling().toElement();
3087 }
3088}
3089
3090void Resource::saveToolBars( QMainWindow *mw, QTextStream &ts, int indent )
3091{
3092 ts << makeIndent( indent ) << "<toolbars>" << endl;
3093 indent++;
3094
3095 QPtrList<QToolBar> tbList;
3096 for ( int i = 0; i <= (int)Qt::DockMinimized; ++i ) {
3097 tbList = mw->toolBars( (Qt::Dock)i );
3098 if ( tbList.isEmpty() )
3099 continue;
3100 for ( QToolBar *tb = tbList.first(); tb; tb = tbList.next() ) {
3101 if ( tb->isHidden() )
3102 continue;
3103 ts << makeIndent( indent ) << "<toolbar dock=\"" << i << "\">" << endl;
3104 indent++;
3105 saveObjectProperties( tb, ts, indent );
3106 QPtrList<QAction> actionList = ( (QDesignerToolBar*)tb )->insertedActions();
3107 for ( QAction *a = actionList.first(); a; a = actionList.next() ) {
3108 if ( ::qt_cast<QSeparatorAction*>(a) ) {
3109 ts << makeIndent( indent ) << "<separator/>" << endl;
3110 } else {
3111 if ( ::qt_cast<QDesignerAction*>(a) && !( (QDesignerAction*)a )->supportsMenu() ) {
3112 QWidget *w = ( (QDesignerAction*)a )->widget();
3113 ts << makeIndent( indent ) << "<widget class=\""
3114 << WidgetFactory::classNameOf( w ) << "\">" << endl;
3115 indent++;
3116 const char *className = WidgetFactory::classNameOf( w );
3117 if ( w->isA( "CustomWidget" ) )
3118 usedCustomWidgets << QString( className );
3119 if ( WidgetFactory::hasItems( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( w ) ), w ) )
3120 saveItems( w, ts, indent );
3121 saveObjectProperties( w, ts, indent );
3122 indent--;
3123 ts << makeIndent( indent ) << "</widget>" << endl;
3124 } else {
3125 ts << makeIndent( indent ) << "<action name=\"" << a->name() << "\"/>" << endl;
3126 }
3127 }
3128 }
3129 indent--;
3130 ts << makeIndent( indent ) << "</toolbar>" << endl;
3131 }
3132 }
3133 indent--;
3134 ts << makeIndent( indent ) << "</toolbars>" << endl;
3135}
3136
3137void Resource::saveMenuBar( QMainWindow *mw, QTextStream &ts, int indent )
3138{
3139 MenuBarEditor *mb = (MenuBarEditor *)mw->child( 0, "MenuBarEditor" );
3140 if ( !mb )
3141 return;
3142 ts << makeIndent( indent ) << "<menubar>" << endl;
3143 indent++;
3144 MetaDataBase::setPropertyChanged( mb, "name", TRUE ); // FIXME: remove
3145 saveObjectProperties( mb, ts, indent );
3146
3147 for ( int i = 0; i < (int)mb->count(); ++i ) {
3148 MenuBarEditorItem *m = mb->item( i );
3149 if ( !m )
3150 continue;
3151 if ( m->isSeparator() ) {
3152 ts << makeIndent( indent ) << "<separator/>" << endl;
3153 } else {
3154 ts << makeIndent( indent ) << "<item text=\"" << entitize( m->menuText() )
3155 << "\" name=\"" << entitize( m->menu()->name() ) << "\">" << endl;
3156 indent++;
3157 savePopupMenu( m->menu(), mw, ts, indent );
3158 indent--;
3159 ts << makeIndent( indent ) << "</item>" << endl;
3160 }
3161 }
3162 indent--;
3163 ts << makeIndent( indent ) << "</menubar>" << endl;
3164}
3165
3166void Resource::savePopupMenu( PopupMenuEditor *pm, QMainWindow *mw, QTextStream &ts, int indent )
3167{
3168 for ( PopupMenuEditorItem *i = pm->items()->first(); i; i = pm->items()->next() ) {
3169 QAction *a = i->action();
3170 if ( ::qt_cast<QSeparatorAction*>(a) )
3171 ts << makeIndent( indent ) << "<separator/>" << endl;
3172 else if ( ::qt_cast<QDesignerAction*>(a) )
3173 ts << makeIndent( indent ) << "<action name=\"" << a->name() << "\"/>" << endl;
3174 else if ( ::qt_cast<QDesignerActionGroup*>(a) )
3175 ts << makeIndent( indent ) << "<actiongroup name=\"" << a->name() << "\"/>" << endl;
3176 PopupMenuEditor *s = i->subMenu();
3177 if ( s && s->count() ) {
3178 QString n = s->name();
3179 ts << makeIndent( indent ) << "<item text=\"" << entitize( a->menuText() )
3180 << "\" name=\"" << entitize( n )
3181 << "\" accel=\"" << entitize( a->accel() )
3182 << "\">" << endl;
3183 indent++;
3184 savePopupMenu( s, mw, ts, indent );
3185 indent--;
3186 ts << makeIndent( indent ) << "</item>" << endl;
3187 }
3188 }
3189}
3190
3191void Resource::loadToolBars( const QDomElement &e )
3192{
3193 QDomElement n = e.firstChild().toElement();
3194 QMainWindow *mw = ( (QMainWindow*)formwindow->mainContainer() );
3195 QDesignerToolBar *tb = 0;
3196 while ( !n.isNull() ) {
3197 if ( n.tagName() == "toolbar" ) {
3198 Qt::Dock dock = (Qt::Dock)n.attribute( "dock" ).toInt();
3199 tb = new QDesignerToolBar( mw, dock );
3200 QDomElement n2 = n.firstChild().toElement();
3201 while ( !n2.isNull() ) {
3202 if ( n2.tagName() == "action" ) {
3203 QAction *a = formwindow->findAction( n2.attribute( "name" ) );
3204 if ( a ) {
3205 a->addTo( tb );
3206 tb->addAction( a );
3207 }
3208 } else if ( n2.tagName() == "separator" ) {
3209 QAction *a = new QSeparatorAction( 0 );
3210 a->addTo( tb );
3211 tb->addAction( a );
3212 } else if ( n2.tagName() == "widget" ) {
3213 QWidget *w = (QWidget*)createObject( n2, tb );
3214 QDesignerAction *a = new QDesignerAction( w, tb );
3215 a->addTo( tb );
3216 tb->addAction( a );
3217 tb->installEventFilters( w );
3218 } else if ( n2.tagName() == "property" ) {
3219 setObjectProperty( tb, n2.attribute( "name" ), n2.firstChild().toElement() );
3220 }
3221 n2 = n2.nextSibling().toElement();
3222 }
3223 }
3224 n = n.nextSibling().toElement();
3225 }
3226}
3227
3228void Resource::loadMenuBar( const QDomElement &e )
3229{
3230 QDomElement n = e.firstChild().toElement();
3231 QMainWindow *mw = (QMainWindow*)formwindow->mainContainer();
3232 MenuBarEditor *mb = new MenuBarEditor( formwindow, mw );
3233 MetaDataBase::addEntry( mb );
3234 while ( !n.isNull() ) {
3235 if ( n.tagName() == "item" ) {
3236 PopupMenuEditor * popup = new PopupMenuEditor( formwindow, mw );
3237 loadPopupMenu( popup, n );
3238 popup->setName( n.attribute( "name" ) );
3239 mb->insertItem( n.attribute( "text" ), popup );
3240 MetaDataBase::addEntry( popup );
3241 } else if ( n.tagName() == "property" ) {
3242 setObjectProperty( mb, n.attribute( "name" ), n.firstChild().toElement() );
3243 } else if ( n.tagName() == "separator" ) {
3244 mb->insertSeparator();
3245 }
3246 n = n.nextSibling().toElement();
3247 }
3248}
3249
3250void Resource::loadPopupMenu( PopupMenuEditor *p, const QDomElement &e )
3251{
3252 MetaDataBase::addEntry( p );
3253 QDomElement n = e.firstChild().toElement();
3254 QAction *a = 0;
3255 while ( !n.isNull() ) {
3256 if ( n.tagName() == "action" || n.tagName() == "actiongroup") {
3257 a = formwindow->findAction( n.attribute( "name" ) );
3258 if ( a )
3259 p->insert( a );
3260 }
3261 if ( n.tagName() == "item" ) {
3262 PopupMenuEditorItem *i = p->at( p->find( a ) );
3263 if ( i ) {
3264 QString name = n.attribute( "name" );
3265 formwindow->unify( i, name, TRUE );
3266 i->setName( name );
3267 MetaDataBase::addEntry( i );
3268 loadPopupMenu( i->subMenu(), n );
3269 }
3270 } else if ( n.tagName() == "separator" ) {
3271 a = new QSeparatorAction( 0 );
3272 p->insert( a );
3273 }
3274 n = n.nextSibling().toElement();
3275 }
3276}
3277
3278bool Resource::saveFormCode( FormFile *formfile, LanguageInterface * /*langIface*/ )
3279{
3280 QString lang = formfile->project()->language();
3281 if ( formfile->hasTempFileName() ||
3282 formfile->code().isEmpty() ||
3283 !formfile->hasFormCode() ||
3284 !formfile->isModified(FormFile::WFormCode) )
3285 return TRUE; // There is no code to be saved.
3286 return saveCode( formfile->project()->makeAbsolute(formfile->codeFile()),
3287 formfile->code() );
3288}
3289
3290void Resource::loadExtraSource( FormFile *formfile, const QString &currFileName,
3291 LanguageInterface *langIface, bool hasFunctions )
3292{
3293 QString lang = "Qt Script";
3294 if ( MainWindow::self )
3295 lang = MainWindow::self->currProject()->language();
3296 LanguageInterface *iface = langIface;
3297 if ( hasFunctions || !iface )
3298 return;
3299 QValueList<LanguageInterface::Function> functions;
3300 QStringList forwards;
3301 QStringList includesImpl;
3302 QStringList includesDecl;
3303 QStringList vars;
3304 QValueList<LanguageInterface::Connection> connections;
3305
3306 iface->loadFormCode( formfile->formName(),
3307 currFileName + iface->formCodeExtension(),
3308 functions,
3309 vars,
3310 connections );
3311
3312 QFile f( formfile->project()->makeAbsolute( formfile->codeFile() ) );
3313 QString code;
3314 if ( f.open( IO_ReadOnly ) ) {
3315 QTextStream ts( &f );
3316 code = ts.read();
3317 }
3318 formfile->setCode( code );
3319
3320 if ( !MainWindow::self || !MainWindow::self->currProject()->isCpp() )
3321 MetaDataBase::setupConnections( formfile, connections );
3322
3323 for ( QValueList<LanguageInterface::Function>::Iterator fit = functions.begin();
3324 fit != functions.end(); ++fit ) {
3325
3326 if ( MetaDataBase::hasFunction( formfile->formWindow() ?
3327 (QObject*)formfile->formWindow() :
3328 (QObject*)formfile,
3329 (*fit).name.latin1() ) ) {
3330 QString access = (*fit).access;
3331 if ( !MainWindow::self || !MainWindow::self->currProject()->isCpp() )
3332 MetaDataBase::changeFunction( formfile->formWindow() ?
3333 (QObject*)formfile->formWindow() :
3334 (QObject*)formfile,
3335 (*fit).name,
3336 (*fit).name,
3337 QString::null );
3338 } else {
3339 QString access = (*fit).access;
3340 if ( access.isEmpty() )
3341 access = "protected";
3342 QString type = "function";
3343 if ( (*fit).returnType == "void" )
3344 type = "slot";
3345 MetaDataBase::addFunction( formfile->formWindow() ?
3346 (QObject*)formfile->formWindow() :
3347 (QObject*)formfile,
3348 (*fit).name.latin1(), "virtual", (*fit).access,
3349 type, lang, (*fit).returnType );
3350 }
3351 }
3352}
Note: See TracBrowser for help on using the repository browser.