uml.cpp 119 KB
Newer Older
Thibault Normand's avatar
Thibault Normand committed
1
2
3
4
5
6
/***************************************************************************
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
Oliver Kellogg's avatar
Oliver Kellogg committed
7
 *   copyright (C) 2002-2014                                               *
Ralf Habacker's avatar
Ralf Habacker committed
8
 *   Umbrello UML Modeller Authors <umbrello-devel@kde.org>                *
Thibault Normand's avatar
Thibault Normand committed
9
10
11
12
13
14
 ***************************************************************************/

// own header
#include "uml.h"

// app includes
Andi Fischer's avatar
Andi Fischer committed
15
#include "birdview.h"
16
#include "umlappprivate.h"
17
18
19
20
21
22
#include "umldoc.h"
#include "umllistview.h"
#include "umlviewlist.h"
#include "worktoolbar.h"
#include "umlviewimageexporter.h"
#include "umlviewimageexporterall.h"
Thibault Normand's avatar
Thibault Normand committed
23
#include "docwindow.h"
24
25
26
27
#include "optionstate.h"
#include "cmdlineexportallviewsevent.h"
#include "cmds.h"
#include "umbrellosettings.h"
28
#include "statusbartoolbutton.h"
29
#include "findresults.h"
30

31
// code generation
32
#include "advancedcodegenerator.h"
Thibault Normand's avatar
Thibault Normand committed
33
#include "codegenerationpolicy.h"
34
35
36
#include "codegenfactory.h"
#include "codegenpolicyext.h"
#include "simplecodegenerator.h"
37
// utils
38
#include "debug_utils.h"
Thibault Normand's avatar
Thibault Normand committed
39
#include "widget_utils.h"
40
#include "icon_utils.h"
41
42
// dialogs
#include "classwizard.h"
43
#include "codegenerationwizard.h"
44
#include "codeimportingwizard.h"
45
46
#include "codeviewerdialog.h"
#include "diagramprintpage.h"
47
#include "diagramselectiondialog.h"
48
#include "settingsdialog.h"
49
#include "finddialog.h"
50
#include "classimport.h"
51
#include "refactoringassistant.h"
52
// clipboard
53
54
#include "umlclipboard.h"
#include "umldragdata.h"
55
// docgenerators
56
57
#include "docbookgenerator.h"
#include "xhtmlgenerator.h"
58
#include "umlscene.h"
Thibault Normand's avatar
Thibault Normand committed
59

60
// kde includes
61
#if QT_VERSION < 0x050000
62
#include <kaction.h>
63
#endif
64
65
66
67
68
69
#include <kactioncollection.h>
#include <kstandardaction.h>
#include <ktoggleaction.h>
#include <krecentfilesaction.h>
#include <kconfig.h>
#include <kcursor.h>
70
#if QT_VERSION < 0x050000
71
#include <kdeprintdialog.h>
72
#include <kfiledialog.h>
73
#endif
74
#include <KLocalizedString>
75
#if QT_VERSION < 0x050000
76
#include <kmenubar.h>
77
#endif
78
#include <KMessageBox>
79
#include <ktip.h>
80
#if QT_VERSION < 0x050000
81
#include <ktabwidget.h>
82
#endif
83
#include <kactionmenu.h>
84
#if QT_VERSION < 0x050000
85
#include <kmenu.h>
86
#endif
87
#include <kxmlguifactory.h>
88
#if QT_VERSION < 0x050000
89
#include <kstatusbar.h>
90
#include <kundostack.h>
91
#endif
92
93

// qt includes
94
#include <QApplication>
95
#include <QClipboard>
96
#include <QDesktopWidget>
97
#include <QDockWidget>
98
99
100
#if QT_VERSION >= 0x050000
#include <QFileDialog>
#endif
101
102
103
#include <QKeyEvent>
#include <QLabel>
#include <QMenu>
104
#if QT_VERSION < 0x050000
105
#include <QMenuItem>
106
#endif
107
108
109
110
111
112
#include <QPointer>
#include <QPrinter>
#include <QPrintDialog>
#include <QPrintPreviewDialog>
#include <QPushButton>
#include <QRegExp>
Andi Fischer's avatar
Andi Fischer committed
113
#include <QScrollBar>
114
#include <QSlider>
115
116
117
#if QT_VERSION >= 0x050000
#include <QStatusBar>
#endif
118
#include <QStackedWidget>
119
#include <QTemporaryFile>
120
121
#include <QTimer>
#include <QToolButton>
122
123
124
#if QT_VERSION >= 0x050000
#include <QUndoStack>
#endif
125
#include <QUndoView>
126
#include <QListWidget>
Thibault Normand's avatar
Thibault Normand committed
127

Andi Fischer's avatar
Andi Fischer committed
128
129
#include <cmath>

130
/** Static pointer, holding the last created instance. */
131
132
UMLApp* UMLApp::s_instance;

133
134
135
136
137
138
139
/**
 * Searches for a menu with the given name.
 * @todo This is an ugly _HACK_ to allow to compile umbrello.
 *       All the menu stuff should be ported to KDE4 (using actions)
 *
 * @param name  The name of the menu to search for (name, not text)
 */
140
QMenu* UMLApp::findMenu(const QString& name)
Thibault Normand's avatar
Thibault Normand committed
141
{
Thibault Normand's avatar
Thibault Normand committed
142
    QWidget* widget = factory()->container(name, this);
143
    if (widget) {
Thibault Normand's avatar
Thibault Normand committed
144
        return dynamic_cast<QMenu*>(widget);
145
    }
146
    DEBUG(DBG_SRC) << "factory()->container(" << name << ") returns NULL";
147
    return 0;
Thibault Normand's avatar
Thibault Normand committed
148
149
}

150
151
DEBUG_REGISTER(UMLApp)

152
153
154
/**
 * Constructor. Calls all init functions to create the application.
 */
155
156
UMLApp::UMLApp(QWidget* parent)
  : KXmlGuiWindow(parent),
157
    m_d(new UMLAppPrivate(this)),
158
159
160
161
162
163
    m_langSelect(0),
    m_zoomSelect(0),
    m_activeLanguage(Uml::ProgrammingLanguage::Reserved),
    m_codegen(0),
    m_commoncodegenpolicy(new CodeGenerationPolicy()),
    m_policyext(0),
164
165
166
#if QT_VERSION >= 0x050000
    m_config(KSharedConfig::openConfig()),
