Fixes a crash in QDoubleSpinBox
[qt-netbsd.git] / src / svg / qsvgnode.cpp
blobe0bebf71a86df4262b0123b306887184f7bcbd6b
1 /****************************************************************************
2 **
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtSvg module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** Commercial Usage
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** GNU General Public License Usage
29 ** Alternatively, this file may be used under the terms of the GNU
30 ** General Public License version 3.0 as published by the Free Software
31 ** Foundation and appearing in the file LICENSE.GPL included in the
32 ** packaging of this file. Please review the following information to
33 ** ensure the GNU General Public License version 3.0 requirements will be
34 ** met: http://www.gnu.org/copyleft/gpl.html.
36 ** If you have questions regarding the use of this file, please contact
37 ** Nokia at qt-info@nokia.com.
38 ** $QT_END_LICENSE$
40 ****************************************************************************/
42 #include "qsvgnode_p.h"
43 #include "qsvgtinydocument_p.h"
45 #ifndef QT_NO_SVG
47 #include "qdebug.h"
49 QT_BEGIN_NAMESPACE
51 QSvgNode::QSvgNode(QSvgNode *parent)
52 : m_parent(parent),
53 m_visible(true),
54 m_displayMode(BlockMode)
58 QSvgNode::~QSvgNode()
63 void QSvgNode::appendStyleProperty(QSvgStyleProperty *prop, const QString &id,
64 bool justLink)
66 //qDebug()<<"appending "<<prop->type()<< " ("<< id <<") "<<"to "<<this<<this->type();
67 if (!justLink) {
68 switch (prop->type()) {
69 case QSvgStyleProperty::QUALITY:
70 m_style.quality = static_cast<QSvgQualityStyle*>(prop);
71 break;
72 case QSvgStyleProperty::FILL:
73 m_style.fill = static_cast<QSvgFillStyle*>(prop);
74 break;
75 case QSvgStyleProperty::VIEWPORT_FILL:
76 m_style.viewportFill = static_cast<QSvgViewportFillStyle*>(prop);
77 break;
78 case QSvgStyleProperty::FONT:
79 m_style.font = static_cast<QSvgFontStyle*>(prop);
80 break;
81 case QSvgStyleProperty::STROKE:
82 m_style.stroke = static_cast<QSvgStrokeStyle*>(prop);
83 break;
84 case QSvgStyleProperty::SOLID_COLOR:
85 m_style.solidColor = static_cast<QSvgSolidColorStyle*>(prop);
86 break;
87 case QSvgStyleProperty::GRADIENT:
88 m_style.gradient = static_cast<QSvgGradientStyle*>(prop);
89 break;
90 case QSvgStyleProperty::TRANSFORM:
91 m_style.transform = static_cast<QSvgTransformStyle*>(prop);
92 break;
93 case QSvgStyleProperty::ANIMATE_COLOR:
94 m_style.animateColor = static_cast<QSvgAnimateColor*>(prop);
95 break;
96 case QSvgStyleProperty::ANIMATE_TRANSFORM:
97 m_style.animateTransforms.append(
98 static_cast<QSvgAnimateTransform*>(prop));
99 break;
100 case QSvgStyleProperty::OPACITY:
101 m_style.opacity = static_cast<QSvgOpacityStyle*>(prop);
102 break;
103 case QSvgStyleProperty::COMP_OP:
104 m_style.compop = static_cast<QSvgCompOpStyle*>(prop);
105 break;
106 default:
107 qDebug("QSvgNode: Trying to append unknown property!");
108 break;
111 if (!id.isEmpty()) {
112 m_styles.insert(id, prop);
116 void QSvgNode::applyStyle(QPainter *p, QSvgExtraStates &states)
118 m_style.apply(p, bounds(), this, states);
121 void QSvgNode::revertStyle(QPainter *p, QSvgExtraStates &states)
123 m_style.revert(p, states);
126 QSvgStyleProperty * QSvgNode::styleProperty(QSvgStyleProperty::Type type) const
128 const QSvgNode *node = this;
129 while (node) {
130 switch (type) {
131 case QSvgStyleProperty::QUALITY:
132 if (node->m_style.quality)
133 return node->m_style.quality;
134 break;
135 case QSvgStyleProperty::FILL:
136 if (node->m_style.fill)
137 return node->m_style.fill;
138 break;
139 case QSvgStyleProperty::VIEWPORT_FILL:
140 if (m_style.viewportFill)
141 return node->m_style.viewportFill;
142 break;
143 case QSvgStyleProperty::FONT:
144 if (node->m_style.font)
145 return node->m_style.font;
146 break;
147 case QSvgStyleProperty::STROKE:
148 if (node->m_style.stroke)
149 return node->m_style.stroke;
150 break;
151 case QSvgStyleProperty::SOLID_COLOR:
152 if (node->m_style.solidColor)
153 return node->m_style.solidColor;
154 break;
155 case QSvgStyleProperty::GRADIENT:
156 if (node->m_style.gradient)
157 return node->m_style.gradient;
158 break;
159 case QSvgStyleProperty::TRANSFORM:
160 if (node->m_style.transform)
161 return node->m_style.transform;
162 break;
163 case QSvgStyleProperty::ANIMATE_COLOR:
164 if (node->m_style.animateColor)
165 return node->m_style.animateColor;
166 break;
167 case QSvgStyleProperty::ANIMATE_TRANSFORM:
168 if (!node->m_style.animateTransforms.isEmpty())
169 return node->m_style.animateTransforms.first();
170 break;
171 case QSvgStyleProperty::OPACITY:
172 if (node->m_style.opacity)
173 return node->m_style.opacity;
174 break;
175 case QSvgStyleProperty::COMP_OP:
176 if (node->m_style.compop)
177 return node->m_style.compop;
178 break;
179 default:
180 break;
182 node = node->parent();
185 return 0;
188 QSvgStyleProperty * QSvgNode::styleProperty(const QString &id) const
190 QString rid = id;
191 if (rid.startsWith(QLatin1Char('#')))
192 rid.remove(0, 1);
193 const QSvgNode *node = this;
194 while (node) {
195 QSvgStyleProperty *style = node->m_styles[rid];
196 if (style)
197 return style;
198 node = node->parent();
201 return 0;
204 QRectF QSvgNode::bounds() const
206 return QRectF(0, 0, 0, 0);
209 QSvgTinyDocument * QSvgNode::document() const
211 QSvgTinyDocument *doc = 0;
212 QSvgNode *node = const_cast<QSvgNode*>(this);
213 while (node && node->type() != QSvgNode::DOC) {
214 node = node->parent();
216 doc = static_cast<QSvgTinyDocument*>(node);
218 return doc;
221 void QSvgNode::setRequiredFeatures(const QStringList &lst)
223 m_requiredFeatures = lst;
226 const QStringList & QSvgNode::requiredFeatures() const
228 return m_requiredFeatures;
231 void QSvgNode::setRequiredExtensions(const QStringList &lst)
233 m_requiredExtensions = lst;
236 const QStringList & QSvgNode::requiredExtensions() const
238 return m_requiredExtensions;
241 void QSvgNode::setRequiredLanguages(const QStringList &lst)
243 m_requiredLanguages = lst;
246 const QStringList & QSvgNode::requiredLanguages() const
248 return m_requiredLanguages;
251 void QSvgNode::setRequiredFormats(const QStringList &lst)
253 m_requiredFormats = lst;
256 const QStringList & QSvgNode::requiredFormats() const
258 return m_requiredFormats;
261 void QSvgNode::setRequiredFonts(const QStringList &lst)
263 m_requiredFonts = lst;
266 const QStringList & QSvgNode::requiredFonts() const
268 return m_requiredFonts;
271 void QSvgNode::setVisible(bool visible)
273 //propagate visibility change of true to the parent
274 //not propagating false is just a small performance
275 //degradation since we'll iterate over children without
276 //drawing any of them
277 if (m_parent && visible && !m_parent->isVisible())
278 m_parent->setVisible(true);
280 m_visible = visible;
283 QRectF QSvgNode::transformedBounds(const QTransform &transform) const
285 QTransform t = transform;
287 QSvgTransformStyle *transStyle = m_style.transform;
288 if (transStyle) {
289 t = transStyle->qtransform() * t;
292 QRectF rect = bounds();
294 rect = t.mapRect(rect);
296 return rect;
299 void QSvgNode::setNodeId(const QString &i)
301 m_id = i;
304 void QSvgNode::setXmlClass(const QString &str)
306 m_class = str;
309 void QSvgNode::setDisplayMode(DisplayMode mode)
311 m_displayMode = mode;
314 QSvgNode::DisplayMode QSvgNode::displayMode() const
316 return m_displayMode;
319 qreal QSvgNode::strokeWidth() const
321 QSvgStrokeStyle *stroke = static_cast<QSvgStrokeStyle*>(
322 styleProperty(QSvgStyleProperty::STROKE));
323 if (!stroke || stroke->qpen().style() == Qt::NoPen)
324 return 0;
325 return stroke->qpen().widthF();
328 QT_END_NAMESPACE
330 #endif // QT_NO_SVG