-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathmainWindow.h
More file actions
418 lines (310 loc) · 13.4 KB
/
mainWindow.h
File metadata and controls
418 lines (310 loc) · 13.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
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
408
409
410
411
412
413
414
415
416
417
418
/* Copyright 2007-2015 QReal Research Group, Dmitry Mordvinov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License. */
#pragma once
#include <QtWidgets/QMainWindow>
#include "scriptAPI/scriptAPI.h"
#include <qrgui/plugins/toolPluginInterface/usedInterfaces/mainWindowInterpretersInterface.h>
#include <qrgui/plugins/toolPluginInterface/usedInterfaces/mainWindowDockInterface.h>
#include <qrgui/preferencesDialog/preferencesDialog.h>
#include <textEditor/qscintillaTextEdit.h>
class QGraphicsView;
class QSignalMapper;
class QListWidget;
class QTreeView;
class PropertyEditorModel;
class FindManager;
class FindReplaceDialog;
namespace Ui {
class MainWindowUi;
}
namespace qReal {
class Controller;
class EditorManagerInterface;
class ProjectManagerWrapper;
class SplashScreen;
class StartWidget;
class SystemFacade;
class ToolPluginManager;
class ActionInfo;
namespace gui {
class ErrorReporter;
class PaletteTree;
namespace editor {
class SceneCustomizer;
class EditorView;
class PropertyEditorView;
}
}
namespace models {
class Models;
}
namespace text {
class TextManager;
}
class MainWindow : public QMainWindow
, public qReal::gui::MainWindowInterpretersInterface
, public qReal::gui::MainWindowDockInterface
{
Q_OBJECT
public:
explicit MainWindow(const QString &fileToOpen = QString());
~MainWindow() override;
EditorManagerInterface &editorManager();
gui::editor::EditorView *getCurrentTab() const;
bool isCurrentTabShapeEdit() const;
models::Models &models();
Controller *controller() const;
gui::editor::PropertyEditorView *propertyEditor() const;
QTreeView *graphicalModelExplorer() const;
QTreeView *logicalModelExplorer() const;
PropertyEditorModel &propertyModel();
ToolPluginManager &toolManager();
QModelIndex rootIndex() const;
void highlight(const Id &graphicalId, bool exclusive = true, const QColor &color = Qt::red) override;
void dehighlight(const Id &graphicalId) override;
void dehighlight() override;
ErrorReporterInterface *errorReporter() override;
Id activeDiagram() const override;
IdList openedDiagrams() const override;
void openShapeEditor(const QPersistentModelIndex &index, int role, const QString &propertyValue
, bool useTypedPorts);
void openQscintillaTextEditor(const QPersistentModelIndex &index, const int role, const QString &propertyValue);
void openShapeEditor(const Id &id
, const QString &propertyValue
/// @todo: whan passing it by reference the build on travis fails
, const EditorManagerInterface *editorManager
, bool useTypedPorts);
void showAndEditPropertyInTextEditor(const QString &title, const QString &text, const QPersistentModelIndex &index
, const int &role);
void openReferenceList(const QPersistentModelIndex &index, const QString &referenceType
, const QString &propertyValue, int role);
void openSettingsDialog(const QString &tab) override;
void showErrors(gui::ErrorReporter *reporter);
/// Tells if we should display trace connections menu or not
//virtual void showInTextEditor(const QFileInfo &fileInfo);
void reinitModels() override;
QWidget *windowWidget() override;
bool unloadPlugin(const QString &pluginName) override;
bool loadPlugin(const QString &fileName, const QString &pluginName) override;
bool pluginLoaded(const QString &pluginName) override;
void saveDiagramAsAPictureToFile(const QString &fileName) override;
void arrangeElementsByDotRunner(const QString &algorithm, const QString &absolutePathToDotFiles) override;
IdList selectedElementsOnActiveDiagram() override;
void updateActiveDiagram() override;
void deleteElementFromDiagram(const Id &id) override;
void reportOperation(const QFuture<void> &operation, const QString &description = QString()) override;
QWidget *currentTab() override;
QList<QWidget*> allTabs() const override;
void openTab(QWidget *tab, const QString &title) override;
void closeTab(QWidget *tab) override;
QMap<QString, gui::PreferencesPage *> preferencesPages() const override;
/// Closes tab having given id as root id. If there is no such tab, does nothing.
/// @param id Id of a diagram (root element) that we want to close.
void closeDiagramTab(const Id &id);
/// Loads (or reloads) available editor plugins and reinits palette.
void loadEditorPlugins();
/// Clears selection on all opened tabs.
void clearSelectionOnTabs();
QDockWidget *logicalModelDock() const override;
QDockWidget *graphicalModelDock() const override;
QDockWidget *propertyEditorDock() const override;
QDockWidget *errorReporterDock() const override;
QDockWidget *paletteDock() const override;
QDockWidget *minimapDock() const override;
QStatusBar *statusBar() const override;
QList<QToolBar *> toolBars() const override;
void tabifyDockWidget(QDockWidget *first, QDockWidget *second) override;
void addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockWidget) override;
void addToolBar(Qt::ToolBarArea area, QToolBar * const toolbar) override;
QByteArray saveState(int version = 0) const override;
bool restoreState(const QByteArray &state, int version = 0) override;
void setCorner(Qt::Corner corner, Qt::DockWidgetArea area) override;
void setTabText(QWidget *tab, const QString &text) override;
void beginPaletteModification() override;
void setElementInPaletteVisible(const Id &metatype, bool visible) override;
void setVisibleForAllElementsInPalette(const Id &diagram, bool visible) override;
void setElementInPaletteEnabled(const Id &metatype, bool enabled) override;
void setEnabledForAllElementsInPalette(const Id &diagram, bool enabled) override;
void endPaletteModification() override;
/// Additional actions for interpreter palette.
QList<QAction *> optionalMenuActionsForInterpretedPlugins();
signals:
void rootDiagramChanged();
public slots:
void propertyEditorScrollTo(const QModelIndex &index);
void activateItemOrDiagram(const Id &id, bool setSelected = true) override;
void activateItemOrDiagram(const QModelIndex &idx, bool setSelected = true);
void selectItem(const Id &id) override;
void selectItemOrDiagram(const Id &graphicalId) override;
void selectItemWithError(const Id &id);
void showErrors(const gui::ErrorReporter * const errorReporter);
void changePaletteRepresentation();
void closeStartTab();
void closeAllTabs();
void refreshRecentProjectsList(const QString &fileName);
void createDiagram(const QString &idString);
/// Creates project with specified root diagram
bool createProject(const QString &diagramIdString);
void openFirstDiagram();
void changeWindowTitle();
void registerEditor(EditorInterface &editor) override;
private slots:
/// Suggests user to select a root diagram for the new project
/// if more than one diagram loaded or creates project with the only diagram
/// as root otherwise
void createProject();
/// Diagram opening must happen after plugins initialization
void initPluginsAndStartWidget();
void initToolPlugins();
void customizeActionsVisibility();
/// handler for menu 'button find' pressed
void showFindDialog();
void adjustMinimapZoom(int zoom);
void updateTabName(const Id &id);
void showAbout() const;
void showHelp();
void openLogs() const;
void fullscreen();
void hideBottomDocks();
void openRecentProjectsMenu();
void tryToSave();
void saveDiagramAsAPicture();
void print();
void makeSvg();
void showGrid(bool isChecked);
void sceneSelectionChanged();
void applySettings();
void resetToolbarSize(int size);
void closeCurrentTab();
void closeTab(int index);
/// Closes the appropriate tab if the specified index corresponds to the diagram on one of the tabs
/// @return true if one of the tabs was closed
bool closeTab(const QModelIndex &graphicsIndex);
void showPreferencesDialog();
void connectActions();
void connectSystemEvents();
void initActionsFromSettings();
void centerOn(const Id &id);
void graphicalModelExplorerClicked(const QModelIndex &index);
void logicalModelExplorerClicked(const QModelIndex &index);
void openNewTab(const QModelIndex &index);
/// Called after current tab was changed somehow --- opened, closed, switched to other
/// @param newIndex Index of a new active tab, -1 if there is none
void currentTabChanged(int newIndex);
void showGestures();
void showAlignment(bool isChecked);
void switchGrid(bool isChecked);
void switchAlignment(bool isChecked);
void setData(const QString &data, const QPersistentModelIndex &index, const int &role);
void setReference(const QStringList &data, const QPersistentModelIndex &index, const int &role);
void openShapeEditor();
void updatePaletteIcons();
void setTextChanged(qReal::text::QScintillaTextEdit *editor, bool changed);
void saveScript();
private:
/// Initializes a tab if it is a diagram --- sets its logical and graphical
/// models, connects to various main window actions and so on
/// @param tab Tab to be initialized
/// @param rootIndex Index of a graphical model element that will be root of a diagram shown in this tab
void initCurrentTab(qReal::gui::editor::EditorView * const tab, const QModelIndex &rootIndex);
/// Sets shortcuts for a given tab which don`t have own buttons anywhere
/// @param tab Tab to be initialized with shortcuts
void setShortcuts(qReal::gui::editor::EditorView * const tab);
void setDefaultShortcuts();
void registerMetaTypes();
QListWidget* createSaveListWidget();
void closeEvent(QCloseEvent *event) override;
void deleteFromLogicalExplorer();
void deleteFromGraphicalExplorer();
QString getSaveFileName(const QString &dialogWindowTitle);
QString getOpenFileName(const QString &dialogWindowTitle);
QString getWorkingFile(const QString &dialogWindowTitle, bool save);
void selectItemInLogicalModel(const Id &id);
void switchToTab(int index);
int getTabIndex(const QModelIndex &index);
void initGridProperties();
void clickErrorListWidget();
void setShowGrid(bool isChecked);
void setShowAlignment(bool isChecked);
void setSwitchGrid(bool isChecked);
void setSwitchAlignment(bool isChecked);
void addActionOrSubmenu(QMenu *target, const ActionInfo &actionOrMenu);
/// Traverses list of actions and adds buttons to toolbar.
/// @param actions - list of actions to traverse
void traverseListOfActions(const QList<ActionInfo> &actions);
void addExternalToolActions();
void setIndexesOfPropertyEditor(const Id &id);
void setBackReference(const QPersistentModelIndex &index, const QString &data);
void removeOldBackReference(const QPersistentModelIndex &index, const int role);
void removeReferences(const Id &id);
/// Check if we need to hide widget in fullscreen mode or not. If we do, hide it
/// @param dockWidget QDockWidget to hide
/// @param name Widget's name in internal map
void hideDockWidget(QDockWidget *dockWidget, const QString &name);
/// Check if we need to show widget in fullscreen mode or not. If we do, show it
/// @param dockWidget QDockWidget to show
/// @param name Widget's name in internal map
void showDockWidget(QDockWidget *dockWidget, const QString &name);
/// Find edges that connect items from itemsToDelete and should be deleted with them
/// @param itemsToDelete selected items that should be deleted
void addEdgesToBeDeleted(IdList &itemsToDelete);
QString getNextDirName(const QString &name);
void initMiniMap();
void customizeWindow();
void initTabs();
void initDocks();
void initExplorers();
void initRecentProjectsMenu();
void initScriptAPI();
void initActionWidgetsNames();
void openStartTab() override;
void setVersion(const QString &version);
void highlightCode(Id const &graphicalId, bool highlight);
void updateUndoRedoState();
Ui::MainWindowUi *mUi;
QScopedPointer<SystemFacade> mFacade;
QScopedPointer<SplashScreen> mSplashScreen;
/// elements & theirs ids
QMap<QString, Id> mElementsNamesAndIds;
/// mFindDialog - Dialog for searching elements.
FindReplaceDialog *mFindReplaceDialog; //Has ownership
QScopedPointer<gui::ErrorReporter> mErrorReporter;
QScopedPointer<PropertyEditorModel> mPropertyModel;
QScopedPointer<text::TextManager> mTextManager;
QScopedPointer<ProjectManagerWrapper> mProjectManager;
QScopedPointer<Controller> mController;
EditorInterface* mCurrentEditor {}; // No ownership
QVector<bool> mSaveListChecked;
QStringList mDiagramsList;
QModelIndex mRootIndex;
/// Fullscreen mode flag
bool mIsFullscreen { false };
/// Internal map table to store info what widgets should we hide/show
QMap<QString, bool> mDocksVisibility;
QString mTempDir;
qReal::gui::PreferencesDialog *mPreferencesDialog; //Has ownership
int mRecentProjectsLimit {};
QMenu *mRecentProjectsMenu {}; // Has ownership
QScopedPointer<FindManager> mFindHelper;
StartWidget *mStartWidget {}; // Has ownership
QScopedPointer<qReal::gui::editor::SceneCustomizer> mSceneCustomizer;
QList<QDockWidget *> mAdditionalDocks;
QMap<QWidget *, int> mLastTabBarIndexes;
QList<QAction *> mListOfAdditionalActions; // doesn't have ownership
/// A field for storing file name passed as console argument
QString mInitialFileToOpen;
gui::ScriptAPI *mScriptAPI {}; // Has ownership, but manages via worker thread
bool mRestoreDefaultSettingsOnClose {};
};
}