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

source code of qtdeclarative/src/quick/items/qquickwindow.h