Index: sources/gui/qml/components/Slider.qml =================================================================== diff -u -r43ffdd5ca0998f06d28b6adeee231a6eec7e7150 -r2ad7c7b4468f6a9aad3373586285ce4c2295ae77 --- sources/gui/qml/components/Slider.qml (.../Slider.qml) (revision 43ffdd5ca0998f06d28b6adeee231a6eec7e7150) +++ sources/gui/qml/components/Slider.qml (.../Slider.qml) (revision 2ad7c7b4468f6a9aad3373586285ce4c2295ae77) @@ -132,50 +132,52 @@ return } - // Calculate the inbetween : + // Calculate the in-between : let mValue = 0 let start = 0 if ( ! stepSnap ) start = mMinimum mValue = getValueOfX(x) - if(step < _handler.width/2) { - // special handling for the case that the step segments are less than half the handle width + // special handling for the case that the step segments are less than the handle's width + let stepWidth = width / ((mMaximum - mMinimum) / step) + if ( stepWidth < _handler.width ) { let valueStepCount = parseInt(mValue / step) - - if(valueStepCount <= 1) mValue = step // special case of segment for first tick - - update(mValue); + mValue = valueStepCount * step + update(mValue.toFixed(decimal)); return; } - if(isSnappingToTicks) + if ( isSnappingToTicks ) { mValue = Math.round((mValue - start) / step) * step + start - else - mValue = Math.round(mValue - start + start) + } - decimals = Math.round(-Math.log10(step)) - if (decimals > 0) { - mValue = mValue.toFixed(decimals) + // For sliders with decimal min, max, values, we need to add refinement to + // the value to achieve slider handle movement close to those of the whole number sliders + if ( decimal > 0 ) { + let additionalDecimalResolution = 3 + mValue = mValue.toFixed(decimal + additionalDecimalResolution) } - if ( mValue < mMinimum ) { mValue = mMinimum; update(mValue); return; } - if ( mValue > mMaximum ) { mValue = mMaximum; update(mValue); return; } - update(mValue); return; + if ( mValue < mMinimum ) { mValue = mMinimum; update(mValue); return; } + if ( mValue > mMaximum ) { mValue = mMaximum; update(mValue); return; } + update(mValue); return; } - // Function not used - function setHandlerPosition() { - if ( _progressRect.width <= 0 ) { - _handler.x = 0 - _root.tickMarksThickness - } else - if ( _progressRect.width >= _root.width - _root.tickMarksThickness ) { - _handler.x = _root.width - _handler.width + _root.tickMarksThickness + function updateSliderVisuals(isSnapped) { + // Correct the handle location when dragging to assure centering of + // the handle on the cursor / touchpoint + // if isSnapped is true, indicates handler is to snap to a tick, remove displacement + // to assure centering on the edge of ProgressRect + if(!isSnapped && (_progressRect.width >= _handler.width/2)) { + _handler.anchors.horizontalCenterOffset = -_progressRect.leftRightTouchMargin + } else { + _handler.anchors.horizontalCenterOffset = 0 } - else { - _handler.x = _progressRect.width - _handler.width / 2 - } + + // update the displayed value to the attentive snapped value + _root.displayedValue = (Math.round(_root.value / step) * step).toFixed(decimal) } ProgressRect { id: _progressRect @@ -195,18 +197,13 @@ onClicked: { _root.clicked(vMouseEvent) progressRectClicked() - } onPressed: { _root.pressed(vMouseEvent) } onReleased: { _root.released(vMouseEvent) } - onWidthChanged: { - // TODO: DEN-5603 : Still has some issues on high resolution sliders [ handler jumps to the 0 ]. - // setHandlerPosition() - } } // used loader for performance since it may not always be required. @@ -227,15 +224,7 @@ onDragged: { setValue(vMouseEvent.x, !stepSnapOnRelease) - - //Correct the handle location when dragging update - if(_progressRect.width >= _handler.width/2) - _handler.anchors.horizontalCenterOffset = -_progressRect.leftRightTouchMargin - else - _handler.anchors.horizontalCenterOffset = 0 - - _root.displayedValue = parseInt(Math.round(_root.value / step) * step) - + updateSliderVisuals(false) } onClicked: { setValue(vMouseEvent.x, true) @@ -245,9 +234,7 @@ } onReleased: { setValue(vMouseEvent.x, true) - - _handler.anchors.horizontalCenterOffset = 0 - _root.displayedValue = parseInt(Math.round(_root.value / step) * step) + updateSliderVisuals(true) } Rectangle { id: _handler