|
| 1 | +import QtQuick |
| 2 | +import "../../../qml" as Skin |
| 3 | +import "../LateNightTheme" |
| 4 | + |
| 5 | +Skin.ControlKnob { |
| 6 | + id: root |
| 7 | + |
| 8 | + readonly property int arcRenderScale: 8 |
| 9 | + property url backgroundSource: LateNightTheme.assetRegularKnobBackground |
| 10 | + property bool displayArc: false |
| 11 | + property color displayArcColor: "transparent" |
| 12 | + property real displayArcOffsetY: 1.998 |
| 13 | + property real displayArcRadius: 12.5 |
| 14 | + property int displayArcStart: 1 // Knob.ArcStart.Center |
| 15 | + property real displayArcWidth: 2 |
| 16 | + property string indicatorColor: "orange" |
| 17 | + property string indicatorKind: "regular" |
| 18 | + |
| 19 | + angle: 135 |
| 20 | + arc: false |
| 21 | + arcStart: displayArcStart |
| 22 | + color: displayArcColor |
| 23 | + implicitHeight: backgroundImage.implicitHeight |
| 24 | + implicitWidth: backgroundImage.implicitWidth |
| 25 | + knobCenterOffsetY: displayArcOffsetY |
| 26 | + showDefaultBackground: false |
| 27 | + showDefaultForeground: false |
| 28 | + |
| 29 | + background: Image { |
| 30 | + id: backgroundImage |
| 31 | + |
| 32 | + anchors.fill: parent |
| 33 | + fillMode: Image.PreserveAspectFit |
| 34 | + source: root.backgroundSource |
| 35 | + } |
| 36 | + foreground: Item { |
| 37 | + anchors.fill: parent |
| 38 | + |
| 39 | + Image { |
| 40 | + anchors.fill: parent |
| 41 | + fillMode: Image.PreserveAspectFit |
| 42 | + source: LateNightTheme.mixerKnobIndicator(root.indicatorKind, root.indicatorColor) |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + Canvas { |
| 47 | + id: arcCanvas |
| 48 | + |
| 49 | + readonly property color renderedColor: root.displayArcColor |
| 50 | + readonly property real renderedOffsetY: root.displayArcOffsetY |
| 51 | + readonly property real renderedRadius: root.displayArcRadius |
| 52 | + readonly property int renderedStart: root.displayArcStart |
| 53 | + readonly property real renderedValue: root.value |
| 54 | + readonly property real renderedWidth: root.displayArcWidth |
| 55 | + |
| 56 | + antialiasing: true |
| 57 | + height: root.height * root.arcRenderScale |
| 58 | + layer.enabled: true |
| 59 | + layer.mipmap: true |
| 60 | + renderStrategy: Canvas.Immediate |
| 61 | + scale: 1 / root.arcRenderScale |
| 62 | + transformOrigin: Item.TopLeft |
| 63 | + visible: root.displayArc |
| 64 | + width: root.width * root.arcRenderScale |
| 65 | + z: 1 |
| 66 | + |
| 67 | + Component.onCompleted: requestPaint() |
| 68 | + onPaint: { |
| 69 | + const ctx = getContext("2d"); |
| 70 | + ctx.clearRect(0, 0, width, height); |
| 71 | + if (!root.displayArc) { |
| 72 | + return; |
| 73 | + } |
| 74 | + |
| 75 | + const renderScale = root.arcRenderScale; |
| 76 | + const startAngle = root.angleFrom(root.arcStartValue - root.valueCenter) - 90; |
| 77 | + const sweepAngle = root.angleFrom(root.value - root.arcStartValue); |
| 78 | + const startRadians = startAngle * Math.PI / 180; |
| 79 | + const endRadians = (startAngle + sweepAngle) * Math.PI / 180; |
| 80 | + |
| 81 | + ctx.beginPath(); |
| 82 | + ctx.strokeStyle = root.displayArcColor; |
| 83 | + ctx.lineWidth = root.displayArcWidth * renderScale; |
| 84 | + ctx.lineCap = "round"; |
| 85 | + ctx.arc((root.width / 2) * renderScale, (root.height / 2 + root.displayArcOffsetY) * renderScale, root.displayArcRadius * renderScale, startRadians, endRadians, sweepAngle < 0); |
| 86 | + ctx.stroke(); |
| 87 | + } |
| 88 | + onRenderedColorChanged: requestPaint() |
| 89 | + onRenderedOffsetYChanged: requestPaint() |
| 90 | + onRenderedRadiusChanged: requestPaint() |
| 91 | + onRenderedStartChanged: requestPaint() |
| 92 | + onRenderedValueChanged: requestPaint() |
| 93 | + onRenderedWidthChanged: requestPaint() |
| 94 | + onVisibleChanged: requestPaint() |
| 95 | + } |
| 96 | +} |
0 commit comments