Debian Codegraph @

src/editor/mainwindow.hpp

raw symbols SCIP
1 // This file is part of Dust Racing 2D.
2 // Copyright (C) 2015 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 MAINWINDOW_HPP
17 #define MAINWINDOW_HPP
18
19 #include <QCloseEvent>
20 #include <QMainWindow>
21 #include <QString>
22
23 #include <memory>
24
25 class AboutDlg;
26 class ObjectModelLoader;
27 class QAction;
28 class QCheckBox;
29 class QSlider;
30 class QTextEdit;
31 class QToolBar;
32
33 class Mediator;
34 class TrackData;
35
36 /*! \class MainWindow
37 * \brief The main window of the editor.
38 */
39 class MainWindow : public QMainWindow
40 {
41 Q_OBJECT
42
43 public:
44 //! Constructor.
45 //! The constructor tries to load object models from
46 //! Config::DATA_PATH/objects.conf.
47 //! \param trackFile Track given as command line argument.
48 explicit MainWindow(QString trackFile = "");
49
50 //! Destructor
51 ~MainWindow() override;
52
53 //! Return the singleton MainWindow.
54 static MainWindow * instance();
55
56 //! Return the current tool bar action, or nullptr if none.
57 QAction * currentToolBarAction() const;
58
59 //! Print text to the console.
60 void console(QString text);
61
62 //! Get reference to the object loaded.
63 ObjectModelLoader & objectModelLoader() const;
64
65 //! Set Windows title + the given file name.
66 void setTitle(QString openFileName);
67
68 //! Return true if objects will be rotated at random.
69 bool randomlyRotateObjects() const;
70
71 public slots:
72
73 //! Begin marking the route.
74 void beginSetRoute();
75
76 void enableUndo(bool enable);
77
78 //! End marking the route.
79 void endSetRoute();
80
81 void setVisible(bool visible) override;
82
83 void updateScaleSlider(int value);
84
85 protected:
86 void closeEvent(QCloseEvent * event) override;
87
88 private slots:
89
90 void clearRoute();
91
92 bool doOpenTrack(QString fileName);
93
94 void handleToolBarActionClick(QAction * action);
95
96 void initializeNewTrack();
97
98 void saveTrack();
99
100 void saveAsTrack();
101
102 void setTrackProperties();
103
104 void setupTrackAfterUndoOrRedo();
105
106 void showAboutDlg();
107
108 void showAboutQtDlg();
109
110 void showTip();
111
112 void openArgTrack();
113
114 void openTrack();
115
116 void updateScale(int value);
117
118 private:
119 void addObjectsToToolBar();
120
121 void clearEditMode();
122
123 void createWidgets();
124
125 void fitScale();
126
127 void init();
128
129 bool loadObjectModels(QString objectFilePath);
130
131 void populateMenuBar();
132
133 void populateToolBar();
134
135 void setActionStatesOnNewTrack();
136
137 std::unique_ptr<ObjectModelLoader> m_objectModelLoader;
138
139 std::unique_ptr<Mediator> m_mediator;
140
141 AboutDlg * m_aboutDlg;
142
143 QTextEdit * m_console;
144
145 QAction * m_saveAction = nullptr;
146
147 QAction * m_saveAsAction = nullptr;
148
149 QAction * m_currentToolBarAction = nullptr;
150
151 QAction * m_undoAction = nullptr;
152
153 QAction * m_redoAction = nullptr;
154
155 QAction * m_clearRouteAction = nullptr;
156
157 QAction * m_setRouteAction = nullptr;
158
159 QAction * m_setTrackPropertiesAction = nullptr;
160
161 QSlider * m_scaleSlider = nullptr;
162
163 QToolBar * m_toolBar = nullptr;
164
165 QCheckBox * m_randomRotationCheck = nullptr;
166
167 QString m_argTrackFile;
168
169 bool m_saved = false;
170
171 const char * m_settingsGroup = "MainWindow";
172
173 const unsigned int m_minZoom = 0;
174
175 const unsigned int m_maxZoom = 200;
176
177 const unsigned int m_initZoom = 100;
178
179 const int m_consoleHeight = 64;
180
181 static MainWindow * m_instance;
182 };
183
184 #endif // MAINWINDOW_HPP