diff options
| author | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-08-31 17:47:55 +0200 |
|---|---|---|
| committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-09-06 07:25:55 +0200 |
| commit | 7673a4d117af634abd84b3462d97207fa107a821 (patch) | |
| tree | 3df734ffc6dbe4b5dbbf549f9e2991ba62cf9959 /src/labs/animation/qquickboundaryrule.cpp | |
| parent | 70e6d671bcca0b8f11de9dcd62ccab6b51d41722 (diff) | |
Add BoundaryRule.returnedToBounds signal
If QML code needs to do something (like re-render an image at a
different resolution) when the returnToBounds() animation is completed,
it's more convenient, performant and reliable to write
BoundaryRule {
...
onReturnedToBounds: { ... }
}
rather than
BoundaryRule {
onCurrentOvershootChanged:
if (currentOvershoot === 0) { ... }
}
[ChangeLog][Qt Labs Animation] BoundaryRule now has a returnedToBounds
signal.
Fixes: QTBUG-105107
Change-Id: Ieb8b990d6d01b652b43bc673c35e8f86cb2d582a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/labs/animation/qquickboundaryrule.cpp')
| -rw-r--r-- | src/labs/animation/qquickboundaryrule.cpp | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/src/labs/animation/qquickboundaryrule.cpp b/src/labs/animation/qquickboundaryrule.cpp index fbf82023bc..973a6d3ac4 100644 --- a/src/labs/animation/qquickboundaryrule.cpp +++ b/src/labs/animation/qquickboundaryrule.cpp @@ -42,6 +42,7 @@ public: qreal easedOvershoot(qreal overshootingValue); void resetOvershoot(); + void onAnimationEnded(); }; class QQuickBoundaryReturnJob : public QAbstractAnimationJob @@ -85,8 +86,7 @@ void QQuickBoundaryReturnJob::updateState(QAbstractAnimationJob::State newState, if (newState == QAbstractAnimationJob::Stopped) { qCDebug(lcBR) << "return animation done"; boundaryRule->resetOvershoot(); - boundaryRule->returnAnimationJob = nullptr; - delete this; + boundaryRule->onAnimationEnded(); } } @@ -352,6 +352,8 @@ void QQuickBoundaryRule::setOvershootFilter(OvershootFilter overshootFilter) Returns true if the value needed to be adjusted, or false if it was already within bounds. + + \sa returnedToBounds */ bool QQuickBoundaryRule::returnToBounds() { @@ -374,16 +376,29 @@ bool QQuickBoundaryRule::returnToBounds() return false; } if (d->returnAnimationJob) { - qCDebug(lcBR) << "animating from" << d->returnAnimationJob->fromValue << "to" << d->returnAnimationJob->toValue; + qCDebug(lcBR) << d->property.name() << "on" << d->property.object() + << ": animating from" << d->returnAnimationJob->fromValue << "to" << d->returnAnimationJob->toValue; d->returnAnimationJob->start(); } else { d->resetOvershoot(); - qCDebug(lcBR) << "returned to" << d->property.read(); + qCDebug(lcBR) << d->property.name() << "on" << d->property.object() << ": returned to" << d->property.read(); + emit returnedToBounds(); } return true; } /*! + \qmlsignal QtQuick::BoundaryRule::returnedToBounds() + + This signal is emitted when \l currentOvershoot returns to \c 0 again, + after the \l maximum or \l minimum constraint has been violated. + If the return is animated, the signal is emitted when the animation + completes. + + \sa returnDuration, returnToBounds() +*/ + +/*! \qmlproperty qreal QtQuick::BoundaryRule::easing This property holds the easing curve to be applied in overshoot mode @@ -532,6 +547,14 @@ void QQuickBoundaryRulePrivate::resetOvershoot() } } +void QQuickBoundaryRulePrivate::onAnimationEnded() +{ + Q_Q(QQuickBoundaryRule); + delete returnAnimationJob; + returnAnimationJob = nullptr; + emit q->returnedToBounds(); +} + QT_END_NAMESPACE #include "moc_qquickboundaryrule_p.cpp" |
