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