From d0a52c72b5756787ceb6094117cd71d935badc06 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 19 Nov 2018 10:27:29 -0600 Subject: [PATCH] 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 --- src/quick/items/qquickpathview.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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;