import QtQuick Item { id: root required property Theme theme property real value: 0 property real step: 0.05 signal moved(real value) readonly property real boundedValue: Math.max(0, Math.min(1, value)) function valueAt(x) { return Math.max(0, Math.min(1, x / Math.max(1, width))); } function moveTo(x) { moved(valueAt(x)); } implicitWidth: 120 implicitHeight: 20 activeFocusOnTab: enabled opacity: enabled ? 1 : 0.48 Accessible.role: Accessible.Slider Accessible.name: "slider" Keys.onLeftPressed: event => { event.accepted = true; moved(Math.max(0, boundedValue - step)); } Keys.onRightPressed: event => { event.accepted = true; moved(Math.min(1, boundedValue + step)); } Rectangle { anchors.left: parent.left anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter height: pointer.containsMouse || pointer.pressed || root.activeFocus ? 8 : 6 radius: height / 2 color: root.theme.withAlpha(root.theme.ui.minor, 0.28) Rectangle { anchors.left: parent.left anchors.top: parent.top anchors.bottom: parent.bottom width: parent.width * root.boundedValue radius: parent.radius color: root.theme.ui.accent } } Rectangle { x: Math.round((root.width - width) * root.boundedValue) anchors.verticalCenter: parent.verticalCenter width: pointer.pressed ? 16 : 14 height: width radius: width / 2 color: root.theme.content.normal border.width: root.activeFocus ? 2 : 1 border.color: root.activeFocus ? root.theme.content.focus : root.theme.withAlpha(root.theme.ui.backdrop, 0.7) Behavior on width { NumberAnimation { duration: root.theme.lowPowerMode ? 0 : 90 } } } MouseArea { id: pointer anchors.fill: parent enabled: root.enabled hoverEnabled: true cursorShape: Qt.PointingHandCursor onPressed: event => root.moveTo(event.x) onPositionChanged: event => { if (pressed) root.moveTo(event.x); } } }