~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to kdevdesigner/designer/mainwindow.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2006-05-23 18:39:42 UTC
  • Revision ID: james.westby@ubuntu.com-20060523183942-hucifbvh68k2bwz7
Tags: upstream-3.3.2
Import upstream version 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 /**********************************************************************
 
2
** Copyright (C) 2000-2002 Trolltech AS.  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 "designerappiface.h"
 
28
#include "designerapp.h"
 
29
 
 
30
#include "mainwindow.h"
 
31
#include "defs.h"
 
32
#include "globaldefs.h"
 
33
#include "formwindow.h"
 
34
#include "widgetdatabase.h"
 
35
#include "widgetfactory.h"
 
36
#include "propertyeditor.h"
 
37
#include "metadatabase.h"
 
38
#include "resource.h"
 
39
#include "hierarchyview.h"
 
40
#include "newformimpl.h"
 
41
#include "workspace.h"
 
42
#include "about.h"
 
43
#include "multilineeditorimpl.h"
 
44
#include "wizardeditorimpl.h"
 
45
#include "outputwindow.h"
 
46
#include "actioneditorimpl.h"
 
47
#include "actiondnd.h"
 
48
#include "project.h"
 
49
#include "projectsettingsimpl.h"
 
50
#include "qwidgetfactory.h"
 
51
#include "pixmapcollection.h"
 
52
#include "qcompletionedit.h"
 
53
#include "sourcefile.h"
 
54
#include "orderindicator.h"
 
55
#include <qtoolbox.h>
 
56
#include "widgetaction.h"
 
57
#include "propertyobject.h"
 
58
#include "popupmenueditor.h"
 
59
#include "menubareditor.h"
 
60
 
 
61
#include "startdialog.h"
 
62
#include "createtemplate.h"
 
63
#include "editfunctions.h"
 
64
//#include "connectionviewer.h"
 
65
#include "formsettings.h"
 
66
#include "preferences.h"
 
67
#include "pixmapcollectioneditor.h"
 
68
#ifndef QT_NO_SQL
 
69
#include "dbconnectionimpl.h"
 
70
#endif
 
71
//#include "connectioneditor.h"
 
72
#include "customwidgeteditorimpl.h"
 
73
#include "paletteeditorimpl.h"
 
74
#include "listboxeditorimpl.h"
 
75
#include "listvieweditorimpl.h"
 
76
#include "iconvieweditorimpl.h"
 
77
#include "tableeditorimpl.h"
 
78
#include "multilineeditor.h"
 
79
#include "finddialog.h"
 
80
#include "replacedialog.h"
 
81
#include "gotolinedialog.h"
 
82
#include "designeraction.h"
 
83
 
 
84
#include <kiconloader.h>
 
85
#include <klocale.h>
 
86
 
 
87
#include <qinputdialog.h>
 
88
#include <qtoolbar.h>
 
89
#include <qfeatures.h>
 
90
#include <qmetaobject.h>
 
91
#include <qaction.h>
 
92
#include <qpixmap.h>
 
93
#include <qworkspace.h>
 
94
#include <qfiledialog.h>
 
95
#include <qclipboard.h>
 
96
#include <qmessagebox.h>
 
97
#include <qbuffer.h>
 
98
#include <qdir.h>
 
99
#include <qstyle.h>
 
100
#include <qlabel.h>
 
101
#include <qstatusbar.h>
 
102
#include <qfile.h>
 
103
#include <qcheckbox.h>
 
104
#include <qwhatsthis.h>
 
105
#include <qwizard.h>
 
106
#include <qtimer.h>
 
107
#include <qlistbox.h>
 
108
#include <qdockwindow.h>
 
109
#include <qstylefactory.h>
 
110
#include <qvbox.h>
 
111
#include <qprocess.h>
 
112
#include <qsettings.h>
 
113
#include <qaccel.h>
 
114
#include <qtooltip.h>
 
115
#include <qsizegrip.h>
 
116
#include <qtextview.h>
 
117
#include <qassistantclient.h>
 
118
#include <stdlib.h>
 
119
 
 
120
#include "kdevdesigner_part.h"
 
121
 
 
122
static bool mblockNewForms = FALSE;
 
123
extern QMap<QWidget*, QString> *qwf_forms;
 
124
extern QString *qwf_language;
 
125
extern bool qwf_execute_code;
 
126
extern bool qwf_stays_on_top;
 
127
extern void set_splash_status( const QString &txt );
 
128
extern QObject* qwf_form_object;
 
129
extern QString *qwf_plugin_dir;
 
130
 
 
131
MainWindow *MainWindow::self = 0;
 
132
 
 
133
QString assistantPath()
 
134
{
 
135
    QString path = QDir::cleanDirPath( QString( qInstallPathBins() ) +
 
136
                                       QDir::separator() );
 
137
    return path;
 
138
}
 
139
 
 
140
 
 
141
static QString textNoAccel( const QString& text)
 
142
{
 
143
    QString t = text;
 
144
    int i;
 
145
    while ( (i = t.find('&') )>= 0 ) {
 
146
        t.remove(i,1);
 
147
    }
 
148
    return t;
 
149
}
 
150
 
 
151
 
 
152
MainWindow::MainWindow( KDevDesignerPart *part, bool asClient, bool single, const QString &plgDir )
 
153
    : QMainWindow( 0, "designer_mainwindow"/*, WType_TopLevel | (single ? 0 : WDestructiveClose) | WGroupLeader*/ ),
 
154
      grd( 10, 10 ), sGrid( TRUE ), snGrid( TRUE ), restoreConfig( TRUE ), splashScreen( TRUE ),
 
155
      fileFilter( i18n( "Qt User-Interface Files (*.ui)" ) ), client( asClient ),
 
156
      previewing( FALSE ), databaseAutoEdit( FALSE ), autoSaveEnabled( FALSE ), autoSaveInterval( 1800 ), m_part(part)
 
157
{
 
158
//    extern void qInitImages_designercore();
 
159
//    qInitImages_designercore();
 
160
 
 
161
    self = this;
 
162
    setPluginDirectory( plgDir );
 
163
    customWidgetToolBar = customWidgetToolBar2 = 0;
 
164
    guiStuffVisible = TRUE;
 
165
    editorsReadOnly = FALSE;
 
166
    sSignalHandlers = TRUE;
 
167
    init_colors();
 
168
    shStartDialog = FALSE;
 
169
 
 
170
    desInterface = new DesignerInterfaceImpl( this );
 
171
    desInterface->addRef();
 
172
    inDebugMode = FALSE;
 
173
    savePluginPaths = FALSE;
 
174
 
 
175
    updateFunctionsTimer = new QTimer( this );
 
176
    connect( updateFunctionsTimer, SIGNAL( timeout() ),
 
177
             this, SLOT( doFunctionsChanged() ) );
 
178
 
 
179
    autoSaveTimer = new QTimer( this );
 
180
    connect( autoSaveTimer, SIGNAL( timeout() ),
 
181
             this, SLOT( fileSaveAll() ) );
 
182
 
 
183
    set_splash_status( "Loading Plugins..." );
 
184
    setupPluginManagers();
 
185
 
 
186
/*    if ( !single )
 
187
        qApp->setMainWidget( this );*/
 
188
    QWidgetFactory::addWidgetFactory( new CustomWidgetFactory );
 
189
#ifndef Q_WS_MACX
 
190
    setIcon( BarIcon( "designer_appicon.png", KDevDesignerPartFactory::instance() ) );
 
191
#endif
 
192
 
 
193
    actionGroupTools = 0;
 
194
    prefDia = 0;
 
195
    windowMenu = 0;
 
196
    hierarchyView = 0;
 
197
    actionEditor = 0;
 
198
    currentProject = 0;
 
199
    wspace = 0;
 
200
    oWindow = 0;
 
201
    singleProject = single;
 
202
 
 
203
    statusBar()->clear();
 
204
#if defined(QT_NON_COMMERCIAL)
 
205
    statusBar()->addWidget( new QLabel(i18n("Ready - This is the non-commercial version of Qt - "
 
206
        "For commercial evaluations, use the help menu to register with Trolltech."), statusBar()), 1 );
 
207
#else
 
208
    statusBar()->addWidget( new QLabel("Ready", statusBar()), 1 );
 
209
#endif
 
210
 
 
211
 
 
212
    set_splash_status( "Setting up GUI..." );
 
213
    setupMDI();
 
214
    setupMenuBar();
 
215
 
 
216
    setupToolbox();
 
217
 
 
218
    setupFileActions();
 
219
    setupEditActions();
 
220
    setupProjectActions();
 
221
    setupSearchActions();
 
222
    layoutToolBar = new QToolBar( this, "Layout" );
 
223
    layoutToolBar->setCloseMode( QDockWindow::Undocked );
 
224
    addToolBar( layoutToolBar, i18n( "Layout" ) );
 
225
    interpreterPluginManager = 0;
 
226
    setupToolActions();
 
227
    setupLayoutActions();
 
228
    setupPreviewActions();
 
229
    setupOutputWindow();
 
230
    setupActionManager();
 
231
    setupWindowActions();
 
232
 
 
233
    setupWorkspace();
 
234
    setupHierarchyView();
 
235
    setupPropertyEditor();
 
236
    setupActionEditor();
 
237
 
 
238
    setupHelpActions();
 
239
 
 
240
    setupRMBMenus();
 
241
 
 
242
    connect( this, SIGNAL( projectChanged() ), this, SLOT( emitProjectSignals() ) );
 
243
    connect( this, SIGNAL( hasActiveWindow(bool) ), this, SLOT( emitProjectSignals() ) );
 
244
 
 
245
    emit hasActiveForm( FALSE );
 
246
    emit hasActiveWindow( FALSE );
 
247
 
 
248
    lastPressWidget = 0;
 
249
    qApp->installEventFilter( this );
 
250
 
 
251
    QSize as( qApp->desktop()->size() );
 
252
    as -= QSize( 30, 30 );
 
253
    resize( QSize( 1200, 1000 ).boundedTo( as ) );
 
254
 
 
255
    connect( qApp->clipboard(), SIGNAL( dataChanged() ),
 
256
             this, SLOT( clipboardChanged() ) );
 
257
    clipboardChanged();
 
258
    layoutChilds = FALSE;
 
259
    layoutSelected = FALSE;
 
260
    breakLayout = FALSE;
 
261
    backPix = TRUE;
 
262
 
 
263
    set_splash_status( "Loading User Settings..." );
 
264
    readConfig();
 
265
    // hack to make WidgetFactory happy (so it knows QWidget and QDialog for resetting properties)
 
266
    QWidget *w = WidgetFactory::create( WidgetDatabase::idFromClassName( "QWidget" ), this, 0, FALSE );
 
267
    delete w;
 
268
    w = WidgetFactory::create( WidgetDatabase::idFromClassName( "QDialog" ), this, 0, FALSE );
 
269
    delete w;
 
270
    w = WidgetFactory::create( WidgetDatabase::idFromClassName( "QLabel" ), this, 0, FALSE );
 
271
    delete w;
 
272
    w = WidgetFactory::create( WidgetDatabase::idFromClassName( "QTabWidget" ), this, 0, FALSE );
 
273
    delete w;
 
274
    w = WidgetFactory::create( WidgetDatabase::idFromClassName( "QFrame" ), this, 0, FALSE );
 
275
    delete w;
 
276
    setAppropriate( (QDockWindow*)actionEditor->parentWidget(), FALSE );
 
277
    actionEditor->parentWidget()->hide();
 
278
 
 
279
    assistant = new QAssistantClient( assistantPath(), this );
 
280
 
 
281
    statusBar()->setSizeGripEnabled( TRUE );
 
282
    set_splash_status( "Initialization Done." );
 
283
/*    if ( shStartDialog )
 
284
        QTimer::singleShot( 0, this, SLOT( showStartDialog() ));*/
 
285
 
 
286
    if ( autoSaveEnabled )
 
287
        autoSaveTimer->start( autoSaveInterval * 1000 );
 
288
 
 
289
    setFocusPolicy( StrongFocus );
 
290
}
 
291
 
 
292
MainWindow::~MainWindow()
 
293
{
 
294
    QValueList<Tab>::Iterator tit;
 
295
    for ( tit = preferenceTabs.begin(); tit != preferenceTabs.end(); ++tit ) {
 
296
        Tab t = *tit;
 
297
        delete t.w;
 
298
    }
 
299
    for ( tit = projectTabs.begin(); tit != projectTabs.end(); ++tit ) {
 
300
        Tab t = *tit;
 
301
        delete t.w;
 
302
    }
 
303
 
 
304
    QMap< QAction*, Project* >::Iterator it = projects.begin();
 
305
    while ( it != projects.end() ) {
 
306
        Project *p = *it;
 
307
        ++it;
 
308
        delete p;
 
309
    }
 
310
    projects.clear();
 
311
 
 
312
    delete oWindow;
 
313
    oWindow = 0;
 
314
 
 
315
    desInterface->release();
 
316
    desInterface = 0;
 
317
 
 
318
    delete actionPluginManager;
 
319
    delete preferencePluginManager;
 
320
    delete projectSettingsPluginManager;
 
321
    delete interpreterPluginManager;
 
322
    delete templateWizardPluginManager;
 
323
    delete editorPluginManager;
 
324
    delete sourceTemplatePluginManager;
 
325
 
 
326
    MetaDataBase::clearDataBase();
 
327
    if(self == this)
 
328
        self = 0;
 
329
}
 
330
 
 
331
void MainWindow::setupMDI()
 
332
{
 
333
    QVBox *vbox = new QVBox( this );
 
334
    setCentralWidget( vbox );
 
335
    vbox->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
 
336
    vbox->setMargin( 1 );
 
337
    vbox->setLineWidth( 1 );
 
338
    qworkspace = new QWorkspace( vbox );
 
339
    qworkspace->setPaletteBackgroundPixmap( UserIcon( "designer_background.png", KDevDesignerPartFactory::instance() ) );
 
340
    qworkspace->setScrollBarsEnabled( TRUE );
 
341
    connect( qworkspace, SIGNAL( windowActivated( QWidget * ) ),
 
342
             this, SLOT( activeWindowChanged( QWidget * ) ) );
 
343
    lastActiveFormWindow = 0;
 
344
    qworkspace->setAcceptDrops( TRUE );
 
345
}
 
346
 
 
347
void MainWindow::setupMenuBar()
 
348
{
 
349
    menubar = menuBar();
 
350
}
 
351
 
 
352
void MainWindow::setupPropertyEditor()
 
353
{
 
354
    QDockWindow *dw = new QDockWindow( QDockWindow::InDock, this );
 
355
    dw->setResizeEnabled( TRUE );
 
356
    dw->setCloseMode( QDockWindow::Always );
 
357
    propertyEditor = new PropertyEditor( dw );
 
358
    addToolBar( dw, Qt::DockRight );
 
359
    dw->setWidget( propertyEditor );
 
360
    dw->setFixedExtentWidth( 250 );
 
361
    dw->setCaption( i18n( "Property Editor/Signal Handlers" ) );
 
362
    QWhatsThis::add( propertyEditor,
 
363
                     i18n("<b>The Property Editor</b>"
 
364
                        "<p>You can change the appearance and behavior of the selected widget in the "
 
365
                        "property editor.</p>"
 
366
                        "<p>You can set properties for components and forms at design time and see the "
 
367
                        "immediately see the effects of the changes. "
 
368
                        "Each property has its own editor which (depending on the property) can be used "
 
369
                        "to enter "
 
370
                        "new values, open a special dialog, or to select values from a predefined list. "
 
371
                        "Click <b>F1</b> to get detailed help for the selected property.</p>"
 
372
                        "<p>You can resize the columns of the editor by dragging the separators in the "
 
373
                        "list's header.</p>"
 
374
                        "<p><b>Signal Handlers</b></p>"
 
375
                        "<p>In the Signal Handlers tab you can define connections between "
 
376
                        "the signals emitted by widgets and the slots in the form. "
 
377
                        "(These connections can also be made using the connection tool.)" ) );
 
378
    dw->show();
 
379
}
 
380
 
 
381
void MainWindow::setupOutputWindow()
 
382
{
 
383
    QDockWindow *dw = new QDockWindow( QDockWindow::InDock, this );
 
384
    dw->setResizeEnabled( TRUE );
 
385
    dw->setCloseMode( QDockWindow::Always );
 
386
    addToolBar( dw, Qt::DockBottom );
 
387
    oWindow = new OutputWindow( dw );
 
388
    dw->setWidget( oWindow );
 
389
    dw->setFixedExtentHeight( 150 );
 
390
    dw->setCaption( i18n( "Output Window" ) );
 
391
}
 
392
 
 
393
void MainWindow::setupHierarchyView()
 
394
{
 
395
    if ( hierarchyView )
 
396
        return;
 
397
    QDockWindow *dw = new QDockWindow( QDockWindow::InDock, this );
 
398
    dw->setResizeEnabled( TRUE );
 
399
    dw->setCloseMode( QDockWindow::Always );
 
400
    hierarchyView = new HierarchyView( dw );
 
401
    addToolBar( dw, Qt::DockRight );
 
402
    dw->setWidget( hierarchyView );
 
403
 
 
404
    dw->setCaption( i18n( "Object Explorer" ) );
 
405
    dw->setFixedExtentWidth( 250 );
 
406
    QWhatsThis::add( hierarchyView,
 
407
                     i18n("<b>The Object Explorer</b>"
 
408
                        "<p>The Object Explorer provides an overview of the relationships "
 
409
                        "between the widgets in a form. You can use the clipboard functions using "
 
410
                        "a context menu for each item in the view. It is also useful for selecting widgets "
 
411
                        "in forms that have complex layouts.</p>"
 
412
                        "<p>The columns can be resized by dragging the separator in the list's header.</p>"
 
413
                        "<p>The second tab shows all the form's slots, class variables, includes, etc.</p>") );
 
414
    dw->show();
 
415
}
 
416
 
 
417
void MainWindow::setupWorkspace()
 
418
{
 
419
    QDockWindow *dw = new QDockWindow( QDockWindow::InDock, this );
 
420
    dw->setResizeEnabled( TRUE );
 
421
    dw->setCloseMode( QDockWindow::Always );
 
422
    QVBox *vbox = new QVBox( dw );
 
423
    QCompletionEdit *edit = new QCompletionEdit( vbox );
 
424
    QToolTip::add( edit, i18n( "Start typing the buffer you want to switch to here (ALT+B)" ) );
 
425
    QAccel *a = new QAccel( this );
 
426
    a->connectItem( a->insertItem( ALT + Key_B ), edit, SLOT( setFocus() ) );
 
427
    wspace = new Workspace( vbox, this );
 
428
    wspace->setBufferEdit( edit );
 
429
    wspace->setCurrentProject( currentProject );
 
430
    addToolBar( dw, Qt::DockRight );
 
431
    dw->setWidget( vbox );
 
432
 
 
433
    dw->setCaption( i18n( "Project Overview" ) );
 
434
    QWhatsThis::add( wspace, i18n("<b>The Project Overview Window</b>"
 
435
                                "<p>The Project Overview Window displays all the current "
 
436
                                "project, including forms and source files.</p>"
 
437
                                "<p>Use the search field to rapidly switch between files.</p>"));
 
438
    dw->setFixedExtentHeight( 100 );
 
439
    dw->show();
 
440
}
 
441
 
 
442
void MainWindow::setupActionEditor()
 
443
{
 
444
    QDockWindow *dw = new QDockWindow( QDockWindow::OutsideDock, this, 0 );
 
445
    addDockWindow( dw, Qt::DockTornOff );
 
446
    dw->setResizeEnabled( TRUE );
 
447
    dw->setCloseMode( QDockWindow::Always );
 
448
    actionEditor = new ActionEditor( dw );
 
449
    dw->setWidget( actionEditor );
 
450
    actionEditor->show();
 
451
    dw->setCaption( i18n( "Action Editor" ) );
 
452
    QWhatsThis::add( actionEditor, i18n("<b>The Action Editor</b>"
 
453
                                      "<p>The Action Editor is used to add actions and action groups to "
 
454
                                      "a form, and to connect actions to slots. Actions and action "
 
455
                                      "groups can be dragged into menus and into toolbars, and may "
 
456
                                      "feature keyboard shortcuts and tooltips. If actions have pixmaps "
 
457
                                      "these are displayed on toolbar buttons and besides their names in "
 
458
                                      "menus.</p>" ) );
 
459
    dw->hide();
 
460
    setAppropriate( dw, FALSE );
 
461
}
 
462
 
 
463
void MainWindow::setupToolbox()
 
464
{
 
465
    QDockWindow *dw = new QDockWindow( QDockWindow::InDock, this );
 
466
    dw->setResizeEnabled( TRUE );
 
467
    dw->setCloseMode( QDockWindow::Always );
 
468
    addToolBar( dw, Qt::DockLeft );
 
469
    toolBox = new QToolBox( dw );
 
470
    dw->setWidget( toolBox );
 
471
    dw->setFixedExtentWidth( 160 );
 
472
    dw->setCaption( i18n( "Toolbox" ) );
 
473
    dw->show();
 
474
    setDockEnabled( dw, Qt::DockTop, FALSE );
 
475
    setDockEnabled( dw, Qt::DockBottom, FALSE );
 
476
    commonWidgetsToolBar = new QToolBar( "Common Widgets", 0, toolBox, FALSE, "Common Widgets" );
 
477
    commonWidgetsToolBar->setFrameStyle( QFrame::NoFrame );
 
478
    commonWidgetsToolBar->setOrientation( Qt::Vertical );
 
479
    commonWidgetsToolBar->setBackgroundMode(PaletteBase);
 
480
    toolBox->addItem( commonWidgetsToolBar, "Common Widgets" );
 
481
}
 
482
 
 
483
void MainWindow::setupRMBMenus()
 
484
{
 
485
    rmbWidgets = new QPopupMenu( this );
 
486
    actionEditCut->addTo( rmbWidgets );
 
487
    actionEditCopy->addTo( rmbWidgets );
 
488
    actionEditPaste->addTo( rmbWidgets );
 
489
    actionEditDelete->addTo( rmbWidgets );
 
490
#if 0
 
491
    rmbWidgets->insertSeparator();
 
492
    actionEditLower->addTo( rmbWidgets );
 
493
    actionEditRaise->addTo( rmbWidgets );
 
494
#endif
 
495
    rmbWidgets->insertSeparator();
 
496
    actionEditAdjustSize->addTo( rmbWidgets );
 
497
    actionEditHLayout->addTo( rmbWidgets );
 
498
    actionEditVLayout->addTo( rmbWidgets );
 
499
    actionEditGridLayout->addTo( rmbWidgets );
 
500
    actionEditSplitHorizontal->addTo( rmbWidgets );
 
501
    actionEditSplitVertical->addTo( rmbWidgets );
 
502
    actionEditBreakLayout->addTo( rmbWidgets );
 
503
    rmbWidgets->insertSeparator();
 
504
    if ( !singleProjectMode() )
 
505
        actionEditConnections->addTo( rmbWidgets );
 
506
    actionEditSource->addTo( rmbWidgets );
 
507
 
 
508
    rmbFormWindow = new QPopupMenu( this );
 
509
    actionEditPaste->addTo( rmbFormWindow );
 
510
    actionEditSelectAll->addTo( rmbFormWindow );
 
511
    actionEditAccels->addTo( rmbFormWindow );
 
512
    rmbFormWindow->insertSeparator();
 
513
    actionEditAdjustSize->addTo( rmbFormWindow );
 
514
    actionEditHLayout->addTo( rmbFormWindow );
 
515
    actionEditVLayout->addTo( rmbFormWindow );
 
516
    actionEditGridLayout->addTo( rmbFormWindow );
 
517
    actionEditBreakLayout->addTo( rmbFormWindow );
 
518
    rmbFormWindow->insertSeparator();
 
519
    if ( !singleProjectMode() ) {
 
520
        actionEditFunctions->addTo( rmbFormWindow );
 
521
        actionEditConnections->addTo( rmbFormWindow );
 
522
    }
 
523
    actionEditSource->addTo( rmbFormWindow );
 
524
    rmbFormWindow->insertSeparator();
 
525
    actionEditFormSettings->addTo( rmbFormWindow );
 
526
}
 
527
 
 
528
void MainWindow::toolSelected( QAction* action )
 
529
{
 
530
    actionCurrentTool = action;
 
531
    emit currentToolChanged();
 
532
    if ( formWindow() )
 
533
        formWindow()->commandHistory()->emitUndoRedo();
 
534
}
 
