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

« back to all changes in this revision

Viewing changes to kdevdesigner/designer/mainwindowactions.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-2001 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 "mainwindow.h"
 
28
 
 
29
#include <kiconloader.h>
 
30
#include <kfiledialog.h>
 
31
#include <klocale.h>
 
32
 
 
33
#include <stdlib.h>
 
34
#include <qaction.h>
 
35
#include <qwhatsthis.h>
 
36
#include <qpopupmenu.h>
 
37
#include <qmenubar.h>
 
38
#include <qlineedit.h>
 
39
#include <qtooltip.h>
 
40
#include <qapplication.h>
 
41
#include <qsignalmapper.h>
 
42
#include <qstylefactory.h>
 
43
#include <qworkspace.h>
 
44
#include <qmessagebox.h>
 
45
#include <qstatusbar.h>
 
46
#include <qlistbox.h>
 
47
#include <qclipboard.h>
 
48
#include <qcombobox.h>
 
49
#include <qspinbox.h>
 
50
#include <qinputdialog.h>
 
51
#include <qdatetimeedit.h>
 
52
#include <qtextedit.h>
 
53
 
 
54
#include "defs.h"
 
55
#include "project.h"
 
56
#include "widgetdatabase.h"
 
57
#include "widgetfactory.h"
 
58
#include "preferences.h"
 
59
#include "formwindow.h"
 
60
#include "newformimpl.h"
 
61
#include "resource.h"
 
62
#include "projectsettingsimpl.h"
 
63
#include "workspace.h"
 
64
#include "createtemplate.h"
 
65
#include "hierarchyview.h"
 
66
#include "editfunctionsimpl.h"
 
67
#include "finddialog.h"
 
68
#include "replacedialog.h"
 
69
#include "gotolinedialog.h"
 
70
#include "formsettingsimpl.h"
 
71
#include "pixmapcollectioneditor.h"
 
72
#include "styledbutton.h"
 
73
#include "customwidgeteditorimpl.h"
 
74
#ifndef QT_NO_SQL
 
75
#include "dbconnectionsimpl.h"
 
76
#include "dbconnectionimpl.h"
 
77
#endif
 
78
#include "widgetaction.h"
 
79
#include <qtoolbox.h>
 
80
#include "startdialogimpl.h"
 
81
#include "designerappiface.h"
 
82
#include "connectiondialog.h"
 
83
#include "configtoolboxdialog.h"
 
84
#include "designeraction.h"
 
85
 
 
86
#include "kdevdesigner_part.h"
 
87
 
 
88
static const char * whatsthis_image[] = {
 
89
    "16 16 3 1",
 
90
    "   c None",
 
91
    "o  c #000000",
 
92
    "a  c #000080",
 
93
    "o        aaaaa  ",
 
94
    "oo      aaa aaa ",
 
95
    "ooo    aaa   aaa",
 
96
    "oooo   aa     aa",
 
97
    "ooooo  aa     aa",
 
98
    "oooooo  a    aaa",
 
99
    "ooooooo     aaa ",
 
100
    "oooooooo   aaa  ",
 
101
    "ooooooooo aaa   ",
 
102
    "ooooo     aaa   ",
 
103
    "oo ooo          ",
 
104
    "o  ooo    aaa   ",
 
105
    "    ooo   aaa   ",
 
106
    "    ooo         ",
 
107
    "     ooo        ",
 
108
    "     ooo        "};
 
109
 
 
110
const QString toolbarHelp = "<p>Toolbars contain a number of buttons to "
 
111
"provide quick access to often used functions.%1"
 
112
"<br>Click on the toolbar handle to hide the toolbar, "
 
113
"or drag and place the toolbar to a different location.</p>";
 
114
 
 
115
static QIconSet createIconSet( const QString &name )
 
116
{
 
117
    QIconSet ic( BarIcon( "" + name, KDevDesignerPartFactory::instance() ) );
 
118
    QString prefix = "designer_";
 
119
    int right = name.length() - prefix.length();
 
120
    ic.setPixmap( BarIcon( prefix + "d_" + name.right( right ), KDevDesignerPartFactory::instance() ),
 
121
                  QIconSet::Small, QIconSet::Disabled );
 
122
    return ic;
 
123
}
 
124
 
 
125
void MainWindow::setupEditActions()
 
126
{
 
127
    actionEditUndo = new DesignerAction( i18n("Undo"), createIconSet( "designer_undo.png" ),i18n("&Undo: Not Available"), CTRL + Key_Z, this, 0 );
 
128
    actionEditUndo->setStatusTip( i18n( "Undoes the last action" ) );
 
129
    actionEditUndo->setWhatsThis( whatsThisFrom( "Edit|Undo" ) );
 
130
    connect( actionEditUndo, SIGNAL( activated() ), this, SLOT( editUndo() ) );
 
131
    actionEditUndo->setEnabled( FALSE );
 
132
 
 
133
    actionEditRedo = new DesignerAction( i18n( "Redo" ), createIconSet("designer_redo.png"), i18n( "&Redo: Not Available" ), CTRL + Key_Y, this, 0 );
 
134
    actionEditRedo->setStatusTip( i18n( "Redoes the last undone operation") );
 
135
    actionEditRedo->setWhatsThis( whatsThisFrom( "Edit|Redo" ) );
 
136
    connect( actionEditRedo, SIGNAL( activated() ), this, SLOT( editRedo() ) );
 
137
    actionEditRedo->setEnabled( FALSE );
 
138
 
 
139
    actionEditCut = new DesignerAction( i18n( "Cut" ), createIconSet("designer_editcut.png"), i18n( "Cu&t" ), CTRL + Key_X, this, 0 );
 
140
    actionEditCut->setStatusTip( i18n( "Cuts the selected widgets and puts them on the clipboard" ) );
 
141
    actionEditCut->setWhatsThis(  whatsThisFrom( "Edit|Cut" ) );
 
142
    connect( actionEditCut, SIGNAL( activated() ), this, SLOT( editCut() ) );
 
143
    actionEditCut->setEnabled( FALSE );
 
144
 
 
145
    actionEditCopy = new DesignerAction( i18n( "Copy" ), createIconSet("designer_editcopy.png"), i18n( "&Copy" ), CTRL + Key_C, this, 0 );
 
146
    actionEditCopy->setStatusTip( i18n( "Copies the selected widgets to the clipboard" ) );
 
147
    actionEditCopy->setWhatsThis(  whatsThisFrom( "Edit|Copy" ) );
 
148
    connect( actionEditCopy, SIGNAL( activated() ), this, SLOT( editCopy() ) );
 
149
    actionEditCopy->setEnabled( FALSE );
 
150
 
 
151
    actionEditPaste = new DesignerAction( i18n( "Paste" ), createIconSet("designer_editpaste.png"), i18n( "&Paste" ), CTRL + Key_V, this, 0 );
 
152
    actionEditPaste->setStatusTip( i18n( "Pastes the clipboard's contents" ) );
 
153
    actionEditPaste->setWhatsThis( whatsThisFrom( "Edit|Paste" ) );
 
154
    connect( actionEditPaste, SIGNAL( activated() ), this, SLOT( editPaste() ) );
 
155
    actionEditPaste->setEnabled( FALSE );
 
156
 
 
157
    actionEditDelete = new DesignerAction( i18n( "Delete" ), QPixmap(), i18n( "&Delete" ), Key_Delete, this, 0 );
 
158
    actionEditDelete->setStatusTip( i18n( "Deletes the selected widgets" ) );
 
159
    actionEditDelete->setWhatsThis( whatsThisFrom( "Edit|Delete" ) );
 
160
    connect( actionEditDelete, SIGNAL( activated() ), this, SLOT( editDelete() ) );
 
161
    actionEditDelete->setEnabled( FALSE );
 
162
#ifdef Q_WS_MAC
 
163
    QAction *macDelete = new DesignerAction( i18n( "Delete" ), QPixmap(), i18n( "&Delete" ), Key_Backspace, this, 0 );
 
164
    connect( macDelete, SIGNAL( activated() ), this, SLOT( editDelete() ) );
 
165
#endif
 
166
 
 
167
    actionEditSelectAll = new DesignerAction( i18n( "Select All" ), QPixmap(), i18n( "Select &All" ), CTRL + Key_A, this, 0 );
 
168
    actionEditSelectAll->setStatusTip( i18n( "Selects all widgets" ) );
 
169
    actionEditSelectAll->setWhatsThis( whatsThisFrom( "Edit|Select All" ) );
 
170
    connect( actionEditSelectAll, SIGNAL( activated() ), this, SLOT( editSelectAll() ) );
 
171
    actionEditSelectAll->setEnabled( TRUE );
 
172
 
 
173
    actionEditRaise = new DesignerAction( i18n( "Bring to Front" ), createIconSet("designer_editraise.png"), i18n( "Bring to &Front" ), 0, this, 0 );
 
174
    actionEditRaise->setStatusTip( i18n( "Raises the selected widgets" ) );
 
175
    actionEditRaise->setWhatsThis( i18n( "Raises the selected widgets" ) );
 
176
    connect( actionEditRaise, SIGNAL( activated() ), this, SLOT( editRaise() ) );
 
177
    actionEditRaise->setEnabled( FALSE );
 
178
 
 
179
    actionEditLower = new DesignerAction( i18n( "Send to Back" ), createIconSet("designer_editlower.png"), i18n( "Send to &Back" ), 0, this, 0 );
 
180
    actionEditLower->setStatusTip( i18n( "Lowers the selected widgets" ) );
 
181
    actionEditLower->setWhatsThis( i18n( "Lowers the selected widgets" ) );
 
182
    connect( actionEditLower, SIGNAL( activated() ), this, SLOT( editLower() ) );
 
183
    actionEditLower->setEnabled( FALSE );
 
184
 
 
185
    actionEditAccels = new DesignerAction( i18n( "Check Accelerators" ), QPixmap(),
 
186
                                    i18n( "Chec&k Accelerators" ), ALT + Key_R, this, 0 );
 
187
    actionEditAccels->setStatusTip( i18n("Checks if the accelerators used in the form are unique") );
 
188
    actionEditAccels->setWhatsThis( whatsThisFrom( "Edit|Check Accelerator" ) );
 
189
    connect( actionEditAccels, SIGNAL( activated() ), this, SLOT( editAccels() ) );
 
190
    connect( this, SIGNAL( hasActiveForm(bool) ), actionEditAccels, SLOT( setEnabled(bool) ) );
 
191
 
 
192
    actionEditFunctions = new DesignerAction( i18n( "Slots" ), createIconSet("designer_editslots.png"),
 
193
                                   i18n( "S&lots..." ), 0, this, 0 );
 
194
    actionEditFunctions->setStatusTip( i18n("Opens a dialog for editing slots") );
 
195
    actionEditFunctions->setWhatsThis( whatsThisFrom( "Edit|Slots" ) );
 
196
    connect( actionEditFunctions, SIGNAL( activated() ), this, SLOT( editFunctions() ) );
 
197
    connect( this, SIGNAL( hasActiveForm(bool) ), actionEditFunctions, SLOT( setEnabled(bool) ) );
 
198
 
 
199
    actionEditConnections = new DesignerAction( i18n( "Connections" ), createIconSet("designer_connecttool.png"),
 
200
                                         i18n( "Co&nnections..." ), 0, this, 0 );
 
201
    actionEditConnections->setStatusTip( i18n("Opens a dialog for editing connections") );
 
202
    actionEditConnections->setWhatsThis( whatsThisFrom( "Edit|Connections" ) );
 
203
    connect( actionEditConnections, SIGNAL( activated() ), this, SLOT( editConnections() ) );
 
204
    connect( this, SIGNAL( hasActiveForm(bool) ), actionEditConnections, SLOT( setEnabled(bool) ) );
 
205
 
 
206
    actionEditSource = new DesignerAction( i18n( "Source" ), QIconSet(),
 
207
                                         i18n( "&Source..." ), CTRL + Key_E, this, 0 );
 
208
    actionEditSource->setStatusTip( i18n("Opens an editor to edit the form's source code") );
 
209
    actionEditSource->setWhatsThis( whatsThisFrom( "Edit|Source" ) );
 
210
    connect( actionEditSource, SIGNAL( activated() ), this, SLOT( editSource() ) );
 
211
    connect( this, SIGNAL( hasActiveForm(bool) ), actionEditSource, SLOT( setEnabled(bool) ) );
 
212
 
 
213
    actionEditFormSettings = new DesignerAction( i18n( "Form Settings" ), QPixmap(),
 
214
                                          i18n( "&Form Settings..." ), 0, this, 0 );
 
215
    actionEditFormSettings->setStatusTip( i18n("Opens a dialog to change the form's settings") );
 
216
    actionEditFormSettings->setWhatsThis( whatsThisFrom( "Edit|Form Settings" ) );
 
217
    connect( actionEditFormSettings, SIGNAL( activated() ), this, SLOT( editFormSettings() ) );
 
218
    connect( this, SIGNAL( hasActiveForm(bool) ), actionEditFormSettings, SLOT( setEnabled(bool) ) );
 
219
 
 
220
    actionEditPreferences = new DesignerAction( i18n( "Preferences" ), QPixmap(),
 
221
                                         i18n( "Preferences..." ), 0, this, 0 );
 
222
    actionEditPreferences->setStatusTip( i18n("Opens a dialog to change preferences") );
 
223
    actionEditPreferences->setWhatsThis( whatsThisFrom( "Edit|Preferences" ) );
 
224
    connect( actionEditPreferences, SIGNAL( activated() ), this, SLOT( editPreferences() ) );
 
225
 
 
226
/*    QToolBar *tb = new QToolBar( this, "Edit" );
 
227
    tb->setCloseMode( QDockWindow::Undocked );
 
228
    QWhatsThis::add( tb, i18n( "<b>The Edit toolbar</b>%1").arg(i18n(toolbarHelp).arg("")) );
 
229
    addToolBar( tb, i18n( "Edit" ) );
 
230
    actionEditUndo->addTo( tb );
 
231
    actionEditRedo->addTo( tb );
 
232
    tb->addSeparator();
 
233
    actionEditCut->addTo( tb );
 
234
    actionEditCopy->addTo( tb );
 
235
    actionEditPaste->addTo( tb );*/
 
236
#if 0
 
237
    tb->addSeparator();
 
238
    actionEditLower->addTo( tb );
 
239
    actionEditRaise->addTo( tb );
 
240
#endif
 
241
 
 
242
    QPopupMenu *menu = new QPopupMenu( this, "Edit" );
 
243
    connect( menu, SIGNAL( aboutToShow() ), this, SLOT( updateEditorUndoRedo() ) );
 
244
    menubar->insertItem( i18n( "&Edit" ), menu );
 
245
    actionEditUndo->addTo( menu );
 
246
    actionEditRedo->addTo( menu );
 
247
    menu->insertSeparator();
 
248
    actionEditCut->addTo( menu );
 
249
    actionEditCopy->addTo( menu );
 
250
    actionEditPaste->addTo( menu );
 
251
    actionEditDelete->addTo( menu );
 
252
    actionEditSelectAll->addTo( menu );
 
253
    actionEditAccels->addTo( menu );
 
254
#if 0
 
255
    menu->insertSeparator();
 
256
    actionEditLower->addTo( menu );
 
257
    actionEditRaise->addTo( menu );
 
258
#endif
 
259
    menu->insertSeparator();
 
260
    if ( !singleProjectMode() ) {
 
261
        actionEditFunctions->addTo( menu );
 
262
        actionEditConnections->addTo( menu );
 
263
    }
 
264
    actionEditFormSettings->addTo( menu );
 
265
    menu->insertSeparator();
 
266
    actionEditPreferences->addTo( menu );
 
267
}
 
