Changeset View
Changeset View
Standalone View
Standalone View
source/qml/lib/Mouse.qml
Show All 12 Lines | |||||
13 | * | 13 | * | ||
14 | * You should have received a copy of the GNU Library General Public | 14 | * You should have received a copy of the GNU Library General Public | ||
15 | * License along with this program; if not, write to the | 15 | * License along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | 16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | import QtQuick 2.2 | 20 | import QtQuick 2.2 | ||
21 | import QtTest 1.2 | ||||
21 | import org.kde.kirigami 2.4 as Kirigami | 22 | import org.kde.kirigami 2.4 as Kirigami | ||
22 | 23 | | |||
23 | // Drawing a brace between to obejcts to show the distance between them | 24 | // Drawing a brace between to obejcts to show the distance between them | ||
24 | Item { | 25 | Item { | ||
25 | id: canvas | 26 | id: canvas | ||
26 | anchors.fill: parent; | 27 | anchors.fill: parent; | ||
27 | property int px | 28 | property int px | ||
28 | property int py | 29 | property int py | ||
30 | z: 2 | ||||
29 | 31 | | |||
30 | Rectangle { | 32 | Rectangle { | ||
31 | id: ind | 33 | id: ind | ||
32 | x: cursor.x - width / 2 | 34 | x: cursor.x - width / 2 | ||
33 | y: cursor.y - width / 2 + 5 | 35 | y: cursor.y - width / 2 + 5 | ||
34 | z: 1 | 36 | z: 2 | ||
35 | width: Kirigami.Units.iconSizes.small | 37 | width: Kirigami.Units.iconSizes.medium | ||
36 | height: width | 38 | height: width | ||
37 | color: "#9911d116" | 39 | color: "#9911d116" | ||
38 | radius: width / 2 | 40 | radius: width / 2 | ||
39 | visible: false | 41 | visible: false | ||
40 | 42 | | |||
41 | NumberAnimation on width { | 43 | NumberAnimation on width { | ||
42 | id: indAnim | 44 | id: indAnim | ||
43 | duration: 300 | 45 | duration: 300 | ||
44 | running: false | 46 | running: false | ||
45 | 47 | | |||
46 | onStopped: { | 48 | onStopped: { | ||
47 | ind.visible = false; | 49 | ind.visible = false; | ||
48 | if (qmlControler) { | 50 | event.mouseClick(canvas.parent, px, py, Qt.LeftButton, Qt.NoModifier, 0) | ||
49 | qmlControler.click(px, py); | | |||
50 | } | | |||
51 | else { | | |||
52 | console.error("Can't find qmlControler."); | | |||
53 | } | 51 | } | ||
54 | | ||||
55 | } | 52 | } | ||
56 | } | 53 | } | ||
54 | | ||||
55 | TestEvent { | ||||
56 | id: event | ||||
57 | } | 57 | } | ||
58 | 58 | | |||
59 | | ||||
59 | Image { | 60 | Image { | ||
60 | id: cursor | 61 | id: cursor | ||
61 | source: "../../img/left_ptr.png" | 62 | source: "../../img/left_ptr.png" | ||
62 | visible: false | 63 | visible: false | ||
63 | width: Kirigami.Units.iconSizes.smallMedium | 64 | width: Kirigami.Units.iconSizes.medium | ||
64 | height: Kirigami.Units.iconSizes.smallMedium | 65 | height: Kirigami.Units.iconSizes.medium | ||
65 | z: 2 | 66 | z: 3 | ||
66 | 67 | | |||
67 | NumberAnimation on x { | 68 | ParallelAnimation { | ||
68 | id: xAnim | | |||
69 | duration: 1000 | | |||
70 | running: false | 69 | running: false | ||
70 | id: cursorAnimation | ||||
71 | NumberAnimation { | ||||
72 | id: cursorAnimationX | ||||
73 | target: cursor | ||||
74 | property: "x" | ||||
75 | duration: 1000 | ||||
71 | } | 76 | } | ||
72 | NumberAnimation on y { | 77 | NumberAnimation { | ||
73 | id: yAnim | 78 | id: cursorAnimationY | ||
74 | running: false | 79 | target: cursor | ||
80 | property: "y" | ||||
75 | duration: 1000 | 81 | duration: 1000 | ||
76 | onStopped: { | | |||
77 | ind.visible = true; | | |||
78 | indAnim.to = Kirigami.Units.iconSizes.smallMedium; | | |||
79 | indAnim.start(); | | |||
80 | } | 82 | } | ||
81 | } | 83 | } | ||
82 | } | 84 | } | ||
83 | 85 | | |||
84 | 86 | | |||
85 | // Animate mouse to x/y and then click | 87 | // Animate mouse to x/y and then click | ||
86 | function click() { | 88 | function click() { | ||
87 | cursor.x = px - 60; | 89 | cursor.x = px - 60; | ||
88 | cursor.y = py + 60; | 90 | cursor.y = py + 60; | ||
89 | cursor.visible = true; | 91 | cursor.visible = true; | ||
90 | 92 | | |||
91 | xAnim.to = px; | 93 | cursorAnimation.onStopped.connect(function() { | ||
92 | xAnim.start(); | 94 | ind.visible = true; | ||
93 | yAnim.to = py; | 95 | indAnim.to = Kirigami.Units.iconSizes.smallMedium; | ||
94 | yAnim.start(); | 96 | indAnim.start(); | ||
97 | }); | ||||
98 | | ||||
99 | cursorAnimationX.to = px; | ||||
100 | cursorAnimationY.to = py; | ||||
101 | cursorAnimation.start(); | ||||
95 | } | 102 | } | ||
96 | 103 | | |||
97 | function hover() { | 104 | function hover() { | ||
98 | cursor.x = px; | 105 | cursor.x = px - 60; | ||
99 | cursor.y = py; | 106 | cursor.y = py + 60; | ||
100 | cursor.visible = true; | 107 | cursor.visible = true; | ||
101 | if (qmlControler) { | 108 | | ||
102 | qmlControler.hover(px, py); | 109 | cursorAnimation.onStopped.connect(function() { | ||
103 | } | 110 | event.mouseMove(canvas.parent, px, py, 0, Qt.NoButton); | ||
104 | else { | 111 | }); | ||
105 | console.error("Can't find qmlControler."); | 112 | | ||
106 | } | 113 | cursorAnimationX.to = px; | ||
114 | cursorAnimationY.to = py; | ||||
115 | cursorAnimation.start(); | ||||
107 | } | 116 | } | ||
108 | } | 117 | } |