-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuickView.h
172 lines (135 loc) · 3.71 KB
/
QuickView.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
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
#ifndef QT_UTILS_QUICK_VIEW_H
#define QT_UTILS_QUICK_VIEW_H
#include "./Setup.h"
#if (_MSC_VER)
# pragma warning ( push, 0 )
#endif
#include <QQuickView>
#include <QStack>
#include <QTimer>
#include <QFlag>
#if (_MSC_VER)
# pragma warning ( pop )
#endif
QT_UTILS_NAMESPACE_BEGIN
//!
//! Implement a QQuickView and improve provides support for the following:
//!
//! - Save and restore position/size/maximized states. This works only if a
//! Settings instance has been created.
//! - Support dynamic switch to fullscreen using the `fullscreen` property.
//! - Makes itself available to QML through the global `rootView` property.
//!
//! Here is a quick example of how to use it:
//!
//! ```
//! int main(int argc, char ** argv)
//! {
//! QApplication app(argc, argv);
//! QuickView view;
//! view.setSource(QUrl("qrc:/Main.qml"));
//! view.Restore(800, 600, QWindow::Visibility::Windowed);
//! return app.exec();
//! }
//! ```
//!
//! That's all. On the first run, the view will have a 800 by 600 size,
//! and on the next runs, it will automatically restore the previous position,
//! size and maximized state.
//!
class QuickView
: public QQuickView
{
Q_OBJECT
public:
enum class PersistenceFlags
{
None = 0,
FullScreen = 1,
Maximized = 1 << 1,
Position = 1 << 2,
Size = 1 << 3,
All = FullScreen | Maximized | Position | Size
};
typedef QFlags< PersistenceFlags > Persistence;
private:
Q_PROPERTY(bool fullscreen READ IsFullScreen WRITE SetFullScreen NOTIFY fullscreenChanged)
Q_PROPERTY(bool maximized READ IsMaximized WRITE SetMaximized NOTIFY maximizedChanged)
Q_PROPERTY(bool minimized READ IsMinimized WRITE SetMinimized NOTIFY minimizedChanged)
Q_PROPERTY(Persistence persistence READ GetPersistence WRITE SetPersistence NOTIFY persistenceChanged)
signals:
void fullscreenChanged(bool fullscreen);
void maximizedChanged(bool maximized);
void minimizedChanged(bool minimized);
void persistenceChanged(Persistence persistence);
public:
// constructor
QuickView(void);
// C++ API
inline bool IsReady(void) const;
inline bool IsFullScreen(void) const;
void SetFullScreen(bool value);
inline bool IsMaximized(void) const;
void SetMaximized(bool value);
inline bool IsMinimized(void) const;
void SetMinimized(bool value);
inline Persistence GetPersistence(void) const;
void SetPersistence(Persistence value);
void Restore(int width, int height, QWindow::Visibility visibility);
protected:
// reimplemented from QObject
bool eventFilter(QObject * watched, QEvent * event) override;
private:
// helpers
QRect GetRestoreRect(void) const;
//! Persitence flags
Persistence m_Persistence;
//! minimized state
bool m_Minimized;
//! maximized state
bool m_Maximized;
//! true if we're in fullscreen
bool m_FullScreen;
//! the windowed geometry
QRect m_WindowedGeometry;
//! window flags
Qt::WindowFlags m_Flags;
};
//!
//! Returns true if the status of the view is ready
//!
inline bool QuickView::IsReady(void) const
{
return this->status() == QQuickView::Status::Ready;
}
//!
//! Get the current fullscreen state.
//!
inline bool QuickView::IsFullScreen(void) const
{
return m_FullScreen;
}
//!
//! Get the current maximized state.
//!
inline bool QuickView::IsMaximized(void) const
{
return m_Maximized;
}
//!
//! Get the current minimized state.
//!
inline bool QuickView::IsMinimized(void) const
{
return m_Minimized;
}
//!
//! Get the persistence flags.
//!
inline QuickView::Persistence QuickView::GetPersistence(void) const
{
return m_Persistence;
}
Q_DECLARE_OPERATORS_FOR_FLAGS(QuickView::Persistence)
QT_UTILS_NAMESPACE_END
#endif