-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCoreController.h
More file actions
250 lines (211 loc) · 8.77 KB
/
Copy pathCoreController.h
File metadata and controls
250 lines (211 loc) · 8.77 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
#ifndef CORECONTROLLER_H
#define CORECONTROLLER_H
#include <QObject>
#include <QQmlApplicationEngine>
#include <QTimer>
#include <QScopedPointer>
#include <QQuickItem>
class AnchorManager;
class BlockList;
class BlockManager;
class Engine;
class FileSystemManager;
class GuiManager;
class HandoffManager;
class KeyboardEmulator;
class LogManager;
class ProjectManager;
class WebsocketConnection;
/**
* @brief The CoreController class initializes all components and
* makes them available by getter functions.
*/
class CoreController : public QObject {
Q_OBJECT
Q_PROPERTY(bool developerMode READ getDeveloperMode WRITE setDeveloperMode NOTIFY developerModeChanged)
Q_PROPERTY(bool clickSounds READ getClickSounds WRITE setClickSounds NOTIFY clickSoundsChanged)
Q_PROPERTY(QString templateFileToImport READ getTemplateFileBaseName NOTIFY templateFileToImportChanged)
public:
/**
* @brief CoreController creates a CoreController object and initializes
* all Manager classes
* @param templateFile if not empty, imports this template on startup
* @param qmlEngine is the QML engine to use to create the GUI
* @param parent the QObject parent
*/
explicit CoreController(QQmlApplicationEngine* qmlEngine, QString templateFile = {}, QObject *parent = nullptr);
void finishLoading(QUrl mainQmlFile, bool restore=true, bool saveReguarly=true);
~CoreController();
signals:
void managersInitialized();
void developerModeChanged();
void clickSoundsChanged();
void templateFileToImportChanged();
public:
// ----------------------- Getter Methods for Manager classes:
void registerManager(QString name, QObject* manager);
template<typename T>
T* manager(QString name) const {
return qobject_cast<T*>(m_manager.value(name));
}
QNetworkAccessManager* networkAccessManager() const;
public slots:
QObject* managerQml(QString name) const { return m_manager.value(name); }
/**
* @brief guiManager is a Getter for the only GuiManager instance to use in this application
* @return a pointer to a GuiManager instance
*/
GuiManager* guiManager() { return m_guiManager.get(); }
/**
* @brief logManager is a Getter for the only LogManager instance to use in this application
* @return a pointer to a LogManager instance
*/
LogManager* logManager() { return m_logManager.get(); }
/**
* @brief engine is a Getter for the only Engine instance to use in this application
* @return a pointer to a LogManager instance
*/
Engine* engine() { return m_engine.get(); }
/**
* @brief dao is a Getter for the only FileSystemManager instance to use in this application
* @return a pointer to a FileSystemManager instance
*/
FileSystemManager* dao() { return m_dao.get(); }
/**
* @brief blockManager is a Getter for the only BlockManager instance to use in this application
* @return a pointer to a BlockManager instance
*/
BlockManager* blockManager() { return m_blockManager.get(); }
/**
* @brief projectManager is a Getter for the only ProjectManager instance to use in this application
* @return a pointer to a ProjectManager instance
*/
ProjectManager* projectManager() { return m_projectManager.get(); }
/**
* @brief anchorManager is a Getter for the only AnchorManager instance to use in this application
* @return a pointer to an AnchorManager instance
*/
AnchorManager* anchorManager() { return m_anchorManager.get(); }
/**
* @brief handoffManager is a Getter for the only HandoffManager instance to use in this application
* @return a pointer to a HandoffManager instance
*/
HandoffManager* handoffManager() { return m_handoffManager.get(); }
/**
* @brief keyboardEmulator is a Getter for the only KeyboardEmulator instance to use in this application
* @return a pointer to a KeyboardEmulator instance
*/
KeyboardEmulator* keyboardEmulator() { return m_keyboardEmulator.get(); }
/**
* @brief websocketConnection is a Getter for the only WebsocketConnection instance to use in this application
* @return a pointer to a WebsocketConnection instance
*/
WebsocketConnection* websocketConnection() { return m_websocketConnection.get(); }
// ----------------------------- State / Projects:
/**
* @brief saveAll saves the application state and current project to the filesystem
*/
void saveAll();
/**
* @brief restoreApp restores the application state and last loaded project from the filesystem,
* to be used at application startup only
*/
void restoreApp();
// ----------------------------- Start / Exit:
/**
* @brief onExit performs actions to be done before a normal application exit
* (stops the Engine, saves everything and deletes all blocks so that they can perform
* "on exit" actions)
*/
void onExit();
/**
* @brief onFirstStart is called only on first appliction start and loads the tutorial project
*/
void onFirstStart();
/**
* @brief askForPermissions shows dialogs to ask the user permission for various feautures
* on Android 6.0+
*/
void askForPermissions();
// ---------------------------- Powermate / universal Controller:
/**
* @brief onControllerRotated forwards the event to the currently focused block
* @param relativeAmount amount of rotation typicaly between 1/512 and 1/64 (accelerated)
* @param degrees amount of rotation in degrees (not accelerated)
* @param pressed true if powermate is pressed
*/
void onControllerRotated(double relativeAmount, double degrees, bool pressed);
/**
* @brief onControllerPressed forwards the event to the currently focused block
*/
void onControllerPressed();
/**
* @brief onControllerReleased forwards the event to the currently focused block
* @param duration how long the powermate was pressed
*/
void onControllerReleased(double duration);
// --------------------------- Getter / Setter:
bool getClickSounds() const { return m_clickSounds; }
void setClickSounds(bool value) { m_clickSounds = value; emit clickSoundsChanged(); }
QString getTemplateFileBaseName() const;
void requestTemplateImport(QString filename);
void onImportTemplateFileAccepted();
// --------------------------- Used in QML:
/**
* @brief getDeveloperMode returns the state of the developer mode
* @return true if developer mode is active
*/
bool getDeveloperMode() const { return m_developerMode; }
/**
* @brief setDeveloperMode enables or disables the developer mode
* @param value true to enable it
*/
void setDeveloperMode(bool value) { m_developerMode = value; emit developerModeChanged(); }
/**
* @brief getVersionString returns the version string to be displayed in GUI
* @return a version string
*/
QString getVersionString() const;
QString getBuildDate() const;
// TODO: move to a better place
void playClickSound();
void playClickUpSound();
// dummy methods for compatibility:
QObject* midiMapping() { return this; }
void registerGuiControl(QQuickItem*, QString) {}
void unregisterGuiControl(QString) {}
void guiControlHasBeenTouched(QString) {}
void sendFeedback(QString, double) const {}
protected:
QNetworkAccessManager* m_networkAccessManager = nullptr;
// Managers:
QScopedPointer<AnchorManager> m_anchorManager; //!< AnchorManager instance
QScopedPointer<BlockManager> m_blockManager; //!< BlockManager instance
QScopedPointer<Engine> m_engine; //!< Engine instance
QScopedPointer<FileSystemManager> m_dao; //!< FileSystemManager instance
QScopedPointer<GuiManager> m_guiManager; //!< GuiManager instance
QScopedPointer<HandoffManager> m_handoffManager; //!< HandoffManager instance
QScopedPointer<KeyboardEmulator> m_keyboardEmulator; //!< KeyboardEmulator instance
QScopedPointer<LogManager> m_logManager; //!< LogManager instance
QScopedPointer<ProjectManager> m_projectManager; //!< GlobalOscCommands instance
QScopedPointer<WebsocketConnection> m_websocketConnection; //!< WebsocketConnection instance
// Attributes:
/**
* @brief m_saveTimer timer to save app state on a regular basis
*/
QTimer m_saveTimer;
/**
* @brief m_developerMode true if developer mode is active
*/
bool m_developerMode;
/**
* @brief m_clickSounds true if click sounds should be played
*/
bool m_clickSounds;
/**
* @brief m_templateFileToImport file provided as commandline argument or via drag'n'drop that should be imported
*/
QString m_templateFileToImport;
QHash<QString, QObject*> m_manager;
};
#endif // CORECONTROLLER_H