Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qsvgtinydocument_p.h
Go to the documentation of this file.
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 QSVGTINYDOCUMENT_P_H
5#define QSVGTINYDOCUMENT_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 "qsvgstructure_p.h"
19#include "qtsvgglobal_p.h"
20
21#include "QtCore/qrect.h"
22#include "QtCore/qlist.h"
23#include "QtCore/qhash.h"
24#include "QtCore/qdatetime.h"
25#include "QtCore/qxmlstream.h"
26#include "qsvgstyle_p.h"
27#include "qsvgfont_p.h"
28
30
31class QPainter;
32class QByteArray;
33class QSvgFont;
34class QTransform;
35
36class Q_SVG_EXPORT QSvgTinyDocument : public QSvgStructureNode
37{
38public:
39 static QSvgTinyDocument *load(const QString &file, QtSvg::Options options = {});
40 static QSvgTinyDocument *load(const QByteArray &contents, QtSvg::Options options = {});
41 static QSvgTinyDocument *load(QXmlStreamReader *contents, QtSvg::Options options = {});
42 static bool isLikelySvg(QIODevice *device, bool *isCompressed = nullptr);
43public:
44 QSvgTinyDocument(QtSvg::Options options);
46 Type type() const override;
47
48 inline QSize size() const;
49 void setWidth(int len, bool percent);
50 void setHeight(int len, bool percent);
51 inline int width() const;
52 inline int height() const;
53 inline bool widthPercent() const;
54 inline bool heightPercent() const;
55
56 inline bool preserveAspectRatio() const;
57 void setPreserveAspectRatio(bool on);
58
59 inline QRectF viewBox() const;
60 void setViewBox(const QRectF &rect);
61
62 QtSvg::Options options() const;
63
64 void drawCommand(QPainter *, QSvgExtraStates &) override;
65
66 void draw(QPainter *p);
67 void draw(QPainter *p, const QRectF &bounds);
68 void draw(QPainter *p, const QString &id,
69 const QRectF &bounds=QRectF());
70
71 QTransform transformForElement(const QString &id) const;
72 QRectF boundsOnElement(const QString &id) const;
73 bool elementExists(const QString &id) const;
74
75 void addSvgFont(QSvgFont *);
76 QSvgFont *svgFont(const QString &family) const;
77 void addNamedNode(const QString &id, QSvgNode *node);
78 QSvgNode *namedNode(const QString &id) const;
79 void addNamedStyle(const QString &id, QSvgPaintStyleProperty *style);
80 QSvgPaintStyleProperty *namedStyle(const QString &id) const;
81
82 void restartAnimation();
83 inline int currentElapsed() const;
84 bool animated() const;
85 void setAnimated(bool a);
86 inline int animationDuration() const;
87 int currentFrame() const;
88 void setCurrentFrame(int);
89 void setFramesPerSecond(int num);
90
91private:
92 void mapSourceToTarget(QPainter *p, const QRectF &targetRect, const QRectF &sourceRect = QRectF());
93private:
94 QSize m_size;
95 bool m_widthPercent;
96 bool m_heightPercent;
97
98 mutable bool m_implicitViewBox = true;
99 mutable QRectF m_viewBox;
100 bool m_preserveAspectRatio = false;
101
102 QHash<QString, QSvgRefCounter<QSvgFont> > m_fonts;
103 QHash<QString, QSvgNode *> m_namedNodes;
104 QHash<QString, QSvgRefCounter<QSvgPaintStyleProperty> > m_namedStyles;
105
106 qint64 m_time;
107 bool m_animated;
108 int m_animationDuration;
109 int m_fps;
110
111 QSvgExtraStates m_states;
112
113 const QtSvg::Options m_options;
114};
115
116Q_SVG_EXPORT QDebug operator<<(QDebug debug, const QSvgTinyDocument &doc);
117
119{
120 if (m_size.isEmpty())
121 return viewBox().size().toSize();
122 if (m_widthPercent || m_heightPercent) {
123 const int width = m_widthPercent ? qRound(0.01 * m_size.width() * viewBox().size().width()) : m_size.width();
124 const int height = m_heightPercent ? qRound(0.01 * m_size.height() * viewBox().size().height()) : m_size.height();
125 return QSize(width, height);
126 }
127 return m_size;
128}
129
130inline int QSvgTinyDocument::width() const
131{
132 return size().width();
133}
134
135inline int QSvgTinyDocument::height() const
136{
137 return size().height();
138}
139
141{
142 return m_widthPercent;
143}
144
146{
147 return m_heightPercent;
148}
149
151{
152 if (m_viewBox.isNull()) {
153 m_viewBox = transformedBounds();
154 m_implicitViewBox = true;
155 }
156
157 return m_viewBox;
158}
159
161{
162 return m_preserveAspectRatio;
163}
164
166{
167 return QDateTime::currentMSecsSinceEpoch() - m_time;
168}
169
171{
172 return m_animationDuration;
173}
174
176
177#endif // QSVGTINYDOCUMENT_P_H
IOBluetoothDevice * device
\inmodule QtCore
Definition qbytearray.h:57
static qint64 currentMSecsSinceEpoch() noexcept
\inmodule QtCore
\inmodule QtCore \reentrant
Definition qiodevice.h:34
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
\inmodule QtCore\reentrant
Definition qrect.h:484
constexpr bool isNull() const noexcept
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition qrect.h:658
constexpr QSizeF size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:735
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
constexpr bool isEmpty() const noexcept
Returns true if either of the width and height is less than or equal to 0; otherwise returns false.
Definition qsize.h:124
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QRectF transformedBounds() const
Definition qsvgnode.cpp:343
int animationDuration() const
bool preserveAspectRatio() const
QRectF viewBox() const
bool heightPercent() const
bool widthPercent() const
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
p1 load("image.bmp")
rect
[4]
Combined button and popup list for selecting options.
SharedPointerFileDialogOptions m_options
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:327
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei width
GLenum type
GLfloat GLfloat p
[1]
GLenum GLsizei len
GLuint num
Q_SVG_EXPORT QDebug operator<<(QDebug debug, const QSvgTinyDocument &doc)
long long qint64
Definition qtypes.h:60
QFile file
[0]
myFilter draw(painter, QPoint(0, 0), originalPixmap)
Definition moc.h:23