Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:07:41

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QVARIANTANIMATION_H
0005 #define QVARIANTANIMATION_H
0006 
0007 #include <QtCore/qabstractanimation.h>
0008 #include <QtCore/qeasingcurve.h>
0009 #include <QtCore/qlist.h>
0010 #include <QtCore/qpair.h>
0011 #include <QtCore/qvariant.h>
0012 
0013 QT_REQUIRE_CONFIG(animation);
0014 
0015 QT_BEGIN_NAMESPACE
0016 
0017 class QVariantAnimationPrivate;
0018 class Q_CORE_EXPORT QVariantAnimation : public QAbstractAnimation
0019 {
0020     Q_OBJECT
0021     Q_PROPERTY(QVariant startValue READ startValue WRITE setStartValue)
0022     Q_PROPERTY(QVariant endValue READ endValue WRITE setEndValue)
0023     Q_PROPERTY(QVariant currentValue READ currentValue NOTIFY valueChanged)
0024     Q_PROPERTY(int duration READ duration WRITE setDuration BINDABLE bindableDuration)
0025     Q_PROPERTY(QEasingCurve easingCurve READ easingCurve WRITE setEasingCurve
0026                BINDABLE bindableEasingCurve)
0027 
0028 public:
0029     using KeyValue = std::pair<qreal, QVariant>;
0030     typedef QList<KeyValue> KeyValues;
0031 
0032     QVariantAnimation(QObject *parent = nullptr);
0033     ~QVariantAnimation();
0034 
0035     QVariant startValue() const;
0036     void setStartValue(const QVariant &value);
0037 
0038     QVariant endValue() const;
0039     void setEndValue(const QVariant &value);
0040 
0041     QVariant keyValueAt(qreal step) const;
0042     void setKeyValueAt(qreal step, const QVariant &value);
0043 
0044     KeyValues keyValues() const;
0045     void setKeyValues(const KeyValues &values);
0046 
0047     QVariant currentValue() const;
0048 
0049     int duration() const override;
0050     void setDuration(int msecs);
0051     QBindable<int> bindableDuration();
0052 
0053     QEasingCurve easingCurve() const;
0054     void setEasingCurve(const QEasingCurve &easing);
0055     QBindable<QEasingCurve> bindableEasingCurve();
0056 
0057     typedef QVariant (*Interpolator)(const void *from, const void *to, qreal progress);
0058 
0059 Q_SIGNALS:
0060     void valueChanged(const QVariant &value);
0061 
0062 protected:
0063     QVariantAnimation(QVariantAnimationPrivate &dd, QObject *parent = nullptr);
0064     bool event(QEvent *event) override;
0065 
0066     void updateCurrentTime(int) override;
0067     void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) override;
0068 
0069     virtual void updateCurrentValue(const QVariant &value);
0070     virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const;
0071 
0072 private:
0073     template <typename T> friend void qRegisterAnimationInterpolator(QVariant (*func)(const T &, const T &, qreal));
0074     static void registerInterpolator(Interpolator func, int interpolationType);
0075 
0076     Q_DISABLE_COPY(QVariantAnimation)
0077     Q_DECLARE_PRIVATE(QVariantAnimation)
0078 };
0079 
0080 template <typename T>
0081 void qRegisterAnimationInterpolator(QVariant (*func)(const T &from, const T &to, qreal progress)) {
0082     QVariantAnimation::registerInterpolator(reinterpret_cast<QVariantAnimation::Interpolator>(reinterpret_cast<void(*)()>(func)), qMetaTypeId<T>());
0083 }
0084 
0085 QT_END_NAMESPACE
0086 
0087 #endif //QVARIANTANIMATION_H