Changeset 561 for trunk/src/gui/painting/qpainterpath.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/painting/qpainterpath.cpp
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 74 74 QT_BEGIN_NAMESPACE 75 75 76 struct 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 76 87 // This value is used to determine the length of control point vectors 77 88 // when approximating arc segments as curves. The factor is multiplied … … 154 165 /*! 155 166 \class QPainterPath 156 \ingroup multimedia167 \ingroup painting 157 168 \ingroup shared 158 169 … … 507 518 */ 508 519 QPainterPath::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(); 513 524 } 514 525 … … 531 542 { 532 543 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); 536 545 } 537 546 … … 545 554 QPainterPath::Element e = { 0, 0, QPainterPath::MoveToElement }; 546 555 data->elements << e; 547 if (d_ptr && !d_ptr->ref.deref()) 548 delete d_ptr; 549 d_ptr = data; 556 d_ptr.reset(data); 550 557 Q_ASSERT(d_ptr != 0); 551 558 } … … 564 571 if (data) 565 572 data->ref.ref(); 566 if (d_ptr && !d_ptr->ref.deref()) 567 delete d_ptr; 568 d_ptr = data; 573 d_ptr.reset(data); 569 574 } 570 575 return *this; … … 576 581 QPainterPath::~QPainterPath() 577 582 { 578 if (d_func() && !d_func()->ref.deref())579 delete d_func();580 583 } 581 584 … … 686 689 Element elm = { p.x(), p.y(), LineToElement }; 687 690 d->elements.append(elm); 691 692 d->convex = d->elements.size() == 3 || (d->elements.size() == 4 && d->isClosed()); 688 693 } 689 694 … … 958 963 detach(); 959 964 965 bool first = d_func()->elements.size() < 2; 966 960 967 d_func()->elements.reserve(d_func()->elements.size() + 5); 961 968 moveTo(r.x(), r.y()); … … 968 975 d_func()->elements << l1 << l2 << l3 << l4; 969 976 d_func()->require_moveTo = true; 977 d_func()->convex = first; 970 978 } 971 979 … … 1007 1015 \fn void QPainterPath::addEllipse(const QRectF &boundingRectangle) 1008 1016 1009 Creates an ellipse within the thespecified \a boundingRectangle1017 Creates an ellipse within the specified \a boundingRectangle 1010 1018 and adds it to the painter path as a closed subpath. 1011 1019 … … 1037 1045 1038 1046 Q_D(QPainterPath); 1047 bool first = d_func()->elements.size() < 2; 1039 1048 d->elements.reserve(d->elements.size() + 13); 1040 1049 … … 1049 1058 cubicTo(pts[9], pts[10], pts[11]); // 90 - >0 1050 1059 d_func()->require_moveTo = true; 1060 1061 d_func()->convex = first; 1051 1062 } 1052 1063 … … 1300 1311 qreal cx = QT_BEZIER_C(b, x); 1301 1312 // specialcase quadratic curves to avoid div by zero 1302 if (qFuzzy Compare(ax + 1, 1)) {1313 if (qFuzzyIsNull(ax)) { 1303 1314 1304 1315 // linear curves are covered by initialization. 1305 if (!qFuzzy Compare(bx + 1, 1)) {1316 if (!qFuzzyIsNull(bx)) { 1306 1317 qreal t = -cx / bx; 1307 1318 QT_BEZIER_CHECK_T(b, t); … … 1330 1341 1331 1342 // specialcase quadratic curves to avoid div by zero 1332 if (qFuzzy Compare(ay + 1, 1)) {1343 if (qFuzzyIsNull(ay)) { 1333 1344 1334 1345 // linear curves are covered by initialization. 1335 if (!qFuzzy Compare(by + 1, 1)) {1346 if (!qFuzzyIsNull(by)) { 1336 1347 qreal t = -cy / by; 1337 1348 QT_BEZIER_CHECK_T(b, t); … … 1518 1529 } 1519 1530 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 1526 1531 /*! 1527 1532 Converts the path into a list of polygons using the … … 1576 1581 QRectF cbounds = bounds.at(j); 1577 1582 for (int i=0; i<count; ++i) { 1578 if ( rect_intersects(cbounds,bounds.at(i))) {1583 if (cbounds.intersects(bounds.at(i))) { 1579 1584 isects[j] << i; 1580 1585 } … … 2001 2006 } 2002 2007 2003 2008 /*! 2009 Translates all elements in the path by (\a{dx}, \a{dy}). 2010 2011 \since 4.6 2012 \sa translated() 2013 */ 2014 void 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 */ 2049 QPainterPath 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 */ 2004 2065 2005 2066 /*! … … 2311 2372 return s; 2312 2373 } 2313 #endif 2374 #endif // QT_NO_DATASTREAM 2314 2375 2315 2376 … … 2341 2402 \since 4.1 2342 2403 \class QPainterPathStroker 2343 \ingroup multimedia2404 \ingroup painting 2344 2405 2345 2406 \brief The QPainterPathStroker class is used to generate fillable … … 2409 2470 QPainterPathStroker::~QPainterPathStroker() 2410 2471 { 2411 delete d_ptr;2412 2472 } 2413 2473 … … 2696 2756 Returns percentage of the whole path at the specified length \a len. 2697 2757 2698 Note that similarly to other percent methods, the percentage measur ment2758 Note that similarly to other percent methods, the percentage measurement 2699 2759 is not linear with regards to the length, if curves are present 2700 2760 in the path. When curves are present the percentage argument is mapped … … 2813 2873 The argument \a t has to be between 0 and 1. 2814 2874 2815 Note that similarly to other percent methods, the percentage measur ment2875 Note that similarly to other percent methods, the percentage measurement 2816 2876 is not linear with regards to the length, if curves are present 2817 2877 in the path. When curves are present the percentage argument is mapped … … 2844 2904 mean the clockwise direction. Zero degrees is at the 3 o'clock position. 2845 2905 2846 Note that similarly to the other percent methods, the percentage measur ment2906 Note that similarly to the other percent methods, the percentage measurement 2847 2907 is not linear with regards to the length if curves are present 2848 2908 in the path. When curves are present the percentage argument is mapped … … 2868 2928 } 2869 2929 2870 #if defined(Q_ OS_WINCE)2930 #if defined(Q_WS_WINCE) 2871 2931 #pragma warning( disable : 4056 4756 ) 2872 2932 #endif … … 2876 2936 argument \a t has to be between 0 and 1. 2877 2937 2878 Note that similarly to other percent methods, the percentage measur ment2938 Note that similarly to other percent methods, the percentage measurement 2879 2939 is not linear with regards to the length, if curves are present 2880 2940 in the path. When curves are present the percentage argument is mapped … … 2976 3036 detach(); 2977 3037 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); 2983 3045 closeSubpath(); 2984 3046 2985 3047 d_func()->require_moveTo = true; 3048 d_func()->convex = first; 2986 3049 } 2987 3050 … … 3030 3093 detach(); 3031 3094 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); 3037 3102 closeSubpath(); 3038 3103 3039 3104 d_func()->require_moveTo = true; 3105 d_func()->convex = first; 3040 3106 } 3041 3107 … … 3101 3167 paths will be treated as implicitly closed. 3102 3168 3103 \sa intersected(), subtracted() , subtractedInverted()3169 \sa intersected(), subtracted() 3104 3170 */ 3105 3171 QPainterPath QPainterPath::united(const QPainterPath &p) const … … 3216 3282 d_func()->dirtyBounds = dirty; 3217 3283 d_func()->dirtyControlBounds = dirty; 3284 delete d_func()->pathConverter; 3285 d_func()->pathConverter = 0; 3286 d_func()->convex = false; 3218 3287 } 3219 3288 … … 3293 3362 const char *types[] = {"MoveTo", "LineTo", "CurveTo", "CurveToData"}; 3294 3363 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; 3296 3365 3297 3366 }
Note:
See TracChangeset
for help on using the changeset viewer.