1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtGui module of the Qt Toolkit.
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
45 #include <QtCore/QObject>
46 #include <QtCore/QEvent>
47 #include <QtCore/QMargins>
48 #include <QtCore/QRect>
50 #include <QtCore/qnamespace.h>
52 #include <QtGui/qsurface.h>
53 #include <QtGui/qsurfaceformat.h>
54 #include <QtGui/qwindowdefs.h>
56 #include <QtGui/qicon.h>
59 #include <QtGui/qcursor.h>
77 #ifndef QT_NO_WHEELEVENT
81 #ifndef QT_NO_TABLETEVENT
85 class QPlatformSurface;
86 class QPlatformWindow;
89 class QAccessibleInterface;
91 class Q_GUI_EXPORT QWindow : public QObject, public QSurface
94 Q_DECLARE_PRIVATE(QWindow)
96 // All properties which are declared here are inherited by QQuickWindow and therefore available in QML.
97 // So please think carefully about what it does to the QML namespace if you add any new ones,
98 // particularly the possible meanings these names might have in any specializations of Window.
99 // For example "state" (meaning windowState) is not a good property to declare, because it has
100 // a different meaning in QQuickItem, and users will tend to assume it is the same for Window.
102 Q_PROPERTY(QString title READ title WRITE setTitle)
103 Q_PROPERTY(Qt::WindowModality modality READ modality WRITE setModality NOTIFY modalityChanged)
104 Q_PROPERTY(Qt::WindowFlags flags READ flags WRITE setFlags)
105 Q_PROPERTY(int x READ x WRITE setX NOTIFY xChanged)
106 Q_PROPERTY(int y READ y WRITE setY NOTIFY yChanged)
107 Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged)
108 Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged)
109 Q_PROPERTY(int minimumWidth READ minimumWidth WRITE setMinimumWidth NOTIFY minimumWidthChanged)
110 Q_PROPERTY(int minimumHeight READ minimumHeight WRITE setMinimumHeight NOTIFY minimumHeightChanged)
111 Q_PROPERTY(int maximumWidth READ maximumWidth WRITE setMaximumWidth NOTIFY maximumWidthChanged)
112 Q_PROPERTY(int maximumHeight READ maximumHeight WRITE setMaximumHeight NOTIFY maximumHeightChanged)
113 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
114 Q_PROPERTY(Qt::ScreenOrientation contentOrientation READ contentOrientation WRITE reportContentOrientationChange NOTIFY contentOrientationChanged)
118 explicit QWindow(QScreen *screen = 0);
119 explicit QWindow(QWindow *parent);
122 void setSurfaceType(SurfaceType surfaceType);
123 SurfaceType surfaceType() const;
125 bool isVisible() const;
131 QWindow *parent() const;
132 void setParent(QWindow *parent);
134 bool isTopLevel() const;
136 bool isModal() const;
137 Qt::WindowModality modality() const;
138 void setModality(Qt::WindowModality modality);
140 void setFormat(const QSurfaceFormat &format);
141 QSurfaceFormat format() const;
142 QSurfaceFormat requestedFormat() const;
144 void setFlags(Qt::WindowFlags flags);
145 Qt::WindowFlags flags() const;
146 Qt::WindowType type() const;
148 QString title() const;
150 void setOpacity(qreal level);
151 void requestActivate();
153 bool isActive() const;
155 void reportContentOrientationChange(Qt::ScreenOrientation orientation);
156 Qt::ScreenOrientation contentOrientation() const;
158 qreal devicePixelRatio() const;
160 Qt::WindowState windowState() const;
161 void setWindowState(Qt::WindowState state);
163 void setTransientParent(QWindow *parent);
164 QWindow *transientParent() const;
171 bool isAncestorOf(const QWindow *child, AncestorMode mode = IncludeTransients) const;
173 bool isExposed() const;
175 inline int minimumWidth() const { return minimumSize().width(); }
176 inline int minimumHeight() const { return minimumSize().height(); }
177 inline int maximumWidth() const { return maximumSize().width(); }
178 inline int maximumHeight() const { return maximumSize().height(); }
180 QSize minimumSize() const;
181 QSize maximumSize() const;
182 QSize baseSize() const;
183 QSize sizeIncrement() const;
185 void setMinimumSize(const QSize &size);
186 void setMaximumSize(const QSize &size);
187 void setBaseSize(const QSize &size);
188 void setSizeIncrement(const QSize &size);
190 void setGeometry(int posx, int posy, int w, int h);
191 void setGeometry(const QRect &rect);
192 QRect geometry() const;
194 QMargins frameMargins() const;
195 QRect frameGeometry() const;
197 QPoint framePosition() const;
198 void setFramePosition(const QPoint &point);
200 inline int width() const { return geometry().width(); }
201 inline int height() const { return geometry().height(); }
202 inline int x() const { return geometry().x(); }
203 inline int y() const { return geometry().y(); }
205 inline QSize size() const { return geometry().size(); }
206 inline QPoint position() const { return geometry().topLeft(); }
208 void setPosition(const QPoint &pt);
209 void setPosition(int posx, int posy);
211 void resize(const QSize &newSize);
212 void resize(int w, int h);
214 void setFilePath(const QString &filePath);
215 QString filePath() const;
217 void setIcon(const QIcon &icon);
222 QPlatformWindow *handle() const;
224 bool setKeyboardGrabEnabled(bool grab);
225 bool setMouseGrabEnabled(bool grab);
227 QScreen *screen() const;
228 void setScreen(QScreen *screen);
230 virtual QAccessibleInterface *accessibleRoot() const;
231 virtual QObject *focusObject() const;
233 QPoint mapToGlobal(const QPoint &pos) const;
234 QPoint mapFromGlobal(const QPoint &pos) const;
237 QCursor cursor() const;
238 void setCursor(const QCursor &);
243 void setVisible(bool visible);
248 void showMinimized();
249 void showMaximized();
250 void showFullScreen();
257 void setTitle(const QString &);
261 void setWidth(int arg);
262 void setHeight(int arg);
264 void setMinimumWidth(int w);
265 void setMinimumHeight(int h);
266 void setMaximumWidth(int w);
267 void setMaximumHeight(int h);
270 void screenChanged(QScreen *screen);
271 void modalityChanged(Qt::WindowModality modality);
272 void windowStateChanged(Qt::WindowState windowState);
274 void xChanged(int arg);
275 void yChanged(int arg);
277 void widthChanged(int arg);
278 void heightChanged(int arg);
280 void minimumWidthChanged(int arg);
281 void minimumHeightChanged(int arg);
282 void maximumWidthChanged(int arg);
283 void maximumHeightChanged(int arg);
285 void visibleChanged(bool arg);
286 void contentOrientationChanged(Qt::ScreenOrientation orientation);
288 void focusObjectChanged(QObject *object);
291 void screenDestroyed(QObject *screen);
294 virtual void exposeEvent(QExposeEvent *);
295 virtual void resizeEvent(QResizeEvent *);
296 virtual void moveEvent(QMoveEvent *);
297 virtual void focusInEvent(QFocusEvent *);
298 virtual void focusOutEvent(QFocusEvent *);
300 virtual void showEvent(QShowEvent *);
301 virtual void hideEvent(QHideEvent *);
303 virtual bool event(QEvent *);
304 virtual void keyPressEvent(QKeyEvent *);
305 virtual void keyReleaseEvent(QKeyEvent *);
306 virtual void mousePressEvent(QMouseEvent *);
307 virtual void mouseReleaseEvent(QMouseEvent *);
308 virtual void mouseDoubleClickEvent(QMouseEvent *);
309 virtual void mouseMoveEvent(QMouseEvent *);
310 #ifndef QT_NO_WHEELEVENT
311 virtual void wheelEvent(QWheelEvent *);
313 virtual void touchEvent(QTouchEvent *);
314 #ifndef QT_NO_TABLETEVENT
315 virtual void tabletEvent(QTabletEvent *);
317 virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result);
319 QWindow(QWindowPrivate &dd, QWindow *parent);
322 QPlatformSurface *surfaceHandle() const;
324 Q_DISABLE_COPY(QWindow)
326 friend class QGuiApplication;
327 friend class QGuiApplicationPrivate;
328 friend Q_GUI_EXPORT QWindowPrivate *qt_window_private(QWindow *window);