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>
This commit is contained in:
Michael Brasser 2018-11-19 10:27:29 -06:00 committed by Michael Brasser
parent 2fa1c92cb7
commit d0a52c72b5
1 changed files with 5 additions and 1 deletions

View File

@ -2403,7 +2403,11 @@ void QQuickPathViewPrivate::snapToIndex(int index, MovementReason reason)
const int duration = highlightMoveDuration; 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); tl.set(moveOffset, targetOffset);
} else if (moveDirection == QQuickPathView::Positive || (moveDirection == QQuickPathView::Shortest && targetOffset - offset > modelCount/2.0)) { } else if (moveDirection == QQuickPathView::Positive || (moveDirection == QQuickPathView::Shortest && targetOffset - offset > modelCount/2.0)) {
qreal distance = modelCount - targetOffset + offset; qreal distance = modelCount - targetOffset + offset;