Qt 6.x
The Qt SDK
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_PRIVATE_EXPORT QSvgTinyDocument : public QSvgStructureNode
37{
38public:
39 static QSvgTinyDocument * load(const QString &file);
41 static QSvgTinyDocument * load(QXmlStreamReader *contents);
42public:
45 Type type() const override;
46
47 QSize size() const;
48 void setWidth(int len, bool percent);
49 void setHeight(int len, bool percent);
50 int width() const;
51 int height() const;
52 bool widthPercent() const;
53 bool heightPercent() const;
54
55 bool preserveAspectRatio() const;
56 void setPreserveAspectRatio(bool on);
57
58 QRectF viewBox() const;
59 void setViewBox(const QRectF &rect);
60
61 void draw(QPainter *p, QSvgExtraStates &) override; //from the QSvgNode
62
63 void draw(QPainter *p);
64 void draw(QPainter *p, const QRectF &bounds);
65 void draw(QPainter *p, const QString &id,
66 const QRectF &bounds=QRectF());
67
68 QTransform transformForElement(const QString &id) const;
69 QRectF boundsOnElement(const QString &id) const;
70 bool elementExists(const QString &id) const;
71
72 void addSvgFont(QSvgFont *);
73 QSvgFont *svgFont(const QString &family) const;
74 void addNamedNode(const QString &id, QSvgNode *node);
75 QSvgNode *namedNode(const QString &id) const;
76 void addNamedStyle(const QString &id, QSvgFillStyleProperty *style);
77 QSvgFillStyleProperty *namedStyle(const QString &id) const;
78
79 void restartAnimation();
80 int currentElapsed() const;
81 bool animated() const;
82 void setAnimated(bool a);
83 int animationDuration() const;
84 int currentFrame() const;
85 void setCurrentFrame(int);
86 void setFramesPerSecond(int num);
87private:
88 void mapSourceToTarget(QPainter *p, const QRectF &targetRect, const QRectF &sourceRect = QRectF());
89private:
90 QSize m_size;
91 bool m_widthPercent;
92 bool m_heightPercent;
93
94 mutable bool m_implicitViewBox = true;
95 mutable QRectF m_viewBox;
96 bool m_preserveAspectRatio = false;
97
99 QHash<QString, QSvgNode *> m_namedNodes;
101
102 qint64 m_time;
103 bool m_animated;
104 int m_animationDuration;
105 int m_fps;
106
107 QSvgExtraStates m_states;
108};
109
111{
112 if (m_size.isEmpty())
113 return viewBox().size().toSize();
114 if (m_widthPercent || m_heightPercent) {
115 const int width = m_widthPercent ? qRound(0.01 * m_size.width() * viewBox().size().width()) : m_size.width();
116 const int height = m_heightPercent ? qRound(0.01 * m_size.height() * viewBox().size().height()) : m_size.height();
117 return QSize(width, height);
118 }
119 return m_size;
120}
121
122inline int QSvgTinyDocument::width() const
123{
124 return size().width();
125}
126
127inline int QSvgTinyDocument::height() const
128{
129 return size().height();
130}
131
133{
134 return m_widthPercent;
135}
136
138{
139 return m_heightPercent;
140}
141
143{
144 if (m_viewBox.isNull()) {
145 m_viewBox = transformedBounds();
146 m_implicitViewBox = true;
147 }
148
149 return m_viewBox;
150}
151
153{
154 return m_preserveAspectRatio;
155}
156
158{
159 return QDateTime::currentMSecsSinceEpoch() - m_time;
160}
161
163{
164 return m_animationDuration;
165}
166
168
169#endif // QSVGTINYDOCUMENT_P_H
\inmodule QtCore
Definition qbytearray.h:57
static qint64 currentMSecsSinceEpoch() noexcept
\inmodule QtCore
Definition qhash.h:818
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
\inmodule QtCore\reentrant
Definition qrect.h:483
constexpr bool isNull() const noexcept
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition qrect.h:644
constexpr QSizeF size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:721
constexpr QSize toSize() const noexcept
Returns an integer based copy of this size.
Definition qsize.h:390
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:132
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:129
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:123
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
friend class QSvgTinyDocument
Definition qsvgnode_p.h:145
virtual void draw(QPainter *p, QSvgExtraStates &states)=0
QRectF transformedBounds() const
Definition qsvgnode.cpp:190
virtual Type type() const =0
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.
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:281
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei width
GLenum GLsizei len
GLfloat GLfloat p
[1]
GLuint num
long long qint64
Definition qtypes.h:55
QFile file
[0]
Definition moc.h:24