Debian Codegraph @

src/editor/mediator.hpp

raw symbols SCIP
1 // This file is part of Dust Racing 2D.
2 // Copyright (C) 2018 Jussi Lind <[email protected]>
3 //
4 // Dust Racing 2D is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 // Dust Racing 2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>.
15
16 #ifndef MEDIATOR_HPP
17 #define MEDIATOR_HPP
18
19 #include <QString>
20
21 #include "editormode.hpp"
22 #include "targetnode.hpp"
23
24 #include <memory>
25 #include <tuple>
26
27 class DragAndDropStore;
28 class EditorData;
29 class EditorView;
30 class MainWindow;
31 class TrackTile;
32 class Object;
33 class QAction;
34 class QGraphicsScene;
35 class QLayout;
36
37 /*! Acts as a communication channel between MainWindow and editor components:
38 *
39 * - MainWindow <-> Mediator <-> QGraphicsScene / EditorView / EditorData
40 * - EditorView <-> Mediator <-> EditorData
41 */
42 class Mediator
43 {
44 public:
45 explicit Mediator(MainWindow & mainWindow);
46
47 ~Mediator();
48
49 void addCurrentToolBarObjectToScene(QPointF clickedScenePos);
50
51 void addItem(QGraphicsItem * item);
52
53 void addObject(std::shared_ptr<Object> object);
54
55 void addViewToLayout(QLayout * layout);
56
57 bool beginSetRoute();
58
59 void clearEditMode();
60
61 void clearRoute();
62
63 int cols();
64
65 void console(QString message);
66
67 QString currentFileName() const;
68
69 QAction * currentToolBarAction() const;
70
71 DragAndDropStore & dadStore();
72
73 void deleteColumn();
74
75 void deleteRow();
76
77 void endSetRoute();
78
79 void enableUndo(bool enable);
80
81 void floodFill(TrackTile & tile, QAction * action, const QString & typeToFill);
82
83 int fitScale();
84
85 void initScene();
86
87 std::tuple<bool, QString, int, int> initializeNewTrack();
88
89 void insertColumnAfter();
90
91 void insertColumnBefore();
92
93 void insertRowAfter();
94
95 void insertRowBefore();
96
97 bool isUndoable() const;
98
99 bool isRedoable() const;
100
101 void mouseWheelZoom(int delta);
102
103 bool openTrack(QString fileName);
104
105 void pushNewTargetNodeToRoute(QPointF pos);
106
107 void redo();
108
109 void removeItem(QGraphicsItem * item);
110
111 void removeObject(Object & object);
112
113 bool routeHasNodes() const;
114
115 int rows();
116
117 void saveUndoPoint();
118
119 bool saveTrackData();
120
121 bool saveTrackDataAs(QString fileName);
122
123 void setScale(int value);
124
125 void setMode(EditorMode newMode);
126 EditorMode mode() const;
127
128 void setSelectedObject(Object * object);
129 Object * selectedObject() const;
130
131 void setSelectedTargetNode(TargetNode * tnode);
132 TargetNode * selectedTargetNode() const;
133
134 bool setTrackProperties();
135
136 void showStatusBarMessage(QString message);
137
138 void setupTrackAfterUndoOrRedo();
139
140 void undo();
141
142 void updateCoordinates(QPointF mappedPos);
143
144 void updateView();
145
146 private:
147 std::unique_ptr<EditorData> m_editorData;
148
149 QGraphicsScene * m_editorScene;
150
151 EditorView * m_editorView;
152
153 MainWindow & m_mainWindow;
154
155 EditorMode m_mode = EditorMode::None;
156 };
157
158 #endif // MEDIATOR_HPP