2022-05-13 13:12:05 +00:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
2012-01-10 11:12:51 +00:00
|
|
|
|
2022-08-31 07:59:05 +00:00
|
|
|
import QtQuick
|
2012-01-10 11:12:51 +00:00
|
|
|
|
|
|
|
// Minimal slider implementation
|
|
|
|
Rectangle {
|
|
|
|
id: slider
|
|
|
|
|
2012-12-11 19:05:04 +00:00
|
|
|
property alias text: buttonText.text
|
2012-01-10 11:12:51 +00:00
|
|
|
Accessible.role: Accessible.Slider
|
|
|
|
|
2013-01-21 14:53:47 +00:00
|
|
|
property int value: 5 // required
|
|
|
|
property int minimumValue: 0 // optional (default INT_MIN)
|
|
|
|
property int maximumValue: 20 // optional (default INT_MAX)
|
|
|
|
property int stepSize: 1 // optional (default 1)
|
2012-01-10 11:12:51 +00:00
|
|
|
|
2012-12-11 19:05:04 +00:00
|
|
|
width: 100
|
2012-01-10 11:12:51 +00:00
|
|
|
height: 30
|
2012-12-11 19:05:04 +00:00
|
|
|
border.color: "black"
|
|
|
|
border.width: 1
|
2012-01-10 11:12:51 +00:00
|
|
|
|
2012-12-11 19:05:04 +00:00
|
|
|
Rectangle {
|
|
|
|
id: indicator
|
|
|
|
x: 1
|
|
|
|
y: 1
|
|
|
|
height: parent.height - 2
|
2019-09-17 16:10:59 +00:00
|
|
|
width: ((parent.width - 2) / slider.maximumValue) * slider.value
|
2012-12-11 19:05:04 +00:00
|
|
|
color: "lightgrey"
|
|
|
|
Behavior on width {
|
|
|
|
NumberAnimation { duration: 50 }
|
|
|
|
}
|
|
|
|
}
|
2012-01-10 11:12:51 +00:00
|
|
|
|
|
|
|
Text {
|
|
|
|
id: buttonText
|
|
|
|
text: parent.value
|
|
|
|
anchors.centerIn: parent
|
|
|
|
font.pixelSize: parent.height * .5
|
|
|
|
}
|
2013-01-21 14:53:47 +00:00
|
|
|
|
2012-12-11 19:05:04 +00:00
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
2019-09-17 16:10:59 +00:00
|
|
|
onClicked: (mouse) => {
|
|
|
|
var pos = mouse.x / slider.width * (slider.maximumValue - slider.minimumValue)
|
|
|
|
+ slider.minimumValue
|
2012-12-11 19:05:04 +00:00
|
|
|
slider.value = pos
|
|
|
|
}
|
|
|
|
}
|
2013-01-21 14:53:47 +00:00
|
|
|
|
2012-12-11 19:05:04 +00:00
|
|
|
Keys.onLeftPressed: value > minimumValue ? value = value - stepSize : minimumValue
|
|
|
|
Keys.onRightPressed: value < maximumValue ? value = value + stepSize : maximumValue
|
2012-01-10 11:12:51 +00:00
|
|
|
}
|