Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickmultipointtoucharea_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 QtDeclarative 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
42 #ifndef QQUICKMULTIPOINTTOUCHAREA_H
43 #define QQUICKMULTIPOINTTOUCHAREA_H
44
45 #include "qquickitem.h"
46 #include "qevent.h"
47
48 #include <QMap>
49 #include <QList>
50 #include <QtGui/qguiapplication.h>
51 #include <QtGui/qstylehints.h>
52
53 QT_BEGIN_HEADER
54
55 QT_BEGIN_NAMESPACE
56
57 class QQuickMultiPointTouchArea;
58 class Q_AUTOTEST_EXPORT QQuickTouchPoint : public QObject
59 {
60     Q_OBJECT
61     Q_PROPERTY(int pointId READ pointId NOTIFY pointIdChanged)
62     Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged)
63     Q_PROPERTY(qreal x READ x NOTIFY xChanged)
64     Q_PROPERTY(qreal y READ y NOTIFY yChanged)
65     Q_PROPERTY(qreal pressure READ pressure NOTIFY pressureChanged)
66     Q_PROPERTY(QRectF area READ area NOTIFY areaChanged)
67
68     Q_PROPERTY(qreal startX READ startX NOTIFY startXChanged)
69     Q_PROPERTY(qreal startY READ startY NOTIFY startYChanged)
70     Q_PROPERTY(qreal previousX READ previousX NOTIFY previousXChanged)
71     Q_PROPERTY(qreal previousY READ previousY NOTIFY previousYChanged)
72     Q_PROPERTY(qreal sceneX READ sceneX NOTIFY sceneXChanged)
73     Q_PROPERTY(qreal sceneY READ sceneY NOTIFY sceneYChanged)
74
75 public:
76     QQuickTouchPoint(bool qmlDefined = true)
77         : _id(0),
78           _x(0.0), _y(0.0),
79           _pressure(0.0),
80           _qmlDefined(qmlDefined),
81           _inUse(false),
82           _pressed(false),
83           _previousX(0.0), _previousY(0.0),
84           _sceneX(0.0), _sceneY(0.0)
85     {}
86
87     int pointId() const { return _id; }
88     void setPointId(int id);
89
90     qreal x() const { return _x; }
91     void setX(qreal x);
92
93     qreal y() const { return _y; }
94     void setY(qreal y);
95
96     qreal pressure() const { return _pressure; }
97     void setPressure(qreal pressure);
98
99     QRectF area() const { return _area; }
100     void setArea(const QRectF &area);
101
102     bool isQmlDefined() const { return _qmlDefined; }
103
104     bool inUse() const { return _inUse; }
105     void setInUse(bool inUse) { _inUse = inUse; }
106
107     bool pressed() const { return _pressed; }
108     void setPressed(bool pressed);
109
110     qreal startX() const { return _startX; }
111     void setStartX(qreal startX);
112
113     qreal startY() const { return _startY; }
114     void setStartY(qreal startY);
115
116     qreal previousX() const { return _previousX; }
117     void setPreviousX(qreal previousX);
118
119     qreal previousY() const { return _previousY; }
120     void setPreviousY(qreal previousY);
121
122     qreal sceneX() const { return _sceneX; }
123     void setSceneX(qreal sceneX);
124
125     qreal sceneY() const { return _sceneY; }
126     void setSceneY(qreal sceneY);
127
128 Q_SIGNALS:
129     void pressedChanged();
130     void pointIdChanged();
131     void xChanged();
132     void yChanged();
133     void pressureChanged();
134     void areaChanged();
135     void startXChanged();
136     void startYChanged();
137     void previousXChanged();
138     void previousYChanged();
139     void sceneXChanged();
140     void sceneYChanged();
141
142 private:
143     friend class QQuickMultiPointTouchArea;
144     int _id;
145     qreal _x;
146     qreal _y;
147     qreal _pressure;
148     QRectF _area;
149     bool _qmlDefined;
150     bool _inUse;    //whether the point is currently in use (only valid when _qmlDefined == true)
151     bool _pressed;
152     qreal _startX;
153     qreal _startY;
154     qreal _previousX;
155     qreal _previousY;
156     qreal _sceneX;
157     qreal _sceneY;
158 };
159
160 class QQuickGrabGestureEvent : public QObject
161 {
162     Q_OBJECT
163     Q_PROPERTY(QDeclarativeListProperty<QObject> touchPoints READ touchPoints)
164     Q_PROPERTY(qreal dragThreshold READ dragThreshold)
165 public:
166     QQuickGrabGestureEvent() : _grab(false), _dragThreshold(qApp->styleHints()->startDragDistance()) {}
167
168     Q_INVOKABLE void grab() { _grab = true; }
169     bool wantsGrab() const { return _grab; }
170
171     QDeclarativeListProperty<QObject> touchPoints() {
172         return QDeclarativeListProperty<QObject>(this, _touchPoints);
173     }
174     qreal dragThreshold() const { return _dragThreshold; }
175
176 private:
177     friend class QQuickMultiPointTouchArea;
178     bool _grab;
179     qreal _dragThreshold;
180     QList<QObject*> _touchPoints;
181 };
182
183 class Q_AUTOTEST_EXPORT QQuickMultiPointTouchArea : public QQuickItem
184 {
185     Q_OBJECT
186
187     Q_PROPERTY(QDeclarativeListProperty<QQuickTouchPoint> touchPoints READ touchPoints)
188     Q_PROPERTY(int minimumTouchPoints READ minimumTouchPoints WRITE setMinimumTouchPoints NOTIFY minimumTouchPointsChanged)
189     Q_PROPERTY(int maximumTouchPoints READ maximumTouchPoints WRITE setMaximumTouchPoints NOTIFY maximumTouchPointsChanged)
190
191 public:
192     QQuickMultiPointTouchArea(QQuickItem *parent=0);
193     ~QQuickMultiPointTouchArea();
194
195     int minimumTouchPoints() const;
196     void setMinimumTouchPoints(int num);
197     int maximumTouchPoints() const;
198     void setMaximumTouchPoints(int num);
199
200     QDeclarativeListProperty<QQuickTouchPoint> touchPoints() {
201         return QDeclarativeListProperty<QQuickTouchPoint>(this, 0, QQuickMultiPointTouchArea::touchPoint_append, QQuickMultiPointTouchArea::touchPoint_count, QQuickMultiPointTouchArea::touchPoint_at, 0);
202     }
203
204     static void touchPoint_append(QDeclarativeListProperty<QQuickTouchPoint> *list, QQuickTouchPoint* touch) {
205         QQuickMultiPointTouchArea *q = static_cast<QQuickMultiPointTouchArea*>(list->object);
206         q->addTouchPrototype(touch);
207     }
208
209     static int touchPoint_count(QDeclarativeListProperty<QQuickTouchPoint> *list) {
210         QQuickMultiPointTouchArea *q = static_cast<QQuickMultiPointTouchArea*>(list->object);
211         return q->_touchPrototypes.count();
212     }
213
214     static QQuickTouchPoint* touchPoint_at(QDeclarativeListProperty<QQuickTouchPoint> *list, int index) {
215         QQuickMultiPointTouchArea *q = static_cast<QQuickMultiPointTouchArea*>(list->object);
216         return q->_touchPrototypes[index];
217     }
218
219 Q_SIGNALS:
220     void pressed(const QList<QObject*> &touchPoints);
221     void updated(const QList<QObject*> &touchPoints);
222     void released(const QList<QObject*> &touchPoints);
223     void canceled(const QList<QObject*> &touchPoints);
224     void gestureStarted(QQuickGrabGestureEvent *gesture);
225     void touchUpdated(const QList<QObject*> &touchPoints);
226     void minimumTouchPointsChanged();
227     void maximumTouchPointsChanged();
228
229     //### deprecated, will be removed for 5.0
230     void touchPointsPressed(const QList<QObject*> &touchPoints);
231     void touchPointsUpdated(const QList<QObject*> &touchPoints);
232     void touchPointsReleased(const QList<QObject*> &touchPoints);
233     void touchPointsCanceled(const QList<QObject*> &touchPoints);
234
235 protected:
236     void touchEvent(QTouchEvent *);
237     bool childMouseEventFilter(QQuickItem *i, QEvent *event);
238     void mousePressEvent(QMouseEvent *event);
239     void mouseReleaseEvent(QMouseEvent *event);
240     void mouseMoveEvent(QMouseEvent *event);
241     void mouseUngrabEvent();
242     void touchUngrabEvent();
243
244     void addTouchPrototype(QQuickTouchPoint* prototype);
245     void addTouchPoint(const QTouchEvent::TouchPoint *p);
246     void clearTouchLists();
247
248     void updateTouchPoint(QQuickTouchPoint*, const QTouchEvent::TouchPoint*);
249     void updateTouchData(QEvent*);
250
251     bool sendMouseEvent(QMouseEvent *event);
252     bool shouldFilter(QEvent *event);
253     void grabGesture();
254
255 private:
256     void ungrab();
257     QMap<int,QQuickTouchPoint*> _touchPrototypes;  //TouchPoints defined in QML
258     QMap<int,QObject*> _touchPoints;            //All current touch points
259     QList<QObject*> _releasedTouchPoints;
260     QList<QObject*> _pressedTouchPoints;
261     QList<QObject*> _movedTouchPoints;
262     int _minimumTouchPoints;
263     int _maximumTouchPoints;
264     bool _stealMouse;
265 };
266
267 QT_END_NAMESPACE
268
269 QML_DECLARE_TYPE(QQuickTouchPoint)
270 QML_DECLARE_TYPE(QQuickGrabGestureEvent)
271 QML_DECLARE_TYPE(QQuickMultiPointTouchArea)
272
273 QT_END_HEADER
274
275 #endif // QQUICKMULTIPOINTTOUCHAREA_H