/src/qtbase/src/gui/kernel/qwindow.h
Line | Count | Source |
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 VIRTUAL) |
91 | | Q_PROPERTY(bool active READ isActive NOTIFY activeChanged REVISION(2, 1)) |
92 | | Q_PROPERTY(Visibility visibility READ visibility WRITE setVisibility NOTIFY visibilityChanged VIRTUAL REVISION(2, 1)) |
93 | | Q_PROPERTY(Qt::ScreenOrientation contentOrientation READ contentOrientation |
94 | | WRITE reportContentOrientationChange NOTIFY contentOrientationChanged) |
95 | | Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged REVISION(2, 1)) |
96 | | #ifdef Q_QDOC |
97 | | Q_PROPERTY(QWindow* transientParent READ transientParent WRITE setTransientParent NOTIFY transientParentChanged) |
98 | | #else |
99 | | Q_PRIVATE_PROPERTY(QWindow::d_func(), QWindow* transientParent MEMBER transientParent |
100 | | WRITE setTransientParent NOTIFY transientParentChanged REVISION(2, 13)) |
101 | | #endif |
102 | | |
103 | | public: |
104 | | enum Visibility { |
105 | | Hidden = 0, |
106 | | AutomaticVisibility, |
107 | | Windowed, |
108 | | Minimized, |
109 | | Maximized, |
110 | | FullScreen |
111 | | }; |
112 | | Q_ENUM(Visibility) |
113 | | |
114 | | enum AncestorMode { |
115 | | ExcludeTransients, |
116 | | IncludeTransients |
117 | | }; |
118 | | Q_ENUM(AncestorMode) |
119 | | |
120 | | explicit QWindow(QScreen *screen = nullptr); |
121 | | explicit QWindow(QWindow *parent); |
122 | | ~QWindow(); |
123 | | |
124 | | void setSurfaceType(SurfaceType surfaceType); |
125 | | SurfaceType surfaceType() const override; |
126 | | |
127 | | bool isVisible() const; |
128 | | |
129 | | Visibility visibility() const; |
130 | | void setVisibility(Visibility v); |
131 | | |
132 | | void create(); |
133 | | |
134 | | WId winId() const; |
135 | | |
136 | | QWindow *parent(AncestorMode mode = ExcludeTransients) const; |
137 | | void setParent(QWindow *parent); |
138 | | |
139 | | bool isTopLevel() const; |
140 | | |
141 | | bool isModal() const; |
142 | | Qt::WindowModality modality() const; |
143 | | void setModality(Qt::WindowModality modality); |
144 | | |
145 | | void setFormat(const QSurfaceFormat &format); |
146 | | QSurfaceFormat format() const override; |
147 | | QSurfaceFormat requestedFormat() const; |
148 | | |
149 | | void setFlags(Qt::WindowFlags flags); |
150 | | Qt::WindowFlags flags() const; |
151 | | void setFlag(Qt::WindowType, bool on = true); |
152 | | Qt::WindowType type() const; |
153 | | |
154 | | QString title() const; |
155 | | |
156 | | void setOpacity(qreal level); |
157 | | qreal opacity() const; |
158 | | |
159 | | void setMask(const QRegion ®ion); |
160 | | QRegion mask() const; |
161 | | |
162 | | bool isActive() const; |
163 | | |
164 | | void reportContentOrientationChange(Qt::ScreenOrientation orientation); |
165 | | Qt::ScreenOrientation contentOrientation() const; |
166 | | |
167 | | qreal devicePixelRatio() const; |
168 | | |
169 | | Qt::WindowState windowState() const; |
170 | | Qt::WindowStates windowStates() const; |
171 | | void setWindowState(Qt::WindowState state); |
172 | | void setWindowStates(Qt::WindowStates states); |
173 | | |
174 | | void setTransientParent(QWindow *parent); |
175 | | QWindow *transientParent() const; |
176 | | |
177 | | bool isAncestorOf(const QWindow *child, AncestorMode mode = IncludeTransients) const; |
178 | | |
179 | | bool isExposed() const; |
180 | | |
181 | 0 | inline int minimumWidth() const { return minimumSize().width(); } |
182 | 0 | inline int minimumHeight() const { return minimumSize().height(); } |
183 | 0 | inline int maximumWidth() const { return maximumSize().width(); } |
184 | 0 | inline int maximumHeight() const { return maximumSize().height(); } |
185 | | |
186 | | QSize minimumSize() const; |
187 | | QSize maximumSize() const; |
188 | | QSize baseSize() const; |
189 | | QSize sizeIncrement() const; |
190 | | |
191 | | void setMinimumSize(const QSize &size); |
192 | | void setMaximumSize(const QSize &size); |
193 | | void setBaseSize(const QSize &size); |
194 | | void setSizeIncrement(const QSize &size); |
195 | | |
196 | | QRect geometry() const; |
197 | | |
198 | | QMargins frameMargins() const; |
199 | | QRect frameGeometry() const; |
200 | | |
201 | | QPoint framePosition() const; |
202 | | void setFramePosition(const QPoint &point); |
203 | | |
204 | | QMargins safeAreaMargins() const; |
205 | | |
206 | 0 | inline int width() const { return geometry().width(); } |
207 | 0 | inline int height() const { return geometry().height(); } |
208 | 0 | inline int x() const { return geometry().x(); } |
209 | 0 | inline int y() const { return geometry().y(); } |
210 | | |
211 | 0 | QSize size() const override { return geometry().size(); } |
212 | 0 | inline QPoint position() const { return geometry().topLeft(); } |
213 | | |
214 | | void setPosition(const QPoint &pt); |
215 | | void setPosition(int posx, int posy); |
216 | | |
217 | | void resize(const QSize &newSize); |
218 | | void resize(int w, int h); |
219 | | |
220 | | void setFilePath(const QString &filePath); |
221 | | QString filePath() const; |
222 | | |
223 | | void setIcon(const QIcon &icon); |
224 | | QIcon icon() const; |
225 | | |
226 | | void destroy(); |
227 | | |
228 | | QPlatformWindow *handle() const; |
229 | | |
230 | | bool setKeyboardGrabEnabled(bool grab); |
231 | | bool setMouseGrabEnabled(bool grab); |
232 | | |
233 | | QScreen *screen() const; |
234 | | void setScreen(QScreen *screen); |
235 | | |
236 | | virtual QAccessibleInterface *accessibleRoot() const; |
237 | | virtual QObject *focusObject() const; |
238 | | |
239 | | QPointF mapToGlobal(const QPointF &pos) const; |
240 | | QPointF mapFromGlobal(const QPointF &pos) const; |
241 | | QPoint mapToGlobal(const QPoint &pos) const; |
242 | | QPoint mapFromGlobal(const QPoint &pos) const; |
243 | | |
244 | | #ifndef QT_NO_CURSOR |
245 | | QCursor cursor() const; |
246 | | void setCursor(const QCursor &); |
247 | | void unsetCursor(); |
248 | | #endif |
249 | | |
250 | | static QWindow *fromWinId(WId id); |
251 | | |
252 | | #if QT_CONFIG(vulkan) || defined(Q_QDOC) |
253 | | void setVulkanInstance(QVulkanInstance *instance); |
254 | | QVulkanInstance *vulkanInstance() const; |
255 | | #endif |
256 | | |
257 | | QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(QWindow) |
258 | | |
259 | | public Q_SLOTS: |
260 | | Q_REVISION(2, 1) void requestActivate(); |
261 | | |
262 | | void setVisible(bool visible); |
263 | | |
264 | | void show(); |
265 | | void hide(); |
266 | | |
267 | | void showMinimized(); |
268 | | void showMaximized(); |
269 | | void showFullScreen(); |
270 | | void showNormal(); |
271 | | |
272 | | bool close(); |
273 | | void raise(); |
274 | | void lower(); |
275 | | bool startSystemResize(Qt::Edges edges); |
276 | | bool startSystemMove(); |
277 | | |
278 | | void setTitle(const QString &); |
279 | | |
280 | | void setX(int arg); |
281 | | void setY(int arg); |
282 | | void setWidth(int arg); |
283 | | void setHeight(int arg); |
284 | | void setGeometry(int posx, int posy, int w, int h); |
285 | | void setGeometry(const QRect &rect); |
286 | | |
287 | | void setMinimumWidth(int w); |
288 | | void setMinimumHeight(int h); |
289 | | void setMaximumWidth(int w); |
290 | | void setMaximumHeight(int h); |
291 | | |
292 | | Q_REVISION(2, 1) void alert(int msec); |
293 | | |
294 | | Q_REVISION(2, 3) void requestUpdate(); |
295 | | |
296 | | Q_SIGNALS: |
297 | | void screenChanged(QScreen *screen); |
298 | | void modalityChanged(Qt::WindowModality modality); |
299 | | Q_REVISION(6, 10) void flagsChanged(Qt::WindowFlags flags); |
300 | | void windowStateChanged(Qt::WindowState windowState); |
301 | | Q_REVISION(2, 2) void windowTitleChanged(const QString &title); |
302 | | |
303 | | void xChanged(int arg); |
304 | | void yChanged(int arg); |
305 | | |
306 | | void widthChanged(int arg); |
307 | | void heightChanged(int arg); |
308 | | |
309 | | void minimumWidthChanged(int arg); |
310 | | void minimumHeightChanged(int arg); |
311 | | void maximumWidthChanged(int arg); |
312 | | void maximumHeightChanged(int arg); |
313 | | |
314 | | Q_REVISION(6, 9) void safeAreaMarginsChanged(QMargins arg); |
315 | | |
316 | | void visibleChanged(bool arg); |
317 | | Q_REVISION(2, 1) void visibilityChanged(QWindow::Visibility visibility); |
318 | | Q_REVISION(2, 1) void activeChanged(); |
319 | | void contentOrientationChanged(Qt::ScreenOrientation orientation); |
320 | | |
321 | | void focusObjectChanged(QObject *object); |
322 | | |
323 | | Q_REVISION(2, 1) void opacityChanged(qreal opacity); |
324 | | |
325 | | Q_REVISION(2, 13) void transientParentChanged(QWindow *transientParent); |
326 | | |
327 | | protected: |
328 | | virtual void exposeEvent(QExposeEvent *); |
329 | | virtual void resizeEvent(QResizeEvent *); |
330 | | virtual void paintEvent(QPaintEvent *); |
331 | | virtual void moveEvent(QMoveEvent *); |
332 | | virtual void focusInEvent(QFocusEvent *); |
333 | | virtual void focusOutEvent(QFocusEvent *); |
334 | | |
335 | | virtual void showEvent(QShowEvent *); |
336 | | virtual void hideEvent(QHideEvent *); |
337 | | virtual void closeEvent(QCloseEvent *); |
338 | | |
339 | | virtual bool event(QEvent *) override; |
340 | | virtual void keyPressEvent(QKeyEvent *); |
341 | | virtual void keyReleaseEvent(QKeyEvent *); |
342 | | virtual void mousePressEvent(QMouseEvent *); |
343 | | virtual void mouseReleaseEvent(QMouseEvent *); |
344 | | virtual void mouseDoubleClickEvent(QMouseEvent *); |
345 | | virtual void mouseMoveEvent(QMouseEvent *); |
346 | | #if QT_CONFIG(wheelevent) |
347 | | virtual void wheelEvent(QWheelEvent *); |
348 | | #endif |
349 | | virtual void touchEvent(QTouchEvent *); |
350 | | #if QT_CONFIG(tabletevent) |
351 | | virtual void tabletEvent(QTabletEvent *); |
352 | | #endif |
353 | | virtual bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result); |
354 | | |
355 | | QWindow(QWindowPrivate &dd, QWindow *parent); |
356 | | |
357 | | private: |
358 | | Q_PRIVATE_SLOT(d_func(), void _q_clearAlert()) |
359 | | QPlatformSurface *surfaceHandle() const override; |
360 | | |
361 | | Q_DISABLE_COPY(QWindow) |
362 | | |
363 | | friend class QGuiApplication; |
364 | | friend class QGuiApplicationPrivate; |
365 | | friend class QWindowContainer; |
366 | | friend Q_GUI_EXPORT QWindowPrivate *qt_window_private(QWindow *window); |
367 | | }; |
368 | | |
369 | | #ifndef Q_QDOC |
370 | | // should these be seen by clang-qdoc? |
371 | | template <> inline QWindow *qobject_cast<QWindow*>(QObject *o) |
372 | 0 | { |
373 | 0 | if (!o || !o->isWindowType()) return nullptr; |
374 | 0 | return static_cast<QWindow*>(o); |
375 | 0 | } |
376 | | template <> inline const QWindow *qobject_cast<const QWindow*>(const QObject *o) |
377 | 0 | { |
378 | 0 | if (!o || !o->isWindowType()) return nullptr; |
379 | 0 | return static_cast<const QWindow*>(o); |
380 | 0 | } |
381 | | #endif // !Q_QDOC |
382 | | |
383 | | #ifndef QT_NO_DEBUG_STREAM |
384 | | Q_GUI_EXPORT QDebug operator<<(QDebug, const QWindow *); |
385 | | #endif |
386 | | |
387 | | QT_END_NAMESPACE |
388 | | |
389 | | #endif // QWINDOW_H |