268
 
 
269
void MainWindow::setupSearchActions()
 
270
{
 
271
    actionSearchFind = new DesignerAction( i18n( "Find" ), createIconSet( "designer_searchfind.png" ),
 
272
                                    i18n( "&Find..." ), CTRL + Key_F, this, 0 );
 
273
    connect( actionSearchFind, SIGNAL( activated() ), this, SLOT( searchFind() ) );
 
274
    actionSearchFind->setEnabled( FALSE );
 
275
    actionSearchFind->setWhatsThis( whatsThisFrom( "Search|Find" ) );
 
276
 
 
277
    actionSearchIncremetal = new DesignerAction( i18n( "Find Incremental" ), QIconSet(),
 
278
                                          i18n( "Find &Incremental" ), ALT + Key_I, this, 0 );
 
279
    connect( actionSearchIncremetal, SIGNAL( activated() ), this, SLOT( searchIncremetalFindMenu() ) );
 
280
    actionSearchIncremetal->setEnabled( FALSE );
 
281
    actionSearchIncremetal->setWhatsThis( whatsThisFrom( "Search|Find Incremental" ) );
 
282
 
 
283
    actionSearchReplace = new DesignerAction( i18n( "Replace" ), QIconSet(),
 
284
                                    i18n( "&Replace..." ), CTRL + Key_R, this, 0 );
 
285
    connect( actionSearchReplace, SIGNAL( activated() ), this, SLOT( searchReplace() ) );
 
286
    actionSearchReplace->setEnabled( FALSE );
 
287
    actionSearchReplace->setWhatsThis( whatsThisFrom( "Search|Replace" ) );
 
288
 
 
289
    actionSearchGotoLine = new DesignerAction( i18n( "Goto Line" ), QIconSet(),
 
290
                                    i18n( "&Goto Line..." ), ALT + Key_G, this, 0 );
 
291
    connect( actionSearchGotoLine, SIGNAL( activated() ), this, SLOT( searchGotoLine() ) );
 
292
    actionSearchGotoLine->setEnabled( FALSE );
 
293
    actionSearchGotoLine->setWhatsThis( whatsThisFrom( "Search|Goto line" ) );
 
294
 
 
295
/*    QToolBar *tb = new QToolBar( this, "Search" );
 
296
    tb->setCloseMode( QDockWindow::Undocked );
 
297
    addToolBar( tb, i18n( "Search" ) );
 
298
 
 
299
    actionSearchFind->addTo( tb );*/
 
300
    incrementalSearch = new QLineEdit( 0 );
 
301
    incrementalSearch->hide();
 
302
    QToolTip::add( incrementalSearch, i18n( "Incremental search (Alt+I)" ) );
 
303
    connect( incrementalSearch, SIGNAL( textChanged( const QString & ) ),
 
304
             this, SLOT( searchIncremetalFind() ) );
 
305
    connect( incrementalSearch, SIGNAL( returnPressed() ),
 
306
             this, SLOT( searchIncremetalFindNext() ) );
 
307
    incrementalSearch->setEnabled( FALSE );
 
308
 
 
309
    QPopupMenu *menu = new QPopupMenu( this, "Search" );
 
310
    menubar->insertItem( i18n( "&Search" ), menu );
 
311
    actionSearchFind->addTo( menu );
 
312
    actionSearchIncremetal->addTo( menu );
 
313
    actionSearchReplace->addTo( menu );
 
314
    menu->insertSeparator();
 
315
    actionSearchGotoLine->addTo( menu );
 
316
}
 
317
 
 
318
void MainWindow::setupLayoutActions()
 
319
{
 
320
    if ( !actionGroupTools ) {
 
321
        actionGroupTools = new QActionGroup( this );
 
322
        actionGroupTools->setExclusive( TRUE );
 
323
        connect( actionGroupTools, SIGNAL( selected(QAction*) ), this, SLOT( toolSelected(QAction*) ) );
 
324
    }
 
325
 
 
326
    actionEditAdjustSize = new DesignerAction( i18n( "Adjust Size" ), createIconSet("designer_adjustsize.png"),
 
327
                                        i18n( "Adjust &Size" ), CTRL + Key_J, this, 0 );
 
328
    actionEditAdjustSize->setStatusTip(i18n("Adjusts the size of the selected widget") );
 
329
    actionEditAdjustSize->setWhatsThis( whatsThisFrom( "Layout|Adjust Size" ) );
 
330
    connect( actionEditAdjustSize, SIGNAL( activated() ), this, SLOT( editAdjustSize() ) );
 
331
    actionEditAdjustSize->setEnabled( FALSE );
 
332
 
 
333
    actionEditHLayout = new DesignerAction( i18n( "Lay Out Horizontally" ), createIconSet("designer_edithlayout.png"),
 
334
                                     i18n( "Lay Out &Horizontally" ), CTRL + Key_H, this, 0 );
 
335
    actionEditHLayout->setStatusTip(i18n("Lays out the selected widgets horizontally") );
 
336
    actionEditHLayout->setWhatsThis( whatsThisFrom( "Layout|Lay Out Horizontally" ) );
 
337
    connect( actionEditHLayout, SIGNAL( activated() ), this, SLOT( editLayoutHorizontal() ) );
 
338
    actionEditHLayout->setEnabled( FALSE );
 
339
 
 
340
    actionEditVLayout = new DesignerAction( i18n( "Lay Out Vertically" ), createIconSet("designer_editvlayout.png"),
 
341
                                     i18n( "Lay Out &Vertically" ), CTRL + Key_L, this, 0 );
 
342
    actionEditVLayout->setStatusTip(i18n("Lays out the selected widgets vertically") );
 
343
    actionEditVLayout->setWhatsThis(  whatsThisFrom( "Layout|Lay Out Vertically" ) );
 
344
    connect( actionEditVLayout, SIGNAL( activated() ), this, SLOT( editLayoutVertical() ) );
 
345
    actionEditVLayout->setEnabled( FALSE );
 
346
 
 
347
    actionEditGridLayout = new DesignerAction( i18n( "Lay Out in a Grid" ), createIconSet("designer_editgrid.png"),
 
348
                                        i18n( "Lay Out in a &Grid" ), CTRL + Key_G, this, 0 );
 
349
    actionEditGridLayout->setStatusTip(i18n("Lays out the selected widgets in a grid") );
 
350
    actionEditGridLayout->setWhatsThis( whatsThisFrom( "Layout|Lay Out in a Grid" ) );
 
351
    connect( actionEditGridLayout, SIGNAL( activated() ), this, SLOT( editLayoutGrid() ) );
 
352
    actionEditGridLayout->setEnabled( FALSE );
 
353
 
 
354
    actionEditSplitHorizontal = new DesignerAction( i18n( "Lay Out Horizontally (in Splitter)" ), createIconSet("designer_editvlayoutsplit.png"),
 
355
                                             i18n( "Lay Out Horizontally (in S&plitter)" ), 0, this, 0 );
 
356
    actionEditSplitHorizontal->setStatusTip(i18n("Lays out the selected widgets horizontally in a splitter") );
 
357
    actionEditSplitHorizontal->setWhatsThis( whatsThisFrom( "Layout|Lay Out Horizontally (in Splitter)" ) );
 
358
    connect( actionEditSplitHorizontal, SIGNAL( activated() ), this, SLOT( editLayoutHorizontalSplit() ) );
 
359
    actionEditSplitHorizontal->setEnabled( FALSE );
 
360
 
 
361
    actionEditSplitVertical = new DesignerAction( i18n( "Lay Out Vertically (in Splitter)" ), createIconSet("designer_edithlayoutsplit.png"),
 
362
                                             i18n( "Lay Out Vertically (in Sp&litter)" ), 0, this, 0 );
 
363
    actionEditSplitVertical->setStatusTip(i18n("Lays out the selected widgets vertically in a splitter") );
 
364
    actionEditSplitVertical->setWhatsThis( whatsThisFrom( "Layout|Lay Out Vertically (in Splitter)" ) );
 
365
    connect( actionEditSplitVertical, SIGNAL( activated() ), this, SLOT( editLayoutVerticalSplit() ) );
 
366
    actionEditSplitVertical->setEnabled( FALSE );
 
367
 
 
368
    actionEditBreakLayout = new DesignerAction( i18n( "Break Layout" ), createIconSet("designer_editbreaklayout.png"),
 
369
                                         i18n( "&Break Layout" ), CTRL + Key_B, this, 0 );
 
370
    actionEditBreakLayout->setStatusTip(i18n("Breaks the selected layout") );
 
371
    actionEditBreakLayout->setWhatsThis( whatsThisFrom( "Layout|Break Layout" ) );
 
372
    connect( actionEditBreakLayout, SIGNAL( activated() ), this, SLOT( editBreakLayout() ) );
 
373
    actionEditBreakLayout->setEnabled( FALSE );
 
374
 
 
375
    int id = WidgetDatabase::idFromClassName( "Spacer" );
 
376
    actionInsertSpacer = new WidgetAction( i18n( "Layout" ), actionGroupTools, QString::number( id ).latin1() );
 
377
    actionInsertSpacer->setToggleAction( TRUE );
 
378
    actionInsertSpacer->setText( WidgetDatabase::className( id ) );
 
379
    actionInsertSpacer->setMenuText( i18n( "Add %1").arg( WidgetDatabase::className( id ) ) );
 
380
    actionInsertSpacer->setIconSet( WidgetDatabase::iconSet( id ) );
 
381
    actionInsertSpacer->setToolTip( WidgetDatabase::toolTip( id ) );
 
382
    actionInsertSpacer->setStatusTip( i18n( "Insert a %1").arg(WidgetDatabase::toolTip( id )) );
 
383
    actionInsertSpacer->setWhatsThis( i18n("<b>A %1</b><p>%2</p>"
 
384
                             "<p>Click to insert a single %3,"
 
385
                             "or double click to keep the tool selected.")
 
386
        .arg(WidgetDatabase::toolTip( id ))
 
387
        .arg(WidgetDatabase::whatsThis( id ))
 
388
        .arg(WidgetDatabase::toolTip( id ) ));
 
389
 
 
390
    actionInsertSpacer->addTo( commonWidgetsToolBar );
 
391
    commonWidgetsPage.append( actionInsertSpacer );
 
392
    QWidget *w;
 
393
    commonWidgetsToolBar->setStretchableWidget( ( w = new QWidget( commonWidgetsToolBar ) ) );
 
394
    w->setBackgroundMode( commonWidgetsToolBar->backgroundMode() );
 
395
    QWhatsThis::add( layoutToolBar, i18n( "<b>The Layout toolbar</b>%1" ).arg(i18n(toolbarHelp).arg("")) );
 
396
    actionEditAdjustSize->addTo( layoutToolBar );
 
397
    layoutToolBar->addSeparator();
 
398
    actionEditHLayout->addTo( layoutToolBar );
 
399
    actionEditVLayout->addTo( layoutToolBar );
 
400
    actionEditGridLayout->addTo( layoutToolBar );
 
401
    actionEditSplitHorizontal->addTo( layoutToolBar );
 
402
    actionEditSplitVertical->addTo( layoutToolBar );
 
403
    actionEditBreakLayout->addTo( layoutToolBar );
 
404
    layoutToolBar->addSeparator();
 
405
    actionInsertSpacer->addTo( layoutToolBar );
 
406
 
 
407
    QPopupMenu *menu = new QPopupMenu( this, "Layout" );
 
408
    layoutMenu = menu;
 
409
    menubar->insertItem( i18n( "&Layout" ), menu, toolsMenuId + 1 );
 
410
    actionEditAdjustSize->addTo( menu );
 
411
    menu->insertSeparator();
 
412
    actionEditHLayout->addTo( menu );
 
413
    actionEditVLayout->addTo( menu );
 
414
    actionEditGridLayout->addTo( menu );
 
415
    actionEditSplitHorizontal->addTo( menu );
 
416
    actionEditSplitVertical->addTo( menu );
 
417
    actionEditBreakLayout->addTo( menu );
 
418
    menu->insertSeparator();
 
419
    actionInsertSpacer->addTo( menu );
 
420
}
 
421
 
 
422
void MainWindow::setupToolActions()
 
