qwindow.h 12 KB

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