Changeset 846 for trunk/src/svg/qsvggraphics.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/svg/qsvggraphics.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 79 79 } 80 80 81 static inline QRectF boundsOnStroke( const QPainterPath &path, qreal width)81 static inline QRectF boundsOnStroke(const QPainterPath &path, qreal width) 82 82 { 83 83 QPainterPathStroker stroker; 84 84 stroker.setWidth(width); 85 85 QPainterPath stroke = stroker.createStroke(path); 86 return stroke.boundingRect();87 } 88 89 QSvg Circle::QSvgCircle(QSvgNode *parent, const QRectF &rect)86 return .boundingRect(); 87 } 88 89 QSvge(QSvgNode *parent, const QRectF &rect) 90 90 : QSvgNode(parent), m_bounds(rect) 91 91 { … … 93 93 94 94 95 QRectF QSvgCircle::bounds() const 96 { 97 qreal sw = strokeWidth(); 98 if (qFuzzyIsNull(sw)) 99 return m_bounds; 100 else { 101 QPainterPath path; 102 path.addRect(m_bounds); 103 return boundsOnStroke(path, sw); 104 } 105 } 106 107 void QSvgCircle::draw(QPainter *p, QSvgExtraStates &states) 95 QRectF QSvgEllipse::bounds(QPainter *p, QSvgExtraStates &) const 96 { 97 QPainterPath path; 98 path.addEllipse(m_bounds); 99 qreal sw = strokeWidth(p); 100 return qFuzzyIsNull(sw) ? p->transform().map(path).boundingRect() : boundsOnStroke(p, path, sw); 101 } 102 103 void QSvgEllipse::draw(QPainter *p, QSvgExtraStates &states) 108 104 { 109 105 applyStyle(p, states); … … 113 109 114 110 QSvgArc::QSvgArc(QSvgNode *parent, const QPainterPath &path) 115 : QSvgNode(parent), cubic(path) 116 { 117 m_cachedBounds = path.boundingRect(); 111 : QSvgNode(parent), m_path(path) 112 { 118 113 } 119 114 … … 124 119 qreal oldOpacity = p->opacity(); 125 120 p->setOpacity(oldOpacity * states.strokeOpacity); 126 p->drawPath( cubic);121 p->drawPath(); 127 122 p->setOpacity(oldOpacity); 128 123 } 129 revertStyle(p, states);130 }131 132 QSvgEllipse::QSvgEllipse(QSvgNode *parent, const QRectF &rect)133 : QSvgNode(parent), m_bounds(rect)134 {135 }136 137 QRectF QSvgEllipse::bounds() const138 {139 qreal sw = strokeWidth();140 if (qFuzzyIsNull(sw))141 return m_bounds;142 else {143 QPainterPath path;144 path.addEllipse(m_bounds);145 return boundsOnStroke(path, sw);146 }147 }148 149 void QSvgEllipse::draw(QPainter *p, QSvgExtraStates &states)150 {151 applyStyle(p, states);152 QT_SVG_DRAW_SHAPE(p->drawEllipse(m_bounds));153 124 revertStyle(p, states); 154 125 } … … 174 145 175 146 QSvgLine::QSvgLine(QSvgNode *parent, const QLineF &line) 176 : QSvgNode(parent), m_ bounds(line)147 : QSvgNode(parent), m_(line) 177 148 { 178 149 } … … 185 156 qreal oldOpacity = p->opacity(); 186 157 p->setOpacity(oldOpacity * states.strokeOpacity); 187 p->drawLine(m_ bounds);158 p->drawLine(m_); 188 159 p->setOpacity(oldOpacity); 189 160 } … … 204 175 } 205 176 206 QRectF QSvgPath::bounds() const 207 { 208 qreal sw = strokeWidth(); 209 if (qFuzzyIsNull(sw)) { 210 if (m_cachedBounds.isNull()) 211 //m_cachedBounds = m_path.controlPointRect(); 212 m_cachedBounds = m_path.boundingRect(); 213 214 return m_cachedBounds; 215 } 216 else { 217 return boundsOnStroke(m_path, sw); 218 } 177 QRectF QSvgPath::bounds(QPainter *p, QSvgExtraStates &) const 178 { 179 qreal sw = strokeWidth(p); 180 return qFuzzyIsNull(sw) ? p->transform().map(m_path).boundingRect() 181 : boundsOnStroke(p, m_path, sw); 219 182 } 220 183 … … 224 187 } 225 188 226 QRectF QSvgPolygon::bounds( ) const227 { 228 qreal sw = strokeWidth( );229 if (qFuzzyIsNull(sw)) 230 return m_poly.boundingRect();231 else {189 QRectF QSvgPolygon::bounds() const 190 { 191 qreal sw = strokeWidth(); 192 if (qFuzzyIsNull(sw)) 193 return .boundingRect(); 194 else { 232 195 QPainterPath path; 233 196 path.addPolygon(m_poly); 234 return boundsOnStroke(p ath, sw);197 return boundsOnStroke(path, sw); 235 198 } 236 199 } … … 275 238 } 276 239 277 QRectF QSvgRect::bounds( ) const278 { 279 qreal sw = strokeWidth( );280 if (qFuzzyIsNull(sw)) 281 return m_rect;282 else {240 QRectF QSvgRect::bounds() const 241 { 242 qreal sw = strokeWidth(); 243 if (qFuzzyIsNull(sw)) 244 return ; 245 else { 283 246 QPainterPath path; 284 247 path.addRect(m_rect); 285 return boundsOnStroke(p ath, sw);248 return boundsOnStroke(path, sw); 286 249 } 287 250 } … … 323 286 } 324 287 325 //QRectF QSvgText::bounds( ) const {}288 //QRectF QSvgText::bounds() const {} 326 289 327 290 void QSvgText::draw(QPainter *p, QSvgExtraStates &states) … … 594 557 } 595 558 596 QRectF QSvgUse::bounds() const 597 { 598 if (m_link && m_bounds.isEmpty()) { 599 m_bounds = m_link->bounds(); 600 m_bounds = QRectF(m_bounds.x()+m_start.x(), 601 m_bounds.y()+m_start.y(), 602 m_bounds.width(), 603 m_bounds.height()); 604 605 return m_bounds; 606 } 607 return m_bounds; 608 } 609 610 QRectF QSvgUse::transformedBounds(const QTransform &transform) const 559 QRectF QSvgUse::bounds(QPainter *p, QSvgExtraStates &states) const 611 560 { 612 561 QRectF bounds; 613 QTransform t = transform; 614 615 if (m_link) { 616 QSvgTransformStyle *transStyle = m_style.transform; 617 if (transStyle) { 618 t = transStyle->qtransform() * t; 619 } 620 t.translate(m_start.x(), m_start.y()); 621 622 bounds = m_link->transformedBounds(t); 623 624 return bounds; 562 if (m_link) { 563 p->translate(m_start); 564 bounds = m_link->transformedBounds(p, states); 565 p->translate(-m_start); 625 566 } 626 567 return bounds; 627 568 } 628 569 629 QRectF QSvgPolyline::bounds( ) const630 { 631 qreal sw = strokeWidth( );632 if (qFuzzyIsNull(sw)) 633 return m_poly.boundingRect();634 else {570 QRectF QSvgPolyline::bounds() const 571 { 572 qreal sw = strokeWidth(); 573 if (qFuzzyIsNull(sw)) 574 return .boundingRect(); 575 else { 635 576 QPainterPath path; 636 577 path.addPolygon(m_poly); 637 return boundsOnStroke(path, sw); 638 } 639 } 640 641 QRectF QSvgArc::bounds() const 642 { 643 qreal sw = strokeWidth(); 644 if (qFuzzyIsNull(sw)) 645 return m_cachedBounds; 646 else { 647 return boundsOnStroke(cubic, sw); 648 } 649 } 650 651 QRectF QSvgImage::bounds() const 652 { 653 return m_bounds; 654 } 655 656 QRectF QSvgLine::bounds() const 657 { 658 qreal sw = strokeWidth(); 578 return boundsOnStroke(p, path, sw); 579 } 580 } 581 582 QRectF QSvgArc::bounds(QPainter *p, QSvgExtraStates &) const 583 { 584 qreal sw = strokeWidth(p); 585 return qFuzzyIsNull(sw) ? p->transform().map(m_path).boundingRect() 586 : boundsOnStroke(p, m_path, sw); 587 } 588 589 QRectF QSvgImage::bounds(QPainter *p, QSvgExtraStates &) const 590 { 591 return p->transform().mapRect(m_bounds); 592 } 593 594 QRectF QSvgLine::bounds(QPainter *p, QSvgExtraStates &) const 595 { 596 qreal sw = strokeWidth(p); 659 597 if (qFuzzyIsNull(sw)) { 660 qreal minX = qMin(m_bounds.x1(), m_bounds.x2()); 661 qreal minY = qMin(m_bounds.y1(), m_bounds.y2()); 662 qreal maxX = qMax(m_bounds.x1(), m_bounds.x2()); 663 qreal maxY = qMax(m_bounds.y1(), m_bounds.y2()); 664 return QRectF(minX, minY, maxX-minX, maxY-minY); 598 QPointF p1 = p->transform().map(m_line.p1()); 599 QPointF p2 = p->transform().map(m_line.p2()); 600 qreal minX = qMin(p1.x(), p2.x()); 601 qreal minY = qMin(p1.y(), p2.y()); 602 qreal maxX = qMax(p1.x(), p2.x()); 603 qreal maxY = qMax(p1.y(), p2.y()); 604 return QRectF(minX, minY, maxX - minX, maxY - minY); 665 605 } else { 666 606 QPainterPath path; 667 path.moveTo(m_ bounds.x1(), m_bounds.y1());668 path.lineTo(m_ bounds.x2(), m_bounds.y2());669 return boundsOnStroke(p ath, sw);607 path.moveTo(m_1()); 608 path.lineTo(m_2()); 609 return boundsOnStroke(path, sw); 670 610 } 671 611 }
Note:
See TracChangeset
for help on using the changeset viewer.