423
{
 
424
    if ( !actionGroupTools ) {
 
425
        actionGroupTools = new QActionGroup( this );
 
426
        actionGroupTools->setExclusive( TRUE );
 
427
        connect( actionGroupTools, SIGNAL( selected(QAction*) ),
 
428
                 this, SLOT( toolSelected(QAction*) ) );
 
429
    }
 
430
 
 
431
    actionPointerTool = new DesignerAction( i18n("Pointer"), createIconSet("designer_pointer.png"),
 
432
                                     i18n("&Pointer"),  Key_F2,
 
433
                                     actionGroupTools,
 
434
                                     QString::number(POINTER_TOOL).latin1(), TRUE );
 
435
    actionPointerTool->setStatusTip( i18n("Selects the pointer tool") );
 
436
    actionPointerTool->setWhatsThis( whatsThisFrom( "Tools|Pointer" ) );
 
437
 
 
438
    actionConnectTool = new DesignerAction( i18n("Connect Signal/Slots"),
 
439
                                     createIconSet("designer_connecttool.png"),
 
440
                                     i18n("&Connect Signal/Slots"),
 
441
                                     singleProjectMode() ? 0 : Key_F3,
 
442
                                     actionGroupTools,
 
443
                                     QString::number(CONNECT_TOOL).latin1(), TRUE );
 
444
    actionConnectTool->setStatusTip( i18n("Selects the connection tool") );
 
445
    actionConnectTool->setWhatsThis( whatsThisFrom( "Tools|Connect Signals and Slots" ) );
 
446
 
 
447
    actionOrderTool = new DesignerAction( i18n("Tab Order"), createIconSet("designer_ordertool.png"),
 
448
                                   i18n("Tab &Order"),  Key_F4,
 
449
                                   actionGroupTools,
 
450
                                   QString::number(ORDER_TOOL).latin1(), TRUE );
 
451
    actionOrderTool->setStatusTip( i18n("Selects the tab order tool") );
 
452
    actionOrderTool->setWhatsThis( whatsThisFrom( "Tools|Tab Order" ) );
 
453
 
 
454
    actionBuddyTool = new DesignerAction( i18n( "Set Buddy" ), createIconSet( "designer_setbuddy.png" ),
 
455
                                   i18n( "Set &Buddy" ), Key_F12,
 
456
                                   actionGroupTools, QString::number( BUDDY_TOOL ).latin1(),
 
457
                                   TRUE );
 
458
    actionBuddyTool->setStatusTip( i18n( "Sets a buddy to a label" ) );
 
459
    actionBuddyTool->setWhatsThis( whatsThisFrom( "Tools|Set Buddy" ) );
 
460
 
 
461
    QToolBar *tb = new QToolBar( this, "Tools" );
 
462
    tb->setCloseMode( QDockWindow::Undocked );
 
463
    toolsToolBar = tb;
 
464
    QWhatsThis::add( tb, i18n( "<b>The Tools toolbar</b>%1" ).arg(i18n(toolbarHelp).arg("")) );
 
465
 
 
466
    addToolBar( tb, i18n( "Tools" ), QMainWindow::DockTop, FALSE );
 
467
    actionPointerTool->addTo( tb );
 
468
    if ( !singleProjectMode() )
 
469
        actionConnectTool->addTo( tb );
 
470
    actionOrderTool->addTo( tb );
 
471
    actionBuddyTool->addTo( tb );
 
472
 
 
473
    QPopupMenu *mmenu = new QPopupMenu( this, "Tools" );
 
474
    toolsMenu = mmenu;
 
475
    toolsMenuId = 100;
 
476
    menubar->insertItem( i18n( "&Tools" ), mmenu, toolsMenuId );
 
477
    toolsMenuIndex = menubar->indexOf( toolsMenuId );
 
478
    actionPointerTool->addTo( mmenu );
 
479
    if ( !singleProjectMode() )
 
480
        actionConnectTool->addTo( mmenu );
 
481
    actionOrderTool->addTo( mmenu );
 
482
    actionBuddyTool->addTo( mmenu );
 
483
    mmenu->insertSeparator();
 
484
 
 
485
    customWidgetToolBar = 0;
 
486
    customWidgetMenu = 0;
 
487
 
 
488
    actionToolsCustomWidget = new DesignerAction( i18n("Custom Widgets"),
 
489
                                           createIconSet( "designer_customwidget.png" ),
 
490
                                           i18n("Edit &Custom Widgets..."), 0, this, 0 );
 
491
    actionToolsCustomWidget->setStatusTip( i18n("Opens a dialog to add and change "
 
492
                                              "custom widgets") );
 
493
    actionToolsCustomWidget->setWhatsThis( whatsThisFrom( "Tools|Custom|Edit Custom"
 
494
                                                          "Widgets" ) );
 
495
    connect( actionToolsCustomWidget, SIGNAL( activated() ),
 
496
             this, SLOT( toolsCustomWidget() ) );
 
497
 
 
498
    for ( int j = 0; j < WidgetDatabase::numWidgetGroups(); ++j ) {
 
499
        QString grp = WidgetDatabase::widgetGroup( j );
 
500
        if ( !WidgetDatabase::isGroupVisible( grp ) ||
 
501
             WidgetDatabase::isGroupEmpty( grp ) )
 
502
            continue;
 
503
        QToolBar *tb = new QToolBar( this, grp.latin1() );
 
504
        tb->setCloseMode( QDockWindow::Undocked );
 
505
        widgetToolBars.append( tb );
 
506
        bool plural = grp[(int)grp.length()-1] == 's';
 
507
        if ( plural ) {
 
508
            QWhatsThis::add( tb, i18n( "<b>The %1</b>%2" ).arg(grp).arg(i18n(toolbarHelp).
 
509
                                arg( i18n(" Click on a button to insert a single widget, "
 
510
                                "or double click to insert multiple %1.") ).arg(grp)) );
 
511
        } else {
 
512
            QWhatsThis::add( tb, i18n( "<b>The %1 Widgets</b>%2" ).arg(grp).arg(i18n(toolbarHelp).
 
513
                                arg( i18n(" Click on a button to insert a single %1 widget, "
 
514
                                "or double click to insert multiple widgets.") ).arg(grp)) );
 
515
        }
 
516
        addToolBar( tb, grp );
 
517
        tb->hide();
 
518
        QPopupMenu *menu = new QPopupMenu( this, grp.latin1() );
 
519
        mmenu->insertItem( grp, menu );
 
520
 
 
521
        QToolBar *tb2 = new QToolBar( grp, 0, toolBox, FALSE, grp.latin1() );
 
522
        tb2->setFrameStyle( QFrame::NoFrame );
 
523
        tb2->setOrientation( Qt::Vertical );
 
524
        tb2->setBackgroundMode( PaletteBase );
 
525
        toolBox->addItem( tb2, grp );
 
526
 
 
527
        if ( grp == "Custom" ) {
 
528
            if ( !customWidgetMenu )
 
529
                actionToolsCustomWidget->addTo( menu );
 
530
            else
 
531
                menu->insertSeparator();
 
532
            customWidgetMenu = menu;
 
533
            customWidgetToolBar = tb;
 
534
        }
 
535
 
 
536
        for ( int i = 0; i < WidgetDatabase::count(); ++i ) {
 
537
            if ( WidgetDatabase::group( i ) != grp )
 
538
                continue; // only widgets, i.e. not forms and temp stuff
 
539
            WidgetAction* a =
 
540
                new WidgetAction( grp, actionGroupTools, QString::number( i ).latin1() );
 
541
            a->setToggleAction( TRUE );
 
542
            QString atext = WidgetDatabase::className( i );
 
543
            if ( atext[0] == 'Q' )
 
544
                atext = atext.mid(1);
 
545
            while ( atext.length() && atext[0] >= 'a' && atext[0] <= 'z' )
 
546
                atext = atext.mid(1);
 
547
            if ( atext.isEmpty() )
 
548
                atext = WidgetDatabase::className( i );
 
549
            a->setText( atext );
 
550
            QString ttip = WidgetDatabase::toolTip( i );
 
551
            a->setIconSet( WidgetDatabase::iconSet( i ) );
 
552
            a->setToolTip( ttip );
 
553
            if ( !WidgetDatabase::isWhatsThisLoaded() )
 
554
                WidgetDatabase::loadWhatsThis( documentationPath() );
 
555
            a->setStatusTip( i18n( "Insert a %1").arg(WidgetDatabase::className( i )) );
 
556
 
 
557
            QString whats = i18n("<b>A %1</b>").arg( WidgetDatabase::className( i ) );
 
558
            if ( !WidgetDatabase::whatsThis( i ).isEmpty() )
 
559
            whats += QString("<p>%1</p>").arg(WidgetDatabase::whatsThis( i ));
 
560
            a->setWhatsThis( whats+ i18n("<p>Double click on this tool to keep it selected.</p>") );
 
561
 
 
562
            if ( grp != "KDE" )
 
563
                a->addTo( tb );
 
564
            a->addTo( menu );
 
565
            a->addTo( tb2 );
 
566
            if ( WidgetDatabase::isCommon( i ) ) {
 
567
                a->addTo( commonWidgetsToolBar );
 
568
                commonWidgetsPage.append( a );
 
569
            }
 
570
        }
 
571
        QWidget *w;
 
572
        tb2->setStretchableWidget( ( w = new QWidget( tb2 ) ) );
 
573
        w->setBackgroundMode( tb2->backgroundMode() );
 
574
    }
 
575
 
 
576
    if ( !customWidgetToolBar ) {
 
577
        QToolBar *tb = new QToolBar( this, "Custom Widgets" );
 
578
        tb->setCloseMode( QDockWindow::Undocked );
 
579
        QWhatsThis::add( tb, i18n( "<b>The Custom Widgets toolbar</b>%1"
 
580
                                 "<p>Click <b>Edit Custom Widgets...</b>"
 
581
                                 "in the <b>Tools|Custom</b> menu to "
 
582
                                 "add and change custom widgets</p>" ).
 
583
                         arg(i18n(toolbarHelp).
 
584
                             arg( i18n(" Click on the buttons to insert a single widget, "
 
585
                                     "or double click to insert multiple widgets.") )) );
 
586
        addToolBar( tb, i18n( "Custom" ) );
 
587
        tb->hide();
 
588
        widgetToolBars.append( tb );
 
589
        customWidgetToolBar = tb;
 
590
        QPopupMenu *menu = new QPopupMenu( this, "Custom Widgets" );
 
591
        mmenu->insertItem( "Custom", menu );
 
592
        customWidgetMenu = menu;
 
593
        customWidgetToolBar->hide();
 
594
        actionToolsCustomWidget->addTo( customWidgetMenu );
 
595
        customWidgetMenu->insertSeparator();
 
596
        QToolBar *tb2 = new QToolBar( "Custom Widgets", 0,
 
597
                                      toolBox, FALSE, "Custom Widgets" );
 
598
        tb2->setBackgroundMode(PaletteBase);
 
599
        tb2->setOrientation( Qt::Vertical );
 
600
        tb2->setFrameStyle( QFrame::NoFrame );
 
601
        toolBox->addItem( tb2, "Custom Widgets" );
 
602
        customWidgetToolBar2 = tb2;
 
603
    }
 
604
 
 
605
    QAction *a = new DesignerAction( i18n( "Configure Toolbox" ), i18n( "Configure Toolbox..." ), 0, this );
 
606
    a->setStatusTip( i18n( "Opens a dialog to configure the common "
 
607
                                               "widgets page of the toolbox") );
 
608
    connect( a, SIGNAL( activated() ), this, SLOT( toolsConfigure() ) );
 
609
    mmenu->insertSeparator();
 
610
    a->addTo( mmenu );
 
611
    resetTool();
 
612
}
 
613
 
 
614
void MainWindow::setupFileActions()
 
615
{
 
616
    QToolBar* tb  = new QToolBar( this, "File" );
 
617
    tb->setCloseMode( QDockWindow::Undocked );
 
618
    projectToolBar = tb;
 
619
 
 
620
    QWhatsThis::add( tb, i18n( "<b>The File toolbar</b>%1" ).arg(i18n(toolbarHelp).arg("")) );
 
621
    addToolBar( tb, i18n( "File" ) );
 
622
    fileMenu = new QPopupMenu( this, "File" );
 
623
    menubar->insertItem( i18n( "&File" ), fileMenu );
 
624
 
 
625
    DesignerAction *a = 0;
 
626
 
 
627
    if ( !singleProject ) {
 
628
        DesignerAction *a = new DesignerAction( this, 0 );
 
629
        a->setText( i18n( "New" ) );
 
630
        a->setToolTip( i18n( "New dialog or file" ) );
 
631
        a->setMenuText( i18n( "&New..." ) );
 
632
        a->setIconSet( createIconSet("designer_filenew.png") );
 
633
        a->setAccel( CTRL + Key_N );
 
634
        a->setStatusTip( i18n( "Creates a new project, form or source file." ) );
 
635
        a->setWhatsThis( whatsThisFrom( "File|New" ) );
 
636
        connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
 
637
        a->addTo( tb );
 
638
        a->addTo( fileMenu );
 
639
        actionNewFile = a;
 
640
    } else {
 
641
        actionGroupNew = new QActionGroup( this, 0, FALSE );
 
642
        QActionGroup* a = actionGroupNew;
 
643
        ( (QActionGroup*)a )->setUsesDropDown( TRUE );
 
644
        a->setText( i18n( "New" ) );
 
645
        a->setMenuText( i18n( "&New..." ) );
 
646
        a->setIconSet( createIconSet("designer_form.png") );
 
647
        a->setStatusTip( i18n( "Creates a new dialog or file" ) );
 
648
        a->setWhatsThis( whatsThisFrom( "File|New" ) );
 
649
 
 
650
        QAction *newForm = new DesignerAction( a, 0 );
 
651
        newForm->setText( i18n( "New Dialog" ) );
 
652
        newForm->setMenuText( i18n( "&Dialog..." ) );
 
653
        newForm->setIconSet( createIconSet("designer_form.png") );
 
654
        newForm->setAccel( CTRL + Key_N );
 
655
        newForm->setStatusTip( i18n( "Creates a new dialog." ) );
 
656
        connect( newForm, SIGNAL( activated() ), this, SLOT( fileNewDialog() ) );
 
657
 
 
658
        DesignerAction *newFile = new DesignerAction( a, 0 );
 
659
        newFile->setText( i18n( "New File" ) );
 
660
        newFile->setMenuText( i18n( "&File..." ) );
 
661
        newFile->setIconSet( createIconSet("designer_filenew.png") );
 
662
        newFile->setAccel( ALT + Key_N );
 
663
        newFile->setStatusTip( i18n( "Creates a new file." ) );
 
664
        connect( newFile, SIGNAL( activated() ), this, SLOT( fileNewFile() ) );
 
665
        actionNewFile = newFile;
 
666
 
 
667
        a->addTo( tb );
 
668
        a->addTo( fileMenu );
 
669
 
 
670
        fileMenu->insertSeparator();
 
671
    }
 
672
 
 
673
    a = new DesignerAction( this, 0 );
 
674
    a->setText( i18n( "Open" ) );
 
675
    a->setMenuText( i18n( "&Open..." ) );
 
676
    a->setIconSet( createIconSet("designer_fileopen.png") );
 
677
    a->setAccel( CTRL + Key_O );
 
678
    a->setStatusTip( i18n( "Opens an existing project, form or source file ") );
 
679
    a->setWhatsThis( whatsThisFrom( "File|Open" ) );
 
680
    connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) );
 
681
    if ( !singleProject ) {
 
682
        a->addTo( tb );
 
683
        a->addTo( fileMenu );
 
684
        fileMenu->insertSeparator();
 
685
    }
 
