import QtQuick // A slider for the badge opacity, from 0% to 100% in steps of 5%. It only // reports the picked value; saving it is up to whoever uses it. Item { id: root required property Theme theme // The color shown along the track, from clear to solid. required property color baseColor required property real value signal picked(real value) implicitHeight: root.theme.hueHeight function pickAt(x: real): void { const share = Math.max(0, Math.min(1, x / track.width)); root.picked(Math.round(share * 20) / 20); } Rectangle { id: track anchors.left: parent.left anchors.right: percent.left anchors.rightMargin: root.theme.popupSpacing anchors.verticalCenter: parent.verticalCenter height: root.theme.hueHeight radius: root.theme.hueHeight / 2 color: root.theme.fieldBg border.width: 1 border.color: root.theme.glassRimBottom Rectangle { anchors.fill: parent radius: parent.radius gradient: Gradient { orientation: Gradient.Horizontal GradientStop { position: 0 color: Qt.rgba(root.baseColor.r, root.baseColor.g, root.baseColor.b, 0) } GradientStop { position: 1 color: Qt.rgba(root.baseColor.r, root.baseColor.g, root.baseColor.b, 1) } } } // Marks the current value. Rectangle { width: 4 height: parent.height + 4 radius: 2 anchors.verticalCenter: parent.verticalCenter x: root.value * (track.width - width) color: root.theme.textColor border.width: 1 border.color: root.theme.buttonText } MouseArea { anchors.fill: parent cursorShape: Qt.PointingHandCursor onPressed: mouse => root.pickAt(mouse.x) onPositionChanged: mouse => root.pickAt(mouse.x) } } Text { id: percent anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter // Fixed width so the track does not jump as the number changes. width: root.theme.buttonWidth horizontalAlignment: Text.AlignRight text: Math.round(root.value * 100) + "%" color: root.theme.textColor font.pixelSize: root.theme.fontSize } }