Changeset View
Changeset View
Standalone View
Standalone View
source/qml/lib/Touch.qml
- This file was copied from source/qml/lib/Mouse.qml.
Show All 18 Lines | |||||
19 | 19 | | |||
20 | import QtQuick 2.2 | 20 | import QtQuick 2.2 | ||
21 | import org.kde.kirigami 2.4 as Kirigami | 21 | import org.kde.kirigami 2.4 as Kirigami | ||
22 | 22 | | |||
23 | // Drawing a brace between to obejcts to show the distance between them | 23 | // Drawing a brace between to obejcts to show the distance between them | ||
24 | Item { | 24 | Item { | ||
25 | id: canvas | 25 | id: canvas | ||
26 | anchors.fill: parent; | 26 | anchors.fill: parent; | ||
27 | property int px | 27 | property int fromX | ||
28 | property int py | 28 | property int fromY | ||
29 | property int toX | ||||
30 | property int toY | ||||
31 | property int dur: 600 | ||||
29 | 32 | | |||
30 | Rectangle { | 33 | Rectangle { | ||
31 | id: ind | 34 | id: ind | ||
32 | x: cursor.x - width / 2 | | |||
33 | y: cursor.y - width / 2 + 5 | | |||
34 | z: 1 | 35 | z: 1 | ||
35 | width: Kirigami.Units.iconSizes.small | 36 | width: height | ||
36 | height: width | 37 | height: Kirigami.Units.iconSizes.smallMedium | ||
37 | color: "#9911d116" | 38 | color: "#331d99f3" | ||
38 | radius: width / 2 | 39 | radius: height / 2 | ||
39 | visible: false | 40 | visible: false | ||
41 | x: cursor.x | ||||
40 | 42 | | |||
41 | NumberAnimation on width { | 43 | NumberAnimation on width { | ||
42 | id: indAnim | 44 | id: indAnim | ||
43 | duration: 300 | 45 | duration: dur | ||
44 | running: false | 46 | running: false | ||
45 | | ||||
46 | onStopped: { | | |||
47 | ind.visible = false; | | |||
48 | if (qmlControler) { | | |||
49 | qmlControler.click(px, py); | | |||
50 | } | | |||
51 | else { | | |||
52 | console.error("Can't find qmlControler."); | | |||
53 | } | | |||
54 | | ||||
55 | } | | |||
56 | } | 47 | } | ||
57 | } | 48 | } | ||
58 | 49 | | |||
59 | Image { | 50 | Image { | ||
60 | id: cursor | 51 | id: cursor | ||
61 | source: "../../img/left_ptr.png" | 52 | source: "../../img/transform-browse.svg" | ||
62 | visible: false | 53 | visible: false | ||
63 | width: Kirigami.Units.iconSizes.smallMedium | 54 | width: Kirigami.Units.iconSizes.smallMedium | ||
64 | height: Kirigami.Units.iconSizes.smallMedium | 55 | height: Kirigami.Units.iconSizes.smallMedium | ||
65 | z: 2 | 56 | z: 2 | ||
66 | 57 | | |||
67 | NumberAnimation on x { | 58 | NumberAnimation on x { | ||
68 | id: xAnim | 59 | id: xAnim | ||
69 | duration: 1000 | 60 | duration: dur | ||
70 | running: false | 61 | running: false | ||
71 | } | 62 | } | ||
72 | NumberAnimation on y { | 63 | NumberAnimation on y { | ||
73 | id: yAnim | 64 | id: yAnim | ||
74 | running: false | 65 | running: false | ||
75 | duration: 1000 | 66 | duration: dur | ||
76 | onStopped: { | 67 | onStopped: { | ||
77 | ind.visible = true; | 68 | timer.start() | ||
78 | indAnim.to = Kirigami.Units.iconSizes.smallMedium; | | |||
79 | indAnim.start(); | | |||
80 | } | 69 | } | ||
81 | } | 70 | } | ||
82 | } | 71 | } | ||
83 | 72 | | |||
73 | Timer { | ||||
74 | id: timer | ||||
75 | interval: 1000 | ||||
76 | repeat: false | ||||
77 | running: false | ||||
78 | onTriggered: { | ||||
79 | ind.visible = false; | ||||
80 | cursor.visible = false; | ||||
81 | } | ||||
82 | } | ||||
84 | 83 | | |||
85 | // Animate mouse to x/y and then click | 84 | // Animate swipe | ||
86 | function click() { | 85 | function swipe() { | ||
87 | cursor.x = px - 60; | 86 | cursor.x = fromX - Kirigami.Units.iconSizes.smallMedium; | ||
88 | cursor.y = py + 60; | 87 | cursor.y = fromY; | ||
89 | cursor.visible = true; | 88 | cursor.visible = true; | ||
90 | 89 | | |||
91 | xAnim.to = px; | 90 | ind.y = fromY; | ||
91 | ind.visible = true; | ||||
92 | | ||||
93 | xAnim.to = toX; | ||||
92 | xAnim.start(); | 94 | xAnim.start(); | ||
93 | yAnim.to = py; | 95 | yAnim.to = toY; | ||
94 | yAnim.start(); | 96 | yAnim.start(); | ||
97 | indAnim.to = Math.abs(fromX - toX); | ||||
98 | indAnim.start(); | ||||
99 | | ||||
100 | qmlControler.swipe(fromX, fromY, toX, toY); | ||||
95 | } | 101 | } | ||
96 | } | 102 | } |