forked from KhoaTranProgrammer/QtQml_Dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpeed.qml
114 lines (99 loc) · 3.47 KB
/
Speed.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
import QtQuick 2.0
Item {
id: id_root
property int value: 0
Rectangle {
id: id_speed
property int numberIndexs: 15
property int startAngle: 234
property int angleLength: 18
property int maxSpeed: 280
anchors.centerIn: parent
height: Math.min(id_root.width, id_root.height)
width: height
radius: width/2
color: "black"
border.color: "light green"
border.width: id_speed.height * 0.02
Canvas {
id:canvas
anchors.fill: parent
contextType: "2d"
rotation: 145
antialiasing: true
onPaint: {
var context = canvas.getContext('2d');
context.strokeStyle = "blue";
context.lineWidth = id_speed.height * 0.05 / 2;
context.beginPath();
context.arc(id_speed.height / 2, id_speed.height / 2, id_speed.height / 2 - id_speed.height * 0.05, 0, Math.PI * 1.1, false);
context.stroke();
context.strokeStyle = "red";
context.lineWidth = id_speed.height * 0.05 / 2;
context.beginPath();
context.arc(id_speed.height / 2, id_speed.height / 2, id_speed.height / 2 - id_speed.height * 0.05, Math.PI * 1.1, Math.PI * 1.4, false);
context.stroke();
}
}
Repeater {
model: id_speed.numberIndexs
Item {
height: id_speed.height/2
transformOrigin: Item.Bottom
rotation: index * id_speed.angleLength + id_speed.startAngle
x: id_speed.width/2
Rectangle {
height: id_speed.height * 0.05
width: height / 2
color: "light green"
antialiasing: true
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
anchors.topMargin: id_speed.height * 0.03
}
Text {
anchors {
horizontalCenter: parent.horizontalCenter
}
x: 0
y: id_speed.height * 0.09
color: "light green"
rotation: 360 - (index * id_speed.angleLength + id_speed.startAngle)
text: index * (id_speed.maxSpeed / (id_speed.numberIndexs - 1))
font.pixelSize: id_speed.height * 0.05
font.family: "Comic Sans MS"
}
}
}
}
Rectangle {
id: id_center
anchors.centerIn: parent
height: id_speed.height*0.1
width: height
radius: width/2
color: "light green"
}
Text {
anchors {
horizontalCenter: parent.horizontalCenter
top: id_speed.verticalCenter
topMargin: id_speed.height * 0.1
}
text: "Speed\n km/h"
color: "light green"
font.pixelSize: id_speed.height * 0.1
font.family: "Comic Sans MS"
}
SpeedNeedle {
id: id_speedNeedle
anchors {
top: id_speed.top
bottom: id_speed.bottom
horizontalCenter: parent.horizontalCenter
}
value: id_root.value
startAngle: id_speed.startAngle
angleLength: id_speed.angleLength / (id_speed.maxSpeed / (id_speed.numberIndexs - 1))
}
}