-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGauge2.qml
312 lines (258 loc) · 11.5 KB
/
Gauge2.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Controls.Styles 1.4
import QtQuick.Extras 1.4
import QtQuick.Layouts 1.3
import QtQuick.Extras.Private 1.0
import QtGraphicalEffects 1.0
CircularGauge {
id: gauge
// Define the radius and angle for the arc
property real arcAngle: 180 // Angle in degrees
property real arcRadius: 90
function speedColor(value){
if(value < 60 ){
return "green"
} else if(value > 60 && value < 150){
return "yellow"
}else{
return "Red"
}
}
style: CircularGaugeStyle {
labelStepSize: 10
labelInset: outerRadius / 2.2
tickmarkInset: outerRadius / 4.2
minorTickmarkInset: outerRadius / 4.2
minimumValueAngle: -155
maximumValueAngle: 155
background:Rectangle {
implicitHeight: gauge.height
implicitWidth: gauge.width
color: "#000000"
anchors.centerIn: parent
radius: 360
// Create a Rotation item to move the Image along the arc
// Image to move along the arc
Image {
sourceSize: Qt.size(16, 17)
source: "qrc:/img/maxLimit.svg"
// Translate the Image along the arc
x: arcRadius * Math.cos(Math.PI * arcAngle / 180)
y: arcRadius * Math.sin(Math.PI * arcAngle / 180)
// Set the pivot to the bottom center of the Image
anchors.bottom: circularCanva.top
anchors.horizontalCenter: parent.horizontalCenter
}
Canvas {
id:circularCanva
property int value: gauge.value
anchors.fill: parent
Component.onCompleted: requestPaint()
function degreesToRadians(degrees) {
return degrees * (Math.PI / 180);
}
function createLinearGradient(ctx, start, end, colors) {
var gradient = ctx.createLinearGradient(start.x, start.y, end.x, end.y);
for (var i = 0; i < colors.length; i++) {
gradient.addColorStop(i / (colors.length - 1), colors[i]);
}
return gradient;
}
onPaint: {
var ctx = getContext("2d");
ctx.reset();
// Define the gradient colors for the filled arc
var gradientColors = [
"#AAFFFF",// Start color
"#AAFFFF", // End color
];
// Calculate the start and end angles for the filled arc
var startAngle = valueToAngle(gauge.minimumValue) - 90;
var endAngle = valueToAngle(250) - 90;
// Create a linear gradient
var gradient = createLinearGradient(ctx, { x: 0, y: 0 }, { x: outerRadius * 2, y: 0 }, gradientColors);
// Loop through the gradient colors and fill the arc segment with each color
for (var i = 0; i < gradientColors.length; i++) {
var gradientColor = gradientColors[i];
var angle = startAngle + (endAngle - startAngle) * (i / (gradientColors.length - 1));
ctx.beginPath();
ctx.lineWidth = 1.5;
ctx.strokeStyle = gradient;
ctx.arc(outerRadius,
outerRadius,
outerRadius - 57,
degreesToRadians(angle),
degreesToRadians(endAngle));
ctx.stroke();
}
}
}
Canvas {
property int value: gauge.value
anchors.fill: parent
Component.onCompleted: requestPaint()
function degreesToRadians(degrees) {
return degrees * (Math.PI / 180);
}
function createLinearGradient(ctx, start, end, colors) {
var gradient = ctx.createLinearGradient(start.x, start.y, end.x, end.y);
for (var i = 0; i < colors.length; i++) {
gradient.addColorStop(i / (colors.length - 1), colors[i]);
}
return gradient;
}
onPaint: {
var ctx = getContext("2d");
ctx.reset();
// Define the gradient colors for the filled arc
var gradientColors = [
"#163546",// Start color
"#163546", // End color
];
// Calculate the start and end angles for the filled arc
var startAngle = valueToAngle(gauge.minimumValue) - 90;
var endAngle = valueToAngle(250) - 90;
// Create a linear gradient
var gradient = createLinearGradient(ctx, { x: 0, y: 0 }, { x: outerRadius * 2, y: 0 }, gradientColors);
// Loop through the gradient colors and fill the arc segment with each color
for (var i = 0; i < gradientColors.length; i++) {
var gradientColor = gradientColors[i];
var angle = startAngle + (endAngle - startAngle) * (i / (gradientColors.length - 1));
ctx.beginPath();
ctx.lineWidth = outerRadius * 0.15;
ctx.strokeStyle = gradient;
ctx.arc(outerRadius,
outerRadius,
outerRadius - 75,
degreesToRadians(angle),
degreesToRadians(endAngle));
ctx.stroke();
}
}
}
Canvas {
property int value: gauge.value
anchors.fill: parent
onValueChanged: requestPaint()
function degreesToRadians(degrees) {
return degrees * (Math.PI / 180);
}
function createLinearGradient(ctx, start, end, colors) {
var gradient = ctx.createLinearGradient(start.x, start.y, end.x, end.y);
for (var i = 0; i < colors.length; i++) {
gradient.addColorStop(i / (colors.length - 1), colors[i]);
}
return gradient;
}
onPaint: {
var ctx = getContext("2d");
ctx.reset();
// Define the gradient colors for the filled arc
var gradientColors = [
"#6369FF",// Start color
"#63FFFF", // End color
"#FFFF00",
"#FF0000"
];
// Calculate the start and end angles for the filled arc
var startAngle = valueToAngle(gauge.minimumValue) - 90;
var endAngle = valueToAngle(gauge.value) - 90;
// Create a linear gradient
var gradient = createLinearGradient(ctx, { x: 0, y: 0 }, { x: outerRadius * 2, y: 0 }, gradientColors);
// Loop through the gradient colors and fill the arc segment with each color
for (var i = 0; i < gradientColors.length; i++) {
var gradientColor = gradientColors[i];
var angle = startAngle + (endAngle - startAngle) * (i / (gradientColors.length - 1));
ctx.beginPath();
ctx.lineWidth = outerRadius * 0.15;
ctx.strokeStyle = gradient;
ctx.arc(outerRadius,
outerRadius,
outerRadius - 75,
degreesToRadians(angle),
degreesToRadians(endAngle));
ctx.stroke();
}
}
}
}
needle: Item {
y: -outerRadius * 0.70
height: outerRadius * 0.02
Image {
id: needle
source: "qrc:/img/Rectangle 4.svg"
width: height * 0.06
asynchronous: true
antialiasing: true
}
Glow {
anchors.fill: needle
radius: 5
samples: 10
color: "white"
source: needle
}
}
foreground: Item {
anchors.centerIn: parent
Image{
anchors.centerIn: parent
source: "qrc:/img/Ellipse 1.svg"
Image {
sourceSize: Qt.size(203,203)
anchors.centerIn: parent
source: "qrc:/img/Subtract.svg"
Image {
z:2
sourceSize: Qt.size(147,147)
anchors.centerIn: parent
source: "qrc:/img/Ellipse 6.svg"
ColumnLayout{
anchors.centerIn: parent
Label{
text: gauge.value.toFixed(0)
font.pixelSize: 65
font.family: "Inter"
color: "#FFFFFF"
font.bold: Font.DemiBold
Layout.alignment: Qt.AlignHCenter
}
Label{
text: "km/h"
font.pixelSize: 18
font.family: "Inter"
color: "#FFFFFF"
opacity: 0.4
font.bold: Font.Normal
Layout.alignment: Qt.AlignHCenter
}
}
}
}
}
}
tickmarkLabel: Text {
visible: false
font.pixelSize: Math.max(6, outerRadius * 0.05)
text: styleData.value
color: styleData.value <= gauge.value ? "white" : "#777776"
antialiasing: true
}
tickmark:Rectangle {
implicitWidth: outerRadius * 0.008
implicitHeight: outerRadius * 0.05
antialiasing: true
smooth: true
color: styleData.value <= gauge.value ? "white" : "darkGray"
}
minorTickmark: Rectangle {
implicitWidth: outerRadius * 0.008
implicitHeight: outerRadius * 0.05
antialiasing: true
smooth: true
color: styleData.value <= gauge.value ? "white" : "darkGray"
}
}
}