535
 
 
536
int MainWindow::currentTool() const
 
537
{
 
538
    if ( !actionCurrentTool )
 
539
        return POINTER_TOOL;
 
540
    return QString::fromLatin1(actionCurrentTool->name()).toInt();
 
541
}
 
542
 
 
543
void MainWindow::runProjectPrecondition()
 
544
{
 
545
    for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() ) {
 
546
        e->save();
 
547
        e->saveBreakPoints();
 
548
    }
 
549
    fileSaveProject();
 
550
 
 
551
    if ( currentTool() == ORDER_TOOL )
 
552
        resetTool();
 
553
    oWindow->clearErrorMessages();
 
554
    oWindow->clearDebug();
 
555
    oWindow->showDebugTab();
 
556
    previewing = TRUE;
 
557
}
 
558
 
 
559
void MainWindow::runProjectPostcondition( QObjectList *l )
 
560
{
 
561
    inDebugMode = TRUE;
 
562
    debuggingForms = *l;
 
563
    enableAll( FALSE );
 
564
    for ( SourceEditor *e2 = sourceEditors.first(); e2; e2 = sourceEditors.next() ) {
 
565
        if ( e2->project() == currentProject )
 
566
            e2->editorInterface()->setMode( EditorInterface::Debugging );
 
567
    }
 
568
}
 
569
 
 
570
QWidget* MainWindow::previewFormInternal( QStyle* style, QPalette* palet )
 
571
{
 
572
    qwf_execute_code = FALSE;
 
573
    for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() )
 
574
        e->save();
 
575
    if ( currentTool() == ORDER_TOOL )
 
576
        resetTool();
 
577
 
 
578
    FormWindow *fw = formWindow();
 
579
    if ( !fw )
 
580
        return 0;
 
581
 
 
582
    QStringList databases;
 
583
    QPtrDictIterator<QWidget> wit( *fw->widgets() );
 
584
    while ( wit.current() ) {
 
585
        QStringList lst = MetaDataBase::fakeProperty( wit.current(), "database" ).toStringList();
 
586
        if ( !lst.isEmpty() )
 
587
            databases << lst [ 0 ];
 
588
        ++wit;
 
589
    }
 
590
 
 
591
    if ( fw->project() ) {
 
592
        QStringList::ConstIterator it;
 
593
        for ( it = databases.begin(); it != databases.end(); ++it )
 
594
            fw->project()->openDatabase( *it, FALSE );
 
595
    }
 
596
    QApplication::setOverrideCursor( WaitCursor );
 
597
 
 
598
    QCString s;
 
599
    QBuffer buffer( s );
 
600
    buffer.open( IO_WriteOnly );
 
601
    Resource resource( this );
 
602
    resource.setWidget( fw );
 
603
    QValueList<Resource::Image> images;
 
604
    resource.save( &buffer );
 
605
 
 
606
    buffer.close();
 
607
    buffer.open( IO_ReadOnly );
 
608
 
 
609
    QWidget *w = QWidgetFactory::create( &buffer );
 
610
    if ( w ) {
 
611
        previewedForm = w;
 
612
        if ( palet ) {
 
613
            if ( style )
 
614
                style->polish( *palet );
 
615
            w->setPalette( *palet );
 
616
        }
 
617
 
 
618
        if ( style )
 
619
            w->setStyle( style );
 
620
 
 
621
        QObjectList *l = w->queryList( "QWidget" );
 
622
        for ( QObject *o = l->first(); o; o = l->next() ) {
 
623
            if ( style )
 
624
                ( (QWidget*)o )->setStyle( style );
 
625
        }
 
626
        delete l;
 
627
 
 
628
        w->move( fw->mapToGlobal( QPoint(0,0) ) );
 
629
        ((MainWindow*)w )->setWFlags( WDestructiveClose );
 
630
        previewing = TRUE;
 
631
        w->show();
 
632
        previewing = FALSE;
 
633
        QApplication::restoreOverrideCursor();
 
634
        return w;
 
635
    }
 
636
    QApplication::restoreOverrideCursor();
 
637
    return 0;
 
638
}
 
639
 
 
640
void MainWindow::previewForm()
 
641
{
 
642
    QWidget* w = previewFormInternal();
 
643
    if ( w )
 
644
        w->show();
 
645
}
 
646
 
 
647
void MainWindow::previewForm( const QString & style )
 
648
{
 
649
    QStyle* st = QStyleFactory::create( style );
 
650
    QWidget* w = 0;
 
651
    if ( style == "Motif" ) {
 
652
        QPalette p( QColor( 192, 192, 192 ) );
 
653
        w = previewFormInternal( st, &p );
 
654
    } else if ( style == "Windows" ) {
 
655
        QPalette p( QColor( 212, 208, 200 ) );
 
656
        w = previewFormInternal( st, &p );
 
657
    } else if ( style == "Platinum" ) {
 
658
        QPalette p( QColor( 220, 220, 220 ) );
 
659
        w = previewFormInternal( st, &p );
 
660
    } else if ( style == "CDE" ) {
 
661
        QPalette p( QColor( 75, 123, 130 ) );
 
662
        p.setColor( QPalette::Active, QColorGroup::Base, QColor( 55, 77, 78 ) );
 
663
        p.setColor( QPalette::Inactive, QColorGroup::Base, QColor( 55, 77, 78 ) );
 
664
        p.setColor( QPalette::Disabled, QColorGroup::Base, QColor( 55, 77, 78 ) );
 
665
        p.setColor( QPalette::Active, QColorGroup::Highlight, Qt::white );
 
666
        p.setColor( QPalette::Active, QColorGroup::HighlightedText, QColor( 55, 77, 78 ) );
 
667
        p.setColor( QPalette::Inactive, QColorGroup::Highlight, Qt::white );
 
668
        p.setColor( QPalette::Inactive, QColorGroup::HighlightedText, QColor( 55, 77, 78 ) );
 
669
        p.setColor( QPalette::Disabled, QColorGroup::Highlight, Qt::white );
 
670
        p.setColor( QPalette::Disabled, QColorGroup::HighlightedText, QColor( 55, 77, 78 ) );
 
671
        p.setColor( QPalette::Active, QColorGroup::Foreground, Qt::white );
 
672
        p.setColor( QPalette::Active, QColorGroup::Text, Qt::white );
 
673
        p.setColor( QPalette::Active, QColorGroup::ButtonText, Qt::white );
 
674
        p.setColor( QPalette::Inactive, QColorGroup::Foreground, Qt::white );
 
675
        p.setColor( QPalette::Inactive, QColorGroup::Text, Qt::white );
 
676
        p.setColor( QPalette::Inactive, QColorGroup::ButtonText, Qt::white );
 
677
        p.setColor( QPalette::Disabled, QColorGroup::Foreground, Qt::lightGray );
 
678
        p.setColor( QPalette::Disabled, QColorGroup::Text, Qt::lightGray );
 
679
        p.setColor( QPalette::Disabled, QColorGroup::ButtonText, Qt::lightGray );
 
680
 
 
681
        w = previewFormInternal( st, &p );
 
682
    } else if ( style == "SGI" ) {
 
683
        QPalette p( QColor( 220, 220, 220 ) );
 
684
        w = previewFormInternal( st, &p );
 
685
    } else if ( style == "MotifPlus" ) {
 
686
        QColor gtkfg(0x00, 0x00, 0x00);
 
687
        QColor gtkdf(0x75, 0x75, 0x75);
 
688
        QColor gtksf(0xff, 0xff, 0xff);
 
689
        QColor gtkbs(0xff, 0xff, 0xff);
 
690
        QColor gtkbg(0xd6, 0xd6, 0xd6);
 
691
        QColor gtksl(0x00, 0x00, 0x9c);
 
692
        QColorGroup active(gtkfg,            // foreground
 
693
                           gtkbg,            // button
 
694
                           gtkbg.light(),    // light
 
695
                           gtkbg.dark(142),  // dark
 
696
                           gtkbg.dark(110),  // mid
 
697
                           gtkfg,            // text
 
698
                           gtkfg,            // bright text
 
699
                           gtkbs,            // base
 
700
                           gtkbg),           // background
 
701
            disabled(gtkdf,            // foreground
 
702
                     gtkbg,            // button
 
703
                     gtkbg.light(), // light
 
704
                     gtkbg.dark(156),  // dark
 
705
                     gtkbg.dark(110),  // mid
 
706
                     gtkdf,            // text
 
707
                     gtkdf,            // bright text
 
708
                     gtkbs,            // base
 
709
                     gtkbg);           // background
 
710
 
 
711
        QPalette pal(active, disabled, active);
 
712
 
 
713
        pal.setColor(QPalette::Active, QColorGroup::Highlight,
 
714
                     gtksl);
 
715
        pal.setColor(QPalette::Active, QColorGroup::HighlightedText,
 
716
                     gtksf);
 
717
        pal.setColor(QPalette::Inactive, QColorGroup::Highlight,
 
718
                     gtksl);
 
719
        pal.setColor(QPalette::Inactive, QColorGroup::HighlightedText,
 
720
                     gtksf);
 
721
        pal.setColor(QPalette::Disabled, QColorGroup::Highlight,
 
722
                     gtksl);
 
723
        pal.setColor(QPalette::Disabled, QColorGroup::HighlightedText,
 
724
                     gtkdf);
 
725
        w = previewFormInternal( st, &pal );
 
726
    } else {
 
727
        w = previewFormInternal( st );
 
728
    }
 
729
 
 
730
    if ( !w )
 
731
        return;
 
732
    w->insertChild( st );
 
733
    w->show();
 
734
}
 
735
 
 
736
void MainWindow::helpContents()
 
737
{
 
738
    QWidget *focusWidget = qApp->focusWidget();
 
739
    bool showClassDocu = TRUE;
 
740
    while ( focusWidget ) {
 
741
        if ( focusWidget->isA( "PropertyList" ) ) {
 
742
            showClassDocu = FALSE;
 
743
            break;
 
744
        }
 
745
        focusWidget = focusWidget->parentWidget();
 
746
    }
 
747
 
 
748
    QString source = "designer-manual.html";
 
749
    if ( propertyDocumentation.isEmpty() ) {
 
750
        QString indexFile = documentationPath() + "/propertyindex";
 
751
        QFile f( indexFile );
 
752
        if ( f.open( IO_ReadOnly ) ) {
 
753
            QTextStream ts( &f );
 
754
            while ( !ts.eof() ) {
 
755
                QString s = ts.readLine();
 
756
                int from = s.find( "\"" );
 
757
                if ( from == -1 )
 
758
                    continue;
 
759
                int to = s.findRev( "\"" );
 
760
                if ( to == -1 )
 
761
                    continue;
 
762
                propertyDocumentation[ s.mid( from + 1, to - from - 1 ) ] = s.mid( to + 2 ) + "-prop";
 
763
            }
 
764
            f.close();
 
765
        }
 
766
    }
 
767
 
 
768
    if ( propertyEditor->widget() && !showClassDocu ) {
 
769
        if ( !propertyEditor->currentProperty().isEmpty() ) {
 
770
            QMetaObject* mo = propertyEditor->metaObjectOfCurrentProperty();
 
771
            QString s;
 
772
            QString cp = propertyEditor->currentProperty();
 
773
            if ( cp == "layoutMargin" ) {
 
774
                source = propertyDocumentation[ "QLayout/margin" ];
 
775
            } else if ( cp == "layoutSpacing" ) {
 
776
                source = propertyDocumentation[ "QLayout/spacing" ];
 
777
            } else if ( cp == "toolTip" ) {
 
778
                source = "qtooltip.html#details";
 
779
            } else if ( mo && qstrcmp( mo->className(), "Spacer" ) == 0 ) {
 
780
                if ( cp != "name" )
 
781
                    source = "qsizepolicy.html#SizeType";
 
782
                else
 
783
                    source = propertyDocumentation[ "QObject/name" ];
 
784
            } else {
 
785
                while ( mo && !propertyDocumentation.contains( ( s = QString( mo->className() ) + "/" + cp ) ) )
 
786
                    mo = mo->superClass();
 
787
                if ( mo )
 
788
                    source = "p:" + propertyDocumentation[s];
 
789
            }
 
790
        }
 
791
 
 
792
        QString classname =  WidgetFactory::classNameOf( propertyEditor->widget() );
 
793
        if ( source.isEmpty() || source == "designer-manual.html" ) {
 
794
            if ( classname.lower() == "spacer" )
 
795
                source = "qspaceritem.html#details";
 
796
            else if ( classname == "QLayoutWidget" )
 
797
                source = "layout.html";
 
798
            else
 
799
                source = QString( WidgetFactory::classNameOf( propertyEditor->widget() ) ).lower() + ".html#details";
 
800
        }
 
801
    } else if ( propertyEditor->widget() ) {
 
802
        source = QString( WidgetFactory::classNameOf( propertyEditor->widget() ) ).lower() + ".html#details";
 
803
    }
 
804
 
 
805
    if ( !source.isEmpty() )
 
806
        assistant->showPage( documentationPath() + source );
 
807
}
 
808
 
 
809
void MainWindow::helpManual()
 
810
{
 
811
    assistant->showPage( documentationPath() + "/designer-manual.html" );
 
812
}
 
813
 
 
814
void MainWindow::helpAbout()
 
815
{
 
816
    AboutDialog dlg( this, 0, TRUE );
 
817
    if ( singleProjectMode() ) {
 
818
        dlg.aboutPixmap->setText( "" );
 
819
        dlg.aboutVersion->setText( "" );
 
820
        dlg.aboutCopyright->setText( "" );
 
821
        LanguageInterface *iface = MetaDataBase::languageInterface( eProject->language() );
 
822
        dlg.aboutLicense->setText( iface->aboutText() );
 
823
    }
 
824
    dlg.aboutVersion->setText(QString("Version ") + QString(QT_VERSION_STR));
 
825
    dlg.resize( dlg.width(), dlg.layout()->heightForWidth(dlg.width()) );
 
826
    dlg.exec();
 
827
}
 
828
 
 
829
void MainWindow::helpAboutQt()
 
830
{
 
831
    QMessageBox::aboutQt( this, "Qt Designer" );
 
832
}
 
833
 
 
834
#if defined(_WS_WIN_)
 
835
#include <qt_windows.h>
 
836
#include <qprocess.h>
 
837
#endif
 
838
 
 
839
void MainWindow::helpRegister()
 
840
{
 
841
#if defined(_WS_WIN_)
 
842
    HKEY key;
 
843
    HKEY subkey;
 
844
    long res;
 
845
    DWORD type;
 
846
    DWORD size = 255;
 
847
    QString command;
 
848
    QString sub( "htmlfile\\shell" );
 
849
#if defined(UNICODE)
 
850
    if ( QApplication::winVersion() & Qt::WV_NT_based ) {
 
851
        unsigned char data[256];
 
852
        res = RegOpenKeyExW( HKEY_CLASSES_ROOT, NULL, 0, KEY_READ, &key );
 
853
        res = RegOpenKeyExW( key, (TCHAR*)sub.ucs2(), 0, KEY_READ, &subkey );
 
854
        res = RegQueryValueExW( subkey, NULL, NULL, &type, data, &size );
 
855
        command = qt_winQString( data ) + "\\command";
 
856
        size = 255;
 
857
        res = RegOpenKeyExW( subkey, (TCHAR*)command.ucs2(), 0, KEY_READ, &subkey );
 
858
        res = RegQueryValueExW( subkey, NULL, NULL, &type, data, &size );
 
859
        command = qt_winQString( data );
 
860
    } else
 
861
#endif
 
862
    {
 
863
        unsigned char data[256];
 
864
        res = RegOpenKeyExA( HKEY_CLASSES_ROOT, NULL, 0, KEY_READ, &key );
 
865
        res = RegOpenKeyExA( key, sub.local8Bit(), 0, KEY_READ, &subkey );
 
866
        res = RegQueryValueExA( subkey, NULL, NULL, &type, data, &size );
 
867
        command = QString::fromLocal8Bit( (const char*) data ) + "\\command";
 
868
        size = 255;
 
869
        res = RegOpenKeyExA( subkey, command.local8Bit(), 0, KEY_READ, &subkey );
 
870
        res = RegQueryValueExA( subkey, NULL, NULL, &type, data, &size );
 
871
        command = QString::fromLocal8Bit( (const char*) data );
 
872
    }
 
873
 
 
874
    res = RegCloseKey( subkey );
 
875
    res = RegCloseKey( key );
 
876
 
 
877
    QProcess process( command + " www.trolltech.com/products/download/eval/evaluation.html" );
 
878
    if ( !process.start() )
 
879
        QMessageBox::information( this, "Register Qt", "Launching your web browser failed.\n"
 
880
        "To register Qt, point your browser to www.trolltech.com/products/download/eval/evaluation.html" );
 
881
#endif
 
882
}
 
883
 
 
884
void MainWindow::showProperties( QObject *o )
 
885
{
 
886
    if ( !o->isWidgetType() ) {
 
887
        propertyEditor->setWidget( o, lastActiveFormWindow );
 
888
        if ( lastActiveFormWindow )
 
889
            hierarchyView->setFormWindow( lastActiveFormWindow, lastActiveFormWindow->mainContainer() );
 
890
        else
 
891
            hierarchyView->setFormWindow( 0, 0 );
 
892
        return;
 
893
    }
 
894
    QWidget *w = (QWidget*)o;
 
895
    setupHierarchyView();
 
896
    FormWindow *fw = (FormWindow*)isAFormWindowChild( w );
 
897
    if ( fw ) {
 
898
        if ( fw->numSelectedWidgets() > 1 ) {
 
899
            QWidgetList wl = fw->selectedWidgets();
 
900
            if ( wl.first() != w ) {
 
901
                wl.removeRef( w );
 
902
                wl.insert( 0, w );
 
903
            }
 
904
            propertyEditor->setWidget( new PropertyObject( wl ), fw );
 
905
        } else {
 
906
            propertyEditor->setWidget( w, fw );
 
907
        }
 
908
        hierarchyView->setFormWindow( fw, w );
 
909
    } else {
 
910
        propertyEditor->setWidget( 0, 0 );
 
911
        hierarchyView->setFormWindow( 0, 0 );
 
912
    }
 
913
 
 
914
    if ( currentTool() == POINTER_TOOL && fw &&
 
915
         ( !qworkspace->activeWindow() || !::qt_cast<SourceEditor*>(qworkspace->activeWindow()) ) )
 
916
        fw->setFocus();
 
917
}
 
918
 
 
919
void MainWindow::resetTool()
 
920
{
 
921
    actionPointerTool->setOn( TRUE );
 
922
}
 
923
 
 
924
void MainWindow::updateProperties( QObject * )
 
925
{
 
926
    if ( propertyEditor )
 
927
        propertyEditor->refetchData();
 
928
}
 
929
 
 
930
bool MainWindow::eventFilter( QObject *o, QEvent *e )
 
