PSlider: Live preview and prevent event stealing

This commit is contained in:
Thomas Perl 2014-02-04 22:56:33 +01:00
parent 9849c4f8d4
commit 7165800c73

View file

@ -27,6 +27,9 @@ Rectangle {
property real min: 0.0 property real min: 0.0
property real max: 1.0 property real max: 1.0
property real displayedValue: mouseArea.pressed ? temporaryValue : value
property real temporaryValue
signal valueChangeRequested(real newValue) signal valueChangeRequested(real newValue)
clip: true clip: true
@ -35,15 +38,23 @@ Rectangle {
height: 50 * pgst.scalef height: 50 * pgst.scalef
MouseArea { MouseArea {
id: mouseArea
anchors.fill: parent anchors.fill: parent
onClicked: slider.valueChangeRequested(min + (max - min) * (mouse.x / width)) onClicked: slider.valueChangeRequested(min + (max - min) * (mouse.x / width))
onPressed: {
slider.temporaryValue = (min + (max - min) * (mouse.x / width));
}
onPositionChanged: {
slider.temporaryValue = (min + (max - min) * (mouse.x / width));
}
preventStealing: true
} }
Rectangle { Rectangle {
id: fillBackground id: fillBackground
color: '#333333' color: '#333333'
height: parent.height * 0.8 height: parent.height * 0.8
width: parent.width * (parent.value - parent.min) / (parent.max - parent.min) width: parent.width * (parent.displayedValue - parent.min) / (parent.max - parent.min)
anchors { anchors {
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter