1
/**********************************************************************
2
** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
4
** This file is part of Qt Designer.
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.
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.
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.
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.
22
** Contact info@trolltech.com if any conditions of this licensing are
25
**********************************************************************/
27
#include "designerappiface.h"
28
#include "designerapp.h"
30
#include "mainwindow.h"
32
#include "globaldefs.h"
33
#include "formwindow.h"
34
#include "widgetdatabase.h"
35
#include "widgetfactory.h"
36
#include "propertyeditor.h"
37
#include "metadatabase.h"
39
#include "hierarchyview.h"
40
#include "newformimpl.h"
41
#include "workspace.h"
43
#include "multilineeditorimpl.h"
44
#include "wizardeditorimpl.h"
45
#include "outputwindow.h"
46
#include "actioneditorimpl.h"
47
#include "actiondnd.h"
49
#include "projectsettingsimpl.h"
50
#include "qwidgetfactory.h"
51
#include "pixmapcollection.h"
52
#include "qcompletionedit.h"
53
#include "sourcefile.h"
54
#include "orderindicator.h"
56
#include "widgetaction.h"
57
#include "propertyobject.h"
58
#include "popupmenueditor.h"
59
#include "menubareditor.h"
61
#include "startdialog.h"
62
#include "createtemplate.h"
63
#include "editfunctions.h"
64
//#include "connectionviewer.h"
65
#include "formsettings.h"
66
#include "preferences.h"
67
#include "pixmapcollectioneditor.h"
69
#include "dbconnectionimpl.h"
71
//#include "connectioneditor.h"
72
#include "customwidgeteditorimpl.h"
73
#include "paletteeditorimpl.h"
74
#include "listboxeditorimpl.h"
75
#include "listvieweditorimpl.h"
76
#include "iconvieweditorimpl.h"
77
#include "tableeditorimpl.h"
78
#include "multilineeditor.h"
79
#include "finddialog.h"
80
#include "replacedialog.h"
81
#include "gotolinedialog.h"
82
#include "designeraction.h"
84
#include <kiconloader.h>
87
#include <qinputdialog.h>
89
#include <qfeatures.h>
90
#include <qmetaobject.h>
93
#include <qworkspace.h>
94
#include <qfiledialog.h>
95
#include <qclipboard.h>
96
#include <qmessagebox.h>
101
#include <qstatusbar.h>
103
#include <qcheckbox.h>
104
#include <qwhatsthis.h>
107
#include <qlistbox.h>
108
#include <qdockwindow.h>
109
#include <qstylefactory.h>
111
#include <qprocess.h>
112
#include <qsettings.h>
114
#include <qtooltip.h>
115
#include <qsizegrip.h>
116
#include <qtextview.h>
117
#include <qassistantclient.h>
120
#include "kdevdesigner_part.h"
122
static bool mblockNewForms = FALSE;
123
extern QMap<QWidget*, QString> *qwf_forms;
124
extern QString *qwf_language;
125
extern bool qwf_execute_code;
126
extern bool qwf_stays_on_top;
127
extern void set_splash_status( const QString &txt );
128
extern QObject* qwf_form_object;
129
extern QString *qwf_plugin_dir;
131
MainWindow *MainWindow::self = 0;
133
QString assistantPath()
135
QString path = QDir::cleanDirPath( QString( qInstallPathBins() ) +
141
static QString textNoAccel( const QString& text)
145
while ( (i = t.find('&') )>= 0 ) {
152
MainWindow::MainWindow( KDevDesignerPart *part, bool asClient, bool single, const QString &plgDir )
153
: QMainWindow( 0, "designer_mainwindow"/*, WType_TopLevel | (single ? 0 : WDestructiveClose) | WGroupLeader*/ ),
154
grd( 10, 10 ), sGrid( TRUE ), snGrid( TRUE ), restoreConfig( TRUE ), splashScreen( TRUE ),
155
fileFilter( i18n( "Qt User-Interface Files (*.ui)" ) ), client( asClient ),
156
previewing( FALSE ), databaseAutoEdit( FALSE ), autoSaveEnabled( FALSE ), autoSaveInterval( 1800 ), m_part(part)
158
// extern void qInitImages_designercore();
159
// qInitImages_designercore();
162
setPluginDirectory( plgDir );
163
customWidgetToolBar = customWidgetToolBar2 = 0;
164
guiStuffVisible = TRUE;
165
editorsReadOnly = FALSE;
166
sSignalHandlers = TRUE;
168
shStartDialog = FALSE;
170
desInterface = new DesignerInterfaceImpl( this );
171
desInterface->addRef();
173
savePluginPaths = FALSE;
175
updateFunctionsTimer = new QTimer( this );
176
connect( updateFunctionsTimer, SIGNAL( timeout() ),
177
this, SLOT( doFunctionsChanged() ) );
179
autoSaveTimer = new QTimer( this );
180
connect( autoSaveTimer, SIGNAL( timeout() ),
181
this, SLOT( fileSaveAll() ) );
183
set_splash_status( "Loading Plugins..." );
184
setupPluginManagers();
187
qApp->setMainWidget( this );*/
188
QWidgetFactory::addWidgetFactory( new CustomWidgetFactory );
190
setIcon( BarIcon( "designer_appicon.png", KDevDesignerPartFactory::instance() ) );
193
actionGroupTools = 0;
201
singleProject = single;
203
statusBar()->clear();
204
#if defined(QT_NON_COMMERCIAL)
205
statusBar()->addWidget( new QLabel(i18n("Ready - This is the non-commercial version of Qt - "
206
"For commercial evaluations, use the help menu to register with Trolltech."), statusBar()), 1 );
208
statusBar()->addWidget( new QLabel("Ready", statusBar()), 1 );
212
set_splash_status( "Setting up GUI..." );
220
setupProjectActions();
221
setupSearchActions();
222
layoutToolBar = new QToolBar( this, "Layout" );
223
layoutToolBar->setCloseMode( QDockWindow::Undocked );
224
addToolBar( layoutToolBar, i18n( "Layout" ) );
225
interpreterPluginManager = 0;
227
setupLayoutActions();
228
setupPreviewActions();
230
setupActionManager();
231
setupWindowActions();
234
setupHierarchyView();
235
setupPropertyEditor();
242
connect( this, SIGNAL( projectChanged() ), this, SLOT( emitProjectSignals() ) );
243
connect( this, SIGNAL( hasActiveWindow(bool) ), this, SLOT( emitProjectSignals() ) );
245
emit hasActiveForm( FALSE );
246
emit hasActiveWindow( FALSE );
249
qApp->installEventFilter( this );
251
QSize as( qApp->desktop()->size() );
252
as -= QSize( 30, 30 );
253
resize( QSize( 1200, 1000 ).boundedTo( as ) );
255
connect( qApp->clipboard(), SIGNAL( dataChanged() ),
256
this, SLOT( clipboardChanged() ) );
258
layoutChilds = FALSE;
259
layoutSelected = FALSE;
263
set_splash_status( "Loading User Settings..." );
265
// hack to make WidgetFactory happy (so it knows QWidget and QDialog for resetting properties)
266
QWidget *w = WidgetFactory::create( WidgetDatabase::idFromClassName( "QWidget" ), this, 0, FALSE );
268
w = WidgetFactory::create( WidgetDatabase::idFromClassName( "QDialog" ), this, 0, FALSE );
270
w = WidgetFactory::create( WidgetDatabase::idFromClassName( "QLabel" ), this, 0, FALSE );
272
w = WidgetFactory::create( WidgetDatabase::idFromClassName( "QTabWidget" ), this, 0, FALSE );
274
w = WidgetFactory::create( WidgetDatabase::idFromClassName( "QFrame" ), this, 0, FALSE );
276
setAppropriate( (QDockWindow*)actionEditor->parentWidget(), FALSE );
277
actionEditor->parentWidget()->hide();
279
assistant = new QAssistantClient( assistantPath(), this );
281
statusBar()->setSizeGripEnabled( TRUE );
282
set_splash_status( "Initialization Done." );
283
/* if ( shStartDialog )
284
QTimer::singleShot( 0, this, SLOT( showStartDialog() ));*/
286
if ( autoSaveEnabled )
287
autoSaveTimer->start( autoSaveInterval * 1000 );
289
setFocusPolicy( StrongFocus );
292
MainWindow::~MainWindow()
294
QValueList<Tab>::Iterator tit;
295
for ( tit = preferenceTabs.begin(); tit != preferenceTabs.end(); ++tit ) {
299
for ( tit = projectTabs.begin(); tit != projectTabs.end(); ++tit ) {
304
QMap< QAction*, Project* >::Iterator it = projects.begin();
305
while ( it != projects.end() ) {
315
desInterface->release();
318
delete actionPluginManager;
319
delete preferencePluginManager;
320
delete projectSettingsPluginManager;
321
delete interpreterPluginManager;
322
delete templateWizardPluginManager;
323
delete editorPluginManager;
324
delete sourceTemplatePluginManager;
326
MetaDataBase::clearDataBase();
331
void MainWindow::setupMDI()
333
QVBox *vbox = new QVBox( this );
334
setCentralWidget( vbox );
335
vbox->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
336
vbox->setMargin( 1 );
337
vbox->setLineWidth( 1 );
338
qworkspace = new QWorkspace( vbox );
339
qworkspace->setPaletteBackgroundPixmap( UserIcon( "designer_background.png", KDevDesignerPartFactory::instance() ) );
340
qworkspace->setScrollBarsEnabled( TRUE );
341
connect( qworkspace, SIGNAL( windowActivated( QWidget * ) ),
342
this, SLOT( activeWindowChanged( QWidget * ) ) );
343
lastActiveFormWindow = 0;
344
qworkspace->setAcceptDrops( TRUE );
347
void MainWindow::setupMenuBar()
352
void MainWindow::setupPropertyEditor()
354
QDockWindow *dw = new QDockWindow( QDockWindow::InDock, this );
355
dw->setResizeEnabled( TRUE );
356
dw->setCloseMode( QDockWindow::Always );
357
propertyEditor = new PropertyEditor( dw );
358
addToolBar( dw, Qt::DockRight );
359
dw->setWidget( propertyEditor );
360
dw->setFixedExtentWidth( 250 );
361
dw->setCaption( i18n( "Property Editor/Signal Handlers" ) );
362
QWhatsThis::add( propertyEditor,
363
i18n("<b>The Property Editor</b>"
364
"<p>You can change the appearance and behavior of the selected widget in the "
365
"property editor.</p>"
366
"<p>You can set properties for components and forms at design time and see the "
367
"immediately see the effects of the changes. "
368
"Each property has its own editor which (depending on the property) can be used "
370
"new values, open a special dialog, or to select values from a predefined list. "
371
"Click <b>F1</b> to get detailed help for the selected property.</p>"
372
"<p>You can resize the columns of the editor by dragging the separators in the "
374
"<p><b>Signal Handlers</b></p>"
375
"<p>In the Signal Handlers tab you can define connections between "
376
"the signals emitted by widgets and the slots in the form. "
377
"(These connections can also be made using the connection tool.)" ) );
381
void MainWindow::setupOutputWindow()
383
QDockWindow *dw = new QDockWindow( QDockWindow::InDock, this );
384
dw->setResizeEnabled( TRUE );
385
dw->setCloseMode( QDockWindow::Always );
386
addToolBar( dw, Qt::DockBottom );
387
oWindow = new OutputWindow( dw );
388
dw->setWidget( oWindow );
389
dw->setFixedExtentHeight( 150 );
390
dw->setCaption( i18n( "Output Window" ) );
393
void MainWindow::setupHierarchyView()
397
QDockWindow *dw = new QDockWindow( QDockWindow::InDock, this );
398
dw->setResizeEnabled( TRUE );
399
dw->setCloseMode( QDockWindow::Always );
400
hierarchyView = new HierarchyView( dw );
401
addToolBar( dw, Qt::DockRight );
402
dw->setWidget( hierarchyView );
404
dw->setCaption( i18n( "Object Explorer" ) );
405
dw->setFixedExtentWidth( 250 );
406
QWhatsThis::add( hierarchyView,
407
i18n("<b>The Object Explorer</b>"
408
"<p>The Object Explorer provides an overview of the relationships "
409
"between the widgets in a form. You can use the clipboard functions using "
410
"a context menu for each item in the view. It is also useful for selecting widgets "
411
"in forms that have complex layouts.</p>"
412
"<p>The columns can be resized by dragging the separator in the list's header.</p>"
413
"<p>The second tab shows all the form's slots, class variables, includes, etc.</p>") );
417
void MainWindow::setupWorkspace()
419
QDockWindow *dw = new QDockWindow( QDockWindow::InDock, this );
420
dw->setResizeEnabled( TRUE );
421
dw->setCloseMode( QDockWindow::Always );
422
QVBox *vbox = new QVBox( dw );
423
QCompletionEdit *edit = new QCompletionEdit( vbox );
424
QToolTip::add( edit, i18n( "Start typing the buffer you want to switch to here (ALT+B)" ) );
425
QAccel *a = new QAccel( this );
426
a->connectItem( a->insertItem( ALT + Key_B ), edit, SLOT( setFocus() ) );
427
wspace = new Workspace( vbox, this );
428
wspace->setBufferEdit( edit );
429
wspace->setCurrentProject( currentProject );
430
addToolBar( dw, Qt::DockRight );
431
dw->setWidget( vbox );
433
dw->setCaption( i18n( "Project Overview" ) );
434
QWhatsThis::add( wspace, i18n("<b>The Project Overview Window</b>"
435
"<p>The Project Overview Window displays all the current "
436
"project, including forms and source files.</p>"
437
"<p>Use the search field to rapidly switch between files.</p>"));
438
dw->setFixedExtentHeight( 100 );
442
void MainWindow::setupActionEditor()
444
QDockWindow *dw = new QDockWindow( QDockWindow::OutsideDock, this, 0 );
445
addDockWindow( dw, Qt::DockTornOff );
446
dw->setResizeEnabled( TRUE );
447
dw->setCloseMode( QDockWindow::Always );
448
actionEditor = new ActionEditor( dw );
449
dw->setWidget( actionEditor );
450
actionEditor->show();
451
dw->setCaption( i18n( "Action Editor" ) );
452
QWhatsThis::add( actionEditor, i18n("<b>The Action Editor</b>"
453
"<p>The Action Editor is used to add actions and action groups to "
454
"a form, and to connect actions to slots. Actions and action "
455
"groups can be dragged into menus and into toolbars, and may "
456
"feature keyboard shortcuts and tooltips. If actions have pixmaps "
457
"these are displayed on toolbar buttons and besides their names in "
460
setAppropriate( dw, FALSE );
463
void MainWindow::setupToolbox()
465
QDockWindow *dw = new QDockWindow( QDockWindow::InDock, this );
466
dw->setResizeEnabled( TRUE );
467
dw->setCloseMode( QDockWindow::Always );
468
addToolBar( dw, Qt::DockLeft );
469
toolBox = new QToolBox( dw );
470
dw->setWidget( toolBox );
471
dw->setFixedExtentWidth( 160 );
472
dw->setCaption( i18n( "Toolbox" ) );
474
setDockEnabled( dw, Qt::DockTop, FALSE );
475
setDockEnabled( dw, Qt::DockBottom, FALSE );
476
commonWidgetsToolBar = new QToolBar( "Common Widgets", 0, toolBox, FALSE, "Common Widgets" );
477
commonWidgetsToolBar->setFrameStyle( QFrame::NoFrame );
478
commonWidgetsToolBar->setOrientation( Qt::Vertical );
479
commonWidgetsToolBar->setBackgroundMode(PaletteBase);
480
toolBox->addItem( commonWidgetsToolBar, "Common Widgets" );
483
void MainWindow::setupRMBMenus()
485
rmbWidgets = new QPopupMenu( this );
486
actionEditCut->addTo( rmbWidgets );
487
actionEditCopy->addTo( rmbWidgets );
488
actionEditPaste->addTo( rmbWidgets );
489
actionEditDelete->addTo( rmbWidgets );
491
rmbWidgets->insertSeparator();
492
actionEditLower->addTo( rmbWidgets );
493
actionEditRaise->addTo( rmbWidgets );
495
rmbWidgets->insertSeparator();
496
actionEditAdjustSize->addTo( rmbWidgets );
497
actionEditHLayout->addTo( rmbWidgets );
498
actionEditVLayout->addTo( rmbWidgets );
499
actionEditGridLayout->addTo( rmbWidgets );
500
actionEditSplitHorizontal->addTo( rmbWidgets );
501
actionEditSplitVertical->addTo( rmbWidgets );
502
actionEditBreakLayout->addTo( rmbWidgets );
503
rmbWidgets->insertSeparator();
504
if ( !singleProjectMode() )
505
actionEditConnections->addTo( rmbWidgets );
506
actionEditSource->addTo( rmbWidgets );
508
rmbFormWindow = new QPopupMenu( this );
509
actionEditPaste->addTo( rmbFormWindow );
510
actionEditSelectAll->addTo( rmbFormWindow );
511
actionEditAccels->addTo( rmbFormWindow );
512
rmbFormWindow->insertSeparator();
513
actionEditAdjustSize->addTo( rmbFormWindow );
514
actionEditHLayout->addTo( rmbFormWindow );
515
actionEditVLayout->addTo( rmbFormWindow );
516
actionEditGridLayout->addTo( rmbFormWindow );
517
actionEditBreakLayout->addTo( rmbFormWindow );
518
rmbFormWindow->insertSeparator();
519
if ( !singleProjectMode() ) {
520
actionEditFunctions->addTo( rmbFormWindow );
521
actionEditConnections->addTo( rmbFormWindow );
523
actionEditSource->addTo( rmbFormWindow );
524
rmbFormWindow->insertSeparator();
525
actionEditFormSettings->addTo( rmbFormWindow );
528
void MainWindow::toolSelected( QAction* action )
530
actionCurrentTool = action;
531
emit currentToolChanged();
533
formWindow()->commandHistory()->emitUndoRedo();
536
int MainWindow::currentTool() const
538
if ( !actionCurrentTool )
540
return QString::fromLatin1(actionCurrentTool->name()).toInt();
543
void MainWindow::runProjectPrecondition()
545
for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() ) {
547
e->saveBreakPoints();
551
if ( currentTool() == ORDER_TOOL )
553
oWindow->clearErrorMessages();
554
oWindow->clearDebug();
555
oWindow->showDebugTab();
559
void MainWindow::runProjectPostcondition( QObjectList *l )
564
for ( SourceEditor *e2 = sourceEditors.first(); e2; e2 = sourceEditors.next() ) {
565
if ( e2->project() == currentProject )
566
e2->editorInterface()->setMode( EditorInterface::Debugging );
570
QWidget* MainWindow::previewFormInternal( QStyle* style, QPalette* palet )
572
qwf_execute_code = FALSE;
573
for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() )
575
if ( currentTool() == ORDER_TOOL )
578
FormWindow *fw = formWindow();
582
QStringList databases;
583
QPtrDictIterator<QWidget> wit( *fw->widgets() );
584
while ( wit.current() ) {
585
QStringList lst = MetaDataBase::fakeProperty( wit.current(), "database" ).toStringList();
586
if ( !lst.isEmpty() )
587
databases << lst [ 0 ];
591
if ( fw->project() ) {
592
QStringList::ConstIterator it;
593
for ( it = databases.begin(); it != databases.end(); ++it )
594
fw->project()->openDatabase( *it, FALSE );
596
QApplication::setOverrideCursor( WaitCursor );
600
buffer.open( IO_WriteOnly );
601
Resource resource( this );
602
resource.setWidget( fw );
603
QValueList<Resource::Image> images;
604
resource.save( &buffer );
607
buffer.open( IO_ReadOnly );
609
QWidget *w = QWidgetFactory::create( &buffer );
614
style->polish( *palet );
615
w->setPalette( *palet );
619
w->setStyle( style );
621
QObjectList *l = w->queryList( "QWidget" );
622
for ( QObject *o = l->first(); o; o = l->next() ) {
624
( (QWidget*)o )->setStyle( style );
628
w->move( fw->mapToGlobal( QPoint(0,0) ) );
629
((MainWindow*)w )->setWFlags( WDestructiveClose );
633
QApplication::restoreOverrideCursor();
636
QApplication::restoreOverrideCursor();
640
void MainWindow::previewForm()
642
QWidget* w = previewFormInternal();
647
void MainWindow::previewForm( const QString & style )
649
QStyle* st = QStyleFactory::create( style );
651
if ( style == "Motif" ) {
652
QPalette p( QColor( 192, 192, 192 ) );
653
w = previewFormInternal( st, &p );
654
} else if ( style == "Windows" ) {
655
QPalette p( QColor( 212, 208, 200 ) );
656
w = previewFormInternal( st, &p );
657
} else if ( style == "Platinum" ) {
658
QPalette p( QColor( 220, 220, 220 ) );
659
w = previewFormInternal( st, &p );
660
} else if ( style == "CDE" ) {
661
QPalette p( QColor( 75, 123, 130 ) );
662
p.setColor( QPalette::Active, QColorGroup::Base, QColor( 55, 77, 78 ) );
663
p.setColor( QPalette::Inactive, QColorGroup::Base, QColor( 55, 77, 78 ) );
664
p.setColor( QPalette::Disabled, QColorGroup::Base, QColor( 55, 77, 78 ) );
665
p.setColor( QPalette::Active, QColorGroup::Highlight, Qt::white );
666
p.setColor( QPalette::Active, QColorGroup::HighlightedText, QColor( 55, 77, 78 ) );
667
p.setColor( QPalette::Inactive, QColorGroup::Highlight, Qt::white );
668
p.setColor( QPalette::Inactive, QColorGroup::HighlightedText, QColor( 55, 77, 78 ) );
669
p.setColor( QPalette::Disabled, QColorGroup::Highlight, Qt::white );
670
p.setColor( QPalette::Disabled, QColorGroup::HighlightedText, QColor( 55, 77, 78 ) );
671
p.setColor( QPalette::Active, QColorGroup::Foreground, Qt::white );
672
p.setColor( QPalette::Active, QColorGroup::Text, Qt::white );
673
p.setColor( QPalette::Active, QColorGroup::ButtonText, Qt::white );
674
p.setColor( QPalette::Inactive, QColorGroup::Foreground, Qt::white );
675
p.setColor( QPalette::Inactive, QColorGroup::Text, Qt::white );
676
p.setColor( QPalette::Inactive, QColorGroup::ButtonText, Qt::white );
677
p.setColor( QPalette::Disabled, QColorGroup::Foreground, Qt::lightGray );
678
p.setColor( QPalette::Disabled, QColorGroup::Text, Qt::lightGray );
679
p.setColor( QPalette::Disabled, QColorGroup::ButtonText, Qt::lightGray );
681
w = previewFormInternal( st, &p );
682
} else if ( style == "SGI" ) {
683
QPalette p( QColor( 220, 220, 220 ) );
684
w = previewFormInternal( st, &p );
685
} else if ( style == "MotifPlus" ) {
686
QColor gtkfg(0x00, 0x00, 0x00);
687
QColor gtkdf(0x75, 0x75, 0x75);
688
QColor gtksf(0xff, 0xff, 0xff);
689
QColor gtkbs(0xff, 0xff, 0xff);
690
QColor gtkbg(0xd6, 0xd6, 0xd6);
691
QColor gtksl(0x00, 0x00, 0x9c);
692
QColorGroup active(gtkfg, // foreground
694
gtkbg.light(), // light
695
gtkbg.dark(142), // dark
696
gtkbg.dark(110), // mid
698
gtkfg, // bright text
700
gtkbg), // background
701
disabled(gtkdf, // foreground
703
gtkbg.light(), // light
704
gtkbg.dark(156), // dark
705
gtkbg.dark(110), // mid
707
gtkdf, // bright text
709
gtkbg); // background
711
QPalette pal(active, disabled, active);
713
pal.setColor(QPalette::Active, QColorGroup::Highlight,
715
pal.setColor(QPalette::Active, QColorGroup::HighlightedText,
717
pal.setColor(QPalette::Inactive, QColorGroup::Highlight,
719
pal.setColor(QPalette::Inactive, QColorGroup::HighlightedText,
721
pal.setColor(QPalette::Disabled, QColorGroup::Highlight,
723
pal.setColor(QPalette::Disabled, QColorGroup::HighlightedText,
725
w = previewFormInternal( st, &pal );
727
w = previewFormInternal( st );
732
w->insertChild( st );
736
void MainWindow::helpContents()
738
QWidget *focusWidget = qApp->focusWidget();
739
bool showClassDocu = TRUE;
740
while ( focusWidget ) {
741
if ( focusWidget->isA( "PropertyList" ) ) {
742
showClassDocu = FALSE;
745
focusWidget = focusWidget->parentWidget();
748
QString source = "designer-manual.html";
749
if ( propertyDocumentation.isEmpty() ) {
750
QString indexFile = documentationPath() + "/propertyindex";
751
QFile f( indexFile );
752
if ( f.open( IO_ReadOnly ) ) {
753
QTextStream ts( &f );
754
while ( !ts.eof() ) {
755
QString s = ts.readLine();
756
int from = s.find( "\"" );
759
int to = s.findRev( "\"" );
762
propertyDocumentation[ s.mid( from + 1, to - from - 1 ) ] = s.mid( to + 2 ) + "-prop";
768
if ( propertyEditor->widget() && !showClassDocu ) {
769
if ( !propertyEditor->currentProperty().isEmpty() ) {
770
QMetaObject* mo = propertyEditor->metaObjectOfCurrentProperty();
772
QString cp = propertyEditor->currentProperty();
773
if ( cp == "layoutMargin" ) {
774
source = propertyDocumentation[ "QLayout/margin" ];
775
} else if ( cp == "layoutSpacing" ) {
776
source = propertyDocumentation[ "QLayout/spacing" ];
777
} else if ( cp == "toolTip" ) {
778
source = "qtooltip.html#details";
779
} else if ( mo && qstrcmp( mo->className(), "Spacer" ) == 0 ) {
781
source = "qsizepolicy.html#SizeType";
783
source = propertyDocumentation[ "QObject/name" ];
785
while ( mo && !propertyDocumentation.contains( ( s = QString( mo->className() ) + "/" + cp ) ) )
786
mo = mo->superClass();
788
source = "p:" + propertyDocumentation[s];
792
QString classname = WidgetFactory::classNameOf( propertyEditor->widget() );
793
if ( source.isEmpty() || source == "designer-manual.html" ) {
794
if ( classname.lower() == "spacer" )
795
source = "qspaceritem.html#details";
796
else if ( classname == "QLayoutWidget" )
797
source = "layout.html";
799
source = QString( WidgetFactory::classNameOf( propertyEditor->widget() ) ).lower() + ".html#details";
801
} else if ( propertyEditor->widget() ) {
802
source = QString( WidgetFactory::classNameOf( propertyEditor->widget() ) ).lower() + ".html#details";
805
if ( !source.isEmpty() )
806
assistant->showPage( documentationPath() + source );
809
void MainWindow::helpManual()
811
assistant->showPage( documentationPath() + "/designer-manual.html" );
814
void MainWindow::helpAbout()
816
AboutDialog dlg( this, 0, TRUE );
817
if ( singleProjectMode() ) {
818
dlg.aboutPixmap->setText( "" );
819
dlg.aboutVersion->setText( "" );
820
dlg.aboutCopyright->setText( "" );
821
LanguageInterface *iface = MetaDataBase::languageInterface( eProject->language() );
822
dlg.aboutLicense->setText( iface->aboutText() );
824
dlg.aboutVersion->setText(QString("Version ") + QString(QT_VERSION_STR));
825
dlg.resize( dlg.width(), dlg.layout()->heightForWidth(dlg.width()) );
829
void MainWindow::helpAboutQt()
831
QMessageBox::aboutQt( this, "Qt Designer" );
834
#if defined(_WS_WIN_)
835
#include <qt_windows.h>
836
#include <qprocess.h>
839
void MainWindow::helpRegister()
841
#if defined(_WS_WIN_)
848
QString sub( "htmlfile\\shell" );
850
if ( QApplication::winVersion() & Qt::WV_NT_based ) {
851
unsigned char data[256];
852
res = RegOpenKeyExW( HKEY_CLASSES_ROOT, NULL, 0, KEY_READ, &key );
853
res = RegOpenKeyExW( key, (TCHAR*)sub.ucs2(), 0, KEY_READ, &subkey );
854
res = RegQueryValueExW( subkey, NULL, NULL, &type, data, &size );
855
command = qt_winQString( data ) + "\\command";
857
res = RegOpenKeyExW( subkey, (TCHAR*)command.ucs2(), 0, KEY_READ, &subkey );
858
res = RegQueryValueExW( subkey, NULL, NULL, &type, data, &size );
859
command = qt_winQString( data );
863
unsigned char data[256];
864
res = RegOpenKeyExA( HKEY_CLASSES_ROOT, NULL, 0, KEY_READ, &key );
865
res = RegOpenKeyExA( key, sub.local8Bit(), 0, KEY_READ, &subkey );
866
res = RegQueryValueExA( subkey, NULL, NULL, &type, data, &size );
867
command = QString::fromLocal8Bit( (const char*) data ) + "\\command";
869
res = RegOpenKeyExA( subkey, command.local8Bit(), 0, KEY_READ, &subkey );
870
res = RegQueryValueExA( subkey, NULL, NULL, &type, data, &size );
871
command = QString::fromLocal8Bit( (const char*) data );
874
res = RegCloseKey( subkey );
875
res = RegCloseKey( key );
877
QProcess process( command + " www.trolltech.com/products/download/eval/evaluation.html" );
878
if ( !process.start() )
879
QMessageBox::information( this, "Register Qt", "Launching your web browser failed.\n"
880
"To register Qt, point your browser to www.trolltech.com/products/download/eval/evaluation.html" );
884
void MainWindow::showProperties( QObject *o )
886
if ( !o->isWidgetType() ) {
887
propertyEditor->setWidget( o, lastActiveFormWindow );
888
if ( lastActiveFormWindow )
889
hierarchyView->setFormWindow( lastActiveFormWindow, lastActiveFormWindow->mainContainer() );
891
hierarchyView->setFormWindow( 0, 0 );
894
QWidget *w = (QWidget*)o;
895
setupHierarchyView();
896
FormWindow *fw = (FormWindow*)isAFormWindowChild( w );
898
if ( fw->numSelectedWidgets() > 1 ) {
899
QWidgetList wl = fw->selectedWidgets();
900
if ( wl.first() != w ) {
904
propertyEditor->setWidget( new PropertyObject( wl ), fw );
906
propertyEditor->setWidget( w, fw );
908
hierarchyView->setFormWindow( fw, w );
910
propertyEditor->setWidget( 0, 0 );
911
hierarchyView->setFormWindow( 0, 0 );
914
if ( currentTool() == POINTER_TOOL && fw &&
915
( !qworkspace->activeWindow() || !::qt_cast<SourceEditor*>(qworkspace->activeWindow()) ) )
919
void MainWindow::resetTool()
921
actionPointerTool->setOn( TRUE );
924
void MainWindow::updateProperties( QObject * )
926
if ( propertyEditor )
927
propertyEditor->refetchData();
930
bool MainWindow::eventFilter( QObject *o, QEvent *e )
932
if ( ::qt_cast<MenuBarEditor*>(o) || ::qt_cast<PopupMenuEditor*>(o) ||
934
( ::qt_cast<MenuBarEditor*>(o->parent()) ||
935
::qt_cast<PopupMenuEditor*>(o->parent()) ) ) ) {
937
if ( e->type() == QEvent::Accel && ::qt_cast<PopupMenuEditor*>(o) ) {
938
return TRUE; // consume accel events
939
} else if ( e->type() == QEvent::MouseButtonPress && ::qt_cast<MenuBarEditor*>(o) ) {
940
QPoint pos = ((QMouseEvent*)e)->pos();
941
MenuBarEditor *m = ::qt_cast<MenuBarEditor*>(o);
943
if ( m->findItem( pos ) >= m->count() )
945
} else if ( e->type() == QEvent::MouseButtonPress && ::qt_cast<PopupMenuEditor*>(o) ) {
946
PopupMenuEditor *m = ::qt_cast<PopupMenuEditor*>(o);
947
PopupMenuEditorItem *i = m->at( ((QMouseEvent*)e)->pos() );
948
if ( m->find( i->action() ) != -1 && !i->isSeparator() )
949
showProperties( i->action() );
951
return QMainWindow::eventFilter( o, e );
954
if ( !o || !e || !o->isWidgetType() )
955
return QMainWindow::eventFilter( o, e );
958
bool passiveInteractor;
959
switch ( e->type() ) {
960
case QEvent::AccelOverride:
961
if ( ( (QKeyEvent*)e )->key() == Key_F1 &&
962
( ( (QKeyEvent*)e )->state() & ShiftButton ) != ShiftButton ) {
965
if ( ::qt_cast<PropertyList*>(w) )
967
w = w->parentWidget( TRUE );
970
propertyEditor->propertyList()->showCurrentWhatsThis();
971
( (QKeyEvent*)e )->accept();
977
if ( ( ( (QKeyEvent*)e )->key() == Key_A ||
978
( (QKeyEvent*)e )->key() == Key_E ) &&
979
( (QKeyEvent*)e )->state() & ControlButton ) {
980
if ( qWorkspace()->activeWindow() &&
981
::qt_cast<SourceEditor*>(qWorkspace()->activeWindow()) ) {
982
( (QKeyEvent*)e )->ignore();
987
case QEvent::ContextMenu:
988
case QEvent::MouseButtonPress:
989
if ( o && currentTool() == POINTER_TOOL &&
990
( ::qt_cast<MenuBarEditor*>(o) ||
991
::qt_cast<PopupMenuEditor*>(o) ||
992
::qt_cast<QDesignerToolBar*>(o) ||
993
( ::qt_cast<QComboBox*>(o) ||
994
::qt_cast<QToolButton*>(o) ||
995
::qt_cast<QDesignerToolBarSeparator*>(o) ) &&
997
&& ( ::qt_cast<QDesignerToolBar*>(o->parent())
998
|| ::qt_cast<QDesignerWidgetStack*>(o->parent())) ) ) {
999
QWidget *w = (QWidget*)o;
1000
if ( ::qt_cast<QToolButton*>(w) ||
1001
::qt_cast<QComboBox*>(w) ||
1002
::qt_cast<PopupMenuEditor*>(w) ||
1003
::qt_cast<QDesignerToolBarSeparator*>(w) )
1004
w = w->parentWidget();
1005
QWidget *pw = w->parentWidget();
1007
if ( ::qt_cast<FormWindow*>(pw) ) {
1008
( (FormWindow*)pw )->emitShowProperties( w );
1009
if ( !::qt_cast<QDesignerToolBar*>(o) )
1010
return ( !::qt_cast<QToolButton*>(o) &&
1011
!::qt_cast<MenuBarEditor*>(o) &&
1012
!::qt_cast<QComboBox*>(o) &&
1013
!::qt_cast<QDesignerToolBarSeparator*>(o) );
1015
pw = pw->parentWidget();
1018
if ( o && ( ::qt_cast<QDesignerToolBar*>(o) || o->inherits("QDockWindowHandle") )
1019
&& e->type() == QEvent::ContextMenu )
1021
if ( isAToolBarChild( o ) && currentTool() != CONNECT_TOOL && currentTool() != BUDDY_TOOL )
1023
if ( ::qt_cast<QSizeGrip*>(o) )
1025
if ( !( w = isAFormWindowChild( o ) ) ||
1026
::qt_cast<SizeHandle*>(o) ||
1027
::qt_cast<OrderIndicator*>(o) )
1029
if ( !w->hasFocus() )
1031
passiveInteractor = WidgetFactory::isPassiveInteractor( o );
1032
if ( !passiveInteractor || currentTool() != ORDER_TOOL ) {
1033
if( e->type() == QEvent::ContextMenu ) {
1034
( (FormWindow*)w )->handleContextMenu( (QContextMenuEvent*)e,
1035
( (FormWindow*)w )->designerWidget( o ) );
1038
( (FormWindow*)w )->handleMousePress( (QMouseEvent*)e,
1039
( (FormWindow*)w )->designerWidget( o ) );
1042
lastPressWidget = (QWidget*)o;
1043
if ( passiveInteractor )
1044
QTimer::singleShot( 0, formWindow(), SLOT( visibilityChanged() ) );
1045
if ( currentTool() == CONNECT_TOOL || currentTool() == BUDDY_TOOL )
1047
return !passiveInteractor;
1048
case QEvent::MouseButtonRelease:
1049
lastPressWidget = 0;
1050
if ( isAToolBarChild( o ) && currentTool() != CONNECT_TOOL && currentTool() != BUDDY_TOOL )
1052
if ( ::qt_cast<QSizeGrip*>(o) )
1054
if ( !( w = isAFormWindowChild( o ) ) ||
1055
::qt_cast<SizeHandle*>(o) ||
1056
::qt_cast<OrderIndicator*>(o) )
1058
passiveInteractor = WidgetFactory::isPassiveInteractor( o );
1059
if ( !passiveInteractor )
1060
( (FormWindow*)w )->handleMouseRelease( (QMouseEvent*)e,
1061
( (FormWindow*)w )->designerWidget( o ) );
1062
if ( passiveInteractor ) {
1063
QTimer::singleShot( 0, this, SLOT( selectionChanged() ) );
1064
QTimer::singleShot( 0, formWindow(), SLOT( visibilityChanged() ) );
1066
return !passiveInteractor;
1067
case QEvent::MouseMove:
1068
if ( isAToolBarChild( o ) && currentTool() != CONNECT_TOOL && currentTool() != BUDDY_TOOL )
1070
w = isAFormWindowChild( o );
1071
if ( lastPressWidget != (QWidget*)o && w &&
1072
!::qt_cast<SizeHandle*>(o) && !::qt_cast<OrderIndicator*>(o) &&
1073
!::qt_cast<PopupMenuEditor*>(o) && !::qt_cast<QMenuBar*>(o) &&
1074
!::qt_cast<QSizeGrip*>(o) )
1076
if ( o && ::qt_cast<QSizeGrip*>(o) )
1078
if ( lastPressWidget != (QWidget*)o ||
1079
( !w || ::qt_cast<SizeHandle*>(o) ) ||
1080
::qt_cast<OrderIndicator*>(o) )
1082
passiveInteractor = WidgetFactory::isPassiveInteractor( o );
1083
if ( !passiveInteractor )
1084
( (FormWindow*)w )->handleMouseMove( (QMouseEvent*)e,
1085
( (FormWindow*)w )->designerWidget( o ) );
1086
return !passiveInteractor;
1087
case QEvent::KeyPress:
1088
if ( ( (QKeyEvent*)e )->key() == Key_Escape && currentTool() != POINTER_TOOL ) {
1092
if ( ( (QKeyEvent*)e )->key() == Key_Escape && incrementalSearch->hasFocus() ) {
1093
if ( ::qt_cast<SourceEditor*>(qWorkspace()->activeWindow()) ) {
1094
qWorkspace()->activeWindow()->setFocus();
1098
if ( !( w = isAFormWindowChild( o ) ) ||
1099
::qt_cast<SizeHandle*>(o) ||
1100
::qt_cast<OrderIndicator*>(o) )
1102
( (FormWindow*)w )->handleKeyPress( (QKeyEvent*)e, ( (FormWindow*)w )->designerWidget( o ) );
1103
if ( ((QKeyEvent*)e)->isAccepted() )
1106
case QEvent::MouseButtonDblClick:
1107
if ( !( w = isAFormWindowChild( o ) ) ||
1108
::qt_cast<SizeHandle*>(o) ||
1109
::qt_cast<OrderIndicator*>(o) ) {
1110
if ( ::qt_cast<QToolButton*>(o) && ((QToolButton*)o)->isOn() &&
1111
o->parent() && ::qt_cast<QToolBar*>(o->parent()) && formWindow() )
1112
formWindow()->setToolFixed();
1115
if ( currentTool() == ORDER_TOOL ) {
1116
( (FormWindow*)w )->handleMouseDblClick( (QMouseEvent*)e,
1117
( (FormWindow*)w )->designerWidget( o ) );
1120
if ( !WidgetFactory::isPassiveInteractor( o ) && ( (FormWindow*)w )->formFile() )
1121
return openEditor( ( (FormWindow*)w )->designerWidget( o ), (FormWindow*)w );
1123
case QEvent::KeyRelease:
1124
if ( !( w = isAFormWindowChild( o ) ) ||
1125
::qt_cast<SizeHandle*>(o) ||
1126
::qt_cast<OrderIndicator*>(o) )
1128
( (FormWindow*)w )->handleKeyRelease( (QKeyEvent*)e, ( (FormWindow*)w )->designerWidget( o ) );
1129
if ( ((QKeyEvent*)e)->isAccepted() )
1133
if ( !( w = isAFormWindowChild( o ) ) ||
1134
::qt_cast<SizeHandle*>(o) ||
1135
::qt_cast<OrderIndicator*>(o) )
1137
if ( ( (FormWindow*)w )->isWidgetSelected( (QWidget*)o ) )
1138
( (FormWindow*)w )->selectWidget( (QWidget*)o, FALSE );
1142
if ( !( w = isAFormWindowChild( o ) ) ||
1143
::qt_cast<SizeHandle*>(o) ||
1144
::qt_cast<OrderIndicator*>(o) ||
1145
::qt_cast<MenuBarEditor*>(o) )
1148
case QEvent::Resize:
1150
if ( !( w = isAFormWindowChild( o ) ) ||
1151
::qt_cast<SizeHandle*>(o) ||
1152
::qt_cast<OrderIndicator*>(o) )
1154
if ( WidgetFactory::layoutType( (QWidget*)o->parent() ) != WidgetFactory::NoLayout ) {
1155
( (FormWindow*)w )->updateSelection( (QWidget*)o );
1156
if ( e->type() != QEvent::Resize )
1157
( (FormWindow*)w )->updateChildSelections( (QWidget*)o );
1161
if ( o->isWidgetType() && (QWidget*)o == (QWidget*)previewedForm ) {
1162
if ( lastActiveFormWindow && lastActiveFormWindow->project() ) {
1164
MetaDataBase::fakeProperty( lastActiveFormWindow, "database" ).toStringList();
1165
lastActiveFormWindow->project()->closeDatabase( lst[ 0 ] );
1169
case QEvent::DragEnter:
1170
if ( o == qWorkspace() || o == workspace() || o == workspace()->viewport() ) {
1171
workspace()->contentsDragEnterEvent( (QDragEnterEvent*)e );
1175
case QEvent::DragMove:
1176
if ( o == qWorkspace() || o == workspace() || o == workspace()->viewport() ) {
1177
workspace()->contentsDragMoveEvent( (QDragMoveEvent*)e );
1182
if ( o == qWorkspace() || o == workspace() || o == workspace()->viewport() ) {
1183
workspace()->contentsDropEvent( (QDropEvent*)e );
1190
if ( ((QShowEvent*)e)->spontaneous() )
1192
QApplication::sendPostedEvents( qworkspace, QEvent::ChildInserted );
1193
showEvent( (QShowEvent*)e );
1197
if ( !( w = isAFormWindowChild( o ) ) ||
1198
::qt_cast<SizeHandle*>(o) ||
1199
::qt_cast<OrderIndicator*>(o) )
1202
case QEvent::FocusIn:
1203
if ( !::qt_cast<FormWindow*>(o) && isAFormWindowChild( o ) )
1204
return TRUE; //FIXME
1205
if ( hierarchyView->formDefinitionView()->isRenaming()
1206
&& ( o->inherits( "Editor" ) || ::qt_cast<FormWindow*>(o) ) )
1207
QApplication::sendPostedEvents();
1208
if ( o->inherits( "Editor" ) ) {
1209
QWidget *w = (QWidget*)o;
1211
if ( ::qt_cast<SourceEditor*>(w) )
1213
w = w->parentWidget( TRUE );
1215
if ( ::qt_cast<SourceEditor*>(w) )
1216
( (SourceEditor*)w )->checkTimeStamp();
1217
} else if ( ::qt_cast<FormWindow*>(o) ) {
1218
FormWindow *fw = (FormWindow*)o;
1219
if ( fw->formFile() && fw->formFile()->editor() )
1220
fw->formFile()->editor()->checkTimeStamp();
1223
case QEvent::FocusOut:
1224
if ( !::qt_cast<FormWindow*>(o) && isAFormWindowChild( o ) )
1228
return QMainWindow::eventFilter( o, e );
1231
return QMainWindow::eventFilter( o, e );
1234
QWidget *MainWindow::isAFormWindowChild( QObject *o ) const
1236
if ( ::qt_cast<QWizard*>(o->parent()) && !::qt_cast<QPushButton*>(o) )
1239
if ( ::qt_cast<FormWindow*>(o) )
1246
QWidget *MainWindow::isAToolBarChild( QObject *o ) const
1249
if ( ::qt_cast<QDesignerToolBar*>(o) )
1251
if ( ::qt_cast<FormWindow*>(o) )
1258
FormWindow *MainWindow::formWindow()
1260
if ( qworkspace->activeWindow() ) {
1262
if ( ::qt_cast<FormWindow*>(qworkspace->activeWindow()) )
1263
fw = (FormWindow*)qworkspace->activeWindow();
1264
else if ( lastActiveFormWindow &&
1265
qworkspace->windowList().find( lastActiveFormWindow ) != -1)
1266
fw = lastActiveFormWindow;
1272
void MainWindow::emitProjectSignals()
1274
emit hasNonDummyProject( !currentProject->isDummy() );
1275
emit hasActiveWindowOrProject( !!qworkspace->activeWindow() || !currentProject->isDummy() );
1278
void MainWindow::insertFormWindow( FormWindow *fw )
1281
QWhatsThis::add( fw, i18n( "<b>The Form Window</b>"
1282
"<p>Use the various tools to add widgets or to change the layout "
1283
"and behavior of the components in the form. Select one or multiple "
1284
"widgets to move them or lay them out. If a single widget is chosen it can "
1285
"be resized using the resize handles.</p>"
1286
"<p>Changes in the <b>Property Editor</b> are visible at design time, "
1287
"and you can preview the form in different styles.</p>"
1288
"<p>You can change the grid resolution, or turn the grid off in the "
1289
"<b>Preferences</b> dialog in the <b>Edit</b> menu."
1290
"<p>You can have several forms open, and all open forms are listed "
1291
"in the <b>Form List</b>.") );
1293
connect( fw, SIGNAL( showProperties( QObject * ) ),
1294
this, SLOT( showProperties( QObject * ) ) );
1295
connect( fw, SIGNAL( updateProperties( QObject * ) ),
1296
this, SLOT( updateProperties( QObject * ) ) );
1297
connect( this, SIGNAL( currentToolChanged() ),
1298
fw, SLOT( currentToolChanged() ) );
1299
connect( fw, SIGNAL( selectionChanged() ),
1300
this, SLOT( selectionChanged() ) );
1301
connect( fw, SIGNAL( undoRedoChanged( bool, bool, const QString &, const QString & ) ),
1302
this, SLOT( updateUndoRedo( bool, bool, const QString &, const QString & ) ) );
1304
if ( !mblockNewForms ) {
1306
fw->setProject( currentProject );
1309
fw->currentToolChanged();
1310
if ( fw->caption().isEmpty() && qstrlen( fw->name() ) )
1311
fw->setCaption( fw->name() );
1312
fw->mainContainer()->setCaption( fw->caption() );
1313
WidgetFactory::saveDefaultProperties( fw->mainContainer(),
1315
idFromClassName( WidgetFactory::classNameOf( fw->mainContainer() ) ) );
1316
activeWindowChanged( fw );
1317
emit formWindowsChanged();
1318
for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() ) {
1319
if ( e->project() == fw->project() )
1324
void MainWindow::createNewProject( const QString &lang )
1326
Project *pro = new Project( "", "", projectSettingsPluginManager );
1327
pro->setLanguage( lang );
1330
if ( !openProjectSettings( pro ) ) {
1335
if ( !pro->isValid() ) {
1336
QMessageBox::information( this, i18n("New Project"), i18n( "Cannot create an invalid project." ) );
1341
QAction *a = new QAction( pro->makeRelative( pro->fileName() ),
1342
pro->makeRelative( pro->fileName() ), 0, actionGroupProjects, 0, TRUE );
1343
projects.insert( a, pro );
1344
addRecentlyOpened( pro->makeAbsolute( pro->fileName() ), recentlyProjects );
1345
projectSelected( a );
1349
bool MainWindow::unregisterClient( FormWindow *w )
1351
propertyEditor->closed( w );
1352
objectHierarchy()->closed( w );
1353
if ( w == lastActiveFormWindow )
1354
lastActiveFormWindow = 0;
1356
QPtrList<SourceEditor> waitingForDelete;
1357
waitingForDelete.setAutoDelete( TRUE );
1358
for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() ) {
1359
if ( e->object() == w )
1360
waitingForDelete.append( e );
1363
if ( actionEditor->form() == w ) {
1364
actionEditor->setFormWindow( 0 );
1365
actionEditor->parentWidget()->hide();
1371
void MainWindow::activeWindowChanged( QWidget *w )
1373
QWidget *old = formWindow();
1374
if ( ::qt_cast<FormWindow*>(w) ) {
1375
FormWindow *fw = (FormWindow*)w;
1376
FormWindow *ofw = lastActiveFormWindow;
1377
lastActiveFormWindow = fw;
1378
lastActiveFormWindow->updateUndoInfo();
1379
emit hasActiveForm( TRUE );
1380
if ( formWindow() ) {
1381
formWindow()->emitShowProperties();
1382
emit formModified( formWindow()->commandHistory()->isModified() );
1383
if ( currentTool() != POINTER_TOOL )
1384
formWindow()->clearSelection();
1386
workspace()->activeFormChanged( fw );
1387
setAppropriate( (QDockWindow*)actionEditor->parentWidget(),
1388
::qt_cast<QMainWindow*>(lastActiveFormWindow->mainContainer()) );
1389
if ( appropriate( (QDockWindow*)actionEditor->parentWidget() ) ) {
1390
if ( actionEditor->wantToBeShown() )
1391
actionEditor->parentWidget()->show();
1394
if ( ofw && (mc = ofw->mainContainer()) && ::qt_cast<QMainWindow*>(mc) )
1395
actionEditor->setWantToBeShown( !actionEditor->parentWidget()->isHidden() );
1396
actionEditor->parentWidget()->hide();
1399
actionEditor->setFormWindow( lastActiveFormWindow );
1400
if ( wspace && fw->project() && fw->project() != currentProject ) {
1401
for ( QMap<QAction*, Project *>::ConstIterator it = projects.begin(); it != projects.end(); ++it ) {
1402
if ( *it == fw->project() ) {
1403
projectSelected( it.key() );
1408
emit formWindowChanged();
1410
} else if ( w == propertyEditor ) {
1411
propertyEditor->resetFocus();
1412
} else if ( !lastActiveFormWindow ) {
1413
emit formWindowChanged();
1414
emit hasActiveForm( FALSE );
1415
actionEditUndo->setEnabled( FALSE );
1416
actionEditRedo->setEnabled( FALSE );
1420
emit formWindowChanged();
1421
emit hasActiveForm( FALSE );
1422
propertyEditor->clear();
1423
hierarchyView->clear();
1424
updateUndoRedo( FALSE, FALSE, QString::null, QString::null );
1429
if ( ::qt_cast<SourceEditor*>(w) ) {
1430
SourceEditor *se = (SourceEditor*)w;
1431
QGuardedPtr<FormWindow> fw = se->formWindow();
1432
if ( se->formWindow() &&
1433
lastActiveFormWindow != fw ) {
1434
activeWindowChanged( se->formWindow() );
1436
actionSearchFind->setEnabled( TRUE );
1437
actionSearchIncremetal->setEnabled( TRUE );
1438
actionSearchReplace->setEnabled( TRUE );
1439
actionSearchGotoLine->setEnabled( TRUE );
1440
incrementalSearch->setEnabled( TRUE );
1442
actionEditUndo->setEnabled( FALSE );
1443
actionEditRedo->setEnabled( FALSE );
1444
actionEditCut->setEnabled( TRUE );
1445
actionEditCopy->setEnabled( TRUE );
1446
actionEditPaste->setEnabled( TRUE );
1447
actionEditSelectAll->setEnabled( TRUE );
1448
actionEditUndo->setMenuText( i18n( "&Undo" ) );
1449
actionEditUndo->setToolTip( textNoAccel( actionEditUndo->menuText()) );
1450
actionEditRedo->setMenuText( i18n( "&Redo" ) );
1451
actionEditRedo->setToolTip( textNoAccel( actionEditRedo->menuText()) );
1452
if ( hierarchyView->sourceEditor() != w )
1453
hierarchyView->showClasses( se );
1454
actionEditor->setFormWindow( 0 );
1455
if ( wspace && se->project() && se->project() != currentProject ) {
1456
for ( QMap<QAction*, Project *>::ConstIterator it = projects.begin(); it != projects.end(); ++it ) {
1457
if ( *it == se->project() ) {
1458
projectSelected( it.key() );
1463
workspace()->activeEditorChanged( se );
1465
actionSearchFind->setEnabled( FALSE );
1466
actionSearchIncremetal->setEnabled( FALSE );
1467
actionSearchReplace->setEnabled( FALSE );
1468
actionSearchGotoLine->setEnabled( FALSE );
1469
incrementalSearch->setEnabled( FALSE );
1472
if ( currentTool() == ORDER_TOOL && w != old )
1473
emit currentToolChanged();
1475
emit hasActiveWindow( !!qworkspace->activeWindow() );
1478
void MainWindow::updateUndoRedo( bool undoAvailable, bool redoAvailable,
1479
const QString &undoCmd, const QString &redoCmd )
1481
if ( qWorkspace()->activeWindow() &&
1482
::qt_cast<SourceEditor*>(qWorkspace()->activeWindow()) )
1483
return; // do not set a formWindow related command
1484
actionEditUndo->setEnabled( undoAvailable );
1485
actionEditRedo->setEnabled( redoAvailable );
1486
if ( !undoCmd.isEmpty() )
1487
actionEditUndo->setMenuText( i18n( "&Undo: %1" ).arg( undoCmd ) );
1489
actionEditUndo->setMenuText( i18n( "&Undo: Not Available" ) );
1490
if ( !redoCmd.isEmpty() )
1491
actionEditRedo->setMenuText( i18n( "&Redo: %1" ).arg( redoCmd ) );
1493
actionEditRedo->setMenuText( i18n( "&Redo: Not Available" ) );
1495
actionEditUndo->setToolTip( textNoAccel( actionEditUndo->menuText()) );
1496
actionEditRedo->setToolTip( textNoAccel( actionEditRedo->menuText()) );
1498
if ( currentTool() == ORDER_TOOL ) {
1499
actionEditUndo->setEnabled( FALSE );
1500
actionEditRedo->setEnabled( FALSE );
1504
void MainWindow::updateEditorUndoRedo()
1506
if ( !qWorkspace()->activeWindow() ||
1507
!::qt_cast<SourceEditor*>(qWorkspace()->activeWindow()) )
1509
SourceEditor *editor = (SourceEditor*)qWorkspace()->activeWindow();
1510
actionEditUndo->setEnabled( editor->editIsUndoAvailable() );
1511
actionEditRedo->setEnabled( editor->editIsRedoAvailable() );
1514
QWorkspace *MainWindow::qWorkspace() const
1519
void MainWindow::popupFormWindowMenu( const QPoint & gp, FormWindow *fw )
1521
QValueList<uint> ids;
1522
QMap<QString, int> commands;
1524
setupRMBSpecialCommands( ids, commands, fw );
1525
setupRMBProperties( ids, commands, fw );
1527
qApp->processEvents();
1528
int r = rmbFormWindow->exec( gp );
1530
handleRMBProperties( r, commands, fw );
1531
handleRMBSpecialCommands( r, commands, fw );
1533
for ( QValueList<uint>::ConstIterator i = ids.begin(); i != ids.end(); ++i )
1534
rmbFormWindow->removeItem( *i );
1537
void MainWindow::popupWidgetMenu( const QPoint &gp, FormWindow * /*fw*/, QWidget * w)
1539
QValueList<uint> ids;
1540
QMap<QString, int> commands;
1542
setupRMBSpecialCommands( ids, commands, w );
1543
setupRMBProperties( ids, commands, w );
1545
qApp->processEvents();
1546
int r = rmbWidgets->exec( gp );
1548
handleRMBProperties( r, commands, w );
1549
handleRMBSpecialCommands( r, commands, w );
1551
for ( QValueList<uint>::ConstIterator i = ids.begin(); i != ids.end(); ++i )
1552
rmbWidgets->removeItem( *i );
1555
void MainWindow::setupRMBProperties( QValueList<uint> &ids, QMap<QString, int> &props, QWidget *w )
1557
const QMetaProperty* text = w->metaObject()->property( w->metaObject()->findProperty( "text", TRUE ), TRUE );
1558
if ( text && qstrcmp( text->type(), "QString") != 0 )
1560
const QMetaProperty* title = w->metaObject()->property( w->metaObject()->findProperty( "title", TRUE ), TRUE );
1561
if ( title && qstrcmp( title->type(), "QString") != 0 )
1563
const QMetaProperty* pagetitle =
1564
w->metaObject()->property( w->metaObject()->findProperty( "pageTitle", TRUE ), TRUE );
1565
if ( pagetitle && qstrcmp( pagetitle->type(), "QString") != 0 )
1567
const QMetaProperty* pixmap =
1568
w->metaObject()->property( w->metaObject()->findProperty( "pixmap", TRUE ), TRUE );
1569
if ( pixmap && qstrcmp( pixmap->type(), "QPixmap") != 0 )
1572
if ( text && text->designable(w) ||
1573
title && title->designable(w) ||
1574
pagetitle && pagetitle->designable(w) ||
1575
pixmap && pixmap->designable(w) ) {
1577
if ( ids.isEmpty() )
1578
ids << rmbWidgets->insertSeparator(0);
1579
if ( pixmap && pixmap->designable(w) ) {
1580
ids << ( id = rmbWidgets->insertItem( i18n("Choose Pixmap..."), -1, 0) );
1581
props.insert( "pixmap", id );
1583
if ( text && text->designable(w) && !::qt_cast<QTextEdit*>(w) ) {
1584
ids << ( id = rmbWidgets->insertItem( i18n("Edit Text..."), -1, 0) );
1585
props.insert( "text", id );
1587
if ( title && title->designable(w) ) {
1588
ids << ( id = rmbWidgets->insertItem( i18n("Edit Title..."), -1, 0) );
1589
props.insert( "title", id );
1591
if ( pagetitle && pagetitle->designable(w) ) {
1592
ids << ( id = rmbWidgets->insertItem( i18n("Edit Page Title..."), -1, 0) );
1593
props.insert( "pagetitle", id );
1598
#ifdef QT_CONTAINER_CUSTOM_WIDGETS
1599
static QWidgetContainerInterfacePrivate *containerWidgetInterface( QWidget *w )
1601
WidgetInterface *iface = 0;
1602
widgetManager()->queryInterface( WidgetFactory::classNameOf( w ), &iface );
1605
QWidgetContainerInterfacePrivate *iface2 = 0;
1606
iface->queryInterface( IID_QWidgetContainer, (QUnknownInterface**)&iface2 );
1614
void MainWindow::setupRMBSpecialCommands( QValueList<uint> &ids,
1615
QMap<QString, int> &commands, QWidget *w )
1619
if ( ::qt_cast<QTabWidget*>(w) ) {
1620
if ( ids.isEmpty() )
1621
ids << rmbWidgets->insertSeparator( 0 );
1622
if ( ( (QDesignerTabWidget*)w )->count() > 1) {
1623
ids << ( id = rmbWidgets->insertItem( i18n("Delete Page"), -1, 0 ) );
1624
commands.insert( "remove", id );
1626
ids << ( id = rmbWidgets->insertItem( i18n("Add Page"), -1, 0 ) );
1627
commands.insert( "add", id );
1628
} else if ( ::qt_cast<QDesignerWidgetStack*>(w) ) {
1629
if ( ids.isEmpty() )
1630
ids << rmbWidgets->insertSeparator( 0 );
1631
if ( ( (QDesignerWidgetStack*)w )->count() > 1) {
1632
ids << ( id = rmbWidgets->insertItem( i18n("Previous Page"), -1, 0 ) );
1633
commands.insert( "prevpage", id );
1634
ids << ( id = rmbWidgets->insertItem( i18n("Next Page"), -1, 0 ) );
1635
ids << rmbWidgets->insertSeparator( 0 );
1636
commands.insert( "nextpage", id );
1637
ids << ( id = rmbWidgets->insertItem( i18n("Delete Page"), -1, 0 ) );
1638
commands.insert( "remove", id );
1640
ids << ( id = rmbWidgets->insertItem( i18n("Add Page"), -1, 0 ) );
1641
commands.insert( "add", id );
1642
} else if ( ::qt_cast<QToolBox*>(w) ) {
1643
if ( ids.isEmpty() )
1644
ids << rmbWidgets->insertSeparator( 0 );
1645
if ( ( (QToolBox*)w )->count() > 1 ) {
1646
ids << ( id = rmbWidgets->insertItem( i18n("Delete Page"), -1, 0 ) );
1647
commands.insert( "remove", id );
1649
ids << ( id = rmbWidgets->insertItem( i18n("Add Page"), -1, 0 ) );
1650
commands.insert( "add", id );
1651
#ifdef QT_CONTAINER_CUSTOM_WIDGETS
1652
} else if ( WidgetDatabase::
1653
isCustomPluginWidget( WidgetDatabase::
1654
idFromClassName( WidgetFactory::classNameOf( w ) ) ) ) {
1655
QWidgetContainerInterfacePrivate *iface = containerWidgetInterface( w );
1656
if ( iface && iface->supportsPages( WidgetFactory::classNameOf( w ) ) ) {
1657
if ( ids.isEmpty() )
1658
ids << rmbWidgets->insertSeparator( 0 );
1660
if ( iface->count( WidgetFactory::classNameOf( w ), w ) > 1 ) {
1661
ids << ( id = rmbWidgets->insertItem( i18n( "Delete Page" ), -1, 0 ) );
1662
commands.insert( "remove", id );
1664
ids << ( id = rmbWidgets->insertItem( i18n("Add Page"), -1, 0 ) );
1665
commands.insert( "add", id );
1666
if ( iface->currentIndex( WidgetFactory::classNameOf( w ), w ) != -1 ) {
1667
ids << ( id = rmbWidgets->insertItem( i18n("Rename Current Page..."), -1, 0 ) );
1668
commands.insert( "rename", id );
1673
#endif // QT_CONTAINER_CUSTOM_WIDGETS
1676
if ( WidgetFactory::hasSpecialEditor( WidgetDatabase::
1677
idFromClassName( WidgetFactory::classNameOf( w ) ), w ) ) {
1678
if ( ids.isEmpty() )
1679
ids << rmbWidgets->insertSeparator( 0 );
1680
ids << ( id = rmbWidgets->insertItem( i18n("Edit..."), -1, 0 ) );
1681
commands.insert( "edit", id );
1685
void MainWindow::setupRMBSpecialCommands( QValueList<uint> &ids,
1686
QMap<QString, int> &commands, FormWindow *fw )
1690
if ( ::qt_cast<QWizard*>(fw->mainContainer()) ) {
1691
if ( ids.isEmpty() )
1692
ids << rmbFormWindow->insertSeparator( 0 );
1694
if ( ( (QWizard*)fw->mainContainer() )->pageCount() > 1) {
1695
ids << ( id = rmbFormWindow->insertItem( i18n("Delete Page"), -1, 0 ) );
1696
commands.insert( "remove", id );
1699
ids << ( id = rmbFormWindow->insertItem( i18n("Add Page"), -1, 0 ) );
1700
commands.insert( "add", id );
1702
ids << ( id = rmbFormWindow->insertItem( i18n("Edit Page Title..."), -1, 0 ) );
1703
commands.insert( "rename", id );
1705
ids << ( id = rmbFormWindow->insertItem( i18n("Edit Pages..."), -1, 0 ) );
1706
commands.insert( "edit", id );
1708
} else if ( ::qt_cast<QMainWindow*>(fw->mainContainer()) ) {
1709
if ( ids.isEmpty() )
1710
ids << rmbFormWindow->insertSeparator( 0 );
1711
ids << ( id = rmbFormWindow->insertItem( i18n( "Add Menu Item" ), -1, 0 ) );
1712
commands.insert( "add_menu_item", id );
1713
ids << ( id = rmbFormWindow->insertItem( i18n( "Add Toolbar" ), -1, 0 ) );
1714
commands.insert( "add_toolbar", id );
1718
void MainWindow::handleRMBProperties( int id, QMap<QString, int> &props, QWidget *w )
1720
if ( id == props[ "text" ] ) {
1722
bool oldDoWrap = FALSE;
1723
if ( ::qt_cast<QLabel*>(w) ) {
1724
int align = w->property( "alignment" ).toInt();
1725
if ( align & WordBreak )
1728
bool doWrap = oldDoWrap;
1731
if ( ::qt_cast<QTextView*>(w) || ::qt_cast<QLabel*>(w) || ::qt_cast<QButton*>(w) ) {
1732
text = MultiLineEditor::getText( this, w->property( "text" ).toString(), !::qt_cast<QButton*>(w), &doWrap );
1733
ok = !text.isNull();
1735
text = QInputDialog::getText( i18n("Text"), i18n( "New text" ),
1736
QLineEdit::Normal, w->property("text").toString(), &ok, this );
1739
if ( oldDoWrap != doWrap ) {
1740
QString pn( i18n( "Set 'wordwrap' of '%1'" ).arg( w->name() ) );
1741
SetPropertyCommand *cmd = new SetPropertyCommand( pn, formWindow(), w, propertyEditor,
1742
"wordwrap", QVariant( oldDoWrap, 0 ),
1743
QVariant( doWrap, 0 ), QString::null, QString::null );
1745
formWindow()->commandHistory()->addCommand( cmd );
1746
MetaDataBase::setPropertyChanged( w, "wordwrap", TRUE );
1749
QString pn( i18n( "Set the 'text' of '%1'" ).arg( w->name() ) );
1750
SetPropertyCommand *cmd = new SetPropertyCommand( pn, formWindow(), w, propertyEditor,
1751
"text", w->property( "text" ),
1752
text, QString::null, QString::null );
1754
formWindow()->commandHistory()->addCommand( cmd );
1755
MetaDataBase::setPropertyChanged( w, "text", TRUE );
1757
} else if ( id == props[ "title" ] ) {
1759
QString title = QInputDialog::getText( i18n("Title"), i18n( "New title" ),
1760
QLineEdit::Normal, w->property("title").toString(), &ok, this );
1762
QString pn( i18n( "Set the 'title' of '%2'" ).arg( w->name() ) );
1763
SetPropertyCommand *cmd = new SetPropertyCommand( pn, formWindow(), w, propertyEditor,
1764
"title", w->property( "title" ),
1765
title, QString::null, QString::null );
1767
formWindow()->commandHistory()->addCommand( cmd );
1768
MetaDataBase::setPropertyChanged( w, "title", TRUE );
1770
} else if ( id == props[ "pagetitle" ] ) {
1772
QString text = QInputDialog::getText( i18n("Page Title"), i18n( "New page title" ),
1773
QLineEdit::Normal, w->property("pageTitle").toString(), &ok, this );
1775
QString pn( i18n( "Set the 'pageTitle' of '%2'" ).arg( w->name() ) );
1776
SetPropertyCommand *cmd = new SetPropertyCommand( pn, formWindow(), w, propertyEditor,
1778
w->property( "pageTitle" ),
1779
text, QString::null, QString::null );
1781
formWindow()->commandHistory()->addCommand( cmd );
1782
MetaDataBase::setPropertyChanged( w, "pageTitle", TRUE );
1784
} else if ( id == props[ "pixmap" ] ) {
1785
QPixmap oldPix = w->property( "pixmap" ).toPixmap();
1786
QPixmap pix = qChoosePixmap( this, formWindow(), oldPix );
1787
if ( !pix.isNull() ) {
1788
QString pn( i18n( "Set the 'pixmap' of '%2'" ).arg( w->name() ) );
1789
SetPropertyCommand *cmd = new SetPropertyCommand( pn, formWindow(), w, propertyEditor,
1790
"pixmap", w->property( "pixmap" ),
1791
pix, QString::null, QString::null );
1793
formWindow()->commandHistory()->addCommand( cmd );
1794
MetaDataBase::setPropertyChanged( w, "pixmap", TRUE );
1799
void MainWindow::handleRMBSpecialCommands( int id, QMap<QString, int> &commands, QWidget *w )
1801
if ( ::qt_cast<QTabWidget*>(w) ) {
1802
QTabWidget *tw = (QTabWidget*)w;
1803
if ( id == commands[ "add" ] ) {
1804
AddTabPageCommand *cmd =
1805
new AddTabPageCommand( i18n( "Add Page to %1" ).arg( tw->name() ), formWindow(),
1807
formWindow()->commandHistory()->addCommand( cmd );
1809
} else if ( id == commands[ "remove" ] ) {
1810
if ( tw->currentPage() ) {
1811
QDesignerTabWidget *dtw = (QDesignerTabWidget*)tw;
1812
DeleteTabPageCommand *cmd =
1813
new DeleteTabPageCommand( i18n( "Delete Page %1 of %2" ).
1814
arg( dtw->pageTitle() ).arg( tw->name() ),
1815
formWindow(), tw, tw->currentPage() );
1816
formWindow()->commandHistory()->addCommand( cmd );
1820
} else if ( ::qt_cast<QToolBox*>(w) ) {
1821
QToolBox *tb = (QToolBox*)w;
1822
if ( id == commands[ "add" ] ) {
1823
AddToolBoxPageCommand *cmd =
1824
new AddToolBoxPageCommand( i18n( "Add Page to %1" ).arg( tb->name() ),
1827
formWindow()->commandHistory()->addCommand( cmd );
1829
} else if ( id == commands[ "remove" ] ) {
1830
if ( tb->currentItem() ) {
1831
DeleteToolBoxPageCommand *cmd =
1832
new DeleteToolBoxPageCommand( i18n( "Delete Page %1 of %2" ).
1833
arg( tb->itemLabel( tb->currentIndex() ) ).
1835
formWindow(), tb, tb->currentItem() );
1836
formWindow()->commandHistory()->addCommand( cmd );
1840
} else if ( ::qt_cast<QWidgetStack*>(w) ) {
1841
QDesignerWidgetStack *ws = (QDesignerWidgetStack*)w;
1842
if ( id == commands[ "add" ] ) {
1843
AddWidgetStackPageCommand *cmd =
1844
new AddWidgetStackPageCommand( i18n( "Add Page to %1" ).arg( ws->name() ),
1846
formWindow()->commandHistory()->addCommand( cmd );
1848
} else if ( id == commands[ "remove" ] ) {
1849
if ( ws->visibleWidget() ) {
1850
DeleteWidgetStackPageCommand *cmd =
1851
new DeleteWidgetStackPageCommand( i18n( "Delete Page %1 of %2" ).
1852
arg( ws->currentPage() ).arg( ws->name() ),
1853
formWindow(), ws, ws->visibleWidget() );
1854
formWindow()->commandHistory()->addCommand( cmd );
1857
} else if ( id == commands[ "nextpage" ] ) {
1858
int currentPage = w->property( "currentPage" ).toInt();
1859
QString pn( i18n( "Raise next page of '%2'" ).arg( w->name() ) );
1860
SetPropertyCommand *cmd =
1861
new SetPropertyCommand( pn, formWindow(), w, propertyEditor,
1862
"currentPage", currentPage,
1863
currentPage + 1, QString::null, QString::null );
1865
formWindow()->commandHistory()->addCommand( cmd );
1866
MetaDataBase::setPropertyChanged( w, "currentPage", TRUE );
1867
} else if ( id == commands[ "prevpage" ] ) {
1868
int currentPage = w->property( "currentPage" ).toInt();
1869
QString pn( i18n( "Raise previous page of '%2'" ).arg( w->name() ) );
1870
SetPropertyCommand *cmd =
1871
new SetPropertyCommand( pn, formWindow(), w, propertyEditor,
1872
"currentPage", currentPage,
1873
currentPage -1, QString::null, QString::null );
1875
formWindow()->commandHistory()->addCommand( cmd );
1876
MetaDataBase::setPropertyChanged( w, "currentPage", TRUE );
1878
#ifdef QT_CONTAINER_CUSTOM_WIDGETS
1879
} else if ( WidgetDatabase::
1880
isCustomPluginWidget( WidgetDatabase::
1881
idFromClassName( WidgetFactory::classNameOf( w ) ) ) ) {
1882
if ( id == commands[ "add" ] ) {
1883
AddContainerPageCommand *cmd =
1884
new AddContainerPageCommand( i18n( "Add Page to %1" ).arg( w->name() ),
1885
formWindow(), w, "Page" );
1886
formWindow()->commandHistory()->addCommand( cmd );
1888
} else if ( id == commands[ "remove" ] ) {
1889
QWidgetContainerInterfacePrivate *iface = containerWidgetInterface( w );
1891
QString wClassName = WidgetFactory::classNameOf( w );
1892
int index = iface->currentIndex( wClassName, w );
1893
DeleteContainerPageCommand *cmd =
1894
new DeleteContainerPageCommand( i18n( "Delete Page %1 of %2" ).
1895
arg( iface->pageLabel( wClassName,
1898
formWindow(), w, index );
1899
formWindow()->commandHistory()->addCommand( cmd );
1903
} else if ( id == commands[ "rename" ] ) {
1904
QWidgetContainerInterfacePrivate *iface = containerWidgetInterface( w );
1907
QString wClassName = WidgetFactory::classNameOf( w );
1908
int index = iface->currentIndex( wClassName, w );
1909
QString text = QInputDialog::getText( i18n("Page Title"), i18n( "New page title" ),
1911
iface->pageLabel( wClassName, w,
1915
RenameContainerPageCommand *cmd =
1916
new RenameContainerPageCommand( i18n( "Rename Page %1 to %2" ).
1918
pageLabel( wClassName, w,
1920
arg( text ), formWindow(),
1922
formWindow()->commandHistory()->addCommand( cmd );
1928
#endif // QT_CONTAINER_CUSTOM_WIDGETS
1931
if ( WidgetFactory::hasSpecialEditor( WidgetDatabase::
1932
idFromClassName( WidgetFactory::classNameOf( w ) ), w ) ) {
1933
if ( id == commands[ "edit" ] )
1934
WidgetFactory::editWidget( WidgetDatabase::
1935
idFromClassName( WidgetFactory::classNameOf( w ) ), this, w, formWindow() );
1939
void MainWindow::handleRMBSpecialCommands( int id, QMap<QString, int> &commands, FormWindow *fw )
1941
if ( ::qt_cast<QWizard*>(fw->mainContainer()) ) {
1942
QWizard *wiz = (QWizard*)fw->mainContainer();
1943
if ( id == commands[ "add" ] ) {
1944
AddWizardPageCommand *cmd =
1945
new AddWizardPageCommand( i18n( "Add Page to %1" ).arg( wiz->name() ),
1946
formWindow(), wiz, "WizardPage" );
1947
formWindow()->commandHistory()->addCommand( cmd );
1949
} else if ( id == commands[ "remove" ] ) {
1950
if ( wiz->currentPage() ) {
1951
QDesignerWizard *dw = (QDesignerWizard*)wiz;
1952
DeleteWizardPageCommand *cmd =
1953
new DeleteWizardPageCommand( i18n( "Delete Page %1 of %2" ).
1954
arg( dw->pageTitle() ).arg( wiz->name() ),
1956
wiz->indexOf( wiz->currentPage() ) );
1957
formWindow()->commandHistory()->addCommand( cmd );
1960
} else if ( id == commands[ "edit" ] ) {
1961
WizardEditor *e = new WizardEditor( this, wiz, fw );
1964
} else if ( id == commands[ "rename" ] ) {
1967
QDesignerWizard *dw = (QDesignerWizard*)wiz;
1968
QString text = QInputDialog::getText( i18n("Page Title"), i18n( "New page title" ),
1969
QLineEdit::Normal, dw->pageTitle(), &ok, this );
1971
QString pn( i18n( "Rename page %1 of %2" ).arg( dw->pageTitle() ).arg( wiz->name() ) );
1972
RenameWizardPageCommand *cmd =
1973
new RenameWizardPageCommand( pn, formWindow()
1974
, wiz, wiz->indexOf( wiz->currentPage() ), text );
1975
formWindow()->commandHistory()->addCommand( cmd );
1979
} else if ( ::qt_cast<QMainWindow*>(fw->mainContainer()) ) {
1980
QMainWindow *mw = (QMainWindow*)fw->mainContainer();
1981
if ( id == commands[ "add_toolbar" ] ) {
1982
AddToolBarCommand *cmd =
1983
new AddToolBarCommand( i18n( "Add Toolbar to '%1'" ).arg( formWindow()->name() ),
1985
formWindow()->commandHistory()->addCommand( cmd );
1987
} else if ( id == commands[ "add_menu_item" ] ) {
1988
AddMenuCommand *cmd =
1989
new AddMenuCommand( i18n( "Add Menu to '%1'" ).arg( formWindow()->name() ),
1991
formWindow()->commandHistory()->addCommand( cmd );
1997
void MainWindow::clipboardChanged()
1999
QString text( qApp->clipboard()->text() );
2000
QString start( "<!DOCTYPE UI-SELECTION>" );
2001
actionEditPaste->setEnabled( text.left( start.length() ) == start );
2004
void MainWindow::selectionChanged()
2006
layoutChilds = FALSE;
2007
layoutSelected = FALSE;
2008
breakLayout = FALSE;
2009
if ( !formWindow() ) {
2010
actionEditCut->setEnabled( FALSE );
2011
actionEditCopy->setEnabled( FALSE );
2012
actionEditDelete->setEnabled( FALSE );
2013
actionEditAdjustSize->setEnabled( FALSE );
2014
actionEditHLayout->setEnabled( FALSE );
2015
actionEditVLayout->setEnabled( FALSE );
2016
actionEditSplitHorizontal->setEnabled( FALSE );
2017
actionEditSplitVertical->setEnabled( FALSE );
2018
actionEditGridLayout->setEnabled( FALSE );
2019
actionEditBreakLayout->setEnabled( FALSE );
2020
actionEditLower->setEnabled( FALSE );
2021
actionEditRaise->setEnabled( FALSE );
2022
actionEditAdjustSize->setEnabled( FALSE );
2026
int selectedWidgets = formWindow()->numSelectedWidgets();
2027
bool enable = selectedWidgets > 0;
2028
actionEditCut->setEnabled( enable );
2029
actionEditCopy->setEnabled( enable );
2030
actionEditDelete->setEnabled( enable );
2031
actionEditLower->setEnabled( enable );
2032
actionEditRaise->setEnabled( enable );
2034
actionEditAdjustSize->setEnabled( FALSE );
2035
actionEditSplitHorizontal->setEnabled( FALSE );
2036
actionEditSplitVertical->setEnabled( FALSE );
2039
QWidgetList widgets = formWindow()->selectedWidgets();
2040
if ( selectedWidgets > 1 ) {
2043
for ( QWidget *w = widgets.first(); w; w = widgets.next() ) {
2044
if ( !w->parentWidget() || WidgetFactory::layoutType( w->parentWidget() ) == WidgetFactory::NoLayout )
2049
actionEditHLayout->setEnabled( unlaidout > 1 );
2050
actionEditVLayout->setEnabled( unlaidout > 1 );
2051
actionEditSplitHorizontal->setEnabled( unlaidout > 1 );
2052
actionEditSplitVertical->setEnabled( unlaidout > 1 );
2053
actionEditGridLayout->setEnabled( unlaidout > 1 );
2054
actionEditBreakLayout->setEnabled( laidout > 0 );
2055
actionEditAdjustSize->setEnabled( laidout > 0 );
2056
layoutSelected = unlaidout > 1;
2057
breakLayout = laidout > 0;
2058
} else if ( selectedWidgets == 1 ) {
2059
QWidget *w = widgets.first();
2060
bool isContainer = WidgetDatabase::isContainer( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( w ) ) ) ||
2061
w == formWindow()->mainContainer();
2062
actionEditAdjustSize->setEnabled( !w->parentWidget() ||
2063
WidgetFactory::layoutType( w->parentWidget() ) == WidgetFactory::NoLayout );
2065
if ( !isContainer ) {
2066
actionEditHLayout->setEnabled( FALSE );
2067
actionEditVLayout->setEnabled( FALSE );
2068
actionEditGridLayout->setEnabled( FALSE );
2069
if ( w->parentWidget() && WidgetFactory::layoutType( w->parentWidget() ) != WidgetFactory::NoLayout ) {
2070
actionEditBreakLayout->setEnabled( !isAToolBarChild( w ) );
2073
actionEditBreakLayout->setEnabled( FALSE );
2076
if ( WidgetFactory::layoutType( w ) == WidgetFactory::NoLayout ) {
2077
if ( !formWindow()->hasInsertedChildren( w ) ) {
2078
actionEditHLayout->setEnabled( FALSE );
2079
actionEditVLayout->setEnabled( FALSE );
2080
actionEditGridLayout->setEnabled( FALSE );
2081
actionEditBreakLayout->setEnabled( FALSE );
2083
actionEditHLayout->setEnabled( TRUE );
2084
actionEditVLayout->setEnabled( TRUE );
2085
actionEditGridLayout->setEnabled( TRUE );
2086
actionEditBreakLayout->setEnabled( FALSE );
2087
layoutChilds = TRUE;
2089
if ( w->parentWidget() && WidgetFactory::layoutType( w->parentWidget() ) != WidgetFactory::NoLayout ) {
2090
actionEditBreakLayout->setEnabled( !isAToolBarChild( w ) );
2094
actionEditHLayout->setEnabled( FALSE );
2095
actionEditVLayout->setEnabled( FALSE );
2096
actionEditGridLayout->setEnabled( FALSE );
2097
actionEditBreakLayout->setEnabled( !isAToolBarChild( w ) );
2101
} else if ( selectedWidgets == 0 ) {
2102
actionEditAdjustSize->setEnabled( TRUE );
2103
QWidget *w = formWindow()->mainContainer();
2104
if ( WidgetFactory::layoutType( w ) == WidgetFactory::NoLayout ) {
2105
if ( !formWindow()->hasInsertedChildren( w ) ) {
2106
actionEditHLayout->setEnabled( FALSE );
2107
actionEditVLayout->setEnabled( FALSE );
2108
actionEditGridLayout->setEnabled( FALSE );
2109
actionEditBreakLayout->setEnabled( FALSE );
2111
actionEditHLayout->setEnabled( TRUE );
2112
actionEditVLayout->setEnabled( TRUE );
2113
actionEditGridLayout->setEnabled( TRUE );
2114
actionEditBreakLayout->setEnabled( FALSE );
2115
layoutChilds = TRUE;
2118
actionEditHLayout->setEnabled( FALSE );
2119
actionEditVLayout->setEnabled( FALSE );
2120
actionEditGridLayout->setEnabled( FALSE );
2121
actionEditBreakLayout->setEnabled( TRUE );
2125
actionEditHLayout->setEnabled( FALSE );
2126
actionEditVLayout->setEnabled( FALSE );
2127
actionEditGridLayout->setEnabled( FALSE );
2128
actionEditBreakLayout->setEnabled( FALSE );
2132
static QString fixArgs( const QString &s2 )
2135
return s.replace( ',', ';' );
2138
void MainWindow::writeConfig()
2142
// No search path for unix, only needs application name
2143
config.insertSearchPath( QSettings::Windows, "/Trolltech" );
2145
QString keybase = DesignerApplication::settingsKey();
2147
if (savePluginPaths) {
2148
QStringList pluginPaths = QApplication::libraryPaths();
2149
config.writeEntry( keybase + "PluginPaths", pluginPaths );
2151
config.writeEntry( keybase + "RestoreWorkspace", restoreConfig );
2152
config.writeEntry( keybase + "SplashScreen", splashScreen );
2153
config.writeEntry( keybase + "ShowStartDialog", shStartDialog );
2154
config.writeEntry( keybase + "FileFilter", fileFilter );
2155
config.writeEntry( keybase + "TemplatePath", templPath );
2156
config.writeEntry( keybase + "RecentlyOpenedFiles", recentlyFiles );
2157
config.writeEntry( keybase + "RecentlyOpenedProjects", recentlyProjects );
2158
config.writeEntry( keybase + "DatabaseAutoEdit", databaseAutoEdit );
2160
config.writeEntry( keybase + "AutoSave/Enabled", autoSaveEnabled );
2161
config.writeEntry( keybase + "AutoSave/Interval", autoSaveInterval );
2163
config.writeEntry( keybase + "Grid/Snap", snGrid );
2164
config.writeEntry( keybase + "Grid/Show", sGrid );
2165
config.writeEntry( keybase + "Grid/x", grid().x() );
2166
config.writeEntry( keybase + "Grid/y", grid().y() );
2167
config.writeEntry( keybase + "LastToolPage",
2168
toolBox->itemLabel( toolBox->currentIndex() ) );
2170
config.writeEntry( keybase + "Background/UsePixmap", backPix );
2171
config.writeEntry( keybase + "Background/Color", (int)qworkspace->backgroundColor().rgb() );
2172
if ( qworkspace->backgroundPixmap() )
2173
qworkspace->backgroundPixmap()->save( QDir::home().absPath() + "/.designer/" + "background.xpm", "PNG" );
2175
config.writeEntry( keybase + "Geometries/MainwindowX", x() );
2176
config.writeEntry( keybase + "Geometries/MainwindowY", y() );
2177
config.writeEntry( keybase + "Geometries/MainwindowWidth", width() );
2178
config.writeEntry( keybase + "Geometries/MainwindowHeight", height() );
2179
config.writeEntry( keybase + "Geometries/MainwindowMaximized", isMaximized() );
2180
config.writeEntry( keybase + "Geometries/PropertyEditorX", propertyEditor->parentWidget()->x() );
2181
config.writeEntry( keybase + "Geometries/PropertyEditorY", propertyEditor->parentWidget()->y() );
2182
config.writeEntry( keybase + "Geometries/PropertyEditorWidth", propertyEditor->parentWidget()->width() );
2183
config.writeEntry( keybase + "Geometries/PropertyEditorHeight", propertyEditor->parentWidget()->height() );
2184
config.writeEntry( keybase + "Geometries/HierarchyViewX", hierarchyView->parentWidget()->x() );
2185
config.writeEntry( keybase + "Geometries/HierarchyViewY", hierarchyView->parentWidget()->y() );
2186
config.writeEntry( keybase + "Geometries/HierarchyViewWidth", hierarchyView->parentWidget()->width() );
2187
config.writeEntry( keybase + "Geometries/HierarchyViewHeight", hierarchyView->parentWidget()->height() );
2188
config.writeEntry( keybase + "Geometries/WorkspaceX", wspace->parentWidget()->x() );
2189
config.writeEntry( keybase + "Geometries/WorkspaceY", wspace->parentWidget()->y() );
2190
config.writeEntry( keybase + "Geometries/WorkspaceWidth", wspace->parentWidget()->width() );
2191
config.writeEntry( keybase + "Geometries/WorkspaceHeight", wspace->parentWidget()->height() );
2193
config.writeEntry( keybase + "View/TextLabels", usesTextLabel() );
2194
config.writeEntry( keybase + "View/BigIcons", usesBigPixmaps() );
2196
QString mwlKey = "MainwindowLayout";
2197
if ( singleProjectMode() )
2199
QString mainWindowLayout;
2200
QTextStream ts( &mainWindowLayout, IO_WriteOnly );
2202
config.writeEntry( keybase + mwlKey, mainWindowLayout );
2205
QPtrList<MetaDataBase::CustomWidget> *lst = MetaDataBase::customWidgets();
2206
config.writeEntry( keybase + "CustomWidgets/num", (int)lst->count() );
2208
QDir::home().mkdir( ".designer" );
2209
for ( MetaDataBase::CustomWidget *w = lst->first(); w; w = lst->next() ) {
2212
l << w->includeFile;
2213
l << QString::number( (int)w->includePolicy );
2214
l << QString::number( w->sizeHint.width() );
2215
l << QString::number( w->sizeHint.height() );
2216
l << QString::number( w->lstSignals.count() );
2217
for ( QValueList<QCString>::ConstIterator it = w->lstSignals.begin(); it != w->lstSignals.end(); ++it )
2218
l << QString( fixArgs( *it ) );
2219
l << QString::number( w->lstSlots.count() );
2220
for ( QValueList<MetaDataBase::Function>::ConstIterator it2 = w->lstSlots.begin(); it2 != w->lstSlots.end(); ++it2 ) {
2221
l << fixArgs( (*it2).function );
2224
l << QString::number( w->lstProperties.count() );
2225
for ( QValueList<MetaDataBase::Property>::ConstIterator it3 = w->lstProperties.begin(); it3 != w->lstProperties.end(); ++it3 ) {
2226
l << (*it3).property;
2229
l << QString::number( size_type_to_int( w->sizePolicy.horData() ) );
2230
l << QString::number( size_type_to_int( w->sizePolicy.verData() ) );
2231
l << QString::number( (int)w->isContainer );
2232
config.writeEntry( keybase + "CustomWidgets/Widget" + QString::number( j++ ), l, ',' );
2233
w->pixmap->save( QDir::home().absPath() + "/.designer/" + w->className, "XPM" );
2237
for ( QAction *a = commonWidgetsPage.first(); a; a = commonWidgetsPage.next() )
2239
config.writeEntry( keybase + "ToolBox/CommonWidgets", l );
2242
static QString fixArgs2( const QString &s2 )
2245
return s.replace( ';', ',' );
2248
void MainWindow::readConfig()
2250
QString keybase = DesignerApplication::settingsKey();
2252
config.insertSearchPath( QSettings::Windows, "/Trolltech" );
2255
bool readPreviousConfig = FALSE;
2256
QString backPixName( QDir::home().absPath() + "/.designer/" + "background.xpm" );
2257
restoreConfig = config.readBoolEntry( keybase + "RestoreWorkspace", TRUE, &ok );
2259
keybase = DesignerApplication::oldSettingsKey();
2260
restoreConfig = config.readBoolEntry( keybase + "RestoreWorkspace", TRUE, &ok );
2263
oWindow->shuttingDown();
2264
( (QDockWindow*)oWindow->parent() )->hide();
2267
pix.load( backPixName );
2268
if ( !pix.isNull() )
2269
qworkspace->setBackgroundPixmap( pix );
2272
readPreviousConfig = TRUE;
2274
if ( !readPreviousConfig ) {
2275
fileFilter = config.readEntry( keybase + "FileFilter", fileFilter );
2276
templPath = config.readEntry( keybase + "TemplatePath", QString::null );
2277
databaseAutoEdit = config.readBoolEntry( keybase + "DatabaseAutoEdit", databaseAutoEdit );
2278
shStartDialog = config.readBoolEntry( keybase + "ShowStartDialog", shStartDialog );
2279
autoSaveEnabled = config.readBoolEntry( keybase + "AutoSave/Enabled", autoSaveEnabled );
2280
autoSaveInterval = config.readNumEntry( keybase + "AutoSave/Interval", autoSaveInterval );
2283
if ( restoreConfig || readPreviousConfig ) {
2284
QString s = config.readEntry( keybase + "LastToolPage" );
2285
for ( int i = 0; i < toolBox->count(); ++i ) {
2286
if ( toolBox->itemLabel(i) == s ) {
2287
toolBox->setCurrentIndex( i );
2291
// We know that the oldSettingsKey() will return 3.1
2292
if ( keybase == DesignerApplication::oldSettingsKey() ) {
2293
if (keybase.contains("3.1"))
2294
recentlyFiles = config.readListEntry( keybase + "RecentlyOpenedFiles", ',' );
2296
recentlyFiles = config.readListEntry(keybase + "RecentlyOpenedFiles");
2298
if ( recentlyFiles.count() == 1 && recentlyFiles[0].isNull() )
2299
recentlyFiles.clear();
2300
if (keybase.contains("3.1"))
2301
recentlyProjects = config.readListEntry( keybase + "RecentlyOpenedProjects", ',' );
2303
recentlyProjects = config.readListEntry( keybase + "RecentlyOpenedProjects");
2304
if ( recentlyProjects.count() == 1 && recentlyProjects[0].isNull() )
2305
recentlyProjects.clear();
2307
recentlyFiles = config.readListEntry( keybase + "RecentlyOpenedFiles" );
2308
recentlyProjects = config.readListEntry( keybase + "RecentlyOpenedProjects" );
2311
backPix = config.readBoolEntry( keybase + "Background/UsePixmap", TRUE ) | readPreviousConfig;
2314
pix.load( backPixName );
2315
if ( !pix.isNull() )
2316
qworkspace->setBackgroundPixmap( pix );
2318
qworkspace->setBackgroundColor( QColor( (QRgb)config.readNumEntry( keybase + "Background/Color" ) ) );
2321
if ( !readPreviousConfig ) {
2322
splashScreen = config.readBoolEntry( keybase + "SplashScreen", TRUE );
2324
sGrid = config.readBoolEntry( keybase + "Grid/Show", TRUE );
2325
snGrid = config.readBoolEntry( keybase + "Grid/Snap", TRUE );
2326
grd.setX( config.readNumEntry( keybase + "Grid/x", 10 ) );
2327
grd.setY( config.readNumEntry( keybase + "Grid/y", 10 ) );
2329
if ( !config.readBoolEntry( DesignerApplication::settingsKey() + "Geometries/MainwindowMaximized", FALSE ) ) {
2330
QRect r( pos(), size() );
2331
r.setX( config.readNumEntry( keybase + "Geometries/MainwindowX", r.x() ) );
2332
r.setY( config.readNumEntry( keybase + "Geometries/MainwindowY", r.y() ) );
2333
r.setWidth( config.readNumEntry( keybase + "Geometries/MainwindowWidth", r.width() ) );
2334
r.setHeight( config.readNumEntry( keybase + "Geometries/MainwindowHeight", r.height() ) );
2336
QRect desk = QApplication::desktop()->geometry();
2337
QRect inter = desk.intersect( r );
2339
if ( inter.width() * inter.height() > ( r.width() * r.height() / 20 ) ) {
2340
move( r.topLeft() );
2343
setUsesTextLabel( config.readBoolEntry( keybase + "View/TextLabels", FALSE ) );
2344
setUsesBigPixmaps( FALSE /*config.readBoolEntry( "BigIcons", FALSE )*/ ); // ### disabled for now
2347
int num = config.readNumEntry( keybase + "CustomWidgets/num" );
2348
for ( int j = 0; j < num; ++j ) {
2349
MetaDataBase::CustomWidget *w = new MetaDataBase::CustomWidget;
2350
QStringList l = config.readListEntry( keybase + "CustomWidgets/Widget" + QString::number( j ), ',' );
2351
w->className = l[ 0 ];
2352
w->includeFile = l[ 1 ];
2353
w->includePolicy = (MetaDataBase::CustomWidget::IncludePolicy)l[ 2 ].toInt();
2354
w->sizeHint.setWidth( l[ 3 ].toInt() );
2355
w->sizeHint.setHeight( l[ 4 ].toInt() );
2357
if ( l.count() > c ) {
2358
int numSignals = l[ c ].toInt();
2360
for ( int i = 0; i < numSignals; ++i, c++ )
2361
w->lstSignals.append( fixArgs2( l[ c ] ).latin1() );
2363
if ( l.count() > c ) {
2364
int numSlots = l[ c ].toInt();
2366
for ( int i = 0; i < numSlots; ++i ) {
2367
MetaDataBase::Function slot;
2368
slot.function = fixArgs2( l[ c ] );
2370
slot.access = l[ c ];
2372
w->lstSlots.append( slot );
2375
if ( l.count() > c ) {
2376
int numProperties = l[ c ].toInt();
2378
for ( int i = 0; i < numProperties; ++i ) {
2379
MetaDataBase::Property prop;
2380
prop.property = l[ c ];
2384
w->lstProperties.append( prop );
2386
} if ( l.count() > c ) {
2387
QSizePolicy::SizeType h, v;
2388
h = int_to_size_type( l[ c++ ].toInt() );
2389
v = int_to_size_type( l[ c++ ].toInt() );
2390
w->sizePolicy = QSizePolicy( h, v );
2392
if ( l.count() > c ) {
2393
w->isContainer = (bool)l[ c++ ].toInt();
2395
w->pixmap = new QPixmap( BarIcon( QDir::home().absPath() + "/.designer/" + w->className , KDevDesignerPartFactory::instance()) );
2396
MetaDataBase::addCustomWidget( w );
2399
rebuildCustomWidgetGUI();
2401
if ( !restoreConfig )
2405
/* I'm sorry to make this not happen on the Mac, but it seems to hang somewhere deep
2406
in QLayout, it gets into a very large loop - and seems it has to do with clever
2407
things the designer does ###Sam */
2408
QApplication::sendPostedEvents();
2411
if ( !readPreviousConfig ) {
2412
QString mwlKey = "MainwindowLayout";
2413
if ( singleProjectMode() )
2415
QString mainWindowLayout = config.readEntry( keybase + mwlKey );
2416
QTextStream ts( &mainWindowLayout, IO_ReadOnly );
2419
if ( readPreviousConfig && oWindow ) {
2420
oWindow->shuttingDown();
2421
( (QDockWindow*)oWindow->parent() )->hide();
2424
rebuildCustomWidgetGUI();
2426
QStringList l = config.readListEntry( keybase + "ToolBox/CommonWidgets" );
2427
if ( !l.isEmpty() ) {
2428
QPtrList<QAction> lst;
2429
commonWidgetsPage.clear();
2430
for ( QStringList::ConstIterator it = l.begin(); it != l.end(); ++it ) {
2431
for ( QAction *a = toolActions.first(); a; a = toolActions.next() ) {
2432
if ( *it == a->text() ) {
2438
if ( lst != commonWidgetsPage ) {
2439
commonWidgetsPage = lst;
2440
rebuildCommonWidgetsToolBoxPage();
2445
HierarchyView *MainWindow::objectHierarchy() const
2447
if ( !hierarchyView )
2448
( (MainWindow*)this )->setupHierarchyView();
2449
return hierarchyView;
2452
QPopupMenu *MainWindow::setupNormalHierarchyMenu( QWidget *parent )
2454
QPopupMenu *menu = new QPopupMenu( parent );
2456
actionEditCut->addTo( menu );
2457
actionEditCopy->addTo( menu );
2458
actionEditPaste->addTo( menu );
2459
actionEditDelete->addTo( menu );
2464
QPopupMenu *MainWindow::setupTabWidgetHierarchyMenu( QWidget *parent, const char *addSlot, const char *removeSlot )
2466
QPopupMenu *menu = new QPopupMenu( parent );
2468
menu->insertItem( i18n( "Add Page" ), parent, addSlot );
2469
menu->insertItem( i18n( "Delete Page" ), parent, removeSlot );
2470
menu->insertSeparator();
2471
actionEditCut->addTo( menu );
2472
actionEditCopy->addTo( menu );
2473
actionEditPaste->addTo( menu );
2474
actionEditDelete->addTo( menu );
2479
void MainWindow::closeEvent( QCloseEvent *e )
2481
if ( singleProject ) {
2487
QWidgetList windows = qWorkspace()->windowList();
2488
QWidgetListIt wit( windows );
2489
while ( wit.current() ) {
2490
QWidget *w = wit.current();
2492
if ( ::qt_cast<FormWindow*>(w) ) {
2493
if ( ( (FormWindow*)w )->formFile()->editor() )
2494
windows.removeRef( ( (FormWindow*)w )->formFile()->editor() );
2495
if ( ( (FormWindow*)w )->formFile()->formWindow() )
2496
windows.removeRef( ( (FormWindow*)w )->formFile()->formWindow() );
2497
if ( !( (FormWindow*)w )->formFile()->close() ) {
2501
} else if ( ::qt_cast<SourceEditor*>(w) ) {
2502
if ( !( (SourceEditor*)w )->close() ) {
2510
QMapConstIterator<QAction*, Project*> it = projects.begin();
2511
while( it != projects.end() ) {
2512
Project *pro = it.data();
2514
if ( pro->isModified() ) {
2515
switch ( QMessageBox::warning( this, i18n( "Save Project Settings" ),
2516
i18n( "Save changes to '%1'?" ).arg( pro->fileName() ),
2517
i18n( "&Yes" ), i18n( "&No" ), i18n( "&Cancel" ), 0, 2 ) ) {
2521
case 1: // don't save
2537
QDir home( QDir::homeDirPath() );
2538
home.remove( ".designerpid" );
2542
Workspace *MainWindow::workspace() const
2545
( (MainWindow*)this )->setupWorkspace();
2549
PropertyEditor *MainWindow::propertyeditor() const
2551
if ( !propertyEditor )
2552
( (MainWindow*)this )->setupPropertyEditor();
2553
return propertyEditor;
2556
ActionEditor *MainWindow::actioneditor() const
2558
if ( !actionEditor )
2559
( (MainWindow*)this )->setupActionEditor();
2560
return actionEditor;
2563
bool MainWindow::openEditor( QWidget *w, FormWindow *f )
2565
if ( f && !f->project()->isCpp() && !WidgetFactory::isPassiveInteractor( w ) ) {
2566
QString defSignal = WidgetFactory::defaultSignal( w );
2567
if ( defSignal.isEmpty() ) {
2570
QString s = QString( w->name() ) + "_" + defSignal;
2571
LanguageInterface *iface = MetaDataBase::languageInterface( f->project()->language() );
2573
QStrList sigs = iface->signalNames( w );
2575
for ( int i = 0; i < (int)sigs.count(); ++i ) {
2576
QString sig = sigs.at( i );
2577
if ( sig.left( sig.find( '(' ) ) == defSignal ) {
2583
if ( !fullSignal.isEmpty() ) {
2584
QString signl = fullSignal;
2585
fullSignal = fullSignal.mid( fullSignal.find( '(' ) + 1 );
2586
fullSignal.remove( (int)fullSignal.length() - 1, 1 );
2587
fullSignal = iface->createArguments( fullSignal.simplifyWhiteSpace() );
2588
s += "(" + fullSignal + ")";
2589
if ( !MetaDataBase::hasFunction( f, s.latin1() ) )
2590
MetaDataBase::addFunction( f, s.latin1(), "", "public", "slot",
2591
f->project()->language(), "void" );
2592
s = s.left( s.find( '(' ) ).latin1();
2593
if ( !MetaDataBase::hasConnection( f, w, defSignal.latin1(), f->mainContainer(), s.latin1() ) ) {
2594
MetaDataBase::Connection conn;
2596
conn.receiver = f->mainContainer();
2597
conn.signal = signl;
2599
AddConnectionCommand *cmd =
2600
new AddConnectionCommand( i18n( "Add Connection" ), f, conn );
2601
f->commandHistory()->addCommand( cmd );
2603
f->formFile()->setModified( TRUE );
2607
editFunction( s, TRUE );
2611
if ( WidgetFactory::hasSpecialEditor( WidgetDatabase::
2612
idFromClassName( WidgetFactory::classNameOf( w ) ), w ) ) {
2613
statusMessage( i18n( "Edit %1..." ).arg( w->className() ) );
2614
WidgetFactory::editWidget( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( w ) ),
2615
this, w, formWindow() );
2616
statusBar()->clear();
2620
const QMetaProperty* text = w->metaObject()->property( w->metaObject()->findProperty( "text", TRUE ), TRUE );
2621
const QMetaProperty* title = w->metaObject()->property( w->metaObject()->findProperty( "title", TRUE ), TRUE );
2622
if ( text && text->designable(w) ) {
2624
bool oldDoWrap = FALSE;
2625
if ( ::qt_cast<QLabel*>(w) ) {
2626
int align = w->property( "alignment" ).toInt();
2627
if ( align & WordBreak )
2630
bool doWrap = oldDoWrap;
2633
if ( ::qt_cast<QTextEdit*>(w) || ::qt_cast<QLabel*>(w) || ::qt_cast<QButton*>(w) ) {
2634
text = MultiLineEditor::getText( this, w->property( "text" ).toString(),
2635
!::qt_cast<QButton*>(w), &doWrap );
2636
ok = !text.isNull();
2638
text = QInputDialog::getText( i18n("Text"), i18n( "New text" ),
2639
QLineEdit::Normal, w->property("text").toString(), &ok, this );
2642
if ( oldDoWrap != doWrap ) {
2643
QString pn( i18n( "Set 'wordwrap' of '%1'" ).arg( w->name() ) );
2644
SetPropertyCommand *cmd = new SetPropertyCommand( pn, formWindow(), w, propertyEditor,
2645
"wordwrap", QVariant( oldDoWrap, 0 ),
2646
QVariant( doWrap, 0 ), QString::null, QString::null );
2648
formWindow()->commandHistory()->addCommand( cmd );
2649
MetaDataBase::setPropertyChanged( w, "wordwrap", TRUE );
2652
QString pn( i18n( "Set the 'text' of '%1'" ).arg( w->name() ) );
2653
SetPropertyCommand *cmd = new SetPropertyCommand( pn, formWindow(), w, propertyEditor,
2654
"text", w->property( "text" ),
2655
text, QString::null, QString::null );
2657
formWindow()->commandHistory()->addCommand( cmd );
2658
MetaDataBase::setPropertyChanged( w, "text", TRUE );
2662
if ( title && title->designable(w) ) {
2665
text = QInputDialog::getText( i18n("Title"), i18n( "New title" ), QLineEdit::Normal, w->property("title").toString(), &ok, this );
2667
QString pn( i18n( "Set the 'title' of '%2'" ).arg( w->name() ) );
2668
SetPropertyCommand *cmd = new SetPropertyCommand( pn, formWindow(), w, propertyEditor,
2669
"title", w->property( "title" ),
2670
text, QString::null, QString::null );
2672
formWindow()->commandHistory()->addCommand( cmd );
2673
MetaDataBase::setPropertyChanged( w, "title", TRUE );
2678
if ( !WidgetFactory::isPassiveInteractor( w ) )
2684
void MainWindow::rebuildCustomWidgetGUI()
2686
customWidgetToolBar->clear();
2687
customWidgetMenu->clear();
2688
customWidgetToolBar2->clear();
2691
QPtrListIterator<QAction> it( toolActions );
2693
while ( ( action = it.current() ) ) {
2695
if ( ( (WidgetAction*)action )->group() == "Custom Widgets" )
2699
QPtrList<MetaDataBase::CustomWidget> *lst = MetaDataBase::customWidgets();
2701
actionToolsCustomWidget->addTo( customWidgetMenu );
2702
customWidgetMenu->insertSeparator();
2704
for ( MetaDataBase::CustomWidget *w = lst->first(); w; w = lst->next() ) {
2705
WidgetAction* a = new WidgetAction( "Custom Widgets", actionGroupTools, QString::number( w->id ).latin1() );
2706
a->setToggleAction( TRUE );
2707
a->setText( w->className );
2708
a->setIconSet( *w->pixmap );
2709
a->setStatusTip( i18n( "Insert a %1 (custom widget)" ).arg( w->className ) );
2710
a->setWhatsThis( i18n("<b>%1 (custom widget)</b>"
2711
"<p>Click <b>Edit Custom Widgets...</b> in the <b>Tools|Custom</b> menu to "
2712
"add and change custom widgets. You can add properties as well as "
2713
"signals and slots to integrate them into Qt Designer, "
2714
"and provide a pixmap which will be used to represent the widget on the form.</p>").arg( w->className ) );
2716
a->addTo( customWidgetToolBar );
2717
a->addTo( customWidgetToolBar2 );
2718
a->addTo( customWidgetMenu );
2722
customWidgetToolBar2->setStretchableWidget( ( wid = new QWidget( customWidgetToolBar2 ) ) );
2723
wid->setBackgroundMode( customWidgetToolBar2->backgroundMode() );
2726
customWidgetToolBar->hide();
2727
else if ( customWidgetToolBar->isVisible() )
2728
customWidgetToolBar->show();
2731
void MainWindow::rebuildCommonWidgetsToolBoxPage()
2733
toolBox->setUpdatesEnabled( FALSE );
2734
commonWidgetsToolBar->setUpdatesEnabled( FALSE );
2735
commonWidgetsToolBar->clear();
2736
for ( QAction *a = commonWidgetsPage.first(); a; a = commonWidgetsPage.next() )
2737
a->addTo( commonWidgetsToolBar );
2739
commonWidgetsToolBar->setStretchableWidget( ( w = new QWidget( commonWidgetsToolBar ) ) );
2740
w->setBackgroundMode( commonWidgetsToolBar->backgroundMode() );
2741
toolBox->setUpdatesEnabled( TRUE );
2742
commonWidgetsToolBar->setUpdatesEnabled( TRUE );
2745
bool MainWindow::isCustomWidgetUsed( MetaDataBase::CustomWidget *wid )
2747
QWidgetList windows = qWorkspace()->windowList();
2748
for ( QWidget *w = windows.first(); w; w = windows.next() ) {
2749
if ( ::qt_cast<FormWindow*>(w) ) {
2750
if ( ( (FormWindow*)w )->isCustomWidgetUsed( wid ) )
2757
void MainWindow::setGrid( const QPoint &p )
2762
QWidgetList windows = qWorkspace()->windowList();
2763
for ( QWidget *w = windows.first(); w; w = windows.next() ) {
2764
if ( !::qt_cast<FormWindow*>(w) )
2766
( (FormWindow*)w )->mainContainer()->update();
2770
void MainWindow::setShowGrid( bool b )
2775
QWidgetList windows = qWorkspace()->windowList();
2776
for ( QWidget *w = windows.first(); w; w = windows.next() ) {
2777
if ( !::qt_cast<FormWindow*>(w) )
2779
( (FormWindow*)w )->mainContainer()->update();
2783
void MainWindow::setSnapGrid( bool b )
2790
QString MainWindow::documentationPath() const
2792
return QString( qInstallPathDocs() ) + "/html/";
2795
void MainWindow::windowsMenuActivated( int id )
2797
QWidget* w = qworkspace->windowList().at( id );
2802
void MainWindow::projectSelected( QAction *a )
2805
if ( currentProject )
2806
currentProject->setActive( FALSE );
2807
Project *p = *projects.find( a );
2808
p->setActive( TRUE );
2809
if ( currentProject == p )
2813
wspace->setCurrentProject( currentProject );
2816
void MainWindow::openProject( const QString &fn )
2818
for ( QMap<QAction*, Project*>::ConstIterator it = projects.begin(); it != projects.end(); ++it ) {
2819
if ( (*it)->fileName() == fn ) {
2820
projectSelected( it.key() );
2824
QApplication::setOverrideCursor( waitCursor );
2825
Project *pro = new Project( fn, "", projectSettingsPluginManager );
2826
pro->setModified( FALSE );
2827
QAction *a = new QAction( pro->projectName(), pro->projectName(), 0, actionGroupProjects, 0, TRUE );
2828
projects.insert( a, pro );
2829
projectSelected( a );
2830
QApplication::restoreOverrideCursor();
2833
void MainWindow::checkTempFiles()
2835
QString s = QDir::homeDirPath() + "/.designer";
2836
QString baseName = s+ "/saved-form-";
2837
if ( !QFile::exists( baseName + "1.ui" ) )
2839
DesignerApplication::closeSplash();
2841
d.setNameFilter( "*.ui" );
2842
QStringList lst = d.entryList();
2843
QApplication::restoreOverrideCursor();
2844
bool load = QMessageBox::information( this, i18n( "Restoring Last Session" ),
2845
i18n( "Qt Designer found some temporary saved files, which were\n"
2846
"written when Qt Designer crashed last time. Do you want to\n"
2847
"load these files?" ), i18n( "&Yes" ), i18n( "&No" ) ) == 0;
2848
QApplication::setOverrideCursor( waitCursor );
2849
for ( QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) {
2851
openFormWindow( s + "/" + *it, FALSE );
2856
void MainWindow::showDialogHelp()
2858
QWidget *w = (QWidget*)sender();
2859
w = w->topLevelWidget();
2861
QString link = documentationPath() + "/designer-manual-13.html#";
2863
if ( ::qt_cast<NewFormBase*>(w) || ::qt_cast<StartDialogBase*>(w) ) // own doc for startdialog?
2864
link += "dialog-file-new";
2865
else if ( ::qt_cast<CreateTemplate*>(w) )
2866
link += "dialog-file-create-template";
2867
else if ( ::qt_cast<EditFunctionsBase*>(w) )
2868
link += "dialog-edit-functions";
2869
// else if ( ::qt_cast<ConnectionViewerBase*>(w) )
2870
else if ( w->inherits("ConnectionViewerBase") )
2871
link += "dialog-view-connections";
2872
else if ( ::qt_cast<FormSettingsBase*>(w) )
2873
link += "dialog-edit-form-settings";
2874
else if ( ::qt_cast<Preferences*>(w) )
2875
link += "dialog-edit-preferences";
2876
else if ( ::qt_cast<PixmapCollectionEditor*>(w) )
2877
link += "dialog-image-collection";
2878
// else if ( ::qt_cast<DatabaseConnectionBase*>(w) )
2879
else if ( w->inherits( "DatabaseConnectionBase" ) )
2880
link += "dialog-edit-database-connections";
2881
else if ( ::qt_cast<ProjectSettingsBase*>(w) )
2882
link += "dialog-project-settings";
2883
else if ( ::qt_cast<FindDialog*>(w) )
2884
link += "dialog-find-text";
2885
else if ( ::qt_cast<ReplaceDialog*>(w) )
2886
link += "dialog-replace-text";
2887
else if ( ::qt_cast<GotoLineDialog*>(w) )
2888
link += "dialog-go-to-line";
2889
// else if ( ::qt_cast<ConnectionEditorBase*>(w) )
2890
else if ( w->inherits("ConnectionEditorBase") )
2891
link += "dialog-edit-connections";
2892
else if ( ::qt_cast<CustomWidgetEditorBase*>(w) )
2893
link += "dialog-edit-custom-widgets";
2894
else if ( ::qt_cast<PaletteEditorBase*>(w) )
2895
link += "dialog-edit-palette";
2896
else if ( ::qt_cast<ListBoxEditorBase*>(w) )
2897
link += "dialog-edit-listbox";
2898
else if ( ::qt_cast<ListViewEditorBase*>(w) )
2899
link += "dialog-edit-listview";
2900
else if ( ::qt_cast<IconViewEditorBase*>(w) )
2901
link += "dialog-edit-iconview";
2902
else if ( ::qt_cast<TableEditorBase*>(w) )
2903
link += "dialog-edit-table";
2904
else if ( ::qt_cast<MultiLineEditor*>(w) )
2905
link += "dialog-text";
2908
QMessageBox::information( this, i18n( "Help" ),
2909
i18n( "There is no help available for this dialog at the moment." ) );
2913
assistant->showPage( link );
2916
void MainWindow::setupActionManager()
2918
actionPluginManager = new QPluginManager<ActionInterface>( IID_Action, QApplication::libraryPaths(), pluginDirectory() );
2920
QStringList lst = actionPluginManager->featureList();
2921
for ( QStringList::ConstIterator ait = lst.begin(); ait != lst.end(); ++ait ) {
2922
ActionInterface *iface = 0;
2923
actionPluginManager->queryInterface( *ait, &iface );
2927
iface->connectTo( desInterface );
2928
QAction *a = iface->create( *ait, this );
2932
QString grp = iface->group( *ait );
2933
if ( grp.isEmpty() )
2934
grp = "3rd party actions";
2935
QPopupMenu *menu = 0;
2938
if ( !( menu = (QPopupMenu*)child( grp.latin1(), "QPopupMenu" ) ) ) {
2939
menu = new QPopupMenu( this, grp.latin1() );
2940
menuBar()->insertItem( i18n( grp ), menu );
2942
if ( !( tb = (QToolBar*)child( grp.latin1(), "QToolBar" ) ) ) {
2943
tb = new QToolBar( this, grp.latin1() );
2944
tb->setCloseMode( QDockWindow::Undocked );
2945
addToolBar( tb, grp );
2948
if ( iface->location( *ait, ActionInterface::Menu ) )
2950
if ( iface->location( *ait, ActionInterface::Toolbar ) )
2957
void MainWindow::editFunction( const QString &func, bool rereadSource )
2959
if ( !formWindow() )
2962
if ( formWindow()->formFile()->codeFileState() != FormFile::Ok )
2963
if ( !formWindow()->formFile()->setupUihFile(FALSE) )
2966
QString lang = currentProject->language();
2967
if ( !MetaDataBase::hasEditor( lang ) ) {
2968
QMessageBox::information( this, i18n( "Edit Source" ),
2969
i18n( "There is no plugin for editing %1 code installed.\n"
2970
"Note: Plugins are not available in static Qt configurations." ).arg( lang ) );
2974
for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() ) {
2975
if ( e->language() == lang && e->formWindow() == formWindow() ) {
2977
e->setFunction( func );
2982
createSourceEditor( formWindow(), formWindow()->project(), lang, func, rereadSource );
2985
void MainWindow::setupRecentlyFilesMenu()
2987
recentlyFilesMenu->clear();
2989
for ( QStringList::ConstIterator it = recentlyFiles.begin(); it != recentlyFiles.end(); ++it ) {
2990
recentlyFilesMenu->insertItem( *it, id );
2995
void MainWindow::setupRecentlyProjectsMenu()
2997
recentlyProjectsMenu->clear();
2999
for ( QStringList::ConstIterator it = recentlyProjects.begin(); it != recentlyProjects.end(); ++it ) {
3000
recentlyProjectsMenu->insertItem( *it, id );
3005
QPtrList<DesignerProject> MainWindow::projectList() const
3007
QPtrList<DesignerProject> list;
3008
QMapConstIterator<QAction*, Project*> it = projects.begin();
3010
while( it != projects.end() ) {
3011
Project *p = it.data();
3013
list.append( p->iFace() );
3019
QStringList MainWindow::projectNames() const
3022
for ( QMap<QAction*, Project* >::ConstIterator it = projects.begin(); it != projects.end(); ++it )
3023
res << (*it)->projectName();
3027
QStringList MainWindow::projectFileNames() const
3030
for ( QMap<QAction*, Project* >::ConstIterator it = projects.begin(); it != projects.end(); ++it )
3031
res << (*it)->makeRelative( (*it)->fileName() );
3035
Project *MainWindow::findProject( const QString &projectName ) const
3037
for ( QMap<QAction*, Project* >::ConstIterator it = projects.begin(); it != projects.end(); ++it ) {
3038
if ( (*it)->projectName() == projectName )
3044
void MainWindow::setCurrentProject( Project *pro )
3046
for ( QMap<QAction*, Project* >::ConstIterator it = projects.begin(); it != projects.end(); ++it ) {
3048
projectSelected( it.key() );
3054
void MainWindow::setCurrentProjectByFilename( const QString& proFilename )
3056
for ( QMap<QAction*, Project* >::ConstIterator it = projects.begin(); it != projects.end(); ++it ) {
3057
if ( (*it)->makeRelative( (*it)->fileName() ) == proFilename ) {
3058
projectSelected( it.key() );
3065
void MainWindow::recentlyFilesMenuActivated( int id )
3068
if ( !QFile::exists( *recentlyFiles.at( id ) ) ) {
3069
QMessageBox::warning( this, i18n( "Open File" ),
3070
i18n( "Could not open '%1'. File does not exist." ).
3071
arg( *recentlyFiles.at( id ) ) );
3072
recentlyFiles.remove( recentlyFiles.at( id ) );
3075
fileOpen( "", "", *recentlyFiles.at( id ) );
3076
QString fn( *recentlyFiles.at( id ) );
3077
addRecentlyOpened( fn, recentlyFiles );
3081
void MainWindow::recentlyProjectsMenuActivated( int id )
3084
if ( !QFile::exists( *recentlyProjects.at( id ) ) ) {
3085
QMessageBox::warning( this, i18n( "Open Project" ),
3086
i18n( "Could not open '%1'. File does not exist." ).
3087
arg( *recentlyProjects.at( id ) ) );
3088
recentlyProjects.remove( recentlyProjects.at( id ) );
3091
openProject( *recentlyProjects.at( id ) );
3092
QString fn( *recentlyProjects.at( id ) );
3093
addRecentlyOpened( fn, recentlyProjects );
3097
void MainWindow::addRecentlyOpened( const QString &fn, QStringList &lst )
3101
QString f = fi.filePath();
3102
if ( lst.find( f ) != lst.end() )
3104
if ( lst.count() >= 10 )
3109
TemplateWizardInterface * MainWindow::templateWizardInterface( const QString& className )
3111
TemplateWizardInterface* iface = 0;
3112
templateWizardPluginManager->queryInterface( className, & iface );
3116
void MainWindow::setupPluginManagers()
3118
editorPluginManager = new QPluginManager<EditorInterface>( IID_Editor, QApplication::libraryPaths(), "/kdevdesigner" );
3119
MetaDataBase::setEditor( editorPluginManager->featureList() );
3121
templateWizardPluginManager =
3122
new QPluginManager<TemplateWizardInterface>( IID_TemplateWizard, QApplication::libraryPaths(), pluginDirectory() );
3124
MetaDataBase::setupInterfaceManagers( "/designer" );
3125
preferencePluginManager =
3126
new QPluginManager<PreferenceInterface>( IID_Preference, QApplication::libraryPaths(), pluginDirectory() );
3127
projectSettingsPluginManager =
3128
new QPluginManager<ProjectSettingsInterface>( IID_ProjectSettings, QApplication::libraryPaths(), pluginDirectory() );
3129
sourceTemplatePluginManager =
3130
new QPluginManager<SourceTemplateInterface>( IID_SourceTemplate, QApplication::libraryPaths(), pluginDirectory() );
3132
if ( preferencePluginManager ) {
3133
QStringList lst = preferencePluginManager->featureList();
3134
for ( QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) {
3135
PreferenceInterface *i = 0;
3136
preferencePluginManager->queryInterface( *it, &i );
3139
i->connectTo( designerInterface() );
3140
PreferenceInterface::Preference *pf = i->preference();
3142
addPreferencesTab( pf->tab, pf->title, pf->receiver, pf->init_slot, pf->accept_slot );
3143
i->deletePreferenceObject( pf );
3148
if ( projectSettingsPluginManager ) {
3149
QStringList lst = projectSettingsPluginManager->featureList();
3150
for ( QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) {
3151
ProjectSettingsInterface *i = 0;
3152
projectSettingsPluginManager->queryInterface( *it, &i );
3155
i->connectTo( designerInterface() );
3157
ProjectSettingsInterface::ProjectSettings *pf = i->projectSetting();
3159
addProjectTab( pf->tab, pf->title, pf->receiver, pf->init_slot, pf->accept_slot );
3160
i->deleteProjectSettingsObject( pf );
3166
void MainWindow::addPreferencesTab( QWidget *tab, const QString &title, QObject *receiver, const char *init_slot, const char *accept_slot )
3171
t.receiver = receiver;
3172
t.init_slot = init_slot;
3173
t.accept_slot = accept_slot;
3174
preferenceTabs << t;
3177
void MainWindow::addProjectTab( QWidget *tab, const QString &title, QObject *receiver, const char *init_slot, const char *accept_slot )
3182
t.receiver = receiver;
3183
t.init_slot = init_slot;
3184
t.accept_slot = accept_slot;
3188
void MainWindow::setModified( bool b, QWidget *window )
3190
QWidget *w = window;
3192
if ( ::qt_cast<FormWindow*>(w) ) {
3193
( (FormWindow*)w )->modificationChanged( b );
3195
} else if ( ::qt_cast<SourceEditor*>(w) ) {
3196
FormWindow *fw = ( (SourceEditor*)w )->formWindow();
3197
if ( fw && !fw->isFake() ) {
3198
//fw->commandHistory()->setModified( b );
3199
//fw->modificationChanged( b );
3200
fw->formFile()->setModified( b, FormFile::WFormCode );
3201
wspace->update( fw->formFile() );
3207
w = w->parentWidget( TRUE );
3211
void MainWindow::editorClosed( SourceEditor *e )
3213
sourceEditors.take( sourceEditors.findRef( e ) );
3216
void MainWindow::functionsChanged()
3218
updateFunctionsTimer->start( 0, TRUE );
3221
void MainWindow::doFunctionsChanged()
3223
for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() )
3224
e->refresh( FALSE );
3225
hierarchyView->formDefinitionView()->refresh();
3228
void MainWindow::updateFunctionList()
3230
if ( !qWorkspace()->activeWindow() || !::qt_cast<SourceEditor*>(qWorkspace()->activeWindow()) )
3232
SourceEditor *se = (SourceEditor*)qWorkspace()->activeWindow();
3234
hierarchyView->formDefinitionView()->refresh();
3235
if ( !currentProject->isCpp() && se->formWindow() ) {
3236
LanguageInterface *iface = MetaDataBase::languageInterface( currentProject->language() );
3239
QValueList<LanguageInterface::Connection> conns;
3240
iface->connections( se->text(), &conns );
3241
MetaDataBase::setupConnections( se->formWindow(), conns );
3242
propertyEditor->eventList()->setup();
3246
void MainWindow::updateWorkspace()
3248
wspace->setCurrentProject( currentProject );
3251
void MainWindow::showDebugStep( QObject *o, int line )
3253
for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() )
3255
if ( !o || line == -1 )
3257
showSourceLine( o, line, Step );
3260
void MainWindow::showStackFrame( QObject *o, int line )
3262
if ( !o || line == -1 )
3264
showSourceLine( o, line, StackFrame );
3267
void MainWindow::showErrorMessage( QObject *o, int errorLine, const QString &errorMessage )
3270
errorLine--; // ######
3272
l << ( errorLine + 1 );
3278
ll << currentProject->locationOfObject( o );
3279
oWindow->setErrorMessages( l2, l, TRUE, ll, ol );
3280
showSourceLine( o, errorLine, Error );
3284
void MainWindow::finishedRun()
3286
inDebugMode = FALSE;
3288
debuggingForms.clear();
3290
for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() ) {
3291
if ( e->project() == currentProject )
3292
e->editorInterface()->setMode( EditorInterface::Editing );
3293
e->clearStackFrame();
3295
outputWindow()->clearErrorMessages();
3298
void MainWindow::enableAll( bool enable )
3300
menuBar()->setEnabled( enable );
3301
QObjectList *l = queryList( "QDockWindow" );
3302
for ( QObject *o = l->first(); o; o = l->next() ) {
3303
if ( o == wspace->parentWidget() ||
3304
o == oWindow->parentWidget() ||
3305
o == hierarchyView->parentWidget() )
3307
( (QWidget*)o )->setEnabled( enable );
3312
void MainWindow::showSourceLine( QObject *o, int line, LineMode lm )
3314
QWidgetList windows = qworkspace->windowList();
3315
for ( QWidget *w = windows.first(); w; w = windows.next() ) {
3317
SourceEditor *se = 0;
3319
if ( ::qt_cast<FormWindow*>(w) ) {
3320
fw = (FormWindow*)w;
3321
} else if ( ::qt_cast<SourceEditor*>(w) ) {
3322
se = (SourceEditor*)w;
3323
if ( !se->object() )
3325
if ( se->formWindow() )
3326
fw = se->formWindow();
3328
sf = se->sourceFile();
3332
if ( fw->project() != currentProject )
3334
if ( qstrcmp( fw->name(), o->name() ) == 0 ||
3335
fw->isFake() && currentProject->objectForFakeForm( fw ) == o ) {
3339
se->editorInterface()->setError( line );
3342
se->editorInterface()->setStep( line );
3345
se->editorInterface()->setStackFrame( line );
3352
lastActiveFormWindow = fw;
3353
qApp->processEvents();
3358
se->editorInterface()->setError( line );
3361
se->editorInterface()->setStep( line );
3364
se->editorInterface()->setStackFrame( line );
3376
se->editorInterface()->setError( line );
3379
se->editorInterface()->setStep( line );
3382
se->editorInterface()->setStackFrame( line );
3389
if ( ::qt_cast<SourceFile*>(o) ) {
3390
for ( QPtrListIterator<SourceFile> sources = currentProject->sourceFiles();
3391
sources.current(); ++sources ) {
3392
SourceFile* f = sources.current();
3394
SourceEditor *se = editSource( f );
3398
se->editorInterface()->setError( line );
3401
se->editorInterface()->setStep( line );
3404
se->editorInterface()->setStackFrame( line );
3413
FormFile *ff = currentProject->fakeFormFileFor( o );
3416
fw = ff->formWindow();
3418
if ( !fw && !qwf_forms ) {
3419
qWarning( "MainWindow::showSourceLine: qwf_forms is NULL!" );
3423
mblockNewForms = TRUE;
3425
openFormWindow( currentProject->makeAbsolute( *qwf_forms->find( (QWidget*)o ) ) );
3427
fw->formFile()->showEditor( FALSE );
3428
qApp->processEvents(); // give all views the chance to get the formwindow
3429
SourceEditor *se = editSource();
3433
se->editorInterface()->setError( line );
3436
se->editorInterface()->setStep( line );
3439
se->editorInterface()->setStackFrame( line );
3443
mblockNewForms = FALSE;
3447
QObject *MainWindow::findRealObject( QObject *o )
3449
QWidgetList windows = qWorkspace()->windowList();
3450
for ( QWidget *w = windows.first(); w; w = windows.next() ) {
3451
if ( ::qt_cast<FormWindow*>(w) && QString( w->name() ) == QString( o->name() ) )
3453
else if ( ::qt_cast<SourceEditor*>(w) && ( (SourceEditor*)w )->formWindow() &&
3454
QString( ( (SourceEditor*)w )->formWindow()->name() ) == QString( o->name() ) )
3456
else if ( ::qt_cast<SourceFile*>(w) && ( (SourceEditor*)w )->sourceFile() &&
3457
( (SourceEditor*)w )->sourceFile() == o )
3463
void MainWindow::formNameChanged( FormWindow *fw )
3465
for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() ) {
3466
if ( e->object() == fw )
3468
if ( e->project() == fw->project() )
3473
void MainWindow::breakPointsChanged()
3477
if ( !qWorkspace()->activeWindow() || !::qt_cast<SourceEditor*>(qWorkspace()->activeWindow()) )
3479
SourceEditor *e = (SourceEditor*)qWorkspace()->activeWindow();
3480
if ( !e->object() || !e->project() )
3482
if ( e->project() != currentProject )
3485
if ( !interpreterPluginManager ) {
3486
interpreterPluginManager =
3487
new QPluginManager<InterpreterInterface>( IID_Interpreter,
3488
QApplication::libraryPaths(),
3492
InterpreterInterface *iiface = 0;
3493
if ( interpreterPluginManager ) {
3494
QString lang = currentProject->language();
3496
interpreterPluginManager->queryInterface( lang, &iiface );
3501
e->saveBreakPoints();
3503
for ( QObject *o = debuggingForms.first(); o; o = debuggingForms.next() ) {
3504
if ( qstrcmp( o->name(), e->object()->name() ) == 0 ) {
3505
iiface->setBreakPoints( o, MetaDataBase::breakPoints( e->object() ) );
3510
for ( e = sourceEditors.first(); e; e = sourceEditors.next() ) {
3511
if ( e->project() == currentProject && e->sourceFile() ) {
3512
QValueList<uint> bps = MetaDataBase::breakPoints( e->sourceFile() );
3513
iiface->setBreakPoints( e->object(), bps );
3520
int MainWindow::currentLayoutDefaultSpacing() const
3522
if ( ( (MainWindow*)this )->formWindow() )
3523
return ( (MainWindow*)this )->formWindow()->layoutDefaultSpacing();
3524
return BOXLAYOUT_DEFAULT_SPACING;
3527
int MainWindow::currentLayoutDefaultMargin() const
3529
if ( ( (MainWindow*)this )->formWindow() )
3530
return ( (MainWindow*)this )->formWindow()->layoutDefaultMargin();
3531
return BOXLAYOUT_DEFAULT_MARGIN;
3534
void MainWindow::saveAllBreakPoints()
3536
for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() ) {
3538
e->saveBreakPoints();
3542
void MainWindow::resetBreakPoints()
3544
for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() )
3545
e->resetBreakPoints();
3548
SourceFile *MainWindow::sourceFile()
3550
for ( SourceEditor *e = sourceEditors.first(); e; e = sourceEditors.next() ) {
3551
if ( qworkspace->activeWindow() == e ) {
3552
if ( e->sourceFile() )
3553
return e->sourceFile();
3559
bool MainWindow::openProjectSettings( Project *pro )
3561
ProjectSettings dia( pro, this, 0, TRUE );
3562
SenderObject *senderObject = new SenderObject( designerInterface() );
3563
QValueList<Tab>::ConstIterator it;
3564
for ( it = projectTabs.begin(); it != projectTabs.end(); ++it ) {
3566
if ( t.title != pro->language() )
3568
dia.tabWidget->addTab( t.w, t.title );
3570
connect( dia.buttonOk, SIGNAL( clicked() ), senderObject, SLOT( emitAcceptSignal() ) );
3571
connect( senderObject, SIGNAL( acceptSignal( QUnknownInterface * ) ), t.receiver, t.accept_slot );
3572
connect( senderObject, SIGNAL( initSignal( QUnknownInterface * ) ), t.receiver, t.init_slot );
3573
senderObject->emitInitSignal();
3574
disconnect( senderObject, SIGNAL( initSignal( QUnknownInterface * ) ), t.receiver, t.init_slot );
3578
if ( singleProject )
3579
dia.tabWidget->setTabEnabled( dia.tabSettings, FALSE );
3581
int res = dia.exec();
3583
delete senderObject;
3585
for ( it = projectTabs.begin(); it != projectTabs.end(); ++it ) {
3587
dia.tabWidget->removePage( t.w );
3588
t.w->reparent( 0, QPoint(0,0), FALSE );
3591
return res == QDialog::Accepted;
3594
void MainWindow::popupProjectMenu( const QPoint &pos )
3596
projectMenu->exec( pos );
3599
QStringList MainWindow::sourceTemplates() const
3601
return sourceTemplatePluginManager->featureList();
3604
SourceTemplateInterface* MainWindow::sourceTemplateInterface( const QString& templ )
3606
SourceTemplateInterface *iface = 0;
3607
sourceTemplatePluginManager->queryInterface( templ, &iface);
3611
QString MainWindow::whatsThisFrom( const QString &key )
3613
if ( menuHelpFile.isEmpty() ) {
3614
QString fn( documentationPath() );
3615
fn += "/designer-manual-11.html";
3617
if ( f.open( IO_ReadOnly ) ) {
3618
QTextStream ts( &f );
3619
menuHelpFile = ts.read();
3623
int i = menuHelpFile.find( key );
3625
return QString::null;
3628
start = menuHelpFile.findRev( "<li>", i ) + 4;
3629
end = menuHelpFile.find( '\n', i ) - 1;
3630
return menuHelpFile.mid( start, end - start + 1 );
3633
void MainWindow::setSingleProject( Project *pro )
3636
Project *pro = eProject;
3638
QWidgetList windows = qWorkspace()->windowList();
3639
qWorkspace()->blockSignals( TRUE );
3640
QWidgetListIt wit( windows );
3641
while ( wit.current() ) {
3642
QWidget *w = wit.current();
3644
if ( ::qt_cast<FormWindow*>(w) ) {
3645
if ( ( (FormWindow*)w )->project() == pro ) {
3646
if ( ( (FormWindow*)w )->formFile()->editor() )
3647
windows.removeRef( ( (FormWindow*)w )->formFile()->editor() );
3648
( (FormWindow*)w )->formFile()->close();
3650
} else if ( ::qt_cast<SourceEditor*>(w) ) {
3651
( (SourceEditor*)w )->close();
3654
hierarchyView->clear();
3655
windows = qWorkspace()->windowList();
3656
qWorkspace()->blockSignals( FALSE );
3658
updateUndoRedo( FALSE, FALSE, QString::null, QString::null );
3661
singleProject = TRUE;
3663
QAction *a = new QAction( i18n( pro->name() ), i18n( pro->name() ), 0,
3664
actionGroupProjects, 0, TRUE );
3666
projects.insert( a, eProject );
3668
actionGroupProjects->removeFrom( projectMenu );
3669
actionGroupProjects->removeFrom( projectToolBar );
3670
currentProject = eProject;
3671
currentProject->designerCreated();
3674
void MainWindow::shuttingDown()
3676
outputWindow()->shuttingDown();
3679
void MainWindow::showGUIStuff( bool b )
3681
if ( (bool)guiStuffVisible == b )
3683
guiStuffVisible = b;
3685
setAppropriate( (QDockWindow*)toolBox->parentWidget(), FALSE );
3686
toolBox->parentWidget()->hide();
3687
for ( QToolBar *tb = widgetToolBars.first(); tb; tb = widgetToolBars.next() ) {
3689
setAppropriate( tb, FALSE );
3691
propertyEditor->setPropertyEditorEnabled( FALSE );
3692
setAppropriate( layoutToolBar, FALSE );
3693
layoutToolBar->hide();
3694
setAppropriate( toolsToolBar, FALSE );
3695
toolsToolBar->hide();
3696
menubar->removeItem( toolsMenuId );
3697
menubar->removeItem( toolsMenuId + 1 );
3698
menubar->removeItem( toolsMenuId + 2 );
3699
disconnect( this, SIGNAL( hasActiveForm(bool) ), actionEditAccels, SLOT( setEnabled(bool) ) );
3700
disconnect( this, SIGNAL( hasActiveForm(bool) ), actionEditFunctions, SLOT( setEnabled(bool) ) );
3701
disconnect( this, SIGNAL( hasActiveForm(bool) ), actionEditConnections, SLOT( setEnabled(bool) ) );
3702
disconnect( this, SIGNAL( hasActiveForm(bool) ), actionEditSource, SLOT( setEnabled(bool) ) );
3703
disconnect( this, SIGNAL( hasActiveForm(bool) ), actionEditFormSettings, SLOT( setEnabled(bool) ) );
3704
actionEditFormSettings->setEnabled( FALSE );
3705
actionEditSource->setEnabled( FALSE );
3706
actionEditConnections->setEnabled( FALSE );
3707
actionEditFunctions->setEnabled( FALSE );
3708
actionEditAccels->setEnabled( FALSE );
3709
( (QDockWindow*)propertyEditor->parentWidget() )->
3710
setCaption( i18n( "Signal Handlers" ) );
3711
actionGroupNew->removeFrom( fileMenu );
3712
actionGroupNew->removeFrom( projectToolBar );
3713
actionFileSave->removeFrom( fileMenu );
3714
actionFileSave->removeFrom( projectToolBar );
3715
actionFileExit->removeFrom( fileMenu );
3716
actionNewFile->addTo( fileMenu );
3717
actionNewFile->addTo( projectToolBar );
3718
actionFileSave->addTo( fileMenu );
3719
actionFileSave->addTo( projectToolBar );
3720
actionFileExit->addTo( fileMenu );
3722
setAppropriate( (QDockWindow*)toolBox->parentWidget(), TRUE );
3723
toolBox->parentWidget()->show();
3724
for ( QToolBar *tb = widgetToolBars.first(); tb; tb = widgetToolBars.next() ) {
3725
setAppropriate( tb, TRUE );
3728
propertyEditor->setPropertyEditorEnabled( TRUE );
3729
setAppropriate( layoutToolBar, TRUE );
3730
layoutToolBar->show();
3731
setAppropriate( toolsToolBar, TRUE );
3732
toolsToolBar->show();
3733
menubar->insertItem( i18n( "&Tools" ), toolsMenu, toolsMenuId, toolsMenuIndex );
3734
menubar->insertItem( i18n( "&Layout" ), layoutMenu, toolsMenuId + 1, toolsMenuIndex + 1 );
3735
menubar->insertItem( i18n( "&Preview" ), previewMenu, toolsMenuId + 2, toolsMenuIndex + 2 );
3736
connect( this, SIGNAL( hasActiveForm(bool) ), actionEditAccels, SLOT( setEnabled(bool) ) );
3737
connect( this, SIGNAL( hasActiveForm(bool) ), actionEditFunctions, SLOT( setEnabled(bool) ) );
3738
connect( this, SIGNAL( hasActiveForm(bool) ), actionEditConnections, SLOT( setEnabled(bool) ) );
3739
connect( this, SIGNAL( hasActiveForm(bool) ), actionEditSource, SLOT( setEnabled(bool) ) );
3740
connect( this, SIGNAL( hasActiveForm(bool) ), actionEditFormSettings, SLOT( setEnabled(bool) ) );
3741
actionEditFormSettings->setEnabled( TRUE );
3742
actionEditSource->setEnabled( TRUE );
3743
actionEditConnections->setEnabled( TRUE );
3744
actionEditFunctions->setEnabled( TRUE );
3745
actionEditAccels->setEnabled( TRUE );
3746
( (QDockWindow*)propertyEditor->parentWidget() )->
3747
setCaption( i18n( "Property Editor/Signal Handlers" ) );
3748
actionFileSave->removeFrom( fileMenu );
3749
actionFileSave->removeFrom( projectToolBar );
3750
actionFileExit->removeFrom( fileMenu );
3751
actionGroupNew->addTo( fileMenu );
3752
actionGroupNew->addTo( projectToolBar );
3753
actionFileSave->addTo( fileMenu );
3754
actionFileSave->addTo( projectToolBar );
3755
actionFileExit->addTo( fileMenu );
3759
void MainWindow::setEditorsReadOnly( bool b )
3761
editorsReadOnly = b;
3764
void MainWindow::setPluginDirectory( const QString &pd )
3767
if ( !qwf_plugin_dir )
3768
qwf_plugin_dir = new QString( pd );
3770
*qwf_plugin_dir = pd;
3773
void MainWindow::toggleSignalHandlers( bool show )
3775
if ( sSignalHandlers == show )
3777
sSignalHandlers = show;
3778
propertyEditor->setSignalHandlersEnabled( show );
3781
void MainWindow::statusMessage( const QString &msg )
3783
m_part->statusMessage(msg);