forked from goldendict/goldendict
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgestures.hh
117 lines (91 loc) · 2.5 KB
/
gestures.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#ifndef __GESTURES_HH_INCLUDED__
#define __GESTURES_HH_INCLUDED__
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
#include <QGestureRecognizer>
#include <QGesture>
#include <QTimer>
#include <QEvent>
#include <QAction>
namespace Gestures
{
enum GestureResult
{
NOT_HANLDED,
SWIPE_LEFT,
SWIPE_RIGHT,
SWIPE_UP,
SWIPE_DOWN,
ZOOM_IN,
ZOOM_OUT
};
extern Qt::GestureType GDPinchGestureType;
extern Qt::GestureType GDSwipeGestureType;
void registerRecognizers();
void unregisterRecognizers();
bool isFewTouchPointsPresented();
class GDPinchGestureRecognizer;
class GDPinchGesture : public QGesture
{
public:
GDPinchGesture();
bool isScaleChanged() const
{ return scaleChanged; }
QPointF const & getCenterPoint() const
{ return centerPoint; }
qreal getTotalScaleFactor() const
{ return totalScaleFactor; }
protected:
QPointF startCenterPoint;
QPointF lastCenterPoint;
QPointF centerPoint;
qreal lastScaleFactor;
qreal scaleFactor;
qreal totalScaleFactor;
bool isNewSequence;
QPointF startPosition[ 2 ];
bool scaleChanged;
friend class GDPinchGestureRecognizer;
};
class GDSwipeGestureRecognizer;
class GDSwipeGesture : public QGesture
{
public:
GDSwipeGesture();
QSwipeGesture::SwipeDirection getHorizDirection() const
{ return horizDirection; }
QSwipeGesture::SwipeDirection getVertDirection() const
{ return vertDirection; }
protected:
QSwipeGesture::SwipeDirection vertDirection;
QSwipeGesture::SwipeDirection horizDirection;
QPoint lastPositions[ 2 ];
bool started;
friend class GDSwipeGestureRecognizer;
};
class GDPinchGestureRecognizer : public QGestureRecognizer
{
public:
static const qreal OUT_SCALE_LIMIT;
static const qreal IN_SCALE_LIMIT;
GDPinchGestureRecognizer() {}
private:
virtual QGesture* create( QObject* pTarget );
virtual QGestureRecognizer::Result recognize( QGesture* pGesture, QObject *pWatched, QEvent * pEvent );
void reset( QGesture *pGesture );
};
class GDSwipeGestureRecognizer : public QGestureRecognizer
{
public:
GDSwipeGestureRecognizer(){}
private:
static const int MOVE_X_TRESHOLD = 100;
static const int MOVE_Y_TRESHOLD = 50;
virtual QGesture * create( QObject* pTarget );
virtual QGestureRecognizer::Result recognize( QGesture* pGesture, QObject * pWatched, QEvent * pEvent );
void reset ( QGesture * pGesture );
qreal computeAngle( int dx, int dy );
};
bool handleGestureEvent( QObject * obj, QEvent * event, GestureResult & result, QPoint & point );
} // namespace
#endif
#endif // __GESTURES_HH_INCLUDED__