#else
167
    m_config(KGlobal::config()),
168
#endif
169
170
171
    m_view(0),
    m_doc(new UMLDoc()),
    m_listView(0),
172
    m_docWindow(0),
Andi Fischer's avatar
Andi Fischer committed
173
    m_birdView(0),
174
175
176
177
178
    m_refactoringAssist(0),
    m_clipTimer(0),
    m_copyTimer(0),
    m_loading(false),
    m_imageMimeType(QString()),
179
    m_settingsDialog(0),
180
181
    m_imageExporterAll(new UMLViewImageExporterAll()),
    m_xhtmlGenerator(0),
182
183
184
#if QT_VERSION >= 0x050000
    m_pUndoStack(new QUndoStack(this)),
#else
185
    m_pUndoStack(new KUndoStack(this)),
186
#endif
187
188
189
190
191
    m_hasBegunMacro(false),
    m_printSettings(0),
    m_printer(new QPrinter())
{
    s_instance = this;
Thibault Normand's avatar
Thibault Normand committed
192
    m_doc->init();
193
    m_printer->setFullPage(true);
194
    layout()->setSizeConstraint(QLayout::SetNoConstraint);
195
196
197
198
199
200

    readOptionState();
    initActions();
    // call this here because the statusBar is shown/hidden by setupGUI()
    initStatusBar();
    // use the absolute path to your umbrelloui.rc file for testing purpose in setupGUI();
201
202
    StandardWindowOptions opt = Default;
    opt &= ~Save;
203
    setupGUI(opt);
Thibault Normand's avatar
Thibault Normand committed
204
205
206
207
208
    initView();
    initClip();
    readOptions();

    //get a reference to the Code->Active Language and to the Diagram->Zoom menu
Oliver Kellogg's avatar
Oliver Kellogg committed
209
    m_langSelect = findMenu(QLatin1String("active_lang_menu"));
Thibault Normand's avatar
Thibault Normand committed
210
211
    //in case langSelect hasn't been initialized we create the Popup menu.
    //it will be hidden, but at least we wont crash if someone takes the entry away from the ui.rc file
212
    if (m_langSelect == 0) {
Oliver Kellogg's avatar
Oliver Kellogg committed
213
        m_langSelect = new QMenu(QLatin1String("active_lang_menu"), this);
Thibault Normand's avatar
Thibault Normand committed
214
215
    }

Oliver Kellogg's avatar
Oliver Kellogg committed
216
    m_zoomSelect = findMenu(QLatin1String("zoom_menu"));
Thibault Normand's avatar
Thibault Normand committed
217
218
    //in case zoomSelect hasn't been initialized we create the Popup menu.
    //it will be hidden, but at least we wont crash if some one takes the entry away from the ui.rc file
219
    if (m_zoomSelect == 0) {
Oliver Kellogg's avatar
Oliver Kellogg committed
220
        m_zoomSelect = new QMenu(QLatin1String("zoom_menu"), this);
Thibault Normand's avatar
Thibault Normand committed
221
222
223
    }

    //connect zoomSelect menu
Ralf Habacker's avatar
Ralf Habacker committed
224
225
    connect(m_zoomSelect, SIGNAL(aboutToShow()), this, SLOT(setupZoomMenu()));
    connect(m_zoomSelect, SIGNAL(triggered(QAction*)), this, SLOT(slotSetZoom(QAction*)));
Thibault Normand's avatar
Thibault Normand committed
226

227
    setAutoSaveSettings();
228
    m_toolsbar->setToolButtonStyle(Qt::ToolButtonIconOnly);  // too many items for text, really we want a toolbox widget
Thibault Normand's avatar
Thibault Normand committed
229
230
}

231
232
233
/**
 * Standard deconstructor.
 */
234
235
UMLApp::~UMLApp()
{
236
237
    disconnect(m_pZoomInPB, SIGNAL(clicked()), this, SLOT(slotZoomIn()));
    disconnect(m_pZoomSlider, SIGNAL(valueChanged(int)), this, SLOT(slotZoomSliderMoved(int)));
238
239
240
241
242
243
244
245
246
#if QT_VERSION >= 0x050000
    disconnect(m_tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(slotCloseDiagram(int)));
    disconnect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotTabChanged(int)));
    disconnect(m_tabWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotDiagramPopupMenu(QPoint)));
#else
    disconnect(m_tabWidget, SIGNAL(closeRequest(QWidget*)), this, SLOT(slotCloseDiagram(QWidget*)));
    disconnect(m_tabWidget, SIGNAL(currentChanged(QWidget*)), this, SLOT(slotTabChanged(QWidget*)));
    disconnect(m_tabWidget, SIGNAL(contextMenu(QWidget*,QPoint)), m_doc, SLOT(slotDiagramPopupMenu(QWidget*,QPoint)));
#endif
247

Andi Fischer's avatar
Andi Fischer committed
248
    delete m_birdView;
Thibault Normand's avatar
Thibault Normand committed
249
250
    delete m_clipTimer;
    delete m_copyTimer;
251
252
253
254
255
    delete m_commoncodegenpolicy;
    delete m_imageExporterAll;
    delete m_printer;
    delete m_policyext;
    delete m_pUndoStack;
Ralf Habacker's avatar
Ralf Habacker committed
256
    m_pUndoStack = 0;
257
    delete m_refactoringAssist;
258
    delete m_xhtmlGenerator;
259
260
261
    delete m_listView;
    delete m_doc;
    delete m_d;
Thibault Normand's avatar
Thibault Normand committed
262
263
}

264
265
266
/**
 * Get the last created instance of this class.
 */
Thibault Normand's avatar
Thibault Normand committed
267
268
269
270
271
UMLApp* UMLApp::app()
{
    return s_instance;
}

272
273
274
/**
 * Helper method to setup the programming language action.
 */
Oliver Kellogg's avatar
Oliver Kellogg committed
275
void UMLApp::setProgLangAction(Uml::ProgrammingLanguage::Enum pl, const char* name, const char* action)
276
{
Oliver Kellogg's avatar
Oliver Kellogg committed
277
278
    m_langAct[pl] = actionCollection()->addAction(QString::fromLatin1(action));
    m_langAct[pl]->setText(QString::fromLatin1(name));
279
280
281
    m_langAct[pl]->setCheckable(true);
}

282
283
284
/**
 * Initializes the KActions and the status bar of the application 
 * and calls setupGUI().
285
 * Note: Check also the file umbrelloui.rc and add actions there too.
286
 */
