Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/painting/qpainterpath.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
     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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    7474QT_BEGIN_NAMESPACE
    7575
     76struct QPainterPathPrivateDeleter
     77{
     78    static inline void cleanup(QPainterPathPrivate *d)
     79    {
     80        // note - we must up-cast to QPainterPathData since QPainterPathPrivate
     81        // has a non-virtual destructor!
     82        if (d && !d->ref.deref())
     83            delete static_cast<QPainterPathData *>(d);
     84    }
     85};
     86
    7687// This value is used to determine the length of control point vectors
    7788// when approximating arc segments as curves. The factor is multiplied
     
    154165/*!
    155166    \class QPainterPath
    156     \ingroup multimedia
     167    \ingroup painting
    157168    \ingroup shared
    158169
     
    507518*/
    508519QPainterPath::QPainterPath(const QPainterPath &other)
    509     : d_ptr(other.d_ptr)
    510 {
    511     if (d_func())
    512         d_func()->ref.ref();
     520    : d_ptr(other.d_ptr.data())
     521{
     522    if (d_ptr)
     523        d_ptr->ref.ref();
    513524}
    514525
     
    531542{
    532543    QPainterPathPrivate *data = new QPainterPathData(*d_func());
    533     if (d_ptr && !d_ptr->ref.deref())
    534         delete d_ptr;
    535     d_ptr = data;
     544    d_ptr.reset(data);
    536545}
    537546
     
    545554    QPainterPath::Element e = { 0, 0, QPainterPath::MoveToElement };
    546555    data->elements << e;
    547     if (d_ptr && !d_ptr->ref.deref())
    548         delete d_ptr;
    549     d_ptr = data;
     556    d_ptr.reset(data);
    550557    Q_ASSERT(d_ptr != 0);
    551558}
     
    564571        if (data)
    565572            data->ref.ref();
    566         if (d_ptr && !d_ptr->ref.deref())
    567             delete d_ptr;
    568         d_ptr = data;
     573        d_ptr.reset(data);
    569574    }
    570575    return *this;
     
    576581QPainterPath::~QPainterPath()
    577582{
    578     if (d_func() && !d_func()->ref.deref())
    579         delete d_func();
    580583}
    581584
     
    686689    Element elm = { p.x(), p.y(), LineToElement };
    687690    d->elements.append(elm);
     691
     692    d->convex = d->elements.size() == 3 || (d->elements.size() == 4 && d->isClosed());
    688693}
    689694
     
    958963    detach();
    959964
     965    bool first = d_func()->elements.size() < 2;
     966
    960967    d_func()->elements.reserve(d_func()->elements.size() + 5);
    961968    moveTo(r.x(), r.y());
     
    968975    d_func()->elements << l1 << l2 << l3 << l4;
    969976    d_func()->require_moveTo = true;
     977    d_func()->convex = first;
    970978}
    971979
     
    10071015    \fn void QPainterPath::addEllipse(const QRectF &boundingRectangle)
    10081016
    1009     Creates an ellipse within the the specified \a boundingRectangle
     1017    Creates an ellipse within the specified \a boundingRectangle
    10101018    and adds it to the painter path as a closed subpath.
    10111019
     
    10371045
    10381046    Q_D(QPainterPath);
     1047    bool first = d_func()->elements.size() < 2;
    10391048    d->elements.reserve(d->elements.size() + 13);
    10401049
     
    10491058    cubicTo(pts[9], pts[10], pts[11]);         // 90 - >0
    10501059    d_func()->require_moveTo = true;
     1060
     1061    d_func()->convex = first;
    10511062}
    10521063
     
    13001311        qreal cx = QT_BEZIER_C(b, x);
    13011312        // specialcase quadratic curves to avoid div by zero
    1302         if (qFuzzyCompare(ax + 1, 1)) {
     1313        if (qFuzzyIsNull(ax)) {
    13031314
    13041315            // linear curves are covered by initialization.
    1305             if (!qFuzzyCompare(bx + 1, 1)) {
     1316            if (!qFuzzyIsNull(bx)) {
    13061317                qreal t = -cx / bx;
    13071318                QT_BEZIER_CHECK_T(b, t);
     
    13301341
    13311342        // specialcase quadratic curves to avoid div by zero
    1332         if (qFuzzyCompare(ay + 1, 1)) {
     1343        if (qFuzzyIsNull(ay)) {
    13331344
    13341345            // linear curves are covered by initialization.
    1335             if (!qFuzzyCompare(by + 1, 1)) {
     1346            if (!qFuzzyIsNull(by)) {
    13361347                qreal t = -cy / by;
    13371348                QT_BEZIER_CHECK_T(b, t);
     
    15181529}
    15191530
    1520 static inline bool rect_intersects(const QRectF &r1, const QRectF &r2)
    1521 {
    1522     return qMax(r1.left(), r2.left()) <= qMin(r1.right(), r2.right())
    1523         && qMax(r1.top(), r2.top()) <= qMin(r1.bottom(), r2.bottom());
    1524 }
    1525 
    15261531/*!
    15271532    Converts the path into a list of polygons using the
     
    15761581        QRectF cbounds = bounds.at(j);
    15771582        for (int i=0; i<count; ++i) {
    1578             if (rect_intersects(cbounds, bounds.at(i))) {
     1583            if (cbounds.intersects(bounds.at(i))) {
    15791584                isects[j] << i;
    15801585            }
     
    20012006}
    20022007
    2003 
     2008/*!
     2009    Translates all elements in the path by (\a{dx}, \a{dy}).
     2010
     2011    \since 4.6
     2012    \sa translated()
     2013*/
     2014void QPainterPath::translate(qreal dx, qreal dy)
     2015{
     2016    if (!d_ptr || (dx == 0 && dy == 0))
     2017        return;
     2018
     2019    int elementsLeft = d_ptr->elements.size();
     2020    if (elementsLeft <= 0)
     2021        return;
     2022
     2023    detach();
     2024    QPainterPath::Element *element = d_func()->elements.data();
     2025    Q_ASSERT(element);
     2026    while (elementsLeft--) {
     2027        element->x += dx;
     2028        element->y += dy;
     2029        ++element;
     2030    }
     2031}
     2032
     2033/*!
     2034    \fn void QPainterPath::translate(const QPointF &offset)
     2035    \overload
     2036    \since 4.6
     2037
     2038    Translates all elements in the path by the given \a offset.
     2039
     2040    \sa translated()
     2041*/
     2042
     2043/*!
     2044    Returns a copy of the path that is translated by (\a{dx}, \a{dy}).
     2045
     2046    \since 4.6
     2047    \sa translate()
     2048*/
     2049QPainterPath QPainterPath::translated(qreal dx, qreal dy) const
     2050{
     2051    QPainterPath copy(*this);
     2052    copy.translate(dx, dy);
     2053    return copy;
     2054}
     2055
     2056/*!
     2057    \fn QPainterPath QPainterPath::translated(const QPointF &offset) const;
     2058    \overload
     2059    \since 4.6
     2060
     2061    Returns a copy of the path that is translated by the given \a offset.
     2062
     2063    \sa translate()
     2064*/
    20042065
    20052066/*!
     
    23112372    return s;
    23122373}
    2313 #endif
     2374#endif // QT_NO_DATASTREAM
    23142375
    23152376
     
    23412402    \since 4.1
    23422403    \class QPainterPathStroker
    2343     \ingroup multimedia
     2404    \ingroup painting
    23442405
    23452406    \brief The QPainterPathStroker class is used to generate fillable
     
    24092470QPainterPathStroker::~QPainterPathStroker()
    24102471{
    2411     delete d_ptr;
    24122472}
    24132473
     
    26962756    Returns percentage of the whole path at the specified length \a len.
    26972757
    2698     Note that similarly to other percent methods, the percentage measurment
     2758    Note that similarly to other percent methods, the percentage measurement
    26992759    is not linear with regards to the length, if curves are present
    27002760    in the path. When curves are present the percentage argument is mapped
     
    28132873    The argument \a t has to be between 0 and 1.
    28142874
    2815     Note that similarly to other percent methods, the percentage measurment
     2875    Note that similarly to other percent methods, the percentage measurement
    28162876    is not linear with regards to the length, if curves are present
    28172877    in the path. When curves are present the percentage argument is mapped
     
    28442904    mean the clockwise direction. Zero degrees is at the 3 o'clock position.
    28452905
    2846     Note that similarly to the other percent methods, the percentage measurment
     2906    Note that similarly to the other percent methods, the percentage measurement
    28472907    is not linear with regards to the length if curves are present
    28482908    in the path. When curves are present the percentage argument is mapped
     
    28682928}
    28692929
    2870 #if defined(Q_OS_WINCE)
     2930#if defined(Q_WS_WINCE)
    28712931#pragma warning( disable : 4056 4756 )
    28722932#endif
     
    28762936    argument \a t has to be between 0 and 1.
    28772937
    2878     Note that similarly to other percent methods, the percentage measurment
     2938    Note that similarly to other percent methods, the percentage measurement
    28792939    is not linear with regards to the length, if curves are present
    28802940    in the path. When curves are present the percentage argument is mapped
     
    29763036    detach();
    29773037
    2978     arcMoveTo(x, y, rxx2, ryy2, 90);
    2979     arcTo(x, y, rxx2, ryy2, 90, 90);
    2980     arcTo(x, y+h-ryy2, rxx2, ryy2, 2*90, 90);
    2981     arcTo(x+w-rxx2, y+h-ryy2, rxx2, ryy2, 3*90, 90);
    2982     arcTo(x+w-rxx2, y, rxx2, ryy2, 0, 90);
     3038    bool first = d_func()->elements.size() < 2;
     3039
     3040    arcMoveTo(x, y, rxx2, ryy2, 180);
     3041    arcTo(x, y, rxx2, ryy2, 180, -90);
     3042    arcTo(x+w-rxx2, y, rxx2, ryy2, 90, -90);
     3043    arcTo(x+w-rxx2, y+h-ryy2, rxx2, ryy2, 0, -90);
     3044    arcTo(x, y+h-ryy2, rxx2, ryy2, 270, -90);
    29833045    closeSubpath();
    29843046
    29853047    d_func()->require_moveTo = true;
     3048    d_func()->convex = first;
    29863049}
    29873050
     
    30303093    detach();
    30313094
    3032     arcMoveTo(x, y, rxx2, ryy2, 90);
    3033     arcTo(x, y, rxx2, ryy2, 90, 90);
    3034     arcTo(x, y+h-ryy2, rxx2, ryy2, 2*90, 90);
    3035     arcTo(x+w-rxx2, y+h-ryy2, rxx2, ryy2, 3*90, 90);
    3036     arcTo(x+w-rxx2, y, rxx2, ryy2, 0, 90);
     3095    bool first = d_func()->elements.size() < 2;
     3096
     3097    arcMoveTo(x, y, rxx2, ryy2, 180);
     3098    arcTo(x, y, rxx2, ryy2, 180, -90);
     3099    arcTo(x+w-rxx2, y, rxx2, ryy2, 90, -90);
     3100    arcTo(x+w-rxx2, y+h-ryy2, rxx2, ryy2, 0, -90);
     3101    arcTo(x, y+h-ryy2, rxx2, ryy2, 270, -90);
    30373102    closeSubpath();
    30383103
    30393104    d_func()->require_moveTo = true;
     3105    d_func()->convex = first;
    30403106}
    30413107
     
    31013167    paths will be treated as implicitly closed.
    31023168
    3103     \sa intersected(), subtracted(), subtractedInverted()
     3169    \sa intersected(), subtracted()
    31043170*/
    31053171QPainterPath QPainterPath::united(const QPainterPath &p) const
     
    32163282    d_func()->dirtyBounds        = dirty;
    32173283    d_func()->dirtyControlBounds = dirty;
     3284    delete d_func()->pathConverter;
     3285    d_func()->pathConverter = 0;
     3286    d_func()->convex = false;
    32183287}
    32193288
     
    32933362    const char *types[] = {"MoveTo", "LineTo", "CurveTo", "CurveToData"};
    32943363    for (int i=0; i<p.elementCount(); ++i) {
    3295         s.nospace() << " -> " << types[p.elementAt(i).type] << "(x=" << p.elementAt(i).x << ", y=" << p.elementAt(i).y << ")" << endl;
     3364        s.nospace() << " -> " << types[p.elementAt(i).type] << "(x=" << p.elementAt(i).x << ", y=" << p.elementAt(i).y << ')' << endl;
    32963365
    32973366    }
Note: See TracChangeset for help on using the changeset viewer.