src/svg/qsvgnode.cpp
branchGCC_SURGE
changeset 31 5daf16870df6
parent 30 5dc02b23752f
equal deleted inserted replaced
27:93b982ccede2 31:5daf16870df6
    43 #include "qsvgtinydocument_p.h"
    43 #include "qsvgtinydocument_p.h"
    44 
    44 
    45 #ifndef QT_NO_SVG
    45 #ifndef QT_NO_SVG
    46 
    46 
    47 #include "qdebug.h"
    47 #include "qdebug.h"
       
    48 #include "qstack.h"
    48 
    49 
    49 QT_BEGIN_NAMESPACE
    50 QT_BEGIN_NAMESPACE
    50 
    51 
    51 QSvgNode::QSvgNode(QSvgNode *parent)
    52 QSvgNode::QSvgNode(QSvgNode *parent)
    52     : m_parent(parent),
    53     : m_parent(parent),
   112         qDebug("QSvgNode: Trying to append unknown property!");
   113         qDebug("QSvgNode: Trying to append unknown property!");
   113         break;
   114         break;
   114     }
   115     }
   115 }
   116 }
   116 
   117 
   117 void QSvgNode::applyStyle(QPainter *p, QSvgExtraStates &states)
   118 void QSvgNode::applyStyle(QPainter *p, QSvgExtraStates &states) const
   118 {
   119 {
   119     m_style.apply(p, bounds(), this, states);
   120     m_style.apply(p, this, states);
   120 }
   121 }
   121 
   122 
   122 void QSvgNode::revertStyle(QPainter *p, QSvgExtraStates &states)
   123 void QSvgNode::revertStyle(QPainter *p, QSvgExtraStates &states) const
   123 {
   124 {
   124     m_style.revert(p, states);
   125     m_style.revert(p, states);
   125 }
   126 }
   126 
   127 
   127 QSvgStyleProperty * QSvgNode::styleProperty(QSvgStyleProperty::Type type) const
   128 QSvgStyleProperty * QSvgNode::styleProperty(QSvgStyleProperty::Type type) const
   193         rid.remove(0, 1);
   194         rid.remove(0, 1);
   194     QSvgTinyDocument *doc = document();
   195     QSvgTinyDocument *doc = document();
   195     return doc ? doc->namedStyle(rid) : 0;
   196     return doc ? doc->namedStyle(rid) : 0;
   196 }
   197 }
   197 
   198 
   198 QRectF QSvgNode::bounds() const
   199 QRectF QSvgNode::bounds(QPainter *, QSvgExtraStates &) const
   199 {
   200 {
   200     return QRectF(0, 0, 0, 0);
   201     return QRectF(0, 0, 0, 0);
       
   202 }
       
   203 
       
   204 QRectF QSvgNode::transformedBounds() const
       
   205 {
       
   206     if (!m_cachedBounds.isEmpty())
       
   207         return m_cachedBounds;
       
   208 
       
   209     QImage dummy(1, 1, QImage::Format_RGB32);
       
   210     QPainter p(&dummy);
       
   211     QSvgExtraStates states;
       
   212 
       
   213     QPen pen(Qt::NoBrush, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
       
   214     pen.setMiterLimit(4);
       
   215     p.setPen(pen);
       
   216 
       
   217     QStack<QSvgNode*> parentApplyStack;
       
   218     QSvgNode *parent = m_parent;
       
   219     while (parent) {
       
   220         parentApplyStack.push(parent);
       
   221         parent = parent->parent();
       
   222     }
       
   223 
       
   224     for (int i = parentApplyStack.size() - 1; i >= 0; --i)
       
   225         parentApplyStack[i]->applyStyle(&p, states);
       
   226     
       
   227     p.setWorldTransform(QTransform());
       
   228 
       
   229     m_cachedBounds = transformedBounds(&p, states);
       
   230     return m_cachedBounds;
   201 }
   231 }
   202 
   232 
   203 QSvgTinyDocument * QSvgNode::document() const
   233 QSvgTinyDocument * QSvgNode::document() const
   204 {
   234 {
   205     QSvgTinyDocument *doc = 0;
   235     QSvgTinyDocument *doc = 0;
   272         m_parent->setVisible(true);
   302         m_parent->setVisible(true);
   273 
   303 
   274     m_visible = visible;
   304     m_visible = visible;
   275 }
   305 }
   276 
   306 
   277 QRectF QSvgNode::transformedBounds(const QTransform &transform) const
   307 QRectF QSvgNode::transformedBounds(QPainter *p, QSvgExtraStates &states) const
   278 {
   308 {
   279     QTransform t = transform;
   309     applyStyle(p, states);
   280 
   310     QRectF rect = bounds(p, states);
   281     QSvgTransformStyle *transStyle = m_style.transform;
   311     revertStyle(p, states);
   282     if (transStyle) {
       
   283         t = transStyle->qtransform() * t;
       
   284     }
       
   285 
       
   286     QRectF rect = bounds();
       
   287 
       
   288     rect = t.mapRect(rect);
       
   289 
       
   290     return rect;
   312     return rect;
   291 }
   313 }
   292 
   314 
   293 void QSvgNode::setNodeId(const QString &i)
   315 void QSvgNode::setNodeId(const QString &i)
   294 {
   316 {
   308 QSvgNode::DisplayMode QSvgNode::displayMode() const
   330 QSvgNode::DisplayMode QSvgNode::displayMode() const
   309 {
   331 {
   310     return m_displayMode;
   332     return m_displayMode;
   311 }
   333 }
   312 
   334 
   313 qreal QSvgNode::strokeWidth() const
   335 qreal QSvgNode::strokeWidth(QPainter *p)
   314 {
   336 {
   315     QSvgStrokeStyle *stroke = static_cast<QSvgStrokeStyle*>(
   337     QPen pen = p->pen();
   316         styleProperty(QSvgStyleProperty::STROKE));
   338     if (pen.style() == Qt::NoPen || pen.brush().style() == Qt::NoBrush || pen.isCosmetic())
   317     if (!stroke)
       
   318         return 0;
   339         return 0;
   319     if (stroke->stroke().brush().style() == Qt::NoBrush)
   340     return pen.widthF();
   320         return 0;
       
   321     return stroke->width();
       
   322 }
   341 }
   323 
   342 
   324 QT_END_NAMESPACE
   343 QT_END_NAMESPACE
   325 
   344 
   326 #endif // QT_NO_SVG
   345 #endif // QT_NO_SVG