287
288
void UMLApp::initActions()
{
289
290
    QAction* fileNew = KStandardAction::openNew(this, SLOT(slotFileNew()), actionCollection());
    QAction* fileOpen = KStandardAction::open(this, SLOT(slotFileOpen()), actionCollection());
Ralf Habacker's avatar
Ralf Habacker committed
291
#if QT_VERSION >= 0x050000
Ralf Habacker's avatar
Ralf Habacker committed
292
293
    fileOpenRecent = KStandardAction::openRecent(this, SLOT(slotFileOpenRecent(QUrl)), actionCollection());
#else
294
    fileOpenRecent = KStandardAction::openRecent(this, SLOT(slotFileOpenRecent(KUrl)), actionCollection());
Ralf Habacker's avatar
Ralf Habacker committed
295
#endif
296
297
298
    QAction* fileSave = KStandardAction::save(this, SLOT(slotFileSave()), actionCollection());
    QAction* fileSaveAs = KStandardAction::saveAs(this, SLOT(slotFileSaveAs()), actionCollection());
    QAction* fileClose = KStandardAction::close(this, SLOT(slotFileClose()), actionCollection());
Thibault Normand's avatar
Thibault Normand committed
299
    filePrint = KStandardAction::print(this, SLOT(slotFilePrint()), actionCollection());
300
301
302
    KStandardAction::find(this, SLOT(slotFind()), actionCollection());
    KStandardAction::findNext(this, SLOT(slotFindNext()), actionCollection());
    KStandardAction::findPrev(this, SLOT(slotFindPrevious()), actionCollection());
303
    printPreview = KStandardAction::printPreview(this, SLOT(slotPrintPreview()), actionCollection());
304
305
#if QT_VERSION >= 0x040600
    filePrint->setPriority(QAction::LowPriority);  // icon only
306
    printPreview->setPriority(QAction::LowPriority);  // icon only
307
#endif
308
    QAction* fileQuit = KStandardAction::quit(this, SLOT(slotFileQuit()), actionCollection());
309

310
311
    editUndo = m_pUndoStack->createUndoAction(actionCollection());
    editRedo = m_pUndoStack->createRedoAction(actionCollection());
312
#if QT_VERSION >= 0x040600
313
314
    editUndo->setPriority(QAction::LowPriority);   // icon only
    editRedo->setPriority(QAction::LowPriority);   // icon only
315
#endif
316

317
318
    disconnect(m_pUndoStack, SIGNAL(undoTextChanged(QString)), editUndo, 0);
    disconnect(m_pUndoStack, SIGNAL(redoTextChanged(QString)), editRedo, 0);
319

Thibault Normand's avatar
Thibault Normand committed
320
321
322
    editCut = KStandardAction::cut(this, SLOT(slotEditCut()), actionCollection());
    editCopy = KStandardAction::copy(this, SLOT(slotEditCopy()), actionCollection());
    editPaste = KStandardAction::paste(this, SLOT(slotEditPaste()), actionCollection());
323

Thibault Normand's avatar
Thibault Normand committed
324
325
    createStandardStatusBarAction();
    setStandardToolBarMenuEnabled(true);
326

327
    /* QAction* selectAll = */ KStandardAction::selectAll(this, SLOT(slotSelectAll()), actionCollection());
Thibault Normand's avatar
Thibault Normand committed
328

Oliver Kellogg's avatar
Oliver Kellogg committed
329
    QAction* fileExportDocbook = actionCollection()->addAction(QLatin1String("file_export_docbook"));
330
    fileExportDocbook->setText(i18n("&Export model to DocBook"));
331
    connect(fileExportDocbook, SIGNAL(triggered(bool)), this, SLOT(slotFileExportDocbook()));
Thibault Normand's avatar
Thibault Normand committed
332

Oliver Kellogg's avatar
Oliver Kellogg committed
333
    QAction* fileExportXhtml = actionCollection()->addAction(QLatin1String("file_export_xhtml"));
334
    fileExportXhtml->setText(i18n("&Export model to XHTML"));
335
    connect(fileExportXhtml, SIGNAL(triggered(bool)), this, SLOT(slotFileExportXhtml()));
Thibault Normand's avatar
Thibault Normand committed
336

Oliver Kellogg's avatar
Oliver Kellogg committed
337
    QAction* classWizard = actionCollection()->addAction(QLatin1String("class_wizard"));
338
    classWizard->setText(i18n("&New Class Wizard..."));
339
    connect(classWizard, SIGNAL(triggered(bool)), this, SLOT(slotClassWizard()));
Thibault Normand's avatar
Thibault Normand committed
340

Oliver Kellogg's avatar
Oliver Kellogg committed
341
    QAction* addDefDatatypes = actionCollection()->addAction(QLatin1String("create_default_datatypes"));
342
    addDefDatatypes->setText(i18n("&Add Default Datatypes for Active Language"));
343
    connect(addDefDatatypes, SIGNAL(triggered(bool)), this, SLOT(slotAddDefaultDatatypes()));
Thibault Normand's avatar
Thibault Normand committed
344

345
    QAction* preferences = KStandardAction::preferences(this, SLOT(slotPrefs()), actionCollection());
Thibault Normand's avatar
Thibault Normand committed
346

Oliver Kellogg's avatar
Oliver Kellogg committed
347
    QAction* impWizard = actionCollection()->addAction(QLatin1String("importing_wizard"));
348
    impWizard->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Import_Files));
349
    impWizard->setText(i18n("Code &Importing Wizard..."));
350
    connect(impWizard, SIGNAL(triggered(bool)), this, SLOT(slotImportingWizard()));
351

Oliver Kellogg's avatar
Oliver Kellogg committed
352
    QAction* importProject = actionCollection()->addAction(QLatin1String("import_project"));
353
    importProject->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Import_Project));
354
    importProject->setText(i18n("Import from Directory..."));
355
356
    connect(importProject, SIGNAL(triggered(bool)), this, SLOT(slotImportProject()));

Oliver Kellogg's avatar
Oliver Kellogg committed
357
    QAction* genWizard = actionCollection()->addAction(QLatin1String("generation_wizard"));
358
    genWizard->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Export_Files));
359
    genWizard->setText(i18n("&Code Generation Wizard..."));
360
    connect(genWizard, SIGNAL(triggered(bool)), this, SLOT(slotExecGenerationWizard()));
Thibault Normand's avatar
Thibault Normand committed
361

