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