aboutsummaryrefslogtreecommitdiffstats
path: root/src/templates
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2016-02-05 15:19:17 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2016-02-08 10:31:44 +0000
commitf5e0aad26351ecf760458a7fa5866532243f4cb5 (patch)
tree165f3d3b30739cd41cb7af8a6da86e325b73808e /src/templates
parentacacc09f85a4f4bafc05819986de55667fd42111 (diff)
Slider: fix stepSize handling when snapping is enabled
The value range and step size are configurable, whereas position is always in the range [0.0..1.0]. The snap handling was applying step size to the position as is, without taking the value range into account. Thus, snapping worked correctly only for the default [0.0..1.0] value range, which happens to match with the position range. Change-Id: If2f48d36c95554de25598d507842576a49e643b9 Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'src/templates')
-rw-r--r--src/templates/qquickslider.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/templates/qquickslider.cpp b/src/templates/qquickslider.cpp
index b62b8280..b197b4a1 100644
--- a/src/templates/qquickslider.cpp
+++ b/src/templates/qquickslider.cpp
@@ -110,9 +110,15 @@ qreal QQuickSliderPrivate::valueAt(qreal position) const
qreal QQuickSliderPrivate::snapPosition(qreal position) const
{
- if (qFuzzyIsNull(stepSize))
+ const qreal range = from + (to - from);
+ if (qFuzzyIsNull(range))
return position;
- return qRound(position / stepSize) * stepSize;
+
+ const qreal effectiveStep = stepSize / range;
+ if (qFuzzyIsNull(effectiveStep))
+ return position;
+
+ return qRound(position / effectiveStep) * effectiveStep;
}
qreal QQuickSliderPrivate::positionAt(const QPoint &point) const