Index: sources/gui/qml/components/Slider.qml =================================================================== diff -u -r95c671ab7037af055db551456a719ff67bf10262 -r9ec7a27375189ad75f0bef142cd6beb386db0955 --- sources/gui/qml/components/Slider.qml (.../Slider.qml) (revision 95c671ab7037af055db551456a719ff67bf10262) +++ sources/gui/qml/components/Slider.qml (.../Slider.qml) (revision 9ec7a27375189ad75f0bef142cd6beb386db0955) @@ -25,6 +25,8 @@ RangeRect { id: _root property alias value : _progressRect.value property int step : 1 + property bool stepSnap : false + property bool ticks : false property alias color : _progressRect.color @@ -62,22 +64,25 @@ font.bold : false } - function getPosition(x) { + function getValueOfX(x) { return ( x * ( maximum - minimum ) ) / width + minimum } function setValue(x) { - if ( x < 0 ) { - value = minimum - } else - if ( x > width ) { - value = maximum - } else - if (step === 1) { // only for performance otherwise formula works perfectly fine for any step. - value = getPosition(x) - } else { - value = Math.round((getPosition(x) - minimum) / step) * step + minimum - } + if ( x < 0 ) { value = minimum; return; } + if ( x > width ) { value = maximum; return; } + + value = getValueOfX(x) + + if ( step === 1 ) { /* keep the value and return */ return; } + + var start = 0 + if ( ! stepSnap ) start = minimum + + value = Math.round((value - start) / step) * step + start + + if ( value < minimum ) { value = minimum; return; } + if ( value > maximum ) { value = maximum; return; } } ProgressRect { id: _progressRect @@ -105,6 +110,8 @@ minimum : _root.minimum maximum : _root.maximum step : _root.step + stepSnap : _root.stepSnap + textColor : _root.color } }