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