aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/util/qquicksmoothedanimation_p_p.h
blob: 2e0fe5be15db6d7350cc7a475a17f43a55e95f2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright (C) 2016 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

#ifndef QQUICKSMOOTHEDANIMATION2_P_H
#define QQUICKSMOOTHEDANIMATION2_P_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include "qquicksmoothedanimation_p.h"
#include "qquickanimation_p.h"

#include "qquickanimation_p_p.h"

#include <private/qobject_p.h>
#include <QBasicTimer>

QT_BEGIN_NAMESPACE
class QSmoothedAnimation;
class QSmoothedAnimationTimer : public QTimer
{
    Q_OBJECT
public:
    explicit QSmoothedAnimationTimer(QSmoothedAnimation *animation, QObject *parent = nullptr);
    ~QSmoothedAnimationTimer();
public Q_SLOTS:
    void stopAnimation();
private:
    QSmoothedAnimation *m_animation;
};

class QQuickSmoothedAnimationPrivate;
class Q_AUTOTEST_EXPORT QSmoothedAnimation : public QAbstractAnimationJob
{
    Q_DISABLE_COPY(QSmoothedAnimation)
public:
    QSmoothedAnimation(QQuickSmoothedAnimationPrivate * = nullptr);

    ~QSmoothedAnimation();
    qreal to;
    qreal velocity;
    int userDuration;

    int maximumEasingTime;
    QQuickSmoothedAnimation::ReversingMode reversingMode;

    qreal initialVelocity;
    qreal trackVelocity;

    QQmlProperty target;

    int duration() const override;
    void restart();
    void init();

    void prepareForRestart();
    void clearTemplate() { animationTemplate = nullptr; }

protected:
    void updateCurrentTime(int) override;
    void updateState(QAbstractAnimationJob::State, QAbstractAnimationJob::State) override;
    void debugAnimation(QDebug d) const override;

private:
    qreal easeFollow(qreal);
    qreal initialValue;

    bool invert;

    int finalDuration;

    // Parameters for use in updateCurrentTime()
    qreal a;  // Acceleration
    qreal d;  // Deceleration
    qreal tf; // Total time
    qreal tp; // Time at which peak velocity occurs
    qreal td; // Time at which deceleration begins
    qreal vp; // Velocity at tp
    qreal sp; // Displacement at tp
    qreal sd; // Displacement at td
    qreal vi; // "Normalized" initialvelocity
    qreal s;  // Total s

    int lastTime;
    bool skipUpdate;

    bool recalc();
    void delayedStop();
    QSmoothedAnimationTimer *delayedStopTimer;
    QQuickSmoothedAnimationPrivate *animationTemplate;
};

class QQuickSmoothedAnimationPrivate : public QQuickPropertyAnimationPrivate
{
    Q_DECLARE_PUBLIC(QQuickSmoothedAnimation)
public:
    QQuickSmoothedAnimationPrivate();
    ~QQuickSmoothedAnimationPrivate();
    void updateRunningAnimations();

    QSmoothedAnimation *anim;
    QHash<QQmlProperty, QSmoothedAnimation*> activeAnimations;
};

QT_END_NAMESPACE

#endif // QQUICKSMOOTHEDANIMATION2_P_H