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 // Temporary backwards-compatible accessors for the benefit of Declarative
242 // to be removed ASAP
243 inline void setPos(const QPoint &pt) { setPosition(pt); }
244 inline void setPos(int posx, int posy) { setPosition(posx, posy); }
245 // end of temporary accessors
247 void resize(const QSize &newSize);
248 inline void resize(int w, int h) { resize(QSize(w, h)); }
250 void setFilePath(const QString &filePath);
251 QString filePath() const;
253 void setIcon(const QIcon &icon);
258 QPlatformWindow *handle() const;
260 bool setKeyboardGrabEnabled(bool grab);
261 bool setMouseGrabEnabled(bool grab);
263 QScreen *screen() const;
264 void setScreen(QScreen *screen);
266 virtual QAccessibleInterface *accessibleRoot() const;
267 virtual QObject *focusObject() const;
269 QPoint mapToGlobal(const QPoint &pos) const;
270 QPoint mapFromGlobal(const QPoint &pos) const;
273 QCursor cursor() const;
274 void setCursor(const QCursor &);
279 void setVisible(bool visible);
284 void showMinimized();
285 void showMaximized();
286 void showFullScreen();
293 void setTitle(const QString &);
298 setGeometry(QRect(arg, y(), width(), height()));
304 setGeometry(QRect(x(), arg, width(), height()));
307 void setWidth(int arg)
310 setGeometry(QRect(x(), y(), arg, height()));
313 void setHeight(int arg)
316 setGeometry(QRect(x(), y(), width(), arg));
319 void setMinimumWidth(int w);
320 void setMinimumHeight(int h);
321 void setMaximumWidth(int w);
322 void setMaximumHeight(int h);
325 void screenChanged(QScreen *screen);
326 void modalityChanged(Qt::WindowModality modality);
327 void windowStateChanged(Qt::WindowState windowState);
329 void xChanged(int arg);
330 void yChanged(int arg);
332 void widthChanged(int arg);
333 void heightChanged(int arg);
335 void minimumWidthChanged(int arg);
336 void minimumHeightChanged(int arg);
337 void maximumWidthChanged(int arg);
338 void maximumHeightChanged(int arg);
340 void visibleChanged(bool arg);
341 void contentOrientationChanged(Qt::ScreenOrientation orientation);
343 void focusObjectChanged(QObject *object);
346 void screenDestroyed(QObject *screen);
349 virtual void exposeEvent(QExposeEvent *);
350 virtual void resizeEvent(QResizeEvent *);
351 virtual void moveEvent(QMoveEvent *);
352 virtual void focusInEvent(QFocusEvent *);
353 virtual void focusOutEvent(QFocusEvent *);
355 virtual void showEvent(QShowEvent *);
356 virtual void hideEvent(QHideEvent *);
358 virtual bool event(QEvent *);
359 virtual void keyPressEvent(QKeyEvent *);
360 virtual void keyReleaseEvent(QKeyEvent *);
361 virtual void mousePressEvent(QMouseEvent *);
362 virtual void mouseReleaseEvent(QMouseEvent *);
363 virtual void mouseDoubleClickEvent(QMouseEvent *);
364 virtual void mouseMoveEvent(QMouseEvent *);
365 #ifndef QT_NO_WHEELEVENT
366 virtual void wheelEvent(QWheelEvent *);
368 virtual void touchEvent(QTouchEvent *);
369 #ifndef QT_NO_TABLETEVENT
370 virtual void tabletEvent(QTabletEvent *);
372 virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result);
374 QWindow(QWindowPrivate &dd, QWindow *parent);
377 QPlatformSurface *surfaceHandle() const;
379 Q_DISABLE_COPY(QWindow)
381 friend class QGuiApplication;
382 friend class QGuiApplicationPrivate;
383 friend Q_GUI_EXPORT QWindowPrivate *qt_window_private(QWindow *window);