2
* Copyright (C) 2015 Canonical, Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
#ifndef UCSWIPEAREAPRIVATE_H
19
#define UCSWIPEAREAPRIVATE_H
21
#include "ucswipearea.h"
23
// Information about an active touch point
24
struct UBUNTUGESTURESQML_EXPORT ActiveTouchInfo {
25
ActiveTouchInfo() : id(-1), startTime(-1) {}
26
bool isValid() const { return id != -1; }
27
void reset() { id = -1; }
31
class UBUNTUGESTURESQML_EXPORT ActiveTouchesInfo {
33
ActiveTouchesInfo(const UbuntuGestures::SharedTimeSource &timeSource);
34
void update(QTouchEvent *event);
35
qint64 touchStartTime(int id);
36
bool isEmpty() const { return m_touchInfoPool.isEmpty(); }
37
qint64 mostRecentStartTime();
38
UbuntuGestures::SharedTimeSource m_timeSource;
40
void addTouchPoint(int touchId);
41
void removeTouchPoint(int touchId);
44
Pool<ActiveTouchInfo> m_touchInfoPool;
47
class UBUNTUGESTURESQML_EXPORT UCSwipeAreaPrivate : public QObject
53
UCSwipeAreaPrivate(UCSwipeArea *q);
56
void giveUpIfDisabledOrInvisible();
60
// Describes the state of the directional drag gesture.
62
// Waiting for a new touch point to land on this area. No gesture is being processed
66
// A touch point has landed on this area but it's not know yet whether it is
67
// performing a drag in the correct direction.
68
// If it's decided that the touch point is not performing a directional drag gesture,
69
// it will be rejected/ignored and status will return to WaitingForTouch.
70
Undecided, //Recognizing,
72
// There's a touch point in this area and it performed a drag in the correct
75
// Once recognized, the gesture state will move back to WaitingForTouch only once
76
// that touch point ends. The gesture will remain in the Recognized state even if
77
// the touch point starts moving in other directions or halts.
81
void touchEvent_absent(QTouchEvent *event);
82
void touchEvent_undecided(QTouchEvent *event);
83
void touchEvent_recognized(QTouchEvent *event);
84
bool movingInRightDirection() const;
85
bool movedFarEnoughAlongGestureAxis() const;
86
bool isPastMaxDistance() const;
87
const QTouchEvent::TouchPoint *fetchTargetTouchPoint(QTouchEvent *event);
88
void setStatus(Status newStatus);
89
void updatePosition(const QPointF &point);
90
void setPublicScenePos(const QPointF &point);
91
bool isWithinTouchCompositionWindow();
92
void updateSceneDirectionVector();
93
// returns the scalar projection between the given vector (in scene coordinates)
94
// and m_sceneDirectionVector
95
qreal projectOntoDirectionVector(const QPointF &sceneVector) const;
96
void touchOwnershipEvent(TouchOwnershipEvent *event);
97
void unownedTouchEvent(UnownedTouchEvent *event);
98
void unownedTouchEvent_undecided(UnownedTouchEvent *unownedTouchEvent);
99
void watchPressedTouchPoints(const QList<QTouchEvent::TouchPoint> &touchPoints);
100
bool recognitionIsDisabled() const;
101
bool sanityCheckRecognitionProperties();
102
void setMaxTime(int value);
103
void setDistanceThreshold(qreal value);
104
void setPixelsPerMm(qreal pixelsPerMm);
105
QString objectName() const { return q->objectName(); }
107
// Replaces the existing Timer with the given one.
109
// Useful for providing a fake timer when testing.
110
void setRecognitionTimer(UbuntuGestures::AbstractTimer *timer);
112
// Useful for testing, where a fake time source can be supplied
113
void setTimeSource(const UbuntuGestures::SharedTimeSource &timeSource);
115
QPointF startScenePos;
116
// The touch position exposed in the public API.
117
// It only starts to move once the gesture gets recognized.
118
QPointF publicScenePos;
119
// A movement damper is used in some of the gesture recognition calculations
120
// to get rid of noise or small oscillations in the touch position.
121
DampedPointF dampedScenePos;
122
QPointF previousDampedScenePos;
123
// Unit vector in scene coordinates describing the direction of the gesture recognition
124
QPointF sceneDirectionVector;
125
UbuntuGestures::SharedTimeSource timeSource;
126
ActiveTouchesInfo activeTouches;
129
UbuntuGestures::AbstractTimer *recognitionTimer;
131
// How far a touch point has to move from its initial position along the gesture axis in order
132
// for it to be recognized as a directional drag.
133
qreal distanceThreshold;
134
qreal distanceThresholdSquared; // it's pow(distanceThreshold, 2)
135
// Maximum distance the gesture can go without crossing the axis-aligned distance threshold
140
// Maximum time (in milliseconds) the gesture can take to go beyond the distance threshold
142
// Maximum time (in milliseconds) after the start of a given touch point where
143
// subsequent touch starts are grouped with the first one into an N-touches gesture
144
// (e.g. a two-fingers tap or drag).
147
// The current status of the directional drag gesture area.
149
UCSwipeArea::Direction direction;
151
bool immediateRecognition;
154
void statusChanged(Status value);
157
#endif // UCSWIPEAREAPRIVATE_H