Oliver Kellogg's avatar
Oliver Kellogg committed
362
    QAction* genAll = actionCollection()->addAction(QLatin1String("generate_all"));
363
    genAll->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Export_Files));
364
    genAll->setText(i18n("&Generate All Code"));
365
    connect(genAll, SIGNAL(triggered(bool)), this, SLOT(slotGenerateAllCode()));
Thibault Normand's avatar
Thibault Normand committed
366

367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
    setProgLangAction(Uml::ProgrammingLanguage::ActionScript, "ActionScript",    "setLang_actionscript");
    setProgLangAction(Uml::ProgrammingLanguage::Ada,          "Ada",             "setLang_ada");
    setProgLangAction(Uml::ProgrammingLanguage::Cpp,          "C++",             "setLang_cpp");
    setProgLangAction(Uml::ProgrammingLanguage::CSharp,       "C#",              "setLang_csharp");
    setProgLangAction(Uml::ProgrammingLanguage::D,            "D",               "setLang_d");
    setProgLangAction(Uml::ProgrammingLanguage::IDL,          "IDL",             "setLang_idl");
    setProgLangAction(Uml::ProgrammingLanguage::Java,         "Java",            "setLang_java");
    setProgLangAction(Uml::ProgrammingLanguage::JavaScript,   "JavaScript",      "setLang_javascript");
    setProgLangAction(Uml::ProgrammingLanguage::MySQL,        "MySQL (SQL)",     "setLang_mysql");
    setProgLangAction(Uml::ProgrammingLanguage::Pascal,       "Pascal",          "setLang_pascal");
    setProgLangAction(Uml::ProgrammingLanguage::Perl,         "Perl",            "setLang_perl");
    setProgLangAction(Uml::ProgrammingLanguage::PHP,          "PHP",             "setLang_php");
    setProgLangAction(Uml::ProgrammingLanguage::PHP5,         "PHP5",            "setLang_php5");
    setProgLangAction(Uml::ProgrammingLanguage::PostgreSQL,   "PostgreSQL(SQL)", "setLang_postgresql");
    setProgLangAction(Uml::ProgrammingLanguage::Python,       "Python",          "setLang_python");
    setProgLangAction(Uml::ProgrammingLanguage::Ruby,         "Ruby",            "setLang_ruby");
    setProgLangAction(Uml::ProgrammingLanguage::SQL,          "SQL",             "setLang_sql");
    setProgLangAction(Uml::ProgrammingLanguage::Tcl,          "Tcl",             "setLang_tcl");
    setProgLangAction(Uml::ProgrammingLanguage::Vala,         "Vala",            "setLang_vala");
    setProgLangAction(Uml::ProgrammingLanguage::XMLSchema,    "XMLSchema",       "setLang_xmlschema");

    connect(m_langAct[Uml::ProgrammingLanguage::ActionScript], SIGNAL(triggered()), this, SLOT(setLang_actionscript()));
    connect(m_langAct[Uml::ProgrammingLanguage::Ada],          SIGNAL(triggered()), this, SLOT(setLang_ada()));
    connect(m_langAct[Uml::ProgrammingLanguage::Cpp],          SIGNAL(triggered()), this, SLOT(setLang_cpp()));
    connect(m_langAct[Uml::ProgrammingLanguage::CSharp],       SIGNAL(triggered()), this, SLOT(setLang_csharp()));
    connect(m_langAct[Uml::ProgrammingLanguage::D],            SIGNAL(triggered()), this, SLOT(setLang_d()));
    connect(m_langAct[Uml::ProgrammingLanguage::IDL],          SIGNAL(triggered()), this, SLOT(setLang_idl()));
    connect(m_langAct[Uml::ProgrammingLanguage::Java],         SIGNAL(triggered()), this, SLOT(setLang_java()));
    connect(m_langAct[Uml::ProgrammingLanguage::JavaScript],   SIGNAL(triggered()), this, SLOT(setLang_javascript()));
    connect(m_langAct[Uml::ProgrammingLanguage::MySQL],        SIGNAL(triggered()), this, SLOT(setLang_mysql()));
    connect(m_langAct[Uml::ProgrammingLanguage::Pascal],       SIGNAL(triggered()), this, SLOT(setLang_pascal()));
    connect(m_langAct[Uml::ProgrammingLanguage::Perl],         SIGNAL(triggered()), this, SLOT(setLang_perl()));
    connect(m_langAct[Uml::ProgrammingLanguage::PHP],          SIGNAL(triggered()), this, SLOT(setLang_php()));
    connect(m_langAct[Uml::ProgrammingLanguage::PHP5],         SIGNAL(triggered()), this, SLOT(setLang_php5()));
    connect(m_langAct[Uml::ProgrammingLanguage::PostgreSQL],   SIGNAL(triggered()), this, SLOT(setLang_postgresql()));
    connect(m_langAct[Uml::ProgrammingLanguage::Python],       SIGNAL(triggered()), this, SLOT(setLang_python()));
    connect(m_langAct[Uml::ProgrammingLanguage::Ruby],         SIGNAL(triggered()), this, SLOT(setLang_ruby()));
    connect(m_langAct[Uml::ProgrammingLanguage::SQL],          SIGNAL(triggered()), this, SLOT(setLang_sql()));
    connect(m_langAct[Uml::ProgrammingLanguage::Tcl],          SIGNAL(triggered()), this, SLOT(setLang_tcl()));
    connect(m_langAct[Uml::ProgrammingLanguage::Vala],         SIGNAL(triggered()), this, SLOT(setLang_vala()));
    connect(m_langAct[Uml::ProgrammingLanguage::XMLSchema],    SIGNAL(triggered()), this, SLOT(setLang_xmlschema()));
408

Thibault Normand's avatar
Thibault Normand committed
409
410
411
412
413
414
    fileNew->setToolTip(i18n("Creates a new document"));
    fileOpen->setToolTip(i18n("Opens an existing document"));
    fileOpenRecent->setToolTip(i18n("Opens a recently used file"));
    fileSave->setToolTip(i18n("Saves the document"));
    fileSaveAs->setToolTip(i18n("Saves the document as..."));
    fileClose->setToolTip(i18n("Closes the document"));
415
    filePrint->setToolTip(i18n("Prints out the document"));
416
    printPreview->setToolTip(i18n("Print Preview of the document"));
