1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** 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(QRectF area READ area NOTIFY areaChanged)
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)
76 QQuickTouchPoint(bool qmlDefined = true)
80 _qmlDefined(qmlDefined),
83 _previousX(0.0), _previousY(0.0),
84 _sceneX(0.0), _sceneY(0.0)
87 int pointId() const { return _id; }
88 void setPointId(int id);
90 qreal x() const { return _x; }
93 qreal y() const { return _y; }
96 qreal pressure() const { return _pressure; }
97 void setPressure(qreal pressure);
99 QRectF area() const { return _area; }
100 void setArea(const QRectF &area);
102 bool isQmlDefined() const { return _qmlDefined; }
104 bool inUse() const { return _inUse; }
105 void setInUse(bool inUse) { _inUse = inUse; }
107 bool pressed() const { return _pressed; }
108 void setPressed(bool pressed);
110 qreal startX() const { return _startX; }
111 void setStartX(qreal startX);
113 qreal startY() const { return _startY; }
114 void setStartY(qreal startY);
116 qreal previousX() const { return _previousX; }
117 void setPreviousX(qreal previousX);
119 qreal previousY() const { return _previousY; }
120 void setPreviousY(qreal previousY);
122 qreal sceneX() const { return _sceneX; }
123 void setSceneX(qreal sceneX);
125 qreal sceneY() const { return _sceneY; }
126 void setSceneY(qreal sceneY);
129 void pressedChanged();
130 void pointIdChanged();
133 void pressureChanged();
135 void startXChanged();
136 void startYChanged();
137 void previousXChanged();
138 void previousYChanged();
139 void sceneXChanged();
140 void sceneYChanged();
143 friend class QQuickMultiPointTouchArea;
150 bool _inUse; //whether the point is currently in use (only valid when _qmlDefined == true)
160 class QQuickGrabGestureEvent : public QObject
163 Q_PROPERTY(QDeclarativeListProperty<QObject> touchPoints READ touchPoints)
164 Q_PROPERTY(qreal dragThreshold READ dragThreshold)
166 QQuickGrabGestureEvent() : _grab(false), _dragThreshold(qApp->styleHints()->startDragDistance()) {}
168 Q_INVOKABLE void grab() { _grab = true; }
169 bool wantsGrab() const { return _grab; }
171 QDeclarativeListProperty<QObject> touchPoints() {
172 return QDeclarativeListProperty<QObject>(this, _touchPoints);
174 qreal dragThreshold() const { return _dragThreshold; }
177 friend class QQuickMultiPointTouchArea;
179 qreal _dragThreshold;
180 QList<QObject*> _touchPoints;
183 class Q_AUTOTEST_EXPORT QQuickMultiPointTouchArea : public QQuickItem
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)
192 QQuickMultiPointTouchArea(QQuickItem *parent=0);
193 ~QQuickMultiPointTouchArea();
195 int minimumTouchPoints() const;
196 void setMinimumTouchPoints(int num);
197 int maximumTouchPoints() const;
198 void setMaximumTouchPoints(int num);
200 QDeclarativeListProperty<QQuickTouchPoint> touchPoints() {
201 return QDeclarativeListProperty<QQuickTouchPoint>(this, 0, QQuickMultiPointTouchArea::touchPoint_append, QQuickMultiPointTouchArea::touchPoint_count, QQuickMultiPointTouchArea::touchPoint_at, 0);
204 static void touchPoint_append(QDeclarativeListProperty<QQuickTouchPoint> *list, QQuickTouchPoint* touch) {
205 QQuickMultiPointTouchArea *q = static_cast<QQuickMultiPointTouchArea*>(list->object);
206 q->addTouchPrototype(touch);
209 static int touchPoint_count(QDeclarativeListProperty<QQuickTouchPoint> *list) {
210 QQuickMultiPointTouchArea *q = static_cast<QQuickMultiPointTouchArea*>(list->object);
211 return q->_touchPrototypes.count();
214 static QQuickTouchPoint* touchPoint_at(QDeclarativeListProperty<QQuickTouchPoint> *list, int index) {
215 QQuickMultiPointTouchArea *q = static_cast<QQuickMultiPointTouchArea*>(list->object);
216 return q->_touchPrototypes[index];
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();
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);
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);
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;
269 QML_DECLARE_TYPE(QQuickTouchPoint)
270 QML_DECLARE_TYPE(QQuickGrabGestureEvent)
271 QML_DECLARE_TYPE(QQuickMultiPointTouchArea)
275 #endif // QQUICKMULTIPOINTTOUCHAREA_H