QtBase  v6.3.1
qwindow.h
Go to the documentation of this file.
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 #include <QtCore/qnativeinterface.h>
51 
52 #include <QtGui/qsurface.h>
53 #include <QtGui/qsurfaceformat.h>
54 #include <QtGui/qwindowdefs.h>
55 
56 #include <QtGui/qicon.h>
57 
58 #ifndef QT_NO_CURSOR
59 #include <QtGui/qcursor.h>
60 #endif
61 
63 
64 
65 class QWindowPrivate;
66 
67 class QExposeEvent;
68 class QPaintEvent;
69 class QFocusEvent;
70 class QMoveEvent;
71 class QResizeEvent;
72 class QShowEvent;
73 class QHideEvent;
74 class QCloseEvent;
75 class QKeyEvent;
76 class QMouseEvent;
77 #if QT_CONFIG(wheelevent)
78 class QWheelEvent;
79 #endif
80 class QTouchEvent;
81 #if QT_CONFIG(tabletevent)
82 class QTabletEvent;
83 #endif
84 
85 class QPlatformSurface;
86 class QPlatformWindow;
87 class QBackingStore;
88 class QScreen;
90 class QWindowContainer;
91 #ifndef QT_NO_DEBUG_STREAM
92 class QDebug;
93 #endif
94 #if QT_CONFIG(vulkan) || defined(Q_CLANG_QDOC)
95 class QVulkanInstance;
96 #endif
97 
98 class Q_GUI_EXPORT QWindow : public QObject, public QSurface
99 {
100  Q_OBJECT
101  Q_DECLARE_PRIVATE(QWindow)
102 
103  // All properties which are declared here are inherited by QQuickWindow and therefore available in QML.
104  // So please think carefully about what it does to the QML namespace if you add any new ones,
105  // particularly the possible meanings these names might have in any specializations of Window.
106  // For example "state" (meaning windowState) is not a good property to declare, because it has
107  // a different meaning in QQuickItem, and users will tend to assume it is the same for Window.
108 
109  // Any new properties which you add here MUST be versioned and MUST be documented both as
110  // C++ properties in qwindow.cpp AND as QML properties in qquickwindow.cpp.
111  // https://doc.qt.io/qt/qtqml-cppintegration-definetypes.html#type-revisions-and-versions
112 
113  Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY windowTitleChanged)
114  Q_PROPERTY(Qt::WindowModality modality READ modality WRITE setModality NOTIFY modalityChanged)
115  Q_PROPERTY(Qt::WindowFlags flags READ flags WRITE setFlags)
116  Q_PROPERTY(int x READ x WRITE setX NOTIFY xChanged)
117  Q_PROPERTY(int y READ y WRITE setY NOTIFY yChanged)
118  Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged)
119  Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged)
120  Q_PROPERTY(int minimumWidth READ minimumWidth WRITE setMinimumWidth NOTIFY minimumWidthChanged)
121  Q_PROPERTY(int minimumHeight READ minimumHeight WRITE setMinimumHeight
122  NOTIFY minimumHeightChanged)
123  Q_PROPERTY(int maximumWidth READ maximumWidth WRITE setMaximumWidth NOTIFY maximumWidthChanged)
124  Q_PROPERTY(int maximumHeight READ maximumHeight WRITE setMaximumHeight
125  NOTIFY maximumHeightChanged)
126  Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
127  Q_PROPERTY(bool active READ isActive NOTIFY activeChanged REVISION(2, 1))
128  Q_PROPERTY(Visibility visibility READ visibility WRITE setVisibility NOTIFY visibilityChanged
129  REVISION(2, 1))
130  Q_PROPERTY(Qt::ScreenOrientation contentOrientation READ contentOrientation
131  WRITE reportContentOrientationChange NOTIFY contentOrientationChanged)
132  Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged REVISION(2, 1))
133 #ifdef Q_QDOC
134  Q_PROPERTY(QWindow* transientParent READ transientParent WRITE setTransientParent NOTIFY transientParentChanged)
135 #else
136  Q_PRIVATE_PROPERTY(QWindow::d_func(), QWindow* transientParent MEMBER transientParent
137  WRITE setTransientParent NOTIFY transientParentChanged REVISION(2, 13))
138 #endif
139 
140 public:
141  enum Visibility {
142  Hidden = 0,
143  AutomaticVisibility,
144  Windowed,
145  Minimized,
146  Maximized,
147  FullScreen
148  };
149  Q_ENUM(Visibility)
150 
151  enum AncestorMode {
152  ExcludeTransients,
153  IncludeTransients
154  };
155  Q_ENUM(AncestorMode)
156 
157  explicit QWindow(QScreen *screen = nullptr);
158  explicit QWindow(QWindow *parent);
159  ~QWindow();
160 
161  void setSurfaceType(SurfaceType surfaceType);
162  SurfaceType surfaceType() const override;
163 
164  bool isVisible() const;
165 
166  Visibility visibility() const;
167  void setVisibility(Visibility v);
168 
169  void create();
170 
171  WId winId() const;
172 
173  QWindow *parent(AncestorMode mode = ExcludeTransients) const;
174  void setParent(QWindow *parent);
175 
176  bool isTopLevel() const;
177 
178  bool isModal() const;
179  Qt::WindowModality modality() const;
180  void setModality(Qt::WindowModality modality);
181 
182  void setFormat(const QSurfaceFormat &format);
183  QSurfaceFormat format() const override;
184  QSurfaceFormat requestedFormat() const;
185 
186  void setFlags(Qt::WindowFlags flags);
187  Qt::WindowFlags flags() const;
188  void setFlag(Qt::WindowType, bool on = true);
189  Qt::WindowType type() const;
190 
191  QString title() const;
192 
193  void setOpacity(qreal level);
194  qreal opacity() const;
195 
196  void setMask(const QRegion &region);
197  QRegion mask() const;
198 
199  bool isActive() const;
200 
201  void reportContentOrientationChange(Qt::ScreenOrientation orientation);
202  Qt::ScreenOrientation contentOrientation() const;
203 
204  qreal devicePixelRatio() const;
205 
206  Qt::WindowState windowState() const;
207  Qt::WindowStates windowStates() const;
209  void setWindowStates(Qt::WindowStates states);
210 
211  void setTransientParent(QWindow *parent);
212  QWindow *transientParent() const;
213 
214  bool isAncestorOf(const QWindow *child, AncestorMode mode = IncludeTransients) const;
215 
216  bool isExposed() const;
217 
218  inline int minimumWidth() const { return minimumSize().width(); }
219  inline int minimumHeight() const { return minimumSize().height(); }
220  inline int maximumWidth() const { return maximumSize().width(); }
221  inline int maximumHeight() const { return maximumSize().height(); }
222 
223  QSize minimumSize() const;
224  QSize maximumSize() const;
225  QSize baseSize() const;
226  QSize sizeIncrement() const;
227 
228  void setMinimumSize(const QSize &size);
229  void setMaximumSize(const QSize &size);
230  void setBaseSize(const QSize &size);
231  void setSizeIncrement(const QSize &size);
232 
233  QRect geometry() const;
234 
235  QMargins frameMargins() const;
236  QRect frameGeometry() const;
237 
238  QPoint framePosition() const;
239  void setFramePosition(const QPoint &point);
240 
241  inline int width() const { return geometry().width(); }
242  inline int height() const { return geometry().height(); }
243  inline int x() const { return geometry().x(); }
244  inline int y() const { return geometry().y(); }
245 
246  QSize size() const override { return geometry().size(); }
247  inline QPoint position() const { return geometry().topLeft(); }
248 
249  void setPosition(const QPoint &pt);
250  void setPosition(int posx, int posy);
251 
252  void resize(const QSize &newSize);
253  void resize(int w, int h);
254 
255  void setFilePath(const QString &filePath);
256  QString filePath() const;
257 
258  void setIcon(const QIcon &icon);
259  QIcon icon() const;
260 
261  void destroy();
262 
263  QPlatformWindow *handle() const;
264 
265  bool setKeyboardGrabEnabled(bool grab);
266  bool setMouseGrabEnabled(bool grab);
267 
268  QScreen *screen() const;
269  void setScreen(QScreen *screen);
270 
271  virtual QAccessibleInterface *accessibleRoot() const;
272  virtual QObject *focusObject() const;
273 
274  QPointF mapToGlobal(const QPointF &pos) const;
275  QPointF mapFromGlobal(const QPointF &pos) const;
276  QPoint mapToGlobal(const QPoint &pos) const;
277  QPoint mapFromGlobal(const QPoint &pos) const;
278 
279 #ifndef QT_NO_CURSOR
280  QCursor cursor() const;
281  void setCursor(const QCursor &);
282  void unsetCursor();
283 #endif
284 
285  static QWindow *fromWinId(WId id);
286 
287 #if QT_CONFIG(vulkan) || defined(Q_CLANG_QDOC)
288  void setVulkanInstance(QVulkanInstance *instance);
289  QVulkanInstance *vulkanInstance() const;
290 #endif
291 
293 
294 public Q_SLOTS:
295  Q_REVISION(2, 1) void requestActivate();
296 
297  void setVisible(bool visible);
298 
299  void show();
300  void hide();
301 
302  void showMinimized();
303  void showMaximized();
304  void showFullScreen();
305  void showNormal();
306 
307  bool close();
308  void raise();
309  void lower();
310  bool startSystemResize(Qt::Edges edges);
311  bool startSystemMove();
312 
313  void setTitle(const QString &);
314 
315  void setX(int arg);
316  void setY(int arg);
317  void setWidth(int arg);
318  void setHeight(int arg);
319  void setGeometry(int posx, int posy, int w, int h);
320  void setGeometry(const QRect &rect);
321 
322  void setMinimumWidth(int w);
323  void setMinimumHeight(int h);
324  void setMaximumWidth(int w);
325  void setMaximumHeight(int h);
326 
327  Q_REVISION(2, 1) void alert(int msec);
328 
329  Q_REVISION(2, 3) void requestUpdate();
330 
331 Q_SIGNALS:
332  void screenChanged(QScreen *screen);
333  void modalityChanged(Qt::WindowModality modality);
334  void windowStateChanged(Qt::WindowState windowState);
335  Q_REVISION(2, 2) void windowTitleChanged(const QString &title);
336 
337  void xChanged(int arg);
338  void yChanged(int arg);
339 
340  void widthChanged(int arg);
341  void heightChanged(int arg);
342 
343  void minimumWidthChanged(int arg);
344  void minimumHeightChanged(int arg);
345  void maximumWidthChanged(int arg);
346  void maximumHeightChanged(int arg);
347 
348  void visibleChanged(bool arg);
349  Q_REVISION(2, 1) void visibilityChanged(QWindow::Visibility visibility);
350  Q_REVISION(2, 1) void activeChanged();
351  void contentOrientationChanged(Qt::ScreenOrientation orientation);
352 
353  void focusObjectChanged(QObject *object);
354 
355  Q_REVISION(2, 1) void opacityChanged(qreal opacity);
356 
357  Q_REVISION(2, 13) void transientParentChanged(QWindow *transientParent);
358 
359 protected:
360  virtual void exposeEvent(QExposeEvent *);
361  virtual void resizeEvent(QResizeEvent *);
362  virtual void paintEvent(QPaintEvent *);
363  virtual void moveEvent(QMoveEvent *);
364  virtual void focusInEvent(QFocusEvent *);
365  virtual void focusOutEvent(QFocusEvent *);
366 
367  virtual void showEvent(QShowEvent *);
368  virtual void hideEvent(QHideEvent *);
369  virtual void closeEvent(QCloseEvent *);
370 
371  virtual bool event(QEvent *) override;
372  virtual void keyPressEvent(QKeyEvent *);
373  virtual void keyReleaseEvent(QKeyEvent *);
374  virtual void mousePressEvent(QMouseEvent *);
375  virtual void mouseReleaseEvent(QMouseEvent *);
376  virtual void mouseDoubleClickEvent(QMouseEvent *);
377  virtual void mouseMoveEvent(QMouseEvent *);
378 #if QT_CONFIG(wheelevent)
379  virtual void wheelEvent(QWheelEvent *);
380 #endif
381  virtual void touchEvent(QTouchEvent *);
382 #if QT_CONFIG(tabletevent)
383  virtual void tabletEvent(QTabletEvent *);
384 #endif
385  virtual bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result);
386 
388 
389 private:
390  Q_PRIVATE_SLOT(d_func(), void _q_clearAlert())
391  QPlatformSurface *surfaceHandle() const override;
392 
394 
395  friend class QGuiApplication;
397  friend class QWindowContainer;
398  friend Q_GUI_EXPORT QWindowPrivate *qt_window_private(QWindow *window);
399 };
400 
401 #ifndef Q_QDOC
402 // should these be seen by clang-qdoc?
404 {
405  if (!o || !o->isWindowType()) return nullptr;
406  return static_cast<QWindow*>(o);
407 }
408 template <> inline const QWindow *qobject_cast<const QWindow*>(const QObject *o)
409 {
410  if (!o || !o->isWindowType()) return nullptr;
411  return static_cast<const QWindow*>(o);
412 }
413 #endif // !Q_QDOC
414 
415 #ifndef QT_NO_DEBUG_STREAM
416 Q_GUI_EXPORT QDebug operator<<(QDebug, const QWindow *);
417 #endif
418 
420 
421 #endif // QWINDOW_H
The QAccessibleInterface class defines an interface that exposes information about accessible objects...
Definition: qaccessible.h:459
The QBackingStore class provides a drawing area for QWindow.
Definition: qbackingstore.h:60
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:85
The QCloseEvent class contains parameters that describe a close event.
Definition: qevent.h:629
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition: qcursor.h:81
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:65
The QEvent class is the base class of all event classes. Event objects contain event parameters.
Definition: qcoreevent.h:58
The QExposeEvent class contains event parameters for expose events. \inmodule QtGui.
Definition: qevent.h:574
The QFocusEvent class contains event parameters for widget focus events. \inmodule QtGui.
Definition: qevent.h:520
The QGuiApplication class manages the GUI application's control flow and main settings.
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition: qevent.h:656
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:56
The QKeyEvent class describes a key event.
Definition: qevent.h:471
The QMargins class defines the four margins of a rectangle.
Definition: qmargins.h:52
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:231
The QMoveEvent class contains event parameters for move events. \inmodule QtGui.
Definition: qevent.h:558
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
QObject * parent() const
Definition: qobject.h:409
void setParent(QObject *parent)
Definition: qobject.cpp:2108
The QPaintEvent class contains event parameters for paint events. \inmodule QtGui.
Definition: qevent.h:539
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:242
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:52
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:59
constexpr int height() const noexcept
Definition: qrect.h:266
constexpr QPoint topLeft() const noexcept
Definition: qrect.h:248
constexpr int x() const noexcept
Definition: qrect.h:212
constexpr QSize size() const noexcept
Definition: qrect.h:269
constexpr int width() const noexcept
Definition: qrect.h:263
constexpr int y() const noexcept
Definition: qrect.h:215
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:63
The QResizeEvent class contains event parameters for resize events. \inmodule QtGui.
Definition: qevent.h:612
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition: qscreen.h:68
The QShowEvent class provides an event that is sent when a widget is shown.
Definition: qevent.h:647
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:55
The QString class provides a Unicode character string.
Definition: qstring.h:388
The QSurfaceFormat class represents the format of a QSurface. \inmodule QtGui.
The QSurface class is an abstraction of renderable surfaces in Qt.
Definition: qsurface.h:57
virtual SurfaceType surfaceType() const =0
SurfaceType
Definition: qsurface.h:66
The QTouchEvent class contains parameters that describe a touch event.
Definition: qevent.h:1020
The QVulkanInstance class represents a native Vulkan instance, enabling Vulkan rendering onto a QSurf...
The QWindow class represents a window in the underlying windowing system.
Definition: qwindow.h:99
Q_REVISION(2, 1) void requestActivate()
widget setFormat(format)
a resize(100000)
QCursor cursor
rect
[4]
else opt state
[0]
auto it unsigned count const
Definition: hb-iter.hh:848
QHighDpiScaling::Point position(T, QHighDpiScaling::Point::Kind)
QTouchEventSequence touchEvent(QWindow *window, QPointingDevice *device, bool autoCommit=true)
Definition: qtesttouch.h:78
Definition: qnamespace.h:55
WindowState
Definition: qnamespace.h:276
WindowModality
Definition: qnamespace.h:1563
ScreenOrientation
Definition: qnamespace.h:296
WindowType
Definition: qnamespace.h:230
void
Definition: png.h:1080
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
#define Q_DISABLE_COPY(Class)
Definition: qglobal.h:515
ptrdiff_t qintptr
Definition: qglobal.h:309
#define QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(T)
GLenum type
Definition: qopengl.h:270
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: qopengl.h:270
GLsizei const GLfloat * v
[13]
GLuint64 GLenum void * handle
GLint GLint GLint GLint GLint x
[0]
GLenum mode
GLenum GLuint GLint level
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei width
GLbitfield flags
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLint GLsizei GLsizei GLenum format
GLint y
GLfloat GLfloat GLfloat GLfloat h
struct _cl_event * event
Definition: qopenglext.h:2998
GLuint64EXT * result
[6]
Definition: qopenglext.h:10932
GLuint * states
Definition: qopenglext.h:9584
SSL_CTX int(*) void arg)
#define Q_ENUM(x)
Definition: qtmetamacros.h:104
#define Q_PROPERTY(...)
Definition: qtmetamacros.h:92
#define Q_OBJECT
Definition: qtmetamacros.h:158
#define Q_REVISION(...)
Definition: qtmetamacros.h:95
#define Q_SLOTS
Definition: qtmetamacros.h:80
#define Q_PRIVATE_SLOT(d, signature)
Definition: qtmetamacros.h:82
#define Q_SIGNALS
Definition: qtmetamacros.h:81
#define Q_PRIVATE_PROPERTY(d, text)
Definition: qtmetamacros.h:93
Q_GUI_EXPORT QWindowPrivate * qt_window_private(QWindow *window)
Definition: qwindow.cpp:2855
const QWindow * qobject_cast< const QWindow * >(const QObject *o)
Definition: qwindow.h:408
QWindow * qobject_cast< QWindow * >(QObject *o)
Definition: qwindow.h:403
Q_GUI_EXPORT QDebug operator<<(QDebug, const QWindow *)
Definition: qwindow.cpp:3066
view show()
[18] //! [19]
HB_EXTERN hb_font_get_glyph_func_t void hb_destroy_func_t destroy
QScreen * screen
[1]
Definition: main.cpp:76
QIcon icon
[15]
QString title
[35]
p setX(p.x()+1)
item setCursor(Qt::IBeamCursor)
[1]
edit hide()
edit isVisible()
myAction setIcon(SomeIcon)
QLayoutItem * child
[0]
w setWindowState(w->windowState() ^ Qt::WindowFullScreen)
[0]
aWidget window() -> setWindowTitle("New Window Title")
[2]
g setTitle("&User information")
[0]
view create()
#define protected
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent