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 QSVGNODE_P_H
5#define QSVGNODE_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 "qsvgstyle_p.h"
19#include "qtsvgglobal_p.h"
20#include "qsvghelper_p.h"
21
22#include "QtCore/qstring.h"
23#include "QtCore/qhash.h"
24
25QT_BEGIN_NAMESPACE
26
27class QPainter;
28class QSvgTinyDocument;
29
30class Q_SVG_EXPORT QSvgNode
31{
32public:
33 enum Type
34 {
35 Doc,
36 Group,
37 Defs,
38 Switch,
39 Animation,
40 Circle,
41 Ellipse,
42 Image,
43 Line,
44 Path,
45 Polygon,
46 Polyline,
47 Rect,
48 Text,
49 Textarea,
50 Tspan,
51 Use,
52 Video,
53 Mask,
54 Symbol,
55 Marker,
56 Pattern,
57 Filter,
58 FeMerge,
59 FeMergenode,
60 FeColormatrix,
61 FeGaussianblur,
62 FeOffset,
63 FeComposite,
64 FeFlood,
65 FeUnsupported
66 };
67 enum DisplayMode {
68 InlineMode,
69 BlockMode,
70 ListItemMode,
71 RunInMode,
72 CompactMode,
73 MarkerMode,
74 TableMode,
75 InlineTableMode,
76 TableRowGroupMode,
77 TableHeaderGroupMode,
78 TableFooterGroupMode,
79 TableRowMode,
80 TableColumnGroupMode,
81 TableColumnMode,
82 TableCellMode,
83 TableCaptionMode,
84 NoneMode,
85 InheritMode
86 };
87
88public:
89 QSvgNode(QSvgNode *parent=0);
90 virtual ~QSvgNode();
91 void draw(QPainter *p, QSvgExtraStates &states);
92 virtual bool separateFillStroke() const {return false;}
93 virtual void drawCommand(QPainter *p, QSvgExtraStates &states) = 0;
94 void fillThenStroke(QPainter *p, QSvgExtraStates &states);
95 QImage drawIntoBuffer(QPainter *p, QSvgExtraStates &states, const QRect &boundsRect);
96 void applyMaskToBuffer(QImage *proxy, QImage mask) const;
97 void drawWithMask(QPainter *p, QSvgExtraStates &states, const QImage &mask, const QRect &boundsRect);
98 void applyBufferToCanvas(QPainter *p, QImage proxy) const;
99
100 QSvgNode *parent() const;
101 bool isDescendantOf(const QSvgNode *parent) const;
102
103 void appendStyleProperty(QSvgStyleProperty *prop, const QString &id);
104 void applyStyle(QPainter *p, QSvgExtraStates &states) const;
105 void applyStyleRecursive(QPainter *p, QSvgExtraStates &states) const;
106 void revertStyle(QPainter *p, QSvgExtraStates &states) const;
107 void revertStyleRecursive(QPainter *p, QSvgExtraStates &states) const;
108 QSvgStyleProperty *styleProperty(QSvgStyleProperty::Type type) const;
109 QSvgPaintStyleProperty *styleProperty(const QString &id) const;
110
111 QSvgTinyDocument *document() const;
112
113 virtual Type type() const = 0;
114 QString typeName() const;
115 virtual QRectF internalFastBounds(QPainter *p, QSvgExtraStates &states) const;
116 virtual QRectF internalBounds(QPainter *p, QSvgExtraStates &states) const;
117 QRectF bounds(QPainter *p, QSvgExtraStates &states) const;
118 QRectF bounds() const;
119 virtual QRectF decoratedInternalBounds(QPainter *p, QSvgExtraStates &states) const;
120 virtual QRectF decoratedBounds(QPainter *p, QSvgExtraStates &states) const;
121
122 void setRequiredFeatures(const QStringList &lst);
123 const QStringList & requiredFeatures() const;
124
125 void setRequiredExtensions(const QStringList &lst);
126 const QStringList & requiredExtensions() const;
127
128 void setRequiredLanguages(const QStringList &lst);
129 const QStringList & requiredLanguages() const;
130
131 void setRequiredFormats(const QStringList &lst);
132 const QStringList & requiredFormats() const;
133
134 void setRequiredFonts(const QStringList &lst);
135 const QStringList & requiredFonts() const;
136
137 void setVisible(bool visible);
138 bool isVisible() const;
139
140 void setDisplayMode(DisplayMode display);
141 DisplayMode displayMode() const;
142
143 QString nodeId() const;
144 void setNodeId(const QString &i);
145
146 QString xmlClass() const;
147 void setXmlClass(const QString &str);
148
149 QString maskId() const;
150 void setMaskId(const QString &str);
151 bool hasMask() const;
152
153 QString filterId() const;
154 void setFilterId(const QString &str);
155 bool hasFilter() const;
156
157 QString markerStartId() const;
158 void setMarkerStartId(const QString &str);
159 bool hasMarkerStart() const;
160
161 QString markerMidId() const;
162 void setMarkerMidId(const QString &str);
163 bool hasMarkerMid() const;
164
165 QString markerEndId() const;
166 void setMarkerEndId(const QString &str);
167 bool hasMarkerEnd() const;
168
169 bool hasAnyMarker() const;
170
171 virtual bool requiresGroupRendering() const;
172
173 virtual bool shouldDrawNode(QPainter *p, QSvgExtraStates &states) const;
174 const QSvgStyle &style() const { return m_style; }
175protected:
176 mutable QSvgStyle m_style;
177
178 QRectF filterRegion(QRectF bounds) const;
179
180 static qreal strokeWidth(QPainter *p);
181 static void initPainter(QPainter *p);
182
183 enum BoundsMode {
184 Simplistic,
185 IncludeMiterLimit
186 };
187 static QRectF boundsOnStroke(QPainter *p, const QPainterPath &path,
188 qreal width, BoundsMode mode);
189
190private:
191 QSvgNode *m_parent;
192
193 QStringList m_requiredFeatures;
194 QStringList m_requiredExtensions;
195 QStringList m_requiredLanguages;
196 QStringList m_requiredFormats;
197 QStringList m_requiredFonts;
198
199 bool m_visible;
200
201 QString m_id;
202 QString m_class;
203 QString m_maskId;
204 QString m_filterId;
205 QString m_markerStartId;
206 QString m_markerMidId;
207 QString m_markerEndId;
208
209
210 DisplayMode m_displayMode;
211 mutable QRectF m_cachedBounds;
212
213 friend class QSvgTinyDocument;
214};
215
216inline QSvgNode *QSvgNode::parent() const
217{
218 return m_parent;
219}
220
221inline bool QSvgNode::isVisible() const
222{
223 return m_visible;
224}
225
226inline QString QSvgNode::nodeId() const
227{
228 return m_id;
229}
230
231inline QString QSvgNode::xmlClass() const
232{
233 return m_class;
234}
235
236QT_END_NAMESPACE
237
238#endif // QSVGNODE_P_H
239

Provided by KDAB

Privacy Policy
Start learning QML with our Intro Training
Find out more

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