Changeset View
Changeset View
Standalone View
Standalone View
source/qml/lib/Touch.qml
Show All 24 Lines | |||||
25 | Item { | 25 | Item { | ||
26 | id: canvas | 26 | id: canvas | ||
27 | anchors.fill: parent; | 27 | anchors.fill: parent; | ||
28 | property int fromX | 28 | property int fromX | ||
29 | property int fromY | 29 | property int fromY | ||
30 | property int toX | 30 | property int toX | ||
31 | property int toY | 31 | property int toY | ||
32 | property int dur: 300 | 32 | property int dur: 300 | ||
33 | property var sequence; | ||||
34 | property int i: 0 | ||||
33 | 35 | | |||
34 | Rectangle { | 36 | Rectangle { | ||
35 | id: ind | 37 | id: ind | ||
36 | z: 1 | 38 | z: 1 | ||
37 | width: height | 39 | width: height | ||
38 | height: Kirigami.Units.iconSizes.smallMedium | 40 | height: Kirigami.Units.iconSizes.smallMedium | ||
39 | color: "#331d99f3" | 41 | color: "#331d99f3" | ||
40 | radius: height / 2 | 42 | radius: height / 2 | ||
Show All 37 Lines | |||||
78 | Timer { | 80 | Timer { | ||
79 | id: timer | 81 | id: timer | ||
80 | interval: 300 | 82 | interval: 300 | ||
81 | repeat: false | 83 | repeat: false | ||
82 | running: false | 84 | running: false | ||
83 | onTriggered: { | 85 | onTriggered: { | ||
84 | ind.visible = false; | 86 | ind.visible = false; | ||
85 | cursor.visible = false; | 87 | cursor.visible = false; | ||
88 | swipeTimer.stop(); | ||||
89 | } | ||||
90 | } | ||||
91 | | ||||
92 | Timer { | ||||
93 | id: swipeTimer | ||||
94 | interval: 30 | ||||
95 | repeat: true | ||||
96 | running: false | ||||
97 | onTriggered: { | ||||
98 | i++; | ||||
99 | var stepX = (toX - fromX) / timer.interval * swipeTimer.interval | ||||
100 | var stepY = (toY - fromY) / timer.interval * swipeTimer.interval | ||||
101 | sequence.move(1, canvas, fromX + i * stepX, toY + i * stepY); | ||||
102 | sequence.commit(); | ||||
86 | } | 103 | } | ||
87 | } | 104 | } | ||
88 | 105 | | |||
89 | // Animate swipe | 106 | // Animate swipe | ||
90 | function swipe() { | 107 | function swipe() { | ||
91 | cursor.x = fromX - Kirigami.Units.iconSizes.smallMedium; | 108 | cursor.x = fromX - Kirigami.Units.iconSizes.smallMedium; | ||
92 | cursor.y = fromY; | 109 | cursor.y = fromY; | ||
93 | cursor.visible = true; | 110 | cursor.visible = true; | ||
94 | 111 | | |||
95 | ind.y = fromY; | 112 | ind.y = fromY; | ||
96 | ind.visible = true; | 113 | ind.visible = true; | ||
97 | 114 | | |||
98 | xAnim.to = toX; | 115 | xAnim.to = toX; | ||
99 | xAnim.start(); | 116 | xAnim.start(); | ||
100 | yAnim.to = toY; | 117 | yAnim.to = toY; | ||
101 | yAnim.start(); | 118 | yAnim.start(); | ||
102 | indAnim.to = Math.abs(fromX - toX); | 119 | indAnim.to = Math.abs(fromX - toX); | ||
103 | indAnim.start(); | 120 | indAnim.start(); | ||
104 | 121 | | |||
105 | timer.triggered.connect(function() { | 122 | sequence = event.touchEvent(canvas); | ||
106 | var sequence = event.touchEvent(canvas); | | |||
107 | sequence.press(1, canvas, fromX, fromY); | 123 | sequence.press(1, canvas, fromX, fromY); | ||
108 | sequence.commit(); | 124 | sequence.commit(); | ||
125 | i = 0; | ||||
126 | swipeTimer.start(); | ||||
109 | 127 | | |||
110 | sequence.move(1, canvas, toX, toY); | 128 | timer.triggered.connect(function() { | ||
129 | sequence.release(1, canvas, toX, toY); | ||||
111 | sequence.commit(); | 130 | sequence.commit(); | ||
112 | }); | 131 | }); | ||
113 | } | 132 | } | ||
114 | 133 | | |||
115 | function touch() { | 134 | function touch() { | ||
116 | cursor.x = toX; | 135 | cursor.x = toX; | ||
117 | cursor.y = toY; | 136 | cursor.y = toY; | ||
118 | cursor.visible = true; | 137 | cursor.visible = true; | ||
119 | console.log(toX + " " + toY); | | |||
120 | timer.start() | 138 | timer.start() | ||
121 | timer.triggered.connect(function() { | 139 | timer.triggered.connect(function() { | ||
122 | var sequence = event.touchEvent(canvas); | 140 | sequence = event.touchEvent(canvas); | ||
123 | sequence.press(1, canvas, toX, toY); | 141 | sequence.press(1, canvas, toX, toY); | ||
124 | sequence.commit(); | 142 | sequence.commit(); | ||
125 | sequence.release(1, canvas, toX, toY); | 143 | sequence.release(1, canvas, toX, toY); | ||
126 | sequence.commit(); | 144 | sequence.commit(); | ||
127 | }); | 145 | }); | ||
128 | } | 146 | } | ||
129 | } | 147 | } |