| 1 | // Copyright (C) 2025 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QLOTTIEVISITOR_P_H |
| 5 | #define QLOTTIEVISITOR_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 <QJsonDocument> |
| 19 | #include <QJsonArray> |
| 20 | |
| 21 | #include <QtCore/QStack> |
| 22 | #include <QtGui/qbrush.h> |
| 23 | #include <QtGui/qpen.h> |
| 24 | |
| 25 | #include <QtGui/private/qfixed_p.h> |
| 26 | |
| 27 | #include <private/qlottiebase_p.h> |
| 28 | #include <private/qlottielayer_p.h> |
| 29 | #include <private/qlottiegroup_p.h> |
| 30 | #include <private/qlottiebasictransform_p.h> |
| 31 | #include <private/qquickgenerator_p.h> |
| 32 | #include <private/qquicknodeinfo_p.h> |
| 33 | #include <private/qfixed_p.h> |
| 34 | |
| 35 | #include <QtLottie/private/qlottierenderer_p.h> |
| 36 | #include <QtLottieVectorImageGenerator/qtlottievectorimagegeneratorexports.h> |
| 37 | |
| 38 | QT_BEGIN_NAMESPACE |
| 39 | |
| 40 | class QLottieRoot; |
| 41 | |
| 42 | class Q_LOTTIEVECTORIMAGEGENERATOR_EXPORT QLottieVisitor : public QLottieRenderer |
| 43 | { |
| 44 | public: |
| 45 | struct PaintInfo |
| 46 | { |
| 47 | QBrush fill = Qt::transparent; |
| 48 | QPen stroke = QPen(Qt::transparent); |
| 49 | qreal opacity = 1.0; |
| 50 | Qt::FillRule fillRule = Qt::WindingFill; |
| 51 | QPainterPath unitedPath; |
| 52 | PathTrimInfo trim; |
| 53 | |
| 54 | QTransform transform; |
| 55 | |
| 56 | struct TransformAnimationInfo |
| 57 | { |
| 58 | QTransform::TransformationType animationType; |
| 59 | |
| 60 | QMap<int, QVariant> frames; |
| 61 | QMap<int, QBezier> easingPerFrame; |
| 62 | }; |
| 63 | QList<TransformAnimationInfo> transformAnimations; |
| 64 | }; |
| 65 | |
| 66 | QLottieVisitor(const QString lottieFileName, QQuickGenerator *generator); |
| 67 | virtual ~QLottieVisitor() {} |
| 68 | |
| 69 | void saveState() override; |
| 70 | void restoreState() override; |
| 71 | |
| 72 | void render(const QLottieRoot &layer); |
| 73 | |
| 74 | void render(const QLottieLayer &layer) override; |
| 75 | void render(const QLottieSolidLayer &layer) override; |
| 76 | void render(const QLottieGroup &group) override; |
| 77 | |
| 78 | void finish(const QLottieLayer &layer) override; |
| 79 | void finish(const QLottieGroup &group) override; |
| 80 | |
| 81 | void render(const QLottieRect &rect) override; |
| 82 | void render(const QLottieEllipse &ellipse) override; |
| 83 | void render(const QLottiePolyStar &star) override; |
| 84 | void render(const QLottieRound &round) override; |
| 85 | void render(const QLottieFill &fill) override; |
| 86 | void render(const QLottieGFill &shape) override; |
| 87 | void render(const QLottieImage &image) override; |
| 88 | void render(const QLottieStroke &stroke) override; |
| 89 | void render(const QLottieBasicTransform &transform) override; |
| 90 | void render(const QLottieShapeTransform &transform) override; |
| 91 | void render(const QLottieFreeFormShape &shape) override; |
| 92 | void render(const QLottieTrimPath &trim) override; |
| 93 | void render(const QLottieFillEffect &effect) override; |
| 94 | void render(const QLottieRepeater &repeater) override; |
| 95 | |
| 96 | void fillCommonNodeInfo(const QLottieBase *node, NodeInfo *info); |
| 97 | void fillAnimationNodeInfo(const QLottieBase *node, NodeInfo *info); |
| 98 | void fillBasicPathInfo(const QLottieShape *strokeOrFill, PathNodeInfo *pathInfo); |
| 99 | void fillLayerAnimationInfo(const QLottieLayer *node, NodeInfo *info); |
| 100 | |
| 101 | private: |
| 102 | static bool nodeIsGraphicElement(const QLottieBase *node); |
| 103 | static bool nodeIsShape(const QLottieBase *node); |
| 104 | static bool hasAnimations(const QLottieBasicTransform *transform, bool isShapeTransform = false); |
| 105 | void processShape(const QLottieShape *shape); |
| 106 | void processShape(const QLottieShape *shape, const QPainterPath &path); |
| 107 | void collectTransformAnimations(const QLottieBasicTransform *transform, |
| 108 | bool isShapeTransform = false); |
| 109 | void enumerateLayerChildren(const QLottieBase *node); |
| 110 | |
| 111 | QString m_lottieFileName; |
| 112 | QQuickGenerator *m_generator; |
| 113 | |
| 114 | PaintInfo m_currentPaintInfo; |
| 115 | |
| 116 | QList<PaintInfo> m_savedPaintInfos; |
| 117 | |
| 118 | int m_frameRate = 30; |
| 119 | int m_duration = 1000; |
| 120 | qreal m_frameOffset = 0; |
| 121 | |
| 122 | QList<const QLottieBase *> m_layers; |
| 123 | QStack<const QLottieBase *> m_currentStructElements; |
| 124 | }; |
| 125 | |
| 126 | QT_END_NAMESPACE |
| 127 | |
| 128 | #endif // QLOTTIEVISITOR_P_H |
| 129 | |
| 130 | |