Thibault Normand's avatar
Thibault Normand committed
417
418
419
420
421
422
    fileQuit->setToolTip(i18n("Quits the application"));
    fileExportDocbook->setToolTip(i18n("Exports the model to the docbook format"));
    fileExportXhtml->setToolTip(i18n("Exports the model to the XHTML format"));
    editCut->setToolTip(i18n("Cuts the selected section and puts it to the clipboard"));
    editCopy->setToolTip(i18n("Copies the selected section to the clipboard"));
    editPaste->setToolTip(i18n("Pastes the contents of the clipboard"));
423
    preferences->setToolTip(i18n("Set the default program preferences"));
Thibault Normand's avatar
Thibault Normand committed
424

Oliver Kellogg's avatar
Oliver Kellogg committed
425
    deleteSelectedWidget = actionCollection()->addAction(QLatin1String("delete_selected"));
426
    deleteSelectedWidget->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Delete));
427
    deleteSelectedWidget->setText(i18nc("delete selected widget", "Delete &Selected"));
Thibault Normand's avatar
Thibault Normand committed
428
    deleteSelectedWidget->setShortcut(QKeySequence(Qt::Key_Delete));
429
    connect(deleteSelectedWidget, SIGNAL(triggered(bool)), this, SLOT(slotDeleteSelected()));
Thibault Normand's avatar
Thibault Normand committed
430
431

    // The different views
Oliver Kellogg's avatar
Oliver Kellogg committed
432
    newDiagram = actionCollection()->add<KActionMenu>(QLatin1String("new_view"));
433
    newDiagram->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_New));
Oliver Kellogg's avatar
Oliver Kellogg committed
434
    newDiagram->setText(QLatin1String("new_view"));
435

Oliver Kellogg's avatar
Oliver Kellogg committed
436
    QAction* classDiagram = actionCollection()->addAction(QLatin1String("new_class_diagram"));
437
438
    classDiagram->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Diagram_Class));
    classDiagram->setText(i18n("&Class Diagram..."));
439
    connect(classDiagram, SIGNAL(triggered(bool)), this, SLOT(slotClassDiagram()));
440
    newDiagram->addAction(classDiagram);
Thibault Normand's avatar
Thibault Normand committed
441

442
#ifdef ENABLE_OBJECT_DIAGRAM
443
444
445
446
447
    QAction* objectDiagram = actionCollection()->addAction(QLatin1String("new_object_diagram"));
    objectDiagram->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Diagram_Object));
    objectDiagram->setText(i18n("&Object Diagram..."));
    connect(objectDiagram, SIGNAL(triggered()), this, SLOT(slotObjectDiagram()));
    newDiagram->addAction(objectDiagram);
448
#endif
449

Oliver Kellogg's avatar
Oliver Kellogg committed
450
    QAction* sequenceDiagram= actionCollection()->addAction(QLatin1String("new_sequence_diagram"));
451
452
    sequenceDiagram->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Diagram_Sequence));
    sequenceDiagram->setText(i18n("&Sequence Diagram..."));
453
    connect(sequenceDiagram, SIGNAL(triggered(bool)), this, SLOT(slotSequenceDiagram()));
454
    newDiagram->addAction(sequenceDiagram);
Thibault Normand's avatar
Thibault Normand committed
455

Oliver Kellogg's avatar
Oliver Kellogg committed
456
    QAction* collaborationDiagram = actionCollection()->addAction(QLatin1String("new_collaboration_diagram"));
457
    collaborationDiagram->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Diagram_Collaboration));
458
    collaborationDiagram->setText(i18n("C&ommunication Diagram..."));
459
    connect(collaborationDiagram, SIGNAL(triggered(bool)), this, SLOT(slotCollaborationDiagram()));
460
    newDiagram->addAction(collaborationDiagram);
Thibault Normand's avatar
Thibault Normand committed
461

Oliver Kellogg's avatar
Oliver Kellogg committed
462
    QAction* useCaseDiagram = actionCollection()->addAction(QLatin1String("new_use_case_diagram"));
463
464
    useCaseDiagram->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Diagram_Usecase));
    useCaseDiagram->setText(i18n("&Use Case Diagram..."));
465
    connect(useCaseDiagram, SIGNAL(triggered(bool)), this, SLOT(slotUseCaseDiagram()));
466
    newDiagram->addAction(useCaseDiagram);
Thibault Normand's avatar
Thibault Normand committed
467

Oliver Kellogg's avatar
Oliver Kellogg committed
468
    QAction* stateDiagram = actionCollection()->addAction(QLatin1String("new_state_diagram"));
469
470
    stateDiagram->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Diagram_State));
    stateDiagram->setText(i18n("S&tate Diagram..."));
471
    connect(stateDiagram, SIGNAL(triggered(bool)), this, SLOT(slotStateDiagram()));
472
    newDiagram->addAction(stateDiagram);
Thibault Normand's avatar
Thibault Normand committed
473

Oliver Kellogg's avatar
Oliver Kellogg committed
474
    QAction* activityDiagram = actionCollection()->addAction(QLatin1String("new_activity_diagram"));
475
476
    activityDiagram->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Diagram_Activity));
    activityDiagram->setText(i18n("&Activity Diagram..."));
477
    connect(activityDiagram, SIGNAL(triggered(bool)), this, SLOT(slotActivityDiagram()));
478
    newDiagram->addAction(activityDiagram);
Thibault Normand's avatar
Thibault Normand committed
479

Oliver Kellogg's avatar
Oliver Kellogg committed
480
    QAction* componentDiagram = actionCollection()->addAction(QLatin1String("new_component_diagram"));
481
482
    componentDiagram->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Diagram_Component));
    componentDiagram->setText(i18n("Co&mponent Diagram..."));
483
    connect(componentDiagram, SIGNAL(triggered(bool)), this, SLOT(slotComponentDiagram()));
484
    newDiagram->addAction(componentDiagram);
Thibault Normand's avatar
Thibault Normand committed
485

Oliver Kellogg's avatar
Oliver Kellogg committed
486
    QAction* deploymentDiagram = actionCollection()->addAction(QLatin1String("new_deployment_diagram"));
487
488
    deploymentDiagram->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Diagram_Deployment));
    deploymentDiagram->setText(i18n("&Deployment Diagram..."));
489
    connect(deploymentDiagram, SIGNAL(triggered(bool)), this, SLOT(slotDeploymentDiagram()));
490
    newDiagram->addAction(deploymentDiagram);
Thibault Normand's avatar
Thibault Normand committed
491

