Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsvganimator.cpp
Go to the documentation of this file.
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
5#include <QtCore/qdatetime.h>
6#include <QtSvg/private/qsvganimate_p.h>
7
9
10QSvgAbstractAnimator::QSvgAbstractAnimator()
11 : m_time(0)
12 , m_animationDuration(0)
13{
14}
15
16QSvgAbstractAnimator::~QSvgAbstractAnimator()
17{
18 for (auto animationHash : {&m_animationsCSS, &m_animationsSMIL}) {
19 for (const auto &nodeAnimations : *std::as_const(animationHash)) {
20 for (QSvgAbstractAnimation *anim : nodeAnimations)
21 delete anim;
22 }
23 }
24}
25
26
27void QSvgAbstractAnimator::appendAnimation(const QSvgNode *node, QSvgAbstractAnimation *anim)
28{
29 if (!node)
30 return;
31
32 if (anim->animationType() == QSvgAbstractAnimation::SMIL)
33 m_animationsSMIL[node].append(anim);
34 else
35 m_animationsCSS[node].append(anim);
36}
37
38QList<QSvgAbstractAnimation *> QSvgAbstractAnimator::animationsForNode(const QSvgNode *node) const
39{
40 return combinedAnimationsForNode(node);
41}
42
43void QSvgAbstractAnimator::advanceAnimations()
44{
45 qreal elapsedTime = currentElapsed();
46 for (auto animationHash : {&m_animationsCSS, &m_animationsSMIL}) {
47 for (const auto &nodeAnimations : *std::as_const(animationHash)) {
48 for (QSvgAbstractAnimation *anim : nodeAnimations)
49 anim->evaluateAnimation(elapsedTime);
50 }
51 }
52}
53
54void QSvgAbstractAnimator::setAnimationDuration(qint64 dur)
55{
56 m_animationDuration = dur;
57}
58
59qint64 QSvgAbstractAnimator::animationDuration() const
60{
61 return m_animationDuration;
62}
63
64QList<QSvgAbstractAnimation *> QSvgAbstractAnimator::combinedAnimationsForNode(const QSvgNode *node) const
65{
66 if (!node)
67 return QList<QSvgAbstractAnimation *>();
68
69 return m_animationsSMIL.value(node) + m_animationsCSS.value(node);
70}
71
72QSvgAnimator::QSvgAnimator()
73{
74}
75
76QSvgAnimator::~QSvgAnimator()
77{
78}
79
80void QSvgAnimator::restartAnimation()
81{
82 m_time = QDateTime::currentMSecsSinceEpoch();
83}
84
85qint64 QSvgAnimator::currentElapsed()
86{
87 return QDateTime::currentMSecsSinceEpoch() - m_time;
88}
89
90void QSvgAnimator::setAnimatorTime(qint64 time)
91{
92 m_time -= time;
93}
94
95QSvgAnimationController::QSvgAnimationController()
96{
97}
98
99QSvgAnimationController::~QSvgAnimationController()
100{
101}
102
103void QSvgAnimationController::restartAnimation()
104{
105 m_time = 0;
106}
107
108qint64 QSvgAnimationController::currentElapsed()
109{
110 return m_time;
111}
112
113void QSvgAnimationController::setAnimatorTime(qint64 time)
114{
115 m_time = qMax(0, time);
116}
117
118QT_END_NAMESPACE