diff options
author | Giulio Camuffo <giulio.camuffo@jollamobile.com> | 2014-09-09 15:06:36 +0300 |
---|---|---|
committer | Giulio Camuffo <giulio.camuffo@jollamobile.com> | 2014-10-09 16:38:00 +0200 |
commit | 8c3d661163fc7517569f1a70ab70c2b23de25406 (patch) | |
tree | 14d9039a515ed73a589d2b9fa5959398408d2a30 | |
parent | e157af88554a694ffa550ead5187649a29b5dda8 (diff) |
Return the content position rounded on the right side
QQuickFlickable::contentX/Y() returns the negative of the value
stored in the QQuickTimeLineValue used by QQuickFlickable.
So we must be careful when using things like qRound, and call it
with the negative of the value ine the QQuickTimeLineValue, else
code like this would fail:
QQuickFlickable *f = ...
f->setPixelAligned(true)
f->setContentY(-10.5)
assert(f->contentY() == qRound(-10.5)) // fail
The assert expression indeed turns into -11 == -10, which is false
but which is not what the user would expect.
Change-Id: Ib92ee2fa613b751462237349d9e4e2f2b4652f82
Reviewed-by: Martin Jones <martin.jones@qinetic.com.au>
-rw-r--r-- | src/quick/items/qquickflickable.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/quick/items/qquickflickable.cpp b/src/quick/items/qquickflickable.cpp index c6b7e5a35a..9f1de39186 100644 --- a/src/quick/items/qquickflickable.cpp +++ b/src/quick/items/qquickflickable.cpp @@ -334,7 +334,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 = -qRound(-(data.move.value() - dist)); dist = -target + data.move.value(); accel = v2 / (2.0f * qAbs(dist)); @@ -436,18 +436,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 (-qRound(-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 (qAbs(-qRound(-val) - val) < 0.25) // round small differences + val = -qRound(-val); else if (data.smoothVelocity.value() > 0) // continue direction of motion for larger - val = qFloor(val); + val = -qFloor(-val); else if (data.smoothVelocity.value() < 0) - val = qCeil(val); + val = -qCeil(-val); else // otherwise round - val = qRound(val); + val = -qRound(-val); timeline.set(data.move, val); } data.inOvershoot = false; @@ -1374,12 +1374,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 ? -qRound(-x) : x); } void QQuickFlickablePrivate::setViewportY(qreal y) { - contentItem->setY(pixelAligned ? qRound(y) : y); + contentItem->setY(pixelAligned ? -qRound(-y) : y); } void QQuickFlickable::timerEvent(QTimerEvent *event) |