43 static std::unique_ptr<QSvgDocument> load(
const QString &file, QtSvg::Options options = {},
44 QtSvg::AnimatorType type = QtSvg::AnimatorType::Automatic);
45 static std::unique_ptr<QSvgDocument> load(
const QByteArray &contents, QtSvg::Options options = {},
46 QtSvg::AnimatorType type = QtSvg::AnimatorType::Automatic);
47 static std::unique_ptr<QSvgDocument> load(QXmlStreamReader *contents, QtSvg::Options options = {},
48 QtSvg::AnimatorType type = QtSvg::AnimatorType::Automatic);
49 static bool isLikelySvg(QIODevice *device,
bool *isCompressed =
nullptr);
51 QSvgDocument(QtSvg::Options options, QtSvg::AnimatorType type);
53 Type type()
const override;
55 inline QSize size()
const;
56 void setWidth(
int len,
bool percent);
57 void setHeight(
int len,
bool percent);
58 inline int width()
const;
59 inline int height()
const;
60 inline bool widthPercent()
const;
61 inline bool heightPercent()
const;
63 inline bool preserveAspectRatio()
const;
64 void setPreserveAspectRatio(
bool on);
66 inline QRectF viewBox()
const;
67 void setViewBox(
const QRectF &rect);
68 bool isCalculatingImplicitViewBox() {
return m_calculatingImplicitViewBox; }
70 QtSvg::Options options()
const;
72 void drawCommand(QPainter *, QSvgExtraStates &) override;
74 void draw(QPainter *p);
75 void draw(QPainter *p,
const QRectF &bounds);
76 void draw(QPainter *p,
const QString &id,
77 const QRectF &bounds=QRectF());
79 QTransform transformForElement(
const QString &id)
const;
80 QRectF boundsOnElement(
const QString &id)
const;
81 bool elementExists(
const QString &id)
const;
83 void addSvgFont(QSvgFont *);
84 QSvgFont *svgFont(
const QString &family)
const;
85 void addNamedNode(
const QString &id, QSvgNode *node);
86 QSvgNode *namedNode(
const QString &id)
const;
87 void addNamedStyle(
const QString &id, QSvgPaintStyleProperty *style);
88 QSvgPaintStyleProperty *namedStyle(
const QString &id)
const;
90 void restartAnimation();
91 inline qint64 currentElapsed()
const;
92 bool animated()
const;
93 void setAnimated(
bool a);
94 inline int animationDuration()
const;
95 int currentFrame()
const;
96 void setCurrentFrame(
int);
97 void setFramesPerSecond(
int num);
99 QSharedPointer<QSvgAbstractAnimator> animator()
const;
102 void mapSourceToTarget(QPainter *p,
const QRectF &targetRect,
const QRectF &sourceRect = QRectF());
106 bool m_heightPercent;
108 mutable bool m_calculatingImplicitViewBox =
false;
109 mutable bool m_implicitViewBox =
true;
110 mutable QRectF m_viewBox;
111 bool m_preserveAspectRatio =
false;
113 QHash<QString, QSvgRefCounter<QSvgFont> > m_fonts;
114 QHash<QString, QSvgNode *> m_namedNodes;
115 QHash<QString, QSvgRefCounter<QSvgPaintStyleProperty> > m_namedStyles;
120 QSvgExtraStates m_states;
122 const QtSvg::Options m_options;
123 QSharedPointer<QSvgAbstractAnimator> m_animator;
128inline QSize QSvgDocument::size()
const
130 if (m_size.isEmpty())
131 return viewBox().size().toSize();
132 if (m_widthPercent || m_heightPercent) {
133 const int width = m_widthPercent ? qRound(0.01 * m_size.width() * viewBox().size().width()) : m_size.width();
134 const int height = m_heightPercent ? qRound(0.01 * m_size.height() * viewBox().size().height()) : m_size.height();
135 return QSize(width, height);