1// Copyright (C) 2016 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 QSVGRENDERER_H
5#define QSVGRENDERER_H
6
7#ifndef QT_NO_SVGRENDERER
8
9#include <QtCore/qobject.h>
10#include <QtCore/qsize.h>
11#include <QtCore/qrect.h>
12#include <QtCore/qxmlstream.h>
13#include <QtSvg/qtsvgglobal.h>
14
15QT_BEGIN_NAMESPACE
16
17
18class QSvgRendererPrivate;
19class QPainter;
20class QByteArray;
21class QTransform;
22
23class Q_SVG_EXPORT QSvgRenderer : public QObject
24{
25 Q_OBJECT
26
27 Q_PROPERTY(QRectF viewBox READ viewBoxF WRITE setViewBox)
28 Q_PROPERTY(int framesPerSecond READ framesPerSecond WRITE setFramesPerSecond)
29 Q_PROPERTY(int currentFrame READ currentFrame WRITE setCurrentFrame)
30 Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode WRITE setAspectRatioMode)
31public:
32 QSvgRenderer(QObject *parent = nullptr);
33 QSvgRenderer(const QString &filename, QObject *parent = nullptr);
34 QSvgRenderer(const QByteArray &contents, QObject *parent = nullptr);
35 QSvgRenderer(QXmlStreamReader *contents, QObject *parent = nullptr);
36 ~QSvgRenderer();
37
38 bool isValid() const;
39
40 QSize defaultSize() const;
41
42 QRect viewBox() const;
43 QRectF viewBoxF() const;
44 void setViewBox(const QRect &viewbox);
45 void setViewBox(const QRectF &viewbox);
46
47 Qt::AspectRatioMode aspectRatioMode() const;
48 void setAspectRatioMode(Qt::AspectRatioMode mode);
49
50 bool animated() const;
51 int framesPerSecond() const;
52 void setFramesPerSecond(int num);
53 int currentFrame() const;
54 void setCurrentFrame(int);
55 int animationDuration() const;//in seconds
56
57 QRectF boundsOnElement(const QString &id) const;
58 bool elementExists(const QString &id) const;
59 QTransform transformForElement(const QString &id) const;
60
61public Q_SLOTS:
62 bool load(const QString &filename);
63 bool load(const QByteArray &contents);
64 bool load(QXmlStreamReader *contents);
65 void render(QPainter *p);
66 void render(QPainter *p, const QRectF &bounds);
67
68 void render(QPainter *p, const QString &elementId,
69 const QRectF &bounds=QRectF());
70
71Q_SIGNALS:
72 void repaintNeeded();
73
74private:
75 Q_DECLARE_PRIVATE(QSvgRenderer)
76};
77
78QT_END_NAMESPACE
79
80#endif // QT_NO_SVGRENDERER
81#endif // QSVGRENDERER_H
82

source code of qtsvg/src/svg/qsvgrenderer.h