From bb594453f9cb96bf8f2975d4a8aa5379cfc46e23 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Sat, 25 Jun 2016 12:16:25 +0200 Subject: Flickable: add horizontal/verticalOvershoot properties [ChangeLog][QtQuick][Flickable] Added horizontalOvershoot and verticalOvershoot properties that can be used for implementing boundary actions and effects. Task-number: QTBUG-38515 Change-Id: I06379348a67d03507b56788d6fc7020bbb2d375f Reviewed-by: Robin Burchell --- src/quick/items/qquickflickable.cpp | 80 ++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 2 deletions(-) (limited to 'src/quick/items/qquickflickable.cpp') diff --git a/src/quick/items/qquickflickable.cpp b/src/quick/items/qquickflickable.cpp index 00a1306627..4ab604b30f 100644 --- a/src/quick/items/qquickflickable.cpp +++ b/src/quick/items/qquickflickable.cpp @@ -1570,12 +1570,52 @@ 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 ? -Round(-x) : x); + Q_Q(QQuickFlickable); + if (pixelAligned) + x = -Round(-x); + + contentItem->setX(x); + if (contentItem->x() != x) + return; // reentered + + const qreal maxX = q->maxXExtent(); + const qreal minX = q->minXExtent(); + + qreal overshoot = 0.0; + if (x <= maxX) + overshoot = maxX - x; + else if (x >= minX) + overshoot = minX - x; + + if (overshoot != hData.overshoot) { + hData.overshoot = overshoot; + emit q->horizontalOvershootChanged(); + } } void QQuickFlickablePrivate::setViewportY(qreal y) { - contentItem->setY(pixelAligned ? -Round(-y) : y); + Q_Q(QQuickFlickable); + if (pixelAligned) + y = -Round(-y); + + contentItem->setY(y); + if (contentItem->y() != y) + return; // reentered + + const qreal maxY = q->maxYExtent(); + const qreal minY = q->minYExtent(); + + qreal overshoot = 0.0; + if (y <= maxY) + overshoot = maxY - y; + else if (y >= minY) + overshoot = minY - y; + + if (overshoot != vData.overshoot) { + vData.overshoot = overshoot; + emit q->verticalOvershootChanged(); + } } void QQuickFlickable::timerEvent(QTimerEvent *event) @@ -1841,6 +1881,8 @@ QQmlListProperty QQuickFlickable::flickableChildren() beyond the boundary of the Flickable, and can overshoot the boundary when flicked. \endlist + + \sa horizontalOvershoot, verticalOvershoot */ QQuickFlickable::BoundsBehavior QQuickFlickable::boundsBehavior() const { @@ -2638,4 +2680,38 @@ void QQuickFlickablePrivate::updateVelocity() emit q->verticalVelocityChanged(); } +/*! + \qmlproperty real QtQuick::Flickable::horizontalOvershoot + \since 5.9 + + This property holds the horizontal overshoot, that is, the horizontal distance by + which the contents has been dragged or flicked past the bounds of the flickable. + The value is negative when the content is dragged or flicked beyond the beginning, + and positive when beyond the end; \c 0.0 otherwise. + + \sa verticalOvershoot, boundsBehavior +*/ +qreal QQuickFlickable::horizontalOvershoot() const +{ + Q_D(const QQuickFlickable); + return d->hData.overshoot; +} + +/*! + \qmlproperty real QtQuick::Flickable::verticalOvershoot + \since 5.9 + + This property holds the vertical overshoot, that is, the vertical distance by + which the contents has been dragged or flicked past the bounds of the flickable. + The value is negative when the content is dragged or flicked beyond the beginning, + and positive when beyond the end; \c 0.0 otherwise. + + \sa horizontalOvershoot, boundsBehavior +*/ +qreal QQuickFlickable::verticalOvershoot() const +{ + Q_D(const QQuickFlickable); + return d->vData.overshoot; +} + QT_END_NAMESPACE -- cgit v1.2.3