931
{
 
932
    if ( ::qt_cast<MenuBarEditor*>(o) || ::qt_cast<PopupMenuEditor*>(o) ||
 
933
         ( o &&
 
934
           ( ::qt_cast<MenuBarEditor*>(o->parent()) ||
 
935
             ::qt_cast<PopupMenuEditor*>(o->parent()) ) ) ) {
 
936
 
 
937
        if ( e->type() == QEvent::Accel && ::qt_cast<PopupMenuEditor*>(o) ) {
 
938
            return TRUE; // consume accel events
 
939
        } else if ( e->type() == QEvent::MouseButtonPress && ::qt_cast<MenuBarEditor*>(o) ) {
 
940
            QPoint pos = ((QMouseEvent*)e)->pos();
 
941
            MenuBarEditor *m = ::qt_cast<MenuBarEditor*>(o);
 
942
            showProperties( o );
 
943
            if ( m->findItem( pos ) >= m->count() )
 
944
                m->setFocus();
 
945
        } else if ( e->type() == QEvent::MouseButtonPress && ::qt_cast<PopupMenuEditor*>(o) ) {
 
946
            PopupMenuEditor *m = ::qt_cast<PopupMenuEditor*>(o);
 
947
            PopupMenuEditorItem *i = m->at( ((QMouseEvent*)e)->pos() );
 
948
            if ( m->find( i->action() ) != -1 && !i->isSeparator() )
 
949
                showProperties( i->action() );
 
950
        }
 
951
        return QMainWindow::eventFilter( o, e );
 
952
    }
 
953
 
 
954
    if ( !o || !e || !o->isWidgetType() )
 
955
        return QMainWindow::eventFilter( o, e );
 
956
 
 
957
    QWidget *w = 0;
 
958
    bool passiveInteractor;
 
959
    switch ( e->type() ) {
 
960
    case QEvent::AccelOverride:
 
961
        if ( ( (QKeyEvent*)e )->key() == Key_F1 &&
 
962
             ( ( (QKeyEvent*)e )->state() & ShiftButton ) != ShiftButton ) {
 
963
            w = (QWidget*)o;
 
964
            while ( w ) {
 
965
                if ( ::qt_cast<PropertyList*>(w) )
 
966
                    break;
 
967
                w = w->parentWidget( TRUE );
 
968
            }
 
969
            if ( w ) {
 
970
                propertyEditor->propertyList()->showCurrentWhatsThis();
 
971
                ( (QKeyEvent*)e )->accept();
 
972
                return TRUE;
 
973
            }
 
974
        }
 
975
        break;
 
976
    case QEvent::Accel:
 
977
        if ( ( ( (QKeyEvent*)e )->key() == Key_A ||
 
978
               ( (QKeyEvent*)e )->key() == Key_E ) &&
 
979
             ( (QKeyEvent*)e )->state() & ControlButton ) {
 
980
            if ( qWorkspace()->activeWindow() &&
 
981
                 ::qt_cast<SourceEditor*>(qWorkspace()->activeWindow()) ) {
 
982
                ( (QKeyEvent*)e )->ignore();
 
983
                return TRUE;
 
984
            }
 
985
        }
 
986
        break;
 
987
    case QEvent::ContextMenu:
 
988
    case QEvent::MouseButtonPress:
 
989
        if ( o && currentTool() == POINTER_TOOL &&
 
990
             ( ::qt_cast<MenuBarEditor*>(o) ||
 
991
               ::qt_cast<PopupMenuEditor*>(o) ||
 
992
               ::qt_cast<QDesignerToolBar*>(o) ||
 
993
               ( ::qt_cast<QComboBox*>(o) ||
 
994
                 ::qt_cast<QToolButton*>(o) ||
 
995
                 ::qt_cast<QDesignerToolBarSeparator*>(o) ) &&
 
996
               o->parent()
 
997
               && ( ::qt_cast<QDesignerToolBar*>(o->parent())
 
998
                   || ::qt_cast<QDesignerWidgetStack*>(o->parent())) ) ) {
 
999
            QWidget *w = (QWidget*)o;
 
1000
            if ( ::qt_cast<QToolButton*>(w) ||
 
1001
                 ::qt_cast<QComboBox*>(w) ||
 
1002
                 ::qt_cast<PopupMenuEditor*>(w) ||
 
1003
                 ::qt_cast<QDesignerToolBarSeparator*>(w) )
 
1004
                w = w->parentWidget();
 
1005
            QWidget *pw = w->parentWidget();
 
1006
            while ( pw ) {
 
1007
                if ( ::qt_cast<FormWindow*>(pw) ) {
 
1008
                    ( (FormWindow*)pw )->emitShowProperties( w );
 
1009
                    if ( !::qt_cast<QDesignerToolBar*>(o) )
 
1010
                        return ( !::qt_cast<QToolButton*>(o) &&
 
1011
                                 !::qt_cast<MenuBarEditor*>(o) &&
 
1012
                                 !::qt_cast<QComboBox*>(o) &&
 
1013
                                 !::qt_cast<QDesignerToolBarSeparator*>(o) );
 
1014
                }
 
1015
                pw = pw->parentWidget();
 
1016
            }
 
1017
        }
 
1018
        if ( o && ( ::qt_cast<QDesignerToolBar*>(o) || o->inherits("QDockWindowHandle") )
 
1019
             && e->type() == QEvent::ContextMenu )
 
1020
            break;
 
1021
        if ( isAToolBarChild( o ) && currentTool() != CONNECT_TOOL && currentTool() != BUDDY_TOOL )
 
1022
            break;
 
1023
        if ( ::qt_cast<QSizeGrip*>(o) )
 
1024
            break;
 
1025
        if ( !( w = isAFormWindowChild( o ) ) ||
 
1026
             ::qt_cast<SizeHandle*>(o) ||
 
1027
             ::qt_cast<OrderIndicator*>(o) )
 
1028
            break;
 
1029
        if ( !w->hasFocus() )
 
1030
            w->setFocus();
 
1031
        passiveInteractor = WidgetFactory::isPassiveInteractor( o );
 
1032
        if ( !passiveInteractor || currentTool() != ORDER_TOOL ) {
 
1033
            if( e->type() == QEvent::ContextMenu ) {
 
1034
                ( (FormWindow*)w )->handleContextMenu( (QContextMenuEvent*)e,
 
1035
                                                       ( (FormWindow*)w )->designerWidget( o ) );
 
1036
                return TRUE;
 
1037
            } else {
 
1038
                ( (FormWindow*)w )->handleMousePress( (QMouseEvent*)e,
 
1039
                                                      ( (FormWindow*)w )->designerWidget( o ) );
 
1040
            }
 
1041
        }
 
1042
        lastPressWidget = (QWidget*)o;
 
1043
        if ( passiveInteractor )
 
1044
            QTimer::singleShot( 0, formWindow(), SLOT( visibilityChanged() ) );
 
1045
        if ( currentTool() == CONNECT_TOOL || currentTool() == BUDDY_TOOL )
 
1046
            return TRUE;
 
1047
        return !passiveInteractor;
 
1048
    case QEvent::MouseButtonRelease:
 
1049
        lastPressWidget = 0;
 
1050
        if ( isAToolBarChild( o )  && currentTool() != CONNECT_TOOL && currentTool() != BUDDY_TOOL )
 
1051
            break;
 
1052
        if ( ::qt_cast<QSizeGrip*>(o) )
 
1053
            break;
 
1054
        if ( !( w = isAFormWindowChild( o ) ) ||
 
1055
             ::qt_cast<SizeHandle*>(o) ||
 
1056
             ::qt_cast<OrderIndicator*>(o) )
 
1057
            break;
 
1058
        passiveInteractor = WidgetFactory::isPassiveInteractor( o );
 
1059
        if ( !passiveInteractor )
 
1060
            ( (FormWindow*)w )->handleMouseRelease( (QMouseEvent*)e,
 
1061
                                                    ( (FormWindow*)w )->designerWidget( o ) );
 
1062
        if ( passiveInteractor ) {
 
1063
            QTimer::singleShot( 0, this, SLOT( selectionChanged() ) );
 
1064
            QTimer::singleShot( 0, formWindow(), SLOT( visibilityChanged() ) );
 
1065
        }
 
1066
        return !passiveInteractor;
 
1067
    case QEvent::MouseMove:
 
1068
        if ( isAToolBarChild( o ) && currentTool() != CONNECT_TOOL && currentTool() != BUDDY_TOOL )
 
1069
            break;
 
1070
        w = isAFormWindowChild( o );
 
1071
        if ( lastPressWidget != (QWidget*)o && w &&
 
1072
             !::qt_cast<SizeHandle*>(o) && !::qt_cast<OrderIndicator*>(o) &&
 
1073
             !::qt_cast<PopupMenuEditor*>(o) && !::qt_cast<QMenuBar*>(o) &&
 
1074
             !::qt_cast<QSizeGrip*>(o) )
 
1075
            return TRUE;
 
1076
        if ( o && ::qt_cast<QSizeGrip*>(o) )
 
1077
            break;
 
1078
        if ( lastPressWidget != (QWidget*)o ||
 
1079
             ( !w || ::qt_cast<SizeHandle*>(o) ) ||
 
1080
               ::qt_cast<OrderIndicator*>(o) )
 
1081
            break;
 
1082
        passiveInteractor = WidgetFactory::isPassiveInteractor( o );
 
1083
        if ( !passiveInteractor )
 
1084
            ( (FormWindow*)w )->handleMouseMove( (QMouseEvent*)e,
 
1085
                                                 ( (FormWindow*)w )->designerWidget( o ) );
 
1086
        return !passiveInteractor;
 
1087
    case QEvent::KeyPress:
 
1088
        if ( ( (QKeyEvent*)e )->key() == Key_Escape && currentTool() != POINTER_TOOL ) {
 
1089
            resetTool();
 
1090
            return FALSE;
 
1091
        }
 
1092
        if ( ( (QKeyEvent*)e )->key() == Key_Escape && incrementalSearch->hasFocus() ) {
 
1093
            if ( ::qt_cast<SourceEditor*>(qWorkspace()->activeWindow()) ) {
 
1094
                qWorkspace()->activeWindow()->setFocus();
 
1095
                return TRUE;
 
1096
            }
 
1097
        }
 
1098
        if ( !( w = isAFormWindowChild( o ) ) ||
 
1099
             ::qt_cast<SizeHandle*>(o) ||
 
1100
             ::qt_cast<OrderIndicator*>(o) )
 
1101
            break;
 
1102
        ( (FormWindow*)w )->handleKeyPress( (QKeyEvent*)e, ( (FormWindow*)w )->designerWidget( o ) );
 
1103
        if ( ((QKeyEvent*)e)->isAccepted() )
 
1104
            return TRUE;
 
1105
        break;
 
1106
    case QEvent::MouseButtonDblClick:
 
1107
        if ( !( w = isAFormWindowChild( o ) ) ||
 
1108
             ::qt_cast<SizeHandle*>(o) ||
 
1109
             ::qt_cast<OrderIndicator*>(o) ) {
 
1110
            if ( ::qt_cast<QToolButton*>(o) && ((QToolButton*)o)->isOn() &&
 
1111
                 o->parent() && ::qt_cast<QToolBar*>(o->parent()) && formWindow() )
 
1112
                formWindow()->setToolFixed();
 
1113
            break;
 
1114
        }
 
1115
        if ( currentTool() == ORDER_TOOL ) {
 
1116
            ( (FormWindow*)w )->handleMouseDblClick( (QMouseEvent*)e,
 
1117
                                                     ( (FormWindow*)w )->designerWidget( o ) );
 
1118
            return TRUE;
 
1119
        }
 
1120
        if ( !WidgetFactory::isPassiveInteractor( o ) && ( (FormWindow*)w )->formFile() )
 
1121
            return openEditor( ( (FormWindow*)w )->designerWidget( o ), (FormWindow*)w );
 
1122
        return TRUE;
 
1123
    case QEvent::KeyRelease:
 
1124
        if ( !( w = isAFormWindowChild( o ) ) ||
 
1125
             ::qt_cast<SizeHandle*>(o) ||
 
1126
             ::qt_cast<OrderIndicator*>(o) )
 
1127
            break;
 
1128
        ( (FormWindow*)w )->handleKeyRelease( (QKeyEvent*)e, ( (FormWindow*)w )->designerWidget( o ) );
 
1129
        if ( ((QKeyEvent*)e)->isAccepted() )
 
1130
            return TRUE;
 
1131
        break;
 
1132
    case QEvent::Hide:
 
1133
        if ( !( w = isAFormWindowChild( o ) ) ||
 
1134
             ::qt_cast<SizeHandle*>(o) ||
 
1135
             ::qt_cast<OrderIndicator*>(o) )
 
1136
            break;
 
1137
        if ( ( (FormWindow*)w )->isWidgetSelected( (QWidget*)o ) )
 
1138
            ( (FormWindow*)w )->selectWidget( (QWidget*)o, FALSE );
 
1139
        break;
 
1140
    case QEvent::Enter:
 
1141
    case QEvent::Leave:
 
1142
        if ( !( w = isAFormWindowChild( o ) ) ||
 
1143
             ::qt_cast<SizeHandle*>(o) ||
 
1144
             ::qt_cast<OrderIndicator*>(o) ||
 
1145
             ::qt_cast<MenuBarEditor*>(o) )
 
1146
            break;
 
1147
        return TRUE;
 
1148
    case QEvent::Resize:
 
1149
    case QEvent::Move:
 
1150
        if ( !( w = isAFormWindowChild( o ) ) ||
 
1151
             ::qt_cast<SizeHandle*>(o) ||
 
1152
             ::qt_cast<OrderIndicator*>(o) )
 
1153
            break;
 
1154
        if ( WidgetFactory::layoutType( (QWidget*)o->parent() ) != WidgetFactory::NoLayout ) {
 
1155
            ( (FormWindow*)w )->updateSelection( (QWidget*)o );
 
1156
            if ( e->type() != QEvent::Resize )
 
1157
                ( (FormWindow*)w )->updateChildSelections( (QWidget*)o );
 
1158
        }
 
1159
        break;
 
1160
    case QEvent::Close:
 
1161
        if ( o->isWidgetType() && (QWidget*)o == (QWidget*)previewedForm ) {
 
1162
            if ( lastActiveFormWindow && lastActiveFormWindow->project() ) {
 
1163
                QStringList lst =
 
1164
                    MetaDataBase::fakeProperty( lastActiveFormWindow, "database" ).toStringList();
 
1165
                lastActiveFormWindow->project()->closeDatabase( lst[ 0 ] );
 
1166
            }
 
1167
        }
 
1168
        break;
 
1169
    case QEvent::DragEnter:
 
1170
        if ( o == qWorkspace() || o == workspace() || o == workspace()->viewport() ) {
 
1171
            workspace()->contentsDragEnterEvent( (QDragEnterEvent*)e );
 
1172
            return TRUE;
 
1173
        }
 
1174
        break;
 
1175
    case QEvent::DragMove:
 
1176
        if ( o == qWorkspace() || o == workspace() || o == workspace()->viewport() ) {
 
1177
            workspace()->contentsDragMoveEvent( (QDragMoveEvent*)e );
 
1178
            return TRUE;
 
1179
        }
 
1180
        break;
 
1181
    case QEvent::Drop:
 
1182
        if ( o == qWorkspace() || o == workspace() || o == workspace()->viewport() ) {
 
1183
            workspace()->contentsDropEvent( (QDropEvent*)e );
 
1184
            return TRUE;
 
1185
        }
 
1186
        break;
 
1187
    case QEvent::Show:
 
1188
        if ( o != this )
 
1189
            break;
 
1190
        if ( ((QShowEvent*)e)->spontaneous() )
 
1191
            break;
 
1192
        QApplication::sendPostedEvents( qworkspace, QEvent::ChildInserted );
 
1193
        showEvent( (QShowEvent*)e );
 
1194
        checkTempFiles();
 
1195
        return TRUE;
 
1196
    case QEvent::Wheel:
 
1197
        if ( !( w = isAFormWindowChild( o ) ) ||
 
1198
             ::qt_cast<SizeHandle*>(o) ||
 
1199
             ::qt_cast<OrderIndicator*>(o) )
 
1200
            break;
 
1201
        return TRUE;
 
1202
    case QEvent::FocusIn:
 
1203
        if ( !::qt_cast<FormWindow*>(o) && isAFormWindowChild( o ) )
 
1204
            return TRUE; //FIXME
 
1205
        if ( hierarchyView->formDefinitionView()->isRenaming()
 
1206
             && ( o->inherits( "Editor" ) || ::qt_cast<FormWindow*>(o) ) )
 
1207
                QApplication::sendPostedEvents();
 
1208
        if ( o->inherits( "Editor" ) ) {
 
1209
            QWidget *w = (QWidget*)o;
 
1210
            while ( w ) {
 
1211
                if ( ::qt_cast<SourceEditor*>(w) )
 
1212
                    break;
 
1213
                w = w->parentWidget( TRUE );
 
1214
            }
 
1215
            if ( ::qt_cast<SourceEditor*>(w) )
 
1216
                ( (SourceEditor*)w )->checkTimeStamp();
 
1217
        } else if ( ::qt_cast<FormWindow*>(o) ) {
 
1218
            FormWindow *fw = (FormWindow*)o;
 
1219
            if ( fw->formFile() && fw->formFile()->editor() )
 
1220
                fw->formFile()->editor()->checkTimeStamp();
 
1221
        }
 
1222
        break;
 
1223
    case QEvent::FocusOut:
 
1224
        if ( !::qt_cast<FormWindow*>(o) && isAFormWindowChild( o ) )
 
1225
            return TRUE;
 
1226
        break;
 
1227
    default:
 
1228
        return QMainWindow::eventFilter( o, e );
 
1229
    }
 
1230
 
 
1231
    return QMainWindow::eventFilter( o, e );
 
1232
}
 
1233
 
 
1234
QWidget *MainWindow::isAFormWindowChild( QObject *o ) const
 
1235
{
 
1236
    if ( ::qt_cast<QWizard*>(o->parent()) && !::qt_cast<QPushButton*>(o) )
 
1237
        return 0;
 
1238
    while ( o ) {
 
1239
        if ( ::qt_cast<FormWindow*>(o) )
 
1240
            return (QWidget*)o;
 
1241
        o = o->parent();
 
1242
    }
 
1243
    return 0;
 
1244
}
 
1245
 
 
1246
QWidget *MainWindow::isAToolBarChild( QObject *o ) const
 
1247
{
 
1248
    while ( o ) {
 
1249
        if ( ::qt_cast<QDesignerToolBar*>(o) )
 
1250
            return (QWidget*)o;
 
1251
        if ( ::qt_cast<FormWindow*>(o) )
 
1252
            return 0;
 
1253
        o = o->parent();
 
1254
    }
 
1255
    return 0;
 
1256
}
 
1257
 
 
1258
FormWindow *MainWindow::formWindow()
 
1259
{
 
1260
    if ( qworkspace->activeWindow() ) {
 
1261
        FormWindow *fw = 0;
 
1262
        if ( ::qt_cast<FormWindow*>(qworkspace->activeWindow()) )
 
1263
            fw = (FormWindow*)qworkspace->activeWindow();
 
1264
        else if ( lastActiveFormWindow &&
 
1265
                    qworkspace->windowList().find( lastActiveFormWindow ) != -1)
 
1266
            fw = lastActiveFormWindow;
 
1267
        return fw;
 
1268
    }
 
1269
    return 0;
 
1270
}
 
1271
 
 
1272
void MainWindow::emitProjectSignals()
 
1273
{
 
1274
    emit hasNonDummyProject( !currentProject->isDummy() );
 
1275
    emit hasActiveWindowOrProject( !!qworkspace->activeWindow() || !currentProject->isDummy() );
 
1276
}
 
1277
 
 
1278
void MainWindow::insertFormWindow( FormWindow *fw )
 
1279
{
 
1280
    if ( fw )
 
1281
        QWhatsThis::add( fw, i18n( "<b>The Form Window</b>"
 
1282
                               "<p>Use the various tools to add widgets or to change the layout "
 
1283
                               "and behavior of the components in the form. Select one or multiple "
 
1284
                               "widgets to move them or lay them out. If a single widget is chosen it can "
 
1285
                               "be resized using the resize handles.</p>"
 
1286
                               "<p>Changes in the <b>Property Editor</b> are visible at design time, "
 
1287
                               "and you can preview the form in different styles.</p>"
 
1288
                               "<p>You can change the grid resolution, or turn the grid off in the "
 
1289
                               "<b>Preferences</b> dialog in the <b>Edit</b> menu."
 
1290
                               "<p>You can have several forms open, and all open forms are listed "
 
1291
                               "in the <b>Form List</b>.") );
 
1292
 
 
1293
    connect( fw, SIGNAL( showProperties( QObject * ) ),
 
1294
             this, SLOT( showProperties( QObject * ) ) );
 
1295
    connect( fw, SIGNAL( updateProperties( QObject * ) ),
 
1296
             this, SLOT( updateProperties( QObject * ) ) );
 
1297
    connect( this, SIGNAL( currentToolChanged() ),
 
1298
             fw, SLOT( currentToolChanged() ) );
 
1299
    connect( fw, SIGNAL( selectionChanged() ),
 
1300
             this, SLOT( selectionChanged() ) );
 
1301
    connect( fw, SIGNAL( undoRedoChanged( bool, bool, const QString &, const QString & ) ),
 
1302
             this, SLOT( updateUndoRedo( bool, bool, const QString &, const QString & ) ) );
 
1303
 
 
1304
    if ( !mblockNewForms ) {
 
1305
    } else {
 
1306
        fw->setProject( currentProject );
 
1307
    }
 
1308
    fw->show();
 
1309
    fw->currentToolChanged();
 
1310
    if ( fw->caption().isEmpty() && qstrlen( fw->name() )  )
 
1311
        fw->setCaption( fw->name() );
 
1312
    fw->mainContainer()->setCaption( fw->caption() );
 
1313
    WidgetFactory::saveDefaultProperties( fw->mainContainer(),
 
1314
                                          WidgetDatabase::
 
1315
                                          idFromClassName( WidgetFactory::classNameOf( fw->mainContainer() ) ) );
 
1316
    activeWindowChanged( fw );
 
1317
    emit formWindowsChanged();
 
1318
    for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() ) {
 
1319
        if ( e->project() == fw->project() )
 
1320
            e->resetContext();
 
1321
    }
 
1322
}
 
1323
 
 
1324
void MainWindow::createNewProject( const QString &lang )
 
1325
{
 
1326
    Project *pro = new Project( "", "", projectSettingsPluginManager );
 
1327
    pro->setLanguage( lang );
 
1328
 
 
1329
 
 
1330
    if ( !openProjectSettings( pro ) ) {
 
1331
        delete pro;
 
1332
        return;
 
1333
    }
 
1334
 
 
1335
    if ( !pro->isValid() ) {
 
1336
        QMessageBox::information( this, i18n("New Project"), i18n( "Cannot create an invalid project." ) );
 
1337
        delete pro;
 
1338
        return;
 
1339
    }
 
1340
 
 
1341
    QAction *a = new QAction( pro->makeRelative( pro->fileName() ),
 
1342
                              pro->makeRelative( pro->fileName() ), 0, actionGroupProjects, 0, TRUE );
 
1343
    projects.insert( a, pro );
 
1344
    addRecentlyOpened( pro->makeAbsolute( pro->fileName() ), recentlyProjects );
 
1345
    projectSelected( a );
 
1346
}
 
1347
 
 
1348
 
 
1349
bool MainWindow::unregisterClient( FormWindow *w )
 
1350
{
 
1351
    propertyEditor->closed( w );
 
1352
    objectHierarchy()->closed( w );
 
1353
    if ( w == lastActiveFormWindow )
 
1354
        lastActiveFormWindow = 0;
 
1355
 
 
1356
    QPtrList<SourceEditor> waitingForDelete;
 
1357
    waitingForDelete.setAutoDelete( TRUE );
 
1358
    for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() ) {
 
1359
        if ( e->object() == w )
 
1360
            waitingForDelete.append( e );
 
1361
    }
 
1362
 
 
1363
    if ( actionEditor->form() == w ) {
 
1364
        actionEditor->setFormWindow( 0 );
 
1365
        actionEditor->parentWidget()->hide();
 
1366
    }
 
1367
 
 
1368
    return TRUE;
 
1369
}
 
1370
 
 
1371
void MainWindow::activeWindowChanged( QWidget *w )
 
1372
{
 
1373
    QWidget *old = formWindow();
 
1374
    if ( ::qt_cast<FormWindow*>(w) ) {
 
1375
        FormWindow *fw = (FormWindow*)w;
 
1376
        FormWindow *ofw = lastActiveFormWindow;
 
1377
        lastActiveFormWindow = fw;
 
1378
        lastActiveFormWindow->updateUndoInfo();
 
1379
        emit hasActiveForm( TRUE );
 
1380
        if ( formWindow() ) {
 
1381
            formWindow()->emitShowProperties();
 
1382
            emit formModified( formWindow()->commandHistory()->isModified() );
 
1383
            if ( currentTool() != POINTER_TOOL )
 
1384
                formWindow()->clearSelection();
 
1385
        }
 
1386
        workspace()->activeFormChanged( fw );
 
1387
        setAppropriate( (QDockWindow*)actionEditor->parentWidget(),
 
1388
                        ::qt_cast<QMainWindow*>(lastActiveFormWindow->mainContainer()) );
 
1389
        if ( appropriate( (QDockWindow*)actionEditor->parentWidget() ) ) {
 
1390
            if ( actionEditor->wantToBeShown() )
 
1391
                actionEditor->parentWidget()->show();
 
1392
        } else {
 
1393
            QWidget *mc = 0;
 
1394
            if ( ofw && (mc = ofw->mainContainer()) && ::qt_cast<QMainWindow*>(mc) )
 
1395
                actionEditor->setWantToBeShown( !actionEditor->parentWidget()->isHidden() );
 
1396
            actionEditor->parentWidget()->hide();
 
1397
        }
 
1398
 
 
1399
        actionEditor->setFormWindow( lastActiveFormWindow );
 
1400
        if ( wspace && fw->project() && fw->project() != currentProject ) {
 
1401
            for ( QMap<QAction*, Project *>::ConstIterator it = projects.begin(); it != projects.end(); ++it ) {
 
1402
                if ( *it == fw->project() ) {
 
1403
                    projectSelected( it.key() );
 
1404
                    break;
 
1405
                }
 
1406
            }
 
1407
        }
 
1408
        emit formWindowChanged();
 
1409
 
 
1410
    } else if ( w == propertyEditor ) {
 
1411
        propertyEditor->resetFocus();
 
1412
    } else if ( !lastActiveFormWindow ) {
 
1413
        emit formWindowChanged();
 
1414
        emit hasActiveForm( FALSE );
 
1415
        actionEditUndo->setEnabled( FALSE );
 
1416
        actionEditRedo->setEnabled( FALSE );
 
1417
    }
 
1418
 
 
1419
    if ( !w ) {
 
1420
        emit formWindowChanged();
 
1421
        emit hasActiveForm( FALSE );
 
1422
        propertyEditor->clear();
 
1423
        hierarchyView->clear();
 
1424
        updateUndoRedo( FALSE, FALSE, QString::null, QString::null );
 
1425
    }
 
1426
 
 
1427
    selectionChanged();
 
1428
 
 
1429
    if ( ::qt_cast<SourceEditor*>(w) ) {
 
1430
        SourceEditor *se = (SourceEditor*)w;
 
1431
        QGuardedPtr<FormWindow> fw = se->formWindow();
 
1432
        if ( se->formWindow() &&
 
1433
             lastActiveFormWindow != fw ) {
 
1434
            activeWindowChanged( se->formWindow() );
 
1435
        }
 
1436
        actionSearchFind->setEnabled( TRUE );
 
1437
        actionSearchIncremetal->setEnabled( TRUE );
 
1438
        actionSearchReplace->setEnabled( TRUE );
 
1439
        actionSearchGotoLine->setEnabled( TRUE );
 
1440
        incrementalSearch->setEnabled( TRUE );
 
1441
 
 
1442
        actionEditUndo->setEnabled( FALSE );
 
1443
        actionEditRedo->setEnabled( FALSE );
 
1444
        actionEditCut->setEnabled( TRUE );
 
1445
        actionEditCopy->setEnabled( TRUE );
 
1446
        actionEditPaste->setEnabled( TRUE );
 
1447
        actionEditSelectAll->setEnabled( TRUE );
 
1448
        actionEditUndo->setMenuText( i18n( "&Undo" ) );
 
1449
        actionEditUndo->setToolTip( textNoAccel( actionEditUndo->menuText()) );
 
1450
        actionEditRedo->setMenuText( i18n( "&Redo" ) );
 
1451
        actionEditRedo->setToolTip( textNoAccel( actionEditRedo->menuText()) );
 
1452
        if ( hierarchyView->sourceEditor() != w )
 
1453
            hierarchyView->showClasses( se );
 
1454
        actionEditor->setFormWindow( 0 );
 
1455
        if ( wspace && se->project() && se->project() != currentProject ) {
 
1456
            for ( QMap<QAction*, Project *>::ConstIterator it = projects.begin(); it != projects.end(); ++it ) {
 
1457
                if ( *it == se->project() ) {
 
1458
                    projectSelected( it.key() );
 
1459
                    break;
 
1460
                }
 
1461
            }
 
1462
        }
 
1463
        workspace()->activeEditorChanged( se );
 
1464
    } else {
 
1465
        actionSearchFind->setEnabled( FALSE );
 
1466
        actionSearchIncremetal->setEnabled( FALSE );
 
1467
        actionSearchReplace->setEnabled( FALSE );
 
1468
        actionSearchGotoLine->setEnabled( FALSE );
 
1469
        incrementalSearch->setEnabled( FALSE );
 
1470
    }
 
1471
 
 
1472
    if ( currentTool() == ORDER_TOOL && w != old )
 
1473
        emit currentToolChanged();
 
1474
 
 
1475
    emit hasActiveWindow( !!qworkspace->activeWindow() );
 
1476
}
 
