forked from N1coc4colA/DA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtouchinterfacing.h
114 lines (96 loc) · 3.08 KB
/
touchinterfacing.h
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
#ifndef TOUCHINTERFACING_H
#define TOUCHINTERFACING_H
#include "libda_global.h"
#include <QWidget>
#include <QGesture>
#include <math.h>
LDA_BEGIN_NAMESPACE
enum SkipEvents {
SwipeGesture = 0b00000000001,
TapGesture = 0b00000000010,
PinchGesture = 0b00000000100,
PanGesture = 0b00000001000,
MouseMove = 0b00000010000,
MousePress = 0b00000100000,
MouseRelease = 0b00001000000,
MouseAll = 0b00010000000,
GestureAll = 0b00100000000,
Any = 0b01000000000,
Other = 0b10000000000
};
class TouchSystem;
class SwipingGesture;
class LIBDA_SHARED_EXPORT TouchInterfacing
{
public:
explicit TouchInterfacing(QWidget *source, Dtk::Addons::TouchInterfacing *face);
virtual ~TouchInterfacing();
/**
* @brief Send mouse clicks to handleTapGesture directly or trigger the two
* @param enable
*/
void enableEventRedirection(bool enable = false);
/**
* @brief Translate some mouse events into gestures such as swipes
* @param enable
*/
void enableEventTranslation(bool enable = true);
/**
* @brief Disable use of proxy, no call are made to the handlers, they are sent to the target class
* @param disable
*/
void disableHandling(bool disable = true);
/**
* @brief Skip function calculations, such as the ones to calculate the swipe angle and the directions
* @param enable
*/
void enableInternalTasks(bool enable = true);
/**
* @brief Choose the events you won't process, they'll be skiped automatically.
* @param events
*/
void setBlockedEvents(int events);
/**
* @brief Watch over IOD class for events and monitor (and see when error happens)
* @param debug
*/
void enableDebug(bool debug);
int getInterfaceUID();
protected:
virtual bool handleSwipeGesture(SwipingGesture *gesture);
virtual bool handleTapGesture(QTapGesture *gesture);
virtual bool handlePinchGesture(QPinchGesture *gesture);
virtual bool handlePanGesture(QPanGesture *gesture);
virtual bool handleMousePress(QMouseEvent *event);
virtual bool handleMouseRelease(QMouseEvent *event);
virtual bool handleMouseMove(QMouseEvent *event);
virtual bool handleOtherEvents(QEvent *e);
private:
QWidget *source = nullptr;
Dtk::Addons::TouchSystem *m_system = nullptr;
QPoint *pointSource = nullptr;
int skipEvents = 0;
int interface_uid;
bool holding = false;
bool press = false;
bool merge = true;
bool handling = true;
bool split = false;
bool reject = false;
inline static int getInternalID() {
static int internal_identifier = 0;
internal_identifier++;
return internal_identifier;
}
SwipingGesture *m_swipe = nullptr;
friend class TouchSystem;
};
LDA_END_NAMESPACE
inline static qreal generateAngle(QPoint source, QPoint target)
{
QPoint middle(source.x(), target.y());
int mt = target.x() - middle.x(), ms = middle.y() - source.y();
double ts = sqrt(pow(ms, 2)+pow(mt, 2));
return (0-asin(mt/ts));
}
#endif // TOUCHINTERFACING_H