From a2aff9c3c8800d265757d5171cb4f39c81328edd Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 8 Feb 2016 12:51:09 +0100 Subject: RangeSlider: fix stepSize handling when snapping is enabled Same as the recent fix for Slider. The step size needs to be normalized when added to or subtracted from the position. Change-Id: I490d105f88db361fb0e1888017e1717e9d79e4c8 Reviewed-by: Mitch Curtis --- src/templates/qquickrangeslider.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/templates') diff --git a/src/templates/qquickrangeslider.cpp b/src/templates/qquickrangeslider.cpp index 4bb320cf..5fae3ae5 100644 --- a/src/templates/qquickrangeslider.cpp +++ b/src/templates/qquickrangeslider.cpp @@ -323,10 +323,15 @@ static qreal valueAt(const QQuickRangeSlider *slider, qreal position) static qreal snapPosition(const QQuickRangeSlider *slider, qreal position) { - const qreal stepSize = slider->stepSize(); - if (qFuzzyIsNull(stepSize)) + const qreal range = slider->from() + (slider->to() - slider->from()); + if (qFuzzyIsNull(range)) return position; - return qRound(position / stepSize) * stepSize; + + const qreal effectiveStep = slider->stepSize() / range; + if (qFuzzyIsNull(effectiveStep)) + return position; + + return qRound(position / effectiveStep) * effectiveStep; } static qreal positionAt(const QQuickRangeSlider *slider, QQuickItem *handle, const QPoint &point) -- cgit v1.2.3