blob: 0ebaf574f9368f36e3d1e6207d908df11ab73340 (
plain)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
import Qt 4.7
import Qt.labs.gestures 1.0
Item{
id: button
property string text : "Press me, Hold me, Strike me"
property int counter : 0
property string bgColor: "steelblue"
property bool enabled : state != "disabled"
width:labelText.width+20
anchors.right: parent.right
anchors.left: parent.left
height: parent.height/3-1
Rectangle {
id: background
anchors.fill: parent
radius: 3
color: parent.bgColor
border.color: '#ffffffff'
opacity:0.7
border.width: 1
anchors.margins: 2
}
Rectangle {
id: mark
anchors.verticalCenter: button.verticalCenter
x: 10
width: button.height/2
height: button.height/2
radius: button.height/2
color: "black"
opacity: 0.7
smooth: true
visible: false
}
function toggleMark() {
if (mark.visible == false)
mark.visible = true
else
mark.visible = false
}
function increaseCounter() {
counter = counter + 1
}
Text {
id: labelText
text: parent.text + (counter ? " "+counter : "")
anchors.centerIn: parent
font.pointSize: 15
}
Rectangle {
id: stroke
x: parent.width * 0.3 / 2
anchors.verticalCenter: parent.verticalCenter
width: 0
height : 10
color: "green"
opacity: 1.0
}
states: [
State {
name: ""
PropertyChanges { target: background; opacity: 0.7 }
PropertyChanges { target: stroke; width: 0 }
},
State {
name: "pressed"
PropertyChanges { target: background; opacity: 1.0 }
},
State {
name: "disabled"
PropertyChanges { target: background; opacity: 0.3 }
PropertyChanges { target: mark; opacity: 0.3 }
PropertyChanges { target: stroke; width: stroke.parent.width * 0.7 }
}
]
transitions: [
Transition {
from: "*"
to: "disabled"
PropertyAnimation { target: stroke; duration: 1000; property: "width" }
},
Transition {
from: "disabled"
to: ""
PropertyAnimation { target: stroke; duration: 1000; property: "width" }
}
]
property bool handled: false
function isHorizontalSwipe(angle) {
if (angle > 150 && angle < 210)
return true;
if (angle > 330 || angle < 30)
return true;
return false;
}
GestureArea {
anchors.fill: parent
Tap {
when: button.enabled
onStarted: { button.state = "pressed" }
onCanceled: {
if (!button.handled) {
button.state = "";
}
}
onFinished: {
if (!button.handled) {
button.state = "";
button.increaseCounter();
}
button.handled = false;
}
}
TapAndHold {
when: button.enabled
onFinished: { console.log("tap-and-hold"); button.toggleMark() }
}
Swipe {
// when: gesture.speed > 25
onStarted: button.handled = true
onFinished: {
if (isHorizontalSwipe(gesture.swipeAngle)) {
if (gesture.horizontalDirection == SwipeGesture.Right) {
button.state = "disabled"
} else if (gesture.horizontalDirection == SwipeGesture.Left) {
button.state = ""
}
}
button.handled = false
}
}
}
}
|