1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QQUICKWINDOW_H |
5 | #define QQUICKWINDOW_H |
6 | |
7 | #include <QtQuick/qtquickglobal.h> |
8 | #include <QtQuick/qsgrendererinterface.h> |
9 | |
10 | #include <QtCore/qmetatype.h> |
11 | #include <QtGui/qwindow.h> |
12 | #include <QtGui/qevent.h> |
13 | #include <QtQml/qqml.h> |
14 | #include <QtQml/qqmldebug.h> |
15 | #include <QtQml/qqmlinfo.h> |
16 | |
17 | QT_BEGIN_NAMESPACE |
18 | |
19 | class QRunnable; |
20 | class QQuickItem; |
21 | class QSGTexture; |
22 | class QInputMethodEvent; |
23 | class QQuickWindowPrivate; |
24 | class QQuickWindowAttached; |
25 | class QQmlIncubationController; |
26 | class QInputMethodEvent; |
27 | class QQuickCloseEvent; |
28 | class QQuickRenderControl; |
29 | class QSGRectangleNode; |
30 | class QSGImageNode; |
31 | class QSGNinePatchNode; |
32 | class QQuickPalette; |
33 | class QQuickRenderTarget; |
34 | class QQuickGraphicsDevice; |
35 | class QQuickGraphicsConfiguration; |
36 | class QRhi; |
37 | class QRhiSwapChain; |
38 | class QRhiTexture; |
39 | class QSGTextNode; |
40 | |
41 | class Q_QUICK_EXPORT QQuickWindow : public QWindow |
42 | { |
43 | Q_OBJECT |
44 | Q_PRIVATE_PROPERTY(QQuickWindow::d_func(), QQmlListProperty<QObject> data READ data DESIGNABLE false) |
45 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
46 | Q_PROPERTY(QQuickItem* contentItem READ contentItem CONSTANT) |
47 | Q_PROPERTY(QQuickItem* activeFocusItem READ activeFocusItem NOTIFY activeFocusItemChanged REVISION(2, 1)) |
48 | Q_PRIVATE_PROPERTY(QQuickWindow::d_func(), QQuickPalette *palette READ palette WRITE setPalette |
49 | RESET resetPalette NOTIFY paletteChanged REVISION(6, 2)) |
50 | QDOC_PROPERTY(QWindow* transientParent READ transientParent WRITE setTransientParent NOTIFY transientParentChanged) |
51 | Q_CLASSINFO("DefaultProperty" , "data" ) |
52 | Q_DECLARE_PRIVATE(QQuickWindow) |
53 | |
54 | QML_NAMED_ELEMENT(Window) |
55 | QML_ADDED_IN_VERSION(2, 0) |
56 | QML_REMOVED_IN_VERSION(2, 1) |
57 | public: |
58 | enum CreateTextureOption { |
59 | TextureHasAlphaChannel = 0x0001, |
60 | TextureHasMipmaps = 0x0002, |
61 | TextureOwnsGLTexture = 0x0004, |
62 | TextureCanUseAtlas = 0x0008, |
63 | TextureIsOpaque = 0x0010 |
64 | }; |
65 | |
66 | enum RenderStage { |
67 | BeforeSynchronizingStage, |
68 | AfterSynchronizingStage, |
69 | BeforeRenderingStage, |
70 | AfterRenderingStage, |
71 | AfterSwapStage, |
72 | NoStage |
73 | }; |
74 | |
75 | Q_DECLARE_FLAGS(CreateTextureOptions, CreateTextureOption) |
76 | Q_FLAG(CreateTextureOptions) |
77 | |
78 | enum SceneGraphError { |
79 | ContextNotAvailable = 1 |
80 | }; |
81 | Q_ENUM(SceneGraphError) |
82 | |
83 | enum TextRenderType { |
84 | QtTextRendering, |
85 | NativeTextRendering, |
86 | CurveTextRendering |
87 | }; |
88 | Q_ENUM(TextRenderType) |
89 | |
90 | explicit QQuickWindow(QWindow *parent = nullptr); |
91 | explicit QQuickWindow(QQuickRenderControl *renderControl); |
92 | |
93 | ~QQuickWindow() override; |
94 | |
95 | QQuickItem *contentItem() const; |
96 | |
97 | QQuickItem *activeFocusItem() const; |
98 | QObject *focusObject() const override; |
99 | |
100 | QQuickItem *mouseGrabberItem() const; |
101 | |
102 | QImage grabWindow(); |
103 | |
104 | void setRenderTarget(const QQuickRenderTarget &target); |
105 | QQuickRenderTarget renderTarget() const; |
106 | |
107 | struct GraphicsStateInfo { |
108 | int currentFrameSlot; |
109 | int framesInFlight; |
110 | }; |
111 | const GraphicsStateInfo &graphicsStateInfo(); |
112 | void beginExternalCommands(); |
113 | void endExternalCommands(); |
114 | QQmlIncubationController *incubationController() const; |
115 | |
116 | #if QT_CONFIG(accessibility) |
117 | QAccessibleInterface *accessibleRoot() const override; |
118 | #endif |
119 | |
120 | // Scene graph specific functions |
121 | QSGTexture *createTextureFromImage(const QImage &image) const; |
122 | QSGTexture *createTextureFromImage(const QImage &image, CreateTextureOptions options) const; |
123 | QSGTexture *createTextureFromRhiTexture(QRhiTexture *texture, CreateTextureOptions options = {}) const; |
124 | |
125 | void setColor(const QColor &color); |
126 | QColor color() const; |
127 | |
128 | static bool hasDefaultAlphaBuffer(); |
129 | static void setDefaultAlphaBuffer(bool useAlpha); |
130 | |
131 | void setPersistentGraphics(bool persistent); |
132 | bool isPersistentGraphics() const; |
133 | |
134 | void setPersistentSceneGraph(bool persistent); |
135 | bool isPersistentSceneGraph() const; |
136 | |
137 | bool isSceneGraphInitialized() const; |
138 | |
139 | void scheduleRenderJob(QRunnable *job, RenderStage schedule); |
140 | |
141 | qreal effectiveDevicePixelRatio() const; |
142 | |
143 | QSGRendererInterface *rendererInterface() const; |
144 | |
145 | static void setGraphicsApi(QSGRendererInterface::GraphicsApi api); |
146 | static QSGRendererInterface::GraphicsApi graphicsApi(); |
147 | |
148 | static void setSceneGraphBackend(const QString &backend); |
149 | static QString sceneGraphBackend(); |
150 | |
151 | void setGraphicsDevice(const QQuickGraphicsDevice &device); |
152 | QQuickGraphicsDevice graphicsDevice() const; |
153 | |
154 | void setGraphicsConfiguration(const QQuickGraphicsConfiguration &config); |
155 | QQuickGraphicsConfiguration graphicsConfiguration() const; |
156 | |
157 | QSGRectangleNode *createRectangleNode() const; |
158 | QSGImageNode *createImageNode() const; |
159 | QSGNinePatchNode *createNinePatchNode() const; |
160 | QSGTextNode *createTextNode() const; |
161 | |
162 | static TextRenderType textRenderType(); |
163 | static void setTextRenderType(TextRenderType renderType); |
164 | |
165 | QRhi *rhi() const; |
166 | QRhiSwapChain *swapChain() const; |
167 | |
168 | Q_SIGNALS: |
169 | void frameSwapped(); |
170 | void sceneGraphInitialized(); |
171 | void sceneGraphInvalidated(); |
172 | void beforeSynchronizing(); |
173 | Q_REVISION(2, 2) void afterSynchronizing(); |
174 | void beforeRendering(); |
175 | void afterRendering(); |
176 | Q_REVISION(2, 2) void afterAnimating(); |
177 | Q_REVISION(2, 2) void sceneGraphAboutToStop(); |
178 | |
179 | Q_REVISION(2, 1) void closing(QQuickCloseEvent *close); |
180 | void colorChanged(const QColor &); |
181 | Q_REVISION(2, 1) void activeFocusItemChanged(); |
182 | Q_REVISION(2, 2) void sceneGraphError(QQuickWindow::SceneGraphError error, const QString &message); |
183 | |
184 | Q_REVISION(2, 14) void beforeRenderPassRecording(); |
185 | Q_REVISION(2, 14) void afterRenderPassRecording(); |
186 | |
187 | Q_REVISION(6, 0) void paletteChanged(); |
188 | Q_REVISION(6, 0) void paletteCreated(); |
189 | |
190 | Q_REVISION(6, 0) void beforeFrameBegin(); |
191 | Q_REVISION(6, 0) void afterFrameEnd(); |
192 | |
193 | public Q_SLOTS: |
194 | void update(); |
195 | void releaseResources(); |
196 | |
197 | protected: |
198 | QQuickWindow(QQuickWindowPrivate &dd, QWindow *parent = nullptr); |
199 | QQuickWindow(QQuickWindowPrivate &dd, QQuickRenderControl *control); |
200 | |
201 | void exposeEvent(QExposeEvent *) override; |
202 | void resizeEvent(QResizeEvent *) override; |
203 | |
204 | void showEvent(QShowEvent *) override; |
205 | void hideEvent(QHideEvent *) override; |
206 | void closeEvent(QCloseEvent *) override; |
207 | |
208 | void focusInEvent(QFocusEvent *) override; |
209 | void focusOutEvent(QFocusEvent *) override; |
210 | |
211 | bool event(QEvent *) override; |
212 | |
213 | // These overrides are no longer normal entry points for |
214 | // input events, but kept in case legacy code calls them. |
215 | void keyPressEvent(QKeyEvent *) override; |
216 | void keyReleaseEvent(QKeyEvent *) override; |
217 | void mousePressEvent(QMouseEvent *) override; |
218 | void mouseReleaseEvent(QMouseEvent *) override; |
219 | void mouseDoubleClickEvent(QMouseEvent *) override; |
220 | void mouseMoveEvent(QMouseEvent *) override; |
221 | #if QT_CONFIG(wheelevent) |
222 | void wheelEvent(QWheelEvent *) override; |
223 | #endif |
224 | #if QT_CONFIG(tabletevent) |
225 | void tabletEvent(QTabletEvent *) override; |
226 | #endif |
227 | |
228 | private Q_SLOTS: |
229 | void maybeUpdate(); |
230 | void cleanupSceneGraph(); |
231 | void physicalDpiChanged(); |
232 | void handleScreenChanged(QScreen *screen); |
233 | void runJobsAfterSwap(); |
234 | void handleApplicationStateChanged(Qt::ApplicationState state); |
235 | void handleFontDatabaseChanged(); |
236 | private: |
237 | #ifndef QT_NO_DEBUG_STREAM |
238 | inline friend QQmlInfo operator<<(QQmlInfo info, const QQuickWindow *window) |
239 | { |
240 | info.QDebug::operator<<(t: window); |
241 | return info; |
242 | } |
243 | #endif |
244 | |
245 | friend class QQuickItem; |
246 | friend class QQuickItemPrivate; |
247 | friend class QQuickWidget; |
248 | friend class QQuickRenderControl; |
249 | friend class QQuickAnimatorController; |
250 | friend class QQuickWidgetPrivate; |
251 | friend class QQuickDeliveryAgentPrivate; |
252 | Q_DISABLE_COPY(QQuickWindow) |
253 | }; |
254 | |
255 | #ifndef QT_NO_DEBUG_STREAM |
256 | QDebug Q_QUICK_EXPORT operator<<(QDebug debug, const QQuickWindow *item); |
257 | |
258 | inline QQmlInfo operator<<(QQmlInfo info, const QWindow *window) |
259 | { |
260 | info.QDebug::operator<<(t: window); |
261 | return info; |
262 | } |
263 | #endif |
264 | |
265 | QT_END_NAMESPACE |
266 | |
267 | Q_DECLARE_METATYPE(QQuickWindow *) |
268 | |
269 | #endif // QQUICKWINDOW_H |
270 | |
271 | |