17 #ifndef TOUCHGESTUREAREA_H 18 #define TOUCHGESTUREAREA_H 20 #include "UbuntuGesturesQmlGlobal.h" 24 #include <UbuntuGestures/Timer> 26 class TouchOwnershipEvent;
27 class UnownedTouchEvent;
29 class GestureTouchPoint :
public QObject
32 Q_PROPERTY(
int id READ
id NOTIFY idChanged)
33 Q_PROPERTY(
bool pressed READ pressed NOTIFY pressedChanged)
34 Q_PROPERTY(qreal x READ x NOTIFY xChanged)
35 Q_PROPERTY(qreal y READ y NOTIFY yChanged)
36 Q_PROPERTY(
bool dragging READ dragging NOTIFY draggingChanged)
47 GestureTouchPoint(
const GestureTouchPoint& other)
53 int id()
const {
return m_id; }
56 bool pressed()
const {
return m_pressed; }
57 void setPressed(
bool pressed);
59 qreal x()
const {
return m_x; }
62 qreal y()
const {
return m_y; }
65 bool dragging()
const {
return m_dragging; }
66 void setDragging(
bool dragging);
68 GestureTouchPoint& operator=(
const GestureTouchPoint& rhs) {
69 if (&rhs ==
this)
return *
this;
71 m_pressed = rhs.m_pressed;
74 m_dragging = rhs.m_dragging;
78 bool operator=(
const GestureTouchPoint& rhs)
const {
79 if (&rhs ==
this)
return true;
80 return m_id == rhs.m_id &&
81 m_pressed == rhs.m_pressed &&
84 m_dragging == rhs.m_dragging;
86 bool operator!=(
const GestureTouchPoint& rhs)
const {
return !operator=(rhs); }
88 void setPos(
const QPointF &pos);
92 void pressedChanged();
95 void draggingChanged();
113 class UBUNTUGESTURESQML_EXPORT TouchGestureArea :
public QQuickItem
118 Q_PROPERTY(
int status READ status NOTIFY statusChanged)
119 Q_PROPERTY(
bool dragging READ dragging NOTIFY draggingChanged)
120 Q_PROPERTY(QQmlListProperty<GestureTouchPoint> touchPoints READ touchPoints NOTIFY touchPointsUpdated)
122 Q_PROPERTY(
int minimumTouchPoints READ minimumTouchPoints WRITE setMinimumTouchPoints NOTIFY minimumTouchPointsChanged)
123 Q_PROPERTY(
int maximumTouchPoints READ maximumTouchPoints WRITE setMaximumTouchPoints NOTIFY maximumTouchPointsChanged)
126 Q_PROPERTY(
int recognitionPeriod READ recognitionPeriod WRITE setRecognitionPeriod NOTIFY recognitionPeriodChanged)
129 Q_PROPERTY(
int releaseRejectPeriod READ releaseRejectPeriod WRITE setReleaseRejectPeriod NOTIFY releaseRejectPeriodChanged)
139 TouchGestureArea(QQuickItem* parent = NULL);
142 bool event(QEvent *e)
override;
144 void setRecognitionTimer(UbuntuGestures::AbstractTimer *timer);
147 bool dragging()
const;
148 QQmlListProperty<GestureTouchPoint> touchPoints();
150 int minimumTouchPoints()
const;
151 void setMinimumTouchPoints(
int value);
153 int maximumTouchPoints()
const;
154 void setMaximumTouchPoints(
int value);
156 int recognitionPeriod()
const;
157 void setRecognitionPeriod(
int value);
159 int releaseRejectPeriod()
const;
160 void setReleaseRejectPeriod(
int value);
163 void statusChanged(
int status);
165 void touchPointsUpdated();
166 void draggingChanged(
bool dragging);
167 void minimumTouchPointsChanged(
bool value);
168 void maximumTouchPointsChanged(
bool value);
169 void recognitionPeriodChanged(
bool value);
170 void releaseRejectPeriodChanged(
bool value);
172 void pressed(
const QList<QObject*>& points);
173 void released(
const QList<QObject*>& points);
174 void updated(
const QList<QObject*>& points);
178 void itemChange(ItemChange change,
const ItemChangeData &value)
override;
181 void rejectGesture();
184 void touchEvent(QTouchEvent *event)
override;
185 void touchEvent_waitingForTouch(QTouchEvent *event);
186 void touchEvent_waitingForMoreTouches(QTouchEvent *event);
187 void touchEvent_waitingForOwnership(QTouchEvent *event);
188 void touchEvent_recognized(QTouchEvent *event);
189 void touchEvent_rejected(QTouchEvent *event);
191 void unownedTouchEvent(QTouchEvent *unownedTouchEvent);
192 void unownedTouchEvent_waitingForMoreTouches(QTouchEvent *unownedTouchEvent);
193 void unownedTouchEvent_waitingForOwnership(QTouchEvent *unownedTouchEvent);
194 void unownedTouchEvent_recognised(QTouchEvent *unownedTouchEvent);
195 void unownedTouchEvent_rejected(QTouchEvent *unownedTouchEvent);
197 void touchOwnershipEvent(TouchOwnershipEvent *event);
198 void updateTouchPoints(QTouchEvent *event);
200 GestureTouchPoint* addTouchPoint(
const QTouchEvent::TouchPoint *tp);
201 void clearTouchLists();
202 void setDragging(
bool dragging);
203 void setInternalStatus(uint status);
204 void resyncCachedTouchPoints();
206 static int touchPoint_count(QQmlListProperty<GestureTouchPoint> *list);
207 static GestureTouchPoint* touchPoint_at(QQmlListProperty<GestureTouchPoint> *list,
int index);
210 QSet<int> m_candidateTouches;
211 QSet<int> m_watchedTouches;
212 UbuntuGestures::AbstractTimer *m_recognitionTimer;
215 QHash<int, GestureTouchPoint*> m_liveTouchPoints;
216 QHash<int, GestureTouchPoint*> m_cachedTouchPoints;
217 QList<QObject*> m_releasedTouchPoints;
218 QList<QObject*> m_pressedTouchPoints;
219 QList<QObject*> m_movedTouchPoints;
220 int m_minimumTouchPoints;
221 int m_maximumTouchPoints;
222 int m_recognitionPeriod;
223 int m_releaseRejectPeriod;
226 QML_DECLARE_TYPE(GestureTouchPoint)
228 #endif // TOUCHGESTUREAREA_H