/src/qtbase/src/gui/kernel/qwindow.h
Line | Count | Source (jump to first uncovered line) |
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 QWINDOW_H |
5 | | #define QWINDOW_H |
6 | | |
7 | | #include <QtGui/qtguiglobal.h> |
8 | | #include <QtCore/QObject> |
9 | | #include <QtCore/QEvent> |
10 | | #include <QtCore/QMargins> |
11 | | #include <QtCore/QRect> |
12 | | |
13 | | #include <QtCore/qnamespace.h> |
14 | | #include <QtCore/qnativeinterface.h> |
15 | | |
16 | | #include <QtGui/qsurface.h> |
17 | | #include <QtGui/qsurfaceformat.h> |
18 | | #include <QtGui/qwindowdefs.h> |
19 | | |
20 | | #include <QtGui/qicon.h> |
21 | | |
22 | | #ifndef QT_NO_CURSOR |
23 | | #include <QtGui/qcursor.h> |
24 | | #endif |
25 | | |
26 | | QT_BEGIN_NAMESPACE |
27 | | |
28 | | |
29 | | class QWindowPrivate; |
30 | | |
31 | | class QExposeEvent; |
32 | | class QPaintEvent; |
33 | | class QFocusEvent; |
34 | | class QMoveEvent; |
35 | | class QResizeEvent; |
36 | | class QShowEvent; |
37 | | class QHideEvent; |
38 | | class QCloseEvent; |
39 | | class QKeyEvent; |
40 | | class QMouseEvent; |
41 | | #if QT_CONFIG(wheelevent) |
42 | | class QWheelEvent; |
43 | | #endif |
44 | | class QTouchEvent; |
45 | | #if QT_CONFIG(tabletevent) |
46 | | class QTabletEvent; |
47 | | #endif |
48 | | |
49 | | class QPlatformSurface; |
50 | | class QPlatformWindow; |
51 | | class QBackingStore; |
52 | | class QScreen; |
53 | | class QAccessibleInterface; |
54 | | class QWindowContainer; |
55 | | #ifndef QT_NO_DEBUG_STREAM |
56 | | class QDebug; |
57 | | #endif |
58 | | #if QT_CONFIG(vulkan) || defined(Q_QDOC) |
59 | | class QVulkanInstance; |
60 | | #endif |
61 | | |
62 | | class Q_GUI_EXPORT QWindow : public QObject, public QSurface |
63 | | { |
64 | | Q_OBJECT |
65 | | Q_DECLARE_PRIVATE(QWindow) |
66 | | |
67 | | // All properties which are declared here are inherited by QQuickWindow and therefore available in QML. |
68 | | // So please think carefully about what it does to the QML namespace if you add any new ones, |
69 | | // particularly the possible meanings these names might have in any specializations of Window. |
70 | | // For example "state" (meaning windowState) is not a good property to declare, because it has |
71 | | // a different meaning in QQuickItem, and users will tend to assume it is the same for Window. |
72 | | |
73 | | // Any new properties which you add here MUST be versioned and MUST be documented both as |
74 | | // C++ properties in qwindow.cpp AND as QML properties in qquickwindow.cpp. |
75 | | // https://doc.qt.io/qt/qtqml-cppintegration-definetypes.html#type-revisions-and-versions |
76 | | |
77 | | Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY windowTitleChanged) |
78 | | Q_PROPERTY(Qt::WindowModality modality READ modality WRITE setModality NOTIFY modalityChanged) |
79 | | Q_PROPERTY(Qt::WindowFlags flags READ flags WRITE setFlags NOTIFY flagsChanged) |
80 | | Q_PROPERTY(int x READ x WRITE setX NOTIFY xChanged) |
81 | | Q_PROPERTY(int y READ y WRITE setY NOTIFY yChanged) |
82 | | Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged) |
83 | | Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged) |
84 | | Q_PROPERTY(int minimumWidth READ minimumWidth WRITE setMinimumWidth NOTIFY minimumWidthChanged) |
85 | | Q_PROPERTY(int minimumHeight READ minimumHeight WRITE setMinimumHeight |
86 | | NOTIFY minimumHeightChanged) |
87 | | Q_PROPERTY(int maximumWidth READ maximumWidth WRITE setMaximumWidth NOTIFY maximumWidthChanged) |
88 | | Q_PROPERTY(int maximumHeight READ maximumHeight WRITE setMaximumHeight |
89 | | NOTIFY maximumHeightChanged) |
90 | | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) |
91 | | Q_PROPERTY(bool active READ isActive NOTIFY activeChanged REVISION(2, 1)) |
92 | | Q_PROPERTY(Visibility visibility READ visibility WRITE setVisibility NOTIFY visibilityChanged |
93 | | REVISION(2, 1)) |
94 | | Q_PROPERTY(Qt::ScreenOrientation contentOrientation READ contentOrientation |
95 | | WRITE reportContentOrientationChange NOTIFY contentOrientationChanged) |
96 | | Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged REVISION(2, 1)) |
97 | | #ifdef Q_QDOC |
98 | | Q_PROPERTY(QWindow* transientParent READ transientParent WRITE setTransientParent NOTIFY transientParentChanged) |
99 | | #else |
100 | | Q_PRIVATE_PROPERTY(QWindow::d_func(), QWindow* transientParent MEMBER transientParent |
101 | | WRITE setTransientParent NOTIFY transientParentChanged REVISION(2, 13)) |
102 | | #endif |
103 | | |
104 | | public: |
105 | | enum Visibility { |
106 | | Hidden = 0, |
107 | | AutomaticVisibility, |
108 | | Windowed, |
109 | | Minimized, |
110 | | Maximized, |
111 | | FullScreen |
112 | | }; |
113 | | Q_ENUM(Visibility) |
114 | | |
115 | | enum AncestorMode { |
116 | | ExcludeTransients, |
117 | | IncludeTransients |
118 | | }; |
119 | | Q_ENUM(AncestorMode) |
120 | | |
121 | | explicit QWindow(QScreen *screen = nullptr); |
122 | | explicit QWindow(QWindow *parent); |
123 | | ~QWindow(); |
124 | | |
125 | | void setSurfaceType(SurfaceType surfaceType); |
126 | | SurfaceType surfaceType() const override; |
127 | | |
128 | | bool isVisible() const; |
129 | | |
130 | | Visibility visibility() const; |
131 | | void setVisibility(Visibility v); |
132 | | |
133 | | void create(); |
134 | | |
135 | | WId winId() const; |
136 | | |
137 | | QWindow *parent(AncestorMode mode = ExcludeTransients) const; |
138 | | void setParent(QWindow *parent); |
139 | | |
140 | | bool isTopLevel() const; |
141 | | |
142 | | bool isModal() const; |
143 | | Qt::WindowModality modality() const; |
144 | | void setModality(Qt::WindowModality modality); |
145 | | |
146 | | void setFormat(const QSurfaceFormat &format); |
147 | | QSurfaceFormat format() const override; |
148 | | QSurfaceFormat requestedFormat() const; |
149 | | |
150 | | void setFlags(Qt::WindowFlags flags); |
151 | | Qt::WindowFlags flags() const; |
152 | | void setFlag(Qt::WindowType, bool on = true); |
153 | | Qt::WindowType type() const; |
154 | | |
155 | | QString title() const; |
156 | | |
157 | | void setOpacity(qreal level); |
158 | | qreal opacity() const; |
159 | | |
160 | | void setMask(const QRegion ®ion); |
161 | | QRegion mask() const; |
162 | | |
163 | | bool isActive() const; |
164 | | |
165 | | void reportContentOrientationChange(Qt::ScreenOrientation orientation); |
166 | | Qt::ScreenOrientation contentOrientation() const; |
167 | | |
168 | | qreal devicePixelRatio() const; |
169 | | |
170 | | Qt::WindowState windowState() const; |
171 | | Qt::WindowStates windowStates() const; |
172 | | void setWindowState(Qt::WindowState state); |
173 | | void setWindowStates(Qt::WindowStates states); |
174 | | |
175 | | void setTransientParent(QWindow *parent); |
176 | | QWindow *transientParent() const; |
177 | | |
178 | | bool isAncestorOf(const QWindow *child, AncestorMode mode = IncludeTransients) const; |
179 | | |
180 | | bool isExposed() const; |
181 | | |
182 | 0 | inline int minimumWidth() const { return minimumSize().width(); } |
183 | 0 | inline int minimumHeight() const { return minimumSize().height(); } |
184 | 0 | inline int maximumWidth() const { return maximumSize().width(); } |
185 | 0 | inline int maximumHeight() const { return maximumSize().height(); } |
186 | | |
187 | | QSize minimumSize() const; |
188 | | QSize maximumSize() const; |
189 | | QSize baseSize() const; |
190 | | QSize sizeIncrement() const; |
191 | | |
192 | | void setMinimumSize(const QSize &size); |
193 | | void setMaximumSize(const QSize &size); |
194 | | void setBaseSize(const QSize &size); |
195 | | void setSizeIncrement(const QSize &size); |
196 | | |
197 | | QRect geometry() const; |
198 | | |
199 | | QMargins frameMargins() const; |
200 | | QRect frameGeometry() const; |
201 | | |
202 | | QPoint framePosition() const; |
203 | | void setFramePosition(const QPoint &point); |
204 | | |
205 | | QMargins safeAreaMargins() const; |
206 | | |
207 | 0 | inline int width() const { return geometry().width(); } |
208 | 0 | inline int height() const { return geometry().height(); } |
209 | 0 | inline int x() const { return geometry().x(); } |
210 | 0 | inline int y() const { return geometry().y(); } |
211 | | |
212 | 0 | QSize size() const override { return geometry().size(); } |
213 | 0 | inline QPoint position() const { return geometry().topLeft(); } |
214 | | |
215 | | void setPosition(const QPoint &pt); |
216 | | void setPosition(int posx, int posy); |
217 | | |
218 | | void resize(const QSize &newSize); |
219 | | void resize(int w, int h); |
220 | | |
221 | | void setFilePath(const QString &filePath); |
222 | | QString filePath() const; |
223 | | |
224 | | void setIcon(const QIcon &icon); |
225 | | QIcon icon() const; |
226 | | |
227 | | void destroy(); |
228 | | |
229 | | QPlatformWindow *handle() const; |
230 | | |
231 | | bool setKeyboardGrabEnabled(bool grab); |
232 | | bool setMouseGrabEnabled(bool grab); |
233 | | |
234 | | QScreen *screen() const; |
235 | | void setScreen(QScreen *screen); |
236 | | |
237 | | virtual QAccessibleInterface *accessibleRoot() const; |
238 | | virtual QObject *focusObject() const; |
239 | | |
240 | | QPointF mapToGlobal(const QPointF &pos) const; |
241 | | QPointF mapFromGlobal(const QPointF &pos) const; |
242 | | QPoint mapToGlobal(const QPoint &pos) const; |
243 | | QPoint mapFromGlobal(const QPoint &pos) const; |
244 | | |
245 | | #ifndef QT_NO_CURSOR |
246 | | QCursor cursor() const; |
247 | | void setCursor(const QCursor &); |
248 | | void unsetCursor(); |
249 | | #endif |
250 | | |
251 | | static QWindow *fromWinId(WId id); |
252 | | |
253 | | #if QT_CONFIG(vulkan) || defined(Q_QDOC) |
254 | | void setVulkanInstance(QVulkanInstance *instance); |
255 | | QVulkanInstance *vulkanInstance() const; |
256 | | #endif |
257 | | |
258 | | QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(QWindow) |
259 | | |
260 | | public Q_SLOTS: |
261 | | Q_REVISION(2, 1) void requestActivate(); |
262 | | |
263 | | void setVisible(bool visible); |
264 | | |
265 | | void show(); |
266 | | void hide(); |
267 | | |
268 | | void showMinimized(); |
269 | | void showMaximized(); |
270 | | void showFullScreen(); |
271 | | void showNormal(); |
272 | | |
273 | | bool close(); |
274 | | void raise(); |
275 | | void lower(); |
276 | | bool startSystemResize(Qt::Edges edges); |
277 | | bool startSystemMove(); |
278 | | |
279 | | void setTitle(const QString &); |
280 | | |
281 | | void setX(int arg); |
282 | | void setY(int arg); |
283 | | void setWidth(int arg); |
284 | | void setHeight(int arg); |
285 | | void setGeometry(int posx, int posy, int w, int h); |
286 | | void setGeometry(const QRect &rect); |
287 | | |
288 | | void setMinimumWidth(int w); |
289 | | void setMinimumHeight(int h); |
290 | | void setMaximumWidth(int w); |
291 | | void setMaximumHeight(int h); |
292 | | |
293 | | Q_REVISION(2, 1) void alert(int msec); |
294 | | |
295 | | Q_REVISION(2, 3) void requestUpdate(); |
296 | | |
297 | | Q_SIGNALS: |
298 | | void screenChanged(QScreen *screen); |
299 | | void modalityChanged(Qt::WindowModality modality); |
300 | | Q_REVISION(6, 10) void flagsChanged(Qt::WindowFlags flags); |
301 | | void windowStateChanged(Qt::WindowState windowState); |
302 | | Q_REVISION(2, 2) void windowTitleChanged(const QString &title); |
303 | | |
304 | | void xChanged(int arg); |
305 | | void yChanged(int arg); |
306 | | |
307 | | void widthChanged(int arg); |
308 | | void heightChanged(int arg); |
309 | | |
310 | | void minimumWidthChanged(int arg); |
311 | | void minimumHeightChanged(int arg); |
312 | | void maximumWidthChanged(int arg); |
313 | | void maximumHeightChanged(int arg); |
314 | | |
315 | | Q_REVISION(6, 9) void safeAreaMarginsChanged(QMargins arg); |
316 | | |
317 | | void visibleChanged(bool arg); |
318 | | Q_REVISION(2, 1) void visibilityChanged(QWindow::Visibility visibility); |
319 | | Q_REVISION(2, 1) void activeChanged(); |
320 | | void contentOrientationChanged(Qt::ScreenOrientation orientation); |
321 | | |
322 | | void focusObjectChanged(QObject *object); |
323 | | |
324 | | Q_REVISION(2, 1) void opacityChanged(qreal opacity); |
325 | | |
326 | | Q_REVISION(2, 13) void transientParentChanged(QWindow *transientParent); |
327 | | |
328 | | protected: |
329 | | virtual void exposeEvent(QExposeEvent *); |
330 | | virtual void resizeEvent(QResizeEvent *); |
331 | | virtual void paintEvent(QPaintEvent *); |
332 | | virtual void moveEvent(QMoveEvent *); |
333 | | virtual void focusInEvent(QFocusEvent *); |
334 | | virtual void focusOutEvent(QFocusEvent *); |
335 | | |
336 | | virtual void showEvent(QShowEvent *); |
337 | | virtual void hideEvent(QHideEvent *); |
338 | | virtual void closeEvent(QCloseEvent *); |
339 | | |
340 | | virtual bool event(QEvent *) override; |
341 | | virtual void keyPressEvent(QKeyEvent *); |
342 | | virtual void keyReleaseEvent(QKeyEvent *); |
343 | | virtual void mousePressEvent(QMouseEvent *); |
344 | | virtual void mouseReleaseEvent(QMouseEvent *); |
345 | | virtual void mouseDoubleClickEvent(QMouseEvent *); |
346 | | virtual void mouseMoveEvent(QMouseEvent *); |
347 | | #if QT_CONFIG(wheelevent) |
348 | | virtual void wheelEvent(QWheelEvent *); |
349 | | #endif |
350 | | virtual void touchEvent(QTouchEvent *); |
351 | | #if QT_CONFIG(tabletevent) |
352 | | virtual void tabletEvent(QTabletEvent *); |
353 | | #endif |
354 | | virtual bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result); |
355 | | |
356 | | QWindow(QWindowPrivate &dd, QWindow *parent); |
357 | | |
358 | | private: |
359 | | Q_PRIVATE_SLOT(d_func(), void _q_clearAlert()) |
360 | | QPlatformSurface *surfaceHandle() const override; |
361 | | |
362 | | Q_DISABLE_COPY(QWindow) |
363 | | |
364 | | friend class QGuiApplication; |
365 | | friend class QGuiApplicationPrivate; |
366 | | friend class QWindowContainer; |
367 | | friend Q_GUI_EXPORT QWindowPrivate *qt_window_private(QWindow *window); |
368 | | }; |
369 | | |
370 | | #ifndef Q_QDOC |
371 | | // should these be seen by clang-qdoc? |
372 | | template <> inline QWindow *qobject_cast<QWindow*>(QObject *o) |
373 | 0 | { |
374 | 0 | if (!o || !o->isWindowType()) return nullptr; |
375 | 0 | return static_cast<QWindow*>(o); |
376 | 0 | } |
377 | | template <> inline const QWindow *qobject_cast<const QWindow*>(const QObject *o) |
378 | 0 | { |
379 | 0 | if (!o || !o->isWindowType()) return nullptr; |
380 | 0 | return static_cast<const QWindow*>(o); |
381 | 0 | } |
382 | | #endif // !Q_QDOC |
383 | | |
384 | | #ifndef QT_NO_DEBUG_STREAM |
385 | | Q_GUI_EXPORT QDebug operator<<(QDebug, const QWindow *); |
386 | | #endif |
387 | | |
388 | | QT_END_NAMESPACE |
389 | | |
390 | | #endif // QWINDOW_H |