686
 
 
687
 
 
688
    a = new DesignerAction( this, 0 );
 
689
    actionFileClose = a;
 
690
    a->setText( i18n( "Close" ) );
 
691
    a->setMenuText( i18n( "&Close" ) );
 
692
    a->setStatusTip( i18n( "Closes the current project or document" ) );
 
693
    a->setWhatsThis(whatsThisFrom( "File|Close" ) );
 
694
    connect( a, SIGNAL( activated() ), this, SLOT( fileClose() ) );
 
695
    connect( this, SIGNAL( hasActiveWindowOrProject(bool) ), a, SLOT( setEnabled(bool) ) );
 
696
    if ( !singleProject ) {
 
697
        a->addTo( fileMenu );
 
698
        fileMenu->insertSeparator();
 
699
    }
 
700
 
 
701
    a = new DesignerAction( this, 0 );
 
702
    actionFileSave = a;
 
703
    a->setText( i18n( "Save" ) );
 
704
    a->setMenuText( i18n( "&Save" ) );
 
705
    a->setIconSet( createIconSet("designer_filesave.png") );
 
706
    a->setAccel( CTRL + Key_S );
 
707
    a->setStatusTip( i18n( "Saves the current project or document" ) );
 
708
    a->setWhatsThis(whatsThisFrom( "File|Save" ) );
 
709
    connect( a, SIGNAL( activated() ), this, SLOT( fileSave() ) );
 
710
    connect( this, SIGNAL( hasActiveWindowOrProject(bool) ), a, SLOT( setEnabled(bool) ) );
 
711
    a->addTo( tb );
 
712
    a->addTo( fileMenu );
 
713
 
 
714
    a = new DesignerAction( this, 0 );
 
715
    actionFileSaveAs = a;
 
716
    a->setText( i18n( "Save As" ) );
 
717
    a->setMenuText( i18n( "Save &As..." ) );
 
718
    a->setStatusTip( i18n( "Saves the current form with a new filename" ) );
 
719
    a->setWhatsThis( whatsThisFrom( "File|Save As" ) );
 
720
    connect( a, SIGNAL( activated() ), this, SLOT( fileSaveAs() ) );
 
721
    connect( this, SIGNAL( hasActiveWindow(bool) ), a, SLOT( setEnabled(bool) ) );
 
722
    if ( !singleProject )
 
723
        a->addTo( fileMenu );
 
724
 
 
725
    a = new DesignerAction( this, 0 );
 
726
    actionFileSaveAll = a;
 
727
    a->setText( i18n( "Save All" ) );
 
728
    a->setMenuText( i18n( "Sa&ve All" ) );
 
729
    a->setStatusTip( i18n( "Saves all open documents" ) );
 
730
    a->setWhatsThis( whatsThisFrom( "File|Save All" ) );
 
731
    connect( a, SIGNAL( activated() ), this, SLOT( fileSaveAll() ) );
 
732
    connect( this, SIGNAL( hasActiveWindowOrProject(bool) ), a, SLOT( setEnabled(bool) ) );
 
733
    if ( !singleProject ) {
 
734
        a->addTo( fileMenu );
 
735
        fileMenu->insertSeparator();
 
736
    }
 
737
 
 
738
    a = new DesignerAction( this, 0 );
 
739
    a->setText( i18n( "Create Template" ) );
 
740
    a->setMenuText( i18n( "Create &Template..." ) );
 
741
    a->setStatusTip( i18n( "Creates a new template" ) );
 
742
    a->setWhatsThis( whatsThisFrom( "File|Create Template" ) );
 
743
    connect( a, SIGNAL( activated() ), this, SLOT( fileCreateTemplate() ) );
 
744
    if ( !singleProject )
 
745
        a->addTo( fileMenu );
 
746
 
 
747
    if ( !singleProject )
 
748
        fileMenu->insertSeparator();
 
749
 
 
750
    recentlyFilesMenu = new QPopupMenu( this );
 
751
    recentlyProjectsMenu = new QPopupMenu( this );
 
752
 
 
753
    if ( !singleProject ) {
 
754
        fileMenu->insertItem( i18n( "Recently Opened Files " ), recentlyFilesMenu );
 
755
        fileMenu->insertItem( i18n( "Recently Opened Projects" ), recentlyProjectsMenu );
 
756
    }
 
757
 
 
758
    connect( recentlyFilesMenu, SIGNAL( aboutToShow() ),
 
759
             this, SLOT( setupRecentlyFilesMenu() ) );
 
760
    connect( recentlyProjectsMenu, SIGNAL( aboutToShow() ),
 
761
             this, SLOT( setupRecentlyProjectsMenu() ) );
 
762
    connect( recentlyFilesMenu, SIGNAL( activated( int ) ),
 
763
             this, SLOT( recentlyFilesMenuActivated( int ) ) );
 
764
    connect( recentlyProjectsMenu, SIGNAL( activated( int ) ),
 
765
             this, SLOT( recentlyProjectsMenuActivated( int ) ) );
 
766
 
 
767
    if ( !singleProject )
 
768
        fileMenu->insertSeparator();
 
769
 
 
770
    a = new DesignerAction( this, 0 );
 
771
    actionFileExit = a;
 
772
    if  ( !singleProjectMode() ) {
 
773
        a->setText( i18n( "Exit" ) );
 
774
        a->setMenuText( i18n( "E&xit" ) );
 
775
        a->setStatusTip( i18n( "Quits the application and prompts to save any changed forms, source files or project settings" ) );
 
776
        a->setWhatsThis( whatsThisFrom( "File|Exit" ) );
 
777
    } else {
 
778
        a->setText( i18n( "Close" ) );
 
779
        a->setMenuText( i18n( "&Close" ) );
 
780
    }
 
781
    connect( a, SIGNAL( activated() ), this, SLOT( fileQuit() ) );
 
782
    a->addTo( fileMenu );
 
783
}
 
784
 
 
785
void MainWindow::setupProjectActions()
 
786
{
 
787
    projectMenu = new QPopupMenu( this, "Project" );
 
788
    menubar->insertItem( i18n( "Pr&oject" ), projectMenu );
 
789
 
 
790
    QActionGroup *ag = new QActionGroup( this, 0 );
 
791
    ag->setText( i18n( "Active Project" ) );
 
792
    ag->setMenuText( i18n( "Active Project" ) );
 
793
    ag->setExclusive( TRUE );
 
794
    ag->setUsesDropDown( TRUE );
 
795
    connect( ag, SIGNAL( selected( QAction * ) ), this, SLOT( projectSelected( QAction * ) ) );
 
796
    connect( ag, SIGNAL( selected( QAction * ) ), this, SIGNAL( projectChanged() ) );
 
797
    DesignerAction *a = new DesignerAction( i18n( "<No Project>" ), i18n( "<No Project>" ), 0, ag, 0, TRUE );
 
798
    eProject = new Project( "", i18n( "<No Project>" ), projectSettingsPluginManager, TRUE );
 
799
    projects.insert( a, eProject );
 
800
    a->setOn( TRUE );
 
801
    ag->addTo( projectMenu );
 
802
    ag->addTo( projectToolBar );
 
803
    actionGroupProjects = ag;
 
804
 
 
805
    if ( !singleProject )
 
806
        projectMenu->insertSeparator();
 
807
 
 
808
    a = new DesignerAction( i18n( "Add File" ), QPixmap(), i18n( "&Add File..." ), 0, this, 0 );
 
809
    actionProjectAddFile = a;
 
810
    a->setStatusTip( i18n("Adds a file to the current project") );
 
811
    a->setWhatsThis( whatsThisFrom( "Project|Add File" ) );
 
812
    connect( a, SIGNAL( activated() ), this, SLOT( projectInsertFile() ) );
 
813
    a->setEnabled( FALSE );
 
814
    connect( this, SIGNAL( hasNonDummyProject(bool) ), a, SLOT( setEnabled(bool) ) );
 
815
    if ( !singleProject )
 
816
        a->addTo( projectMenu );
 
817
 
 
818
    actionEditPixmapCollection = new DesignerAction( i18n( "Image Collection..." ), QPixmap(),
 
819
                                          i18n( "&Image Collection..." ), 0, this, 0 );
 
820
    actionEditPixmapCollection->setStatusTip( i18n("Opens a dialog for editing the current project's image collection") );
 
821
    actionEditPixmapCollection->setWhatsThis( whatsThisFrom( "Project|Image Collection" ) );
 
822
    connect( actionEditPixmapCollection, SIGNAL( activated() ), this, SLOT( editPixmapCollection() ) );
 
823
    actionEditPixmapCollection->setEnabled( FALSE );
 
824
    connect( this, SIGNAL( hasNonDummyProject(bool) ), actionEditPixmapCollection, SLOT( setEnabled(bool) ) );
 
825
    actionEditPixmapCollection->addTo( projectMenu );
 
826
 
 
827
#ifndef QT_NO_SQL
 
828
    actionEditDatabaseConnections = new DesignerAction( i18n( "Database Connections..." ), QPixmap(),
 
829
                                                 i18n( "&Database Connections..." ), 0, this, 0 );
 
830
    actionEditDatabaseConnections->setStatusTip( i18n("Opens a dialog for editing the current project's database connections") );
 
831
    actionEditDatabaseConnections->setWhatsThis( whatsThisFrom( "Project|Database Connections" ) );
 
832
    connect( actionEditDatabaseConnections, SIGNAL( activated() ), this, SLOT( editDatabaseConnections() ) );
 
833
    //actionEditDatabaseConnections->setEnabled( FALSE );
 
834
    //connect( this, SIGNAL( hasNonDummyProject(bool) ), actionEditDatabaseConnections, SLOT( setEnabled(bool) ) );
 
835
    if ( !singleProject )
 
836
        actionEditDatabaseConnections->addTo( projectMenu );
 
837
#endif
 
838
 
 
839
    actionEditProjectSettings = new DesignerAction( i18n( "Project Settings..." ), QPixmap(),
 
840
                                          i18n( "&Project Settings..." ), 0, this, 0 );
 
841
    actionEditProjectSettings->setStatusTip( i18n("Opens a dialog to change the project's settings") );
 
842
    actionEditProjectSettings->setWhatsThis( whatsThisFrom( "Project|Project Settings" ) );
 
843
    connect( actionEditProjectSettings, SIGNAL( activated() ), this, SLOT( editProjectSettings() ) );
 
844
    actionEditProjectSettings->setEnabled( FALSE );
 
845
    connect( this, SIGNAL( hasNonDummyProject(bool) ), actionEditProjectSettings, SLOT( setEnabled(bool) ) );
 
846
    actionEditProjectSettings->addTo( projectMenu );
 
847
 
 
848
}
 
849
 
 
850
void MainWindow::setupPreviewActions()
 
851
{
 
852
    DesignerAction* a = 0;
 
853
    QPopupMenu *menu = new QPopupMenu( this, "Preview" );
 
854
    layoutMenu = menu;
 
855
    menubar->insertItem( i18n( "&Preview" ), menu, toolsMenuId + 2 );
 
856
 
 
857
    a = new DesignerAction( i18n( "Preview Form" ), QPixmap(), i18n( "Preview &Form" ), 0, this, 0 );
 
858
    actionPreview = a;
 
859
    a->setAccel( CTRL + Key_T );
 
860
    a->setStatusTip( i18n("Opens a preview") );
 
861
    a->setWhatsThis( whatsThisFrom( "Preview|Preview Form" ) );
 
862
    connect( a, SIGNAL( activated() ), this, SLOT( previewForm() ) );
 
863
    connect( this, SIGNAL( hasActiveForm(bool) ), a, SLOT( setEnabled(bool) ) );
 
864
    a->addTo( menu );
 
865
 
 
866
    menu->insertSeparator();
 
867
 
 
868
    QSignalMapper *mapper = new QSignalMapper( this );
 
869
    connect( mapper, SIGNAL(mapped(const QString&)), this, SLOT(previewForm(const QString&)) );
 
870
    QStringList styles = QStyleFactory::keys();
 
871
    for ( QStringList::Iterator it = styles.begin(); it != styles.end(); ++it ) {
 
872
        QString info;
 
873
        if ( *it == "Motif" )
 
874
            info = i18n( "The preview will use the Motif look and feel which is used as the default style on most UNIX systems." );
 
875
        else if ( *it == "Windows" )
 
876
            info = i18n( "The preview will use the Windows look and feel." );
 
877
        else if ( *it == "Platinum" )
 
878
            info = i18n( "The preview will use the Platinum look and feel which is similar to the Macintosh GUI style." );
 
879
        else if ( *it == "CDE" )
 
880
            info = i18n( "The preview will use the CDE look and feel which is similar to some versions of the Common Desktop Environment." );
 
881
        else if ( *it == "SGI" )
 
882
            info = i18n( "The preview will use the Motif look and feel which is used as the default style on SGI systems." );
 
883
        else if ( *it == "MotifPlus" )
 
884
            info = i18n( "The preview will use the advanced Motif look and feel used by the GIMP toolkit (GTK) on Linux." );
 
885
 
 
886
        a = new DesignerAction( i18n( "Preview Form in %1 Style" ).arg( *it ), QPixmap(),
 
887
                                         i18n( "... in %1 Style" ).arg( *it ), 0, this, 0 );
 
888
        a->setStatusTip( i18n("Opens a preview in %1 style").arg( *it ) );
 
889
        a->setWhatsThis( i18n("<b>Open a preview in %1 style.</b>"
 
890
                        "<p>Use the preview to test the design and "
 
891
                        "signal-slot connections of the current form. %2</p>").arg( *it ).arg( info ) );
 
892
        mapper->setMapping( a, *it );
 
893
        connect( a, SIGNAL(activated()), mapper, SLOT(map()) );
 
894
        connect( this, SIGNAL( hasActiveForm(bool) ), a, SLOT( setEnabled(bool) ) );
 
895
        a->addTo( menu );
 
896
    }
 
897
}
 
898
 
 
899
void MainWindow::setupWindowActions()
 