1477
 
 
1478
void MainWindow::updateUndoRedo( bool undoAvailable, bool redoAvailable,
 
1479
                                 const QString &undoCmd, const QString &redoCmd )
 
1480
{
 
1481
    if ( qWorkspace()->activeWindow() &&
 
1482
         ::qt_cast<SourceEditor*>(qWorkspace()->activeWindow()) )
 
1483
         return; // do not set a formWindow related command
 
1484
    actionEditUndo->setEnabled( undoAvailable );
 
1485
    actionEditRedo->setEnabled( redoAvailable );
 
1486
    if ( !undoCmd.isEmpty() )
 
1487
        actionEditUndo->setMenuText( i18n( "&Undo: %1" ).arg( undoCmd ) );
 
1488
    else
 
1489
        actionEditUndo->setMenuText( i18n( "&Undo: Not Available" ) );
 
1490
    if ( !redoCmd.isEmpty() )
 
1491
        actionEditRedo->setMenuText( i18n( "&Redo: %1" ).arg( redoCmd ) );
 
1492
    else
 
1493
        actionEditRedo->setMenuText( i18n( "&Redo: Not Available" ) );
 
1494
 
 
1495
    actionEditUndo->setToolTip( textNoAccel( actionEditUndo->menuText()) );
 
1496
    actionEditRedo->setToolTip( textNoAccel( actionEditRedo->menuText()) );
 
1497
 
 
1498
    if ( currentTool() == ORDER_TOOL ) {
 
1499
        actionEditUndo->setEnabled( FALSE );
 
1500
        actionEditRedo->setEnabled( FALSE );
 
1501
    }
 
1502
}
 
1503
 
 
1504
void MainWindow::updateEditorUndoRedo()
 
1505
{
 
1506
    if ( !qWorkspace()->activeWindow() ||
 
1507
         !::qt_cast<SourceEditor*>(qWorkspace()->activeWindow()) )
 
1508
        return;
 
1509
    SourceEditor *editor = (SourceEditor*)qWorkspace()->activeWindow();
 
1510
    actionEditUndo->setEnabled( editor->editIsUndoAvailable() );
 
1511
    actionEditRedo->setEnabled( editor->editIsRedoAvailable() );
 
1512
}
 
1513
 
 
1514
QWorkspace *MainWindow::qWorkspace() const
 
1515
{
 
1516
    return qworkspace;
 
1517
}
 
1518
 
 
1519
void MainWindow::popupFormWindowMenu( const QPoint & gp, FormWindow *fw )
 
1520
{
 
1521
    QValueList<uint> ids;
 
1522
    QMap<QString, int> commands;
 
1523
 
 
1524
    setupRMBSpecialCommands( ids, commands, fw );
 
1525
    setupRMBProperties( ids, commands, fw );
 
1526
 
 
1527
    qApp->processEvents();
 
1528
    int r = rmbFormWindow->exec( gp );
 
1529
 
 
1530
    handleRMBProperties( r, commands, fw );
 
1531
    handleRMBSpecialCommands( r, commands, fw );
 
1532
 
 
1533
    for ( QValueList<uint>::ConstIterator i = ids.begin(); i != ids.end(); ++i )
 
1534
        rmbFormWindow->removeItem( *i );
 
1535
}
 
1536
 
 
1537
void MainWindow::popupWidgetMenu( const QPoint &gp, FormWindow * /*fw*/, QWidget * w)
 
1538
{
 
1539
    QValueList<uint> ids;
 
1540
    QMap<QString, int> commands;
 
1541
 
 
1542
    setupRMBSpecialCommands( ids, commands, w );
 
1543
    setupRMBProperties( ids, commands, w );
 
1544
 
 
1545
    qApp->processEvents();
 
1546
    int r = rmbWidgets->exec( gp );
 
1547
 
 
1548
    handleRMBProperties( r, commands, w );
 
1549
    handleRMBSpecialCommands( r, commands, w );
 
1550
 
 
1551
    for ( QValueList<uint>::ConstIterator i = ids.begin(); i != ids.end(); ++i )
 
1552
        rmbWidgets->removeItem( *i );
 
1553
}
 
1554
 
 
1555
void MainWindow::setupRMBProperties( QValueList<uint> &ids, QMap<QString, int> &props, QWidget *w )
 
1556
{
 
1557
    const QMetaProperty* text = w->metaObject()->property( w->metaObject()->findProperty( "text", TRUE ), TRUE );
 
1558
    if ( text && qstrcmp( text->type(), "QString") != 0 )
 
1559
        text = 0;
 
1560
    const QMetaProperty* title = w->metaObject()->property( w->metaObject()->findProperty( "title", TRUE ), TRUE );
 
1561
    if ( title && qstrcmp( title->type(), "QString") != 0 )
 
1562
        title = 0;
 
1563
    const QMetaProperty* pagetitle =
 
1564
        w->metaObject()->property( w->metaObject()->findProperty( "pageTitle", TRUE ), TRUE );
 
1565
    if ( pagetitle && qstrcmp( pagetitle->type(), "QString") != 0 )
 
1566
        pagetitle = 0;
 
1567
    const QMetaProperty* pixmap =
 
1568
        w->metaObject()->property( w->metaObject()->findProperty( "pixmap", TRUE ), TRUE );
 
1569
    if ( pixmap && qstrcmp( pixmap->type(), "QPixmap") != 0 )
 
1570
        pixmap = 0;
 
1571
 
 
1572
    if ( text && text->designable(w) ||
 
1573
         title && title->designable(w) ||
 
1574
         pagetitle && pagetitle->designable(w) ||
 
1575
         pixmap && pixmap->designable(w) ) {
 
1576
        int id = 0;
 
1577
        if ( ids.isEmpty() )
 
1578
            ids << rmbWidgets->insertSeparator(0);
 
1579
        if ( pixmap && pixmap->designable(w) ) {
 
1580
            ids << ( id = rmbWidgets->insertItem( i18n("Choose Pixmap..."), -1, 0) );
 
1581
            props.insert( "pixmap", id );
 
1582
        }
 
1583
        if ( text && text->designable(w) && !::qt_cast<QTextEdit*>(w) ) {
 
1584
            ids << ( id = rmbWidgets->insertItem( i18n("Edit Text..."), -1, 0) );
 
1585
            props.insert( "text", id );
 
1586
        }
 
1587
        if ( title && title->designable(w) ) {
 
1588
            ids << ( id = rmbWidgets->insertItem( i18n("Edit Title..."), -1, 0) );
 
1589
            props.insert( "title", id );
 
1590
        }
 
1591
        if ( pagetitle && pagetitle->designable(w) ) {
 
1592
            ids << ( id = rmbWidgets->insertItem( i18n("Edit Page Title..."), -1, 0) );
 
1593
            props.insert( "pagetitle", id );
 
1594
        }
 
1595
    }
 
1596
}
 
1597
 
 
1598
#ifdef QT_CONTAINER_CUSTOM_WIDGETS
 
1599
static QWidgetContainerInterfacePrivate *containerWidgetInterface( QWidget *w )
 
1600
{
 
1601
    WidgetInterface *iface = 0;
 
1602
    widgetManager()->queryInterface( WidgetFactory::classNameOf( w ), &iface );
 
1603
    if ( !iface )
 
1604
        return 0;
 
1605
    QWidgetContainerInterfacePrivate *iface2 = 0;
 
1606
    iface->queryInterface( IID_QWidgetContainer, (QUnknownInterface**)&iface2 );
 
1607
    if ( !iface2 )
 
1608
        return 0;
 
1609
    iface->release();
 
1610
    return iface2;
 
1611
}
 
1612
#endif
 
1613
 
 
1614
void MainWindow::setupRMBSpecialCommands( QValueList<uint> &ids,
 
1615
                                          QMap<QString, int> &commands, QWidget *w )
 
1616
{
 
1617
    int id;
 
1618
 
 
1619
    if ( ::qt_cast<QTabWidget*>(w) ) {
 
1620
        if ( ids.isEmpty() )
 
1621
            ids << rmbWidgets->insertSeparator( 0 );
 
1622
        if ( ( (QDesignerTabWidget*)w )->count() > 1) {
 
1623
            ids << ( id = rmbWidgets->insertItem( i18n("Delete Page"), -1, 0 ) );
 
1624
            commands.insert( "remove", id );
 
1625
        }
 
1626
        ids << ( id = rmbWidgets->insertItem( i18n("Add Page"), -1, 0 ) );
 
1627
        commands.insert( "add", id );
 
1628
    } else if ( ::qt_cast<QDesignerWidgetStack*>(w) ) {
 
1629
        if ( ids.isEmpty() )
 
1630
            ids << rmbWidgets->insertSeparator( 0 );
 
1631
        if ( ( (QDesignerWidgetStack*)w )->count() > 1) {
 
1632
            ids << ( id = rmbWidgets->insertItem( i18n("Previous Page"), -1, 0 ) );
 
1633
            commands.insert( "prevpage", id );
 
1634
            ids << ( id = rmbWidgets->insertItem( i18n("Next Page"), -1, 0 ) );
 
1635
            ids << rmbWidgets->insertSeparator( 0 );
 
1636
            commands.insert( "nextpage", id );
 
1637
            ids << ( id = rmbWidgets->insertItem( i18n("Delete Page"), -1, 0 ) );
 
1638
            commands.insert( "remove", id );
 
1639
        }
 
1640
        ids << ( id = rmbWidgets->insertItem( i18n("Add Page"), -1, 0 ) );
 
1641
        commands.insert( "add", id );
 
1642
    } else if ( ::qt_cast<QToolBox*>(w) ) {
 
1643
        if ( ids.isEmpty() )
 
1644
            ids << rmbWidgets->insertSeparator( 0 );
 
1645
        if ( ( (QToolBox*)w )->count() > 1 ) {
 
1646
            ids << ( id = rmbWidgets->insertItem( i18n("Delete Page"), -1, 0 ) );
 
1647
            commands.insert( "remove", id );
 
1648
        }
 
1649
        ids << ( id = rmbWidgets->insertItem( i18n("Add Page"), -1, 0 ) );
 
1650
        commands.insert( "add", id );
 
1651
#ifdef QT_CONTAINER_CUSTOM_WIDGETS
 
1652
    } else if ( WidgetDatabase::
 
1653
                isCustomPluginWidget( WidgetDatabase::
 
1654
                                      idFromClassName( WidgetFactory::classNameOf( w ) ) ) ) {
 
1655
        QWidgetContainerInterfacePrivate *iface = containerWidgetInterface( w );
 
1656
        if ( iface && iface->supportsPages( WidgetFactory::classNameOf( w ) ) ) {
 
1657
            if ( ids.isEmpty() )
 
1658
                ids << rmbWidgets->insertSeparator( 0 );
 
1659
 
 
1660
            if ( iface->count( WidgetFactory::classNameOf( w ), w ) > 1 ) {
 
1661
                ids << ( id = rmbWidgets->insertItem( i18n( "Delete Page" ), -1, 0 ) );
 
1662
                commands.insert( "remove", id );
 
1663
            }
 
1664
            ids << ( id = rmbWidgets->insertItem( i18n("Add Page"), -1, 0 ) );
 
1665
            commands.insert( "add", id );
 
1666
            if ( iface->currentIndex( WidgetFactory::classNameOf( w ), w ) != -1 ) {
 
1667
                ids << ( id = rmbWidgets->insertItem( i18n("Rename Current Page..."), -1, 0 ) );
 
1668
                commands.insert( "rename", id );
 
1669
            }
 
1670
        }
 
1671
        if ( iface )
 
1672
            iface->release();
 
1673
#endif // QT_CONTAINER_CUSTOM_WIDGETS
 
1674
    }
 
1675
 
 
1676
    if ( WidgetFactory::hasSpecialEditor( WidgetDatabase::
 
1677
                          idFromClassName( WidgetFactory::classNameOf( w ) ), w ) ) {
 
1678
        if ( ids.isEmpty() )
 
1679
            ids << rmbWidgets->insertSeparator( 0 );
 
1680
        ids << ( id = rmbWidgets->insertItem( i18n("Edit..."), -1, 0 ) );
 
1681
        commands.insert( "edit", id );
 
1682
    }
 
1683
}
 
1684
 
 
1685
void MainWindow::setupRMBSpecialCommands( QValueList<uint> &ids,
 
1686
                                          QMap<QString, int> &commands, FormWindow *fw )
 
1687
{
 
1688
    int id;
 
1689
 
 
1690
    if ( ::qt_cast<QWizard*>(fw->mainContainer()) ) {
 
1691
        if ( ids.isEmpty() )
 
1692
            ids << rmbFormWindow->insertSeparator( 0 );
 
1693
 
 
1694
        if ( ( (QWizard*)fw->mainContainer() )->pageCount() > 1) {
 
1695
            ids << ( id = rmbFormWindow->insertItem( i18n("Delete Page"), -1, 0 ) );
 
1696
            commands.insert( "remove", id );
 
1697
        }
 
1698
 
 
1699
        ids << ( id = rmbFormWindow->insertItem( i18n("Add Page"), -1, 0 ) );
 
1700
        commands.insert( "add", id );
 
1701
 
 
1702
        ids << ( id = rmbFormWindow->insertItem( i18n("Edit Page Title..."), -1, 0 ) );
 
1703
        commands.insert( "rename", id );
 
1704
 
 
1705
        ids << ( id = rmbFormWindow->insertItem( i18n("Edit Pages..."), -1, 0 ) );
 
1706
        commands.insert( "edit", id );
 
1707
 
 
1708
    } else if ( ::qt_cast<QMainWindow*>(fw->mainContainer()) ) {
 
1709
        if ( ids.isEmpty() )
 
1710
            ids << rmbFormWindow->insertSeparator( 0 );
 
1711
        ids << ( id = rmbFormWindow->insertItem( i18n( "Add Menu Item" ), -1, 0 ) );
 
1712
        commands.insert( "add_menu_item", id );
 
1713
        ids << ( id = rmbFormWindow->insertItem( i18n( "Add Toolbar" ), -1, 0 ) );
 
1714
        commands.insert( "add_toolbar", id );
 
1715
    }
 
1716
}
 
1717
 
 
1718
void MainWindow::handleRMBProperties( int id, QMap<QString, int> &props, QWidget *w )
 
1719
{
 
1720
    if ( id == props[ "text" ] ) {
 
1721
        bool ok = FALSE;
 
1722
        bool oldDoWrap = FALSE;
 
1723
        if ( ::qt_cast<QLabel*>(w) ) {
 
1724
            int align = w->property( "alignment" ).toInt();
 
1725
            if ( align & WordBreak )
 
1726
                oldDoWrap = TRUE;
 
1727
        }
 
1728
        bool doWrap = oldDoWrap;
 
1729
 
 
1730
        QString text;
 
1731
        if ( ::qt_cast<QTextView*>(w) || ::qt_cast<QLabel*>(w) || ::qt_cast<QButton*>(w) ) {
 
1732
            text = MultiLineEditor::getText( this, w->property( "text" ).toString(), !::qt_cast<QButton*>(w), &doWrap );
 
1733
            ok = !text.isNull();
 
1734
        } else {
 
1735
            text = QInputDialog::getText( i18n("Text"), i18n( "New text" ),
 
1736
                                  QLineEdit::Normal, w->property("text").toString(), &ok, this );
 
1737
        }
 
1738
        if ( ok ) {
 
1739
            if ( oldDoWrap != doWrap ) {
 
1740
                QString pn( i18n( "Set 'wordwrap' of '%1'" ).arg( w->name() ) );
 
1741
                SetPropertyCommand *cmd = new SetPropertyCommand( pn, formWindow(), w, propertyEditor,
 
1742
                                                                  "wordwrap", QVariant( oldDoWrap, 0 ),
 
1743
                                                                  QVariant( doWrap, 0 ), QString::null, QString::null );
 
1744
                cmd->execute();
 
1745
                formWindow()->commandHistory()->addCommand( cmd );
 
1746
                MetaDataBase::setPropertyChanged( w, "wordwrap", TRUE );
 
1747
            }
 
1748
 
 
1749
            QString pn( i18n( "Set the 'text' of '%1'" ).arg( w->name() ) );
 
1750
            SetPropertyCommand *cmd = new SetPropertyCommand( pn, formWindow(), w, propertyEditor,
 
1751
                                                              "text", w->property( "text" ),
 
1752
                                                              text, QString::null, QString::null );
 
1753
            cmd->execute();
 
1754
            formWindow()->commandHistory()->addCommand( cmd );
 
1755
            MetaDataBase::setPropertyChanged( w, "text", TRUE );
 
1756
        }
 
1757
    } else if ( id == props[ "title" ] ) {
 
1758
        bool ok = FALSE;
 
1759
        QString title = QInputDialog::getText( i18n("Title"), i18n( "New title" ),
 
1760
                               QLineEdit::Normal, w->property("title").toString(), &ok, this );
 
1761
        if ( ok ) {
 
1762
            QString pn( i18n( "Set the 'title' of '%2'" ).arg( w->name() ) );
 
1763
            SetPropertyCommand *cmd = new SetPropertyCommand( pn, formWindow(), w, propertyEditor,
 
1764
                                                              "title", w->property( "title" ),
 
1765
                                                              title, QString::null, QString::null );
 
1766
            cmd->execute();
 
1767
            formWindow()->commandHistory()->addCommand( cmd );
 
1768
            MetaDataBase::setPropertyChanged( w, "title", TRUE );
 
1769
        }
 
1770
    } else if ( id == props[ "pagetitle" ] ) {
 
1771
        bool ok = FALSE;
 
1772
        QString text = QInputDialog::getText( i18n("Page Title"), i18n( "New page title" ),
 
1773
                              QLineEdit::Normal, w->property("pageTitle").toString(), &ok, this );
 
1774
        if ( ok ) {
 
1775
            QString pn( i18n( "Set the 'pageTitle' of '%2'" ).arg( w->name() ) );
 
1776
            SetPropertyCommand *cmd = new SetPropertyCommand( pn, formWindow(), w, propertyEditor,
 
1777
                                                              "pageTitle",
 
1778
                                                              w->property( "pageTitle" ),
 
1779
                                                              text, QString::null, QString::null );
 
1780
            cmd->execute();
 
1781
            formWindow()->commandHistory()->addCommand( cmd );
 
1782
            MetaDataBase::setPropertyChanged( w, "pageTitle", TRUE );
 
1783
        }
 
1784
    } else if ( id == props[ "pixmap" ] ) {
 
1785
        QPixmap oldPix = w->property( "pixmap" ).toPixmap();
 
1786
        QPixmap pix = qChoosePixmap( this, formWindow(), oldPix );
 
1787
        if ( !pix.isNull() ) {
 
1788
            QString pn( i18n( "Set the 'pixmap' of '%2'" ).arg( w->name() ) );
 
1789
            SetPropertyCommand *cmd = new SetPropertyCommand( pn, formWindow(), w, propertyEditor,
 
1790
                                                              "pixmap", w->property( "pixmap" ),
 
1791
                                                              pix, QString::null, QString::null );
 
1792
            cmd->execute();
 
1793
            formWindow()->commandHistory()->addCommand( cmd );
 
1794
            MetaDataBase::setPropertyChanged( w, "pixmap", TRUE );
 
1795
        }
 
1796
    }
 
1797
}
 
1798
 
 
1799
void MainWindow::handleRMBSpecialCommands( int id, QMap<QString, int> &commands, QWidget *w )
 
1800
{
 
1801
    if ( ::qt_cast<QTabWidget*>(w) ) {
 
1802
        QTabWidget *tw = (QTabWidget*)w;
 
1803
        if ( id == commands[ "add" ] ) {
 
1804
            AddTabPageCommand *cmd =
 
1805
                new AddTabPageCommand( i18n( "Add Page to %1" ).arg( tw->name() ), formWindow(),
 
1806
                                       tw, "Tab" );
 
1807
            formWindow()->commandHistory()->addCommand( cmd );
 
1808
            cmd->execute();
 
1809
        } else if ( id == commands[ "remove" ] ) {
 
1810
            if ( tw->currentPage() ) {
 
1811
                QDesignerTabWidget *dtw = (QDesignerTabWidget*)tw;
 
1812
                DeleteTabPageCommand *cmd =
 
1813
                    new DeleteTabPageCommand( i18n( "Delete Page %1 of %2" ).
 
1814
                                              arg( dtw->pageTitle() ).arg( tw->name() ),
 
1815
                                              formWindow(), tw, tw->currentPage() );
 
1816
                formWindow()->commandHistory()->addCommand( cmd );
 
1817
                cmd->execute();
 
1818
            }
 
1819
        }
 
1820
    } else if ( ::qt_cast<QToolBox*>(w) ) {
 
1821
        QToolBox *tb = (QToolBox*)w;
 
1822
        if ( id == commands[ "add" ] ) {
 
1823
            AddToolBoxPageCommand *cmd =
 
1824
                new AddToolBoxPageCommand( i18n( "Add Page to %1" ).arg( tb->name() ),
 
1825
                                           formWindow(),
 
1826
                                           tb, "Page" );
 
1827
            formWindow()->commandHistory()->addCommand( cmd );
 
1828
            cmd->execute();
 
1829
        } else if ( id == commands[ "remove" ] ) {
 
1830
            if ( tb->currentItem() ) {
 
1831
                DeleteToolBoxPageCommand *cmd =
 
1832
                    new DeleteToolBoxPageCommand( i18n( "Delete Page %1 of %2" ).
 
1833
                                          arg( tb->itemLabel( tb->currentIndex() ) ).
 
1834
                                          arg( tb->name() ),
 
1835
                                          formWindow(), tb, tb->currentItem() );
 
1836
                formWindow()->commandHistory()->addCommand( cmd );
 
1837
                cmd->execute();
 
1838
            }
 
1839
        }
 
1840
    } else if ( ::qt_cast<QWidgetStack*>(w) ) {
 
1841
        QDesignerWidgetStack *ws = (QDesignerWidgetStack*)w;
 
1842
        if ( id == commands[ "add" ] ) {
 
1843
            AddWidgetStackPageCommand *cmd =
 
1844
                new AddWidgetStackPageCommand( i18n( "Add Page to %1" ).arg( ws->name() ),
 
1845
                                               formWindow(), ws );
 
1846
            formWindow()->commandHistory()->addCommand( cmd );
 
1847
            cmd->execute();
 
1848
        } else if ( id == commands[ "remove" ] ) {
 
1849
            if ( ws->visibleWidget() ) {
 
1850
                DeleteWidgetStackPageCommand *cmd =
 
1851
                    new DeleteWidgetStackPageCommand( i18n( "Delete Page %1 of %2" ).
 
1852
                                                      arg( ws->currentPage() ).arg( ws->name() ),
 
1853
                                                      formWindow(), ws, ws->visibleWidget() );
 
1854
                formWindow()->commandHistory()->addCommand( cmd );
 
1855
                cmd->execute();
 
1856
            }
 
1857
        } else if ( id == commands[ "nextpage" ] ) {
 
1858
            int currentPage = w->property( "currentPage" ).toInt();
 
1859
            QString pn( i18n( "Raise next page of '%2'" ).arg( w->name() ) );
 
1860
            SetPropertyCommand *cmd =
 
1861
                new SetPropertyCommand( pn, formWindow(), w, propertyEditor,
 
1862
                                        "currentPage", currentPage,
 
1863
                                        currentPage + 1, QString::null, QString::null );
 
1864
            cmd->execute();
 
1865
            formWindow()->commandHistory()->addCommand( cmd );
 
1866
            MetaDataBase::setPropertyChanged( w, "currentPage", TRUE );
 
1867
        } else if ( id == commands[ "prevpage" ] ) {
 
1868
            int currentPage = w->property( "currentPage" ).toInt();
 
1869
            QString pn( i18n( "Raise previous page of '%2'" ).arg( w->name() ) );
 
1870
            SetPropertyCommand *cmd =
 
1871
                new SetPropertyCommand( pn, formWindow(), w, propertyEditor,
 
1872
                                        "currentPage", currentPage,
 
1873
                                        currentPage -1, QString::null, QString::null );
 
1874
            cmd->execute();
 
1875
            formWindow()->commandHistory()->addCommand( cmd );
 
1876
            MetaDataBase::setPropertyChanged( w, "currentPage", TRUE );
 
1877
        }
 
1878
#ifdef QT_CONTAINER_CUSTOM_WIDGETS
 
1879
    } else if ( WidgetDatabase::
 
1880
                isCustomPluginWidget( WidgetDatabase::
 
1881
                                      idFromClassName( WidgetFactory::classNameOf( w ) ) ) ) {
 
1882
        if ( id == commands[ "add" ] ) {
 
1883
            AddContainerPageCommand *cmd =
 
1884
                new AddContainerPageCommand( i18n( "Add Page to %1" ).arg( w->name() ),
 
1885
                                             formWindow(), w, "Page" );
 
1886
            formWindow()->commandHistory()->addCommand( cmd );
 
1887
            cmd->execute();
 
1888
        } else if ( id == commands[ "remove" ] ) {
 
1889
            QWidgetContainerInterfacePrivate *iface = containerWidgetInterface( w );
 
1890
            if ( iface ) {
 
1891
                QString wClassName = WidgetFactory::classNameOf( w );
 
1892
                int index = iface->currentIndex( wClassName, w );
 
1893
                DeleteContainerPageCommand *cmd =
 
1894
                    new DeleteContainerPageCommand( i18n( "Delete Page %1 of %2" ).
 
1895
                                                    arg( iface->pageLabel( wClassName,
 
1896
                                                                           w, index ) ).
 
1897
                                                    arg( w->name() ),
 
1898
                                                    formWindow(), w, index );
 
1899
                formWindow()->commandHistory()->addCommand( cmd );
 
1900
                cmd->execute();
 
1901
                iface->release();
 
1902
            }
 
1903
        } else if ( id == commands[ "rename" ] ) {
 
1904
            QWidgetContainerInterfacePrivate *iface = containerWidgetInterface( w );
 
1905
            if ( iface ) {
 
1906
                bool ok = FALSE;
 
1907
                QString wClassName = WidgetFactory::classNameOf( w );
 
1908
                int index = iface->currentIndex( wClassName, w );
 
1909
                QString text = QInputDialog::getText( i18n("Page Title"), i18n( "New page title" ),
 
1910
                                                      QLineEdit::Normal,
 
1911
                                                      iface->pageLabel( wClassName, w,
 
1912
                                                                       index ),
 
1913
                                                      &ok, this );
 
1914
                if ( ok ) {
 
1915
                    RenameContainerPageCommand *cmd =
 
1916
                        new RenameContainerPageCommand( i18n( "Rename Page %1 to %2" ).
 
1917
                                                        arg( iface->
 
1918
                                                             pageLabel( wClassName, w,
 
1919
                                                                        index ) ).
 
1920
                                                        arg( text ), formWindow(),
 
1921
                                                        w, index, text );
 
1922
                    formWindow()->commandHistory()->addCommand( cmd );
 
1923
                    cmd->execute();
 
1924
                }
 
1925
                iface->release();
 
1926
            }
 
1927
        }
 
1928
#endif // QT_CONTAINER_CUSTOM_WIDGETS
 
1929
    }
 
1930
 
 
1931
    if ( WidgetFactory::hasSpecialEditor( WidgetDatabase::
 
1932
                                  idFromClassName( WidgetFactory::classNameOf( w ) ), w ) ) {
 
1933
        if ( id == commands[ "edit" ] )
 
1934
            WidgetFactory::editWidget( WidgetDatabase::
 
1935
                       idFromClassName( WidgetFactory::classNameOf( w ) ), this, w, formWindow() );
 
1936
    }
 
1937
}
 
