-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gauge_animation.qml
173 lines (162 loc) · 5.68 KB
/
Gauge_animation.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import QtQuick 2.15
import QtQuick.Controls 2.0
import QtQuick.Controls.Styles 1.4
import QtQuick.Extras 1.4
import QtQuick.Extras.Private 1.0
import QtGraphicalEffects 1.0
CircularGauge {
id: gauge
style: CircularGaugeStyle {
minimumValueAngle: -150
maximumValueAngle: 150
background: Rectangle {
implicitHeight: gauge.height
implicitWidth: gauge.width
color: "#0039383c"
anchors.centerIn: parent
radius: 360
Image {
id:needleColor1
visible: false
anchors.fill: parent
source: "/img/background60.svg"
asynchronous: true
sourceSize {
width: width
}
}
Image {
id:needleColor2
visible: false
anchors.fill: parent
source: "/img/background120.svg"
asynchronous: true
sourceSize {
width: width
}
}
Image {
id:needleColor3
visible: false
anchors.fill: parent
source: "/img/background.svg"
asynchronous: true
sourceSize {
width: width
}
}
// Add tick labels behind the Canvas
Repeater {
model: 7
delegate: Text {
property real angle: -200 + (index * 37)
property real radius: gauge.width / 2 - 25 // Adjust radius as needed
property real xOffset: Math.cos(Math.PI * angle / 180) * radius
property real yOffset: Math.sin(Math.PI * angle / 180) * radius
x: (gauge.width / 2) + xOffset - width / 2
y: (gauge.height / 2) + yOffset - height / 2
text: (20+(index *20)).toFixed(0)
color: "white"
font.pixelSize: 20
transform: Rotation {
origin.x: x + width / 2
origin.y: y + height / 2
angle: angle
}
}
}
Canvas {
property int value: gauge.value
anchors.fill: parent
onValueChanged: requestPaint()
function degreesToRadians(degrees) {
return degrees * (Math.PI / 180);
}
Repeater {
z:1
model: 7
delegate: Text {
property real angle: -200 + (index * 37)
property real radius: gauge.width / 2 - 25 // Adjust radius as needed
property real xOffset: Math.cos(Math.PI * angle / 180) * radius
property real yOffset: Math.sin(Math.PI * angle / 180) * radius
x: (gauge.width / 2) + xOffset - width / 2
y: (gauge.height / 2) + yOffset - height / 2
text: (20+(index *20)).toFixed(0)
color: "white"
font.pixelSize: 20
transform: Rotation {
origin.x: x + width / 2
origin.y: y + height / 2
angle: angle
}
}
}
onPaint: {
if(gauge.value>0&&gauge.value<60){
needleColor1.visible=true
needleColor2.visible=false
needleColor3.visible=false
}
if (gauge.value>=60&&gauge.value<120){
needleColor1.visible=false
needleColor2.visible=true
needleColor3.visible=false
}
if(gauge.value>=120){
needleColor1.visible=false
needleColor2.visible=false
needleColor3.visible=true
}
var ctx = getContext("2d");
ctx.reset();
ctx.beginPath();
ctx.strokeStyle = "#39383c"
ctx.lineWidth = 46
ctx.arc(outerRadius,
outerRadius,
outerRadius - ctx.lineWidth / 2,
degreesToRadians(valueToAngle(gauge.value) - 90),
degreesToRadians(valueToAngle(gauge.maximumValue + 1) - 90)
);
ctx.stroke();
}
}
}
foreground: Item {
Text {
x: 118
y: 200
width: 167
height: 97
font.pixelSize: 80
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignBottom
font.family: "Futura"
font.bold: true
smooth: true
anchors.centerIn: parent
text: gauge.value.toFixed(0)
color: "white"
visible: false
}
}
tickmarkLabel: Text {
visible: false
}
tickmark: Rectangle {
visible: false
}
needle: Item {
visible: false
}
minorTickmark: Rectangle {
visible: false
}
}
}
/*##^##
Designer {
D{i:0;autoSize:true;height:480;width:640}
}
##^##*/