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
52QT_BEGIN_NAMESPACE
53
54class QRunnable;
55class QQuickItem;
56class QSGTexture;
57class QInputMethodEvent;
58class QQuickWindowPrivate;
59class QQuickWindowAttached;
60class QOpenGLContext;
61class QOpenGLFramebufferObject;
62class QQmlIncubationController;
63class QInputMethodEvent;
64class QQuickCloseEvent;
65class QQuickRenderControl;
66class QSGRectangleNode;
67class QSGImageNode;
68class QSGNinePatchNode;
69class QRhi;
70
71class 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)
80public:
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 explicit QQuickWindow(QWindow *parent = nullptr);
113 explicit QQuickWindow(QQuickRenderControl *renderControl);
114
115 ~QQuickWindow() override;
116
117 QQuickItem *contentItem() const;
118
119 QQuickItem *activeFocusItem() const;
120 QObject *focusObject() const override;
121
122 QQuickItem *mouseGrabberItem() const;
123
124#if QT_DEPRECATED_SINCE(5, 8)
125 QT_DEPRECATED bool sendEvent(QQuickItem *, QEvent *);
126#endif
127
128 QImage grabWindow();
129#if QT_CONFIG(opengl)
130 void setRenderTarget(QOpenGLFramebufferObject *fbo);
131 QOpenGLFramebufferObject *renderTarget() const;
132#endif
133 void setRenderTarget(uint fboId, const QSize &size);
134 uint renderTargetId() const;
135 QSize renderTargetSize() const;
136#if QT_CONFIG(opengl)
137 void resetOpenGLState();
138#endif
139 struct GraphicsStateInfo {
140 int currentFrameSlot = 0;
141 int framesInFlight = 0;
142 };
143 const GraphicsStateInfo *graphicsStateInfo();
144 void beginExternalCommands();
145 void endExternalCommands();
146 QQmlIncubationController *incubationController() const;
147
148#if QT_CONFIG(accessibility)
149 QAccessibleInterface *accessibleRoot() const override;
150#endif
151
152 // Scene graph specific functions
153 QSGTexture *createTextureFromImage(const QImage &image) const;
154 QSGTexture *createTextureFromImage(const QImage &image, CreateTextureOptions options) const;
155 QSGTexture *createTextureFromId(uint id, const QSize &size, CreateTextureOptions options = CreateTextureOption()) const;
156
157 void setClearBeforeRendering(bool enabled);
158 bool clearBeforeRendering() const;
159
160 void setColor(const QColor &color);
161 QColor color() const;
162
163 static bool hasDefaultAlphaBuffer();
164 static void setDefaultAlphaBuffer(bool useAlpha);
165
166 void setPersistentOpenGLContext(bool persistent);
167 bool isPersistentOpenGLContext() const;
168
169 void setPersistentSceneGraph(bool persistent);
170 bool isPersistentSceneGraph() const;
171
172 QOpenGLContext *openglContext() const;
173 bool isSceneGraphInitialized() const;
174
175 void scheduleRenderJob(QRunnable *job, RenderStage schedule);
176
177 qreal effectiveDevicePixelRatio() const;
178
179 QSGRendererInterface *rendererInterface() const;
180
181 static void setSceneGraphBackend(QSGRendererInterface::GraphicsApi api);
182 static void setSceneGraphBackend(const QString &backend);
183 static QString sceneGraphBackend();
184
185 QSGRectangleNode *createRectangleNode() const;
186 QSGImageNode *createImageNode() const;
187 QSGNinePatchNode *createNinePatchNode() const;
188
189 static TextRenderType textRenderType();
190 static void setTextRenderType(TextRenderType renderType);
191
192Q_SIGNALS:
193 void frameSwapped();
194 Q_REVISION(2) void openglContextCreated(QOpenGLContext *context);
195 void sceneGraphInitialized();
196 void sceneGraphInvalidated();
197 void beforeSynchronizing();
198 Q_REVISION(2) void afterSynchronizing();
199 void beforeRendering();
200 void afterRendering();
201 Q_REVISION(2) void afterAnimating();
202 Q_REVISION(2) void sceneGraphAboutToStop();
203
204 Q_REVISION(1) void closing(QQuickCloseEvent *close);
205 void colorChanged(const QColor &);
206 Q_REVISION(1) void activeFocusItemChanged();
207 Q_REVISION(2) void sceneGraphError(QQuickWindow::SceneGraphError error, const QString &message);
208
209 Q_REVISION(14) void beforeRenderPassRecording();
210 Q_REVISION(14) void afterRenderPassRecording();
211
212public Q_SLOTS:
213 void update();
214 void releaseResources();
215
216protected:
217 QQuickWindow(QQuickWindowPrivate &dd, QWindow *parent = nullptr);
218 QQuickWindow(QQuickWindowPrivate &dd, QQuickRenderControl *control);
219
220 void exposeEvent(QExposeEvent *) override;
221 void resizeEvent(QResizeEvent *) override;
222
223 void showEvent(QShowEvent *) override;
224 void hideEvent(QHideEvent *) override;
225 // TODO Qt 6: reimplement QWindow::closeEvent to emit closing
226
227 void focusInEvent(QFocusEvent *) override;
228 void focusOutEvent(QFocusEvent *) override;
229
230 bool event(QEvent *) override;
231 void keyPressEvent(QKeyEvent *) override;
232 void keyReleaseEvent(QKeyEvent *) override;
233 void mousePressEvent(QMouseEvent *) override;
234 void mouseReleaseEvent(QMouseEvent *) override;
235 void mouseDoubleClickEvent(QMouseEvent *) override;
236 void mouseMoveEvent(QMouseEvent *) override;
237#if QT_CONFIG(wheelevent)
238 void wheelEvent(QWheelEvent *) override;
239#endif
240
241private Q_SLOTS:
242 void maybeUpdate();
243 void cleanupSceneGraph();
244 void physicalDpiChanged();
245 void handleScreenChanged(QScreen *screen);
246 void setTransientParent_helper(QQuickWindow *window);
247 void runJobsAfterSwap();
248 void handleApplicationStateChanged(Qt::ApplicationState state);
249private:
250 friend class QQuickItem;
251 friend class QQuickWidget;
252 friend class QQuickRenderControl;
253 friend class QQuickAnimatorController;
254 friend class QQuickWidgetPrivate;
255 Q_DISABLE_COPY(QQuickWindow)
256};
257
258#ifndef QT_NO_DEBUG_STREAM
259QDebug Q_QUICK_EXPORT operator<<(QDebug debug, const QQuickWindow *item);
260#endif
261
262QT_END_NAMESPACE
263
264Q_DECLARE_METATYPE(QQuickWindow *)
265
266#endif // QQUICKWINDOW_H
267
268