| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | // Qt-Security score:significant reason:default |
| 4 | |
| 5 | #ifndef QVARIANTANIMATION_H |
| 6 | #define QVARIANTANIMATION_H |
| 7 | |
| 8 | #include <QtCore/qabstractanimation.h> |
| 9 | #include <QtCore/qeasingcurve.h> |
| 10 | #include <QtCore/qlist.h> |
| 11 | #include <QtCore/qpair.h> |
| 12 | #include <QtCore/qvariant.h> |
| 13 | |
| 14 | QT_REQUIRE_CONFIG(animation); |
| 15 | |
| 16 | QT_BEGIN_NAMESPACE |
| 17 | |
| 18 | class QVariantAnimationPrivate; |
| 19 | class Q_CORE_EXPORT QVariantAnimation : public QAbstractAnimation |
| 20 | { |
| 21 | Q_OBJECT |
| 22 | Q_PROPERTY(QVariant startValue READ startValue WRITE setStartValue) |
| 23 | Q_PROPERTY(QVariant endValue READ endValue WRITE setEndValue) |
| 24 | Q_PROPERTY(QVariant currentValue READ currentValue NOTIFY valueChanged) |
| 25 | Q_PROPERTY(int duration READ duration WRITE setDuration BINDABLE bindableDuration) |
| 26 | Q_PROPERTY(QEasingCurve easingCurve READ easingCurve WRITE setEasingCurve |
| 27 | BINDABLE bindableEasingCurve) |
| 28 | |
| 29 | public: |
| 30 | using KeyValue = std::pair<qreal, QVariant>; |
| 31 | typedef QList<KeyValue> KeyValues; |
| 32 | |
| 33 | QVariantAnimation(QObject *parent = nullptr); |
| 34 | ~QVariantAnimation(); |
| 35 | |
| 36 | QVariant startValue() const; |
| 37 | void setStartValue(const QVariant &value); |
| 38 | |
| 39 | QVariant endValue() const; |
| 40 | void setEndValue(const QVariant &value); |
| 41 | |
| 42 | QVariant keyValueAt(qreal step) const; |
| 43 | void setKeyValueAt(qreal step, const QVariant &value); |
| 44 | |
| 45 | KeyValues keyValues() const; |
| 46 | void setKeyValues(const KeyValues &values); |
| 47 | |
| 48 | QVariant currentValue() const; |
| 49 | |
| 50 | int duration() const override; |
| 51 | void setDuration(int msecs); |
| 52 | QBindable<int> bindableDuration(); |
| 53 | |
| 54 | QEasingCurve easingCurve() const; |
| 55 | void setEasingCurve(const QEasingCurve &easing); |
| 56 | QBindable<QEasingCurve> bindableEasingCurve(); |
| 57 | |
| 58 | typedef QVariant (*Interpolator)(const void *from, const void *to, qreal progress); |
| 59 | |
| 60 | Q_SIGNALS: |
| 61 | void valueChanged(const QVariant &value); |
| 62 | |
| 63 | protected: |
| 64 | QVariantAnimation(QVariantAnimationPrivate &dd, QObject *parent = nullptr); |
| 65 | bool event(QEvent *event) override; |
| 66 | |
| 67 | void updateCurrentTime(int) override; |
| 68 | void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) override; |
| 69 | |
| 70 | virtual void updateCurrentValue(const QVariant &value); |
| 71 | virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const; |
| 72 | |
| 73 | private: |
| 74 | template <typename T> friend void qRegisterAnimationInterpolator(QVariant (*func)(const T &, const T &, qreal)); |
| 75 | static void registerInterpolator(Interpolator func, int interpolationType); |
| 76 | |
| 77 | Q_DISABLE_COPY(QVariantAnimation) |
| 78 | Q_DECLARE_PRIVATE(QVariantAnimation) |
| 79 | }; |
| 80 | |
| 81 | template <typename T> |
| 82 | void qRegisterAnimationInterpolator(QVariant (*func)(const T &from, const T &to, qreal progress)) { |
| 83 | QVariantAnimation::registerInterpolator(func: reinterpret_cast<QVariantAnimation::Interpolator>(reinterpret_cast<void(*)()>(func)), interpolationType: qMetaTypeId<T>()); |
| 84 | } |
| 85 | |
| 86 | QT_END_NAMESPACE |
| 87 | |
| 88 | #endif //QVARIANTANIMATION_H |
| 89 | |