diff options
author | Riku Palomäki <riku@palomaki.fi> | 2015-10-21 22:13:19 +0300 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2016-08-18 13:36:44 +0000 |
commit | 96bd2337a98c892b5def555163c491507dce7185 (patch) | |
tree | 83fe9de9c7a6f873c84fde54ba96ab0443bba62b /src/quick/items/qquickflickable.cpp | |
parent | b5f9c1e6e7f3a6881874e4ec2f43cea68107a06b (diff) |
Flickable: Fixed rounding errors with contentX/Y
contentX/Y are qreals, but they are rounded using qRound/qFloor/qCeil
which will limit the values to 2^31 needlessly. This fix will use
(std::)round, std::floor and std::ceil instead to allow bigger values for
contentX and contentY.
Change-Id: I35ad4bcfa3b8bbc21e90768d348d3002ca400081
Task-number: QTBUG-48018
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quick/items/qquickflickable.cpp')
-rw-r--r-- | src/quick/items/qquickflickable.cpp | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/quick/items/qquickflickable.cpp b/src/quick/items/qquickflickable.cpp index 31581c0f07..0333f6b9bd 100644 --- a/src/quick/items/qquickflickable.cpp +++ b/src/quick/items/qquickflickable.cpp @@ -55,6 +55,8 @@ #include <QtCore/qmath.h> #include "qplatformdefs.h" +#include <cmath> + QT_BEGIN_NAMESPACE // FlickThreshold determines how far the "mouse" must have moved @@ -69,6 +71,21 @@ static const int RetainGrabVelocity = 100; static const int MovementEndingTimerInterval = 100; #endif +// Currently std::round can't be used on Android when using ndk g++, so +// use C version instead. We could just define two versions of Round, one +// for float and one for double, but then only one of them would be used +// and compiler would trigger a warning about unused function. +// +// See https://code.google.com/p/android/issues/detail?id=54418 +template<typename T> +static T Round(T t) { + return round(t); +} +template<> +Q_DECL_UNUSED float Round<float>(float f) { + return roundf(f); +} + static qreal EaseOvershoot(qreal t) { return qAtan(t); } @@ -351,7 +368,7 @@ bool QQuickFlickablePrivate::flick(AxisData &data, qreal minExtent, qreal maxExt qreal dist = v2 / (accel * 2.0); if (v > 0) dist = -dist; - qreal target = -qRound(-(data.move.value() - dist)); + qreal target = -Round(-(data.move.value() - dist)); dist = -target + data.move.value(); accel = v2 / (2.0f * qAbs(dist)); @@ -455,18 +472,18 @@ void QQuickFlickablePrivate::fixup(AxisData &data, qreal minExtent, qreal maxExt } else if (data.move.value() <= maxExtent) { resetTimeline(data); adjustContentPos(data, maxExtent); - } else if (-qRound(-data.move.value()) != data.move.value()) { + } else if (-Round(-data.move.value()) != data.move.value()) { // We could animate, but since it is less than 0.5 pixel it's probably not worthwhile. resetTimeline(data); qreal val = data.move.value(); - if (qAbs(-qRound(-val) - val) < 0.25) // round small differences - val = -qRound(-val); + if (std::abs(-Round(-val) - val) < 0.25) // round small differences + val = -Round(-val); else if (data.smoothVelocity.value() > 0) // continue direction of motion for larger - val = -qFloor(-val); + val = -std::floor(-val); else if (data.smoothVelocity.value() < 0) - val = -qCeil(-val); + val = -std::ceil(-val); else // otherwise round - val = -qRound(-val); + val = -Round(-val); timeline.set(data.move, val); } data.inOvershoot = false; @@ -1553,12 +1570,12 @@ void QQuickFlickablePrivate::replayDelayedPress() //XXX pixelAligned ignores the global position of the Flickable, i.e. assumes Flickable itself is pixel aligned. void QQuickFlickablePrivate::setViewportX(qreal x) { - contentItem->setX(pixelAligned ? -qRound(-x) : x); + contentItem->setX(pixelAligned ? -Round(-x) : x); } void QQuickFlickablePrivate::setViewportY(qreal y) { - contentItem->setY(pixelAligned ? -qRound(-y) : y); + contentItem->setY(pixelAligned ? -Round(-y) : y); } void QQuickFlickable::timerEvent(QTimerEvent *event) |