Oliver Kellogg's avatar
Oliver Kellogg committed
492
    QAction* entityRelationshipDiagram = actionCollection()->addAction(QLatin1String("new_entityrelationship_diagram"));
493
494
    entityRelationshipDiagram->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Diagram_EntityRelationship));
    entityRelationshipDiagram->setText(i18n("&Entity Relationship Diagram..."));
495
    connect(entityRelationshipDiagram, SIGNAL(triggered(bool)), this, SLOT(slotEntityRelationshipDiagram()));
496
    newDiagram->addAction(entityRelationshipDiagram);
Thibault Normand's avatar
Thibault Normand committed
497

Oliver Kellogg's avatar
Oliver Kellogg committed
498
    viewShowTree = actionCollection()->add<KToggleAction>(QLatin1String("view_show_tree"));
499
500
501
    viewShowTree->setText(i18n("&Tree View"));
    connect(viewShowTree, SIGNAL(triggered(bool)), this, SLOT(slotShowTreeView(bool)));

Oliver Kellogg's avatar
Oliver Kellogg committed
502
    viewShowDebug = actionCollection()->add<KToggleAction>(QLatin1String("view_show_debug"));
503
504
505
    viewShowDebug->setText(i18n("&Debugging"));
    connect(viewShowDebug, SIGNAL(triggered(bool)), this, SLOT(slotShowDebugView(bool)));

Oliver Kellogg's avatar
Oliver Kellogg committed
506
    viewShowDoc = actionCollection()->add<KToggleAction>(QLatin1String("view_show_doc"));
507
508
509
    viewShowDoc->setText(i18n("&Documentation"));
    connect(viewShowDoc, SIGNAL(triggered(bool)), this, SLOT(slotShowDocumentationView(bool)));

Oliver Kellogg's avatar
Oliver Kellogg committed
510
    viewShowLog = actionCollection()->add<KToggleAction>(QLatin1String("view_show_log"));
511
512
513
    viewShowLog->setText(i18n("&Logging"));
    connect(viewShowLog, SIGNAL(triggered(bool)), this, SLOT(slotShowLogView(bool)));

Oliver Kellogg's avatar
Oliver Kellogg committed
514
    viewShowCmdHistory = actionCollection()->add<KToggleAction>(QLatin1String("view_show_undo"));
515
516
517
    viewShowCmdHistory->setText(i18n("&Command history"));
    connect(viewShowCmdHistory, SIGNAL(triggered(bool)), this, SLOT(slotShowCmdHistoryView(bool)));

Andi Fischer's avatar
Andi Fischer committed
518
519
520
521
    viewShowBirdView = actionCollection()->add<KToggleAction>(QLatin1String("view_show_bird"));
    viewShowBirdView->setText(i18n("&Bird's eye view"));
    connect(viewShowBirdView, SIGNAL(triggered(bool)), this, SLOT(slotShowBirdView(bool)));

Oliver Kellogg's avatar
Oliver Kellogg committed
522
    viewClearDiagram = actionCollection()->addAction(QLatin1String("view_clear_diagram"));
523
524
    viewClearDiagram->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Clear));
    viewClearDiagram->setText(i18n("&Clear Diagram"));
525
    connect(viewClearDiagram, SIGNAL(triggered(bool)), this, SLOT(slotCurrentViewClearDiagram()));
Thibault Normand's avatar
Thibault Normand committed
526

Oliver Kellogg's avatar
Oliver Kellogg committed
527
    viewSnapToGrid = actionCollection()->add<KToggleAction>(QLatin1String("view_snap_to_grid"));
528
    viewSnapToGrid->setText(i18n("&Snap to Grid"));
529
    connect(viewSnapToGrid, SIGNAL(triggered(bool)), this, SLOT(slotCurrentViewToggleSnapToGrid()));
Thibault Normand's avatar
Thibault Normand committed
530

Oliver Kellogg's avatar
Oliver Kellogg committed
531
    viewShowGrid = actionCollection()->add<KToggleAction>(QLatin1String("view_show_grid"));
532
    viewShowGrid->setText(i18n("S&how Grid"));
533
    connect(viewShowGrid, SIGNAL(triggered(bool)), this, SLOT(slotCurrentViewToggleShowGrid()));
534

Oliver Kellogg's avatar
Oliver Kellogg committed
535
    deleteDiagram = actionCollection()->addAction(QLatin1String("view_delete"));
536
    deleteDiagram->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Delete));
537
    deleteDiagram->setText(i18n("&Delete Diagram"));
538
    connect(deleteDiagram, SIGNAL(triggered(bool)), this, SLOT(slotDeleteDiagram()));
Thibault Normand's avatar
Thibault Normand committed
539

Oliver Kellogg's avatar
Oliver Kellogg committed
540
    viewExportImage = actionCollection()->addAction(QLatin1String("view_export_image"));
541
542
    viewExportImage->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Export_Picture));
    viewExportImage->setText(i18n("&Export as Picture..."));
543
    connect(viewExportImage, SIGNAL(triggered(bool)), this, SLOT(slotCurrentViewExportImage()));
Thibault Normand's avatar
Thibault Normand committed
544

545
    QAction* viewExportImageAll = actionCollection()->addAction(QLatin1String("view_export_images"));
546
    viewExportImageAll->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Export_Picture));
547
548
    viewExportImageAll->setText(i18n("Export &Diagrams as Pictures..."));
    connect(viewExportImageAll, SIGNAL(triggered(bool)), this, SLOT(slotViewsExportImages()));
Thibault Normand's avatar
Thibault Normand committed
549

Oliver Kellogg's avatar
Oliver Kellogg committed
550
    viewProperties = actionCollection()->addAction(QLatin1String("view_properties"));
551
552
    viewProperties->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Properties));
    viewProperties->setText(i18n("&Properties"));
553
    connect(viewProperties, SIGNAL(triggered(bool)), this, SLOT(slotCurrentProperties()));
Thibault Normand's avatar
Thibault Normand committed
554
555
556
557
558
559
560
561
562
563
564

    viewSnapToGrid->setChecked(false);
    viewShowGrid->setChecked(false);

    viewClearDiagram->setEnabled(false);
    viewSnapToGrid->setEnabled(false);
    viewShowGrid->setEnabled(false);
    deleteDiagram->setEnabled(false);
    viewExportImage->setEnabled(false);
    viewProperties->setEnabled(false);