1938
 
 
1939
void MainWindow::handleRMBSpecialCommands( int id, QMap<QString, int> &commands, FormWindow *fw )
 
1940
{
 
1941
    if ( ::qt_cast<QWizard*>(fw->mainContainer()) ) {
 
1942
        QWizard *wiz = (QWizard*)fw->mainContainer();
 
1943
        if ( id == commands[ "add" ] ) {
 
1944
            AddWizardPageCommand *cmd =
 
1945
                new AddWizardPageCommand( i18n( "Add Page to %1" ).arg( wiz->name() ),
 
1946
                                          formWindow(), wiz, "WizardPage" );
 
1947
            formWindow()->commandHistory()->addCommand( cmd );
 
1948
            cmd->execute();
 
1949
        } else if ( id == commands[ "remove" ] ) {
 
1950
            if ( wiz->currentPage() ) {
 
1951
                QDesignerWizard *dw = (QDesignerWizard*)wiz;
 
1952
                DeleteWizardPageCommand *cmd =
 
1953
                    new DeleteWizardPageCommand( i18n( "Delete Page %1 of %2" ).
 
1954
                                                 arg( dw->pageTitle() ).arg( wiz->name() ),
 
1955
                                                 formWindow(), wiz,
 
1956
                                                 wiz->indexOf( wiz->currentPage() ) );
 
1957
                formWindow()->commandHistory()->addCommand( cmd );
 
1958
                cmd->execute();
 
1959
            }
 
1960
        } else if ( id == commands[ "edit" ] ) {
 
1961
            WizardEditor *e = new WizardEditor( this, wiz, fw );
 
1962
            e->exec();
 
1963
            delete e;
 
1964
        } else if ( id == commands[ "rename" ] ) {
 
1965
 
 
1966
            bool ok = FALSE;
 
1967
            QDesignerWizard *dw = (QDesignerWizard*)wiz;
 
1968
            QString text = QInputDialog::getText( i18n("Page Title"), i18n( "New page title" ),
 
1969
                                          QLineEdit::Normal, dw->pageTitle(), &ok, this );
 
1970
            if ( ok ) {
 
1971
                QString pn( i18n( "Rename page %1 of %2" ).arg( dw->pageTitle() ).arg( wiz->name() ) );
 
1972
                RenameWizardPageCommand *cmd =
 
1973
                    new RenameWizardPageCommand( pn, formWindow()
 
1974
                                                 , wiz, wiz->indexOf( wiz->currentPage() ), text );
 
1975
                formWindow()->commandHistory()->addCommand( cmd );
 
1976
                cmd->execute();
 
1977
            }
 
1978
        }
 
1979
    } else if ( ::qt_cast<QMainWindow*>(fw->mainContainer()) ) {
 
1980
        QMainWindow *mw = (QMainWindow*)fw->mainContainer();
 
1981
        if ( id == commands[ "add_toolbar" ] ) {
 
1982
            AddToolBarCommand *cmd =
 
1983
                new AddToolBarCommand( i18n( "Add Toolbar to '%1'" ).arg( formWindow()->name() ),
 
1984
                                       formWindow(), mw );
 
1985
            formWindow()->commandHistory()->addCommand( cmd );
 
1986
            cmd->execute();
 
1987
        } else if ( id == commands[ "add_menu_item" ] ) {
 
1988
            AddMenuCommand *cmd =
 
1989
                new AddMenuCommand( i18n( "Add Menu to '%1'" ).arg( formWindow()->name() ),
 
1990
                                    formWindow(), mw );
 
1991
            formWindow()->commandHistory()->addCommand( cmd );
 
1992
            cmd->execute();
 
1993
        }
 
1994
    }
 
1995
}
 
1996
 
 
1997
void MainWindow::clipboardChanged()
 
1998
{
 
1999
    QString text( qApp->clipboard()->text() );
 
2000
    QString start( "<!DOCTYPE UI-SELECTION>" );
 
2001
    actionEditPaste->setEnabled( text.left( start.length() ) == start );
 
2002
}
 
2003
 
 
2004
void MainWindow::selectionChanged()
 
2005
{
 
2006
    layoutChilds = FALSE;
 
2007
    layoutSelected = FALSE;
 
2008
    breakLayout = FALSE;
 
2009
    if ( !formWindow() ) {
 
2010
        actionEditCut->setEnabled( FALSE );
 
2011
        actionEditCopy->setEnabled( FALSE );
 
2012
        actionEditDelete->setEnabled( FALSE );
 
2013
        actionEditAdjustSize->setEnabled( FALSE );
 
2014
        actionEditHLayout->setEnabled( FALSE );
 
2015
        actionEditVLayout->setEnabled( FALSE );
 
2016
        actionEditSplitHorizontal->setEnabled( FALSE );
 
2017
        actionEditSplitVertical->setEnabled( FALSE );
 
2018
        actionEditGridLayout->setEnabled( FALSE );
 
2019
        actionEditBreakLayout->setEnabled( FALSE );
 
2020
        actionEditLower->setEnabled( FALSE );
 
2021
        actionEditRaise->setEnabled( FALSE );
 
2022
        actionEditAdjustSize->setEnabled( FALSE );
 
2023
        return;
 
2024
    }
 
2025
 
 
2026
    int selectedWidgets = formWindow()->numSelectedWidgets();
 
2027
    bool enable = selectedWidgets > 0;
 
2028
    actionEditCut->setEnabled( enable );
 
2029
    actionEditCopy->setEnabled( enable );
 
2030
    actionEditDelete->setEnabled( enable );
 
2031
    actionEditLower->setEnabled( enable );
 
2032
    actionEditRaise->setEnabled( enable );
 
2033
 
 
2034
    actionEditAdjustSize->setEnabled( FALSE );
 
2035
    actionEditSplitHorizontal->setEnabled( FALSE );
 
2036
    actionEditSplitVertical->setEnabled( FALSE );
 
2037
 
 
2038
    enable = FALSE;
 
2039
    QWidgetList widgets = formWindow()->selectedWidgets();
 
2040
    if ( selectedWidgets > 1 ) {
 
2041
        int unlaidout = 0;
 
2042
        int laidout = 0;
 
2043
        for ( QWidget *w = widgets.first(); w; w = widgets.next() ) {
 
2044
            if ( !w->parentWidget() || WidgetFactory::layoutType( w->parentWidget() ) == WidgetFactory::NoLayout )
 
2045
                unlaidout++;
 
2046
            else
 
2047
                laidout++;
 
2048
        }
 
2049
        actionEditHLayout->setEnabled( unlaidout > 1 );
 
2050
        actionEditVLayout->setEnabled( unlaidout > 1 );
 
2051
        actionEditSplitHorizontal->setEnabled( unlaidout > 1 );
 
2052
        actionEditSplitVertical->setEnabled( unlaidout > 1 );
 
2053
        actionEditGridLayout->setEnabled( unlaidout > 1 );
 
2054
        actionEditBreakLayout->setEnabled( laidout > 0 );
 
2055
        actionEditAdjustSize->setEnabled( laidout > 0 );
 
2056
        layoutSelected = unlaidout > 1;
 
2057
        breakLayout = laidout > 0;
 
2058
    } else if ( selectedWidgets == 1 ) {
 
2059
        QWidget *w = widgets.first();
 
2060
        bool isContainer = WidgetDatabase::isContainer( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( w ) ) ) ||
 
2061
                           w == formWindow()->mainContainer();
 
2062
        actionEditAdjustSize->setEnabled( !w->parentWidget() ||
 
2063
                                          WidgetFactory::layoutType( w->parentWidget() ) == WidgetFactory::NoLayout );
 
2064
 
 
2065
        if ( !isContainer ) {
 
2066
            actionEditHLayout->setEnabled( FALSE );
 
2067
            actionEditVLayout->setEnabled( FALSE );
 
2068
            actionEditGridLayout->setEnabled( FALSE );
 
2069
            if ( w->parentWidget() && WidgetFactory::layoutType( w->parentWidget() ) != WidgetFactory::NoLayout ) {
 
2070
                actionEditBreakLayout->setEnabled( !isAToolBarChild( w ) );
 
2071
                breakLayout = TRUE;
 
2072
            } else {
 
2073
                actionEditBreakLayout->setEnabled( FALSE );
 
2074
            }
 
2075
        } else {
 
2076
            if ( WidgetFactory::layoutType( w ) == WidgetFactory::NoLayout ) {
 
2077
                if ( !formWindow()->hasInsertedChildren( w ) ) {
 
2078
                    actionEditHLayout->setEnabled( FALSE );
 
2079
                    actionEditVLayout->setEnabled( FALSE );
 
2080
                    actionEditGridLayout->setEnabled( FALSE );
 
2081
                    actionEditBreakLayout->setEnabled( FALSE );
 
2082
                } else {
 
2083
                    actionEditHLayout->setEnabled( TRUE );
 
2084
                    actionEditVLayout->setEnabled( TRUE );
 
2085
                    actionEditGridLayout->setEnabled( TRUE );
 
2086
                    actionEditBreakLayout->setEnabled( FALSE );
 
2087
                    layoutChilds = TRUE;
 
2088
                }
 
2089
                if ( w->parentWidget() && WidgetFactory::layoutType( w->parentWidget() ) != WidgetFactory::NoLayout ) {
 
2090
                    actionEditBreakLayout->setEnabled( !isAToolBarChild( w ) );
 
2091
                    breakLayout = TRUE;
 
2092
                }
 
2093
            } else {
 
2094
                actionEditHLayout->setEnabled( FALSE );
 
2095
                actionEditVLayout->setEnabled( FALSE );
 
2096
                actionEditGridLayout->setEnabled( FALSE );
 
2097
                actionEditBreakLayout->setEnabled( !isAToolBarChild( w ) );
 
2098
                breakLayout = TRUE;
 
2099
            }
 
2100
        }
 
2101
    } else if ( selectedWidgets == 0 ) {
 
2102
        actionEditAdjustSize->setEnabled( TRUE );
 
2103
        QWidget *w = formWindow()->mainContainer();
 
2104
        if ( WidgetFactory::layoutType( w ) == WidgetFactory::NoLayout ) {
 
2105
            if ( !formWindow()->hasInsertedChildren( w ) ) {
 
2106
                actionEditHLayout->setEnabled( FALSE );
 
2107
                actionEditVLayout->setEnabled( FALSE );
 
2108
                actionEditGridLayout->setEnabled( FALSE );
 
2109
                actionEditBreakLayout->setEnabled( FALSE );
 
2110
            } else {
 
2111
                actionEditHLayout->setEnabled( TRUE );
 
2112
                actionEditVLayout->setEnabled( TRUE );
 
2113
                actionEditGridLayout->setEnabled( TRUE );
 
2114
                actionEditBreakLayout->setEnabled( FALSE );
 
2115
                layoutChilds = TRUE;
 
2116
            }
 
2117
        } else {
 
2118
            actionEditHLayout->setEnabled( FALSE );
 
2119
            actionEditVLayout->setEnabled( FALSE );
 
2120
            actionEditGridLayout->setEnabled( FALSE );
 
2121
            actionEditBreakLayout->setEnabled( TRUE );
 
2122
            breakLayout = TRUE;
 
2123
        }
 
2124
    } else {
 
2125
        actionEditHLayout->setEnabled( FALSE );
 
2126
        actionEditVLayout->setEnabled( FALSE );
 
2127
        actionEditGridLayout->setEnabled( FALSE );
 
2128
        actionEditBreakLayout->setEnabled( FALSE );
 
2129
    }
 
2130
}
 
2131
 
 
2132
static QString fixArgs( const QString &s2 )
 
2133
{
 
2134
    QString s = s2;
 
2135
    return s.replace( ',', ';' );
 
2136
}
 
2137
 
 
2138
void MainWindow::writeConfig()
 
2139
{
 
2140
    QSettings config;
 
2141
 
 
2142
    // No search path for unix, only needs application name
 
2143
    config.insertSearchPath( QSettings::Windows, "/Trolltech" );
 
2144
 
 
2145
    QString keybase = DesignerApplication::settingsKey();
 
2146
 
 
2147
    if (savePluginPaths) {
 
2148
        QStringList pluginPaths = QApplication::libraryPaths();
 
2149
        config.writeEntry( keybase + "PluginPaths", pluginPaths );
 
2150
    }
 
2151
    config.writeEntry( keybase + "RestoreWorkspace", restoreConfig );
 
2152
    config.writeEntry( keybase + "SplashScreen", splashScreen );
 
2153
    config.writeEntry( keybase + "ShowStartDialog", shStartDialog );
 
2154
    config.writeEntry( keybase + "FileFilter", fileFilter );
 
2155
    config.writeEntry( keybase + "TemplatePath", templPath );
 
2156
    config.writeEntry( keybase + "RecentlyOpenedFiles", recentlyFiles );
 
2157
    config.writeEntry( keybase + "RecentlyOpenedProjects", recentlyProjects );
 
2158
    config.writeEntry( keybase + "DatabaseAutoEdit", databaseAutoEdit );
 
2159
 
 
2160
    config.writeEntry( keybase + "AutoSave/Enabled", autoSaveEnabled );
 
2161
    config.writeEntry( keybase + "AutoSave/Interval", autoSaveInterval );
 
2162
 
 
2163
    config.writeEntry( keybase + "Grid/Snap", snGrid );
 
2164
    config.writeEntry( keybase + "Grid/Show", sGrid );
 
2165
    config.writeEntry( keybase + "Grid/x", grid().x() );
 
2166
    config.writeEntry( keybase + "Grid/y", grid().y() );
 
2167
    config.writeEntry( keybase + "LastToolPage",
 
2168
                       toolBox->itemLabel( toolBox->currentIndex() ) );
 
2169
 
 
2170
    config.writeEntry( keybase + "Background/UsePixmap", backPix );
 
2171
    config.writeEntry( keybase + "Background/Color", (int)qworkspace->backgroundColor().rgb() );
 
2172
    if ( qworkspace->backgroundPixmap() )
 
2173
        qworkspace->backgroundPixmap()->save( QDir::home().absPath() + "/.designer/" + "background.xpm", "PNG" );
 
2174
 
 
2175
    config.writeEntry( keybase + "Geometries/MainwindowX", x() );
 
2176
    config.writeEntry( keybase + "Geometries/MainwindowY", y() );
 
2177
    config.writeEntry( keybase + "Geometries/MainwindowWidth", width() );
 
2178
    config.writeEntry( keybase + "Geometries/MainwindowHeight", height() );
 
2179
    config.writeEntry( keybase + "Geometries/MainwindowMaximized", isMaximized() );
 
2180
    config.writeEntry( keybase + "Geometries/PropertyEditorX", propertyEditor->parentWidget()->x() );
 
2181
    config.writeEntry( keybase + "Geometries/PropertyEditorY", propertyEditor->parentWidget()->y() );
 
2182
    config.writeEntry( keybase + "Geometries/PropertyEditorWidth", propertyEditor->parentWidget()->width() );
 
2183
    config.writeEntry( keybase + "Geometries/PropertyEditorHeight", propertyEditor->parentWidget()->height() );
 
2184
    config.writeEntry( keybase + "Geometries/HierarchyViewX", hierarchyView->parentWidget()->x() );
 
2185
    config.writeEntry( keybase + "Geometries/HierarchyViewY", hierarchyView->parentWidget()->y() );
 
2186
    config.writeEntry( keybase + "Geometries/HierarchyViewWidth", hierarchyView->parentWidget()->width() );
 
2187
    config.writeEntry( keybase + "Geometries/HierarchyViewHeight", hierarchyView->parentWidget()->height() );
 
2188
    config.writeEntry( keybase + "Geometries/WorkspaceX", wspace->parentWidget()->x() );
 
2189
    config.writeEntry( keybase + "Geometries/WorkspaceY", wspace->parentWidget()->y() );
 
2190
    config.writeEntry( keybase + "Geometries/WorkspaceWidth", wspace->parentWidget()->width() );
 
2191
    config.writeEntry( keybase + "Geometries/WorkspaceHeight", wspace->parentWidget()->height() );
 
2192
 
 
2193
    config.writeEntry( keybase + "View/TextLabels", usesTextLabel() );
 
2194
    config.writeEntry( keybase + "View/BigIcons", usesBigPixmaps() );
 
2195
 
 
2196
    QString mwlKey = "MainwindowLayout";
 
2197
    if ( singleProjectMode() )
 
2198
        mwlKey += "S";
 
2199
    QString mainWindowLayout;
 
2200
    QTextStream ts( &mainWindowLayout, IO_WriteOnly );
 
2201
    ts << *this;
 
2202
    config.writeEntry( keybase + mwlKey, mainWindowLayout );
 
2203
 
 
2204
 
 
2205
    QPtrList<MetaDataBase::CustomWidget> *lst = MetaDataBase::customWidgets();
 
2206
    config.writeEntry( keybase + "CustomWidgets/num", (int)lst->count() );
 
2207
    int j = 0;
 
2208
    QDir::home().mkdir( ".designer" );
 
2209
    for ( MetaDataBase::CustomWidget *w = lst->first(); w; w = lst->next() ) {
 
2210
        QStringList l;
 
2211
        l << w->className;
 
2212
        l << w->includeFile;
 
2213
        l << QString::number( (int)w->includePolicy );
 
2214
        l << QString::number( w->sizeHint.width() );
 
2215
        l << QString::number( w->sizeHint.height() );
 
2216
        l << QString::number( w->lstSignals.count() );
 
2217
        for ( QValueList<QCString>::ConstIterator it = w->lstSignals.begin(); it != w->lstSignals.end(); ++it )
 
2218
            l << QString( fixArgs( *it ) );
 
2219
        l << QString::number( w->lstSlots.count() );
 
2220
        for ( QValueList<MetaDataBase::Function>::ConstIterator it2 = w->lstSlots.begin(); it2 != w->lstSlots.end(); ++it2 ) {
 
2221
            l << fixArgs( (*it2).function );
 
2222
            l << (*it2).access;
 
2223
        }
 
2224
        l << QString::number( w->lstProperties.count() );
 
2225
        for ( QValueList<MetaDataBase::Property>::ConstIterator it3 = w->lstProperties.begin(); it3 != w->lstProperties.end(); ++it3 ) {
 
2226
            l << (*it3).property;
 
2227
            l << (*it3).type;
 
2228
        }
 
2229
        l << QString::number( size_type_to_int( w->sizePolicy.horData() ) );
 
2230
        l << QString::number( size_type_to_int( w->sizePolicy.verData() ) );
 
2231
        l << QString::number( (int)w->isContainer );
 
2232
        config.writeEntry( keybase + "CustomWidgets/Widget" + QString::number( j++ ), l, ',' );
 
2233
        w->pixmap->save( QDir::home().absPath() + "/.designer/" + w->className, "XPM" );
 
2234
    }
 
2235
 
 
2236
    QStringList l;
 
2237
    for ( QAction *a = commonWidgetsPage.first(); a; a = commonWidgetsPage.next() )
 
2238
        l << a->text();
 
2239
    config.writeEntry( keybase + "ToolBox/CommonWidgets", l );
 
2240
}
 
2241
 
 
2242
static QString fixArgs2( const QString &s2 )
 
2243
{
 
2244
    QString s = s2;
 
2245
    return s.replace( ';', ',' );
 
2246
}
 
2247
 
 
2248
void MainWindow::readConfig()
 
