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
qsvgabstractanimation.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
7
8QSvgAbstractAnimation::QSvgAbstractAnimation()
9 : m_start(0)
10 , m_duration(0)
11 , m_finished(false)
12 , m_iterationCount(0)
13{
14
15}
16
17QSvgAbstractAnimation::~QSvgAbstractAnimation()
18{
19 for (auto prop : m_properties)
20 delete prop;
21}
22
23void QSvgAbstractAnimation::appendProperty(QSvgAbstractAnimatedProperty *property)
24{
25 m_properties.append(property);
26}
27
28QList<QSvgAbstractAnimatedProperty *> QSvgAbstractAnimation::properties() const
29{
30 return m_properties;
31}
32
33bool QSvgAbstractAnimation::finished() const
34{
35 return m_finished;
36}
37
38bool QSvgAbstractAnimation::isActive() const
39{
40 return !finished();
41}
42
43void QSvgAbstractAnimation::evaluateAnimation(qreal elapsedTime)
44{
45 if (m_duration == 0 || m_start > elapsedTime)
46 return;
47
48 qreal fractionOfTotalTime = (elapsedTime - m_start) / m_duration;
49
50 if (m_iterationCount >= 0 && m_iterationCount < fractionOfTotalTime)
51 m_finished = true;
52 else
53 m_finished = false;
54
55 if (m_finished)
56 return;
57
58 qreal fractionOfCurrentIterationTime = fractionOfTotalTime - std::trunc(fractionOfTotalTime);
59
60 for (QSvgAbstractAnimatedProperty *animProperty : m_properties) {
61 const QList<qreal> keyFrames = animProperty->keyFrames();
62 for (int i = 1; i < keyFrames.size(); i++) {
63 qreal from = keyFrames.at(i - 1);
64 qreal to = keyFrames.at(i);
65 if (fractionOfCurrentIterationTime >= from && fractionOfCurrentIterationTime < to) {
66 qreal currFraction = (fractionOfCurrentIterationTime - from) / (to - from);
67 animProperty->interpolate(i, currFraction);
68 }
69 }
70 }
71}
72
73void QSvgAbstractAnimation::setRunningTime(int startMs, int durationMs)
74{
75 m_start = (startMs > 0) ? startMs : 0;
76 m_duration = (durationMs > 0) ? durationMs : 0;
77}
78
79int QSvgAbstractAnimation::start() const
80{
81 return m_start;
82}
83
84int QSvgAbstractAnimation::duration() const
85{
86 return m_duration;
87}
88
89void QSvgAbstractAnimation::setIterationCount(int count)
90{
91 m_iterationCount = count;
92}
93
94int QSvgAbstractAnimation::iterationCount() const
95{
96 return m_iterationCount;
97}
98
99QT_END_NAMESPACE