900
{
 
901
/*    static bool windowActionsSetup = FALSE;
 
902
    if ( !windowActionsSetup ) {
 
903
        windowActionsSetup = TRUE;
 
904
*/
 
905
        actionWindowTile = new DesignerAction( i18n( "Tile" ), i18n( "&Tile" ), 0, this );
 
906
        actionWindowTile->setStatusTip( i18n("Tiles the windows so that they are all visible") );
 
907
        actionWindowTile->setWhatsThis( whatsThisFrom( "Window|Tile" ) );
 
908
        connect( actionWindowTile, SIGNAL( activated() ), qworkspace, SLOT( tile() ) );
 
909
        actionWindowCascade = new DesignerAction( i18n( "Cascade" ), i18n( "&Cascade" ), 0, this );
 
910
        actionWindowCascade->setStatusTip( i18n("Cascades the windows so that all their title bars are visible") );
 
911
        actionWindowCascade->setWhatsThis( whatsThisFrom( "Window|Cascade" ) );
 
912
        connect( actionWindowCascade, SIGNAL( activated() ), qworkspace, SLOT( cascade() ) );
 
913
 
 
914
        actionWindowClose = new DesignerAction( i18n( "Close" ), i18n( "Cl&ose" ), CTRL + Key_F4, this );
 
915
        actionWindowClose->setStatusTip( i18n( "Closes the active window") );
 
916
        actionWindowClose->setWhatsThis( whatsThisFrom( "Window|Close" ) );
 
917
        connect( actionWindowClose, SIGNAL( activated() ), qworkspace, SLOT( closeActiveWindow() ) );
 
918
 
 
919
        actionWindowCloseAll = new DesignerAction( i18n( "Close All" ), i18n( "Close Al&l" ), 0, this );
 
920
        actionWindowCloseAll->setStatusTip( i18n( "Closes all form windows") );
 
921
        actionWindowCloseAll->setWhatsThis( whatsThisFrom( "Window|Close All" ) );
 
922
        connect( actionWindowCloseAll, SIGNAL( activated() ), qworkspace, SLOT( closeAllWindows() ) );
 
923
 
 
924
        actionWindowNext = new DesignerAction( i18n( "Next" ), i18n( "Ne&xt" ), CTRL + Key_F6, this );
 
925
        actionWindowNext->setStatusTip( i18n( "Activates the next window" ) );
 
926
        actionWindowNext->setWhatsThis( whatsThisFrom( "Window|Next" ) );
 
927
        connect( actionWindowNext, SIGNAL( activated() ), qworkspace, SLOT( activateNextWindow() ) );
 
928
 
 
929
        actionWindowPrevious = new DesignerAction( i18n( "Previous" ), i18n( "Pre&vious" ), CTRL + SHIFT + Key_F6, this );
 
930
        actionWindowPrevious->setStatusTip( i18n( "Activates the previous window" ) );
 
931
        actionWindowPrevious->setWhatsThis( whatsThisFrom( "Window|Previous" ) );
 
932
        connect( actionWindowPrevious, SIGNAL( activated() ), qworkspace, SLOT( activatePreviousWindow() ) );
 
933
  //  }
 
934
 
 
935
    if ( !windowMenu ) {
 
936
        windowMenu = new QPopupMenu( this, "Window" );
 
937
        menubar->insertItem( i18n( "&Window" ), windowMenu );
 
938
        connect( windowMenu, SIGNAL( aboutToShow() ),
 
939
                 this, SLOT( setupWindowActions() ) );
 
940
    } else {
 
941
        windowMenu->clear();
 
942
    }
 
943
 
 
944
    actionWindowClose->addTo( windowMenu );
 
945
    actionWindowCloseAll->addTo( windowMenu );
 
946
    windowMenu->insertSeparator();
 
947
    actionWindowNext->addTo( windowMenu );
 
948
    actionWindowPrevious->addTo( windowMenu );
 
949
    windowMenu->insertSeparator();
 
950
    actionWindowTile->addTo( windowMenu );
 
951
    actionWindowCascade->addTo( windowMenu );
 
952
    windowMenu->insertSeparator();
 
953
    windowMenu->insertItem( i18n( "Vie&ws" ), createDockWindowMenu( NoToolBars ) );
 
954
    windowMenu->insertItem( i18n( "Tool&bars" ), createDockWindowMenu( OnlyToolBars ) );
 
955
    QWidgetList windows = qworkspace->windowList();
 
956
    if ( windows.count() && formWindow() )
 
957
        windowMenu->insertSeparator();
 
958
    int j = 0;
 
959
    for ( int i = 0; i < int( windows.count() ); ++i ) {
 
960
        QWidget *w = windows.at( i );
 
961
        if ( !::qt_cast<FormWindow*>(w) && !::qt_cast<SourceEditor*>(w) )
 
962
            continue;
 
963
        if ( ::qt_cast<FormWindow*>(w) && ( ( (FormWindow*)w )->isFake() ) )
 
964
            continue;
 
965
        j++;
 
966
        QString itemText;
 
967
        if ( j < 10 )
 
968
            itemText = QString("&%1 ").arg( j );
 
969
        if ( ::qt_cast<FormWindow*>(w) )
 
970
            itemText += w->name();
 
971
        else
 
972
            itemText += w->caption();
 
973
 
 
974
        int id = windowMenu->insertItem( itemText, this, SLOT( windowsMenuActivated( int ) ) );
 
975
        windowMenu->setItemParameter( id, i );
 
976
        windowMenu->setItemChecked( id, qworkspace->activeWindow() == windows.at( i ) );
 
977
    }
 
978
}
 
979
 
 
980
void MainWindow::setupHelpActions()
 
981
{
 
982
    actionHelpContents = new DesignerAction( i18n( "Contents" ), i18n( "&Contents" ), Key_F1, this, 0 );
 
983
    actionHelpContents->setStatusTip( i18n("Opens the online help") );
 
984
    actionHelpContents->setWhatsThis( whatsThisFrom( "Help|Contents" ) );
 
985
    connect( actionHelpContents, SIGNAL( activated() ), this, SLOT( helpContents() ) );
 
986
 
 
987
    actionHelpManual = new DesignerAction( i18n( "Manual" ), i18n( "&Manual" ), CTRL + Key_M, this, 0 );
 
988
    actionHelpManual->setStatusTip( i18n("Opens the Qt Designer manual") );
 
989
    actionHelpManual->setWhatsThis( whatsThisFrom( "Help|Manual" ) );
 
990
    connect( actionHelpManual, SIGNAL( activated() ), this, SLOT( helpManual() ) );
 
991
 
 
992
    actionHelpAbout = new DesignerAction( i18n("About"), QPixmap(), i18n("&About"), 0, this, 0 );
 
993
    actionHelpAbout->setStatusTip( i18n("Displays information about Qt Designer") );
 
994
    actionHelpAbout->setWhatsThis( whatsThisFrom( "Help|About" ) );
 
995
    connect( actionHelpAbout, SIGNAL( activated() ), this, SLOT( helpAbout() ) );
 
996
 
 
997
    actionHelpAboutQt = new DesignerAction( i18n("About Qt"), QPixmap(), i18n("About &Qt"), 0, this, 0 );
 
998
    actionHelpAboutQt->setStatusTip( i18n("Displays information about the Qt Toolkit") );
 
999
    actionHelpAboutQt->setWhatsThis( whatsThisFrom( "Help|About Qt" ) );
 
1000
    connect( actionHelpAboutQt, SIGNAL( activated() ), this, SLOT( helpAboutQt() ) );
 
1001
 
 
1002
#if 0 //defined(QT_NON_COMMERCIAL)
 
1003
    // ### not used anymore -- should be deleted?
 
1004
    actionHelpRegister = new DesignerAction( i18n("Register Qt"), QPixmap(), i18n("&Register Qt..."), 0, this, 0 );
 
1005
    actionHelpRegister->setStatusTip( i18n("Opens a web browser at the evaluation form on www.trolltech.com") );
 
1006
    actionHelpRegister->setWhatsThis( i18n("Register with Trolltech") );
 
1007
    connect( actionHelpRegister, SIGNAL( activated() ), this, SLOT( helpRegister() ) );
 
1008
#endif
 
1009
 
 
1010
    actionHelpWhatsThis = new DesignerAction( i18n("What's This?"), QIconSet( whatsthis_image, whatsthis_image ),
 
1011
                                       i18n("What's This?"), SHIFT + Key_F1, this, 0 );
 
1012
    actionHelpWhatsThis->setStatusTip( i18n("\"What's This?\" context sensitive help") );
 
1013
    actionHelpWhatsThis->setWhatsThis( whatsThisFrom( "Help|What's This?" ) );
 
1014
    connect( actionHelpWhatsThis, SIGNAL( activated() ), this, SLOT( whatsThis() ) );
 
1015
 
 
1016
/*    QToolBar *tb = new QToolBar( this, "Help" );
 
1017
    tb->setCloseMode( QDockWindow::Undocked );
 
1018
    QWhatsThis::add( tb, i18n( "<b>The Help toolbar</b>%1" ).arg(i18n(toolbarHelp).arg("") ));
 
1019
    addToolBar( tb, i18n( "Help" ) );
 
1020
    actionHelpWhatsThis->addTo( tb );*/
 
1021
 
 
1022
    QPopupMenu *menu = new QPopupMenu( this, "Help" );
 
1023
    menubar->insertSeparator();
 
1024
    menubar->insertItem( i18n( "&Help" ), menu );
 
1025
    actionHelpContents->addTo( menu );
 
1026
    actionHelpManual->addTo( menu );
 
1027
    menu->insertSeparator();
 
1028
    actionHelpAbout->addTo( menu );
 
1029
    actionHelpAboutQt->addTo( menu );
 
1030
#if 0 //defined(QT_NON_COMMERCIAL)
 
1031
    // ### not used anymore -- should be deleted?
 
1032
    actionHelpRegister->addTo( menu );
 
1033
#endif
 
1034
 
 
1035
    menu->insertSeparator();
 
1036
    actionHelpWhatsThis->addTo( menu );
 
1037
}
 
1038
 
 
1039
void MainWindow::fileNew()
 
1040
{
 
1041
    statusMessage( i18n( "Create a new project, form or source file...") );
 
1042
    NewForm dlg( this, projectNames(), currentProject->projectName(), templatePath() );
 
1043
    dlg.exec();
 
1044
    statusBar()->clear();
 
1045
}
 
1046
 
 
1047
void MainWindow::fileNewDialog()
 
1048
{
 
1049
    static int forms = 0;
 
1050
    QString n = "Dialog" + QString::number( ++forms );
 
1051
    while ( currentProject->findFormFile( n + ".ui" ) )
 
1052
        n = "Dialog" + QString::number( ++forms );
 
1053
    FormWindow *fw = 0;
 
1054
    FormFile *ff = new FormFile( n + ".ui", FALSE, currentProject );
 
1055
    fw = new FormWindow( ff, MainWindow::self, MainWindow::self->qWorkspace(), n );
 
1056
    ff->setModified( TRUE );
 
1057
    currentProject->setModified( TRUE );
 
1058
    workspace()->update();
 
1059
    fw->setProject( currentProject );
 
1060
    MetaDataBase::addEntry( fw );
 
1061
    QWidget *w = WidgetFactory::create( WidgetDatabase::idFromClassName( "QDialog" ), fw, n.latin1() );
 
1062
    fw->setMainContainer( w );
 
1063
    fw->setCaption( n );
 
1064
    fw->resize( 600, 480 );
 
1065
    insertFormWindow( fw );
 
1066
    fw->killAccels( fw );
 
1067
    fw->project()->setModified( TRUE );
 
1068
    fw->setFocus();
 
1069
    fw->setSavePixmapInProject( TRUE );
 
1070
    fw->setSavePixmapInline( FALSE );
 
1071
}
 
1072
 
 
1073
void MainWindow::fileNewFile()
 
1074
{
 
1075
    QString name = QInputDialog::getText( i18n( "Name of File" ), i18n( "Enter the name of the new source file:" ) );
 
1076
    if ( name.isEmpty() )
 
1077
        return;
 
1078
    if ( name.right( 3 ) != ".qs" )
 
1079
        name += ".qs";
 
1080
    SourceFile *f = new SourceFile( name, FALSE, currentProject );
 
1081
    MainWindow::self->editSource( f );
 
1082
    f->setModified( TRUE );
 
1083
    currentProject->setModified( TRUE );
 
1084
    workspace()->update();
 
1085
}
 
1086
 
 
1087
void MainWindow::fileQuit()
 
1088
{
 
1089
    close();
 
1090
    if ( !singleProjectMode() )
 
1091
        qApp->closeAllWindows();
 
1092
}
 
1093
 
 
1094
void MainWindow::fileClose()
 
1095
{
 
1096
    if ( !currentProject->isDummy() ) {
 
1097
        fileCloseProject();
 
1098
    } else {
 
1099
        QWidget *w = qworkspace->activeWindow();
 
1100
        if ( w ) {
 
1101
            if ( ::qt_cast<FormWindow*>(w) )
 
1102
                ( (FormWindow*)w )->formFile()->close();
 
1103
            else if ( ::qt_cast<SourceEditor*>(w) )
 
1104
                ( (SourceEditor*)w )->close();
 
1105
        }
 
1106
    }
 
1107
}
 
1108
 
 
1109
 
 
1110
void MainWindow::fileCloseProject()
 
