Index: sources/gui/qml/components/Slider.qml =================================================================== diff -u -rf148379112a69d1c52027f2667e95f3f96d948ad -r9ec7a27375189ad75f0bef142cd6beb386db0955 --- sources/gui/qml/components/Slider.qml (.../Slider.qml) (revision f148379112a69d1c52027f2667e95f3f96d948ad) +++ sources/gui/qml/components/Slider.qml (.../Slider.qml) (revision 9ec7a27375189ad75f0bef142cd6beb386db0955) @@ -25,19 +25,32 @@ 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 property alias bgColor : _root.color - property real handlerWidth: 35 + property alias handler : _handler + height : Variables.progressbarHeight touchMargin : 25 minimum : 0 maximum : 0 + // real-time bound change should effect the current set value + onMinimumChanged: { + if (value < minimum ) + value = minimum + } + onMaximumChanged: { + if (value > maximum ) + value = maximum + } + minText { visible : true anchors.topMargin: Variables.sliderTextMargin @@ -51,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 @@ -94,6 +110,8 @@ minimum : _root.minimum maximum : _root.maximum step : _root.step + stepSnap : _root.stepSnap + textColor : _root.color } } @@ -105,7 +123,7 @@ } Rectangle { id: _handler - property real diameter : parent.handlerWidth + property real diameter : Variables.progressbarHandler anchors.verticalCenter : parent.verticalCenter anchors.horizontalCenter: _progressRect.right