2249
{
 
2250
    QString keybase = DesignerApplication::settingsKey();
 
2251
    QSettings config;
 
2252
    config.insertSearchPath( QSettings::Windows, "/Trolltech" );
 
2253
 
 
2254
    bool ok;
 
2255
    bool readPreviousConfig = FALSE;
 
2256
    QString backPixName( QDir::home().absPath() + "/.designer/" + "background.xpm" );
 
2257
    restoreConfig = config.readBoolEntry( keybase + "RestoreWorkspace", TRUE, &ok );
 
2258
    if ( !ok ) {
 
2259
        keybase = DesignerApplication::oldSettingsKey();
 
2260
        restoreConfig = config.readBoolEntry( keybase + "RestoreWorkspace", TRUE, &ok );
 
2261
        if ( !ok ) {
 
2262
            if ( oWindow ) {
 
2263
                oWindow->shuttingDown();
 
2264
                ( (QDockWindow*)oWindow->parent() )->hide();
 
2265
            }
 
2266
            QPixmap pix;
 
2267
            pix.load( backPixName );
 
2268
            if ( !pix.isNull() )
 
2269
                qworkspace->setBackgroundPixmap( pix );
 
2270
            return;
 
2271
        }
 
2272
        readPreviousConfig = TRUE;
 
2273
    }
 
2274
    if ( !readPreviousConfig ) {
 
2275
        fileFilter = config.readEntry( keybase + "FileFilter", fileFilter );
 
2276
        templPath = config.readEntry( keybase + "TemplatePath", QString::null );
 
2277
        databaseAutoEdit = config.readBoolEntry( keybase + "DatabaseAutoEdit", databaseAutoEdit );
 
2278
        shStartDialog = config.readBoolEntry( keybase + "ShowStartDialog", shStartDialog );
 
2279
        autoSaveEnabled = config.readBoolEntry( keybase + "AutoSave/Enabled", autoSaveEnabled );
 
2280
        autoSaveInterval = config.readNumEntry( keybase + "AutoSave/Interval", autoSaveInterval );
 
2281
    }
 
2282
 
 
2283
    if ( restoreConfig || readPreviousConfig ) {
 
2284
        QString s = config.readEntry( keybase + "LastToolPage" );
 
2285
        for ( int i = 0; i < toolBox->count(); ++i ) {
 
2286
            if ( toolBox->itemLabel(i) == s ) {
 
2287
                toolBox->setCurrentIndex( i );
 
2288
                break;
 
2289
            }
 
2290
        }
 
2291
        // We know that the oldSettingsKey() will return 3.1
 
2292
        if ( keybase == DesignerApplication::oldSettingsKey() ) {
 
2293
            if (keybase.contains("3.1"))
 
2294
                recentlyFiles = config.readListEntry( keybase + "RecentlyOpenedFiles", ',' );
 
2295
            else
 
2296
                recentlyFiles = config.readListEntry(keybase + "RecentlyOpenedFiles");
 
2297
 
 
2298
            if ( recentlyFiles.count() == 1 && recentlyFiles[0].isNull() )
 
2299
                recentlyFiles.clear();
 
2300
            if (keybase.contains("3.1"))
 
2301
                recentlyProjects = config.readListEntry( keybase + "RecentlyOpenedProjects", ',' );
 
2302
            else
 
2303
                recentlyProjects = config.readListEntry( keybase + "RecentlyOpenedProjects");
 
2304
            if ( recentlyProjects.count() == 1 && recentlyProjects[0].isNull() )
 
2305
                recentlyProjects.clear();
 
2306
        } else {
 
2307
            recentlyFiles = config.readListEntry( keybase + "RecentlyOpenedFiles" );
 
2308
            recentlyProjects = config.readListEntry( keybase + "RecentlyOpenedProjects" );
 
2309
        }
 
2310
 
 
2311
        backPix = config.readBoolEntry( keybase + "Background/UsePixmap", TRUE ) | readPreviousConfig;
 
2312
        if ( backPix ) {
 
2313
            QPixmap pix;
 
2314
            pix.load( backPixName );
 
2315
            if ( !pix.isNull() )
 
2316
                qworkspace->setBackgroundPixmap( pix );
 
2317
        } else {
 
2318
            qworkspace->setBackgroundColor( QColor( (QRgb)config.readNumEntry( keybase + "Background/Color" ) ) );
 
2319
        }
 
2320
 
 
2321
        if ( !readPreviousConfig ) {
 
2322
            splashScreen = config.readBoolEntry( keybase + "SplashScreen", TRUE );
 
2323
 
 
2324
            sGrid = config.readBoolEntry( keybase + "Grid/Show", TRUE );
 
2325
            snGrid = config.readBoolEntry( keybase + "Grid/Snap", TRUE );
 
2326
            grd.setX( config.readNumEntry( keybase + "Grid/x", 10 ) );
 
2327
            grd.setY( config.readNumEntry( keybase + "Grid/y", 10 ) );
 
2328
 
 
2329
            if ( !config.readBoolEntry( DesignerApplication::settingsKey() + "Geometries/MainwindowMaximized", FALSE ) ) {
 
2330
                QRect r( pos(), size() );
 
2331
                r.setX( config.readNumEntry( keybase + "Geometries/MainwindowX", r.x() ) );
 
2332
                r.setY( config.readNumEntry( keybase + "Geometries/MainwindowY", r.y() ) );
 
2333
                r.setWidth( config.readNumEntry( keybase + "Geometries/MainwindowWidth", r.width() ) );
 
2334
                r.setHeight( config.readNumEntry( keybase + "Geometries/MainwindowHeight", r.height() ) );
 
2335
 
 
2336
                QRect desk = QApplication::desktop()->geometry();
 
2337
                QRect inter = desk.intersect( r );
 
2338
                resize( r.size() );
 
2339
                if ( inter.width() * inter.height() > ( r.width() * r.height() / 20 ) ) {
 
2340
                    move( r.topLeft() );
 
2341
                }
 
2342
            }
 
2343
            setUsesTextLabel( config.readBoolEntry( keybase + "View/TextLabels", FALSE ) );
 
2344
            setUsesBigPixmaps( FALSE /*config.readBoolEntry( "BigIcons", FALSE )*/ ); // ### disabled for now
 
2345
        }
 
2346
    }
 
2347
    int num = config.readNumEntry( keybase + "CustomWidgets/num" );
 
2348
    for ( int j = 0; j < num; ++j ) {
 
2349
        MetaDataBase::CustomWidget *w = new MetaDataBase::CustomWidget;
 
2350
        QStringList l = config.readListEntry( keybase + "CustomWidgets/Widget" + QString::number( j ), ',' );
 
2351
        w->className = l[ 0 ];
 
2352
        w->includeFile = l[ 1 ];
 
2353
        w->includePolicy = (MetaDataBase::CustomWidget::IncludePolicy)l[ 2 ].toInt();
 
2354
        w->sizeHint.setWidth( l[ 3 ].toInt() );
 
2355
        w->sizeHint.setHeight( l[ 4 ].toInt() );
 
2356
        uint c = 5;
 
2357
        if ( l.count() > c ) {
 
2358
            int numSignals = l[ c ].toInt();
 
2359
            c++;
 
2360
            for ( int i = 0; i < numSignals; ++i, c++ )
 
2361
                w->lstSignals.append( fixArgs2( l[ c ] ).latin1() );
 
2362
        }
 
2363
        if ( l.count() > c ) {
 
2364
            int numSlots = l[ c ].toInt();
 
2365
            c++;
 
2366
            for ( int i = 0; i < numSlots; ++i ) {
 
2367
                MetaDataBase::Function slot;
 
2368
                slot.function = fixArgs2( l[ c ] );
 
2369
                c++;
 
2370
                slot.access = l[ c ];
 
2371
                c++;
 
2372
                w->lstSlots.append( slot );
 
2373
            }
 
2374
        }
 
2375
        if ( l.count() > c ) {
 
2376
            int numProperties = l[ c ].toInt();
 
2377
            c++;
 
2378
            for ( int i = 0; i < numProperties; ++i ) {
 
2379
                MetaDataBase::Property prop;
 
2380
                prop.property = l[ c ];
 
2381
                c++;
 
2382
                prop.type = l[ c ];
 
2383
                c++;
 
2384
                w->lstProperties.append( prop );
 
2385
            }
 
2386
        } if ( l.count() > c ) {
 
2387
            QSizePolicy::SizeType h, v;
 
2388
             h = int_to_size_type( l[ c++ ].toInt() );
 
2389
             v = int_to_size_type( l[ c++ ].toInt() );
 
2390
             w->sizePolicy = QSizePolicy( h, v );
 
2391
        }
 
2392
        if ( l.count() > c ) {
 
2393
            w->isContainer = (bool)l[ c++ ].toInt();
 
2394
        }
 
2395
        w->pixmap = new QPixmap( BarIcon( QDir::home().absPath() + "/.designer/" + w->className , KDevDesignerPartFactory::instance()) );
 
2396
        MetaDataBase::addCustomWidget( w );
 
2397
    }
 
2398
    if ( num > 0 )
 
2399
        rebuildCustomWidgetGUI();
 
2400
 
 
2401
    if ( !restoreConfig )
 
2402
        return;
 
2403
 
 
2404
#ifndef Q_WS_MAC
 
2405
    /* I'm sorry to make this not happen on the Mac, but it seems to hang somewhere deep
 
2406
       in QLayout, it gets into a very large loop - and seems it has to do with clever
 
2407
       things the designer does ###Sam */
 
2408
    QApplication::sendPostedEvents();
 
2409
#endif
 
2410
 
 
2411
    if ( !readPreviousConfig ) {
 
2412
        QString mwlKey = "MainwindowLayout";
 
2413
        if ( singleProjectMode() )
 
2414
            mwlKey += "S";
 
2415
        QString mainWindowLayout = config.readEntry( keybase + mwlKey );
 
2416
        QTextStream ts( &mainWindowLayout, IO_ReadOnly );
 
2417
        ts >> *this;
 
2418
    }
 
2419
    if ( readPreviousConfig && oWindow ) {
 
2420
        oWindow->shuttingDown();
 
2421
        ( (QDockWindow*)oWindow->parent() )->hide();
 
2422
    }
 
2423
 
 
2424
    rebuildCustomWidgetGUI();
 
2425
 
 
2426
    QStringList l = config.readListEntry( keybase + "ToolBox/CommonWidgets" );
 
2427
    if ( !l.isEmpty() ) {
 
2428
        QPtrList<QAction> lst;
 
2429
        commonWidgetsPage.clear();
 
2430
        for ( QStringList::ConstIterator it = l.begin(); it != l.end(); ++it ) {
 
2431
            for ( QAction *a = toolActions.first(); a; a = toolActions.next() ) {
 
2432
                if ( *it == a->text() ) {
 
2433
                    lst.append( a );
 
2434
                    break;
 
2435
                }
 
2436
            }
 
2437
        }
 
2438
        if ( lst != commonWidgetsPage ) {
 
2439
            commonWidgetsPage = lst;
 
2440
            rebuildCommonWidgetsToolBoxPage();
 
2441
        }
 
2442
    }
 
2443
}
 
2444
 
 
2445
HierarchyView *MainWindow::objectHierarchy() const
 
2446
{
 
2447
    if ( !hierarchyView )
 
2448
        ( (MainWindow*)this )->setupHierarchyView();
 
2449
    return hierarchyView;
 
2450
}
 
2451
 
 
2452
QPopupMenu *MainWindow::setupNormalHierarchyMenu( QWidget *parent )
 
2453
{
 
2454
    QPopupMenu *menu = new QPopupMenu( parent );
 
2455
 
 
2456
    actionEditCut->addTo( menu );
 
2457
    actionEditCopy->addTo( menu );
 
2458
    actionEditPaste->addTo( menu );
 
2459
    actionEditDelete->addTo( menu );
 
2460
 
 
2461
    return menu;
 
2462
}
 
2463
 
 
2464
QPopupMenu *MainWindow::setupTabWidgetHierarchyMenu( QWidget *parent, const char *addSlot, const char *removeSlot )
 
2465
{
 
2466
    QPopupMenu *menu = new QPopupMenu( parent );
 
2467
 
 
2468
    menu->insertItem( i18n( "Add Page" ), parent, addSlot );
 
2469
    menu->insertItem( i18n( "Delete Page" ), parent, removeSlot );
 
2470
    menu->insertSeparator();
 
2471
    actionEditCut->addTo( menu );
 
2472
    actionEditCopy->addTo( menu );
 
2473
    actionEditPaste->addTo( menu );
 
2474
    actionEditDelete->addTo( menu );
 
2475
 
 
2476
    return menu;
 
2477
}
 
2478
 
 
2479
void MainWindow::closeEvent( QCloseEvent *e )
 
2480
{
 
2481
    if ( singleProject ) {
 
2482
        hide();
 
2483
        e->ignore();
 
2484
        return;
 
2485
    }
 
2486
 
 
2487
    QWidgetList windows = qWorkspace()->windowList();
 
2488
    QWidgetListIt wit( windows );
 
2489
    while ( wit.current() ) {
 
2490
        QWidget *w = wit.current();
 
2491
        ++wit;
 
2492
        if ( ::qt_cast<FormWindow*>(w) ) {
 
2493
            if ( ( (FormWindow*)w )->formFile()->editor() )
 
2494
                windows.removeRef( ( (FormWindow*)w )->formFile()->editor() );
 
2495
            if ( ( (FormWindow*)w )->formFile()->formWindow() )
 
2496
                windows.removeRef( ( (FormWindow*)w )->formFile()->formWindow() );
 
2497
            if ( !( (FormWindow*)w )->formFile()->close() ) {
 
2498
                e->ignore();
 
2499
                return;
 
2500
            }
 
2501
        } else if ( ::qt_cast<SourceEditor*>(w) ) {
 
2502
            if ( !( (SourceEditor*)w )->close() ) {
 
2503
                e->ignore();
 
2504
                return;
 
2505
            }
 
2506
        }
 
2507
        w->close();
 
2508
    }
 
2509
 
 
2510
    QMapConstIterator<QAction*, Project*> it = projects.begin();
 
2511
    while( it != projects.end() ) {
 
2512
        Project *pro = it.data();
 
2513
        ++it;
 
2514
        if ( pro->isModified() ) {
 
2515
            switch ( QMessageBox::warning( this, i18n( "Save Project Settings" ),
 
2516
                                           i18n( "Save changes to '%1'?" ).arg( pro->fileName() ),
 
2517
                                           i18n( "&Yes" ), i18n( "&No" ), i18n( "&Cancel" ), 0, 2 ) ) {
 
2518
            case 0: // save
 
2519
                pro->save();
 
2520
                break;
 
2521
            case 1: // don't save
 
2522
                break;
 
2523
            case 2: // cancel
 
2524
                e->ignore();
 
2525
                return;
 
2526
            default:
 
2527
                break;
 
2528
            }
 
2529
        }
 
2530
    }
 
2531
 
 
2532
    writeConfig();
 
2533
    hide();
 
2534
    e->accept();
 
2535
 
 
2536
    if ( client ) {
 
2537
        QDir home( QDir::homeDirPath() );
 
2538
        home.remove( ".designerpid" );
 
2539
    }
 
2540
}
 
2541
 
 
2542
Workspace *MainWindow::workspace() const
 
2543
{
 
2544
    if ( !wspace )
 
2545
        ( (MainWindow*)this )->setupWorkspace();
 
2546
    return wspace;
 
2547
}
 
2548
 
 
2549
PropertyEditor *MainWindow::propertyeditor() const
 
2550
{
 
2551
    if ( !propertyEditor )
 
2552
        ( (MainWindow*)this )->setupPropertyEditor();
 
2553
    return propertyEditor;
 
2554
}
 
2555
 
 
2556
ActionEditor *MainWindow::actioneditor() const
 
2557
{
 
2558
    if ( !actionEditor )
 
2559
        ( (MainWindow*)this )->setupActionEditor();
 
2560
    return actionEditor;
 
2561
}
 
2562
 
 
2563
bool MainWindow::openEditor( QWidget *w, FormWindow *f )
 
2564
{
 
2565
    if ( f && !f->project()->isCpp() && !WidgetFactory::isPassiveInteractor( w ) ) {
 
2566
        QString defSignal = WidgetFactory::defaultSignal( w );
 
2567
        if ( defSignal.isEmpty() ) {
 
2568
            editSource();
 
2569
        } else {
 
2570
            QString s = QString( w->name() ) + "_" + defSignal;
 
2571
            LanguageInterface *iface = MetaDataBase::languageInterface( f->project()->language() );
 
2572
            if ( iface ) {
 
2573
                QStrList sigs = iface->signalNames( w );
 
2574
                QString fullSignal;
 
2575
                for ( int i = 0; i < (int)sigs.count(); ++i ) {
 
2576
                    QString sig = sigs.at( i );
 
2577
                    if ( sig.left( sig.find( '(' ) ) == defSignal ) {
 
2578
                        fullSignal = sig;
 
2579
                        break;
 
2580
                    }
 
2581
                }
 
2582
 
 
2583
                if ( !fullSignal.isEmpty() ) {
 
2584
                    QString signl = fullSignal;
 
2585
                    fullSignal = fullSignal.mid( fullSignal.find( '(' ) + 1 );
 
2586
                    fullSignal.remove( (int)fullSignal.length() - 1, 1 );
 
2587
                    fullSignal = iface->createArguments( fullSignal.simplifyWhiteSpace() );
 
2588
                    s += "(" + fullSignal + ")";
 
2589
                    if ( !MetaDataBase::hasFunction( f, s.latin1() ) )
 
2590
                        MetaDataBase::addFunction( f, s.latin1(), "", "public", "slot",
 
2591
                                                   f->project()->language(), "void" );
 
2592
                    s = s.left( s.find( '(' ) ).latin1();
 
2593
                    if ( !MetaDataBase::hasConnection( f, w, defSignal.latin1(), f->mainContainer(), s.latin1() ) ) {
 
2594
                        MetaDataBase::Connection conn;
 
2595
                        conn.sender = w;
 
2596
                        conn.receiver = f->mainContainer();
 
2597
                        conn.signal = signl;
 
2598
                        conn.slot = s;
 
2599
                        AddConnectionCommand *cmd =
 
2600
                            new AddConnectionCommand( i18n( "Add Connection" ), f, conn );
 
2601
                        f->commandHistory()->addCommand( cmd );
 
2602
                        cmd->execute();
 
2603
                        f->formFile()->setModified( TRUE );
 
2604
                    }
 
2605
                }
 
2606
            }
 
2607
            editFunction( s, TRUE );
 
2608
        }
 
2609
        return TRUE;
 
2610
    }
 
2611
    if ( WidgetFactory::hasSpecialEditor( WidgetDatabase::
 
2612
                                          idFromClassName( WidgetFactory::classNameOf( w ) ), w ) ) {
 
2613
        statusMessage( i18n( "Edit %1..." ).arg( w->className() ) );
 
2614
        WidgetFactory::editWidget( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( w ) ),
 
2615
                                   this, w, formWindow() );
 
2616
        statusBar()->clear();
 
2617
        return TRUE;
 
2618
    }
 
2619
 
 
2620
    const QMetaProperty* text = w->metaObject()->property( w->metaObject()->findProperty( "text", TRUE ), TRUE );
 
2621
    const QMetaProperty* title = w->metaObject()->property( w->metaObject()->findProperty( "title", TRUE ), TRUE );
 
2622
    if ( text && text->designable(w) ) {
 
2623
        bool ok = FALSE;
 
2624
        bool oldDoWrap = FALSE;
 
2625
        if ( ::qt_cast<QLabel*>(w) ) {
 
2626
            int align = w->property( "alignment" ).toInt();
 
2627
            if ( align & WordBreak )
 
2628
                oldDoWrap = TRUE;
 
2629
        }
 
2630
        bool doWrap = oldDoWrap;
 
2631
 
 
2632
        QString text;
 
2633
        if ( ::qt_cast<QTextEdit*>(w) || ::qt_cast<QLabel*>(w) || ::qt_cast<QButton*>(w) ) {
 
2634
            text = MultiLineEditor::getText( this, w->property( "text" ).toString(),
 
2635
                                             !::qt_cast<QButton*>(w), &doWrap );
 
2636
            ok = !text.isNull();
 
2637
        } else {
 
2638
            text = QInputDialog::getText( i18n("Text"), i18n( "New text" ),
 
2639
                                  QLineEdit::Normal, w->property("text").toString(), &ok, this );
 
2640
        }
 
2641
        if ( ok ) {
 
2642
            if ( oldDoWrap != doWrap ) {
 
2643
                QString pn( i18n( "Set 'wordwrap' of '%1'" ).arg( w->name() ) );
 
2644
                SetPropertyCommand *cmd = new SetPropertyCommand( pn, formWindow(), w, propertyEditor,
 
2645
                                                                  "wordwrap", QVariant( oldDoWrap, 0 ),
 
2646
                                                                  QVariant( doWrap, 0 ), QString::null, QString::null );
 
2647
                cmd->execute();
 
2648
                formWindow()->commandHistory()->addCommand( cmd );
 
2649
                MetaDataBase::setPropertyChanged( w, "wordwrap", TRUE );
 
2650
            }
 
2651
 
 
2652
            QString pn( i18n( "Set the 'text' of '%1'" ).arg( w->name() ) );
 
2653
            SetPropertyCommand *cmd = new SetPropertyCommand( pn, formWindow(), w, propertyEditor,
 
2654
                                                              "text", w->property( "text" ),
 
2655
                                                              text, QString::null, QString::null );
 
2656
            cmd->execute();
 
2657
            formWindow()->commandHistory()->addCommand( cmd );
 
2658
            MetaDataBase::setPropertyChanged( w, "text", TRUE );
 
2659
        }
 
2660
        return TRUE;
 
2661
    }
 
2662
    if ( title && title->designable(w) ) {
 
2663
        bool ok = FALSE;
 
2664
        QString text;
 
2665
        text = QInputDialog::getText( i18n("Title"), i18n( "New title" ), QLineEdit::Normal, w->property("title").toString(), &ok, this );
 
2666
        if ( ok ) {
 
2667
            QString pn( i18n( "Set the 'title' of '%2'" ).arg( w->name() ) );
 
2668
            SetPropertyCommand *cmd = new SetPropertyCommand( pn, formWindow(), w, propertyEditor,
 
2669
                                                              "title", w->property( "title" ),
 
2670
                                                              text, QString::null, QString::null );
 
2671
            cmd->execute();
 
2672
            formWindow()->commandHistory()->addCommand( cmd );
 
2673
            MetaDataBase::setPropertyChanged( w, "title", TRUE );
 
2674
        }
 
2675
        return TRUE;
 
2676
    }
 
2677
 
 
2678
    if ( !WidgetFactory::isPassiveInteractor( w ) )
 
2679
        editSource();
 
2680
 
 
2681
    return TRUE;
 
2682
}
 
2683
 
 
2684
void MainWindow::rebuildCustomWidgetGUI()
 
2685
{
 
2686
    customWidgetToolBar->clear();
 
2687
    customWidgetMenu->clear();
 
2688
    customWidgetToolBar2->clear();
 
2689
    int count = 0;
 
2690
 
 
2691
    QPtrListIterator<QAction> it( toolActions );
 
2692
    QAction *action;
 
2693
    while ( ( action = it.current() ) ) {
 
2694
        ++it;
 
2695
        if ( ( (WidgetAction*)action )->group() == "Custom Widgets" )
 
2696
            delete action;
 
2697
    }
 
2698
 
 
2699
    QPtrList<MetaDataBase::CustomWidget> *lst = MetaDataBase::customWidgets();
 
2700
 
 
2701
    actionToolsCustomWidget->addTo( customWidgetMenu );
 
2702
    customWidgetMenu->insertSeparator();
 
2703
 
 
2704
    for ( MetaDataBase::CustomWidget *w = lst->first(); w; w = lst->next() ) {
 
2705
        WidgetAction* a = new WidgetAction( "Custom Widgets", actionGroupTools, QString::number( w->id ).latin1() );
 
2706
        a->setToggleAction( TRUE );
 
2707
        a->setText( w->className );
 
2708
        a->setIconSet( *w->pixmap );
 
2709
        a->setStatusTip( i18n( "Insert a %1 (custom widget)" ).arg( w->className ) );
 
2710
        a->setWhatsThis( i18n("<b>%1 (custom widget)</b>"
 
2711
                            "<p>Click <b>Edit Custom Widgets...</b> in the <b>Tools|Custom</b> menu to "
 
2712
                            "add and change custom widgets. You can add properties as well as "
 
2713
                            "signals and slots to integrate them into Qt Designer, "
 
2714
                            "and provide a pixmap which will be used to represent the widget on the form.</p>").arg( w->className ) );
 
2715
 
 
2716
        a->addTo( customWidgetToolBar );
 
2717
        a->addTo( customWidgetToolBar2 );
 
2718
        a->addTo( customWidgetMenu );
 
2719
        count++;
 
2720
    }
 
2721
    QWidget *wid;
 
2722
    customWidgetToolBar2->setStretchableWidget( ( wid = new QWidget( customWidgetToolBar2 ) ) );
 
2723
    wid->setBackgroundMode( customWidgetToolBar2->backgroundMode() );
 
2724
 
 
2725
    if ( count == 0 )
 
2726
        customWidgetToolBar->hide();
 
2727
    else if ( customWidgetToolBar->isVisible() )
 
2728
        customWidgetToolBar->show();
 
2729
}
 
2730
 
 
2731
void MainWindow::rebuildCommonWidgetsToolBoxPage()
 
2732
{
 
2733
    toolBox->setUpdatesEnabled( FALSE );
 
2734
    commonWidgetsToolBar->setUpdatesEnabled( FALSE );
 
2735
    commonWidgetsToolBar->clear();
 
2736
    for ( QAction *a = commonWidgetsPage.first(); a; a = commonWidgetsPage.next() )
 
2737
        a->addTo( commonWidgetsToolBar );
 
2738
    QWidget *w;
 
2739
    commonWidgetsToolBar->setStretchableWidget( ( w = new QWidget( commonWidgetsToolBar ) ) );
 
2740
    w->setBackgroundMode( commonWidgetsToolBar->backgroundMode() );
 
2741
    toolBox->setUpdatesEnabled( TRUE );
 
2742
    commonWidgetsToolBar->setUpdatesEnabled( TRUE );
 
2743
}
 
