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

source code of qtbase/src/gui/kernel/qwindow.h