1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtQuick module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QQUICKWINDOW_H |
41 | #define QQUICKWINDOW_H |
42 | |
43 | #include <QtQuick/qtquickglobal.h> |
44 | #include <QtQuick/qsgrendererinterface.h> |
45 | #include <QtCore/qmetatype.h> |
46 | #include <QtGui/qopengl.h> |
47 | #include <QtGui/qwindow.h> |
48 | #include <QtGui/qevent.h> |
49 | #include <QtQml/qqml.h> |
50 | #include <QtQml/qqmldebug.h> |
51 | |
52 | QT_BEGIN_NAMESPACE |
53 | |
54 | class QRunnable; |
55 | class QQuickItem; |
56 | class QSGTexture; |
57 | class QInputMethodEvent; |
58 | class QQuickWindowPrivate; |
59 | class QQuickWindowAttached; |
60 | class QOpenGLContext; |
61 | class QOpenGLFramebufferObject; |
62 | class QQmlIncubationController; |
63 | class QInputMethodEvent; |
64 | class QQuickCloseEvent; |
65 | class QQuickRenderControl; |
66 | class QSGRectangleNode; |
67 | class QSGImageNode; |
68 | class QSGNinePatchNode; |
69 | class QRhi; |
70 | |
71 | class Q_QUICK_EXPORT QQuickWindow : public QWindow |
72 | { |
73 | Q_OBJECT |
74 | Q_PRIVATE_PROPERTY(QQuickWindow::d_func(), QQmlListProperty<QObject> data READ data DESIGNABLE false) |
75 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
76 | Q_PROPERTY(QQuickItem* contentItem READ contentItem CONSTANT) |
77 | Q_PROPERTY(QQuickItem* activeFocusItem READ activeFocusItem NOTIFY activeFocusItemChanged REVISION 1) |
78 | Q_CLASSINFO("DefaultProperty" , "data" ) |
79 | Q_DECLARE_PRIVATE(QQuickWindow) |
80 | public: |
81 | enum CreateTextureOption { |
82 | TextureHasAlphaChannel = 0x0001, |
83 | TextureHasMipmaps = 0x0002, |
84 | TextureOwnsGLTexture = 0x0004, |
85 | TextureCanUseAtlas = 0x0008, |
86 | TextureIsOpaque = 0x0010 |
87 | }; |
88 | |
89 | enum RenderStage { |
90 | BeforeSynchronizingStage, |
91 | AfterSynchronizingStage, |
92 | BeforeRenderingStage, |
93 | AfterRenderingStage, |
94 | AfterSwapStage, |
95 | NoStage |
96 | }; |
97 | |
98 | Q_DECLARE_FLAGS(CreateTextureOptions, CreateTextureOption) |
99 | Q_FLAG(CreateTextureOptions) |
100 | |
101 | enum SceneGraphError { |
102 | ContextNotAvailable = 1 |
103 | }; |
104 | Q_ENUM(SceneGraphError) |
105 | |
106 | enum TextRenderType { |
107 | QtTextRendering, |
108 | NativeTextRendering |
109 | }; |
110 | Q_ENUM(TextRenderType) |
111 | |
112 | enum NativeObjectType { |
113 | NativeObjectTexture |
114 | }; |
115 | Q_ENUM(NativeObjectType) |
116 | |
117 | explicit QQuickWindow(QWindow *parent = nullptr); |
118 | explicit QQuickWindow(QQuickRenderControl *renderControl); |
119 | |
120 | ~QQuickWindow() override; |
121 | |
122 | QQuickItem *contentItem() const; |
123 | |
124 | QQuickItem *activeFocusItem() const; |
125 | QObject *focusObject() const override; |
126 | |
127 | QQuickItem *mouseGrabberItem() const; |
128 | |
129 | #if QT_DEPRECATED_SINCE(5, 8) |
130 | QT_DEPRECATED bool sendEvent(QQuickItem *, QEvent *); |
131 | #endif |
132 | |
133 | QImage grabWindow(); |
134 | #if QT_CONFIG(opengl) |
135 | void setRenderTarget(QOpenGLFramebufferObject *fbo); |
136 | QOpenGLFramebufferObject *renderTarget() const; |
137 | #endif |
138 | void setRenderTarget(uint fboId, const QSize &size); |
139 | uint renderTargetId() const; |
140 | QSize renderTargetSize() const; |
141 | #if QT_CONFIG(opengl) |
142 | void resetOpenGLState(); |
143 | #endif |
144 | struct GraphicsStateInfo { |
145 | int currentFrameSlot; |
146 | int framesInFlight; |
147 | }; |
148 | const GraphicsStateInfo &graphicsStateInfo(); |
149 | void beginExternalCommands(); |
150 | void endExternalCommands(); |
151 | QQmlIncubationController *incubationController() const; |
152 | |
153 | #if QT_CONFIG(accessibility) |
154 | QAccessibleInterface *accessibleRoot() const override; |
155 | #endif |
156 | |
157 | // Scene graph specific functions |
158 | QSGTexture *createTextureFromImage(const QImage &image) const; |
159 | QSGTexture *createTextureFromImage(const QImage &image, CreateTextureOptions options) const; |
160 | |
161 | #if QT_DEPRECATED_SINCE(5, 15) |
162 | QT_DEPRECATED_X("Use createTextureFromNativeObject() instead" ) |
163 | QSGTexture *createTextureFromId(uint id, const QSize &size, CreateTextureOptions options = CreateTextureOption()) const; |
164 | #endif |
165 | |
166 | QSGTexture *createTextureFromNativeObject(NativeObjectType type, |
167 | const void *nativeObjectPtr, |
168 | int nativeLayout, |
169 | const QSize &size, |
170 | CreateTextureOptions options = CreateTextureOption()) const; |
171 | |
172 | void setClearBeforeRendering(bool enabled); |
173 | bool clearBeforeRendering() const; |
174 | |
175 | void setColor(const QColor &color); |
176 | QColor color() const; |
177 | |
178 | static bool hasDefaultAlphaBuffer(); |
179 | static void setDefaultAlphaBuffer(bool useAlpha); |
180 | |
181 | void setPersistentOpenGLContext(bool persistent); |
182 | bool isPersistentOpenGLContext() const; |
183 | |
184 | void setPersistentSceneGraph(bool persistent); |
185 | bool isPersistentSceneGraph() const; |
186 | |
187 | QOpenGLContext *openglContext() const; |
188 | bool isSceneGraphInitialized() const; |
189 | |
190 | void scheduleRenderJob(QRunnable *job, RenderStage schedule); |
191 | |
192 | qreal effectiveDevicePixelRatio() const; |
193 | |
194 | QSGRendererInterface *rendererInterface() const; |
195 | |
196 | static void setSceneGraphBackend(QSGRendererInterface::GraphicsApi api); |
197 | static void setSceneGraphBackend(const QString &backend); |
198 | static QString sceneGraphBackend(); |
199 | |
200 | QSGRectangleNode *createRectangleNode() const; |
201 | QSGImageNode *createImageNode() const; |
202 | QSGNinePatchNode *createNinePatchNode() const; |
203 | |
204 | static TextRenderType textRenderType(); |
205 | static void setTextRenderType(TextRenderType renderType); |
206 | |
207 | Q_SIGNALS: |
208 | void frameSwapped(); |
209 | Q_REVISION(2) void openglContextCreated(QOpenGLContext *context); |
210 | void sceneGraphInitialized(); |
211 | void sceneGraphInvalidated(); |
212 | void beforeSynchronizing(); |
213 | Q_REVISION(2) void afterSynchronizing(); |
214 | void beforeRendering(); |
215 | void afterRendering(); |
216 | Q_REVISION(2) void afterAnimating(); |
217 | Q_REVISION(2) void sceneGraphAboutToStop(); |
218 | |
219 | Q_REVISION(1) void closing(QQuickCloseEvent *close); |
220 | void colorChanged(const QColor &); |
221 | Q_REVISION(1) void activeFocusItemChanged(); |
222 | Q_REVISION(2) void sceneGraphError(QQuickWindow::SceneGraphError error, const QString &message); |
223 | |
224 | Q_REVISION(14) void beforeRenderPassRecording(); |
225 | Q_REVISION(14) void afterRenderPassRecording(); |
226 | |
227 | public Q_SLOTS: |
228 | void update(); |
229 | void releaseResources(); |
230 | |
231 | protected: |
232 | QQuickWindow(QQuickWindowPrivate &dd, QWindow *parent = nullptr); |
233 | QQuickWindow(QQuickWindowPrivate &dd, QQuickRenderControl *control); |
234 | |
235 | void exposeEvent(QExposeEvent *) override; |
236 | void resizeEvent(QResizeEvent *) override; |
237 | |
238 | void showEvent(QShowEvent *) override; |
239 | void hideEvent(QHideEvent *) override; |
240 | // TODO Qt 6: reimplement QWindow::closeEvent to emit closing |
241 | |
242 | void focusInEvent(QFocusEvent *) override; |
243 | void focusOutEvent(QFocusEvent *) override; |
244 | |
245 | bool event(QEvent *) override; |
246 | void keyPressEvent(QKeyEvent *) override; |
247 | void keyReleaseEvent(QKeyEvent *) override; |
248 | void mousePressEvent(QMouseEvent *) override; |
249 | void mouseReleaseEvent(QMouseEvent *) override; |
250 | void mouseDoubleClickEvent(QMouseEvent *) override; |
251 | void mouseMoveEvent(QMouseEvent *) override; |
252 | #if QT_CONFIG(wheelevent) |
253 | void wheelEvent(QWheelEvent *) override; |
254 | #endif |
255 | #if QT_CONFIG(tabletevent) |
256 | void tabletEvent(QTabletEvent *) override; |
257 | #endif |
258 | |
259 | private Q_SLOTS: |
260 | void maybeUpdate(); |
261 | void cleanupSceneGraph(); |
262 | void physicalDpiChanged(); |
263 | void handleScreenChanged(QScreen *screen); |
264 | void setTransientParent_helper(QQuickWindow *window); |
265 | void runJobsAfterSwap(); |
266 | void handleApplicationStateChanged(Qt::ApplicationState state); |
267 | private: |
268 | friend class QQuickItem; |
269 | friend class QQuickWidget; |
270 | friend class QQuickRenderControl; |
271 | friend class QQuickAnimatorController; |
272 | friend class QQuickWidgetPrivate; |
273 | Q_DISABLE_COPY(QQuickWindow) |
274 | }; |
275 | |
276 | #ifndef QT_NO_DEBUG_STREAM |
277 | QDebug Q_QUICK_EXPORT operator<<(QDebug debug, const QQuickWindow *item); |
278 | #endif |
279 | |
280 | QT_END_NAMESPACE |
281 | |
282 | Q_DECLARE_METATYPE(QQuickWindow *) |
283 | |
284 | #endif // QQUICKWINDOW_H |
285 | |
286 | |