2744
 
 
2745
bool MainWindow::isCustomWidgetUsed( MetaDataBase::CustomWidget *wid )
 
2746
{
 
2747
    QWidgetList windows = qWorkspace()->windowList();
 
2748
    for ( QWidget *w = windows.first(); w; w = windows.next() ) {
 
2749
        if ( ::qt_cast<FormWindow*>(w) ) {
 
2750
            if ( ( (FormWindow*)w )->isCustomWidgetUsed( wid ) )
 
2751
                return TRUE;
 
2752
        }
 
2753
    }
 
2754
    return FALSE;
 
2755
}
 
2756
 
 
2757
void MainWindow::setGrid( const QPoint &p )
 
2758
{
 
2759
    if ( p == grd )
 
2760
        return;
 
2761
    grd = p;
 
2762
    QWidgetList windows = qWorkspace()->windowList();
 
2763
    for ( QWidget *w = windows.first(); w; w = windows.next() ) {
 
2764
        if ( !::qt_cast<FormWindow*>(w) )
 
2765
            continue;
 
2766
        ( (FormWindow*)w )->mainContainer()->update();
 
2767
    }
 
2768
}
 
2769
 
 
2770
void MainWindow::setShowGrid( bool b )
 
2771
{
 
2772
    if ( b == sGrid )
 
2773
        return;
 
2774
    sGrid = b;
 
2775
    QWidgetList windows = qWorkspace()->windowList();
 
2776
    for ( QWidget *w = windows.first(); w; w = windows.next() ) {
 
2777
        if ( !::qt_cast<FormWindow*>(w) )
 
2778
            continue;
 
2779
        ( (FormWindow*)w )->mainContainer()->update();
 
2780
    }
 
2781
}
 
2782
 
 
2783
void MainWindow::setSnapGrid( bool b )
 
2784
{
 
2785
    if ( b == snGrid )
 
2786
        return;
 
2787
    snGrid = b;
 
2788
}
 
2789
 
 
2790
QString MainWindow::documentationPath() const
 
2791
{
 
2792
    return QString( qInstallPathDocs() ) + "/html/";
 
2793
}
 
2794
 
 
2795
void MainWindow::windowsMenuActivated( int id )
 
2796
{
 
2797
    QWidget* w = qworkspace->windowList().at( id );
 
2798
    if ( w )
 
2799
        w->setFocus();
 
2800
}
 
2801
 
 
2802
void MainWindow::projectSelected( QAction *a )
 
2803
{
 
2804
    a->setOn( TRUE );
 
2805
    if ( currentProject )
 
2806
        currentProject->setActive( FALSE );
 
2807
    Project *p = *projects.find( a );
 
2808
    p->setActive( TRUE );
 
2809
    if ( currentProject == p )
 
2810
        return;
 
2811
    currentProject = p;
 
2812
    if ( wspace )
 
2813
        wspace->setCurrentProject( currentProject );
 
2814
}
 
2815
 
 
2816
void MainWindow::openProject( const QString &fn )
 
2817
{
 
2818
    for ( QMap<QAction*, Project*>::ConstIterator it = projects.begin(); it != projects.end(); ++it ) {
 
2819
        if ( (*it)->fileName() == fn ) {
 
2820
            projectSelected( it.key() );
 
2821
            return;
 
2822
        }
 
2823
    }
 
2824
    QApplication::setOverrideCursor( waitCursor );
 
2825
    Project *pro = new Project( fn, "", projectSettingsPluginManager );
 
2826
    pro->setModified( FALSE );
 
2827
    QAction *a = new QAction( pro->projectName(), pro->projectName(), 0, actionGroupProjects, 0, TRUE );
 
2828
    projects.insert( a, pro );
 
2829
    projectSelected( a );
 
2830
    QApplication::restoreOverrideCursor();
 
2831
}
 
2832
 
 
2833
void MainWindow::checkTempFiles()
 
2834
{
 
2835
    QString s = QDir::homeDirPath() + "/.designer";
 
2836
    QString baseName = s+ "/saved-form-";
 
2837
    if ( !QFile::exists( baseName + "1.ui" ) )
 
2838
        return;
 
2839
    DesignerApplication::closeSplash();
 
2840
    QDir d( s );
 
2841
    d.setNameFilter( "*.ui" );
 
2842
    QStringList lst = d.entryList();
 
2843
    QApplication::restoreOverrideCursor();
 
2844
    bool load = QMessageBox::information( this, i18n( "Restoring Last Session" ),
 
2845
                                          i18n( "Qt Designer found some temporary saved files, which were\n"
 
2846
                                              "written when Qt Designer crashed last time. Do you want to\n"
 
2847
                                              "load these files?" ), i18n( "&Yes" ), i18n( "&No" ) ) == 0;
 
2848
    QApplication::setOverrideCursor( waitCursor );
 
2849
    for ( QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) {
 
2850
        if ( load )
 
2851
            openFormWindow( s + "/" + *it, FALSE );
 
2852
        d.remove( *it );
 
2853
    }
 
2854
}
 
2855
 
 
2856
void MainWindow::showDialogHelp()
 
2857
{
 
2858
    QWidget *w = (QWidget*)sender();
 
2859
    w = w->topLevelWidget();
 
2860
 
 
2861
    QString link = documentationPath() + "/designer-manual-13.html#";
 
2862
 
 
2863
    if ( ::qt_cast<NewFormBase*>(w) || ::qt_cast<StartDialogBase*>(w) ) // own doc for startdialog?
 
2864
        link += "dialog-file-new";
 
2865
    else if ( ::qt_cast<CreateTemplate*>(w) )
 
2866
        link += "dialog-file-create-template";
 
2867
    else if ( ::qt_cast<EditFunctionsBase*>(w) )
 
2868
        link += "dialog-edit-functions";
 
2869
//     else if ( ::qt_cast<ConnectionViewerBase*>(w) )
 
2870
    else if ( w->inherits("ConnectionViewerBase") )
 
2871
        link += "dialog-view-connections";
 
2872
    else if ( ::qt_cast<FormSettingsBase*>(w) )
 
2873
        link += "dialog-edit-form-settings";
 
2874
    else if ( ::qt_cast<Preferences*>(w) )
 
2875
        link += "dialog-edit-preferences";
 
2876
    else if ( ::qt_cast<PixmapCollectionEditor*>(w) )
 
2877
        link += "dialog-image-collection";
 
2878
//    else if ( ::qt_cast<DatabaseConnectionBase*>(w) )
 
2879
    else if ( w->inherits( "DatabaseConnectionBase" ) )
 
2880
        link += "dialog-edit-database-connections";
 
2881
    else if ( ::qt_cast<ProjectSettingsBase*>(w) )
 
2882
        link += "dialog-project-settings";
 
2883
    else if ( ::qt_cast<FindDialog*>(w) )
 
2884
        link += "dialog-find-text";
 
2885
    else if ( ::qt_cast<ReplaceDialog*>(w) )
 
2886
        link += "dialog-replace-text";
 
2887
    else if ( ::qt_cast<GotoLineDialog*>(w) )
 
2888
        link += "dialog-go-to-line";
 
2889
//    else if ( ::qt_cast<ConnectionEditorBase*>(w) )
 
2890
    else if ( w->inherits("ConnectionEditorBase") )
 
2891
        link += "dialog-edit-connections";
 
2892
    else if ( ::qt_cast<CustomWidgetEditorBase*>(w) )
 
2893
        link += "dialog-edit-custom-widgets";
 
2894
    else if ( ::qt_cast<PaletteEditorBase*>(w) )
 
2895
        link += "dialog-edit-palette";
 
2896
    else if ( ::qt_cast<ListBoxEditorBase*>(w) )
 
2897
        link += "dialog-edit-listbox";
 
2898
    else if ( ::qt_cast<ListViewEditorBase*>(w) )
 
2899
        link += "dialog-edit-listview";
 
2900
    else if ( ::qt_cast<IconViewEditorBase*>(w) )
 
2901
        link += "dialog-edit-iconview";
 
2902
    else if ( ::qt_cast<TableEditorBase*>(w) )
 
2903
        link += "dialog-edit-table";
 
2904
    else if ( ::qt_cast<MultiLineEditor*>(w) )
 
2905
        link += "dialog-text";
 
2906
 
 
2907
    else {
 
2908
        QMessageBox::information( this, i18n( "Help" ),
 
2909
                                  i18n( "There is no help available for this dialog at the moment." ) );
 
2910
        return;
 
2911
    }
 
2912
 
 
2913
    assistant->showPage( link );
 
2914
}
 
2915
 
 
2916
void MainWindow::setupActionManager()
 
2917
{
 
2918
    actionPluginManager = new QPluginManager<ActionInterface>( IID_Action, QApplication::libraryPaths(), pluginDirectory() );
 
2919
 
 
2920
    QStringList lst = actionPluginManager->featureList();
 
2921
    for ( QStringList::ConstIterator ait = lst.begin(); ait != lst.end(); ++ait ) {
 
2922
        ActionInterface *iface = 0;
 
2923
        actionPluginManager->queryInterface( *ait, &iface );
 
2924
        if ( !iface )
 
2925
            continue;
 
2926
 
 
2927
        iface->connectTo( desInterface );
 
2928
        QAction *a = iface->create( *ait, this );
 
2929
        if ( !a )
 
2930
            continue;
 
2931
 
 
2932
        QString grp = iface->group( *ait );
 
2933
        if ( grp.isEmpty() )
 
2934
            grp = "3rd party actions";
 
2935
        QPopupMenu *menu = 0;
 
2936
        QToolBar *tb = 0;
 
2937
 
 
2938
        if ( !( menu = (QPopupMenu*)child( grp.latin1(), "QPopupMenu" ) ) ) {
 
2939
            menu = new QPopupMenu( this, grp.latin1() );
 
2940
            menuBar()->insertItem( i18n( grp ), menu );
 
2941
        }
 
2942
        if ( !( tb = (QToolBar*)child( grp.latin1(), "QToolBar" ) ) ) {
 
2943
            tb = new QToolBar( this, grp.latin1() );
 
2944
            tb->setCloseMode( QDockWindow::Undocked );
 
2945
            addToolBar( tb, grp );
 
2946
        }
 
2947
 
 
2948
        if ( iface->location( *ait, ActionInterface::Menu ) )
 
2949
            a->addTo( menu );
 
2950
        if ( iface->location( *ait, ActionInterface::Toolbar ) )
 
2951
            a->addTo( tb );
 
2952
 
 
2953
        iface->release();
 
2954
    }
 
2955
}
 
2956
 
 
2957
void MainWindow::editFunction( const QString &func, bool rereadSource )
 
2958
{
 
2959
    if ( !formWindow() )
 
2960
        return;
 
2961
 
 
2962
    if ( formWindow()->formFile()->codeFileState() != FormFile::Ok )
 
2963
        if ( !formWindow()->formFile()->setupUihFile(FALSE) )
 
2964
            return;
 
2965
 
 
2966
    QString lang = currentProject->language();
 
2967
    if ( !MetaDataBase::hasEditor( lang ) ) {
 
2968
        QMessageBox::information( this, i18n( "Edit Source" ),
 
2969
                                  i18n( "There is no plugin for editing %1 code installed.\n"
 
2970
                                      "Note: Plugins are not available in static Qt configurations." ).arg( lang ) );
 
2971
        return;
 
2972
    }
 
2973
 
 
2974
    for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() ) {
 
2975
        if ( e->language() == lang && e->formWindow() == formWindow() ) {
 
2976
            e->show();
 
2977
            e->setFunction( func );
 
2978
            return;
 
2979
        }
 
2980
    }
 
2981
 
 
2982
    createSourceEditor( formWindow(), formWindow()->project(), lang, func, rereadSource );
 
2983
}
 
2984
 
 
2985
void MainWindow::setupRecentlyFilesMenu()
 
2986
{
 
2987
    recentlyFilesMenu->clear();
 
2988
    int id = 0;
 
2989
    for ( QStringList::ConstIterator it = recentlyFiles.begin(); it != recentlyFiles.end(); ++it ) {
 
2990
        recentlyFilesMenu->insertItem( *it, id );
 
2991
        id++;
 
2992
    }
 
2993
}
 
2994
 
 
2995
void MainWindow::setupRecentlyProjectsMenu()
 
2996
{
 
2997
    recentlyProjectsMenu->clear();
 
2998
    int id = 0;
 
2999
    for ( QStringList::ConstIterator it = recentlyProjects.begin(); it != recentlyProjects.end(); ++it ) {
 
3000
        recentlyProjectsMenu->insertItem( *it, id );
 
3001
        id++;
 
3002
    }
 
3003
}
 
3004
 
 
3005
QPtrList<DesignerProject> MainWindow::projectList() const
 
3006
{
 
3007
    QPtrList<DesignerProject> list;
 
3008
    QMapConstIterator<QAction*, Project*> it = projects.begin();
 
3009
 
 
3010
    while( it != projects.end() ) {
 
3011
        Project *p = it.data();
 
3012
        ++it;
 
3013
        list.append( p->iFace() );
 
3014
    }
 
3015
 
 
3016
    return list;
 
3017
}
 
3018
 
 
3019
QStringList MainWindow::projectNames() const
 
3020
{
 
3021
    QStringList res;
 
3022
    for ( QMap<QAction*, Project* >::ConstIterator it = projects.begin(); it != projects.end(); ++it )
 
3023
        res << (*it)->projectName();
 
3024
    return res;
 
3025
}
 
3026
 
 
3027
QStringList MainWindow::projectFileNames() const
 
3028
{
 
3029
    QStringList res;
 
3030
    for ( QMap<QAction*, Project* >::ConstIterator it = projects.begin(); it != projects.end(); ++it )
 
3031
        res << (*it)->makeRelative( (*it)->fileName() );
 
3032
    return res;
 
3033
}
 
3034
 
 
3035
Project *MainWindow::findProject( const QString &projectName ) const
 
3036
{
 
3037
    for ( QMap<QAction*, Project* >::ConstIterator it = projects.begin(); it != projects.end(); ++it ) {
 
3038
        if ( (*it)->projectName() == projectName )
 
3039
            return *it;
 
3040
    }
 
3041
    return 0;
 
3042
}
 
3043
 
 
3044
void MainWindow::setCurrentProject( Project *pro )
 
3045
{
 
3046
    for ( QMap<QAction*, Project* >::ConstIterator it = projects.begin(); it != projects.end(); ++it ) {
 
3047
        if ( *it == pro ) {
 
3048
            projectSelected( it.key() );
 
3049
            return;
 
3050
        }
 
3051
    }
 
3052
}
 
3053
 
 
3054
void MainWindow::setCurrentProjectByFilename( const QString& proFilename )
 
3055
{
 
3056
    for ( QMap<QAction*, Project* >::ConstIterator it = projects.begin(); it != projects.end(); ++it ) {
 
3057
        if ( (*it)->makeRelative( (*it)->fileName() ) == proFilename ) {
 
3058
            projectSelected( it.key() );
 
3059
            return;
 
3060
        }
 
3061
    }
 
3062
}
 
3063
 
 
3064
 
 
3065
void MainWindow::recentlyFilesMenuActivated( int id )
 
3066
{
 
3067
    if ( id != -1 ) {
 
3068
        if ( !QFile::exists( *recentlyFiles.at( id ) ) ) {
 
3069
            QMessageBox::warning( this, i18n( "Open File" ),
 
3070
                                  i18n( "Could not open '%1'. File does not exist." ).
 
3071
                                  arg( *recentlyFiles.at( id ) ) );
 
3072
            recentlyFiles.remove( recentlyFiles.at( id ) );
 
3073
            return;
 
3074
        }
 
3075
        fileOpen( "", "", *recentlyFiles.at( id ) );
 
3076
        QString fn( *recentlyFiles.at( id ) );
 
3077
        addRecentlyOpened( fn, recentlyFiles );
 
3078
    }
 
3079
}
 
3080
 
 
3081
void MainWindow::recentlyProjectsMenuActivated( int id )
 
3082
{
 
3083
    if ( id != -1 ) {
 
3084
        if ( !QFile::exists( *recentlyProjects.at( id ) ) ) {
 
3085
            QMessageBox::warning( this, i18n( "Open Project" ),
 
3086
                                  i18n( "Could not open '%1'. File does not exist." ).
 
3087
                                  arg( *recentlyProjects.at( id ) ) );
 
3088
            recentlyProjects.remove( recentlyProjects.at( id ) );
 
3089
            return;
 
3090
        }
 
3091
        openProject( *recentlyProjects.at( id ) );
 
3092
        QString fn( *recentlyProjects.at( id ) );
 
3093
        addRecentlyOpened( fn, recentlyProjects );
 
3094
    }
 
3095
}
 
3096
 
 
3097
void MainWindow::addRecentlyOpened( const QString &fn, QStringList &lst )
 
3098
{
 
3099
    QFileInfo fi( fn );
 
3100
    fi.convertToAbs();
 
3101
    QString f = fi.filePath();
 
3102
    if ( lst.find( f ) != lst.end() )
 
3103
        lst.remove( f );
 
3104
    if ( lst.count() >= 10 )
 
3105
        lst.pop_back();
 
3106
    lst.prepend( f );
 
3107
}
 
3108
 
 
3109
TemplateWizardInterface * MainWindow::templateWizardInterface( const QString& className )
 
3110
{
 
3111
    TemplateWizardInterface* iface = 0;
 
3112
    templateWizardPluginManager->queryInterface( className, & iface );
 
3113
    return iface;
 
3114
}
 
3115
 
 
3116
void MainWindow::setupPluginManagers()
 
3117
{
 
3118
    editorPluginManager = new QPluginManager<EditorInterface>( IID_Editor, QApplication::libraryPaths(), "/kdevdesigner" );
 
3119
    MetaDataBase::setEditor( editorPluginManager->featureList() );
 
3120
 
 
3121
    templateWizardPluginManager =
 
3122
        new QPluginManager<TemplateWizardInterface>( IID_TemplateWizard, QApplication::libraryPaths(), pluginDirectory() );
 
3123
 
 
3124
    MetaDataBase::setupInterfaceManagers( "/designer" );
 
3125
    preferencePluginManager =
 
3126
        new QPluginManager<PreferenceInterface>( IID_Preference, QApplication::libraryPaths(), pluginDirectory() );
 
3127
    projectSettingsPluginManager =
 
3128
        new QPluginManager<ProjectSettingsInterface>( IID_ProjectSettings, QApplication::libraryPaths(), pluginDirectory() );
 
3129
    sourceTemplatePluginManager =
 
3130
        new QPluginManager<SourceTemplateInterface>( IID_SourceTemplate, QApplication::libraryPaths(), pluginDirectory() );
 
3131
 
 
3132
    if ( preferencePluginManager ) {
 
3133
        QStringList lst = preferencePluginManager->featureList();
 
3134
        for ( QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) {
 
3135
            PreferenceInterface *i = 0;
 
3136
            preferencePluginManager->queryInterface( *it, &i );
 
3137
            if ( !i )
 
3138
                continue;
 
3139
            i->connectTo( designerInterface() );
 
3140
            PreferenceInterface::Preference *pf = i->preference();
 
3141
            if ( pf )
 
3142
                addPreferencesTab( pf->tab, pf->title, pf->receiver, pf->init_slot, pf->accept_slot );
 
3143
            i->deletePreferenceObject( pf );
 
3144
 
 
3145
            i->release();
 
3146
        }
 
3147
    }
 
3148
    if ( projectSettingsPluginManager ) {
 
3149
        QStringList lst = projectSettingsPluginManager->featureList();
 
3150
        for ( QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) {
 
3151
            ProjectSettingsInterface *i = 0;
 
3152
            projectSettingsPluginManager->queryInterface( *it, &i );
 
3153
            if ( !i )
 
3154
                continue;
 
3155
            i->connectTo( designerInterface() );
 
3156
 
 
3157
            ProjectSettingsInterface::ProjectSettings *pf = i->projectSetting();
 
3158
            if ( pf )
 
3159
                addProjectTab( pf->tab, pf->title, pf->receiver, pf->init_slot, pf->accept_slot );
 
3160
            i->deleteProjectSettingsObject( pf );
 
3161
            i->release();
 
3162
        }
 
3163
    }
 
3164
}
 
3165
 
 
3166
void MainWindow::addPreferencesTab( QWidget *tab, const QString &title, QObject *receiver, const char *init_slot, const char *accept_slot )
 
3167
{
 
3168
    Tab t;
 
3169
    t.w = tab;
 
3170
    t.title = title;
 
3171
    t.receiver = receiver;
 
3172
    t.init_slot = init_slot;
 
3173
    t.accept_slot = accept_slot;
 
3174
    preferenceTabs << t;
 
3175
}
 
3176
 
 
3177
void MainWindow::addProjectTab( QWidget *tab, const QString &title, QObject *receiver, const char *init_slot, const char *accept_slot )
 
3178
{
 
3179
    Tab t;
 
3180
    t.w = tab;
 
3181
    t.title = title;
 
3182
    t.receiver = receiver;
 
3183
    t.init_slot = init_slot;
 
3184
    t.accept_slot = accept_slot;
 
3185
    projectTabs << t;
 
3186
}
 
3187
 
 
3188
void MainWindow::setModified( bool b, QWidget *window )
 
3189
{
 
3190
    QWidget *w = window;
 
3191
    while ( w ) {
 
3192
        if ( ::qt_cast<FormWindow*>(w) ) {
 
3193
            ( (FormWindow*)w )->modificationChanged( b );
 
3194
            return;
 
3195
        } else if ( ::qt_cast<SourceEditor*>(w) ) {
 
3196
            FormWindow *fw = ( (SourceEditor*)w )->formWindow();
 
3197
            if ( fw && !fw->isFake() ) {
 
3198
                //fw->commandHistory()->setModified( b );
 
3199
                //fw->modificationChanged( b );
 
3200
                fw->formFile()->setModified( b, FormFile::WFormCode );
 
3201
                wspace->update( fw->formFile() );
 
3202
            } else {
 
3203
                wspace->update();
 
3204
            }
 
3205
            return;
 
3206
        }
 
3207
        w = w->parentWidget( TRUE );
 
3208
    }
 
3209
}
 
3210
 
 
3211
void MainWindow::editorClosed( SourceEditor *e )
 
3212
{
 
3213
    sourceEditors.take( sourceEditors.findRef( e ) );
 
3214
}
 
3215
 
 
3216
void MainWindow::functionsChanged()
 
3217
{
 
3218
    updateFunctionsTimer->start( 0, TRUE );
 
3219
}
 
3220
 
 
3221
void MainWindow::doFunctionsChanged()
 
3222
{
 
3223
    for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() )
 
3224
        e->refresh( FALSE );
 
3225
    hierarchyView->formDefinitionView()->refresh();
 
3226
}
 
3227
 
 
3228
void MainWindow::updateFunctionList()
 
3229
{
 
3230
    if ( !qWorkspace()->activeWindow() || !::qt_cast<SourceEditor*>(qWorkspace()->activeWindow()) )
 
3231
        return;
 
3232
    SourceEditor *se = (SourceEditor*)qWorkspace()->activeWindow();
 
3233
    se->save();
 
3234
    hierarchyView->formDefinitionView()->refresh();
 
3235
    if ( !currentProject->isCpp() && se->formWindow() ) {
 
3236
        LanguageInterface *iface = MetaDataBase::languageInterface( currentProject->language() );
 
3237
        if ( !iface )
 
3238
            return;
 
3239
        QValueList<LanguageInterface::Connection> conns;
 
3240
        iface->connections( se->text(), &conns );
 
3241
        MetaDataBase::setupConnections( se->formWindow(), conns );
 
3242
        propertyEditor->eventList()->setup();
 
3243
    }
 
3244
}
 
3245
 
 
3246
void MainWindow::updateWorkspace()
 
3247
{
 
3248
    wspace->setCurrentProject( currentProject );
 
3249
}
 
3250
 
 
3251
void MainWindow::showDebugStep( QObject *o, int line )
 
3252
{
 
3253
    for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() )
 
3254
        e->clearStep();
 
3255
    if ( !o || line == -1 )
 
3256
        return;
 
3257
    showSourceLine( o, line, Step );
 
3258
}
 
3259
 
 
3260
void MainWindow::showStackFrame( QObject *o, int line )
 
3261
{
 
3262
    if ( !o || line == -1 )
 
3263
        return;
 
3264
    showSourceLine( o, line, StackFrame );
 
3265
}
 
