1 /****************************************************************************
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtSvg module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
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.
40 ****************************************************************************/
42 #include "qsvgnode_p.h"
43 #include "qsvgtinydocument_p.h"
51 QSvgNode::QSvgNode(QSvgNode
*parent
)
54 m_displayMode(BlockMode
)
63 void QSvgNode::appendStyleProperty(QSvgStyleProperty
*prop
, const QString
&id
,
66 //qDebug()<<"appending "<<prop->type()<< " ("<< id <<") "<<"to "<<this<<this->type();
68 switch (prop
->type()) {
69 case QSvgStyleProperty::QUALITY
:
70 m_style
.quality
= static_cast<QSvgQualityStyle
*>(prop
);
72 case QSvgStyleProperty::FILL
:
73 m_style
.fill
= static_cast<QSvgFillStyle
*>(prop
);
75 case QSvgStyleProperty::VIEWPORT_FILL
:
76 m_style
.viewportFill
= static_cast<QSvgViewportFillStyle
*>(prop
);
78 case QSvgStyleProperty::FONT
:
79 m_style
.font
= static_cast<QSvgFontStyle
*>(prop
);
81 case QSvgStyleProperty::STROKE
:
82 m_style
.stroke
= static_cast<QSvgStrokeStyle
*>(prop
);
84 case QSvgStyleProperty::SOLID_COLOR
:
85 m_style
.solidColor
= static_cast<QSvgSolidColorStyle
*>(prop
);
87 case QSvgStyleProperty::GRADIENT
:
88 m_style
.gradient
= static_cast<QSvgGradientStyle
*>(prop
);
90 case QSvgStyleProperty::TRANSFORM
:
91 m_style
.transform
= static_cast<QSvgTransformStyle
*>(prop
);
93 case QSvgStyleProperty::ANIMATE_COLOR
:
94 m_style
.animateColor
= static_cast<QSvgAnimateColor
*>(prop
);
96 case QSvgStyleProperty::ANIMATE_TRANSFORM
:
97 m_style
.animateTransforms
.append(
98 static_cast<QSvgAnimateTransform
*>(prop
));
100 case QSvgStyleProperty::OPACITY
:
101 m_style
.opacity
= static_cast<QSvgOpacityStyle
*>(prop
);
103 case QSvgStyleProperty::COMP_OP
:
104 m_style
.compop
= static_cast<QSvgCompOpStyle
*>(prop
);
107 qDebug("QSvgNode: Trying to append unknown property!");
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;
131 case QSvgStyleProperty::QUALITY
:
132 if (node
->m_style
.quality
)
133 return node
->m_style
.quality
;
135 case QSvgStyleProperty::FILL
:
136 if (node
->m_style
.fill
)
137 return node
->m_style
.fill
;
139 case QSvgStyleProperty::VIEWPORT_FILL
:
140 if (m_style
.viewportFill
)
141 return node
->m_style
.viewportFill
;
143 case QSvgStyleProperty::FONT
:
144 if (node
->m_style
.font
)
145 return node
->m_style
.font
;
147 case QSvgStyleProperty::STROKE
:
148 if (node
->m_style
.stroke
)
149 return node
->m_style
.stroke
;
151 case QSvgStyleProperty::SOLID_COLOR
:
152 if (node
->m_style
.solidColor
)
153 return node
->m_style
.solidColor
;
155 case QSvgStyleProperty::GRADIENT
:
156 if (node
->m_style
.gradient
)
157 return node
->m_style
.gradient
;
159 case QSvgStyleProperty::TRANSFORM
:
160 if (node
->m_style
.transform
)
161 return node
->m_style
.transform
;
163 case QSvgStyleProperty::ANIMATE_COLOR
:
164 if (node
->m_style
.animateColor
)
165 return node
->m_style
.animateColor
;
167 case QSvgStyleProperty::ANIMATE_TRANSFORM
:
168 if (!node
->m_style
.animateTransforms
.isEmpty())
169 return node
->m_style
.animateTransforms
.first();
171 case QSvgStyleProperty::OPACITY
:
172 if (node
->m_style
.opacity
)
173 return node
->m_style
.opacity
;
175 case QSvgStyleProperty::COMP_OP
:
176 if (node
->m_style
.compop
)
177 return node
->m_style
.compop
;
182 node
= node
->parent();
188 QSvgStyleProperty
* QSvgNode::styleProperty(const QString
&id
) const
191 if (rid
.startsWith(QLatin1Char('#')))
193 const QSvgNode
*node
= this;
195 QSvgStyleProperty
*style
= node
->m_styles
[rid
];
198 node
= node
->parent();
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
);
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);
283 QRectF
QSvgNode::transformedBounds(const QTransform
&transform
) const
285 QTransform t
= transform
;
287 QSvgTransformStyle
*transStyle
= m_style
.transform
;
289 t
= transStyle
->qtransform() * t
;
292 QRectF rect
= bounds();
294 rect
= t
.mapRect(rect
);
299 void QSvgNode::setNodeId(const QString
&i
)
304 void QSvgNode::setXmlClass(const QString
&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
)
325 return stroke
->qpen().widthF();