80 lines
2.3 KiB
QML
80 lines
2.3 KiB
QML
import QtQuick
|
|
import QtQuick.Controls.Basic
|
|
import Asteria
|
|
|
|
// Settings slider with a label row and a debounced committed() signal so
|
|
// preference writes don't fire on every pixel of a drag.
|
|
Column {
|
|
id: root
|
|
|
|
property string label: ""
|
|
property string valueText: slider.value.toString()
|
|
property alias from: slider.from
|
|
property alias to: slider.to
|
|
property alias stepSize: slider.stepSize
|
|
property alias value: slider.value
|
|
|
|
signal committed(real value)
|
|
|
|
spacing: 4
|
|
|
|
Item {
|
|
width: parent.width
|
|
height: Math.max(labelItem.implicitHeight, valueItem.implicitHeight)
|
|
|
|
Text {
|
|
id: labelItem
|
|
text: root.label
|
|
font.pixelSize: 13
|
|
color: ThemeManager.currentTheme.uiText
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
}
|
|
Text {
|
|
id: valueItem
|
|
text: root.valueText
|
|
font.pixelSize: 12
|
|
color: ThemeManager.currentTheme.dimText
|
|
anchors {
|
|
right: parent.right
|
|
verticalCenter: parent.verticalCenter
|
|
}
|
|
}
|
|
}
|
|
|
|
Timer {
|
|
id: debounce
|
|
interval: 250
|
|
onTriggered: root.committed(slider.value)
|
|
}
|
|
|
|
Slider {
|
|
id: slider
|
|
width: parent.width
|
|
onMoved: debounce.restart()
|
|
|
|
background: Rectangle {
|
|
x: slider.leftPadding
|
|
y: slider.topPadding + slider.availableHeight / 2 - height / 2
|
|
width: slider.availableWidth
|
|
height: 3
|
|
radius: 2
|
|
color: ThemeManager.currentTheme.scrollbarThumb
|
|
Rectangle {
|
|
width: slider.visualPosition * parent.width
|
|
height: parent.height
|
|
radius: 2
|
|
color: ThemeManager.currentTheme.buttonAccent
|
|
}
|
|
}
|
|
handle: Rectangle {
|
|
x: slider.leftPadding + slider.visualPosition * (slider.availableWidth - width)
|
|
y: slider.topPadding + slider.availableHeight / 2 - height / 2
|
|
width: 14
|
|
height: 14
|
|
radius: 7
|
|
color: slider.pressed ? Qt.lighter(ThemeManager.currentTheme.buttonAccent, 1.15)
|
|
: ThemeManager.currentTheme.buttonAccent
|
|
}
|
|
}
|
|
}
|