aboutsummaryrefslogtreecommitdiffstats
path: root/src/labs/animation/qquickboundaryrule.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/labs/animation/qquickboundaryrule.cpp')
-rw-r--r--src/labs/animation/qquickboundaryrule.cpp128
1 files changed, 57 insertions, 71 deletions
diff --git a/src/labs/animation/qquickboundaryrule.cpp b/src/labs/animation/qquickboundaryrule.cpp
index 3083dd26d2..ead72be187 100644
--- a/src/labs/animation/qquickboundaryrule.cpp
+++ b/src/labs/animation/qquickboundaryrule.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQuick module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qquickboundaryrule_p.h"
@@ -74,10 +38,11 @@ public:
int returnDuration = 100;
QQuickBoundaryRule::OvershootFilter overshootFilter = QQuickBoundaryRule::OvershootFilter::None;
bool enabled = true;
- bool finalized = false;
+ bool completed = false;
qreal easedOvershoot(qreal overshootingValue);
void resetOvershoot();
+ void onAnimationEnded();
};
class QQuickBoundaryReturnJob : public QAbstractAnimationJob
@@ -121,14 +86,13 @@ void QQuickBoundaryReturnJob::updateState(QAbstractAnimationJob::State newState,
if (newState == QAbstractAnimationJob::Stopped) {
qCDebug(lcBR) << "return animation done";
boundaryRule->resetOvershoot();
- boundaryRule->returnAnimationJob = nullptr;
- delete this;
+ boundaryRule->onAnimationEnded();
}
}
/*!
\qmltype BoundaryRule
- \instantiates QQuickBoundaryRule
+//! \instantiates QQuickBoundaryRule
\inqmlmodule Qt.labs.animation
\ingroup qtquick-transitions-animations
\ingroup qtquick-interceptors
@@ -146,7 +110,8 @@ void QQuickBoundaryReturnJob::updateState(QAbstractAnimationJob::State newState,
Note that a property cannot have more than one assigned BoundaryRule.
- \sa {Animation and Transitions in Qt Quick}, {Qt Quick Examples - Animation#Behaviors}{Behavior example}, {Qt QML}
+ \sa {Animation and Transitions in Qt Quick}, {Qt Quick Examples - Animation#Behaviors}{Behavior
+example}, {Qt Qml}, {Qt Quick Examples - Pointer Handlers}
*/
QQuickBoundaryRule::QQuickBoundaryRule(QObject *parent)
@@ -164,7 +129,7 @@ QQuickBoundaryRule::~QQuickBoundaryRule()
}
/*!
- \qmlproperty bool QtQuick::BoundaryRule::enabled
+ \qmlproperty bool Qt.labs.animation::BoundaryRule::enabled
This property holds whether the rule will be enforced when the tracked
property changes value.
@@ -187,7 +152,7 @@ void QQuickBoundaryRule::setEnabled(bool enabled)
}
/*!
- \qmlproperty qreal QtQuick::BoundaryRule::minimum
+ \qmlproperty qreal Qt.labs.animation::BoundaryRule::minimum
This property holds the smallest unconstrained value that the property is
allowed to have. If the property is set to a smaller value, it will be
@@ -211,7 +176,7 @@ void QQuickBoundaryRule::setMinimum(qreal minimum)
}
/*!
- \qmlproperty qreal QtQuick::BoundaryRule::minimumOvershoot
+ \qmlproperty qreal Qt.labs.animation::BoundaryRule::minimumOvershoot
This property holds the amount that the property is allowed to be
less than \l minimum. Whenever the value is less than \l minimum
@@ -237,7 +202,7 @@ void QQuickBoundaryRule::setMinimumOvershoot(qreal minimumOvershoot)
}
/*!
- \qmlproperty qreal QtQuick::BoundaryRule::maximum
+ \qmlproperty qreal Qt.labs.animation::BoundaryRule::maximum
This property holds the largest unconstrained value that the property is
allowed to have. If the property is set to a larger value, it will be
@@ -261,7 +226,7 @@ void QQuickBoundaryRule::setMaximum(qreal maximum)
}
/*!
- \qmlproperty qreal QtQuick::BoundaryRule::maximumOvershoot
+ \qmlproperty qreal Qt.labs.animation::BoundaryRule::maximumOvershoot
This property holds the amount that the property is allowed to be
more than \l maximum. Whenever the value is greater than \l maximum
@@ -287,7 +252,7 @@ void QQuickBoundaryRule::setMaximumOvershoot(qreal maximumOvershoot)
}
/*!
- \qmlproperty qreal QtQuick::BoundaryRule::overshootScale
+ \qmlproperty qreal Qt.labs.animation::BoundaryRule::overshootScale
This property holds the amount by which the \l easing is scaled during the
overshoot condition. For example if an Item is restricted from moving more
@@ -319,7 +284,7 @@ void QQuickBoundaryRule::setOvershootScale(qreal overshootScale)
}
/*!
- \qmlproperty qreal QtQuick::BoundaryRule::currentOvershoot
+ \qmlproperty qreal Qt.labs.animation::BoundaryRule::currentOvershoot
This property holds the amount by which the most recently set value of the
intercepted property exceeds \l maximum or is less than \l minimum.
@@ -335,7 +300,7 @@ qreal QQuickBoundaryRule::currentOvershoot() const
}
/*!
- \qmlproperty qreal QtQuick::BoundaryRule::peakOvershoot
+ \qmlproperty qreal Qt.labs.animation::BoundaryRule::peakOvershoot
This property holds the most-positive or most-negative value of
\l currentOvershoot that has been seen, until \l returnToBounds() is called.
@@ -353,7 +318,7 @@ qreal QQuickBoundaryRule::peakOvershoot() const
}
/*!
- \qmlproperty enum QtQuick::BoundaryRule::overshootFilter
+ \qmlproperty enumeration Qt.labs.animation::BoundaryRule::overshootFilter
This property specifies the aggregation function that will be applied to
the intercepted property value.
@@ -379,7 +344,7 @@ void QQuickBoundaryRule::setOvershootFilter(OvershootFilter overshootFilter)
}
/*!
- \qmlmethod bool QtQuick::BoundaryRule::returnToBounds
+ \qmlmethod bool Qt.labs.animation::BoundaryRule::returnToBounds
Returns the intercepted property to a value between \l minimum and
\l maximum, such that \l currentOvershoot and \l peakOvershoot are both
@@ -387,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()
{
@@ -409,17 +376,30 @@ 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;
}
/*!
- \qmlproperty qreal QtQuick::BoundaryRule::easing
+ \qmlsignal Qt.labs.animation::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 enumeration Qt.labs.animation::BoundaryRule::easing
This property holds the easing curve to be applied in overshoot mode
(whenever the \l minimum or \l maximum constraint is violated, while
@@ -443,7 +423,7 @@ void QQuickBoundaryRule::setEasing(const QEasingCurve &easing)
}
/*!
- \qmlproperty int QtQuick::BoundaryRule::returnDuration
+ \qmlproperty int Qt.labs.animation::BoundaryRule::returnDuration
This property holds the amount of time in milliseconds that
\l returnToBounds() will take to return the target property to the nearest bound.
@@ -467,6 +447,17 @@ void QQuickBoundaryRule::setReturnDuration(int duration)
emit returnDurationChanged();
}
+void QQuickBoundaryRule::classBegin()
+{
+
+}
+
+void QQuickBoundaryRule::componentComplete()
+{
+ Q_D(QQuickBoundaryRule);
+ d->completed = true;
+}
+
void QQuickBoundaryRule::write(const QVariant &value)
{
bool conversionOk = false;
@@ -476,14 +467,13 @@ void QQuickBoundaryRule::write(const QVariant &value)
return;
}
Q_D(QQuickBoundaryRule);
- bool bypass = !d->enabled || !d->finalized || QQmlEnginePrivate::designerMode();
+ bool bypass = !d->enabled || !d->completed || QQmlEnginePrivate::designerMode();
if (bypass) {
QQmlPropertyPrivate::write(d->property, value,
QQmlPropertyData::BypassInterceptor | QQmlPropertyData::DontRemoveBinding);
return;
}
- qmlExecuteDeferred(this);
d->targetValue = d->easedOvershoot(rValue);
QQmlPropertyPrivate::write(d->property, d->targetValue,
QQmlPropertyData::BypassInterceptor | QQmlPropertyData::DontRemoveBinding);
@@ -493,18 +483,6 @@ void QQuickBoundaryRule::setTarget(const QQmlProperty &property)
{
Q_D(QQuickBoundaryRule);
d->property = property;
-
- QQmlEnginePrivate *engPriv = QQmlEnginePrivate::get(qmlEngine(this));
- static int finalizedIdx = -1;
- if (finalizedIdx < 0)
- finalizedIdx = metaObject()->indexOfSlot("componentFinalized()");
- engPriv->registerFinalizeCallback(this, finalizedIdx);
-}
-
-void QQuickBoundaryRule::componentFinalized()
-{
- Q_D(QQuickBoundaryRule);
- d->finalized = true;
}
/*!
@@ -569,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"