aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <mbrasser@ford.com>2018-11-19 10:27:29 -0600
committerMichael Brasser <michael.brasser@live.com>2018-11-29 17:45:39 +0000
commitd0a52c72b5756787ceb6094117cd71d935badc06 (patch)
tree33b7c15f48982e87ab4164f8053b01f4778e4328
parent2fa1c92cb7e60f89e200eff48cf7e76d8d2febe6 (diff)
Prevent overly drawn-out animation when snapping
Don't trigger (potentially seconds long) animation to to fix very small errors in offset. Change-Id: Ibdba16e4fb7a1aff7577a29ab594af8aba231d6d Reviewed-by: Martin Jones <martin.jones@qinetic.com.au>
-rw-r--r--src/quick/items/qquickpathview.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/quick/items/qquickpathview.cpp b/src/quick/items/qquickpathview.cpp
index e7e19b041e..77ed8a659c 100644
--- a/src/quick/items/qquickpathview.cpp
+++ b/src/quick/items/qquickpathview.cpp
@@ -2403,7 +2403,11 @@ void QQuickPathViewPrivate::snapToIndex(int index, MovementReason reason)
const int duration = highlightMoveDuration;
- if (!duration) {
+ const qreal count = pathItems == -1 ? modelCount : qMin(pathItems, modelCount);
+ const qreal averageItemLength = path->path().length() / count;
+ const qreal threshold = 0.5 / averageItemLength; // if we are within .5 px, we want to immediately assign rather than animate
+
+ if (!duration || qAbs(offset - targetOffset) < threshold || (qFuzzyIsNull(targetOffset) && qAbs(modelCount - offset) < threshold)) {
tl.set(moveOffset, targetOffset);
} else if (moveDirection == QQuickPathView::Positive || (moveDirection == QQuickPathView::Shortest && targetOffset - offset > modelCount/2.0)) {
qreal distance = modelCount - targetOffset + offset;