Repository navigation
Expand file tree
/
Copy pathkraken_appcontroller.h
More file actions
188 lines (169 loc) · 6.27 KB
/
Copy pathkraken_appcontroller.h
File metadata and controls
188 lines (169 loc) · 6.27 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
#ifndef KRAKEN_APPCONTROLLER_H
#define KRAKEN_APPCONTROLLER_H
#include <QObject>
#include <QSize>
#include <QString>
#include <QDir>
#include <QQmlComponent>
#include <QImage>
#include <QScreen>
#include <QJsonObject>
#include <QAnimationDriver>
#include <QQuickItem>
class SystemMonitor;
class KrakenZInterface;
class QTimer;
class QOpenGLContext;
class QOpenGLFramebufferObject;
class QOffscreenSurface;
class QQuickRenderControl;
class QQuickWindow;
class QQmlApplicationEngine;
class AnimationDriver : public QAnimationDriver
{
public:
AnimationDriver(int msPerStep) : mStep(msPerStep), mElapsed(0) {}
void advance() override {
mElapsed += mStep;
advanceAnimation();
}
qint64 elapsed() const override { return mElapsed; }
protected:
int mStep;
qint64 mElapsed;
};
class KrakenAppController : public QObject
{
Q_OBJECT
Q_PROPERTY(QQuickItem* container NOTIFY containerChanged MEMBER mContainer)
Q_PROPERTY(int frameDelay READ frameDelay WRITE setFrameDelay NOTIFY frameDelayChanged MEMBER mFrameDelay)
// Screen Size
Q_PROPERTY(QSize screenSize READ screenSize WRITE setScreenSize NOTIFY screenSizeChanged MEMBER mSize)
Q_PROPERTY(Qt::ScreenOrientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged MEMBER mOrientation);
// Application and preview control
Q_PROPERTY(AppMode mode READ mode NOTIFY modeChanged MEMBER mMode)
Q_PROPERTY(bool drawFPS READ drawFPS WRITE setDrawFPS NOTIFY drawFPSChanged MEMBER mDrawFPS)
Q_PROPERTY(bool showFPS READ showFPS WRITE setShowFPS NOTIFY showFPSChanged MEMBER mShowFPS)
Q_PROPERTY(QString loadedPath READ loadedPath NOTIFY loadedPathChanged MEMBER mLoadedPath)
Q_PROPERTY(bool animationPlaying READ animationPlaying WRITE setAnimationPlaying NOTIFY animationPlayingChanged MEMBER mPlaying)
public:
KrakenAppController(QObject* preview, KrakenZInterface* controller, SystemMonitor* monitor, QObject* parent = nullptr);
~KrakenAppController();
enum AppMode{ BUILT_IN = -1, STATIC_IMAGE = 0, GIF_MODE = 1, QML_APP = 2};
Q_ENUM(AppMode)
AppMode mode() {return mMode; }
// Public API
Q_INVOKABLE void loadImage(QString file_path);
Q_INVOKABLE bool loadQmlFile(QString path);
Q_INVOKABLE QJsonObject toJsonProfile();
Q_INVOKABLE void setOrientationFromAngle(int angle);
Q_INVOKABLE QString getLocalFolderPath(QString path);
bool event(QEvent *event) override;
bool animationPlaying() { return mPlaying; }
Q_INVOKABLE bool timerDrawn() { return mActive; }
QSize screenSize() { return mSize; }
void closeQmlApplications();
int depthSize() { return mDepthSize; }
int stencilSize() { return mStencilSize; }
int alphaSize() { return mAlphaSize; }
int blueSize() { return mBlueSize; }
int redSize() { return mRedSize; }
int greenSize() { return mGreenSize; }
int frameDelay() { return mFrameDelay; }
void setPrimaryScreen(QScreen* screen);
Qt::ScreenOrientation orientation() { return mOrientation; }
bool drawFPS() { return mDrawFPS; }
bool showFPS() { return mShowFPS; }
void setDepthSize(int depth_size);
void setStencilSize(int stencil_size);
void setAlphaSize(int alpha_size);
void setRedSize(int red_size);
void setBlueSize(int blue_size);
void setGreenSize(int green_size);
void setController(KrakenZInterface* controller);
QString loadedPath() { return mLoadedPath; }
void setSystemMonitor(SystemMonitor* monitor);
// Application Settings API
Q_INVOKABLE QJsonObject loadAppSettings();
Q_INVOKABLE void saveAppSettings(QJsonObject);
signals:
void containerChanged(QQuickItem* container);
void animationPlayingChanged(bool animation);
void appReady();
void qmlFailed(QString error);
void frameDelayChanged(int frame_delay);
void screenSizeChanged(QSize size);
void fpsChanged(int fps);
void initialized();
void draw();
void frameReady(QImage frame);
void orientationChanged(Qt::ScreenOrientation orientation);
void modeChanged(KrakenAppController::AppMode mode);
void loadGIFPrompt(QString file_path);
void drawFPSChanged(bool draw_fps);
void showFPSChanged(bool show_fps);
void loadedPathChanged(QString path);
public slots:
void initialize();
void initializeOffScreenWindow();
void setBuiltIn(bool loadingGif);
void setFrameDelay(int frame_delay);
void setScreenSize(QSize screen_size);
void setOrientation(Qt::ScreenOrientation orientation, bool updateController = true);
void setDrawFPS(bool draw_fps);
void setShowFPS(bool show_fps);
void setJsonProfile(QJsonObject profile);
void setAnimationPlaying(bool playing = true);
protected slots:
void userComponentReady();
void containerComponentReady();
void renderNext();
protected:
QObject* mPreview;
KrakenZInterface* mController;
SystemMonitor* mMonitor;
QQuickItem* mContainer;
QQuickItem* mCurrentApp;
QQmlComponent* mCurrentComponent;
QQmlComponent* mContainerComponent;
// Offscreen rendering
QOffscreenSurface* mOffscreenSurface;
QOpenGLContext* mGLContext;
QQuickRenderControl* mRenderControl;
QQuickWindow* mOffscreenWindow;
QOpenGLFramebufferObject* mFBO;
QQmlApplicationEngine* mAppEngine;
Qt::ScreenOrientation mOrientation;
// controlling the state
int mFrameDelay;
uint8_t mDrawCount;
bool mInitialized;
bool mActive;
AnimationDriver* mAnimationDriver;
// Surface format (set to match outgoing display)
QSize mSize;
int mDepthSize;
int mStencilSize;
int mAlphaSize;
int mBlueSize;
int mRedSize;
int mGreenSize;
QObject* mPrimaryScreen;
QTimer* mDelayTimer;
qreal mDPR;
AppMode mMode;
bool mDrawFPS;
bool mShowFPS;
bool mPlaying;
QString mLoadedPath;
void adjustAnimationDriver();
void createApplication();
void createContainer();
void handleComponentErrors();
void releaseApplication(bool deleteComponent = true);
void releaseAppEngine();
void resetAppEngine();
void setMode(AppMode mode);
void reconfigureSurfaceFormat();
};
#endif // KRAKEN_APPCONTROLLER_H