Oliver Kellogg's avatar
Oliver Kellogg committed
565
    zoom100Action = actionCollection()->addAction(QLatin1String("zoom100"));
566
    zoom100Action->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Zoom_100));
Thibault Normand's avatar
Thibault Normand committed
567
    zoom100Action->setText(i18n("Z&oom to 100%"));
568
    connect(zoom100Action, SIGNAL(triggered(bool)), this, SLOT(slotZoom100()));
Thibault Normand's avatar
Thibault Normand committed
569

Oliver Kellogg's avatar
Oliver Kellogg committed
570
    QAction* alignRight = actionCollection()->addAction(QLatin1String("align_right"));
571
572
    alignRight->setText(i18n("Align Right"));
    alignRight->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Align_Right));
573
    connect(alignRight, SIGNAL(triggered(bool)), this, SLOT(slotAlignRight()));
574

Oliver Kellogg's avatar
Oliver Kellogg committed
575
    QAction* alignLeft = actionCollection()->addAction(QLatin1String("align_left"));
576
577
    alignLeft->setText(i18n("Align Left"));
    alignLeft->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Align_Left));
578
    connect(alignLeft, SIGNAL(triggered(bool)), this, SLOT(slotAlignLeft()));
579

Oliver Kellogg's avatar
Oliver Kellogg committed
580
    QAction* alignTop = actionCollection()->addAction(QLatin1String("align_top"));
581
582
    alignTop->setText(i18n("Align Top"));
    alignTop->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Align_Top));
583
    connect(alignTop, SIGNAL(triggered(bool)), this, SLOT(slotAlignTop()));
584

Oliver Kellogg's avatar
Oliver Kellogg committed
585
    QAction* alignBottom = actionCollection()->addAction(QLatin1String("align_bottom"));
586
587
    alignBottom->setText(i18n("Align Bottom"));
    alignBottom->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Align_Bottom));
588
    connect(alignBottom, SIGNAL(triggered(bool)), this, SLOT(slotAlignBottom()));
589

Oliver Kellogg's avatar
Oliver Kellogg committed
590
    QAction* alignVerticalMiddle = actionCollection()->addAction(QLatin1String("align_vertical_middle"));
591
592
    alignVerticalMiddle->setText(i18n("Align Vertical Middle"));
    alignVerticalMiddle->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Align_VerticalMiddle));
593
    connect(alignVerticalMiddle, SIGNAL(triggered(bool)), this, SLOT(slotAlignVerticalMiddle()));
594

Oliver Kellogg's avatar
Oliver Kellogg committed
595
    QAction* alignHorizontalMiddle = actionCollection()->addAction(QLatin1String("align_horizontal_middle"));
596
597
    alignHorizontalMiddle->setText(i18n("Align Horizontal Middle"));
    alignHorizontalMiddle->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Align_HorizontalMiddle));
598
    connect(alignHorizontalMiddle, SIGNAL(triggered(bool)), this, SLOT(slotAlignHorizontalMiddle()));
599

Oliver Kellogg's avatar
Oliver Kellogg committed
600
    QAction* alignVerticalDistribute = actionCollection()->addAction(QLatin1String("align_vertical_distribute"));
601
602
    alignVerticalDistribute->setText(i18n("Align Vertical Distribute"));
    alignVerticalDistribute->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Align_VerticalDistribute));
603
    connect(alignVerticalDistribute, SIGNAL(triggered(bool)), this, SLOT(slotAlignVerticalDistribute()));
604

Oliver Kellogg's avatar
Oliver Kellogg committed
605
    QAction* alignHorizontalDistribute = actionCollection()->addAction(QLatin1String("align_horizontal_distribute"));
606
607
    alignHorizontalDistribute->setText(i18n("Align Horizontal Distribute"));
    alignHorizontalDistribute->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Align_HorizontalDistribute));
608
    connect(alignHorizontalDistribute, SIGNAL(triggered(bool)), this, SLOT(slotAlignHorizontalDistribute()));
609

Thibault Normand's avatar
Thibault Normand committed
610
611
    QString moveTabLeftString = i18n("&Move Tab Left");
    QString moveTabRightString = i18n("&Move Tab Right");
612
613
614
#if QT_VERSION >= 0x050000
    QAction* moveTabLeft = actionCollection()->addAction(QLatin1String("move_tab_left"));
#else
Oliver Kellogg's avatar
Oliver Kellogg committed
615
    KAction* moveTabLeft = actionCollection()->addAction(QLatin1String("move_tab_left"));
616
#endif
617
    moveTabLeft->setIcon(Icon_Utils::SmallIcon(QApplication::layoutDirection() ? Icon_Utils::it_Go_Next : Icon_Utils::it_Go_Previous));
Thibault Normand's avatar
Thibault Normand committed
618
    moveTabLeft->setText(QApplication::layoutDirection() ? moveTabRightString : moveTabLeftString);
Thibault Normand's avatar
Thibault Normand committed
619
    moveTabLeft->setShortcut(QApplication::layoutDirection() ?
620
                 QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_Right) : QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_Left));
621
    connect(moveTabLeft, SIGNAL(triggered(bool)), this, SLOT(slotMoveTabLeft()));
Thibault Normand's avatar
Thibault Normand committed
622

623
624
625
#if QT_VERSION >= 0x050000
    QAction* moveTabRight = actionCollection()->addAction(QLatin1String("move_tab_right"));
#else
Oliver Kellogg's avatar
Oliver Kellogg committed
626
    KAction* moveTabRight = actionCollection()->addAction(QLatin1String("move_tab_right"));
627
#endif
628
    moveTabRight->setIcon(Icon_Utils::SmallIcon(QApplication::layoutDirection() ? Icon_Utils::it_Go_Previous : Icon_Utils::it_Go_Next));
Thibault Normand's avatar
Thibault Normand committed
629
    moveTabRight->setText(QApplication::layoutDirection() ? moveTabLeftString : moveTabRightString);
Thibault Normand's avatar
Thibault Normand committed
630
    moveTabRight->setShortcut(QApplication::layoutDirection() ?
631
                  QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_Left) : QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_Right));
632
    connect(moveTabRight, SIGNAL(triggered(bool)), this, SLOT(slotMoveTabRight()));
Thibault Normand's avatar
Thibault Normand committed
633
634
635

    QString selectTabLeftString = i18n("Select Diagram on Left");
    QString selectTabRightString = i18n("Select Diagram on Right");
