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)
116 // ------------------------------------------------------------------------
117 // Temporary backwards-compatibility properties to be removed ASAP
118 Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle)
119 Q_PROPERTY(QString windowFilePath READ windowFilePath WRITE setWindowFilePath)
120 Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon)
121 Q_PROPERTY(Qt::WindowModality windowModality READ windowModality WRITE setWindowModality NOTIFY windowModalityChanged)
125 Qt::WindowModality windowModality() const { return modality(); }
126 void setWindowModality(Qt::WindowModality wm) { setModality(wm); }
127 void setWindowFlags(Qt::WindowFlags f) { setFlags(f); }
128 Qt::WindowFlags windowFlags() const { return flags(); }
129 Qt::WindowType windowType() const { return type(); }
130 QString windowTitle() const { return title(); }
131 void requestActivateWindow() { requestActivate(); }
132 bool requestWindowOrientation(Qt::ScreenOrientation o) { return requestOrientation(o); }
133 Qt::ScreenOrientation windowOrientation() const { return orientation(); }
134 void setWindowFilePath(const QString &fp) { setFilePath(fp); }
135 QString windowFilePath() const { return filePath(); }
136 void setWindowIcon(const QIcon &i) { setIcon(i); }
137 QIcon windowIcon() const { return icon(); }
138 void setWindowTitle(const QString &t) { setTitle(t); }
141 void windowModalityChanged(Qt::WindowModality windowModality);
142 // End of temporary backwards-compatibility properties
143 // ------------------------------------------------------------------------
147 explicit QWindow(QScreen *screen = 0);
148 explicit QWindow(QWindow *parent);
151 void setSurfaceType(SurfaceType surfaceType);
152 SurfaceType surfaceType() const;
154 bool isVisible() const;
160 QWindow *parent() const;
161 void setParent(QWindow *parent);
163 bool isTopLevel() const;
165 bool isModal() const;
166 Qt::WindowModality modality() const;
167 void setModality(Qt::WindowModality modality);
169 void setFormat(const QSurfaceFormat &format);
170 QSurfaceFormat format() const;
171 QSurfaceFormat requestedFormat() const;
173 void setFlags(Qt::WindowFlags flags);
174 Qt::WindowFlags flags() const;
175 Qt::WindowType type() const;
177 QString title() const;
179 void setOpacity(qreal level);
180 void requestActivate();
182 bool isActive() const;
184 void reportContentOrientationChange(Qt::ScreenOrientation orientation);
185 Qt::ScreenOrientation contentOrientation() const;
187 bool requestOrientation(Qt::ScreenOrientation orientation);
188 Qt::ScreenOrientation orientation() const;
190 Qt::WindowState windowState() const;
191 void setWindowState(Qt::WindowState state);
193 void setTransientParent(QWindow *parent);
194 QWindow *transientParent() const;
201 bool isAncestorOf(const QWindow *child, AncestorMode mode = IncludeTransients) const;
203 bool isExposed() const;
205 int minimumWidth() const { return minimumSize().width(); }
206 int minimumHeight() const { return minimumSize().height(); }
207 int maximumWidth() const { return maximumSize().width(); }
208 int maximumHeight() const { return maximumSize().height(); }
210 QSize minimumSize() const;
211 QSize maximumSize() const;
212 QSize baseSize() const;
213 QSize sizeIncrement() const;
215 void setMinimumSize(const QSize &size);
216 void setMaximumSize(const QSize &size);
217 void setBaseSize(const QSize &size);
218 void setSizeIncrement(const QSize &size);
220 void setGeometry(int posx, int posy, int w, int h) { setGeometry(QRect(posx, posy, w, h)); }
221 void setGeometry(const QRect &rect);
222 QRect geometry() const;
224 QMargins frameMargins() const;
225 QRect frameGeometry() const;
227 QPoint framePos() const;
228 void setFramePos(const QPoint &point);
230 inline int width() const { return geometry().width(); }
231 inline int height() const { return geometry().height(); }
232 inline int x() const { return geometry().x(); }
233 inline int y() const { return geometry().y(); }
235 inline QSize size() const { return geometry().size(); }
236 inline QPoint position() const { return geometry().topLeft(); }
238 inline void setPosition(const QPoint &pt) { setGeometry(QRect(pt, size())); }
239 inline void setPosition(int posx, int posy) { setPosition(QPoint(posx, posy)); }
241 void resize(const QSize &newSize);
242 inline void resize(int w, int h) { resize(QSize(w, h)); }
244 void setFilePath(const QString &filePath);
245 QString filePath() const;
247 void setIcon(const QIcon &icon);
252 QPlatformWindow *handle() const;
254 bool setKeyboardGrabEnabled(bool grab);
255 bool setMouseGrabEnabled(bool grab);
257 QScreen *screen() const;
258 void setScreen(QScreen *screen);
260 virtual QAccessibleInterface *accessibleRoot() const;
261 virtual QObject *focusObject() const;
263 QPoint mapToGlobal(const QPoint &pos) const;
264 QPoint mapFromGlobal(const QPoint &pos) const;
267 QCursor cursor() const;
268 void setCursor(const QCursor &);
273 void setVisible(bool visible);
278 void showMinimized();
279 void showMaximized();
280 void showFullScreen();
287 void setTitle(const QString &);
292 setGeometry(QRect(arg, y(), width(), height()));
298 setGeometry(QRect(x(), arg, width(), height()));
301 void setWidth(int arg)
304 setGeometry(QRect(x(), y(), arg, height()));
307 void setHeight(int arg)
310 setGeometry(QRect(x(), y(), width(), arg));
313 void setMinimumWidth(int w);
314 void setMinimumHeight(int h);
315 void setMaximumWidth(int w);
316 void setMaximumHeight(int h);
319 void screenChanged(QScreen *screen);
320 void modalityChanged(Qt::WindowModality modality);
321 void windowStateChanged(Qt::WindowState windowState);
323 void xChanged(int arg);
324 void yChanged(int arg);
326 void widthChanged(int arg);
327 void heightChanged(int arg);
329 void minimumWidthChanged(int arg);
330 void minimumHeightChanged(int arg);
331 void maximumWidthChanged(int arg);
332 void maximumHeightChanged(int arg);
334 void visibleChanged(bool arg);
335 void contentOrientationChanged(Qt::ScreenOrientation orientation);
337 void focusObjectChanged(QObject *object);
340 void screenDestroyed(QObject *screen);
343 virtual void exposeEvent(QExposeEvent *);
344 virtual void resizeEvent(QResizeEvent *);
345 virtual void moveEvent(QMoveEvent *);
346 virtual void focusInEvent(QFocusEvent *);
347 virtual void focusOutEvent(QFocusEvent *);
349 virtual void showEvent(QShowEvent *);
350 virtual void hideEvent(QHideEvent *);
352 virtual bool event(QEvent *);
353 virtual void keyPressEvent(QKeyEvent *);
354 virtual void keyReleaseEvent(QKeyEvent *);
355 virtual void mousePressEvent(QMouseEvent *);
356 virtual void mouseReleaseEvent(QMouseEvent *);
357 virtual void mouseDoubleClickEvent(QMouseEvent *);
358 virtual void mouseMoveEvent(QMouseEvent *);
359 #ifndef QT_NO_WHEELEVENT
360 virtual void wheelEvent(QWheelEvent *);
362 virtual void touchEvent(QTouchEvent *);
363 #ifndef QT_NO_TABLETEVENT
364 virtual void tabletEvent(QTabletEvent *);
366 virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result);
368 QWindow(QWindowPrivate &dd, QWindow *parent);
371 QPlatformSurface *surfaceHandle() const;
373 Q_DISABLE_COPY(QWindow)
375 friend class QGuiApplication;
376 friend class QGuiApplicationPrivate;
377 friend Q_GUI_EXPORT QWindowPrivate *qt_window_private(QWindow *window);