1111
{
 
1112
    if ( currentProject->isDummy() )
 
1113
        return;
 
1114
    Project *pro = currentProject;
 
1115
    QAction* a = 0;
 
1116
    QAction* lastValid = 0;
 
1117
    for ( QMap<QAction*, Project* >::Iterator it = projects.begin(); it != projects.end(); ++it ) {
 
1118
        if ( it.data() == pro ) {
 
1119
            a = it.key();
 
1120
            if ( lastValid )
 
1121
                break;
 
1122
        }
 
1123
        lastValid = it.key();
 
1124
    }
 
1125
    if ( a ) {
 
1126
        if ( pro->isModified() ) {
 
1127
            switch ( QMessageBox::warning( this, i18n( "Save Project Settings" ),
 
1128
                                           i18n( "Save changes to '%1'?" ).arg( pro->fileName() ),
 
1129
                                           i18n( "&Yes" ), i18n( "&No" ), i18n( "&Cancel" ), 0, 2 ) ) {
 
1130
            case 0: // save
 
1131
                pro->save();
 
1132
                break;
 
1133
            case 1: // don't save
 
1134
                break;
 
1135
            case 2: // cancel
 
1136
                return;
 
1137
            default:
 
1138
                break;
 
1139
            }
 
1140
        }
 
1141
 
 
1142
        QWidgetList windows = qWorkspace()->windowList();
 
1143
        qWorkspace()->blockSignals( TRUE );
 
1144
        QWidgetListIt wit( windows );
 
1145
        while ( wit.current() ) {
 
1146
            QWidget *w = wit.current();
 
1147
            ++wit;
 
1148
            if ( ::qt_cast<FormWindow*>(w) ) {
 
1149
                if ( ( (FormWindow*)w )->project() == pro ) {
 
1150
                    if ( ( (FormWindow*)w )->formFile()->editor() )
 
1151
                        windows.removeRef( ( (FormWindow*)w )->formFile()->editor() );
 
1152
                    if ( !( (FormWindow*)w )->formFile()->close() )
 
1153
                        return;
 
1154
                }
 
1155
            } else if ( ::qt_cast<SourceEditor*>(w) ) {
 
1156
                if ( !( (SourceEditor*)w )->close() )
 
1157
                    return;
 
1158
            }
 
1159
        }
 
1160
        hierarchyView->clear();
 
1161
        windows = qWorkspace()->windowList();
 
1162
        qWorkspace()->blockSignals( FALSE );
 
1163
        actionGroupProjects->removeChild( a );
 
1164
        projects.remove( a );
 
1165
        delete a;
 
1166
        currentProject = 0;
 
1167
        if ( lastValid ) {
 
1168
            projectSelected( lastValid );
 
1169
            statusMessage( i18n( "Selected project '%1'" ).arg( currentProject->projectName() ) );
 
1170
        }
 
1171
        if ( !windows.isEmpty() ) {
 
1172
            for ( QWidget *w = windows.first(); w; w = windows.next() ) {
 
1173
                if ( !::qt_cast<FormWindow*>(w) )
 
1174
                    continue;
 
1175
                w->setFocus();
 
1176
                activeWindowChanged( w );
 
1177
                break;
 
1178
            }
 
1179
        } else {
 
1180
            emit hasActiveWindow( FALSE );
 
1181
            emit hasActiveForm( FALSE );
 
1182
            updateUndoRedo( FALSE, FALSE, QString::null, QString::null );
 
1183
        }
 
1184
    }
 
1185
}
 
1186
 
 
1187
void MainWindow::fileOpen() // as called by the menu
 
1188
{
 
1189
    fileOpen( "", "", "", FALSE );
 
1190
}
 
1191
 
 
1192
void MainWindow::projectInsertFile()
 
1193
{
 
1194
    fileOpen( "", "" );
 
1195
}
 
1196
 
 
1197
void MainWindow::fileOpen( const QString &filter, const QString &extension, const QString &fn, bool inProject  )
 
1198
{
 
1199
    statusMessage( i18n( "Open a file...") );
 
1200
 
 
1201
    QPluginManager<ImportFilterInterface> manager( IID_ImportFilter, QApplication::libraryPaths(), pluginDirectory() );
 
1202
 
 
1203
    Project* project = inProject ? currentProject : eProject;
 
1204
 
 
1205
    QStringList additionalSources;
 
1206
 
 
1207
    {
 
1208
        QStringList filterlist;
 
1209
        if ( filter.isEmpty() ) {
 
1210
            if ( !inProject )
 
1211
                filterlist << i18n( "*.ui *.pro|Designer Files" );
 
1212
            filterlist << i18n( "*.ui|Qt User-Interface Files" );
 
1213
            if ( !inProject )
 
1214
                filterlist << i18n( "*.pro|QMAKE Project Files" );
 
1215
            QStringList list = manager.featureList();
 
1216
            for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
 
1217
                filterlist << *it;
 
1218
            LanguageInterface *iface = MetaDataBase::languageInterface( project->language() );
 
1219
            if ( iface ) {
 
1220
                filterlist +=  iface->fileFilterList();
 
1221
                additionalSources += iface->fileExtensionList();
 
1222
            }
 
1223
            filterlist << i18n( "*|All Files" );
 
1224
        } else {
 
1225
            filterlist << filter;
 
1226
        }
 
1227
 
 
1228
        QString filters = filterlist.join( "\n" );
 
1229
 
 
1230
        QStringList filenames;
 
1231
        if ( fn.isEmpty() ) {
 
1232
            if ( !inProject ) {
 
1233
                QString f = KFileDialog::getOpenFileName( QString::null, filters, this, /*0,*/
 
1234
                                                          i18n("Open" )/*, &lastOpenFilter */);
 
1235
                filenames << f;
 
1236
            } else {
 
1237
                filenames = KFileDialog::getOpenFileNames( QString::null, filters, this, /*0,*/
 
1238
                                                           i18n("Add")/*, &lastOpenFilter */);
 
1239
            }
 
1240
        } else {
 
1241
            filenames << fn;
 
1242
        }
 
1243
 
 
1244
        for ( QStringList::Iterator fit = filenames.begin(); fit != filenames.end(); ++fit ) {
 
1245
            QString filename = *fit;
 
1246
            if ( !filename.isEmpty() ) {
 
1247
                QFileInfo fi( filename );
 
1248
 
 
1249
                if ( fi.extension( FALSE ) == "pro" && ( extension.isEmpty() || extension.find( ";pro" ) != -1 ) ) {
 
1250
                    addRecentlyOpened( filename, recentlyProjects );
 
1251
                    openProject( filename );
 
1252
                } else if ( fi.extension( FALSE ) == "ui" && ( extension.isEmpty() || extension.find( ";ui" ) != -1 ) ) {
 
1253
                    if ( !inProject )
 
1254
                        setCurrentProject( eProject );
 
1255
                    openFormWindow( filename );
 
1256
                    addRecentlyOpened( filename, recentlyFiles );
 
1257
                } else if ( !extension.isEmpty() && extension.find( ";" + fi.extension( FALSE ) ) != -1 ||
 
1258
                            additionalSources.find( fi.extension( FALSE ) ) != additionalSources.end() ) {
 
1259
                    SourceFile *sf = project->findSourceFile( project->makeRelative( filename ) );
 
1260
                    if ( !sf )
 
1261
                        sf = new SourceFile( project->makeRelative( filename ), FALSE, project );
 
1262
                    editSource( sf );
 
1263
                } else if ( extension.isEmpty() ) {
 
1264
                    QString filter;
 
1265
                    for ( QStringList::Iterator it2 = filterlist.begin(); it2 != filterlist.end(); ++it2 ) {
 
1266
                        if ( (*it2).contains( "." + fi.extension( FALSE ), FALSE ) ) {
 
1267
                            filter = *it2;
 
1268
                            break;
 
1269
                        }
 
1270
                    }
 
1271
 
 
1272
                    ImportFilterInterface* iface = 0;
 
1273
                    manager.queryInterface( filter, &iface );
 
1274
                    if ( !iface ) {
 
1275
                        statusMessage( i18n( "No import filter is available to import '%1'").
 
1276
                                              arg( filename )/*, 3000*/ );
 
1277
                        return;
 
1278
                    }
 
1279
                    statusMessage( i18n( "Importing '%1' using import filter ...").arg( filename ) );
 
1280
                    QStringList list = iface->import( filter, filename );
 
1281
                    iface->release();
 
1282
                    if ( list.isEmpty() ) {
 
1283
                        statusMessage( i18n( "Nothing to load in '%1'").arg( filename )/*, 3000*/ );
 
1284
                        return;
 
1285
                    }
 
1286
                    if ( !inProject )
 
1287
                        setCurrentProject( eProject );
 
1288
                    addRecentlyOpened( filename, recentlyFiles );
 
1289
                    for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
 
1290
                        openFormWindow( *it, FALSE );
 
1291
                        QFile::remove( *it );
 
1292
                    }
 
1293
                    statusBar()->clear();
 
1294
                }
 
1295
            }
 
1296
        }
 
1297
    }
 
1298
}
 
1299
 
 
1300
FormWindow *MainWindow::openFormWindow( const QString &filename, bool validFileName, FormFile *ff )
 
1301
{
 
1302
    if ( filename.isEmpty() )
 
1303
        return 0;
 
1304
 
 
1305
    bool makeNew = FALSE;
 
1306
 
 
1307
    if ( !QFile::exists( filename ) ) {
 
1308
        makeNew = TRUE;
 
1309
    } else {
 
1310
        QFile f( filename );
 
1311
        f.open( IO_ReadOnly );
 
1312
        QTextStream ts( &f );
 
1313
        makeNew = ts.read().length() < 2;
 
1314
    }
 
1315
    if ( makeNew ) {
 
1316
        fileNew();
 
1317
        if ( formWindow() )
 
1318
            formWindow()->setFileName( filename );
 
1319
        return formWindow();
 
1320
    }
 
1321
 
 
1322
    statusMessage( i18n( "Reading file '%1'...").arg( filename ) );
 
1323
    FormFile *ff2 = currentProject->findFormFile( currentProject->makeRelative(filename) );
 
1324
    if ( ff2 && ff2->formWindow() ) {
 
1325
        ff2->formWindow()->setFocus();
 
1326
        return ff2->formWindow();
 
1327
    }
 
1328
 
 
1329
    if ( ff2 )
 
1330
        ff = ff2;
 
1331
    QApplication::setOverrideCursor( WaitCursor );
 
1332
    Resource resource( this );
 
1333
    if ( !ff )
 
1334
        ff = new FormFile( currentProject->makeRelative( filename ), FALSE, currentProject );
 
1335
    bool b = resource.load( ff ) && (FormWindow*)resource.widget();
 
1336
    if ( !validFileName && resource.widget() )
 
1337
        ( (FormWindow*)resource.widget() )->setFileName( QString::null );
 
1338
    QApplication::restoreOverrideCursor();
 
1339
    if ( b ) {
 
1340
        rebuildCustomWidgetGUI();
 
1341
        statusMessage( i18n( "Loaded file '%1'").arg( filename )/*, 3000 */);
 
1342
    } else {
 
1343
        statusMessage( i18n( "Failed to load file '%1'").arg( filename )/*, 5000 */);
 
1344
        QMessageBox::information( this, i18n("Load File"), i18n("Could not load file '%1'.").arg( filename ) );
 
1345
        delete ff;
 
1346
    }
 
1347
    return (FormWindow*)resource.widget();
 
1348
}
 
1349
 
 
1350
bool MainWindow::fileSave()
 
1351
{
 
1352
 
 
1353
    if ( !currentProject->isDummy() )
 
1354
        return fileSaveProject();
 
1355
    return fileSaveForm();
 
1356
}
 
1357
 
 
1358
bool MainWindow::fileSaveForm()
 
1359
{
 
1360
    for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() ) {
 
1361
        if ( e->object() == formWindow() || e == qWorkspace()->activeWindow() ) {
 
1362
            e->save();
 
1363
        }
 
1364
    }
 
1365
 
 
1366
    FormWindow *fw = 0;
 
1367
 
 
1368
    QWidget *w = qWorkspace()->activeWindow();
 
1369
    if ( w ) {
 
1370
        if ( ::qt_cast<SourceEditor*>(w) ) {
 
1371
            SourceEditor *se = (SourceEditor*)w;
 
1372
            if ( se->formWindow() )
 
1373
                fw = se->formWindow();
 
1374
            else if ( se->sourceFile() ) {
 
1375
                se->sourceFile()->save();
 
1376
                return TRUE;
 
1377
            }
 
1378
        }
 
1379
    }
 
1380
 
 
1381
    if ( !fw )
 
1382
        fw = formWindow();
 
1383
    if ( !fw || !fw->formFile()->save() )
 
1384
        return FALSE;
 
1385
    QApplication::restoreOverrideCursor();
 
1386
    return TRUE;
 
1387
}
 
1388
 
 
1389
bool MainWindow::fileSaveProject()
 
1390
{
 
1391
    currentProject->save();
 
1392
    statusMessage( i18n( "Project '%1' saved.").arg( currentProject->projectName() )/*, 3000 */);
 
1393
    return TRUE;
 
1394
}
 
1395
 
 
1396
bool MainWindow::fileSaveAs()
 
1397
{
 
1398
    statusMessage( i18n( "Enter a filename..." ) );
 
1399
 
 
1400
    QWidget *w = qworkspace->activeWindow();
 
1401
    if ( !w )
 
1402
        return TRUE;
 
1403
    if ( ::qt_cast<FormWindow*>(w) )
 
1404
        return ( (FormWindow*)w )->formFile()->saveAs();
 
1405
    else if ( ::qt_cast<SourceEditor*>(w) )
 
1406
        return ( (SourceEditor*)w )->saveAs();
 
1407
    return FALSE;
 
1408
}
 
1409
 
 
1410
void MainWindow::fileSaveAll()
 
1411
{
 
1412
    for ( QMap<QAction*, Project* >::Iterator it = projects.begin(); it != projects.end(); ++it )
 
1413
        (*it)->save();
 
1414
}
 
1415
 
 
1416
void MainWindow::fileCreateTemplate()
 
1417
{
 
1418
    CreateTemplate dia( this, 0, TRUE );
 
1419
 
 
1420
    int i = 0;
 
1421
    for ( i = 0; i < WidgetDatabase::count(); ++i ) {
 
1422
        if ( WidgetDatabase::isForm( i ) && WidgetDatabase::group( i ) != "Temp") {
 
1423
            dia.listClass->insertItem( WidgetDatabase::className( i ) );
 
1424
        }
 
1425
    }
 
1426
    for ( i = 0; i < WidgetDatabase::count(); ++i ) {
 
1427
        if ( WidgetDatabase::isContainer( i ) && !WidgetDatabase::isForm(i) &&
 
1428
             WidgetDatabase::className( i ) != "QTabWidget" && WidgetDatabase::group( i ) != "Temp" ) {
 
1429
            dia.listClass->insertItem( WidgetDatabase::className( i ) );
 
1430
        }
 
1431
    }
 
1432
 
 
1433
    QPtrList<MetaDataBase::CustomWidget> *lst = MetaDataBase::customWidgets();
 
1434
    for ( MetaDataBase::CustomWidget *w = lst->first(); w; w = lst->next() ) {
 
1435
        if ( w->isContainer )
 
1436
            dia.listClass->insertItem( w->className );
 
1437
    }
 
1438
 
 
1439
    dia.editName->setText( i18n( "NewTemplate" ) );
 
1440
    connect( dia.buttonCreate, SIGNAL( clicked() ),
 
1441
             this, SLOT( createNewTemplate() ) );
 
1442
    dia.exec();
 
1443
}
 
1444
 
 
1445
void MainWindow::createNewTemplate()
 
