| 1 | // Copyright (C) 2025 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 | |
| 4 | #ifndef QQUICKANIMATEDPROPERTY_P_H |
| 5 | #define QQUICKANIMATEDPROPERTY_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QMap> |
| 19 | #include <QVariant> |
| 20 | #include <QtGui/private/qbezier_p.h> |
| 21 | |
| 22 | QT_BEGIN_NAMESPACE |
| 23 | |
| 24 | class QQuickAnimatedProperty |
| 25 | { |
| 26 | public: |
| 27 | struct PropertyAnimation { |
| 28 | enum Flag { |
| 29 | NoFlags = 0, |
| 30 | FreezeAtEnd = 1, |
| 31 | ReplacePreviousAnimations = 2, |
| 32 | }; |
| 33 | |
| 34 | QMap<int, QVariant> frames; |
| 35 | QMap<int, QBezier> easingPerFrame; |
| 36 | int subtype = 0; |
| 37 | int repeatCount = 1; |
| 38 | int startOffset = 0; |
| 39 | quint8 flags = NoFlags; |
| 40 | |
| 41 | bool isConstant() const { |
| 42 | for (const auto& frame : frames) { |
| 43 | if (frame != frames.first()) |
| 44 | return false; |
| 45 | } |
| 46 | return true; |
| 47 | } |
| 48 | }; |
| 49 | |
| 50 | QQuickAnimatedProperty(const QVariant &defaultValue) |
| 51 | : m_defaultValue(defaultValue) |
| 52 | { |
| 53 | } |
| 54 | |
| 55 | bool isAnimated() const |
| 56 | { |
| 57 | return !m_animations.isEmpty(); |
| 58 | } |
| 59 | |
| 60 | QVariant defaultValue() const |
| 61 | { |
| 62 | return m_defaultValue; |
| 63 | } |
| 64 | |
| 65 | void setDefaultValue(const QVariant &value) |
| 66 | { |
| 67 | m_defaultValue = value; |
| 68 | } |
| 69 | |
| 70 | qsizetype animationCount() const |
| 71 | { |
| 72 | return m_animations.size(); |
| 73 | } |
| 74 | |
| 75 | const PropertyAnimation &animation(int index) const |
| 76 | { |
| 77 | return m_animations.at(i: index); |
| 78 | } |
| 79 | |
| 80 | void addAnimation(const PropertyAnimation &animation) |
| 81 | { |
| 82 | if (m_animationGroups.isEmpty()) |
| 83 | beginAnimationGroup(); |
| 84 | |
| 85 | m_animations.append(t: animation); |
| 86 | } |
| 87 | |
| 88 | qsizetype animationGroupCount() const |
| 89 | { |
| 90 | return m_animationGroups.size(); |
| 91 | } |
| 92 | |
| 93 | int animationGroup(int index) const |
| 94 | { |
| 95 | return m_animationGroups.at(i: index); |
| 96 | } |
| 97 | |
| 98 | void beginAnimationGroup() |
| 99 | { |
| 100 | m_animationGroups.append(t: m_animations.size()); |
| 101 | } |
| 102 | |
| 103 | private: |
| 104 | QVariant m_defaultValue; |
| 105 | QList<PropertyAnimation> m_animations; |
| 106 | QList<int> m_animationGroups; |
| 107 | }; |
| 108 | |
| 109 | QT_END_NAMESPACE |
| 110 | |
| 111 | #endif // QQUICKANIMATEDPROPERTY_P_H |
| 112 |
