| 1 | import QtQuick |
| 2 | |
| 3 | Item { |
| 4 | id: s |
| 5 | property real value: 0 |
| 6 | property real from: 0 |
| 7 | property real to: 1 |
| 8 | property real step: 0.02 |
| 9 | property bool muted: false |
| 10 | signal moved(real v) |
| 11 | |
| 12 | readonly property real frac: to > from ? Math.max(0, Math.min(1, (value - from) / (to - from))) : 0 |
| 13 | |
| 14 | implicitHeight: 20 |
| 15 | |
| 16 | Rectangle { |
| 17 | id: track |
| 18 | anchors.verticalCenter: parent.verticalCenter |
| 19 | width: parent.width |
| 20 | height: 6 |
| 21 | color: Theme.surfaceHi |
| 22 | |
| 23 | Rectangle { |
| 24 | width: parent.width * s.frac |
| 25 | height: parent.height |
| 26 | opacity: s.muted ? 0.35 : 1 |
| 27 | gradient: Gradient { |
| 28 | orientation: Gradient.Horizontal |
| 29 | GradientStop { position: 0; color: Theme.accentDim } |
| 30 | GradientStop { position: 1; color: Theme.accent } |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | Rectangle { |
| 36 | x: Math.max(0, Math.min(s.width - width, s.width * s.frac - width / 2)) |
| 37 | anchors.verticalCenter: parent.verticalCenter |
| 38 | width: 4 |
| 39 | height: 14 |
| 40 | color: Theme.fg |
| 41 | opacity: s.muted ? 0.5 : 1 |
| 42 | } |
| 43 | |
| 44 | MouseArea { |
| 45 | anchors.fill: parent |
| 46 | cursorShape: Qt.PointingHandCursor |
| 47 | function setFromX(mx) { |
| 48 | var f = Math.max(0, Math.min(1, mx / width)) |
| 49 | s.moved(s.from + f * (s.to - s.from)) |
| 50 | } |
| 51 | onPressed: m => setFromX(m.x) |
| 52 | onPositionChanged: m => { if (pressed) setFromX(m.x) } |
| 53 | onWheel: w => { |
| 54 | var d = (w.angleDelta.y > 0 ? 1 : -1) * s.step * (s.to - s.from) |
| 55 | s.moved(Math.max(s.from, Math.min(s.to, s.value + d))) |
| 56 | } |
| 57 | } |
| 58 | } |