From 057fc4b5b037284ffe299a28725fcf59c7ac066f Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 27 Apr 2017 11:11:49 +0200 Subject: FakeFlickable: animate returnToBounds() when flicking is done It looks much nicer than just jerking back into position. We still don't have "resistance" to dragging past the bounds, though. Change-Id: I60f6f58fe87638fd17144ea6640bae673a3b633d Reviewed-by: Shawn Rutledge --- tests/manual/pointer/content/FakeFlickable.qml | 49 +++++++++++++++++++++----- 1 file changed, 41 insertions(+), 8 deletions(-) (limited to 'tests/manual') diff --git a/tests/manual/pointer/content/FakeFlickable.qml b/tests/manual/pointer/content/FakeFlickable.qml index bfae653503..801b6b9f31 100644 --- a/tests/manual/pointer/content/FakeFlickable.qml +++ b/tests/manual/pointer/content/FakeFlickable.qml @@ -62,14 +62,23 @@ Item { property real ylimit: root.height - __contentItem.height function returnToBounds() { - if (x > 0) - x = 0 - else if (x < xlimit) - x = xlimit - if (y > 0) - y = 0 - else if (y < ylimit) - y = ylimit + var startAnim = false + if (x > 0) { + returnToBoundsAnim.x = 0 + startAnim = true + } else if (x < xlimit) { + returnToBoundsAnim.x = xlimit + startAnim = true + } + if (y > 0) { + returnToBoundsAnim.y = 0 + startAnim = true + } else if (y < ylimit) { + returnToBoundsAnim.y = ylimit + startAnim = true + } + if (startAnim) + returnToBoundsAnim.start() } DragHandler { @@ -85,5 +94,29 @@ Item { root.flickEnded() } } + ParallelAnimation { + id: returnToBoundsAnim + property Item target: __contentItem + property int duration: 200 + property real x: 0 + property real y: 0 + + NumberAnimation { + id: xAnim + target: returnToBoundsAnim.target + property: "x" + to: returnToBoundsAnim.x + duration: returnToBoundsAnim.duration + easing.type: Easing.OutQuad + } + NumberAnimation { + id: yAnim + target: returnToBoundsAnim.target + property: "y" + to: returnToBoundsAnim.y + duration: returnToBoundsAnim.duration + easing.type: Easing.OutQuad + } + } } } -- cgit v1.2.3