Temporary backwards-compatible QWindow::setPos accessors
[profile/ivi/qtbase.git] / src / gui / kernel / qwindow.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 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.
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 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.
24 **
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.
28 **
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.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QWINDOW_H
43 #define QWINDOW_H
44
45 #include <QtCore/QObject>
46 #include <QtCore/QEvent>
47 #include <QtCore/QMargins>
48 #include <QtCore/QRect>
49
50 #include <QtCore/qnamespace.h>
51
52 #include <QtGui/qsurface.h>
53 #include <QtGui/qsurfaceformat.h>
54 #include <QtGui/qwindowdefs.h>
55
56 #include <QtGui/qicon.h>
57
58 #ifndef QT_NO_CURSOR
59 #include <QtGui/qcursor.h>
60 #endif
61
62 QT_BEGIN_HEADER
63
64 QT_BEGIN_NAMESPACE
65
66
67 class QWindowPrivate;
68
69 class QExposeEvent;
70 class QFocusEvent;
71 class QMoveEvent;
72 class QResizeEvent;
73 class QShowEvent;
74 class QHideEvent;
75 class QKeyEvent;
76 class QMouseEvent;
77 #ifndef QT_NO_WHEELEVENT
78 class QWheelEvent;
79 #endif
80 class QTouchEvent;
81 #ifndef QT_NO_TABLETEVENT
82 class QTabletEvent;
83 #endif
84
85 class QPlatformSurface;
86 class QPlatformWindow;
87 class QBackingStore;
88 class QScreen;
89 class QAccessibleInterface;
90
91 class Q_GUI_EXPORT QWindow : public QObject, public QSurface
92 {
93     Q_OBJECT
94     Q_DECLARE_PRIVATE(QWindow)
95
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.
101
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)
115
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)
122
123 public:
124
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); }
139
140 Q_SIGNALS:
141     void windowModalityChanged(Qt::WindowModality windowModality);
142     // End of temporary backwards-compatibility properties
143     // ------------------------------------------------------------------------
144
145 public:
146
147     explicit QWindow(QScreen *screen = 0);
148     explicit QWindow(QWindow *parent);
149     virtual ~QWindow();
150
151     void setSurfaceType(SurfaceType surfaceType);
152     SurfaceType surfaceType() const;
153
154     bool isVisible() const;
155
156     void create();
157
158     WId winId() const;
159
160     QWindow *parent() const;
161     void setParent(QWindow *parent);
162
163     bool isTopLevel() const;
164
165     bool isModal() const;
166     Qt::WindowModality modality() const;
167     void setModality(Qt::WindowModality modality);
168
169     void setFormat(const QSurfaceFormat &format);
170     QSurfaceFormat format() const;
171     QSurfaceFormat requestedFormat() const;
172
173     void setFlags(Qt::WindowFlags flags);
174     Qt::WindowFlags flags() const;
175     Qt::WindowType type() const;
176
177     QString title() const;
178
179     void setOpacity(qreal level);
180     void requestActivate();
181
182     bool isActive() const;
183
184     void reportContentOrientationChange(Qt::ScreenOrientation orientation);
185     Qt::ScreenOrientation contentOrientation() const;
186
187     bool requestOrientation(Qt::ScreenOrientation orientation);
188     Qt::ScreenOrientation orientation() const;
189
190     Qt::WindowState windowState() const;
191     void setWindowState(Qt::WindowState state);
192
193     void setTransientParent(QWindow *parent);
194     QWindow *transientParent() const;
195
196     enum AncestorMode {
197         ExcludeTransients,
198         IncludeTransients
199     };
200
201     bool isAncestorOf(const QWindow *child, AncestorMode mode = IncludeTransients) const;
202
203     bool isExposed() const;
204
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(); }
209
210     QSize minimumSize() const;
211     QSize maximumSize() const;
212     QSize baseSize() const;
213     QSize sizeIncrement() const;
214
215     void setMinimumSize(const QSize &size);
216     void setMaximumSize(const QSize &size);
217     void setBaseSize(const QSize &size);
218     void setSizeIncrement(const QSize &size);
219
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;
223
224     QMargins frameMargins() const;
225     QRect frameGeometry() const;
226
227     QPoint framePos() const;
228     void setFramePos(const QPoint &point);
229
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(); }
234
235     inline QSize size() const { return geometry().size(); }
236     inline QPoint position() const { return geometry().topLeft(); }
237
238     inline void setPosition(const QPoint &pt) { setGeometry(QRect(pt, size())); }
239     inline void setPosition(int posx, int posy) { setPosition(QPoint(posx, posy)); }
240
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
246
247     void resize(const QSize &newSize);
248     inline void resize(int w, int h) { resize(QSize(w, h)); }
249
250     void setFilePath(const QString &filePath);
251     QString filePath() const;
252
253     void setIcon(const QIcon &icon);
254     QIcon icon() const;
255
256     void destroy();
257
258     QPlatformWindow *handle() const;
259
260     bool setKeyboardGrabEnabled(bool grab);
261     bool setMouseGrabEnabled(bool grab);
262
263     QScreen *screen() const;
264     void setScreen(QScreen *screen);
265
266     virtual QAccessibleInterface *accessibleRoot() const;
267     virtual QObject *focusObject() const;
268
269     QPoint mapToGlobal(const QPoint &pos) const;
270     QPoint mapFromGlobal(const QPoint &pos) const;
271
272 #ifndef QT_NO_CURSOR
273     QCursor cursor() const;
274     void setCursor(const QCursor &);
275     void unsetCursor();
276 #endif
277
278 public Q_SLOTS:
279     void setVisible(bool visible);
280
281     void show();
282     void hide();
283
284     void showMinimized();
285     void showMaximized();
286     void showFullScreen();
287     void showNormal();
288
289     bool close();
290     void raise();
291     void lower();
292
293     void setTitle(const QString &);
294
295     void setX(int arg)
296     {
297         if (x() != arg)
298             setGeometry(QRect(arg, y(), width(), height()));
299     }
300
301     void setY(int arg)
302     {
303         if (y() != arg)
304             setGeometry(QRect(x(), arg, width(), height()));
305     }
306
307     void setWidth(int arg)
308     {
309         if (width() != arg)
310             setGeometry(QRect(x(), y(), arg, height()));
311     }
312
313     void setHeight(int arg)
314     {
315         if (height() != arg)
316             setGeometry(QRect(x(), y(), width(), arg));
317     }
318
319     void setMinimumWidth(int w);
320     void setMinimumHeight(int h);
321     void setMaximumWidth(int w);
322     void setMaximumHeight(int h);
323
324 Q_SIGNALS:
325     void screenChanged(QScreen *screen);
326     void modalityChanged(Qt::WindowModality modality);
327     void windowStateChanged(Qt::WindowState windowState);
328
329     void xChanged(int arg);
330     void yChanged(int arg);
331
332     void widthChanged(int arg);
333     void heightChanged(int arg);
334
335     void minimumWidthChanged(int arg);
336     void minimumHeightChanged(int arg);
337     void maximumWidthChanged(int arg);
338     void maximumHeightChanged(int arg);
339
340     void visibleChanged(bool arg);
341     void contentOrientationChanged(Qt::ScreenOrientation orientation);
342
343     void focusObjectChanged(QObject *object);
344
345 private Q_SLOTS:
346     void screenDestroyed(QObject *screen);
347
348 protected:
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 *);
354
355     virtual void showEvent(QShowEvent *);
356     virtual void hideEvent(QHideEvent *);
357
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 *);
367 #endif
368     virtual void touchEvent(QTouchEvent *);
369 #ifndef QT_NO_TABLETEVENT
370     virtual void tabletEvent(QTabletEvent *);
371 #endif
372     virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result);
373
374     QWindow(QWindowPrivate &dd, QWindow *parent);
375
376 private:
377     QPlatformSurface *surfaceHandle() const;
378
379     Q_DISABLE_COPY(QWindow)
380
381     friend class QGuiApplication;
382     friend class QGuiApplicationPrivate;
383     friend Q_GUI_EXPORT QWindowPrivate *qt_window_private(QWindow *window);
384 };
385
386 QT_END_NAMESPACE
387
388 QT_END_HEADER
389
390 #endif // QWINDOW_H