| 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 | |
| 4 | #ifndef QSVGVISITORIMPL_P_H |
| 5 | #define QSVGVISITORIMPL_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 <QtSvg/private/qsvgvisitor_p.h> |
| 19 | #include "qquickgenerator_p.h" |
| 20 | #include "qquickanimatedproperty_p.h" |
| 21 | |
| 22 | QT_BEGIN_NAMESPACE |
| 23 | |
| 24 | class QTextStream; |
| 25 | class QSvgTinyDocument; |
| 26 | class QString; |
| 27 | class QQuickItem; |
| 28 | |
| 29 | class QSvgVisitorImpl : public QSvgVisitor |
| 30 | { |
| 31 | public: |
| 32 | QSvgVisitorImpl(const QString svgFileName, QQuickGenerator *generator, bool assumeTrustedSource); |
| 33 | bool traverse(); |
| 34 | |
| 35 | protected: |
| 36 | void visitNode(const QSvgNode *node) override; |
| 37 | void visitImageNode(const QSvgImage *node) override; |
| 38 | void visitRectNode(const QSvgRect *node) override; |
| 39 | void visitEllipseNode(const QSvgEllipse *node) override; |
| 40 | void visitPathNode(const QSvgPath *node) override; |
| 41 | void visitLineNode(const QSvgLine *node) override; |
| 42 | void visitPolygonNode(const QSvgPolygon *node) override; |
| 43 | void visitPolylineNode(const QSvgPolyline *node) override; |
| 44 | void visitTextNode(const QSvgText *node) override; |
| 45 | void visitUseNode(const QSvgUse *node) override; |
| 46 | bool visitDefsNodeStart(const QSvgDefs *node) override; |
| 47 | bool visitStructureNodeStart(const QSvgStructureNode *node) override; |
| 48 | void visitStructureNodeEnd(const QSvgStructureNode *node) override; |
| 49 | |
| 50 | bool visitDocumentNodeStart(const QSvgTinyDocument *node) override; |
| 51 | void visitDocumentNodeEnd(const QSvgTinyDocument *node) override; |
| 52 | |
| 53 | bool visitSwitchNodeStart(const QSvgSwitch *node) override; |
| 54 | void visitSwitchNodeEnd(const QSvgSwitch *node) override; |
| 55 | |
| 56 | private: |
| 57 | typedef std::pair<const QSvgAbstractAnimation *, const QSvgAbstractAnimatedProperty *> AnimationPair; |
| 58 | QList<AnimationPair> collectAnimations(const QSvgNode *node, const QString &propertyName); |
| 59 | void applyAnimationsToProperty(const QList<AnimationPair> &animations, |
| 60 | QQuickAnimatedProperty *property, |
| 61 | std::function<QVariant(const QSvgAbstractAnimatedProperty *, int index, int subtype)> calculateValue); |
| 62 | |
| 63 | void fillCommonNodeInfo(const QSvgNode *node, NodeInfo &info); |
| 64 | void fillPathAnimationInfo(const QSvgNode *node, PathNodeInfo &info); |
| 65 | void fillAnimationInfo(const QSvgNode *node, NodeInfo &info); |
| 66 | void fillColorAnimationInfo(const QSvgNode *node, PathNodeInfo &info); |
| 67 | void fillTransformAnimationInfo(const QSvgNode *node, NodeInfo &info); |
| 68 | void handleBaseNodeSetup(const QSvgNode *node); |
| 69 | void handleBaseNode(const QSvgNode *node); |
| 70 | void handleBaseNodeEnd(const QSvgNode *node); |
| 71 | void handlePathNode(const QSvgNode *node, const QPainterPath &path); |
| 72 | void outputShapePath(QPainterPath pathCopy, const PathNodeInfo &info); |
| 73 | static QString gradientCssDescription(const QGradient *gradient); |
| 74 | static QString colorCssDescription(QColor color); |
| 75 | |
| 76 | private: |
| 77 | QString m_svgFileName; |
| 78 | QQuickGenerator *m_generator; |
| 79 | bool m_assumeTrustedSource; |
| 80 | }; |
| 81 | |
| 82 | QT_END_NAMESPACE |
| 83 | |
| 84 | #endif // QSVGVISITORIMPL_P_H |
| 85 | |