Port QVariantAnimation to the new property system
Skipped startValue/endValue properties, since they are computed and writable, which is not supported at the moment. Skipped currentValue, since its setter might be called inside the getter, which is not recommended. Task-number: QTBUG-85520 Change-Id: I1f872b4fcc7227ed91b6915891bbc66019151826 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Andreas Buhr <andreas.buhr@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
0d76a5cd2c
commit
7a1fdcedfc
@ -230,7 +230,8 @@ void QVariantAnimationPrivate::recalculateCurrentInterval(bool force/*=false*/)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
const qreal endProgress = (direction == QAbstractAnimation::Forward) ? qreal(1) : qreal(0);
|
const qreal endProgress = (direction == QAbstractAnimation::Forward) ? qreal(1) : qreal(0);
|
||||||
const qreal progress = easing.valueForProgress(((duration == 0) ? endProgress : qreal(currentTime) / qreal(duration)));
|
const qreal progress = easing.value().valueForProgress(
|
||||||
|
duration == 0 ? endProgress : qreal(currentTime) / qreal(duration));
|
||||||
|
|
||||||
//0 and 1 are still the boundaries
|
//0 and 1 are still the boundaries
|
||||||
if (force || (currentInterval.start.first > 0 && progress < currentInterval.start.first)
|
if (force || (currentInterval.start.first > 0 && progress < currentInterval.start.first)
|
||||||
@ -386,8 +387,17 @@ QEasingCurve QVariantAnimation::easingCurve() const
|
|||||||
void QVariantAnimation::setEasingCurve(const QEasingCurve &easing)
|
void QVariantAnimation::setEasingCurve(const QEasingCurve &easing)
|
||||||
{
|
{
|
||||||
Q_D(QVariantAnimation);
|
Q_D(QVariantAnimation);
|
||||||
|
const bool valueChanged = easing != d->easing;
|
||||||
d->easing = easing;
|
d->easing = easing;
|
||||||
d->recalculateCurrentInterval();
|
d->recalculateCurrentInterval();
|
||||||
|
if (valueChanged)
|
||||||
|
d->easing.notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
QBindable<QEasingCurve> QVariantAnimation::bindableEasingCurve()
|
||||||
|
{
|
||||||
|
Q_D(QVariantAnimation);
|
||||||
|
return &d->easing;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef QList<QVariantAnimation::Interpolator> QInterpolatorVector;
|
typedef QList<QVariantAnimation::Interpolator> QInterpolatorVector;
|
||||||
@ -506,10 +516,19 @@ void QVariantAnimation::setDuration(int msecs)
|
|||||||
qWarning("QVariantAnimation::setDuration: cannot set a negative duration");
|
qWarning("QVariantAnimation::setDuration: cannot set a negative duration");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (d->duration == msecs)
|
if (d->duration == msecs) {
|
||||||
|
d->duration.removeBindingUnlessInWrapper();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
d->duration = msecs;
|
d->duration = msecs;
|
||||||
d->recalculateCurrentInterval();
|
d->recalculateCurrentInterval();
|
||||||
|
d->duration.notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
QBindable<int> QVariantAnimation::bindableDuration()
|
||||||
|
{
|
||||||
|
Q_D(QVariantAnimation);
|
||||||
|
return &d->duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -57,8 +57,9 @@ class Q_CORE_EXPORT QVariantAnimation : public QAbstractAnimation
|
|||||||
Q_PROPERTY(QVariant startValue READ startValue WRITE setStartValue)
|
Q_PROPERTY(QVariant startValue READ startValue WRITE setStartValue)
|
||||||
Q_PROPERTY(QVariant endValue READ endValue WRITE setEndValue)
|
Q_PROPERTY(QVariant endValue READ endValue WRITE setEndValue)
|
||||||
Q_PROPERTY(QVariant currentValue READ currentValue NOTIFY valueChanged)
|
Q_PROPERTY(QVariant currentValue READ currentValue NOTIFY valueChanged)
|
||||||
Q_PROPERTY(int duration READ duration WRITE setDuration)
|
Q_PROPERTY(int duration READ duration WRITE setDuration BINDABLE bindableDuration)
|
||||||
Q_PROPERTY(QEasingCurve easingCurve READ easingCurve WRITE setEasingCurve)
|
Q_PROPERTY(QEasingCurve easingCurve READ easingCurve WRITE setEasingCurve
|
||||||
|
BINDABLE bindableEasingCurve)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef QPair<qreal, QVariant> KeyValue;
|
typedef QPair<qreal, QVariant> KeyValue;
|
||||||
@ -83,9 +84,11 @@ public:
|
|||||||
|
|
||||||
int duration() const override;
|
int duration() const override;
|
||||||
void setDuration(int msecs);
|
void setDuration(int msecs);
|
||||||
|
QBindable<int> bindableDuration();
|
||||||
|
|
||||||
QEasingCurve easingCurve() const;
|
QEasingCurve easingCurve() const;
|
||||||
void setEasingCurve(const QEasingCurve &easing);
|
void setEasingCurve(const QEasingCurve &easing);
|
||||||
|
QBindable<QEasingCurve> bindableEasingCurve();
|
||||||
|
|
||||||
typedef QVariant (*Interpolator)(const void *from, const void *to, qreal progress);
|
typedef QVariant (*Interpolator)(const void *from, const void *to, qreal progress);
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@
|
|||||||
#include <QtCore/qmetaobject.h>
|
#include <QtCore/qmetaobject.h>
|
||||||
|
|
||||||
#include "private/qabstractanimation_p.h"
|
#include "private/qabstractanimation_p.h"
|
||||||
|
#include "private/qproperty_p.h"
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
@ -87,8 +88,14 @@ public:
|
|||||||
QVariantAnimation::KeyValue start, end;
|
QVariantAnimation::KeyValue start, end;
|
||||||
} currentInterval;
|
} currentInterval;
|
||||||
|
|
||||||
QEasingCurve easing;
|
void setEasingCurve(const QEasingCurve &easing) { q_func()->setEasingCurve(easing); }
|
||||||
int duration;
|
Q_OBJECT_COMPAT_PROPERTY(QVariantAnimationPrivate, QEasingCurve, easing,
|
||||||
|
&QVariantAnimationPrivate::setEasingCurve)
|
||||||
|
|
||||||
|
void setDuration(int msecs) { q_func()->setDuration(msecs); }
|
||||||
|
Q_OBJECT_COMPAT_PROPERTY(QVariantAnimationPrivate, int, duration,
|
||||||
|
&QVariantAnimationPrivate::setDuration)
|
||||||
|
|
||||||
QVariantAnimation::KeyValues keyValues;
|
QVariantAnimation::KeyValues keyValues;
|
||||||
QVariantAnimation::Interpolator interpolator;
|
QVariantAnimation::Interpolator interpolator;
|
||||||
|
|
||||||
|
@ -7,4 +7,6 @@
|
|||||||
qt_internal_add_test(tst_qvariantanimation
|
qt_internal_add_test(tst_qvariantanimation
|
||||||
SOURCES
|
SOURCES
|
||||||
tst_qvariantanimation.cpp
|
tst_qvariantanimation.cpp
|
||||||
|
LIBRARIES
|
||||||
|
Qt::TestPrivate
|
||||||
)
|
)
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#include <QtCore/qvariantanimation.h>
|
#include <QtCore/qvariantanimation.h>
|
||||||
#include <QTest>
|
#include <QTest>
|
||||||
|
#include <QtTest/private/qpropertytesthelper_p.h>
|
||||||
|
|
||||||
class tst_QVariantAnimation : public QObject
|
class tst_QVariantAnimation : public QObject
|
||||||
{
|
{
|
||||||
@ -44,6 +45,8 @@ private slots:
|
|||||||
void keyValues();
|
void keyValues();
|
||||||
void duration();
|
void duration();
|
||||||
void interpolation();
|
void interpolation();
|
||||||
|
void durationBindings();
|
||||||
|
void easingCurveBindings();
|
||||||
};
|
};
|
||||||
|
|
||||||
class TestableQVariantAnimation : public QVariantAnimation
|
class TestableQVariantAnimation : public QVariantAnimation
|
||||||
@ -154,6 +157,32 @@ void tst_QVariantAnimation::interpolation()
|
|||||||
QCOMPARE(pointAnim.currentValue().toPoint(), QPoint(50, 50));
|
QCOMPARE(pointAnim.currentValue().toPoint(), QPoint(50, 50));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QVariantAnimation::durationBindings()
|
||||||
|
{
|
||||||
|
QVariantAnimation animation;
|
||||||
|
|
||||||
|
// duration property
|
||||||
|
QProperty<int> duration;
|
||||||
|
animation.bindableDuration().setBinding(Qt::makePropertyBinding(duration));
|
||||||
|
|
||||||
|
// negative values must be ignored
|
||||||
|
QTest::ignoreMessage(QtWarningMsg,
|
||||||
|
"QVariantAnimation::setDuration: cannot set a negative duration");
|
||||||
|
duration = -1;
|
||||||
|
QVERIFY(animation.duration() != duration);
|
||||||
|
|
||||||
|
QTestPrivate::testReadWritePropertyBasics(animation, 42, 43, "duration");
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QVariantAnimation::easingCurveBindings()
|
||||||
|
{
|
||||||
|
QVariantAnimation animation;
|
||||||
|
|
||||||
|
QTestPrivate::testReadWritePropertyBasics(animation, QEasingCurve(QEasingCurve::InQuad),
|
||||||
|
QEasingCurve(QEasingCurve::BezierSpline),
|
||||||
|
"easingCurve");
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QVariantAnimation)
|
QTEST_MAIN(tst_QVariantAnimation)
|
||||||
|
|
||||||
#include "tst_qvariantanimation.moc"
|
#include "tst_qvariantanimation.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user