17#ifndef TOUCHGESTUREAREA_H
18#define TOUCHGESTUREAREA_H
20#include "LomiriGesturesQmlGlobal.h"
24#include <LomiriGestures/lomirigesturesglobal.h>
25#include <LomiriGestures/private/timer_p.h>
27UG_FORWARD_DECLARE_CLASS(TouchOwnershipEvent)
28UG_FORWARD_DECLARE_CLASS(UnownedTouchEvent)
30class GestureTouchPoint :
public QObject
33 Q_PROPERTY(
int id READ
id NOTIFY idChanged)
34 Q_PROPERTY(
bool pressed READ pressed NOTIFY pressedChanged)
35 Q_PROPERTY(qreal x READ x NOTIFY xChanged)
36 Q_PROPERTY(qreal y READ y NOTIFY yChanged)
37 Q_PROPERTY(
bool dragging READ dragging NOTIFY draggingChanged)
48 GestureTouchPoint(
const GestureTouchPoint& other)
54 int id()
const {
return m_id; }
57 bool pressed()
const {
return m_pressed; }
58 void setPressed(
bool pressed);
60 qreal x()
const {
return m_x; }
63 qreal y()
const {
return m_y; }
66 bool dragging()
const {
return m_dragging; }
67 void setDragging(
bool dragging);
69 GestureTouchPoint& operator=(
const GestureTouchPoint& rhs) {
70 if (&rhs ==
this)
return *
this;
72 m_pressed = rhs.m_pressed;
75 m_dragging = rhs.m_dragging;
79 bool operator==(
const GestureTouchPoint& rhs)
const {
80 if (&rhs ==
this)
return true;
81 return m_id == rhs.m_id &&
82 m_pressed == rhs.m_pressed &&
85 m_dragging == rhs.m_dragging;
87 bool operator!=(
const GestureTouchPoint& rhs)
const {
return !operator==(rhs); }
89 void setPos(
const QPointF &pos);
93 void pressedChanged();
96 void draggingChanged();
114class LOMIRIGESTURESQML_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)
140 TouchGestureArea(QQuickItem* parent =
nullptr);
143 bool event(QEvent *e)
override;
145 void setRecognitionTimer(UG_PREPEND_NAMESPACE(AbstractTimer) *timer);
148 bool dragging()
const;
149 QQmlListProperty<GestureTouchPoint> touchPoints();
151 int minimumTouchPoints()
const;
152 void setMinimumTouchPoints(
int value);
154 int maximumTouchPoints()
const;
155 void setMaximumTouchPoints(
int value);
157 int recognitionPeriod()
const;
158 void setRecognitionPeriod(
int value);
160 int releaseRejectPeriod()
const;
161 void setReleaseRejectPeriod(
int value);
164 void statusChanged(
int status);
166 void touchPointsUpdated();
167 void draggingChanged(
bool dragging);
168 void minimumTouchPointsChanged(
int value);
169 void maximumTouchPointsChanged(
int value);
170 void recognitionPeriodChanged(
int value);
171 void releaseRejectPeriodChanged(
int value);
173 void pressed(
const QList<QObject*>& points);
174 void released(
const QList<QObject*>& points);
175 void updated(
const QList<QObject*>& points);
179 void itemChange(ItemChange change,
const ItemChangeData &value)
override;
182 void rejectGesture();
185 void touchEvent(QTouchEvent *event)
override;
186 void touchEvent_waitingForTouch(QTouchEvent *event);
187 void touchEvent_waitingForMoreTouches(QTouchEvent *event);
188 void touchEvent_waitingForOwnership(QTouchEvent *event);
189 void touchEvent_recognized(QTouchEvent *event);
190 void touchEvent_rejected(QTouchEvent *event);
192 void unownedTouchEvent(QTouchEvent *unownedTouchEvent);
193 void unownedTouchEvent_waitingForMoreTouches(QTouchEvent *unownedTouchEvent);
194 void unownedTouchEvent_waitingForOwnership(QTouchEvent *unownedTouchEvent);
195 void unownedTouchEvent_recognised(QTouchEvent *unownedTouchEvent);
196 void unownedTouchEvent_rejected(QTouchEvent *unownedTouchEvent);
198 void touchOwnershipEvent(UG_PREPEND_NAMESPACE(TouchOwnershipEvent) *event);
199 void updateTouchPoints(QTouchEvent *event);
201 GestureTouchPoint* addTouchPoint(
const QTouchEvent::TouchPoint *tp);
202 void clearTouchLists();
203 void setDragging(
bool dragging);
204 void setInternalStatus(uint status);
205 void resyncCachedTouchPoints();
207 static int touchPoint_count(QQmlListProperty<GestureTouchPoint> *list);
208 static GestureTouchPoint* touchPoint_at(QQmlListProperty<GestureTouchPoint> *list,
int index);
211 QSet<int> m_candidateTouches;
212 QSet<int> m_watchedTouches;
213 UG_PREPEND_NAMESPACE(AbstractTimer) *m_recognitionTimer;
216 QHash<int, GestureTouchPoint*> m_liveTouchPoints;
217 QHash<int, GestureTouchPoint*> m_cachedTouchPoints;
218 QList<QObject*> m_releasedTouchPoints;
219 QList<QObject*> m_pressedTouchPoints;
220 QList<QObject*> m_movedTouchPoints;
221 int m_minimumTouchPoints;
222 int m_maximumTouchPoints;
223 int m_recognitionPeriod;
224 int m_releaseRejectPeriod;
227QML_DECLARE_TYPE(GestureTouchPoint)