Change copyrights from Nokia to Digia
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickmultipointtoucharea_p.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 QtQml 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 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(QVector2D velocity READ velocity NOTIFY velocityChanged)
67     Q_PROPERTY(QRectF area READ area NOTIFY areaChanged)
68
69     Q_PROPERTY(qreal startX READ startX NOTIFY startXChanged)
70     Q_PROPERTY(qreal startY READ startY NOTIFY startYChanged)
71     Q_PROPERTY(qreal previousX READ previousX NOTIFY previousXChanged)
72     Q_PROPERTY(qreal previousY READ previousY NOTIFY previousYChanged)
73     Q_PROPERTY(qreal sceneX READ sceneX NOTIFY sceneXChanged)
74     Q_PROPERTY(qreal sceneY READ sceneY NOTIFY sceneYChanged)
75
76 public:
77     QQuickTouchPoint(bool qmlDefined = true)
78         : _id(0),
79           _x(0.0), _y(0.0),
80           _pressure(0.0),
81           _qmlDefined(qmlDefined),
82           _inUse(false),
83           _pressed(false),
84           _previousX(0.0), _previousY(0.0),
85           _sceneX(0.0), _sceneY(0.0)
86     {}
87
88     int pointId() const { return _id; }
89     void setPointId(int id);
90
91     qreal x() const { return _x; }
92     void setX(qreal x);
93
94     qreal y() const { return _y; }
95     void setY(qreal y);
96
97     qreal pressure() const { return _pressure; }
98     void setPressure(qreal pressure);
99
100     QVector2D velocity() const { return _velocity; }
101     void setVelocity(const QVector2D &velocity);
102
103     QRectF area() const { return _area; }
104     void setArea(const QRectF &area);
105
106     bool isQmlDefined() const { return _qmlDefined; }
107
108     bool inUse() const { return _inUse; }
109     void setInUse(bool inUse) { _inUse = inUse; }
110
111     bool pressed() const { return _pressed; }
112     void setPressed(bool pressed);
113
114     qreal startX() const { return _startX; }
115     void setStartX(qreal startX);
116
117     qreal startY() const { return _startY; }
118     void setStartY(qreal startY);
119
120     qreal previousX() const { return _previousX; }
121     void setPreviousX(qreal previousX);
122
123     qreal previousY() const { return _previousY; }
124     void setPreviousY(qreal previousY);
125
126     qreal sceneX() const { return _sceneX; }
127     void setSceneX(qreal sceneX);
128
129     qreal sceneY() const { return _sceneY; }
130     void setSceneY(qreal sceneY);
131
132 Q_SIGNALS:
133     void pressedChanged();
134     void pointIdChanged();
135     void xChanged();
136     void yChanged();
137     void pressureChanged();
138     void velocityChanged();
139     void areaChanged();
140     void startXChanged();
141     void startYChanged();
142     void previousXChanged();
143     void previousYChanged();
144     void sceneXChanged();
145     void sceneYChanged();
146
147 private:
148     friend class QQuickMultiPointTouchArea;
149     int _id;
150     qreal _x;
151     qreal _y;
152     qreal _pressure;
153     QVector2D _velocity;
154     QRectF _area;
155     bool _qmlDefined;
156     bool _inUse;    //whether the point is currently in use (only valid when _qmlDefined == true)
157     bool _pressed;
158     qreal _startX;
159     qreal _startY;
160     qreal _previousX;
161     qreal _previousY;
162     qreal _sceneX;
163     qreal _sceneY;
164 };
165
166 class QQuickGrabGestureEvent : public QObject
167 {
168     Q_OBJECT
169     Q_PROPERTY(QQmlListProperty<QObject> touchPoints READ touchPoints)
170     Q_PROPERTY(qreal dragThreshold READ dragThreshold)
171 public:
172     QQuickGrabGestureEvent() : _grab(false), _dragThreshold(qApp->styleHints()->startDragDistance()) {}
173
174     Q_INVOKABLE void grab() { _grab = true; }
175     bool wantsGrab() const { return _grab; }
176
177     QQmlListProperty<QObject> touchPoints() {
178         return QQmlListProperty<QObject>(this, _touchPoints);
179     }
180     qreal dragThreshold() const { return _dragThreshold; }
181
182 private:
183     friend class QQuickMultiPointTouchArea;
184     bool _grab;
185     qreal _dragThreshold;
186     QList<QObject*> _touchPoints;
187 };
188
189 class Q_AUTOTEST_EXPORT QQuickMultiPointTouchArea : public QQuickItem
190 {
191     Q_OBJECT
192
193     Q_PROPERTY(QQmlListProperty<QQuickTouchPoint> touchPoints READ touchPoints)
194     Q_PROPERTY(int minimumTouchPoints READ minimumTouchPoints WRITE setMinimumTouchPoints NOTIFY minimumTouchPointsChanged)
195     Q_PROPERTY(int maximumTouchPoints READ maximumTouchPoints WRITE setMaximumTouchPoints NOTIFY maximumTouchPointsChanged)
196
197 public:
198     QQuickMultiPointTouchArea(QQuickItem *parent=0);
199     ~QQuickMultiPointTouchArea();
200
201     int minimumTouchPoints() const;
202     void setMinimumTouchPoints(int num);
203     int maximumTouchPoints() const;
204     void setMaximumTouchPoints(int num);
205
206     QQmlListProperty<QQuickTouchPoint> touchPoints() {
207         return QQmlListProperty<QQuickTouchPoint>(this, 0, QQuickMultiPointTouchArea::touchPoint_append, QQuickMultiPointTouchArea::touchPoint_count, QQuickMultiPointTouchArea::touchPoint_at, 0);
208     }
209
210     static void touchPoint_append(QQmlListProperty<QQuickTouchPoint> *list, QQuickTouchPoint* touch) {
211         QQuickMultiPointTouchArea *q = static_cast<QQuickMultiPointTouchArea*>(list->object);
212         q->addTouchPrototype(touch);
213     }
214
215     static int touchPoint_count(QQmlListProperty<QQuickTouchPoint> *list) {
216         QQuickMultiPointTouchArea *q = static_cast<QQuickMultiPointTouchArea*>(list->object);
217         return q->_touchPrototypes.count();
218     }
219
220     static QQuickTouchPoint* touchPoint_at(QQmlListProperty<QQuickTouchPoint> *list, int index) {
221         QQuickMultiPointTouchArea *q = static_cast<QQuickMultiPointTouchArea*>(list->object);
222         return q->_touchPrototypes[index];
223     }
224
225 Q_SIGNALS:
226     void pressed(const QList<QObject*> &touchPoints);
227     void updated(const QList<QObject*> &touchPoints);
228     void released(const QList<QObject*> &touchPoints);
229     void canceled(const QList<QObject*> &touchPoints);
230     void gestureStarted(QQuickGrabGestureEvent *gesture);
231     void touchUpdated(const QList<QObject*> &touchPoints);
232     void minimumTouchPointsChanged();
233     void maximumTouchPointsChanged();
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     virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
255
256 private:
257     void ungrab();
258     QMap<int,QQuickTouchPoint*> _touchPrototypes;  //TouchPoints defined in QML
259     QMap<int,QObject*> _touchPoints;            //All current touch points
260     QList<QObject*> _releasedTouchPoints;
261     QList<QObject*> _pressedTouchPoints;
262     QList<QObject*> _movedTouchPoints;
263     int _minimumTouchPoints;
264     int _maximumTouchPoints;
265     bool _stealMouse;
266 };
267
268 QT_END_NAMESPACE
269
270 QML_DECLARE_TYPE(QQuickTouchPoint)
271 QML_DECLARE_TYPE(QQuickGrabGestureEvent)
272 QML_DECLARE_TYPE(QQuickMultiPointTouchArea)
273
274 QT_END_HEADER
275
276 #endif // QQUICKMULTIPOINTTOUCHAREA_H