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 Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle)
97 Q_PROPERTY(QString windowFilePath READ windowFilePath WRITE setWindowFilePath)
98 Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon)
99 Q_PROPERTY(Qt::WindowModality windowModality READ windowModality WRITE setWindowModality NOTIFY windowModalityChanged)
100 Q_PROPERTY(int x READ x WRITE setX NOTIFY xChanged)
101 Q_PROPERTY(int y READ y WRITE setY NOTIFY yChanged)
102 Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged)
103 Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged)
104 Q_PROPERTY(QPoint pos READ pos WRITE setPos)
105 Q_PROPERTY(QSize size READ size WRITE resize)
106 Q_PROPERTY(QRect geometry READ geometry WRITE setGeometry)
107 Q_PROPERTY(int minimumWidth READ minimumWidth WRITE setMinimumWidth NOTIFY minimumWidthChanged)
108 Q_PROPERTY(int minimumHeight READ minimumHeight WRITE setMinimumHeight NOTIFY minimumHeightChanged)
109 Q_PROPERTY(int maximumWidth READ maximumWidth WRITE setMaximumWidth NOTIFY maximumWidthChanged)
110 Q_PROPERTY(int maximumHeight READ maximumHeight WRITE setMaximumHeight NOTIFY maximumHeightChanged)
111 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
112 Q_PROPERTY(Qt::ScreenOrientation contentOrientation READ contentOrientation WRITE reportContentOrientationChange NOTIFY contentOrientationChanged)
114 Q_PROPERTY(QCursor cursor READ cursor WRITE setCursor RESET unsetCursor)
119 explicit QWindow(QScreen *screen = 0);
120 explicit QWindow(QWindow *parent);
123 void setSurfaceType(SurfaceType surfaceType);
124 SurfaceType surfaceType() const;
126 bool isVisible() const;
132 QWindow *parent() const;
133 void setParent(QWindow *parent);
135 bool isTopLevel() const;
137 bool isModal() const;
138 Qt::WindowModality windowModality() const;
139 void setWindowModality(Qt::WindowModality windowModality);
141 void setFormat(const QSurfaceFormat &format);
142 QSurfaceFormat format() const;
143 QSurfaceFormat requestedFormat() const;
145 void setWindowFlags(Qt::WindowFlags flags);
146 Qt::WindowFlags windowFlags() const;
147 Qt::WindowType windowType() const;
149 QString windowTitle() const;
151 void setOpacity(qreal level);
152 void requestActivateWindow();
154 bool isActive() const;
156 void reportContentOrientationChange(Qt::ScreenOrientation orientation);
157 Qt::ScreenOrientation contentOrientation() const;
159 bool requestWindowOrientation(Qt::ScreenOrientation orientation);
160 Qt::ScreenOrientation windowOrientation() const;
162 Qt::WindowState windowState() const;
163 void setWindowState(Qt::WindowState state);
165 void setTransientParent(QWindow *parent);
166 QWindow *transientParent() const;
173 bool isAncestorOf(const QWindow *child, AncestorMode mode = IncludeTransients) const;
175 bool isExposed() const;
177 int minimumWidth() const { return minimumSize().width(); }
178 int minimumHeight() const { return minimumSize().height(); }
179 int maximumWidth() const { return maximumSize().width(); }
180 int maximumHeight() const { return maximumSize().height(); }
182 QSize minimumSize() const;
183 QSize maximumSize() const;
184 QSize baseSize() const;
185 QSize sizeIncrement() const;
187 void setMinimumSize(const QSize &size);
188 void setMaximumSize(const QSize &size);
189 void setBaseSize(const QSize &size);
190 void setSizeIncrement(const QSize &size);
192 void setGeometry(int posx, int posy, int w, int h) { setGeometry(QRect(posx, posy, w, h)); }
193 void setGeometry(const QRect &rect);
194 QRect geometry() const;
196 QMargins frameMargins() const;
197 QRect frameGeometry() const;
199 QPoint framePos() const;
200 void setFramePos(const QPoint &point);
202 inline int width() const { return geometry().width(); }
203 inline int height() const { return geometry().height(); }
204 inline int x() const { return geometry().x(); }
205 inline int y() const { return geometry().y(); }
207 inline QSize size() const { return geometry().size(); }
208 inline QPoint pos() const { return geometry().topLeft(); }
210 inline void setPos(const QPoint &pt) { setGeometry(QRect(pt, size())); }
211 inline void setPos(int posx, int posy) { setPos(QPoint(posx, posy)); }
213 void resize(const QSize &newSize);
214 inline void resize(int w, int h) { resize(QSize(w, h)); }
216 void setWindowFilePath(const QString &filePath);
217 QString windowFilePath() const;
219 void setWindowIcon(const QIcon &icon);
220 QIcon windowIcon() const;
224 QPlatformWindow *handle() const;
226 bool setKeyboardGrabEnabled(bool grab);
227 bool setMouseGrabEnabled(bool grab);
229 QScreen *screen() const;
230 void setScreen(QScreen *screen);
232 virtual QAccessibleInterface *accessibleRoot() const;
233 virtual QObject *focusObject() const;
235 QPoint mapToGlobal(const QPoint &pos) const;
236 QPoint mapFromGlobal(const QPoint &pos) const;
239 QCursor cursor() const;
240 void setCursor(const QCursor &);
245 void setVisible(bool visible);
250 void showMinimized();
251 void showMaximized();
252 void showFullScreen();
259 void setWindowTitle(const QString &);
264 setGeometry(QRect(arg, y(), width(), height()));
270 setGeometry(QRect(x(), arg, width(), height()));
273 void setWidth(int arg)
276 setGeometry(QRect(x(), y(), arg, height()));
279 void setHeight(int arg)
282 setGeometry(QRect(x(), y(), width(), arg));
285 void setMinimumWidth(int w);
286 void setMinimumHeight(int h);
287 void setMaximumWidth(int w);
288 void setMaximumHeight(int h);
291 void screenChanged(QScreen *screen);
292 void windowModalityChanged(Qt::WindowModality windowModality);
294 void xChanged(int arg);
295 void yChanged(int arg);
297 void widthChanged(int arg);
298 void heightChanged(int arg);
300 void minimumWidthChanged(int arg);
301 void minimumHeightChanged(int arg);
302 void maximumWidthChanged(int arg);
303 void maximumHeightChanged(int arg);
305 void visibleChanged(bool arg);
306 void contentOrientationChanged(Qt::ScreenOrientation orientation);
308 void focusObjectChanged(QObject *object);
311 void screenDestroyed(QObject *screen);
314 virtual void exposeEvent(QExposeEvent *);
315 virtual void resizeEvent(QResizeEvent *);
316 virtual void moveEvent(QMoveEvent *);
317 virtual void focusInEvent(QFocusEvent *);
318 virtual void focusOutEvent(QFocusEvent *);
320 virtual void showEvent(QShowEvent *);
321 virtual void hideEvent(QHideEvent *);
323 virtual bool event(QEvent *);
324 virtual void keyPressEvent(QKeyEvent *);
325 virtual void keyReleaseEvent(QKeyEvent *);
326 virtual void mousePressEvent(QMouseEvent *);
327 virtual void mouseReleaseEvent(QMouseEvent *);
328 virtual void mouseDoubleClickEvent(QMouseEvent *);
329 virtual void mouseMoveEvent(QMouseEvent *);
330 #ifndef QT_NO_WHEELEVENT
331 virtual void wheelEvent(QWheelEvent *);
333 virtual void touchEvent(QTouchEvent *);
334 #ifndef QT_NO_TABLETEVENT
335 virtual void tabletEvent(QTabletEvent *);
337 virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result);
339 QWindow(QWindowPrivate &dd, QWindow *parent);
342 QPlatformSurface *surfaceHandle() const;
344 Q_DISABLE_COPY(QWindow)
346 friend class QGuiApplication;
347 friend class QGuiApplicationPrivate;
348 friend Q_GUI_EXPORT QWindowPrivate *qt_window_private(QWindow *window);