Index: sources/gui/qml/components/Slider.qml =================================================================== diff -u -r9e862b7d1f4485c157c6fe32bb1656e161b8b6a1 -r0e2a9c05ce36fd5ffd717b83be813174121dd0cf --- sources/gui/qml/components/Slider.qml (.../Slider.qml) (revision 9e862b7d1f4485c157c6fe32bb1656e161b8b6a1) +++ sources/gui/qml/components/Slider.qml (.../Slider.qml) (revision 0e2a9c05ce36fd5ffd717b83be813174121dd0cf) @@ -25,7 +25,7 @@ */ RangeRect { id: _root property real value : _progressRect.value - property real minStop : undefined + property real minStop : _root.minimum property real defaultValue : _root.minimum property real step : 1 @@ -57,6 +57,8 @@ property bool showMinMaxText : true property color borderColor : Colors.borderDisableButton property color highlightColor : Colors.sliderHighlightColor + property color progressBorderActiveColor : Colors.sliderProgressBorderActive + property color progressBorderInactiveColor : Colors.borderDisableButton signal activeChanged() signal handleSelected() @@ -88,14 +90,16 @@ let newValue = Number.NaN if(vIsIncrement) { - newValue = _progressRect.value + amountChanged + newValue = calculateRoundedValue(_progressRect.value + amountChanged) } else { - newValue = _progressRect.value - amountChanged + newValue = calculateRoundedValue(_progressRect.value - amountChanged) } // Capping values based on min/max threshold - if ( newValue < minimum ) newValue = minimum - if ( newValue > maximum ) newValue = maximum + let min = calculateMinimum() + let max = calculateRoundedValue(_root.maximum) + if ( newValue < min ) newValue = min + if ( newValue > max ) newValue = max // Update the slider's visual value _progressRect.previousSliderValue = newValue // for comparison purposes @@ -190,17 +194,9 @@ } function calculateValue(x, isSnappingToTicks) { - let mMinimum = Number(_root.minimum.toFixed(decimal)) - let mMaximum = Number(_root.maximum.toFixed(decimal)) + let mMinimum = calculateMinimum() + let mMaximum = calculateRoundedValue(_root.maximum) - // if there is a minimum stop, then adjust the slider minimum to that value - if (minStop && mMinimum < minStop) { - // if slider is set to snap and minimum stop is not on a step, then - // adjust it to one step above - mMinimum = stepSnap ? Math.ceil(minStop/step) * step - : minStop - } - // the center of the handler is aligned on the snap point and half width shall be used to set as min not the entire width. // also half of the hadler is out of slider min position when set on min, which proves the same as above. if(x < ( _handler.width / 2 ) ) { @@ -226,8 +222,10 @@ let stepWidth = width / ((mMaximum - mMinimum) / step) if ( stepWidth < _handler.width ) { let valueStepCount = parseInt(mValue / step) - mValue = valueStepCount * step - return mValue.toFixed(decimal) + mValue = calculateRoundedValue((valueStepCount * step)) + if ( mValue < mMinimum ) { return mMinimum } + if ( mValue > mMaximum ) { return mMaximum } + return mValue } // For sliders with decimal min, max, values, we need to add refinement to @@ -247,6 +245,31 @@ return mValue; } + /*! + * \brief Calculate the minimum value for the slider based on the current minimum, + * minStop, and stepSnap values. + * \return If minimum is greater than or equal to minStop, then just return minimum. + * If minStop is greater than minimum and stepSnap is false, then return minStop. + * If minStop is greater than minimum and stepSnap is true, then return minStep if + * it falls on a step, otherwise return the step above minStop. + */ + function calculateMinimum() { + let result = calculateRoundedValue(_root.minimum) + let rdMinStop = calculateRoundedValue(_root.minStop) + if (rdMinStop > result) { + if (stepSnap) { + // if slider is set to snap and minimum stop is not on a step, then + // adjust it to one step above + let rdStep = calculateRoundedValue(step) + result = Math.ceil(rdMinStop/rdStep) * rdStep + } + else { + result = rdMinStop + } + } + return result + } + // used loader for performance since it may not always be required. // and can be a heavy Component Loader { id: _ticksLoader @@ -280,7 +303,7 @@ radius : _root.isRoundedEnds ? (height/2) : Variables.rangeRectRadius border.width: _root.hasBorder ? Variables.rangeRectBorderWidth : 0 - border.color: _root.isActive ? Colors.sliderProgressBorderActive : Colors.borderDisableButton + border.color: _root.isActive ? _root.progressBorderActiveColor : _root.progressBorderInactiveColor // propagation is not working on drag ! onDragged: {