1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QQUICKMULTIPOINTTOUCHAREA_H
43 #define QQUICKMULTIPOINTTOUCHAREA_H
45 #include "qquickitem.h"
50 #include <QtGui/qguiapplication.h>
51 #include <QtGui/qstylehints.h>
57 class QQuickMultiPointTouchArea;
58 class Q_AUTOTEST_EXPORT QQuickTouchPoint : public QObject
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)
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)
77 QQuickTouchPoint(bool qmlDefined = true)
81 _qmlDefined(qmlDefined),
84 _previousX(0.0), _previousY(0.0),
85 _sceneX(0.0), _sceneY(0.0)
88 int pointId() const { return _id; }
89 void setPointId(int id);
91 qreal x() const { return _x; }
94 qreal y() const { return _y; }
97 qreal pressure() const { return _pressure; }
98 void setPressure(qreal pressure);
100 QVector2D velocity() const { return _velocity; }
101 void setVelocity(const QVector2D &velocity);
103 QRectF area() const { return _area; }
104 void setArea(const QRectF &area);
106 bool isQmlDefined() const { return _qmlDefined; }
108 bool inUse() const { return _inUse; }
109 void setInUse(bool inUse) { _inUse = inUse; }
111 bool pressed() const { return _pressed; }
112 void setPressed(bool pressed);
114 qreal startX() const { return _startX; }
115 void setStartX(qreal startX);
117 qreal startY() const { return _startY; }
118 void setStartY(qreal startY);
120 qreal previousX() const { return _previousX; }
121 void setPreviousX(qreal previousX);
123 qreal previousY() const { return _previousY; }
124 void setPreviousY(qreal previousY);
126 qreal sceneX() const { return _sceneX; }
127 void setSceneX(qreal sceneX);
129 qreal sceneY() const { return _sceneY; }
130 void setSceneY(qreal sceneY);
133 void pressedChanged();
134 void pointIdChanged();
137 void pressureChanged();
138 void velocityChanged();
140 void startXChanged();
141 void startYChanged();
142 void previousXChanged();
143 void previousYChanged();
144 void sceneXChanged();
145 void sceneYChanged();
148 friend class QQuickMultiPointTouchArea;
156 bool _inUse; //whether the point is currently in use (only valid when _qmlDefined == true)
166 class QQuickGrabGestureEvent : public QObject
169 Q_PROPERTY(QQmlListProperty<QObject> touchPoints READ touchPoints)
170 Q_PROPERTY(qreal dragThreshold READ dragThreshold)
172 QQuickGrabGestureEvent() : _grab(false), _dragThreshold(qApp->styleHints()->startDragDistance()) {}
174 Q_INVOKABLE void grab() { _grab = true; }
175 bool wantsGrab() const { return _grab; }
177 QQmlListProperty<QObject> touchPoints() {
178 return QQmlListProperty<QObject>(this, _touchPoints);
180 qreal dragThreshold() const { return _dragThreshold; }
183 friend class QQuickMultiPointTouchArea;
185 qreal _dragThreshold;
186 QList<QObject*> _touchPoints;
189 class Q_AUTOTEST_EXPORT QQuickMultiPointTouchArea : public QQuickItem
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)
198 QQuickMultiPointTouchArea(QQuickItem *parent=0);
199 ~QQuickMultiPointTouchArea();
201 int minimumTouchPoints() const;
202 void setMinimumTouchPoints(int num);
203 int maximumTouchPoints() const;
204 void setMaximumTouchPoints(int num);
206 QQmlListProperty<QQuickTouchPoint> touchPoints() {
207 return QQmlListProperty<QQuickTouchPoint>(this, 0, QQuickMultiPointTouchArea::touchPoint_append, QQuickMultiPointTouchArea::touchPoint_count, QQuickMultiPointTouchArea::touchPoint_at, 0);
210 static void touchPoint_append(QQmlListProperty<QQuickTouchPoint> *list, QQuickTouchPoint* touch) {
211 QQuickMultiPointTouchArea *q = static_cast<QQuickMultiPointTouchArea*>(list->object);
212 q->addTouchPrototype(touch);
215 static int touchPoint_count(QQmlListProperty<QQuickTouchPoint> *list) {
216 QQuickMultiPointTouchArea *q = static_cast<QQuickMultiPointTouchArea*>(list->object);
217 return q->_touchPrototypes.count();
220 static QQuickTouchPoint* touchPoint_at(QQmlListProperty<QQuickTouchPoint> *list, int index) {
221 QQuickMultiPointTouchArea *q = static_cast<QQuickMultiPointTouchArea*>(list->object);
222 return q->_touchPrototypes[index];
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();
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();
244 void addTouchPrototype(QQuickTouchPoint* prototype);
245 void addTouchPoint(const QTouchEvent::TouchPoint *p);
246 void clearTouchLists();
248 void updateTouchPoint(QQuickTouchPoint*, const QTouchEvent::TouchPoint*);
249 void updateTouchData(QEvent*);
251 bool sendMouseEvent(QMouseEvent *event);
252 bool shouldFilter(QEvent *event);
254 virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
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;
270 QML_DECLARE_TYPE(QQuickTouchPoint)
271 QML_DECLARE_TYPE(QQuickGrabGestureEvent)
272 QML_DECLARE_TYPE(QQuickMultiPointTouchArea)
276 #endif // QQUICKMULTIPOINTTOUCHAREA_H