Use QPointer instead of QWeakPointer.
[profile/ivi/qtbase.git] / src / gui / kernel / qwindowsysteminterface_qpa_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 #ifndef QWINDOWSYSTEMINTERFACE_QPA_P_H
42 #define QWINDOWSYSTEMINTERFACE_QPA_P_H
43
44 #include "qwindowsysteminterface_qpa.h"
45
46 #include <QElapsedTimer>
47 #include <QPointer>
48
49 QT_BEGIN_HEADER
50
51 QT_BEGIN_NAMESPACE
52
53 class QWindowSystemInterfacePrivate {
54 public:
55     enum EventType {
56         Close,
57         GeometryChange,
58         Enter,
59         Leave,
60         ActivatedWindow,
61         WindowStateChanged,
62         Mouse,
63         Wheel,
64         Key,
65         Touch,
66         ScreenOrientation,
67         ScreenGeometry,
68         ScreenAvailableGeometry,
69         ScreenLogicalDotsPerInch,
70         ScreenRefreshRate,
71         ThemeChange,
72         Expose,
73         FileOpen,
74         Tablet,
75         TabletEnterProximity,
76         TabletLeaveProximity
77     };
78
79     class WindowSystemEvent {
80     public:
81         explicit WindowSystemEvent(EventType t)
82             : type(t), synthetic(false) { }
83         virtual ~WindowSystemEvent() { }
84         EventType type;
85         bool synthetic;
86     };
87
88     class CloseEvent : public WindowSystemEvent {
89     public:
90         explicit CloseEvent(QWindow *w)
91             : WindowSystemEvent(Close), window(w) { }
92         QPointer<QWindow> window;
93     };
94
95     class GeometryChangeEvent : public WindowSystemEvent {
96     public:
97         GeometryChangeEvent(QWindow *tlw, const QRect &newGeometry)
98             : WindowSystemEvent(GeometryChange), tlw(tlw), newGeometry(newGeometry)
99         { }
100         QPointer<QWindow> tlw;
101         QRect newGeometry;
102     };
103
104     class EnterEvent : public WindowSystemEvent {
105     public:
106         explicit EnterEvent(QWindow *enter)
107             : WindowSystemEvent(Enter), enter(enter)
108         { }
109         QPointer<QWindow> enter;
110     };
111
112     class LeaveEvent : public WindowSystemEvent {
113     public:
114         explicit LeaveEvent(QWindow *leave)
115             : WindowSystemEvent(Leave), leave(leave)
116         { }
117         QPointer<QWindow> leave;
118     };
119
120     class ActivatedWindowEvent : public WindowSystemEvent {
121     public:
122         explicit ActivatedWindowEvent(QWindow *activatedWindow)
123             : WindowSystemEvent(ActivatedWindow), activated(activatedWindow)
124         { }
125         QPointer<QWindow> activated;
126     };
127
128     class WindowStateChangedEvent : public WindowSystemEvent {
129     public:
130         WindowStateChangedEvent(QWindow *_window, Qt::WindowState _newState)
131             : WindowSystemEvent(WindowStateChanged), window(_window), newState(_newState)
132         { }
133
134         QPointer<QWindow> window;
135         Qt::WindowState newState;
136     };
137
138     class UserEvent : public WindowSystemEvent {
139     public:
140         UserEvent(QWindow * w, ulong time, EventType t)
141             : WindowSystemEvent(t), window(w), nullWindow(w == 0), timestamp(time) { }
142         QPointer<QWindow> window;
143         bool nullWindow;
144         unsigned long timestamp;
145     };
146
147     class InputEvent: public UserEvent {
148     public:
149         InputEvent(QWindow * w, ulong time, EventType t, Qt::KeyboardModifiers mods)
150             : UserEvent(w, time, t), modifiers(mods) {}
151         Qt::KeyboardModifiers modifiers;
152     };
153
154     class MouseEvent : public InputEvent {
155     public:
156         MouseEvent(QWindow * w, ulong time, const QPointF & local, const QPointF & global,
157                    Qt::MouseButtons b, Qt::KeyboardModifiers mods)
158             : InputEvent(w, time, Mouse, mods), localPos(local), globalPos(global), buttons(b) { }
159         QPointF localPos;
160         QPointF globalPos;
161         Qt::MouseButtons buttons;
162     };
163
164     class WheelEvent : public InputEvent {
165     public:
166         WheelEvent(QWindow *w, ulong time, const QPointF & local, const QPointF & global, QPoint pixelD, QPoint angleD, int qt4D, Qt::Orientation qt4O,
167                    Qt::KeyboardModifiers mods)
168             : InputEvent(w, time, Wheel, mods), pixelDelta(pixelD), angleDelta(angleD), qt4Delta(qt4D), qt4Orientation(qt4O), localPos(local), globalPos(global) { }
169         QPoint pixelDelta;
170         QPoint angleDelta;
171         int qt4Delta;
172         Qt::Orientation qt4Orientation;
173         QPointF localPos;
174         QPointF globalPos;
175     };
176
177     class KeyEvent : public InputEvent {
178     public:
179         KeyEvent(QWindow *w, ulong time, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1)
180             :InputEvent(w, time, Key, mods), key(k), unicode(text), repeat(autorep),
181              repeatCount(count), keyType(t),
182              nativeScanCode(0), nativeVirtualKey(0), nativeModifiers(0) { }
183         KeyEvent(QWindow *w, ulong time, QEvent::Type t, int k, Qt::KeyboardModifiers mods,
184                  quint32 nativeSC, quint32 nativeVK, quint32 nativeMods,
185                  const QString & text = QString(), bool autorep = false, ushort count = 1)
186             :InputEvent(w, time, Key, mods), key(k), unicode(text), repeat(autorep),
187              repeatCount(count), keyType(t),
188              nativeScanCode(nativeSC), nativeVirtualKey(nativeVK), nativeModifiers(nativeMods) { }
189         int key;
190         QString unicode;
191         bool repeat;
192         ushort repeatCount;
193         QEvent::Type keyType;
194         quint32 nativeScanCode;
195         quint32 nativeVirtualKey;
196         quint32 nativeModifiers;
197     };
198
199     class TouchEvent : public InputEvent {
200     public:
201         TouchEvent(QWindow *w, ulong time, QEvent::Type t, QTouchDevice *dev,
202                    const QList<QTouchEvent::TouchPoint> &p, Qt::KeyboardModifiers mods)
203             :InputEvent(w, time, Touch, mods), device(dev), points(p), touchType(t) { }
204         QTouchDevice *device;
205         QList<QTouchEvent::TouchPoint> points;
206         QEvent::Type touchType;
207     };
208
209     class ScreenOrientationEvent : public WindowSystemEvent {
210     public:
211         ScreenOrientationEvent(QScreen *s, Qt::ScreenOrientation o)
212             : WindowSystemEvent(ScreenOrientation), screen(s), orientation(o) { }
213         QPointer<QScreen> screen;
214         Qt::ScreenOrientation orientation;
215     };
216
217     class ScreenGeometryEvent : public WindowSystemEvent {
218     public:
219         ScreenGeometryEvent(QScreen *s, const QRect &g)
220             : WindowSystemEvent(ScreenGeometry), screen(s), geometry(g) { }
221         QPointer<QScreen> screen;
222         QRect geometry;
223     };
224
225     class ScreenAvailableGeometryEvent : public WindowSystemEvent {
226     public:
227         ScreenAvailableGeometryEvent(QScreen *s, const QRect &g)
228             : WindowSystemEvent(ScreenAvailableGeometry), screen(s), availableGeometry(g) { }
229         QPointer<QScreen> screen;
230         QRect availableGeometry;
231     };
232
233     class ScreenLogicalDotsPerInchEvent : public WindowSystemEvent {
234     public:
235         ScreenLogicalDotsPerInchEvent(QScreen *s, qreal dx, qreal dy)
236             : WindowSystemEvent(ScreenLogicalDotsPerInch), screen(s), dpiX(dx), dpiY(dy) { }
237         QPointer<QScreen> screen;
238         qreal dpiX;
239         qreal dpiY;
240     };
241
242     class ScreenRefreshRateEvent : public WindowSystemEvent {
243     public:
244         ScreenRefreshRateEvent(QScreen *s, qreal r)
245             : WindowSystemEvent(ScreenRefreshRate), screen(s), rate(r) { }
246         QPointer<QScreen> screen;
247         qreal rate;
248     };
249
250     class ThemeChangeEvent : public WindowSystemEvent {
251     public:
252         explicit ThemeChangeEvent(QWindow * w)
253             : WindowSystemEvent(ThemeChange), window(w) { }
254         QPointer<QWindow> window;
255     };
256
257     class ExposeEvent : public WindowSystemEvent {
258     public:
259         ExposeEvent(QWindow *exposed, const QRegion &region);
260         QPointer<QWindow> exposed;
261         bool isExposed;
262         QRegion region;
263     };
264
265     class FileOpenEvent : public WindowSystemEvent {
266     public:
267         FileOpenEvent(const QString& fileName)
268             : WindowSystemEvent(FileOpen), fileName(fileName)
269         { }
270         QString fileName;
271     };
272
273     class TabletEvent : public InputEvent {
274     public:
275         static void handleTabletEvent(QWindow *w, bool down, const QPointF &local, const QPointF &global,
276                                       int device, int pointerType, qreal pressure, int xTilt, int yTilt,
277                                       qreal tangentialPressure, qreal rotation, int z, qint64 uid,
278                                       Qt::KeyboardModifiers modifiers = Qt::NoModifier);
279
280         TabletEvent(QWindow *w, ulong time, bool down, const QPointF &local, const QPointF &global,
281                     int device, int pointerType, qreal pressure, int xTilt, int yTilt, qreal tpressure,
282                     qreal rotation, int z, qint64 uid, Qt::KeyboardModifiers mods)
283             : InputEvent(w, time, Tablet, Qt::NoModifier),
284               down(down), local(local), global(global), device(device), pointerType(pointerType),
285               pressure(pressure), xTilt(xTilt), yTilt(yTilt), tangentialPressure(tpressure),
286               rotation(rotation), z(z), uid(uid), mods(mods) { }
287         bool down;
288         QPointF local;
289         QPointF global;
290         int device;
291         int pointerType;
292         qreal pressure;
293         int xTilt;
294         int yTilt;
295         qreal tangentialPressure;
296         qreal rotation;
297         int z;
298         qint64 uid;
299         Qt::KeyboardModifiers mods;
300     };
301
302     class TabletEnterProximityEvent : public InputEvent {
303     public:
304         TabletEnterProximityEvent(ulong time, int device, int pointerType, qint64 uid)
305             : InputEvent(0, time, TabletEnterProximity, Qt::NoModifier),
306               device(device), pointerType(pointerType), uid(uid) { }
307         int device;
308         int pointerType;
309         qint64 uid;
310     };
311
312     class TabletLeaveProximityEvent : public InputEvent {
313     public:
314         TabletLeaveProximityEvent(ulong time, int device, int pointerType, qint64 uid)
315             : InputEvent(0, time, TabletLeaveProximity, Qt::NoModifier),
316               device(device), pointerType(pointerType), uid(uid) { }
317         int device;
318         int pointerType;
319         qint64 uid;
320     };
321
322     static QList<WindowSystemEvent *> windowSystemEventQueue;
323     static QMutex queueMutex;
324
325     static int windowSystemEventsQueued();
326     static WindowSystemEvent * getWindowSystemEvent();
327     static void queueWindowSystemEvent(WindowSystemEvent *ev);
328
329     static QElapsedTimer eventTime;
330
331     static QList<QTouchEvent::TouchPoint> convertTouchPoints(const QList<QWindowSystemInterface::TouchPoint> &points, QEvent::Type *type);
332 };
333
334 QT_END_HEADER
335 QT_END_NAMESPACE
336
337 #endif // QWINDOWSYSTEMINTERFACE_QPA_P_H