-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMutitouchDispatcher.qml
128 lines (110 loc) · 2.6 KB
/
MutitouchDispatcher.qml
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
118
119
120
121
122
123
124
125
126
127
128
import QtQuick 2.7
import "Private"
import "."
MultiPointTouchArea {
id: touch
anchors.fill: target
mouseEnabled: false
property Item target: parent
// enable for faster response but stick and drag while moving
property bool stickAndDrag: !mouseEnabled
// perform drag on each point (multidrag)
property bool simulateDrag: false
// less drag event
property bool accumulateDrag: simulateDrag
// show ripple helper on touch event
property bool touchVisualize: false
QtObject {
id: d
// property bool accumulateDrag: touch.accumulateDrag && touch.simulateDrag
property var prevPoints: ({})
}
TouchVisualRipple {
id: ripple
}
InputEventDefer {
id: defer
pauseInput: !stickAndDrag
}
onPressed: {
for (var i in touchPoints) {
var p = touchPoints[i];
if (touchVisualize)
ripple.create(p.x, p.y, parent, "lime");
if (accumulateDrag)
d.prevPoints[p.pointId] = {x:p.x,y:p.y};
defer.push({
x:p.x, y:p.y,
action: function(){
target.focus = true;
InputEventSource.mousePress(target,
this.x, this.y,
Qt.LeftButton, Qt.NoModifier, -1
);
}
})
}
defer.start();
}
onReleased: {
for (var i in touchPoints) {
var p = touchPoints[i];
if (touchVisualize)
ripple.create(p.x, p.y, parent, "slateblue");
if (accumulateDrag)
delete d.prevPoints[p.pointId];
defer.push({
x:p.x, y:p.y,
action: function(){
target.focus = true;
InputEventSource.mouseRelease(target,
this.x, this.y,
Qt.LeftButton, Qt.NoModifier, -1
);
}
})
}
defer.start();
}
onUpdated: {
for (var i in touchPoints) {
var p = touchPoints[i];
var sx = p.previousX, sy = p.previousY;
if (accumulateDrag) {
var dx = p.x-d.prevPoints[p.pointId].x;
var dy = p.y-d.prevPoints[p.pointId].y;
if (dx*dx+dy*dy<InputEventSource.threshold2)
continue;
sx = d.prevPoints[p.pointId].x;
sy = d.prevPoints[p.pointId].y;
d.prevPoints[p.pointId] = {x:p.x,y:p.y};
}
if (touchVisualize) // only draw with event
ripple.create(p.x, p.y, parent, "teal");
defer.push(simulateDrag?
{
x:p.x, y:p.y, px: sx, py: sy,
action: function(){
target.focus = true;
InputEventSource.mouseDrag(target,
this.px, this.py, this.x, this.y,
Qt.LeftButton, Qt.NoModifier, -1
);
}
}:{
x:p.x, y:p.y,
action: function(){
target.focus = true;
InputEventSource.mouseMove(target,
this.x, this.y, -1, Qt.LeftButton
);
}
}
)
}
defer.start();
}
// onCanceled: {
// }
// TODO: add two finger to wheel convertion
}