3266
 
 
3267
void MainWindow::showErrorMessage( QObject *o, int errorLine, const QString &errorMessage )
 
3268
{
 
3269
    if ( o ) {
 
3270
        errorLine--; // ######
 
3271
        QValueList<uint> l;
 
3272
        l << ( errorLine + 1 );
 
3273
        QStringList l2;
 
3274
        l2 << errorMessage;
 
3275
        QObjectList ol;
 
3276
        ol.append( o );
 
3277
        QStringList ll;
 
3278
        ll << currentProject->locationOfObject( o );
 
3279
        oWindow->setErrorMessages( l2, l, TRUE, ll, ol );
 
3280
        showSourceLine( o, errorLine, Error );
 
3281
    }
 
3282
}
 
3283
 
 
3284
void MainWindow::finishedRun()
 
3285
{
 
3286
    inDebugMode = FALSE;
 
3287
    previewing = FALSE;
 
3288
    debuggingForms.clear();
 
3289
    enableAll( TRUE );
 
3290
    for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() ) {
 
3291
        if ( e->project() == currentProject )
 
3292
            e->editorInterface()->setMode( EditorInterface::Editing );
 
3293
        e->clearStackFrame();
 
3294
    }
 
3295
    outputWindow()->clearErrorMessages();
 
3296
}
 
3297
 
 
3298
void MainWindow::enableAll( bool enable )
 
3299
{
 
3300
    menuBar()->setEnabled( enable );
 
3301
    QObjectList *l = queryList( "QDockWindow" );
 
3302
    for ( QObject *o = l->first(); o; o = l->next() ) {
 
3303
        if ( o == wspace->parentWidget() ||
 
3304
             o == oWindow->parentWidget() ||
 
3305
             o == hierarchyView->parentWidget() )
 
3306
            continue;
 
3307
        ( (QWidget*)o )->setEnabled( enable );
 
3308
    }
 
3309
    delete l;
 
3310
}
 
3311
 
 
3312
void MainWindow::showSourceLine( QObject *o, int line, LineMode lm )
 
3313
{
 
3314
    QWidgetList windows = qworkspace->windowList();
 
3315
    for ( QWidget *w = windows.first(); w; w = windows.next() ) {
 
3316
        FormWindow *fw = 0;
 
3317
        SourceEditor *se = 0;
 
3318
        SourceFile *sf = 0;
 
3319
        if ( ::qt_cast<FormWindow*>(w) ) {
 
3320
            fw = (FormWindow*)w;
 
3321
        } else if ( ::qt_cast<SourceEditor*>(w) ) {
 
3322
            se = (SourceEditor*)w;
 
3323
            if ( !se->object() )
 
3324
                continue;
 
3325
            if ( se->formWindow() )
 
3326
                fw = se->formWindow();
 
3327
            else
 
3328
                sf = se->sourceFile();
 
3329
        }
 
3330
 
 
3331
        if ( fw ) {
 
3332
            if ( fw->project() != currentProject )
 
3333
                continue;
 
3334
            if ( qstrcmp( fw->name(), o->name() ) == 0 ||
 
3335
                 fw->isFake() && currentProject->objectForFakeForm( fw ) == o ) {
 
3336
                if ( se ) {
 
3337
                    switch ( lm ) {
 
3338
                    case Error:
 
3339
                        se->editorInterface()->setError( line );
 
3340
                        break;
 
3341
                    case Step:
 
3342
                        se->editorInterface()->setStep( line );
 
3343
                        break;
 
3344
                    case StackFrame:
 
3345
                        se->editorInterface()->setStackFrame( line );
 
3346
                        break;
 
3347
                    }
 
3348
                    return;
 
3349
                } else {
 
3350
                    fw->showNormal();
 
3351
                    fw->setFocus();
 
3352
                    lastActiveFormWindow = fw;
 
3353
                    qApp->processEvents();
 
3354
                    se = editSource();
 
3355
                    if ( se ) {
 
3356
                        switch ( lm ) {
 
3357
                        case Error:
 
3358
                            se->editorInterface()->setError( line );
 
3359
                            break;
 
3360
                        case Step:
 
3361
                            se->editorInterface()->setStep( line );
 
3362
                            break;
 
3363
                        case StackFrame:
 
3364
                            se->editorInterface()->setStackFrame( line );
 
3365
                            break;
 
3366
                        }
 
3367
                        return;
 
3368
                    }
 
3369
                }
 
3370
            }
 
3371
        } else if ( se ) {
 
3372
            if ( o != sf )
 
3373
                continue;
 
3374
            switch ( lm ) {
 
3375
            case Error:
 
3376
                se->editorInterface()->setError( line );
 
3377
                break;
 
3378
            case Step:
 
3379
                se->editorInterface()->setStep( line );
 
3380
                break;
 
3381
            case StackFrame:
 
3382
                se->editorInterface()->setStackFrame( line );
 
3383
                break;
 
3384
            }
 
3385
            return;
 
3386
        }
 
3387
    }
 
3388
 
 
3389
    if ( ::qt_cast<SourceFile*>(o) ) {
 
3390
        for ( QPtrListIterator<SourceFile> sources = currentProject->sourceFiles();
 
3391
              sources.current(); ++sources ) {
 
3392
            SourceFile* f = sources.current();
 
3393
            if ( f == o ) {
 
3394
                SourceEditor *se = editSource( f );
 
3395
                if ( se ) {
 
3396
                    switch ( lm ) {
 
3397
                    case Error:
 
3398
                        se->editorInterface()->setError( line );
 
3399
                        break;
 
3400
                    case Step:
 
3401
                        se->editorInterface()->setStep( line );
 
3402
                        break;
 
3403
                    case StackFrame:
 
3404
                        se->editorInterface()->setStackFrame( line );
 
3405
                        break;
 
3406
                    }
 
3407
                }
 
3408
                return;
 
3409
            }
 
3410
        }
 
3411
    }
 
3412
 
 
3413
    FormFile *ff = currentProject->fakeFormFileFor( o );
 
3414
    FormWindow *fw = 0;
 
3415
    if ( ff )
 
3416
        fw = ff->formWindow();
 
3417
 
 
3418
    if ( !fw && !qwf_forms ) {
 
3419
        qWarning( "MainWindow::showSourceLine: qwf_forms is NULL!" );
 
3420
        return;
 
3421
    }
 
3422
 
 
3423
    mblockNewForms = TRUE;
 
3424
    if ( !fw )
 
3425
        openFormWindow( currentProject->makeAbsolute( *qwf_forms->find( (QWidget*)o ) ) );
 
3426
    else
 
3427
        fw->formFile()->showEditor( FALSE );
 
3428
    qApp->processEvents(); // give all views the chance to get the formwindow
 
3429
    SourceEditor *se = editSource();
 
3430
    if ( se ) {
 
3431
        switch ( lm ) {
 
3432
        case Error:
 
3433
            se->editorInterface()->setError( line );
 
3434
            break;
 
3435
        case Step:
 
3436
            se->editorInterface()->setStep( line );
 
3437
            break;
 
3438
        case StackFrame:
 
3439
            se->editorInterface()->setStackFrame( line );
 
3440
            break;
 
3441
        }
 
3442
    }
 
3443
    mblockNewForms = FALSE;
 
3444
}
 
3445
 
 
3446
 
 
3447
QObject *MainWindow::findRealObject( QObject *o )
 
3448
{
 
3449
    QWidgetList windows = qWorkspace()->windowList();
 
3450
    for ( QWidget *w = windows.first(); w; w = windows.next() ) {
 
3451
        if ( ::qt_cast<FormWindow*>(w) && QString( w->name() ) == QString( o->name() ) )
 
3452
            return w;
 
3453
        else if ( ::qt_cast<SourceEditor*>(w) && ( (SourceEditor*)w )->formWindow() &&
 
3454
                  QString( ( (SourceEditor*)w )->formWindow()->name() ) == QString( o->name() ) )
 
3455
            return w;
 
3456
        else if ( ::qt_cast<SourceFile*>(w) && ( (SourceEditor*)w )->sourceFile() &&
 
3457
                  ( (SourceEditor*)w )->sourceFile() == o )
 
3458
            return o;
 
3459
    }
 
3460
    return 0;
 
3461
}
 
3462
 
 
3463
void MainWindow::formNameChanged( FormWindow *fw )
 
3464
{
 
3465
    for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() ) {
 
3466
        if ( e->object() == fw )
 
3467
            e->refresh( TRUE );
 
3468
        if ( e->project() == fw->project() )
 
3469
            e->resetContext();
 
3470
    }
 
3471
}
 
3472
 
 
3473
void MainWindow::breakPointsChanged()
 
3474
{
 
3475
    if ( !inDebugMode )
 
3476
        return;
 
3477
    if ( !qWorkspace()->activeWindow() || !::qt_cast<SourceEditor*>(qWorkspace()->activeWindow()) )
 
3478
        return;
 
3479
    SourceEditor *e = (SourceEditor*)qWorkspace()->activeWindow();
 
3480
    if ( !e->object() || !e->project() )
 
3481
        return;
 
3482
    if ( e->project() != currentProject )
 
3483
        return;
 
3484
 
 
3485
    if ( !interpreterPluginManager ) {
 
3486
        interpreterPluginManager =
 
3487
            new QPluginManager<InterpreterInterface>( IID_Interpreter,
 
3488
                                                      QApplication::libraryPaths(),
 
3489
                                                      "/qsa" );
 
3490
    }
 
3491
 
 
3492
    InterpreterInterface *iiface = 0;
 
3493
    if ( interpreterPluginManager ) {
 
3494
        QString lang = currentProject->language();
 
3495
        iiface = 0;
 
3496
        interpreterPluginManager->queryInterface( lang, &iiface );
 
3497
        if ( !iiface )
 
3498
            return;
 
3499
    }
 
3500
 
 
3501
    e->saveBreakPoints();
 
3502
 
 
3503
    for ( QObject *o = debuggingForms.first(); o; o = debuggingForms.next() ) {
 
3504
        if ( qstrcmp( o->name(), e->object()->name() ) == 0 ) {
 
3505
            iiface->setBreakPoints( o, MetaDataBase::breakPoints( e->object() ) );
 
3506
            break;
 
3507
        }
 
3508
    }
 
3509
 
 
3510
    for ( e = sourceEditors.first(); e; e = sourceEditors.next() ) {
 
3511
        if ( e->project() == currentProject && e->sourceFile() ) {
 
3512
            QValueList<uint> bps = MetaDataBase::breakPoints( e->sourceFile() );
 
3513
            iiface->setBreakPoints( e->object(), bps );
 
3514
        }
 
3515
    }
 
3516
 
 
3517
    iiface->release();
 
3518
}
 
3519
 
 
3520
int MainWindow::currentLayoutDefaultSpacing() const
 
3521
{
 
3522
    if ( ( (MainWindow*)this )->formWindow() )
 
3523
        return ( (MainWindow*)this )->formWindow()->layoutDefaultSpacing();
 
3524
    return BOXLAYOUT_DEFAULT_SPACING;
 
3525
}
 
3526
 
 
3527
int MainWindow::currentLayoutDefaultMargin() const
 
3528
{
 
3529
    if ( ( (MainWindow*)this )->formWindow() )
 
3530
        return ( (MainWindow*)this )->formWindow()->layoutDefaultMargin();
 
3531
    return BOXLAYOUT_DEFAULT_MARGIN;
 
3532
}
 
3533
 
 
3534
void MainWindow::saveAllBreakPoints()
 
3535
{
 
3536
    for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() ) {
 
3537
        e->save();
 
3538
        e->saveBreakPoints();
 
3539
    }
 
3540
}
 
3541
 
 
3542
void MainWindow::resetBreakPoints()
 
3543
{
 
3544
    for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() )
 
3545
        e->resetBreakPoints();
 
3546
}
 
3547
 
 
3548
SourceFile *MainWindow::sourceFile()
 
3549
{
 
3550
    for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() ) {
 
3551
        if ( qworkspace->activeWindow() == e ) {
 
3552
            if ( e->sourceFile() )
 
3553
                return e->sourceFile();
 
3554
        }
 
3555
    }
 
3556
    return 0;
 
3557
}
 
3558
 
 
3559
bool MainWindow::openProjectSettings( Project *pro )
 
3560
{
 
3561
    ProjectSettings dia( pro, this, 0, TRUE );
 
3562
    SenderObject *senderObject = new SenderObject( designerInterface() );
 
3563
    QValueList<Tab>::ConstIterator it;
 
3564
    for ( it = projectTabs.begin(); it != projectTabs.end(); ++it ) {
 
3565
        Tab t = *it;
 
3566
        if ( t.title != pro->language() )
 
3567
            continue;
 
3568
        dia.tabWidget->addTab( t.w, t.title );
 
3569
        if ( t.receiver ) {
 
3570
            connect( dia.buttonOk, SIGNAL( clicked() ), senderObject, SLOT( emitAcceptSignal() ) );
 
3571
            connect( senderObject, SIGNAL( acceptSignal( QUnknownInterface * ) ), t.receiver, t.accept_slot );
 
3572
            connect( senderObject, SIGNAL( initSignal( QUnknownInterface * ) ), t.receiver, t.init_slot );
 
3573
            senderObject->emitInitSignal();
 
3574
            disconnect( senderObject, SIGNAL( initSignal( QUnknownInterface * ) ), t.receiver, t.init_slot );
 
3575
        }
 
3576
    }
 
3577
 
 
3578
    if ( singleProject )
 
3579
        dia.tabWidget->setTabEnabled( dia.tabSettings, FALSE );
 
3580
 
 
3581
    int res = dia.exec();
 
3582
 
 
3583
    delete senderObject;
 
3584
 
 
3585
    for ( it = projectTabs.begin(); it != projectTabs.end(); ++it ) {
 
3586
        Tab t = *it;
 
3587
        dia.tabWidget->removePage( t.w );
 
3588
        t.w->reparent( 0, QPoint(0,0), FALSE );
 
3589
    }
 
3590
 
 
3591
    return res == QDialog::Accepted;
 
3592
}
 
3593
 
 
3594
void MainWindow::popupProjectMenu( const QPoint &pos )
 
3595
{
 
3596
    projectMenu->exec( pos );
 
3597
}
 
3598
 
 
3599
QStringList MainWindow::sourceTemplates() const
 
3600
{
 
3601
    return sourceTemplatePluginManager->featureList();
 
3602
}
 
3603
 
 
3604
SourceTemplateInterface* MainWindow::sourceTemplateInterface( const QString& templ )
 
3605
{
 
3606
    SourceTemplateInterface *iface = 0;
 
3607
    sourceTemplatePluginManager->queryInterface( templ, &iface);
 
3608
    return iface;
 
3609
}
 
3610
 
 
3611
QString MainWindow::whatsThisFrom( const QString &key )
 
3612
{
 
3613
    if ( menuHelpFile.isEmpty() ) {
 
3614
        QString fn( documentationPath() );
 
3615
        fn += "/designer-manual-11.html";
 
3616
        QFile f( fn );
 
3617
        if ( f.open( IO_ReadOnly ) ) {
 
3618
            QTextStream ts( &f );
 
3619
            menuHelpFile = ts.read();
 
3620
        }
 
3621
    }
 
3622
 
 
3623
    int i = menuHelpFile.find( key );
 
3624
    if ( i == -1 )
 
3625
        return QString::null;
 
3626
    int start = i;
 
3627
    int end = i;
 
3628
    start = menuHelpFile.findRev( "<li>", i ) + 4;
 
3629
    end = menuHelpFile.find( '\n', i ) - 1;
 
3630
    return menuHelpFile.mid( start, end - start + 1 );
 
3631
}
 
3632
 
 
3633
void MainWindow::setSingleProject( Project *pro )
 
3634
{
 
3635
    if ( eProject ) {
 
3636
        Project *pro = eProject;
 
3637
        pro->save();
 
3638
        QWidgetList windows = qWorkspace()->windowList();
 
3639
        qWorkspace()->blockSignals( TRUE );
 
3640
        QWidgetListIt wit( windows );
 
3641
        while ( wit.current() ) {
 
3642
            QWidget *w = wit.current();
 
3643
            ++wit;
 
3644
            if ( ::qt_cast<FormWindow*>(w) ) {
 
3645
                if ( ( (FormWindow*)w )->project() == pro ) {
 
3646
                    if ( ( (FormWindow*)w )->formFile()->editor() )
 
3647
                        windows.removeRef( ( (FormWindow*)w )->formFile()->editor() );
 
3648
                    ( (FormWindow*)w )->formFile()->close();
 
3649
                }
 
3650
            } else if ( ::qt_cast<SourceEditor*>(w) ) {
 
3651
                ( (SourceEditor*)w )->close();
 
3652
            }
 
3653
        }
 
3654
        hierarchyView->clear();
 
3655
        windows = qWorkspace()->windowList();
 
3656
        qWorkspace()->blockSignals( FALSE );
 
3657
        currentProject = 0;
 
3658
        updateUndoRedo( FALSE, FALSE, QString::null, QString::null );
 
3659
    }
 
3660
 
 
3661
    singleProject = TRUE;
 
3662
    projects.clear();
 
3663
    QAction *a = new QAction( i18n( pro->name() ), i18n( pro->name() ), 0,
 
3664
                              actionGroupProjects, 0, TRUE );
 
3665
    eProject = pro;
 
3666
    projects.insert( a, eProject );
 
3667
    a->setOn( TRUE );
 
3668
    actionGroupProjects->removeFrom( projectMenu );
 
3669
    actionGroupProjects->removeFrom( projectToolBar );
 
3670
    currentProject = eProject;
 
3671
    currentProject->designerCreated();
 
3672
}
 
3673
 
 
3674
void MainWindow::shuttingDown()
 
3675
{
 
3676
    outputWindow()->shuttingDown();
 
3677
}
 
3678
 
 
3679
void MainWindow::showGUIStuff( bool b )
 
3680
{
 
3681
    if ( (bool)guiStuffVisible == b )
 
3682
        return;
 
3683
    guiStuffVisible = b;
 
3684
    if ( !b ) {
 
3685
        setAppropriate( (QDockWindow*)toolBox->parentWidget(), FALSE );
 
3686
        toolBox->parentWidget()->hide();
 
3687
        for ( QToolBar *tb = widgetToolBars.first(); tb; tb = widgetToolBars.next() ) {
 
3688
            tb->hide();
 
3689
            setAppropriate( tb, FALSE );
 
3690
        }
 
3691
        propertyEditor->setPropertyEditorEnabled( FALSE );
 
3692
        setAppropriate( layoutToolBar, FALSE );
 
3693
        layoutToolBar->hide();
 
3694
        setAppropriate( toolsToolBar, FALSE );
 
3695
        toolsToolBar->hide();
 
3696
        menubar->removeItem( toolsMenuId );
 
3697
        menubar->removeItem( toolsMenuId + 1 );
 
3698
        menubar->removeItem( toolsMenuId + 2 );
 
3699
        disconnect( this, SIGNAL( hasActiveForm(bool) ), actionEditAccels, SLOT( setEnabled(bool) ) );
 
3700
        disconnect( this, SIGNAL( hasActiveForm(bool) ), actionEditFunctions, SLOT( setEnabled(bool) ) );
 
3701
        disconnect( this, SIGNAL( hasActiveForm(bool) ), actionEditConnections, SLOT( setEnabled(bool) ) );
 
3702
        disconnect( this, SIGNAL( hasActiveForm(bool) ), actionEditSource, SLOT( setEnabled(bool) ) );
 
3703
        disconnect( this, SIGNAL( hasActiveForm(bool) ), actionEditFormSettings, SLOT( setEnabled(bool) ) );
 
3704
        actionEditFormSettings->setEnabled( FALSE );
 
3705
        actionEditSource->setEnabled( FALSE );
 
3706
        actionEditConnections->setEnabled( FALSE );
 
3707
        actionEditFunctions->setEnabled( FALSE );
 
3708
        actionEditAccels->setEnabled( FALSE );
 
3709
        ( (QDockWindow*)propertyEditor->parentWidget() )->
 
3710
            setCaption( i18n( "Signal Handlers" ) );
 
3711
        actionGroupNew->removeFrom( fileMenu );
 
3712
        actionGroupNew->removeFrom( projectToolBar );
 
3713
        actionFileSave->removeFrom( fileMenu );
 
3714
        actionFileSave->removeFrom( projectToolBar );
 
3715
        actionFileExit->removeFrom( fileMenu );
 
3716
        actionNewFile->addTo( fileMenu );
 
3717
        actionNewFile->addTo( projectToolBar );
 
3718
        actionFileSave->addTo( fileMenu );
 
3719
        actionFileSave->addTo( projectToolBar );
 
3720
        actionFileExit->addTo( fileMenu );
 
3721
    } else {
 
3722
        setAppropriate( (QDockWindow*)toolBox->parentWidget(), TRUE );
 
3723
        toolBox->parentWidget()->show();
 
3724
        for ( QToolBar *tb = widgetToolBars.first(); tb; tb = widgetToolBars.next() ) {
 
3725
            setAppropriate( tb, TRUE );
 
3726
            tb->hide();
 
3727
        }
 
3728
        propertyEditor->setPropertyEditorEnabled( TRUE );
 
3729
        setAppropriate( layoutToolBar, TRUE );
 
3730
        layoutToolBar->show();
 
3731
        setAppropriate( toolsToolBar, TRUE );
 
3732
        toolsToolBar->show();
 
3733
        menubar->insertItem( i18n( "&Tools" ), toolsMenu, toolsMenuId, toolsMenuIndex );
 
3734
        menubar->insertItem( i18n( "&Layout" ), layoutMenu, toolsMenuId + 1, toolsMenuIndex + 1 );
 
3735
        menubar->insertItem( i18n( "&Preview" ), previewMenu, toolsMenuId + 2, toolsMenuIndex + 2 );
 
3736
        connect( this, SIGNAL( hasActiveForm(bool) ), actionEditAccels, SLOT( setEnabled(bool) ) );
 
3737
        connect( this, SIGNAL( hasActiveForm(bool) ), actionEditFunctions, SLOT( setEnabled(bool) ) );
 
3738
        connect( this, SIGNAL( hasActiveForm(bool) ), actionEditConnections, SLOT( setEnabled(bool) ) );
 
3739
        connect( this, SIGNAL( hasActiveForm(bool) ), actionEditSource, SLOT( setEnabled(bool) ) );
 
3740
        connect( this, SIGNAL( hasActiveForm(bool) ), actionEditFormSettings, SLOT( setEnabled(bool) ) );
 
3741
        actionEditFormSettings->setEnabled( TRUE );
 
3742
        actionEditSource->setEnabled( TRUE );
 
3743
        actionEditConnections->setEnabled( TRUE );
 
3744
        actionEditFunctions->setEnabled( TRUE );
 
3745
        actionEditAccels->setEnabled( TRUE );
 
3746
        ( (QDockWindow*)propertyEditor->parentWidget() )->
 
3747
            setCaption( i18n( "Property Editor/Signal Handlers" ) );
 
3748
        actionFileSave->removeFrom( fileMenu );
 
3749
        actionFileSave->removeFrom( projectToolBar );
 
3750
        actionFileExit->removeFrom( fileMenu );
 
3751
        actionGroupNew->addTo( fileMenu );
 
3752
        actionGroupNew->addTo( projectToolBar );
 
3753
        actionFileSave->addTo( fileMenu );
 
3754
        actionFileSave->addTo( projectToolBar );
 
3755
        actionFileExit->addTo( fileMenu );
 
3756
    }
 
3757
}
 
3758
 
 
3759
void MainWindow::setEditorsReadOnly( bool b )
 
3760
{
 
3761
    editorsReadOnly = b;
 
3762
}
 
3763
 
 
3764
void MainWindow::setPluginDirectory( const QString &pd )
 
3765
{
 
3766
    pluginDir = pd;
 
3767
    if ( !qwf_plugin_dir )
 
3768
        qwf_plugin_dir = new QString( pd );
 
3769
    else
 
3770
        *qwf_plugin_dir = pd;
 
3771
}
 
3772
 
 
3773
void MainWindow::toggleSignalHandlers( bool show )
 
3774
{
 
3775
    if ( sSignalHandlers == show )
 
3776
        return;
 
3777
    sSignalHandlers = show;
 
3778
    propertyEditor->setSignalHandlersEnabled( show );
 
3779
}
 
3780
 
 
3781
void MainWindow::statusMessage( const QString &msg )
 
3782
{
 
3783
    m_part->statusMessage(msg);
 
3784
}