-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVirtualMouse.qml
143 lines (140 loc) · 5.17 KB
/
VirtualMouse.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
132
133
134
135
136
137
138
139
140
141
142
143
import QtQuick 2.12
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import QtGraphicalEffects 1.12
Item{
id: virtualMouse
property bool angle: false
width: map.width/15
height: width
Item{
x:-dragPoint2.width/2
y:-dragPoint2.width/2
width: parent.width
opacity: 1
Rectangle{
id:dragPoint2
visible: true
x:0
y:0
width: parent.width
height: width
border.width: width/20
border.color: "steelblue"
rotation: -45
z:-1
radius: height/2
gradient: Gradient {
GradientStop { position: 0.0; color: mouseArea.pressed ? "GhostWhite":"Gainsboro" }
GradientStop { position: 1.0; color: mouseArea.pressed ? "Gainsboro":"GhostWhite" }
}
Rectangle {
property var k: 1.5
id: rectIn2
anchors.horizontalCenter: dragPoint2.horizontalCenter
anchors.verticalCenter: dragPoint2.verticalCenter
width: parent.width/k
height: parent.height/k
radius: parent.radius/k
rotation: 135
z:1
gradient: Gradient {
GradientStop { position: 0.0; color: mouseArea.pressed ? "GhostWhite":"Gainsboro" }
GradientStop { position: 1.0; color: mouseArea.pressed ? "Gainsboro":"GhostWhite" }
}
}
Image{
id:img2
width: rectIn.width
height: rectIn.height
source: angle ? "/res/switch.png" : "/res/drag.png"
anchors.horizontalCenter: dragPoint2.horizontalCenter
anchors.verticalCenter: dragPoint2.verticalCenter
rotation: 45
z:2
fillMode: Image.PreserveAspectFit
}
}
}
Item{
x:-dragPoint.width/2
y:-dragPoint.width/2
opacity: .7
Rectangle{
id:dragPoint
visible: true
property double relativeX: x*Math.cos(displayView.rotation*Math.PI/180.)+y*Math.sin(displayView.rotation*Math.PI/180.)
property double relativeY: y*Math.cos(displayView.rotation*Math.PI/180.)-x*Math.sin(displayView.rotation*Math.PI/180.)
x:0
y:0
width: map.width/15
height: width
border.width: width/20
border.color: "steelblue"
rotation: -45
z:-1
radius: height/2
gradient: Gradient {
GradientStop { position: 0.0; color: mouseArea.pressed ? "GhostWhite":"Gainsboro" }
GradientStop { position: 1.0; color: mouseArea.pressed ? "Gainsboro":"GhostWhite" }
}
Rectangle {
property var k: 1.5
id: rectIn
anchors.horizontalCenter: dragPoint.horizontalCenter
anchors.verticalCenter: dragPoint.verticalCenter
width: parent.width/k
height: parent.height/k
radius: parent.radius/k
rotation: 135
z:1
gradient: Gradient {
GradientStop { position: 0.0; color: mouseArea.pressed ? "GhostWhite":"Gainsboro" }
GradientStop { position: 1.0; color: mouseArea.pressed ? "Gainsboro":"GhostWhite" }
}
}
Image{
id:img
width: rectIn.width
height: rectIn.height
source: angle ? "/res/switch.png" : "/res/drag.png"
anchors.horizontalCenter: dragPoint.horizontalCenter
anchors.verticalCenter: dragPoint.verticalCenter
rotation: 45
z:2
fillMode: Image.PreserveAspectFit
}
MouseArea {
id:mouseArea
anchors.fill: dragPoint
drag.target: dragPoint
drag.axis: Drag.XAndYAxis
onReleased: {
timerUpdate.stop()
dragPoint.x=0
dragPoint.y=0
moving = true
if(!angle)
pubCommand("mouse;"+parseInt(dragPoint.relativeX)+":"+parseInt(dragPoint.relativeY)+":0:0")
else
pubCommand("mouse;0:0:"+parseInt(dragPoint.relativeX)+":"+parseInt(dragPoint.relativeY))
}
onPressed: {
timerUpdate.restart()
}
Timer{
id: timerUpdate
interval: 10
running: false
repeat: true
onTriggered: {
if(!angle)
pubCommand("mouse;"+parseInt(dragPoint.relativeX)+":"+parseInt(dragPoint.relativeY)+":0:0")
else
pubCommand("mouse;0:0:"+parseInt(dragPoint.relativeX)+":"+parseInt(dragPoint.relativeY))
}
}
}
}
}
}