1446
{
 
1447
    CreateTemplate *dia = (CreateTemplate*)sender()->parent();
 
1448
    QString fn = dia->editName->text();
 
1449
    QString cn = dia->listClass->currentText();
 
1450
    if ( fn.isEmpty() || cn.isEmpty() ) {
 
1451
        QMessageBox::information( this, i18n( "Create Template" ), i18n( "Could not create the template." ) );
 
1452
        return;
 
1453
    }
 
1454
 
 
1455
    QStringList templRoots;
 
1456
    const char *qtdir = getenv( "QTDIR" );
 
1457
    if(qtdir)
 
1458
        templRoots << qtdir;
 
1459
    templRoots << qInstallPathData();
 
1460
    if(qtdir) //try the tools/designer directory last!
 
1461
        templRoots << (QString(qtdir) + "/tools/designer");
 
1462
    QFile f;
 
1463
    for ( QStringList::Iterator it = templRoots.begin(); it != templRoots.end(); ++it ) {
 
1464
        if ( QFile::exists( (*it) + "/templates/" )) {
 
1465
            QString tmpfn = (*it) + "/templates/" + fn + ".ui";
 
1466
            f.setName(tmpfn);
 
1467
            if(f.open(IO_WriteOnly))
 
1468
                break;
 
1469
        }
 
1470
    }
 
1471
    if ( !f.isOpen() ) {
 
1472
        QMessageBox::information( this, i18n( "Create Template" ), i18n( "Could not create the template." ) );
 
1473
        return;
 
1474
    }
 
1475
    QTextStream ts( &f );
 
1476
 
 
1477
    ts << "<!DOCTYPE UI><UI>" << endl;
 
1478
    ts << "<widget>" << endl;
 
1479
    ts << "<class>" << cn << "</class>" << endl;
 
1480
    ts << "<property stdset=\"1\">" << endl;
 
1481
    ts << "    <name>name</name>" << endl;
 
1482
    ts << "    <cstring>" << cn << "Form</cstring>" << endl;
 
1483
    ts << "</property>" << endl;
 
1484
    ts << "<property stdset=\"1\">" << endl;
 
1485
    ts << "    <name>geometry</name>" << endl;
 
1486
    ts << "    <rect>" << endl;
 
1487
    ts << "        <width>300</width>" << endl;
 
1488
    ts << "        <height>400</height>" << endl;
 
1489
    ts << "    </rect>" << endl;
 
1490
    ts << "</property>" << endl;
 
1491
    ts << "</widget>" << endl;
 
1492
    ts << "</UI>" << endl;
 
1493
 
 
1494
    dia->editName->setText( i18n( "NewTemplate" ) );
 
1495
 
 
1496
    f.close();
 
1497
}
 
1498
 
 
1499
void MainWindow::editUndo()
 
1500
{
 
1501
    if ( qWorkspace()->activeWindow() &&
 
1502
         ::qt_cast<SourceEditor*>(qWorkspace()->activeWindow()) ) {
 
1503
        ( (SourceEditor*)qWorkspace()->activeWindow() )->editUndo();
 
1504
        return;
 
1505
    }
 
1506
    if ( formWindow() )
 
1507
        formWindow()->undo();
 
1508
}
 
1509
 
 
1510
void MainWindow::editRedo()
 
1511
{
 
1512
    if ( qWorkspace()->activeWindow() &&
 
1513
         ::qt_cast<SourceEditor*>(qWorkspace()->activeWindow()) ) {
 
1514
        ( (SourceEditor*)qWorkspace()->activeWindow() )->editRedo();
 
1515
        return;
 
1516
    }
 
1517
    if ( formWindow() )
 
1518
        formWindow()->redo();
 
1519
}
 
1520
 
 
1521
void MainWindow::editCut()
 
1522
{
 
1523
    if ( qWorkspace()->activeWindow() &&
 
1524
         ::qt_cast<SourceEditor*>(qWorkspace()->activeWindow()) ) {
 
1525
        ( (SourceEditor*)qWorkspace()->activeWindow() )->editCut();
 
1526
        return;
 
1527
    }
 
1528
    editCopy();
 
1529
    editDelete();
 
1530
}
 
1531
 
 
1532
void MainWindow::editCopy()
 
1533
{
 
1534
    if ( qWorkspace()->activeWindow() &&
 
1535
         ::qt_cast<SourceEditor*>(qWorkspace()->activeWindow()) ) {
 
1536
        ( (SourceEditor*)qWorkspace()->activeWindow() )->editCopy();
 
1537
        return;
 
1538
    }
 
1539
    if ( formWindow() )
 
1540
        qApp->clipboard()->setText( formWindow()->copy() );
 
1541
}
 
1542
 
 
1543
void MainWindow::editPaste()
 
1544
{
 
1545
    if ( qWorkspace()->activeWindow() &&
 
1546
         ::qt_cast<SourceEditor*>(qWorkspace()->activeWindow()) ) {
 
1547
        ( (SourceEditor*)qWorkspace()->activeWindow() )->editPaste();
 
1548
        return;
 
1549
    }
 
1550
    if ( !formWindow() )
 
1551
        return;
 
1552
 
 
1553
    QWidget *w = formWindow()->mainContainer();
 
1554
    QWidgetList l( formWindow()->selectedWidgets() );
 
1555
    if ( l.count() == 1 ) {
 
1556
        w = l.first();
 
1557
        if ( WidgetFactory::layoutType( w ) != WidgetFactory::NoLayout ||
 
1558
             ( !WidgetDatabase::isContainer( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( w ) ) ) &&
 
1559
               w != formWindow()->mainContainer() ) )
 
1560
            w = formWindow()->mainContainer();
 
1561
    }
 
1562
 
 
1563
    if ( w && WidgetFactory::layoutType( w ) == WidgetFactory::NoLayout ) {
 
1564
        formWindow()->paste( qApp->clipboard()->text(), WidgetFactory::containerOfWidget( w ) );
 
1565
        hierarchyView->widgetInserted( 0 );
 
1566
        formWindow()->commandHistory()->setModified( TRUE );
 
1567
    } else {
 
1568
        QMessageBox::information( this, i18n( "Paste Error" ),
 
1569
                                  i18n( "Cannot paste widgets. Designer could not find a container\n"
 
1570
                                      "to paste into which does not contain a layout. Break the layout\n"
 
1571
                                      "of the container you want to paste into and select this container\n"
 
1572
                                      "and then paste again." ) );
 
1573
    }
 
1574
}
 
1575
 
 
1576
void MainWindow::editDelete()
 
1577
{
 
1578
    if ( formWindow() )
 
1579
        formWindow()->deleteWidgets();
 
1580
}
 
1581
 
 
1582
void MainWindow::editSelectAll()
 
1583
{
 
1584
    if ( qWorkspace()->activeWindow() &&
 
1585
         ::qt_cast<SourceEditor*>(qWorkspace()->activeWindow()) ) {
 
1586
        ( (SourceEditor*)qWorkspace()->activeWindow() )->editSelectAll();
 
1587
        return;
 
1588
    }
 
1589
    if ( formWindow() )
 
1590
        formWindow()->selectAll();
 
1591
}
 
1592
 
 
1593
 
 
1594
void MainWindow::editLower()
 
1595
{
 
1596
    if ( formWindow() )
 
1597
        formWindow()->lowerWidgets();
 
1598
}
 
1599
 
 
1600
void MainWindow::editRaise()
 
1601
{
 
1602
    if ( formWindow() )
 
1603
        formWindow()->raiseWidgets();
 
1604
}
 
1605
 
 
1606
void MainWindow::editAdjustSize()
 
1607
{
 
1608
    if ( formWindow() )
 
1609
        formWindow()->editAdjustSize();
 
1610
}
 
1611
 
 
1612
void MainWindow::editLayoutHorizontal()
 
1613
{
 
1614
    if ( layoutChilds )
 
1615
        editLayoutContainerHorizontal();
 
1616
    else if ( layoutSelected && formWindow() )
 
1617
        formWindow()->layoutHorizontal();
 
1618
}
 
1619
 
 
1620
void MainWindow::editLayoutVertical()
 
1621
{
 
1622
    if ( layoutChilds )
 
1623
        editLayoutContainerVertical();
 
1624
    else if ( layoutSelected && formWindow() )
 
1625
        formWindow()->layoutVertical();
 
1626
}
 
1627
 
 
1628
void MainWindow::editLayoutHorizontalSplit()
 
1629
{
 
1630
    if ( layoutChilds )
 
1631
        ; // no way to do that
 
1632
    else if ( layoutSelected && formWindow() )
 
1633
        formWindow()->layoutHorizontalSplit();
 
1634
}
 
1635
 
 
1636
void MainWindow::editLayoutVerticalSplit()
 
1637
{
 
1638
    if ( layoutChilds )
 
1639
        ; // no way to do that
 
1640
    else if ( layoutSelected && formWindow() )
 
1641
        formWindow()->layoutVerticalSplit();
 
1642
}
 
1643
 
 
1644
void MainWindow::editLayoutGrid()
 
1645
{
 
1646
    if ( layoutChilds )
 
1647
        editLayoutContainerGrid();
 
1648
    else if ( layoutSelected && formWindow() )
 
1649
        formWindow()->layoutGrid();
 
1650
}
 
1651
 
 
1652
void MainWindow::editLayoutContainerVertical()
 
1653
{
 
1654
    if ( !formWindow() )
 
1655
        return;
 
1656
    QWidget *w = formWindow()->mainContainer();
 
1657
    QWidgetList l( formWindow()->selectedWidgets() );
 
1658
    if ( l.count() == 1 )
 
1659
        w = l.first();
 
1660
    if ( w )
 
1661
        formWindow()->layoutVerticalContainer( w  );
 
1662
}
 
1663
 
 
1664
void MainWindow::editLayoutContainerHorizontal()
 
1665
{
 
1666
    if ( !formWindow() )
 
1667
        return;
 
1668
    QWidget *w = formWindow()->mainContainer();
 
1669
    QWidgetList l( formWindow()->selectedWidgets() );
 
1670
    if ( l.count() == 1 )
 
1671
        w = l.first();
 
1672
    if ( w )
 
1673
        formWindow()->layoutHorizontalContainer( w );
 
1674
}
 
1675
 
 
1676
void MainWindow::editLayoutContainerGrid()
 
1677
{
 
1678
    if ( !formWindow() )
 
1679
        return;
 
1680
    QWidget *w = formWindow()->mainContainer();
 
1681
    QWidgetList l( formWindow()->selectedWidgets() );
 
1682
    if ( l.count() == 1 )
 
1683
        w = l.first();
 
1684
    if ( w )
 
1685
        formWindow()->layoutGridContainer( w  );
 
1686
}
 
1687
 
 
1688
void MainWindow::editBreakLayout()
 
1689
{
 
1690
    if ( !formWindow() || !breakLayout )
 
1691
        return;
 
1692
    QWidget *w = formWindow()->mainContainer();
 
1693
    if ( formWindow()->currentWidget() )
 
1694
        w = formWindow()->currentWidget();
 
1695
    if ( WidgetFactory::layoutType( w ) != WidgetFactory::NoLayout ||
 
1696
         w->parentWidget() && WidgetFactory::layoutType( w->parentWidget() ) != WidgetFactory::NoLayout ) {
 
1697
        formWindow()->breakLayout( w );
 
1698
        return;
 
1699
    } else {
 
1700
        QWidgetList widgets = formWindow()->selectedWidgets();
 
1701
        for ( w = widgets.first(); w; w = widgets.next() ) {
 
1702
            if ( WidgetFactory::layoutType( w ) != WidgetFactory::NoLayout ||
 
1703
                 w->parentWidget() && WidgetFactory::layoutType( w->parentWidget() ) != WidgetFactory::NoLayout )
 
1704
                break;
 
1705
        }
 
1706
        if ( w ) {
 
1707
            formWindow()->breakLayout( w );
 
1708
            return;
 
1709
        }
 
1710
    }
 
1711
 
 
1712
    w = formWindow()->mainContainer();
 
1713
    if ( WidgetFactory::layoutType( w ) != WidgetFactory::NoLayout ||
 
1714
         w->parentWidget() && WidgetFactory::layoutType( w->parentWidget() ) != WidgetFactory::NoLayout )
 
1715
        formWindow()->breakLayout( w );
 
1716
}
 
1717
 
 
1718
void MainWindow::editAccels()
 
1719
{
 
1720
    if ( !formWindow() )
 
1721
        return;
 
1722
    formWindow()->checkAccels();
 
1723
}
 
1724
 
 
1725
void MainWindow::editFunctions()
 
1726
{
 
1727
    if ( !formWindow() )
 
1728
        return;
 
1729
 
 
1730
    statusMessage( i18n( "Edit the current form's slots..." ) );
 
1731
    EditFunctions dlg( this, formWindow(), TRUE );
 
1732
    dlg.exec();
 
1733
    statusBar()->clear();
 
1734
}
 
1735
 
 
1736
void MainWindow::editConnections()
 
1737
{
 
1738
    if ( !formWindow() )
 
1739
        return;
 
1740
 
 
1741
    statusMessage( i18n( "Edit the current form's connections..." ) );
 
1742
    ConnectionDialog dlg( this );
 
1743
    dlg.exec();
 
1744
 
 
1745
    statusBar()->clear();
 
1746
}
 
1747
 
 
1748
SourceEditor *MainWindow::editSource()
 
1749
{
 
1750
    if ( !formWindow() )
 
1751
        return 0;
 
1752
    return formWindow()->formFile()->showEditor();
 
1753
}
 
1754
 
 
1755
SourceEditor *MainWindow::openSourceEditor()
 
1756
{
 
1757
    if ( !formWindow() )
 
1758
        return 0;
 
1759
 
 
1760
    QString lang = currentProject->language();
 
1761
    if ( !MetaDataBase::hasEditor( lang ) ) {
 
1762
        QMessageBox::information( this, i18n( "Edit Source" ),
 
1763
                                  i18n( "There is no plugin for editing %1 code installed.\n"
 
1764
                                      "Note: Plugins are not available in static Qt configurations." ).arg( lang ) );
 
1765
        return 0;
 
1766
    }
 
1767
 
 
1768
    SourceEditor *editor = 0;
 
1769
    for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() ) {
 
1770
        if ( e->language() == lang && e->formWindow() == formWindow() ) {
 
1771
            editor = e;
 
1772
            break;
 
1773
        }
 
1774
    }
 
1775
 
 
1776
    if ( !editor )
 
1777
        editor = createSourceEditor( formWindow(), formWindow()->project(), lang );
 
1778
    return editor;
 
1779
}
 
1780
 
 
1781
SourceEditor *MainWindow::editSource( SourceFile *f )
 
