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