| 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 | |
| 4 | #ifndef QQUICKSMOOTHEDANIMATION2_P_H |
| 5 | #define QQUICKSMOOTHEDANIMATION2_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include "qquicksmoothedanimation_p.h" |
| 19 | #include "qquickanimation_p.h" |
| 20 | |
| 21 | #include "qquickanimation_p_p.h" |
| 22 | |
| 23 | #include <private/qobject_p.h> |
| 24 | #include <QTimer> |
| 25 | |
| 26 | QT_BEGIN_NAMESPACE |
| 27 | class QSmoothedAnimation; |
| 28 | class QSmoothedAnimationTimer : public QTimer |
| 29 | { |
| 30 | Q_OBJECT |
| 31 | public: |
| 32 | explicit QSmoothedAnimationTimer(QSmoothedAnimation *animation, QObject *parent = nullptr); |
| 33 | ~QSmoothedAnimationTimer(); |
| 34 | public Q_SLOTS: |
| 35 | void stopAnimation(); |
| 36 | private: |
| 37 | QSmoothedAnimation *m_animation; |
| 38 | }; |
| 39 | |
| 40 | class QQuickSmoothedAnimationPrivate; |
| 41 | class Q_AUTOTEST_EXPORT QSmoothedAnimation : public QAbstractAnimationJob |
| 42 | { |
| 43 | Q_DISABLE_COPY(QSmoothedAnimation) |
| 44 | public: |
| 45 | QSmoothedAnimation(QQuickSmoothedAnimationPrivate * = nullptr); |
| 46 | |
| 47 | ~QSmoothedAnimation(); |
| 48 | qreal to; |
| 49 | qreal velocity; |
| 50 | int userDuration; |
| 51 | |
| 52 | int maximumEasingTime; |
| 53 | QQuickSmoothedAnimation::ReversingMode reversingMode; |
| 54 | |
| 55 | qreal initialVelocity; |
| 56 | qreal trackVelocity; |
| 57 | |
| 58 | QQmlProperty target; |
| 59 | |
| 60 | int duration() const override; |
| 61 | void restart(); |
| 62 | void init(); |
| 63 | |
| 64 | void prepareForRestart(); |
| 65 | void clearTemplate() { animationTemplate = nullptr; } |
| 66 | |
| 67 | protected: |
| 68 | void updateCurrentTime(int) override; |
| 69 | void updateState(QAbstractAnimationJob::State, QAbstractAnimationJob::State) override; |
| 70 | void debugAnimation(QDebug d) const override; |
| 71 | |
| 72 | private: |
| 73 | qreal easeFollow(qreal); |
| 74 | qreal initialValue; |
| 75 | |
| 76 | bool invert; |
| 77 | |
| 78 | int finalDuration; |
| 79 | |
| 80 | // Parameters for use in updateCurrentTime() |
| 81 | qreal a; // Acceleration |
| 82 | qreal d; // Deceleration |
| 83 | qreal tf; // Total time |
| 84 | qreal tp; // Time at which peak velocity occurs |
| 85 | qreal td; // Time at which deceleration begins |
| 86 | qreal vp; // Velocity at tp |
| 87 | qreal sp; // Displacement at tp |
| 88 | qreal sd; // Displacement at td |
| 89 | qreal vi; // "Normalized" initialvelocity |
| 90 | qreal s; // Total s |
| 91 | |
| 92 | int lastTime; |
| 93 | bool skipUpdate; |
| 94 | |
| 95 | bool recalc(); |
| 96 | void delayedStop(); |
| 97 | QSmoothedAnimationTimer *delayedStopTimer; |
| 98 | QQuickSmoothedAnimationPrivate *animationTemplate; |
| 99 | }; |
| 100 | |
| 101 | class QQuickSmoothedAnimationPrivate : public QQuickPropertyAnimationPrivate |
| 102 | { |
| 103 | Q_DECLARE_PUBLIC(QQuickSmoothedAnimation) |
| 104 | public: |
| 105 | QQuickSmoothedAnimationPrivate(); |
| 106 | ~QQuickSmoothedAnimationPrivate(); |
| 107 | void updateRunningAnimations(); |
| 108 | |
| 109 | QSmoothedAnimation *anim; |
| 110 | QHash<QQmlProperty, QSmoothedAnimation*> activeAnimations; |
| 111 | }; |
| 112 | |
| 113 | QT_END_NAMESPACE |
| 114 | |
| 115 | #endif // QQUICKSMOOTHEDANIMATION2_P_H |
| 116 |