636
637
638
#if QT_VERSION >= 0x050000
    QAction* changeTabLeft = actionCollection()->addAction(QLatin1String("previous_tab"));
#else
Oliver Kellogg's avatar
Oliver Kellogg committed
639
    KAction* changeTabLeft = actionCollection()->addAction(QLatin1String("previous_tab"));
640
#endif
641
    changeTabLeft->setText(QApplication::layoutDirection() ? selectTabRightString : selectTabLeftString);
Thibault Normand's avatar
Thibault Normand committed
642
    changeTabLeft->setShortcut(QApplication::layoutDirection() ?
643
                   QKeySequence(Qt::SHIFT+Qt::Key_Right) : QKeySequence(Qt::SHIFT+Qt::Key_Left));
644
    connect(changeTabLeft, SIGNAL(triggered(bool)), this, SLOT(slotChangeTabLeft()));
Thibault Normand's avatar
Thibault Normand committed
645

646
647
648
#if QT_VERSION >= 0x050000
    QAction* changeTabRight = actionCollection()->addAction(QLatin1String("next_tab"));
#else
Oliver Kellogg's avatar
Oliver Kellogg committed
649
    KAction* changeTabRight = actionCollection()->addAction(QLatin1String("next_tab"));
650
#endif
651
    changeTabRight->setText(QApplication::layoutDirection() ? selectTabLeftString : selectTabRightString);
Thibault Normand's avatar
Thibault Normand committed
652
    changeTabRight->setShortcut(QApplication::layoutDirection() ?
653
                    QKeySequence(Qt::SHIFT+Qt::Key_Left) : QKeySequence(Qt::SHIFT+Qt::Key_Right));
654
    connect(changeTabRight, SIGNAL(triggered(bool)), this, SLOT(slotChangeTabRight()));
Thibault Normand's avatar
Thibault Normand committed
655
656

// @todo Check if this should be ported
Oliver Kellogg's avatar
Oliver Kellogg committed
657
//     QMenu* menu = findMenu(QLatin1String("settings"));
Thibault Normand's avatar
Thibault Normand committed
658
//     menu->insertItem(i18n("&Windows"), dockHideShowMenu(), -1, 0);
659
660
661
662
663
664
665
666
667
668

    // disable actions at startup
    fileSave->setEnabled(true);
    fileSaveAs->setEnabled(true);
    enablePrint(false);
    editCut->setEnabled(false);
    editCopy->setEnabled(false);
    editPaste->setEnabled(false);
    editUndo->setEnabled(false);
    editRedo->setEnabled(false);
Thibault Normand's avatar
Thibault Normand committed
669
670
}

671
/**
672
 * Connected to by the  zoomAction, a value of between 300
673
 * and 2200 is scaled to zoom to between 9% and 525%.
674
 * The min and max values of the slider are hard coded in the statusbar slider.
675
 */
676
677
void UMLApp::slotZoomSliderMoved(int value)
{
678
    setZoom(value);
Thibault Normand's avatar
Thibault Normand committed
679
680
}

Andi Fischer's avatar
Andi Fischer committed
681
682
683
684
685
/**
 * Set zoom to fit the view.
 */
void UMLApp::slotZoomFit()
{
Ralf Habacker's avatar
Ralf Habacker committed
686
    QRectF items = currentView()->umlScene()->itemsBoundingRect();
687
688
689
690
    if (items.isNull()) {
        setZoom(100);
        return;
    }
Ralf Habacker's avatar
Ralf Habacker committed
691
692
693
694
    currentView()->umlScene()->setSceneRect(items);
    // TODO: QGraphicsView seems not to be informed about the scene rect update
    currentView()->setSceneRect(items);

695
696
    int scaleW = ceil(100.0 * currentView()->viewport()->width() / currentView()->umlScene()->width());
    int scaleH = ceil(100.0 * currentView()->viewport()->height() / currentView()->umlScene()->height());
Andi Fischer's avatar
Andi Fischer committed
697
698
699
700
701
702
703
    int scale = 100;
    if (scaleW < scaleH) {
        scale = scaleW;
    }
    else {
        scale = scaleH;
    }
704
705
706
707
708
709
710
    if (scale < 0)
        scale = 100;
    else if (scale > 500)
        scale = 500;
    else
        scale -= 2;
    setZoom(scale);
Andi Fischer's avatar
Andi Fischer committed
711
712
}

713
714
715
/**
 * Set zoom to 100%.
 */
716
717
void UMLApp::slotZoom100()
{
Thibault Normand's avatar
Thibault Normand committed
718
719
720
    setZoom(100);
}

721
722
723
724
725
/**
 * Decrease the zoom factor of the current diagram.
 */
void UMLApp::slotZoomOut()
{
726
    setZoom(currentView()->zoom()-5);
727
728
729
730
731
732
733
}

/**
 * Increase the zoom factor of the current diagram.
 */
void UMLApp::slotZoomIn()
{
734
    setZoom(currentView()->zoom()+5);
735
736
}

737
738
739
740
/**
 * Set the zoom factor of the current diagram.
 *
 * @param zoom  Zoom factor in percentage.
741
 * @param withView also setup the currently displayed diagram
742
 */
743
void UMLApp::setZoom(int zoom, bool withView)
744
{
745
746
747
    if (withView)
        currentView()->setZoom(zoom);
    bool oldState = m_pZoomSlider->blockSignals(true);
748
    m_pZoomSlider->setValue(zoom);
749
    m_pZoomSlider->blockSignals(oldState);
Oliver Kellogg's avatar
Oliver Kellogg committed
750
    m_zoomValueLbl->setText(QString::number(zoom) + QLatin1Char('%'));
Thibault Normand's avatar
Thibault Normand committed
751
752
}

753
754
755
756
757
/**
 * Set the zoom factor of the current diagram.
 *
 * @param action  Action which is called.
 */
758
759
760
761
void UMLApp::slotSetZoom(QAction* action)
{
    QVariant var = action->data();
    if (var.canConvert<int>()) {
762
        setZoom(var.toInt());
763
764
765
    }
}

766
767
768
/**
 * Helper method to create the zoom actions.
 */
769
770
771
772
773
QAction* UMLApp::createZoomAction(int zoom, int currentZoom)
{
    //IMPORTANT: The zoom value is added to the action.
    QAction* action = new QAction(this);
    action->setCheckable(true);
774
    action->setText(i18nc("%1 percent value from 20 to 500", " &%1%", zoom));
775