Skip to content

Commit

Permalink
QML: Make Knob arc calculation more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed Jun 15, 2021
1 parent 9c687d4 commit 314c474
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions res/skins/QMLDemo/Mixxx/Controls/Knob.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ Item {
property alias arcWidth: arcPath.strokeWidth
property alias arcStyle: arcPath.strokeStyle
property alias arcStylePattern: arcPath.dashPattern
readonly property real valueCenter: (max - min) / 2

signal turned(real value)

function angleFrom(targetValue) {
return targetValue * 2 * root.angle;
}

Item {
id: background

Expand All @@ -35,7 +40,7 @@ Item {
id: foreground

anchors.fill: parent
rotation: (root.value - (root.max - root.min) / 2) * 2 * root.angle
rotation: root.angleFrom(root.value - root.valueCenter)
}

Shape {
Expand All @@ -51,8 +56,8 @@ Item {
fillColor: "transparent"

PathAngleArc {
startAngle: -90 + root.angle * 2 * (root.arcStart - (root.max - root.min) / 2)
sweepAngle: (root.value - root.arcStart) * 2 * root.angle
startAngle: root.angleFrom(root.arcStart - root.valueCenter) - 90
sweepAngle: root.angleFrom(root.value - root.arcStart)
radiusX: root.arcRadius
radiusY: root.arcRadius
centerX: root.width / 2 + root.arcOffsetX
Expand Down

0 comments on commit 314c474

Please sign in to comment.