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