forked from FredTingaud/FSM-Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFSMEditor.h
137 lines (111 loc) · 3.36 KB
/
FSMEditor.h
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
#pragma once
#include <QMainWindow>
#include <fsm-editor/FSMScene.h>
#include <fsm-editor/FSMView.h>
#include <QUndoStack>
class QToolBar;
class QUndoCommand;
class QPlainTextEdit;
class Settings;
class QMenuBar;
class QMenu;
class QSplitter;
class QLabel;
/**
* @brief Main class of the FSM Editor project.
*
* Include this QWidget in your application to use it.
* The FSMEditor takes a Settings object in its constructor, that allows to customize the
* editor, depending on the use-case.
*/
class FSMEditor : public QMainWindow
{
Q_OBJECT;
public:
FSMEditor(Settings& settings);
virtual ~FSMEditor();
/**
* Set whether the top level menu is visible.
* This parameter is initially set from Settings object, but can be overridden here.
*/
void setMenuVisible(bool visible);
/**
* Open a new empty graph.
* @return Whether the new graph was actually opened.
*/
Q_SLOT bool newGraph();
/**
* Call a file dialog and save in the selected file.
* @return Whether the file was actually saved.
*/
Q_SLOT bool saveAs();
/**
* Save in the current file if any, call "save as" otherwise.
* @return Whether the file was actually saved.
*/
Q_SLOT bool save();
/**
* Save in passed file.
* @return Whether the file was actually saved.
*/
Q_SLOT bool save(const QString& fileName);
/**
* Call a file dialog and open the selected file.
* @return Whether the file was actually opened.
*/
Q_SLOT bool open();
/**
* Open the passed file.
* @return Whether the file was actually opened.
*/
Q_SLOT bool open(const QString& fileName);
protected:
virtual void closeEvent(QCloseEvent *event) override;
private:
Q_SLOT void stackCommand(QUndoCommand* command);
Q_SLOT void beginMacro(const QString& title);
Q_SLOT void endMacro();
Q_SLOT void transferCodeChanged();
Q_SLOT void displaySetCode(const QString& code, const QString& error);
Q_SLOT void hideCode();
Q_SLOT void modifiedChanged(bool undoClean);
void setCurrentFile(QString fileName);
bool checkValidity();
private:
QWidget* makeViewPanel();
QWidget* makeCodeEditor();
void configureCodeEditor();
void configureErrorLabel();
void fillAllMenus(QToolBar* toolbar);
void completeFileMenu(QMenu* fileMenu);
void fillMenu(QToolBar* toolbar, QMenu* menu, const QList<std::tuple<QAction*, bool>>& actions);
QList<std::tuple<QAction*, bool>> createElementActions();
QList<std::tuple<QAction*, bool>> createUndoRedoActions();
QList<std::tuple<QAction*, bool>> createCopyPasteActions();
QList<std::tuple<QAction*, bool>> createZoomActions();
QList<std::tuple<QAction*, bool>> createFileActions();
void loadSettings();
void saveSettings();
/**
* Make sure everything is saved or discarded on purpose, before whipping the scene.
*/
bool maybeSave();
private:
static const QString LAST_DIR_KEY;
static const QString LAST_ZOOM;
static const QString LAST_SPLITS;
static const QString LAST_STATE;
static const QString LAST_GEOMETRY;
private:
Settings& settings_;
FSMScene scene_;
FSMView fsmView_;
QSplitter* splitter_;
QUndoStack undoStack_;
QPlainTextEdit* editor_;
QString lastDir_;
QString currentFile_;
QAction* saveAction_;
QMenuBar* menu_;
QLabel* errorLabel_;
};