/src/qtsvg/src/svg/animation/qsvganimator.cpp
Line | Count | Source |
1 | | // Copyright (C) 2024 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 | | |
6 | | #include "qsvganimator_p.h" |
7 | | #include <QtCore/qdatetime.h> |
8 | | #include <QtSvg/private/qsvganimate_p.h> |
9 | | |
10 | | QT_BEGIN_NAMESPACE |
11 | | |
12 | | QSvgAbstractAnimator::QSvgAbstractAnimator() |
13 | 40.6k | : m_time(0) |
14 | 40.6k | , m_animationDuration(0) |
15 | 40.6k | { |
16 | 40.6k | } |
17 | | |
18 | | QSvgAbstractAnimator::~QSvgAbstractAnimator() |
19 | 40.6k | { |
20 | 81.3k | for (auto animationHash : {&m_animationsCSS, &m_animationsSMIL}) { |
21 | 81.3k | for (const auto &nodeAnimations : std::as_const(*animationHash)) { |
22 | 0 | for (QSvgAbstractAnimation *anim : nodeAnimations) |
23 | 0 | delete anim; |
24 | 0 | } |
25 | 81.3k | } |
26 | 40.6k | } |
27 | | |
28 | | |
29 | | void QSvgAbstractAnimator::appendAnimation(const QSvgNode *node, QSvgAbstractAnimation *anim) |
30 | 0 | { |
31 | 0 | if (!node) |
32 | 0 | return; |
33 | | |
34 | 0 | if (anim->animationType() == QSvgAbstractAnimation::SMIL) |
35 | 0 | m_animationsSMIL[node].append(anim); |
36 | 0 | else |
37 | 0 | m_animationsCSS[node].append(anim); |
38 | 0 | } |
39 | | |
40 | | QList<QSvgAbstractAnimation *> QSvgAbstractAnimator::animationsForNode(const QSvgNode *node) const |
41 | 0 | { |
42 | 0 | return combinedAnimationsForNode(node); |
43 | 0 | } |
44 | | |
45 | | void QSvgAbstractAnimator::advanceAnimations() |
46 | 2.66k | { |
47 | 2.66k | qreal elapsedTime = currentElapsed(); |
48 | 5.33k | for (auto animationHash : {&m_animationsCSS, &m_animationsSMIL}) { |
49 | 5.33k | for (const auto &nodeAnimations : std::as_const(*animationHash)) { |
50 | 0 | for (QSvgAbstractAnimation *anim : nodeAnimations) |
51 | 0 | anim->evaluateAnimation(elapsedTime); |
52 | 0 | } |
53 | 5.33k | } |
54 | 2.66k | } |
55 | | |
56 | | void QSvgAbstractAnimator::setAnimationDuration(qint64 dur) |
57 | 2.76k | { |
58 | 2.76k | m_animationDuration = dur; |
59 | 2.76k | } |
60 | | |
61 | | qint64 QSvgAbstractAnimator::animationDuration() const |
62 | 0 | { |
63 | 0 | return m_animationDuration; |
64 | 0 | } |
65 | | |
66 | | QList<QSvgAbstractAnimation *> QSvgAbstractAnimator::combinedAnimationsForNode(const QSvgNode *node) const |
67 | 0 | { |
68 | 0 | if (!node) |
69 | 0 | return QList<QSvgAbstractAnimation *>(); |
70 | | |
71 | 0 | return m_animationsSMIL.value(node) + m_animationsCSS.value(node); |
72 | 0 | } |
73 | | |
74 | | QSvgAnimator::QSvgAnimator() |
75 | 40.6k | { |
76 | 40.6k | } |
77 | | |
78 | | QSvgAnimator::~QSvgAnimator() |
79 | | { |
80 | | } |
81 | | |
82 | | void QSvgAnimator::restartAnimation() |
83 | 2.76k | { |
84 | 2.76k | m_time = QDateTime::currentMSecsSinceEpoch(); |
85 | 2.76k | } |
86 | | |
87 | | qint64 QSvgAnimator::currentElapsed() |
88 | 2.66k | { |
89 | 2.66k | return QDateTime::currentMSecsSinceEpoch() - m_time; |
90 | 2.66k | } |
91 | | |
92 | | void QSvgAnimator::setAnimatorTime(qint64 time) |
93 | 0 | { |
94 | 0 | m_time -= time; |
95 | 0 | } |
96 | | |
97 | | QSvgAnimationController::QSvgAnimationController() |
98 | 0 | { |
99 | 0 | } |
100 | | |
101 | | QSvgAnimationController::~QSvgAnimationController() |
102 | | { |
103 | | } |
104 | | |
105 | | void QSvgAnimationController::restartAnimation() |
106 | 0 | { |
107 | 0 | m_time = 0; |
108 | 0 | } |
109 | | |
110 | | qint64 QSvgAnimationController::currentElapsed() |
111 | 0 | { |
112 | 0 | return m_time; |
113 | 0 | } |
114 | | |
115 | | void QSvgAnimationController::setAnimatorTime(qint64 time) |
116 | 0 | { |
117 | 0 | m_time = qMax(0, time); |
118 | 0 | } |
119 | | |
120 | | QT_END_NAMESPACE |