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 | |
15 | QT_BEGIN_NAMESPACE |
16 | |
17 | |
18 | class QSvgRendererPrivate; |
19 | class QPainter; |
20 | class QByteArray; |
21 | class QTransform; |
22 | |
23 | class 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) |
31 | Q_PROPERTY(QtSvg::Options options READ options WRITE setOptions) |
32 | Q_PROPERTY(bool animationEnabled READ isAnimationEnabled WRITE setAnimationEnabled) |
33 | public: |
34 | QSvgRenderer(QObject *parent = nullptr); |
35 | QSvgRenderer(const QString &filename, QObject *parent = nullptr); |
36 | QSvgRenderer(const QByteArray &contents, QObject *parent = nullptr); |
37 | QSvgRenderer(QXmlStreamReader *contents, QObject *parent = nullptr); |
38 | ~QSvgRenderer(); |
39 | |
40 | bool isValid() const; |
41 | |
42 | QSize defaultSize() const; |
43 | |
44 | QRect viewBox() const; |
45 | QRectF viewBoxF() const; |
46 | void setViewBox(const QRect &viewbox); |
47 | void setViewBox(const QRectF &viewbox); |
48 | |
49 | Qt::AspectRatioMode aspectRatioMode() const; |
50 | void setAspectRatioMode(Qt::AspectRatioMode mode); |
51 | |
52 | QtSvg::Options options() const; |
53 | void setOptions(QtSvg::Options flags); |
54 | |
55 | bool animated() const; |
56 | int framesPerSecond() const; |
57 | void setFramesPerSecond(int num); |
58 | int currentFrame() const; |
59 | void setCurrentFrame(int); |
60 | int animationDuration() const;//in seconds |
61 | bool isAnimationEnabled() const; |
62 | void setAnimationEnabled(bool enable); |
63 | |
64 | QRectF boundsOnElement(const QString &id) const; |
65 | bool elementExists(const QString &id) const; |
66 | QTransform transformForElement(const QString &id) const; |
67 | |
68 | static void setDefaultOptions(QtSvg::Options flags); |
69 | |
70 | public Q_SLOTS: |
71 | bool load(const QString &filename); |
72 | bool load(const QByteArray &contents); |
73 | bool load(QXmlStreamReader *contents); |
74 | void render(QPainter *p); |
75 | void render(QPainter *p, const QRectF &bounds); |
76 | |
77 | void render(QPainter *p, const QString &elementId, |
78 | const QRectF &bounds=QRectF()); |
79 | |
80 | Q_SIGNALS: |
81 | void repaintNeeded(); |
82 | |
83 | private: |
84 | Q_DECLARE_PRIVATE(QSvgRenderer) |
85 | }; |
86 | |
87 | QT_END_NAMESPACE |
88 | |
89 | #endif // QT_NO_SVGRENDERER |
90 | #endif // QSVGRENDERER_H |
91 | |