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