-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.qml
131 lines (114 loc) · 3.88 KB
/
main.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
129
130
131
import QtQuick 2.9
import QtQuick.Window 2.2
import myquickitem 1.0
Window {
id: window
visible: true
width: 640
height: 480
title: qsTr("Hello World")
MyQuickItem {
id: item
width: window.width
height: window.height
MultiPointTouchArea {
id: mptArea
signal twoFingersPressed()
anchors.fill: parent
mouseEnabled: false
minimumTouchPoints: 2
maximumTouchPoints: 2
touchPoints: [
TouchPoint {
id: tp1
},
TouchPoint {
id: tp2
}
]
onPressed: mptTimer.start()
Timer {
id: mptTimer
interval: 100
onTriggered: if (!pinchArea.pinching) mptArea.twoFingersPressed()
}
PinchArea {
id: pinchArea
property bool pinching
anchors.fill: parent
onPinchStarted: pinching = true
onPinchFinished: pinching = false
MouseArea {
id: mouseArea
anchors.fill: parent
}
MouseArea {
id: swipeArea
anchors.fill: parent
property real prevX: 0
property real velocityX: 0.0
property int startX: 0
property bool tracing: false
property bool swipedLeft: false
property bool swipedRight: false
signal swipeLeft()
signal swipeRight()
propagateComposedEvents: true
onPressed: {
startX = mouse.x
prevX = mouse.x
velocityX = 0
tracing = true
}
onClicked: {
mouse.accepted = swipedLeft || swipedRight
swipedLeft = swipedRight = false
}
onPositionChanged: {
if ( !tracing ) return
var currVelX = (mouse.x-prevX)
velocityX = (velocityX + currVelX)/2.0;
prevX = mouse.x
if ( velocityX > 10 && mouse.x > width * 0.25 ) {
tracing = false
swipeRight()
swipedRight = true
} else if ( velocityX < -10 && mouse.x < width * 0.75 ) {
tracing = false
swipeLeft()
swipedLeft = true
}
}
}
}
}
}
Text {
id: textBox
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
Connections {
target: mouseArea
onClicked: {print("touch");textBox.text = "touch";timer.start()}
onPressAndHold: {print("long touch");textBox.text = "long touch";timer.start()}
}
Connections {
target: swipeArea
onSwipeLeft: {print("swipe left");textBox.text = "swipe left";timer.start()}
onSwipeRight: {print("swipe right");textBox.text = "swipe right";timer.start()}
}
Connections {
target: pinchArea
onPinchStarted: {print("pinch");textBox.text = "pinch";timer.start()}
}
Connections {
target: mptArea
onTwoFingersPressed: {print("two-finger touch");textBox.text = "two-finger touch";timer.start()}
}
Timer {
id: timer
interval: 1000
onTriggered: textBox.text = ""
}
}
}