Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/svg/qsvggraphics.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    7979}
    8080
    81 static inline QRectF boundsOnStroke(const QPainterPath &path, qreal width)
     81static inline QRectF boundsOnStroke(const QPainterPath &path, qreal width)
    8282{
    8383    QPainterPathStroker stroker;
    8484    stroker.setWidth(width);
    8585    QPainterPath stroke = stroker.createStroke(path);
    86     return stroke.boundingRect();
    87 }
    88 
    89 QSvgCircle::QSvgCircle(QSvgNode *parent, const QRectF &rect)
     86    return .boundingRect();
     87}
     88
     89QSvge(QSvgNode *parent, const QRectF &rect)
    9090    : QSvgNode(parent), m_bounds(rect)
    9191{
     
    9393
    9494
    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)
     95QRectF 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
     103void QSvgEllipse::draw(QPainter *p, QSvgExtraStates &states)
    108104{
    109105    applyStyle(p, states);
     
    113109
    114110QSvgArc::QSvgArc(QSvgNode *parent, const QPainterPath &path)
    115     : QSvgNode(parent), cubic(path)
    116 {
    117     m_cachedBounds = path.boundingRect();
     111    : QSvgNode(parent), m_path(path)
     112{
    118113}
    119114
     
    124119        qreal oldOpacity = p->opacity();
    125120        p->setOpacity(oldOpacity * states.strokeOpacity);
    126         p->drawPath(cubic);
     121        p->drawPath();
    127122        p->setOpacity(oldOpacity);
    128123    }
    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() const
    138 {
    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));
    153124    revertStyle(p, states);
    154125}
     
    174145
    175146QSvgLine::QSvgLine(QSvgNode *parent, const QLineF &line)
    176     : QSvgNode(parent), m_bounds(line)
     147    : QSvgNode(parent), m_(line)
    177148{
    178149}
     
    185156        qreal oldOpacity = p->opacity();
    186157        p->setOpacity(oldOpacity * states.strokeOpacity);
    187         p->drawLine(m_bounds);
     158        p->drawLine(m_);
    188159        p->setOpacity(oldOpacity);
    189160    }
     
    204175}
    205176
    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     }
     177QRectF 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);
    219182}
    220183
     
    224187}
    225188
    226 QRectF QSvgPolygon::bounds() const
    227 {
    228     qreal sw = strokeWidth();
    229     if (qFuzzyIsNull(sw))
    230         return m_poly.boundingRect();
    231     else {
     189QRectF QSvgPolygon::bounds() const
     190{
     191    qreal sw = strokeWidth();
     192    if (qFuzzyIsNull(sw))
     193        return .boundingRect();
     194    else {
    232195        QPainterPath path;
    233196        path.addPolygon(m_poly);
    234         return boundsOnStroke(path, sw);
     197        return boundsOnStroke(path, sw);
    235198    }
    236199}
     
    275238}
    276239
    277 QRectF QSvgRect::bounds() const
    278 {
    279     qreal sw = strokeWidth();
    280     if (qFuzzyIsNull(sw))
    281         return m_rect;
    282     else {
     240QRectF QSvgRect::bounds() const
     241{
     242    qreal sw = strokeWidth();
     243    if (qFuzzyIsNull(sw))
     244        return ;
     245    else {
    283246        QPainterPath path;
    284247        path.addRect(m_rect);
    285         return boundsOnStroke(path, sw);
     248        return boundsOnStroke(path, sw);
    286249    }
    287250}
     
    323286}
    324287
    325 //QRectF QSvgText::bounds() const {}
     288//QRectF QSvgText::bounds() const {}
    326289
    327290void QSvgText::draw(QPainter *p, QSvgExtraStates &states)
     
    594557}
    595558
    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
     559QRectF QSvgUse::bounds(QPainter *p, QSvgExtraStates &states) const
    611560{
    612561    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);
    625566    }
    626567    return bounds;
    627568}
    628569
    629 QRectF QSvgPolyline::bounds() const
    630 {
    631     qreal sw = strokeWidth();
    632     if (qFuzzyIsNull(sw))
    633         return m_poly.boundingRect();
    634     else {
     570QRectF QSvgPolyline::bounds() const
     571{
     572    qreal sw = strokeWidth();
     573    if (qFuzzyIsNull(sw))
     574        return .boundingRect();
     575    else {
    635576        QPainterPath path;
    636577        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
     582QRectF 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
     589QRectF QSvgImage::bounds(QPainter *p, QSvgExtraStates &) const
     590{
     591    return p->transform().mapRect(m_bounds);
     592}
     593
     594QRectF QSvgLine::bounds(QPainter *p, QSvgExtraStates &) const
     595{
     596    qreal sw = strokeWidth(p);
    659597    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);
    665605    } else {
    666606        QPainterPath path;
    667         path.moveTo(m_bounds.x1(), m_bounds.y1());
    668         path.lineTo(m_bounds.x2(), m_bounds.y2());
    669         return boundsOnStroke(path, sw);
     607        path.moveTo(m_1());
     608        path.lineTo(m_2());
     609        return boundsOnStroke(path, sw);
    670610    }
    671611}
Note: See TracChangeset for help on using the changeset viewer.