| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com)
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtSvg module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 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.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com.
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "qsvgnode_p.h"
|
|---|
| 43 | #include "qsvgtinydocument_p.h"
|
|---|
| 44 |
|
|---|
| 45 | #ifndef QT_NO_SVG
|
|---|
| 46 |
|
|---|
| 47 | #include "qdebug.h"
|
|---|
| 48 |
|
|---|
| 49 | QT_BEGIN_NAMESPACE
|
|---|
| 50 |
|
|---|
| 51 | QSvgNode::QSvgNode(QSvgNode *parent)
|
|---|
| 52 | : m_parent(parent),
|
|---|
| 53 | m_visible(true),
|
|---|
| 54 | m_displayMode(BlockMode)
|
|---|
| 55 | {
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | QSvgNode::~QSvgNode()
|
|---|
| 59 | {
|
|---|
| 60 |
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | void QSvgNode::appendStyleProperty(QSvgStyleProperty *prop, const QString &id,
|
|---|
| 64 | bool justLink)
|
|---|
| 65 | {
|
|---|
| 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;
|
|---|
| 109 | }
|
|---|
| 110 | }
|
|---|
| 111 | if (!id.isEmpty()) {
|
|---|
| 112 | m_styles.insert(id, prop);
|
|---|
| 113 | }
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | void QSvgNode::applyStyle(QPainter *p, QSvgExtraStates &states)
|
|---|
| 117 | {
|
|---|
| 118 | m_style.apply(p, bounds(), this, states);
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | void QSvgNode::revertStyle(QPainter *p, QSvgExtraStates &states)
|
|---|
| 122 | {
|
|---|
| 123 | m_style.revert(p, states);
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | QSvgStyleProperty * QSvgNode::styleProperty(QSvgStyleProperty::Type type) const
|
|---|
| 127 | {
|
|---|
| 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;
|
|---|
| 181 | }
|
|---|
| 182 | node = node->parent();
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | return 0;
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | QSvgStyleProperty * QSvgNode::styleProperty(const QString &id) const
|
|---|
| 189 | {
|
|---|
| 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();
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | return 0;
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | QRectF QSvgNode::bounds() const
|
|---|
| 205 | {
|
|---|
| 206 | return QRectF(0, 0, 0, 0);
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | QSvgTinyDocument * QSvgNode::document() const
|
|---|
| 210 | {
|
|---|
| 211 | QSvgTinyDocument *doc = 0;
|
|---|
| 212 | QSvgNode *node = const_cast<QSvgNode*>(this);
|
|---|
| 213 | while (node && node->type() != QSvgNode::DOC) {
|
|---|
| 214 | node = node->parent();
|
|---|
| 215 | }
|
|---|
| 216 | doc = static_cast<QSvgTinyDocument*>(node);
|
|---|
| 217 |
|
|---|
| 218 | return doc;
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|
| 221 | void QSvgNode::setRequiredFeatures(const QStringList &lst)
|
|---|
| 222 | {
|
|---|
| 223 | m_requiredFeatures = lst;
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | const QStringList & QSvgNode::requiredFeatures() const
|
|---|
| 227 | {
|
|---|
| 228 | return m_requiredFeatures;
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | void QSvgNode::setRequiredExtensions(const QStringList &lst)
|
|---|
| 232 | {
|
|---|
| 233 | m_requiredExtensions = lst;
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 | const QStringList & QSvgNode::requiredExtensions() const
|
|---|
| 237 | {
|
|---|
| 238 | return m_requiredExtensions;
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | void QSvgNode::setRequiredLanguages(const QStringList &lst)
|
|---|
| 242 | {
|
|---|
| 243 | m_requiredLanguages = lst;
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | const QStringList & QSvgNode::requiredLanguages() const
|
|---|
| 247 | {
|
|---|
| 248 | return m_requiredLanguages;
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 | void QSvgNode::setRequiredFormats(const QStringList &lst)
|
|---|
| 252 | {
|
|---|
| 253 | m_requiredFormats = lst;
|
|---|
| 254 | }
|
|---|
| 255 |
|
|---|
| 256 | const QStringList & QSvgNode::requiredFormats() const
|
|---|
| 257 | {
|
|---|
| 258 | return m_requiredFormats;
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | void QSvgNode::setRequiredFonts(const QStringList &lst)
|
|---|
| 262 | {
|
|---|
| 263 | m_requiredFonts = lst;
|
|---|
| 264 | }
|
|---|
| 265 |
|
|---|
| 266 | const QStringList & QSvgNode::requiredFonts() const
|
|---|
| 267 | {
|
|---|
| 268 | return m_requiredFonts;
|
|---|
| 269 | }
|
|---|
| 270 |
|
|---|
| 271 | void QSvgNode::setVisible(bool visible)
|
|---|
| 272 | {
|
|---|
| 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);
|
|---|
| 279 |
|
|---|
| 280 | m_visible = visible;
|
|---|
| 281 | }
|
|---|
| 282 |
|
|---|
| 283 | QRectF QSvgNode::transformedBounds(const QTransform &transform) const
|
|---|
| 284 | {
|
|---|
| 285 | QTransform t = transform;
|
|---|
| 286 |
|
|---|
| 287 | QSvgTransformStyle *transStyle = m_style.transform;
|
|---|
| 288 | if (transStyle) {
|
|---|
| 289 | t = transStyle->qtransform() * t;
|
|---|
| 290 | }
|
|---|
| 291 |
|
|---|
| 292 | QRectF rect = bounds();
|
|---|
| 293 |
|
|---|
| 294 | rect = t.mapRect(rect);
|
|---|
| 295 |
|
|---|
| 296 | return rect;
|
|---|
| 297 | }
|
|---|
| 298 |
|
|---|
| 299 | void QSvgNode::setNodeId(const QString &i)
|
|---|
| 300 | {
|
|---|
| 301 | m_id = i;
|
|---|
| 302 | }
|
|---|
| 303 |
|
|---|
| 304 | void QSvgNode::setXmlClass(const QString &str)
|
|---|
| 305 | {
|
|---|
| 306 | m_class = str;
|
|---|
| 307 | }
|
|---|
| 308 |
|
|---|
| 309 | void QSvgNode::setDisplayMode(DisplayMode mode)
|
|---|
| 310 | {
|
|---|
| 311 | m_displayMode = mode;
|
|---|
| 312 | }
|
|---|
| 313 |
|
|---|
| 314 | QSvgNode::DisplayMode QSvgNode::displayMode() const
|
|---|
| 315 | {
|
|---|
| 316 | return m_displayMode;
|
|---|
| 317 | }
|
|---|
| 318 |
|
|---|
| 319 | qreal QSvgNode::strokeWidth() const
|
|---|
| 320 | {
|
|---|
| 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();
|
|---|
| 326 | }
|
|---|
| 327 |
|
|---|
| 328 | QT_END_NAMESPACE
|
|---|
| 329 |
|
|---|
| 330 | #endif // QT_NO_SVG
|
|---|