Repository navigation
Expand file tree
/
Copy pathCircularGaugeMeter.qml
More file actions
82 lines (74 loc) · 3.17 KB
/
Copy pathCircularGaugeMeter.qml
File metadata and controls
82 lines (74 loc) · 3.17 KB
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
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
property bool shadowVisible: true
style: CircularGaugeStyle {
labelStepSize: 10
labelInset: outerRadius / 2.2
tickmarkInset: outerRadius / 4.2
minorTickmarkInset: outerRadius / 4.2
minimumValueAngle: -120
maximumValueAngle: 120
background:Rectangle {
implicitHeight: gauge.height
implicitWidth: gauge.width
color: "transparent"
anchors.centerIn: parent
radius: 360
Canvas {
visible: shadowVisible
property int value: gauge.value
anchors.fill: parent
opacity: 0.03
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 = [
"#D9D9D9",// Start color
"#D9D9D9", // End color
];
// 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 - 48,
degreesToRadians(angle),
degreesToRadians(endAngle));
ctx.stroke();
}
}
}
}
tickmarkLabel :Item{}
tickmark:Item{}
minorTickmark:Item{}
}
}