1 /****************************************************************************
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QML Touch Area plugin of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
43 #ifndef QDECLARATIVETOUCHAREA_H
44 #define QDECLARATIVETOUCHAREA_H
46 #include "qdeclarativeitem.h"
51 #include <QDeclarativeScriptString>
53 class QDeclarativeTouchPoint : public QObject {
55 Q_PROPERTY(int id READ id)
56 Q_PROPERTY(qreal x READ x NOTIFY xChanged)
57 Q_PROPERTY(qreal y READ y NOTIFY yChanged)
58 Q_PROPERTY(qreal sceneX READ sceneX NOTIFY sceneXChanged)
59 Q_PROPERTY(qreal sceneY READ sceneY NOTIFY sceneYChanged)
60 Q_PROPERTY(bool valid READ isValid NOTIFY validityChanged)
62 QDeclarativeTouchPoint(bool qmlReference = true)
68 _qmlReferenced(qmlReference),
72 int id() const { return _id; }
73 void setId(int id) { _id = id; }
75 qreal x() const { return _x; }
81 qreal y() const { return _y; }
87 qreal sceneX() const { return _sceneX; }
88 void setSceneX(qreal sceneX) {
90 emit(sceneXChanged());
93 qreal sceneY() const { return _sceneY; }
94 void setSceneY(qreal sceneY) {
96 emit(sceneYChanged());
99 bool isQmlReferenced() { return _qmlReferenced; }
101 bool isValid() { return _valid; }
102 void setValid(bool valid) {
104 emit(validityChanged());
110 void sceneXChanged();
111 void sceneYChanged();
112 void validityChanged();
126 class QDeclarativeTouchArea : public QDeclarativeItem
130 Q_PROPERTY(QList<QObject*> touches READ touches)
131 Q_PROPERTY(QList<QObject*> changedTouches READ changedTouches)
132 Q_PROPERTY(QList<QObject*> releasedTouches READ releasedTouches)
134 Q_PROPERTY(QDeclarativeListProperty<QDeclarativeTouchPoint> touchPoints READ touchPoints NOTIFY touchPointsChanged)
135 Q_PROPERTY(int minimumTouches READ minimumTouches WRITE setMinimumTouches)
136 Q_PROPERTY(int maximumTouches READ maximumTouches WRITE setMaximumTouches)
137 Q_PROPERTY(qreal scaleFactor READ scaleFactor NOTIFY scaleFactorChanged)
138 Q_PROPERTY(qreal rotationAngle READ rotationAngle NOTIFY rotationAngleChanged)
139 Q_PROPERTY(QDeclarativeScriptString keepMouseFocus READ keepMouseFocus WRITE setKeepMouseFocus)
142 static void registerQML();
144 QDeclarativeTouchArea(QDeclarativeItem *parent=0);
145 ~QDeclarativeTouchArea();
147 int minimumTouches() const { return _minimumTouches; }
148 void setMinimumTouches(int num) { _minimumTouches = num; }
149 int maximumTouches() const { return _maximumTouches; }
150 void setMaximumTouches(int num) { _maximumTouches = num; }
152 qreal scaleFactor() const { return _scaleFactor; }
153 qreal rotationAngle() const { return _rotationAngle; }
155 QDeclarativeScriptString keepMouseFocus() const { return _keepMouseFocus; }
156 void setKeepMouseFocus(const QDeclarativeScriptString &keep) { _keepMouseFocus = keep; }
158 QList<QObject*> touches() { return _touches.values(); }
159 QList<QObject*> changedTouches() { return _changedTouches.values(); }
160 QList<QObject*> releasedTouches() { return _releasedTouches; }
162 QDeclarativeListProperty<QDeclarativeTouchPoint> touchPoints() {
163 return QDeclarativeListProperty<QDeclarativeTouchPoint>(this, 0, QDeclarativeTouchArea::touchPoint_append, QDeclarativeTouchArea::touchPoint_count, QDeclarativeTouchArea::touchPoint_at, 0);
166 static void touchPoint_append(QDeclarativeListProperty<QDeclarativeTouchPoint> *list, QDeclarativeTouchPoint* touch) {
167 QDeclarativeTouchArea *q = static_cast<QDeclarativeTouchArea*>(list->object);
168 q->addTouchPrototype(touch);
171 static int touchPoint_count(QDeclarativeListProperty<QDeclarativeTouchPoint> *list) {
172 QDeclarativeTouchArea *q = static_cast<QDeclarativeTouchArea*>(list->object);
173 return q->_touchPrototypes.count();
176 static QDeclarativeTouchPoint* touchPoint_at(QDeclarativeListProperty<QDeclarativeTouchPoint> *list, int index) {
177 QDeclarativeTouchArea *q = static_cast<QDeclarativeTouchArea*>(list->object);
178 return static_cast<QDeclarativeTouchPoint*>(q->_touchPrototypes[index]);
186 void touchPointsChanged();
187 void scaleFactorChanged();
188 void rotationAngleChanged();
191 bool sceneEvent(QEvent *);
192 void updateTouchPoint(QDeclarativeTouchPoint*, const QTouchEvent::TouchPoint*);
193 void updatePinch(QList<QTouchEvent::TouchPoint> *touchPoints);
194 void addTouchPrototype(QDeclarativeTouchPoint* prototype);
195 void addTouchPoint(const QTouchEvent::TouchPoint *p);
196 void clearChangedAndReleasedTouches();
197 void updateTopTouchArea();
198 void updateTouchData(QEvent*);
199 bool event(QEvent *event);
200 bool sceneEventFilter(QGraphicsItem *i, QEvent *event);
203 QMap<int,QObject*> _touchPrototypes;
204 QMap<int,QObject*> _touches;
205 QMap<int,QObject*> _changedTouches;
206 QList<QObject*> _releasedTouches;
210 qreal _rotationAngle;
211 QDeclarativeTouchArea* _parentTouchArea;
214 QDeclarativeScriptString _keepMouseFocus;
218 QML_DECLARE_TYPE(QDeclarativeTouchPoint)
220 #endif // QDECLARATIVETOUCHAREA_H