1782
{
 
1783
    QString lang = currentProject->language();
 
1784
    if ( !MetaDataBase::hasEditor( lang ) ) {
 
1785
        QMessageBox::information( this, i18n( "Edit Source" ),
 
1786
                                  i18n( "There is no plugin for editing %1 code installed.\n"
 
1787
                                      "Note: Plugins are not available in static Qt configurations." ).arg( lang ) );
 
1788
        return 0;
 
1789
    }
 
1790
 
 
1791
    SourceEditor *editor = 0;
 
1792
    if ( f )
 
1793
        editor = f->editor();
 
1794
    if ( !editor )
 
1795
        editor = createSourceEditor( f, currentProject, lang );
 
1796
    editor->setActiveWindow();
 
1797
    editor->setFocus();
 
1798
    return editor;
 
1799
}
 
1800
 
 
1801
SourceEditor *MainWindow::createSourceEditor( QObject *object, Project *project,
 
1802
                                              const QString &lang, const QString &func,
 
1803
                                              bool rereadSource )
 
1804
{
 
1805
    SourceEditor *editor = 0;
 
1806
    EditorInterface *eIface = 0;
 
1807
    editorPluginManager->queryInterface( lang, &eIface );
 
1808
    if ( !eIface )
 
1809
        return 0;
 
1810
    LanguageInterface *lIface = MetaDataBase::languageInterface( lang );
 
1811
    if ( !lIface )
 
1812
        return 0;
 
1813
    QApplication::setOverrideCursor( WaitCursor );
 
1814
    editor = new SourceEditor( qWorkspace(), eIface, lIface );
 
1815
    eIface->release();
 
1816
    lIface->release();
 
1817
 
 
1818
    editor->setLanguage( lang );
 
1819
    sourceEditors.append( editor );
 
1820
    QApplication::restoreOverrideCursor();
 
1821
 
 
1822
    if ( editor->object() != object )
 
1823
        editor->setObject( object, project );
 
1824
    else if ( rereadSource )
 
1825
        editor->refresh( FALSE );
 
1826
 
 
1827
    editor->show();
 
1828
    editor->setFocus();
 
1829
    if ( !func.isEmpty() )
 
1830
        editor->setFunction( func );
 
1831
    emit editorChanged();
 
1832
 
 
1833
    return editor;
 
1834
}
 
1835
 
 
1836
void MainWindow::editFormSettings()
 
1837
{
 
1838
    if ( !formWindow() )
 
1839
        return;
 
1840
 
 
1841
    statusMessage( i18n( "Edit the current form's settings..." ) );
 
1842
    FormSettings dlg( this, formWindow() );
 
1843
    dlg.exec();
 
1844
    statusBar()->clear();
 
1845
}
 
1846
 
 
1847
void MainWindow::editProjectSettings()
 
1848
{
 
1849
    openProjectSettings( currentProject );
 
1850
    wspace->setCurrentProject( currentProject );
 
1851
}
 
1852
 
 
1853
void MainWindow::editPixmapCollection()
 
1854
{
 
1855
    PixmapCollectionEditor dia( this, 0, TRUE );
 
1856
    dia.setProject( currentProject );
 
1857
    dia.exec();
 
1858
}
 
1859
 
 
1860
void MainWindow::editDatabaseConnections()
 
1861
{
 
1862
#ifndef QT_NO_SQL
 
1863
    DatabaseConnectionsEditor dia( currentProject, this, 0, TRUE );
 
1864
    dia.exec();
 
1865
#endif
 
1866
}
 
1867
 
 
1868
void MainWindow::editPreferences()
 
1869
{
 
1870
    statusMessage( i18n( "Edit preferences..." ) );
 
1871
    Preferences *dia = new Preferences( this, 0, TRUE );
 
1872
    prefDia = dia;
 
1873
    connect( dia->helpButton, SIGNAL( clicked() ), MainWindow::self, SLOT( showDialogHelp() ) );
 
1874
    dia->buttonColor->setEditor( StyledButton::ColorEditor );
 
1875
    dia->buttonPixmap->setEditor( StyledButton::PixmapEditor );
 
1876
    dia->groupBoxGrid->setChecked( sGrid );
 
1877
    dia->checkBoxSnapGrid->setChecked( snGrid );
 
1878
    dia->spinGridX->setValue( grid().x() );
 
1879
    dia->spinGridY->setValue( grid().y() );
 
1880
    dia->checkBoxWorkspace->setChecked( restoreConfig );
 
1881
    dia->checkBoxTextLabels->setChecked( usesTextLabel() );
 
1882
    dia->buttonColor->setColor( qworkspace->backgroundColor() );
 
1883
    QString pluginPaths = QApplication::libraryPaths().join("\n");
 
1884
    dia->textEditPluginPaths->setText(pluginPaths);
 
1885
    if ( qworkspace->backgroundPixmap() )
 
1886
        dia->buttonPixmap->setPixmap( *qworkspace->backgroundPixmap() );
 
1887
    if ( backPix )
 
1888
        dia->radioPixmap->setChecked( TRUE );
 
1889
    else
 
1890
        dia->radioColor->setChecked( TRUE );
 
1891
    dia->checkBoxSplash->setChecked( splashScreen );
 
1892
    dia->checkAutoEdit->setChecked( !databaseAutoEdit );
 
1893
    dia->checkBoxStartDialog->setChecked( shStartDialog );
 
1894
    dia->checkBoxAutoSave->setChecked( autoSaveEnabled );
 
1895
    int h = autoSaveInterval / 3600;
 
1896
    int m = ( autoSaveInterval - h * 3600 ) / 60;
 
1897
    int s = autoSaveInterval - ( h * 3600 + m * 60 );
 
1898
    QTime t( h, m, s );
 
1899
    dia->timeEditAutoSave->setTime( t );
 
1900
 
 
1901
    SenderObject *senderObject = new SenderObject( designerInterface() );
 
1902
    QValueList<Tab>::Iterator it;
 
1903
    for ( it = preferenceTabs.begin(); it != preferenceTabs.end(); ++it ) {
 
1904
        Tab t = *it;
 
1905
        dia->tabWidget->addTab( t.w, t.title );
 
1906
        if ( t.receiver ) {
 
1907
            connect( dia->buttonOk, SIGNAL( clicked() ), senderObject, SLOT( emitAcceptSignal() ) );
 
1908
            connect( senderObject, SIGNAL( acceptSignal( QUnknownInterface * ) ), t.receiver, t.accept_slot );
 
1909
            connect( senderObject, SIGNAL( initSignal( QUnknownInterface * ) ), t.receiver, t.init_slot );
 
1910
            senderObject->emitInitSignal();
 
1911
            disconnect( senderObject, SIGNAL( initSignal( QUnknownInterface * ) ), t.receiver, t.init_slot );
 
1912
        }
 
1913
    }
 
1914
 
 
1915
    if ( dia->exec() == QDialog::Accepted ) {
 
1916
        setSnapGrid( dia->checkBoxSnapGrid->isChecked() );
 
1917
        setShowGrid( dia->groupBoxGrid->isChecked() );
 
1918
        setGrid( QPoint( dia->spinGridX->value(),
 
1919
                         dia->spinGridY->value() ) );
 
1920
        restoreConfig = dia->checkBoxWorkspace->isChecked();
 
1921
        setUsesTextLabel( dia->checkBoxTextLabels->isChecked() );
 
1922
        if (dia->textEditPluginPaths->isModified()) {
 
1923
            pluginPaths = dia->textEditPluginPaths->text();
 
1924
            QApplication::setLibraryPaths(QStringList::split("\n", pluginPaths));
 
1925
            savePluginPaths = TRUE;
 
1926
        }
 
1927
 
 
1928
        if ( dia->radioPixmap->isChecked() && dia->buttonPixmap->pixmap() ) {
 
1929
            qworkspace->setBackgroundPixmap( *dia->buttonPixmap->pixmap() );
 
1930
            backPix = TRUE;
 
1931
        } else {
 
1932
            qworkspace->setBackgroundColor( dia->buttonColor->color() );
 
1933
            backPix = FALSE;
 
1934
        }
 
1935
        splashScreen = dia->checkBoxSplash->isChecked();
 
1936
        databaseAutoEdit = !dia->checkAutoEdit->isChecked();
 
1937
        shStartDialog = dia->checkBoxStartDialog->isChecked();
 
1938
        autoSaveEnabled = dia->checkBoxAutoSave->isChecked();
 
1939
        QTime time = dia->timeEditAutoSave->time();
 
1940
        autoSaveInterval = time.hour() * 3600 + time.minute() * 60 + time.second();
 
1941
        if ( autoSaveEnabled )
 
1942
            autoSaveTimer->start( autoSaveInterval * 1000 );
 
1943
        else
 
1944
            autoSaveTimer->stop();
 
1945
    }
 
1946
    delete senderObject;
 
1947
    for ( it = preferenceTabs.begin(); it != preferenceTabs.end(); ++it ) {
 
1948
        Tab t = *it;
 
1949
        dia->tabWidget->removePage( t.w );
 
1950
        t.w->reparent( 0, QPoint(0,0), FALSE );
 
1951
    }
 
1952
 
 
1953
    for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() )
 
1954
        e->configChanged();
 
1955
 
 
1956
    delete dia;
 
1957
    prefDia = 0;
 
1958
    statusBar()->clear();
 
1959
}
 
1960
 
 
1961
void MainWindow::searchFind()
 
1962
{
 
1963
    if ( !qWorkspace()->activeWindow() ||
 
1964
         !::qt_cast<SourceEditor*>(qWorkspace()->activeWindow()) )
 
1965
         return;
 
1966
 
 
1967
    if ( !findDialog )
 
1968
        findDialog = new FindDialog( this, 0, FALSE );
 
1969
    findDialog->show();
 
1970
    findDialog->raise();
 
1971
    findDialog->setEditor( ( (SourceEditor*)qWorkspace()->activeWindow() )->editorInterface(),
 
1972
                           ( (SourceEditor*)qWorkspace()->activeWindow() )->object() );
 
1973
    findDialog->comboFind->setFocus();
 
1974
    findDialog->comboFind->lineEdit()->selectAll();
 
1975
}
 
1976
 
 
1977
void MainWindow::searchIncremetalFindMenu()
 
1978
{
 
1979
    incrementalSearch->selectAll();
 
1980
    incrementalSearch->setFocus();
 
1981
}
 
1982
 
 
1983
void MainWindow::searchIncremetalFind()
 
1984
{
 
1985
    if ( !qWorkspace()->activeWindow() ||
 
1986
         !::qt_cast<SourceEditor*>(qWorkspace()->activeWindow()) )
 
1987
         return;
 
1988
 
 
1989
    ( (SourceEditor*)qWorkspace()->activeWindow() )->editorInterface()->find( incrementalSearch->text(),
 
1990
                                                                             FALSE, FALSE, TRUE, FALSE );
 
1991
}
 
1992
 
 
1993
void MainWindow::searchIncremetalFindNext()
 
1994
{
 
1995
    if ( !qWorkspace()->activeWindow() ||
 
1996
         !::qt_cast<SourceEditor*>(qWorkspace()->activeWindow()) )
 
1997
         return;
 
1998
 
 
1999
    ( (SourceEditor*)qWorkspace()->activeWindow() )->editorInterface()->find( incrementalSearch->text(),
 
2000
                                                                             FALSE, FALSE, TRUE, TRUE );
 
2001
}
 
2002
 
 
2003
void MainWindow::searchReplace()
 
2004
{
 
2005
    if ( !qWorkspace()->activeWindow() ||
 
2006
         !::qt_cast<SourceEditor*>(qWorkspace()->activeWindow()) )
 
2007
         return;
 
2008
 
 
2009
    if ( !replaceDialog )
 
2010
        replaceDialog = new ReplaceDialog( this, 0, FALSE );
 
2011
    replaceDialog->show();
 
2012
    replaceDialog->raise();
 
2013
    replaceDialog->setEditor( ( (SourceEditor*)qWorkspace()->activeWindow() )->editorInterface(),
 
2014
                           ( (SourceEditor*)qWorkspace()->activeWindow() )->object() );
 
2015
    replaceDialog->comboFind->setFocus();
 
2016
    replaceDialog->comboFind->lineEdit()->selectAll();
 
2017
}
 
2018
 
 
2019
void MainWindow::searchGotoLine()
 
2020
{
 
2021
    if ( !qWorkspace()->activeWindow() ||
 
2022
         !::qt_cast<SourceEditor*>(qWorkspace()->activeWindow()) )
 
2023
         return;
 
2024
 
 
2025
    if ( !gotoLineDialog )
 
2026
        gotoLineDialog = new GotoLineDialog( this, 0, FALSE );
 
2027
    gotoLineDialog->show();
 
2028
    gotoLineDialog->raise();
 
2029
    gotoLineDialog->setEditor( ( (SourceEditor*)qWorkspace()->activeWindow() )->editorInterface() );
 
2030
    gotoLineDialog->spinLine->setFocus();
 
2031
    gotoLineDialog->spinLine->setMinValue( 1 );
 
2032
    gotoLineDialog->spinLine->setMaxValue( ( (SourceEditor*)qWorkspace()->activeWindow() )->numLines() );
 
2033
    gotoLineDialog->spinLine->selectAll();
 
2034
}
 
2035
 
 
2036
void MainWindow::toolsCustomWidget()
 
2037
{
 
2038
    statusMessage( i18n( "Edit custom widgets..." ) );
 
2039
    CustomWidgetEditor edit( this, this );
 
2040
    edit.exec();
 
2041
    rebuildCustomWidgetGUI();
 
2042
    statusBar()->clear();
 
2043
}
 
2044
 
 
2045
void MainWindow::toolsConfigure()
 
2046
{
 
2047
    ConfigToolboxDialog dlg( this );
 
2048
    if ( dlg.exec() != QDialog::Accepted )
 
2049
        return;
 
2050
    rebuildCommonWidgetsToolBoxPage();
 
2051
}
 
2052
 
 
2053
void MainWindow::showStartDialog()
 
2054
{
 
2055
    if ( singleProjectMode() )
 
2056
        return;
 
2057
    for ( int i = 1; i < qApp->argc(); ++i ) {
 
2058
        QString arg = qApp->argv()[i];
 
2059
        if ( arg[0] != '-' )
 
2060
            return;
 
2061
    }
 
2062
    StartDialog *sd = new StartDialog( this, templatePath() );
 
2063
    sd->setRecentlyFiles( recentlyFiles );
 
2064
    sd->setRecentlyProjects( recentlyProjects );
 
2065
    sd->exec();
 
2066
    shStartDialog = sd->showDialogInFuture();
 
2067
}