#include <qpainterpath.h>
Collaboration diagram for QPainterPath:

A painter path is an object composed of a number of graphical building blocks, such as rectangles, ellipses, lines, and curves. Building blocks can be joined in closed subpaths, for example as a rectangle or an ellipse. A closed path has coinciding start and end points. Or they can exist independently as unclosed subpaths, such as lines and curves.
A QPainterPath object can be used for filling, outlining, and clipping. To generate fillable outlines for a given painter path, use the QPainterPathStroker class. The main advantage of painter paths over normal drawing operations is that complex shapes only need to be created once; then they can be drawn many times using only calls to the QPainter::drawPath() function.
QPainterPath provides a collection of functions that can be used to obtain information about the path and its elements. In addition it is possible to reverse the order of the elements using the toReversed() function. There are also several functions to convert this painter path object into a polygon representation.
A QPainterPath object can be constructed as an empty path, with a given start point, or as a copy of another QPainterPath object. Once created, lines and curves can be added to the path using the lineTo(), arcTo(), cubicTo() and quadTo() functions. The lines and curves stretch from the currentPosition() to the position passed as argument. The currentPosition() of the QPainterPath object is always the end position of the last subpath that was added (or the initial start point). Use the moveTo() function to move the currentPosition() without adding a component. The moveTo() function implicitly starts a new subpath, and closes the previous one. Another way of starting a new subpath is to call the closeSubpath() function which closes the current path by adding a line from the currentPosition() back to the path's start position. Note that the new path will have (0, 0) as its initial currentPosition(). QPainterPath class also provides several convenience functions to add closed subpaths to a painter path: addEllipse(), addPath(), addRect(), addRegion() and addText(). The addPolygon() function adds an \e unclosed subpath. In fact, these functions are all collections of moveTo(), lineTo() and cubicTo() operations. In addition, a path can be added to the current path using the connectPath() function. But note that this function will connect the last element of the current path to the first element of given one by adding a line. Below is a code snippet that shows how a QPainterPath object can be used: \table 100% \row \o \inlineimage qpainterpath-construction.png \o @code QPainterPath path; path.addRect(20, 20, 60, 60); path.moveTo(0, 0); path.cubicTo(99, 0, 50, 50, 99, 99); path.cubicTo(0, 99, 50, 50, 0, 0); QPainter painter(this); painter.fillRect(0, 0, 100, 100, Qt::white); painter.setPen(QPen(QColor(79, 106, 25), 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); painter.setBrush(QColor(122, 163, 39)); painter.drawPath(path); \endcode \endtable The painter path is initially empty when constructed. We first add a rectangle, which is a closed subpath. Then we add two bezier curves which together form a closed subpath even though they are not closed individually. Finally we draw the entire path. The path is filled using the default fill rule, Qt::OddEvenFill. Qt provides two methods for filling paths: \table \row \o \inlineimage qt-fillrule-oddeven.png \o \inlineimage qt-fillrule-winding.png \header \o Qt::OddEvenFill \o Qt::WindingFill \endtable See the Qt::Fillrule documentation for the definition of the rules. A painter path's currently set fill rule can be retrieved using the fillRule() function, and altered using the setFillRule() function. @section QPainterPath Information The QPainterPath class provides a collection of functions that returns information about the path and its elements. The currentPosition() function returns the end point of the last subpath that was added (or the initial start point). The elementAt() function can be used to retrieve the various subpath elements, the \e number of elements can be retrieved using the elementCount() function, and the isEmpty() function tells whether this QPainterPath object contains any elements at all. The controlPointRect() function returns the rectangle containing all the points and control points in this path. This function is significantly faster to compute than the exact boundingRect() which returns the bounding rectangle of this painter path with floating point precision. Finally, QPainterPath provides the contains() function which can be used to determine whether a given point or rectangle is inside the path, and the intersects() function which determines if any of the points inside a given rectangle also are inside this path. @section QPainterPath Conversion For compatibility reasons, it might be required to simplify the representation of a painter path: QPainterPath provides the toFillPolygon(), toFillPolygons() and toSubpathPolygons() functions which convert the painter path into a polygon. The toFillPolygon() returns the painter path as one single polygon, while the two latter functions return a list of polygons. The toFillPolygons() and toSubpathPolygons() functions are provided because it is usually faster to draw several small polygons than to draw one large polygon, even though the total number of points drawn is the same. The difference between the two is the \e number of polygons they return: The toSubpathPolygons() creates one polygon for each subpath regardless of intersecting subpaths (i.e. overlapping bounding rectangles), while the toFillPolygons() functions creates only one polygon for overlapping subpaths. The toFillPolygon() and toFillPolygons() functions first convert all the subpaths to polygons, then uses a rewinding technique to make sure that overlapping subpaths can be filled using the correct fill rule. Note that rewinding inserts additional lines in the polygon so the outline of the fill polygon does not match the outline of the path. @section Examples Qt provides the \l {painting/painterpaths}{Painter Paths Example} and the \l {demos/deform}{Vector Deformation Demo} which are located in Qt's example and demo directories respectively. The \l {painting/painterpaths}{Painter Paths Example} shows how painter paths can be used to build complex shapes for rendering and lets the user experiment with the filling and stroking. The \l {demos/deform}{Vector Deformation Demo} shows how to use QPainterPath to draw text. \table \row \o \inlineimage qpainterpath-example.png \o \inlineimage qpainterpath-demo.png \header \o \l {painting/painterpaths}{Painter Paths Example} \o \l {demos/deform}{Vector Deformation Demo} \endtable \sa QPainterPathStroker, QPainter, QRegion, {Painter Paths Example} Definition at line 44 of file qpainterpath.h.
Public Types | |
| enum | ElementType |
Public Member Functions | |
| QPainterPath () | |
| QPainterPath (const QPointF &startPoint) | |
| QPainterPath (const QPainterPath &other) | |
| QPainterPath & | operator= (const QPainterPath &other) |
| ~QPainterPath () | |
| void | closeSubpath () |
| void | moveTo (const QPointF &p) |
| void | moveTo (qreal x, qreal y) |
| void | lineTo (const QPointF &p) |
| void | lineTo (qreal x, qreal y) |
| void | arcMoveTo (const QRectF &rect, qreal angle) |
| void | arcMoveTo (qreal x, qreal y, qreal w, qreal h, qreal angle) |
| void | arcTo (const QRectF &rect, qreal startAngle, qreal arcLength) |
| void | arcTo (qreal x, qreal y, qreal w, qreal h, qreal startAngle, qreal arcLength) |
| void | cubicTo (const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt) |
| void | cubicTo (qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y, qreal endPtx, qreal endPty) |
| void | quadTo (const QPointF &ctrlPt, const QPointF &endPt) |
| void | quadTo (qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty) |
| QPointF | currentPosition () const |
| void | addRect (const QRectF &rect) |
| void | addRect (qreal x, qreal y, qreal w, qreal h) |
| void | addEllipse (const QRectF &rect) |
| void | addEllipse (qreal x, qreal y, qreal w, qreal h) |
| void | addPolygon (const QPolygonF &polygon) |
| void | addText (const QPointF &point, const QFont &f, const QString &text) |
| void | addText (qreal x, qreal y, const QFont &f, const QString &text) |
| void | addPath (const QPainterPath &path) |
| void | addRegion (const QRegion ®ion) |
| void | connectPath (const QPainterPath &path) |
| bool | contains (const QPointF &pt) const |
| bool | contains (const QRectF &rect) const |
| bool | intersects (const QRectF &rect) const |
| QRectF | boundingRect () const |
| QRectF | controlPointRect () const |
| Qt::FillRule | fillRule () const |
| void | setFillRule (Qt::FillRule fillRule) |
| bool | isEmpty () const |
| QPainterPath | toReversed () const |
| QList< QPolygonF > | toSubpathPolygons (const QMatrix &matrix=QMatrix()) const |
| QList< QPolygonF > | toFillPolygons (const QMatrix &matrix=QMatrix()) const |
| QPolygonF | toFillPolygon (const QMatrix &matrix=QMatrix()) const |
| int | elementCount () const |
| const QPainterPath::Element & | elementAt (int i) const |
| void | setElementPositionAt (int i, qreal x, qreal y) |
| bool | operator== (const QPainterPath &other) const |
| bool | operator!= (const QPainterPath &other) const |
Private Member Functions | |
| void | ensureData () |
| void | ensureData_helper () |
| void | detach () |
| void | detach_helper () |
| QPainterPathData * | d_func () const |
Private Attributes | |
| QPainterPathPrivate * | d_ptr |
Friends | |
| class | QPainterPathData |
| class | QPainterPathStroker |
| class | QPainterPathStrokerPrivate |
| class | QMatrix |
| Q_GUI_EXPORT QDataStream & | operator<< (QDataStream &, const QPainterPath &) |
| Q_GUI_EXPORT QDataStream & | operator>> (QDataStream &, QPainterPath &) |
Classes | |
| class | Element |
| The QPainterPath::Element class specifies the position and type of a subpath. More... | |
This enum describes the types of elements used to connect vertices in subpaths.
Note that elements added as closed subpaths using the addEllipse(), addPath(), addPolygon(), addRect(), addRegion() and addText() convenience functions, is actually added to the path as a collection of separate elements using the moveTo(), lineTo() and cubicTo() functions.
MoveToElement A new subpath. See also moveTo(). LineToElement A line. See also lineTo(). CurveToElement A curve. See also cubicTo() and quadTo(). CurveToDataElement The extra data required to describe a curve in a CurveToElement element.
Definition at line 47 of file qpainterpath.h.
00047 { 00048 MoveToElement, 00049 LineToElement, 00050 CurveToElement, 00051 CurveToDataElement 00052 };
| QPainterPath::QPainterPath | ( | ) |
Constructs an empty QPainterPath object.
Definition at line 462 of file qpainterpath.cpp.
00463 : d_ptr(0) 00464 { 00465 }
| QPainterPath::QPainterPath | ( | const QPointF & | startPoint | ) | [explicit] |
Creates a QPainterPath object with the given startPoint as its current position.
Definition at line 486 of file qpainterpath.cpp.
References d_func(), MoveToElement, QPointF::x(), and QPointF::y().
00487 : d_ptr(new QPainterPathData) 00488 { 00489 Element e = { startPoint.x(), startPoint.y(), MoveToElement }; 00490 d_func()->elements << e; 00491 }
Here is the call graph for this function:

| QPainterPath::QPainterPath | ( | const QPainterPath & | path | ) |
Creates a QPainterPath object that is a copy of the given path.
Definition at line 474 of file qpainterpath.cpp.
References d_func().
Here is the call graph for this function:

| QPainterPath::~QPainterPath | ( | ) |
Destroys this QPainterPath object.
Definition at line 541 of file qpainterpath.cpp.
References d_func().
Here is the call graph for this function:

| QPainterPath & QPainterPath::operator= | ( | const QPainterPath & | path | ) |
Assigns the given path to this painter path.
Definition at line 526 of file qpainterpath.cpp.
References d_func(), d_ptr, data, and qAtomicSetPtr().
00527 { 00528 if (other.d_func() != d_func()) { 00529 QPainterPathPrivate *data = other.d_func(); 00530 if (data) data->ref.ref(); 00531 data = qAtomicSetPtr(&d_ptr, data); 00532 if (data && !data->ref.deref()) 00533 delete (QPainterPathData *) data; 00534 } 00535 return *this; 00536 }
Here is the call graph for this function:

| void QPainterPath::closeSubpath | ( | ) |
Closes the current subpath by drawing a line to the beginning of the subpath, automatically starting a new path. The current point of the new path is (0, 0).
If the subpath does not contain any elements, this function does nothing.
Definition at line 558 of file qpainterpath.cpp.
References QPainterPathData::close(), d_func(), detach(), isEmpty(), and printf.
Referenced by QPainter::drawConvexPolygon(), QPainter::drawPolygon(), PieView::itemRegion(), ArthurFrame::paintEvent(), Launcher::showCategories(), and Launcher::showExamples().
00559 { 00560 #ifdef QPP_DEBUG 00561 printf("QPainterPath::closeSubpath()\n"); 00562 #endif 00563 if (isEmpty()) 00564 return; 00565 detach(); 00566 00567 d_func()->close(); 00568 }
Here is the call graph for this function:

| void QPainterPath::moveTo | ( | const QPointF & | point | ) |
Moves the current point to the given point, implicitly starting a new subpath and closing the previous one.
Definition at line 588 of file qpainterpath.cpp.
References d, d_func(), detach(), ensureData(), MoveToElement, p, printf, qIsNan(), and qWarning().
Referenced by addEllipse(), addPolygon(), addRect(), arcMoveTo(), QPainter::drawLines(), ArthurStyle::drawPrimitive(), PieView::itemRegion(), moveTo(), RenderArea::paintEvent(), ArthurFrame::paintEvent(), Window::setupShapes(), Launcher::showCategories(), Launcher::showExamples(), SortingBox::SortingBox(), and toReversed().
00589 { 00590 #ifdef QPP_DEBUG 00591 printf("QPainterPath::moveTo() (%.2f,%.2f)\n", p.x(), p.y()); 00592 #endif 00593 #ifndef QT_NO_DEBUG 00594 if (qIsNan(p.x()) || qIsNan(p.y())) 00595 qWarning("QPainterPath::moveTo: Adding point where x or y is NaN, results are undefined"); 00596 #endif 00597 ensureData(); 00598 detach(); 00599 00600 QPainterPathData *d = d_func(); 00601 Q_ASSERT(!d->elements.isEmpty()); 00602 00603 d->require_moveTo = false; 00604 00605 if (d->elements.last().type == MoveToElement) { 00606 d->elements.last().x = p.x(); 00607 d->elements.last().y = p.y(); 00608 } else { 00609 Element elm = { p.x(), p.y(), MoveToElement }; 00610 d->elements.append(elm); 00611 } 00612 d->cStart = d->elements.size() - 1; 00613 }
Here is the call graph for this function:

| void QPainterPath::moveTo | ( | qreal | x, | |
| qreal | y | |||
| ) | [inline] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Moves the current position to ({x}, {y}) and starts a new subpath, implicitly closing the previous path.
Definition at line 211 of file qpainterpath.h.
References moveTo().
Here is the call graph for this function:

| void QPainterPath::lineTo | ( | const QPointF & | endPoint | ) |
Adds a straight line from the current position to the given endPoint. After the line is drawn, the current position is updated to be at the end point of the line.
Definition at line 634 of file qpainterpath.cpp.
References d, d_func(), detach(), ensureData(), LineToElement, p, printf, qIsNan(), and qWarning().
Referenced by arcTo(), QPlastiqueStyle::drawControl(), QPainter::drawConvexPolygon(), QPainter::drawLines(), QPainter::drawPolygon(), QPainter::drawPolyline(), lineTo(), VersionLabel::mouseMoveEvent(), VersionLabel::mouseReleaseEvent(), RenderArea::paintEvent(), Window::setupShapes(), Launcher::showCategories(), Launcher::showExamples(), SortingBox::SortingBox(), and toReversed().
00635 { 00636 #ifdef QPP_DEBUG 00637 printf("QPainterPath::lineTo() (%.2f,%.2f)\n", p.x(), p.y()); 00638 #endif 00639 #ifndef QT_NO_DEBUG 00640 if (qIsNan(p.x()) || qIsNan(p.y())) 00641 qWarning("QPainterPath::lineTo: Adding point where x or y is NaN, results are undefined"); 00642 #endif 00643 ensureData(); 00644 detach(); 00645 00646 QPainterPathData *d = d_func(); 00647 Q_ASSERT(!d->elements.isEmpty()); 00648 d->maybeMoveTo(); 00649 if (p == QPointF(d->elements.last())) 00650 return; 00651 Element elm = { p.x(), p.y(), LineToElement }; 00652 d->elements.append(elm); 00653 }
Here is the call graph for this function:

| void QPainterPath::lineTo | ( | qreal | x, | |
| qreal | y | |||
| ) | [inline] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Draws a line from the current position to the point ({x}, {y}).
Definition at line 216 of file qpainterpath.h.
References lineTo().
Here is the call graph for this function:

| void QPainterPath::arcMoveTo | ( | const QRectF & | rectangle, | |
| qreal | angle | |||
| ) |
Angles are specified in degrees. Clockwise arcs can be specified using negative angles.
Definition at line 886 of file qpainterpath.cpp.
References QRectF::isNull(), moveTo(), and qt_find_ellipse_coords().
Referenced by arcMoveTo().
00887 { 00888 if (rect.isNull()) 00889 return; 00890 00891 QPointF pt; 00892 qt_find_ellipse_coords(rect, angle, 0, &pt, 0); 00893 moveTo(pt); 00894 }
Here is the call graph for this function:

| void QPainterPath::arcMoveTo | ( | qreal | x, | |
| qreal | y, | |||
| qreal | width, | |||
| qreal | height, | |||
| qreal | angle | |||
| ) | [inline] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 226 of file qpainterpath.h.
References arcMoveTo().
Here is the call graph for this function:

| void QPainterPath::arcTo | ( | const QRectF & | rectangle, | |
| qreal | startAngle, | |||
| qreal | sweepLength | |||
| ) |
Creates an arc that occupies the given rectangle, beginning at the specified startAngle and extending sweepLength degrees counter-clockwise.
Angles are specified in degrees. Clockwise arcs can be specified using negative angles.
Note that this function connects the starting point of the arc to the current position if they are not already connected. After the arc has been added, the current position is the last point in arc. To draw a line back to the first point, use the closeSubpath() function.
100% qpainterpath-arcto.png
QLinearGradient myGradient; QPen myPen; QPointF center, startPoint; QPainterPath myPath; myPath.moveTo(center); myPath.arcTo(boundingRect, startAngle, sweepLength); QPainter painter(this); painter.setBrush(myGradient); painter.setPen(myPen); painter.drawPath(myPath);
Definition at line 832 of file qpainterpath.cpp.
References cubicTo(), detach(), ensureData(), QRectF::height(), i, QRectF::isNull(), lineTo(), printf, qIsNan(), qt_curves_for_arc(), qWarning(), QRectF::width(), QRectF::x(), x, QRectF::y(), and y.
Referenced by arcTo(), ArthurStyle::drawPrimitive(), PieView::itemRegion(), and ArthurFrame::paintEvent().
00833 { 00834 #ifdef QPP_DEBUG 00835 printf("QPainterPath::arcTo() (%.2f, %.2f, %.2f, %.2f, angle=%.2f, sweep=%.2f\n", 00836 rect.x(), rect.y(), rect.width(), rect.height(), startAngle, sweepLength); 00837 #endif 00838 #ifndef QT_NO_DEBUG 00839 if (qIsNan(rect.x()) || qIsNan(rect.y()) || qIsNan(rect.width()) || qIsNan(rect.height()) 00840 || qIsNan(startAngle) || qIsNan(sweepLength)) 00841 qWarning("QPainterPath::arcTo: Adding arc where a parameter is NaN, results are undefined"); 00842 #endif 00843 if (rect.isNull()) 00844 return; 00845 00846 ensureData(); 00847 detach(); 00848 00849 int point_count; 00850 QPointF pts[12]; 00851 QPointF curve_start = qt_curves_for_arc(rect, startAngle, sweepLength, pts, &point_count); 00852 00853 lineTo(curve_start); 00854 for (int i=0; i<point_count; i+=3) { 00855 cubicTo(pts[i].x(), pts[i].y(), 00856 pts[i+1].x(), pts[i+1].y(), 00857 pts[i+2].x(), pts[i+2].y()); 00858 } 00859 00860 }
Here is the call graph for this function:

| void QPainterPath::arcTo | ( | qreal | x, | |
| qreal | y, | |||
| qreal | width, | |||
| qreal | height, | |||
| qreal | startAngle, | |||
| qreal | sweepLength | |||
| ) | [inline] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Creates an arc that occupies the rectangle QRectF(x, y, width, height), beginning at the specified startAngle and extending sweepLength degrees counter-clockwise.
Definition at line 221 of file qpainterpath.h.
References arcTo().
Here is the call graph for this function:

Adds a cubic Bezier curve between the current position and the given endPoint using the control points specified by c1, and c2.
After the curve is added, the current position is updated to be at the end point of the curve.
100% qpainterpath-cubicto.png
QLinearGradient myGradient; QPen myPen; QPainterPath myPath; myPath.cubicto(c1, c2, endPoint); QPainter painter(this); painter.setBrush(myGradient); painter.setPen(myPen); painter.drawPath(myPath);
Definition at line 697 of file qpainterpath.cpp.
References CurveToDataElement, CurveToElement, d, d_func(), detach(), ensureData(), printf, qIsNan(), qWarning(), QPointF::x(), and QPointF::y().
Referenced by addEllipse(), arcTo(), cubicTo(), RenderArea::paintEvent(), quadTo(), and toReversed().
00698 { 00699 #ifdef QPP_DEBUG 00700 printf("QPainterPath::cubicTo() (%.2f,%.2f), (%.2f,%.2f), (%.2f,%.2f)\n", 00701 c1.x(), c1.y(), c2.x(), c2.y(), e.x(), e.y()); 00702 #endif 00703 #ifndef QT_NO_DEBUG 00704 if (qIsNan(c1.x()) || qIsNan(c1.y()) || qIsNan(c2.x()) || qIsNan(c2.y()) 00705 || qIsNan(e.x()) || qIsNan(e.y())) 00706 qWarning("QPainterPath::cubicTo: Adding point where x or y is NaN, results are undefined"); 00707 #endif 00708 ensureData(); 00709 detach(); 00710 00711 QPainterPathData *d = d_func(); 00712 Q_ASSERT(!d->elements.isEmpty()); 00713 00714 00715 // Abort on empty curve as a stroker cannot handle this and the 00716 // curve is irrelevant anyway. 00717 if (d->elements.last() == c1 && c1 == c2 && c2 == e) 00718 return; 00719 00720 d->maybeMoveTo(); 00721 00722 Element ce1 = { c1.x(), c1.y(), CurveToElement }; 00723 Element ce2 = { c2.x(), c2.y(), CurveToDataElement }; 00724 Element ee = { e.x(), e.y(), CurveToDataElement }; 00725 d->elements << ce1 << ce2 << ee; 00726 }
Here is the call graph for this function:

| void QPainterPath::cubicTo | ( | qreal | c1X, | |
| qreal | c1Y, | |||
| qreal | c2X, | |||
| qreal | c2Y, | |||
| qreal | endPointX, | |||
| qreal | endPointY | |||
| ) | [inline] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Adds a cubic Bezier curve between the current position and the end point ({endPointX}, {endPointY}) with control points specified by ({c1X}, {c1Y}) and ({c2X}, {c2Y}).
Definition at line 231 of file qpainterpath.h.
References cubicTo().
00233 { 00234 cubicTo(QPointF(ctrlPt1x, ctrlPt1y), QPointF(ctrlPt2x, ctrlPt2y), 00235 QPointF(endPtx, endPty)); 00236 }
Here is the call graph for this function:

Adds a quadratic Bezier curve between the current position and the given endPoint with the control point specified by c.
After the curve is added, the current point is updated to be at the end point of the curve.
Definition at line 750 of file qpainterpath.cpp.
References c, cubicTo(), d, detach(), elementCount(), ensureData(), printf, qIsNan(), qWarning(), QPainterPath::Element::x, QPointF::x(), QPainterPath::Element::y, and QPointF::y().
Referenced by quadTo().
00751 { 00752 #ifdef QPP_DEBUG 00753 printf("QPainterPath::quadTo() (%.2f,%.2f), (%.2f,%.2f)\n", 00754 c.x(), c.y(), e.x(), e.y()); 00755 #endif 00756 #ifndef QT_NO_DEBUG 00757 if (qIsNan(c.x()) || qIsNan(c.y()) || qIsNan(e.x()) || qIsNan(e.y())) 00758 qWarning("QPainterPath::quadTo: Adding point where x or y is NaN, results are undefined"); 00759 #endif 00760 ensureData(); 00761 detach(); 00762 00763 Q_D(QPainterPath); 00764 Q_ASSERT(!d->elements.isEmpty()); 00765 const QPainterPath::Element &elm = d->elements.at(elementCount()-1); 00766 QPointF prev(elm.x, elm.y); 00767 00768 // Abort on empty curve as a stroker cannot handle this and the 00769 // curve is irrelevant anyway. 00770 if (prev == c && c == e) 00771 return; 00772 00773 QPointF c1((prev.x() + 2*c.x()) / 3, (prev.y() + 2*c.y()) / 3); 00774 QPointF c2((e.x() + 2*c.x()) / 3, (e.y() + 2*c.y()) / 3); 00775 cubicTo(c1, c2, e); 00776 }
Here is the call graph for this function:

| void QPainterPath::quadTo | ( | qreal | cx, | |
| qreal | cy, | |||
| qreal | endPointX, | |||
| qreal | endPointY | |||
| ) | [inline] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Adds a quadratic Bezier curve between the current point and the endpoint ({endPointX}, {endPointY}) with the control point specified by ({cx}, {cy}).
Definition at line 238 of file qpainterpath.h.
References quadTo().
Here is the call graph for this function:

| QPointF QPainterPath::currentPosition | ( | ) | const |
Returns the current position of the path.
Definition at line 903 of file qpainterpath.cpp.
References d_func(), d_ptr, and elements.
Referenced by SortingBox::SortingBox().
00904 { 00905 return !d_ptr || d_func()->elements.isEmpty() 00906 ? QPointF() 00907 : QPointF(d_func()->elements.last().x, d_func()->elements.last().y); 00908 }
Here is the call graph for this function:

| void QPainterPath::addRect | ( | const QRectF & | rectangle | ) |
Adds the given rectangle to this path as a closed subpath.
The rectangle is added as a clockwise set of lines. The painter path's current position after the rectangle has been added is at the top-left corner of the rectangle.
100% qpainterpath-addrectangle.png
QLinearGradient myGradient; QPen myPen; QRectF myRectangle; QPainterPath myPath; myPath.addRect(myRectangle); QPainter painter(this); painter.setBrush(myGradient); painter.setPen(myPen); painter.drawPath(myPath);
Definition at line 951 of file qpainterpath.cpp.
References d_func(), detach(), elements, ensureData(), QRectF::height(), QRectF::isNull(), LineToElement, moveTo(), qIsNan(), qWarning(), QPainterPathData::require_moveTo, QRectF::width(), QRectF::x(), and QRectF::y().
Referenced by addRect(), addRegion(), addText(), Launcher::addTitleBackground(), QGraphicsItem::collidesWithPath(), QPainter::drawRects(), QPaintEngine::drawTextItem(), Window::setupShapes(), Launcher::showCategories(), SortingBox::SortingBox(), and QGraphicsPixmapItemPrivate::updateShape().
00952 { 00953 #ifndef QT_NO_DEBUG 00954 if (qIsNan(r.x()) || qIsNan(r.y()) || qIsNan(r.width()) || qIsNan(r.height())) 00955 qWarning("QPainterPath::addRect: Adding rect where a parameter is NaN, results are undefined"); 00956 #endif 00957 if (r.isNull()) 00958 return; 00959 00960 ensureData(); 00961 detach(); 00962 00963 d_func()->elements.reserve(d_func()->elements.size() + 5); 00964 moveTo(r.x(), r.y()); 00965 00966 Element l1 = { r.x() + r.width(), r.y(), LineToElement }; 00967 Element l2 = { r.x() + r.width(), r.y() + r.height(), LineToElement }; 00968 Element l3 = { r.x(), r.y() + r.height(), LineToElement }; 00969 Element l4 = { r.x(), r.y(), LineToElement }; 00970 00971 d_func()->elements << l1 << l2 << l3 << l4; 00972 d_func()->require_moveTo = true; 00973 }
Here is the call graph for this function:

| void QPainterPath::addRect | ( | qreal | x, | |
| qreal | y, | |||
| qreal | width, | |||
| qreal | height | |||
| ) | [inline] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Adds a rectangle at position ({x}, {y}), with the given width and height, as a closed subpath.
Definition at line 248 of file qpainterpath.h.
References addRect().
Here is the call graph for this function:

| void QPainterPath::addEllipse | ( | const QRectF & | boundingRectangle | ) |
Creates an ellipse within the the specified boundingRectangle and adds it to the painter path as a closed subpath.
The ellipse is composed of a clockwise curve, starting and finishing at zero degrees (the 3 o'clock position).
100% qpainterpath-addellipse.png
QLinearGradient myGradient; QPen myPen; QRectF boundingRectangle; QPainterPath myPath; myPath.addEllipse(boundingRectangle); QPainter painter(this); painter.setBrush(myGradient); painter.setPen(myPen); painter.drawPath(myPath);
Definition at line 1052 of file qpainterpath.cpp.
References boundingRect(), cubicTo(), d, d_func(), detach(), ensureData(), QRectF::height(), QRectF::isNull(), moveTo(), qIsNan(), qt_curves_for_arc(), qWarning(), QPainterPathData::require_moveTo, start, QRectF::width(), QRectF::x(), and QRectF::y().
Referenced by addEllipse(), Window::setupShapes(), and SortingBox::SortingBox().
01053 { 01054 #ifndef QT_NO_DEBUG 01055 if (qIsNan(boundingRect.x()) || qIsNan(boundingRect.y()) 01056 || qIsNan(boundingRect.width()) || qIsNan(boundingRect.height())) 01057 qWarning("QPainterPath::addEllipse: Adding ellipse where a parameter is NaN, results are undefined"); 01058 #endif 01059 if (boundingRect.isNull()) 01060 return; 01061 01062 ensureData(); 01063 detach(); 01064 01065 Q_D(QPainterPath); 01066 d->elements.reserve(d->elements.size() + 13); 01067 01068 QPointF pts[12]; 01069 int point_count; 01070 QPointF start = qt_curves_for_arc(boundingRect, 0, 360, pts, &point_count); 01071 01072 moveTo(start); 01073 cubicTo(pts[0], pts[1], pts[2]); // 0 -> 270 01074 cubicTo(pts[3], pts[4], pts[5]); // 270 -> 180 01075 cubicTo(pts[6], pts[7], pts[8]); // 180 -> 90 01076 cubicTo(pts[9], pts[10], pts[11]); // 90 - >0 01077 d_func()->require_moveTo = true; 01078 }
Here is the call graph for this function:

| void QPainterPath::addEllipse | ( | qreal | x, | |
| qreal | y, | |||
| qreal | width, | |||
| qreal | height | |||
| ) | [inline] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Creates an ellipse within the bounding rectangle defined by its top-left corner at (x, y), width and height, and adds it to the painter path as a closed subpath.
Definition at line 243 of file qpainterpath.h.
References addEllipse().
Here is the call graph for this function:

| void QPainterPath::addPolygon | ( | const QPolygonF & | polygon | ) |
Adds the given polygon to the path as an (unclosed) subpath.
Note that the current position after the polygon has been added, is the last point in polygon. To draw a line back to the first point, use the closeSubpath() function.
100% qpainterpath-addpolygon.png
QLinearGradient myGradient; QPen myPen; QPolygonF myPolygon; QPainterPath myPath; myPath.addPolygon(myPolygon); QPainter painter(this); painter.setBrush(myGradient); painter.setPen(myPen); painter.drawPath(myPath);
Definition at line 1004 of file qpainterpath.cpp.
References QVector< T >::at(), d_func(), detach(), elements, ensureData(), QVector< T >::first(), i, QVector< T >::isEmpty(), LineToElement, moveTo(), QVector< T >::size(), QPointF::x(), and QPointF::y().
Referenced by QGraphicsScene::items(), and QGraphicsView::mouseMoveEvent().
01005 { 01006 if (polygon.isEmpty()) 01007 return; 01008 01009 ensureData(); 01010 detach(); 01011 01012 d_func()->elements.reserve(d_func()->elements.size() + polygon.size()); 01013 01014 moveTo(polygon.first()); 01015 for (int i=1; i<polygon.size(); ++i) { 01016 Element elm = { polygon.at(i).x(), polygon.at(i).y(), LineToElement }; 01017 d_func()->elements << elm; 01018 } 01019 }
Here is the call graph for this function:

Adds the given text to this path as a set of closed subpaths created from the font supplied. The subpaths are positioned so that the left end of the text's baseline lies at the specified point.
100% qpainterpath-addtext.png
QLinearGradient myGradient; QPen myPen; QFont myFont; QPointF baseline(x, y); QPainterPath myPath; myPath.addText(baseline, myFont, tr("Qt")); QPainter painter(this); painter.setBrush(myGradient); painter.setPen(myPen); painter.drawPath(myPath);
Definition at line 1111 of file qpainterpath.cpp.
References QFontEngine::addOutlineToPath(), addRect(), QScriptItem::analysis, QFontEngine::ascent(), QTextEngine::bidiReorder(), QFont::d, detach(), QFontPrivate::engineForScript(), ensureData(), QTextEngine::glyphs(), i, QString::isEmpty(), QScriptItem::isObject, QScriptItem::isTab, layout, QTextEngine::layoutData, QScriptLine::length, levels, QTextEngine::lines, QFontEngine::lineThickness(), QScriptItem::num_glyphs, QFontPrivate::overline, QTextItem::RightToLeft, QFontPrivate::strikeOut, QFixed::toReal(), QFontPrivate::underline, QFontEngine::underlinePosition(), QScriptItem::width, QPointF::x(), x, QPointF::y(), and y.
Referenced by addText(), and Window::setupShapes().
01112 { 01113 if (text.isEmpty()) 01114 return; 01115 01116 ensureData(); 01117 detach(); 01118 01119 QTextLayout layout(text, f); 01120 layout.setCacheEnabled(true); 01121 QTextEngine *eng = layout.engine(); 01122 layout.beginLayout(); 01123 QTextLine line = layout.createLine(); 01124 layout.endLayout(); 01125 const QScriptLine &sl = eng->lines[0]; 01126 if (!sl.length || !eng->layoutData) 01127 return; 01128 01129 int nItems = eng->layoutData->items.size(); 01130 01131 qreal x(point.x()); 01132 qreal y(point.y()); 01133 01134 QVarLengthArray<int> visualOrder(nItems); 01135 QVarLengthArray<uchar> levels(nItems); 01136 for (int i = 0; i < nItems; ++i) 01137 levels[i] = eng->layoutData->items[i].analysis.bidiLevel; 01138 QTextEngine::bidiReorder(nItems, levels.data(), visualOrder.data()); 01139 01140 for (int i = 0; i < nItems; ++i) { 01141 int item = visualOrder[i]; 01142 QScriptItem &si = eng->layoutData->items[item]; 01143 01144 if (!si.isTab && !si.isObject) { 01145 QGlyphLayout *glyphs = eng->glyphs(&si); 01146 QFontEngine *fe = f.d->engineForScript(si.analysis.script); 01147 Q_ASSERT(fe); 01148 fe->addOutlineToPath(x, y, glyphs, si.num_glyphs, this, 01149 si.analysis.bidiLevel % 2 01150 ? QTextItem::RenderFlags(QTextItem::RightToLeft) 01151 : QTextItem::RenderFlags(0)); 01152 01153 const qreal lw = fe->lineThickness().toReal(); 01154 if (f.d->underline) { 01155 qreal pos = fe->underlinePosition().toReal(); 01156 addRect(x, y + pos, si.width.toReal(), lw); 01157 } 01158 if (f.d->overline) { 01159 qreal pos = fe->ascent().toReal() + 1; 01160 addRect(x, y - pos, si.width.toReal(), lw); 01161 } 01162 if (f.d->strikeOut) { 01163 qreal pos = fe->ascent().toReal() / 3; 01164 addRect(x, y - pos, si.width.toReal(), lw); 01165 } 01166 } 01167 x += si.width.toReal(); 01168 } 01169 }
Here is the call graph for this function:

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Adds the given text to this path as a set of closed subpaths created from the font supplied. The subpaths are positioned so that the left end of the text's baseline lies at the point specified by (x, y).
Definition at line 253 of file qpainterpath.h.
References addText().
Here is the call graph for this function:

| void QPainterPath::addPath | ( | const QPainterPath & | path | ) |
Adds the given path to this path as a closed subpath.
Definition at line 1179 of file qpainterpath.cpp.
References QPainterPathData::cStart, d, d_func(), detach(), ensureData(), QPainterPathData::isClosed(), isEmpty(), and MoveToElement.
01180 { 01181 if (other.isEmpty()) 01182 return; 01183 01184 ensureData(); 01185 detach(); 01186 01187 QPainterPathData *d = reinterpret_cast<QPainterPathData *>(d_func()); 01188 // Remove last moveto so we don't get multiple moveto's 01189 if (d->elements.last().type == MoveToElement) 01190 d->elements.remove(d->elements.size()-1); 01191 01192 // Locate where our own current subpath will start after the other path is added. 01193 int cStart = d->elements.size() + other.d_func()->cStart; 01194 d->elements += other.d_func()->elements; 01195 d->cStart = cStart; 01196 01197 d->require_moveTo = other.d_func()->isClosed(); 01198 }
Here is the call graph for this function:

| void QPainterPath::addRegion | ( | const QRegion & | region | ) |
Adds the given region to the path by adding each rectangle in the region as a separate closed subpath.
Definition at line 1240 of file qpainterpath.cpp.
References addRect(), QVector< T >::at(), d_func(), detach(), ensureData(), i, QRegion::rects(), and QVector< T >::size().
Referenced by Q3SVGPaintEngine::updateClipRegion(), and QGraphicsPixmapItemPrivate::updateShape().
01241 { 01242 ensureData(); 01243 detach(); 01244 01245 QVector<QRect> rects = region.rects(); 01246 d_func()->elements.reserve(rects.size() * 5); 01247 for (int i=0; i<rects.size(); ++i) 01248 addRect(rects.at(i)); 01249 }
Here is the call graph for this function:

| void QPainterPath::connectPath | ( | const QPainterPath & | path | ) |
Connects the given path to this path by adding a line from the last element of this path to the first element of the given path.
Definition at line 1210 of file qpainterpath.cpp.
References QPainterPathData::cStart, d, d_func(), detach(), ensureData(), isEmpty(), LineToElement, and MoveToElement.
01211 { 01212 if (other.isEmpty()) 01213 return; 01214 01215 ensureData(); 01216 detach(); 01217 01218 QPainterPathData *d = reinterpret_cast<QPainterPathData *>(d_func()); 01219 // Remove last moveto so we don't get multiple moveto's 01220 if (d->elements.last().type == MoveToElement) 01221 d->elements.remove(d->elements.size()-1); 01222 01223 // Locate where our own current subpath will start after the other path is added. 01224 int cStart = d->elements.size() + other.d_func()->cStart; 01225 int first = d->elements.size(); 01226 d->elements += other.d_func()->elements; 01227 01228 d->elements[first].type = LineToElement; 01229 if (cStart != first) 01230 d->cStart = cStart; 01231 }
Here is the call graph for this function:

| bool QPainterPath::contains | ( | const QPointF & | point | ) | const |
Returns true if the given point is inside the path, otherwise returns false.
Definition at line 1799 of file qpainterpath.cpp.
References CurveToElement, d, d_func(), QBezier::fromPoints(), i, isEmpty(), LineToElement, MoveToElement, qt_painterpath_isect_curve(), qt_painterpath_isect_line(), and Qt::WindingFill.
Referenced by QGraphicsItem::collidesWithPath(), contains(), QGraphicsItem::contains(), intersects(), and VersionLabel::mouseReleaseEvent().
01800 { 01801 if (isEmpty()) 01802 return false; 01803 01804 QPainterPathData *d = d_func(); 01805 01806 int winding_number = 0; 01807 01808 QPointF last_pt; 01809 QPointF last_start; 01810 for (int i=0; i<d->elements.size(); ++i) { 01811 const Element &e = d->elements.at(i); 01812 01813 switch (e.type) { 01814 01815 case MoveToElement: 01816 if (i > 0) // implicitly close all paths. 01817 qt_painterpath_isect_line(last_pt, last_start, pt, &winding_number); 01818 last_start = last_pt = e; 01819 break; 01820 01821 case LineToElement: 01822 qt_painterpath_isect_line(last_pt, e, pt, &winding_number); 01823 last_pt = e; 01824 break; 01825 01826 case CurveToElement: 01827 { 01828 const QPainterPath::Element &cp2 = d->elements.at(++i); 01829 const QPainterPath::Element &ep = d->elements.at(++i); 01830 qt_painterpath_isect_curve(QBezier::fromPoints(last_pt, e, cp2, ep), 01831 pt, &winding_number); 01832 last_pt = ep; 01833 01834 } 01835 break; 01836 01837 default: 01838 break; 01839 } 01840 } 01841 01842 // implicitly close last subpath 01843 if (last_pt != last_start) 01844 qt_painterpath_isect_line(last_pt, last_start, pt, &winding_number); 01845 01846 return (d->fillRule == Qt::WindingFill 01847 ? (winding_number != 0) 01848 : ((winding_number % 2) != 0)); 01849 }
Here is the call graph for this function:

| bool QPainterPath::contains | ( | const QRectF & | rectangle | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns true if the given rectangle is inside the path, otherwise returns false.
Definition at line 2078 of file qpainterpath.cpp.
References QRectF::bottomLeft(), QRectF::bottomRight(), QRectF::center(), QRectF::contains(), contains(), controlPointRect(), CurveToElement, d, fillRule(), i, isEmpty(), LineToElement, MoveToElement, Qt::OddEvenFill, qt_painterpath_check_crossing(), QRectF::topLeft(), and QRectF::topRight().
02079 { 02080 Q_D(QPainterPath); 02081 02082 // the path is empty or the control point rect doesn't completely 02083 // cover the rectangle we abort stratight away. 02084 if (isEmpty() || !controlPointRect().contains(rect)) 02085 return false; 02086 02087 // if there are intersections, chances are that the rect is not 02088 // contained, except if we have winding rule, in which case it 02089 // still might. 02090 if (qt_painterpath_check_crossing(this, rect)) { 02091 if (fillRule() == Qt::OddEvenFill) { 02092 return false; 02093 } else { 02094 // Do some wague sampling in the winding case. This is not 02095 // precise but it should mostly be good enough. 02096 if (!contains(rect.topLeft()) || 02097 !contains(rect.topRight()) || 02098 !contains(rect.bottomRight()) || 02099 !contains(rect.bottomLeft())) 02100 return false; 02101 } 02102 } 02103 02104 // If there exists a point inside that is not part of the path its 02105 // because: rectangle lies completely outside path or a subpath 02106 // excludes parts of the rectangle. Both cases mean that the rect 02107 // is not contained 02108 if (!contains(rect.center())) 02109 return false; 02110 02111 // If there are any subpaths inside this rectangle we need to 02112 // check if they are still contained as a result of the fill 02113 // rule. This can only be the case for WindingFill though. For 02114 // OddEvenFill the rect will never be contained if it surrounds a 02115 // subpath. (the case where two subpaths are completely identical 02116 // can be argued but we choose to neglect it). 02117 for (int i=0; i<d->elements.size(); ++i) { 02118 const Element &e = d->elements.at(i); 02119 if (e.type == QPainterPath::MoveToElement && rect.contains(e)) { 02120 if (fillRule() == Qt::OddEvenFill) 02121 return false; 02122 02123 bool stop = false; 02124 for (; !stop && i<d->elements.size(); ++i) { 02125 const Element &el = d->elements.at(i); 02126 switch (el.type) { 02127 case MoveToElement: 02128 stop = true; 02129 break; 02130 case LineToElement: 02131 if (!contains(el)) 02132 return false; 02133 break; 02134 case CurveToElement: 02135 if (!contains(d->elements.at(i+2))) 02136 return false; 02137 i += 2; 02138 break; 02139 default: 02140 break; 02141 } 02142 } 02143 02144 // compensate for the last ++i in the inner for 02145 --i; 02146 } 02147 } 02148 02149 return true; 02150 }
Here is the call graph for this function:

| bool QPainterPath::intersects | ( | const QRectF & | rectangle | ) | const |
Returns true if any point in the given rectangle intersects the path; otherwise returns false.
There is an intersection if any of the lines making up the rectangle crosses a part of the path or if any part of the rectangle overlaps with any area enclosed by the path. This function respects the current fillRule to determine what is considered inside the path.
Definition at line 2045 of file qpainterpath.cpp.
References QRectF::center(), QRectF::contains(), contains(), controlPointRect(), d, i, isEmpty(), MoveToElement, and qt_painterpath_check_crossing().
02046 { 02047 if (isEmpty() || !controlPointRect().intersects(rect)) 02048 return false; 02049 02050 // If any path element cross the rect its bound to be an intersection 02051 if (qt_painterpath_check_crossing(this, rect)) 02052 return true; 02053 02054 if (contains(rect.center())) 02055 return true; 02056 02057 Q_D(QPainterPath); 02058 02059 // Check if the rectangle surounds any subpath... 02060 for (int i=0; i<d->elements.size(); ++i) { 02061 const Element &e = d->elements.at(i); 02062 if (e.type == QPainterPath::MoveToElement && rect.contains(e)) 02063 return true; 02064 } 02065 02066 return false; 02067 }
Here is the call graph for this function:

| QRectF QPainterPath::boundingRect | ( | ) | const |
Returns the bounding rectangle of this painter path as a rectangle with floating point precision.
Definition at line 1384 of file qpainterpath.cpp.
References b, CurveToElement, d, QBezier::fromPoints(), i, isEmpty(), LineToElement, MoveToElement, qt_painterpath_bezier_extrema(), QTextStream::right(), and right().
Referenced by addEllipse(), Launcher::addTitleBackground(), PaintArea::mousePressEvent(), PathDeformRenderer::paint(), QSvgPath::QSvgPath(), and PanelShape::rect().
01385 { 01386 Q_D(QPainterPath); 01387 if (isEmpty()) 01388 return QRect(); 01389 01390 qreal minx, maxx, miny, maxy; 01391 minx = maxx = d->elements.at(0).x; 01392 miny = maxy = d->elements.at(0).y; 01393 for (int i=1; i<d->elements.size(); ++i) { 01394 const Element &e = d->elements.at(i); 01395 01396 switch (e.type) { 01397 case MoveToElement: 01398 case LineToElement: 01399 if (e.x > maxx) maxx = e.x; 01400 else if (e.x < minx) minx = e.x; 01401 if (e.y > maxy) maxy = e.y; 01402 else if (e.y < miny) miny = e.y; 01403 break; 01404 case CurveToElement: 01405 { 01406 QBezier b = QBezier::fromPoints(d->elements.at(i-1), 01407 e, 01408 d->elements.at(i+1), 01409 d->elements.at(i+2)); 01410 QRectF r = qt_painterpath_bezier_extrema(b); 01411 qreal right = r.right(); 01412 qreal bottom = r.bottom(); 01413 if (r.x() < minx) minx = r.x(); 01414 if (right > maxx) maxx = right; 01415 if (r.y() < miny) miny = r.y(); 01416 if (bottom > maxy) maxy = bottom; 01417 i += 2; 01418 } 01419 break; 01420 default: 01421 break; 01422 } 01423 } 01424 return QRectF(minx, miny, maxx - minx, maxy - miny); 01425 }
Here is the call graph for this function:

| QRectF QPainterPath::controlPointRect | ( | ) | const |
Returns the rectangle containing all the points and control points in this path.
This function is significantly faster to compute than the exact boundingRect(), and the returned rectangle is always a superset of the rectangle returned by boundingRect().
Definition at line 1437 of file qpainterpath.cpp.
References d, i, and isEmpty().
Referenced by contains(), intersects(), and QGraphicsPathItem::setPath().
01438 { 01439 Q_D(QPainterPath); 01440 if (isEmpty()) 01441 return QRect(); 01442 01443 qreal minx, maxx, miny, maxy; 01444 minx = maxx = d->elements.at(0).x; 01445 miny = maxy = d->elements.at(0).y; 01446 for (int i=1; i<d->elements.size(); ++i) { 01447 const Element &e = d->elements.at(i); 01448 if (e.x > maxx) maxx = e.x; 01449 else if (e.x < minx) minx = e.x; 01450 if (e.y > maxy) maxy = e.y; 01451 else if (e.y < miny) miny = e.y; 01452 } 01453 return QRectF(minx, miny, maxx - minx, maxy - miny); 01454 }
Here is the call graph for this function:

| Qt::FillRule QPainterPath::fillRule | ( | ) | const |
Returns the painter path's currently set fill rule.
Definition at line 1257 of file qpainterpath.cpp.
References d_func(), QPainterPathData::fillRule, isEmpty(), and Qt::OddEvenFill.
Referenced by contains(), QRasterPaintEngine::updateState(), and QX11PaintEngine::updateState().
01258 { 01259 return isEmpty() ? Qt::OddEvenFill : d_func()->fillRule; 01260 }
Here is the call graph for this function:

| void QPainterPath::setFillRule | ( | Qt::FillRule | fillRule | ) |
Sets the fill rule of the painter path to the given fillRule. Qt provides two methods for filling paths:
qt-fillrule-oddeven.png qt-fillrule-winding.png Qt::OddEvenFill (default) Qt::WindingFill
Definition at line 1279 of file qpainterpath.cpp.
References d_func(), detach(), ensureData(), and QPainterPathData::fillRule.
Referenced by createPathNode(), QPainter::drawConvexPolygon(), QX11PaintEngine::drawPath(), QPainter::drawPolygon(), QPaintEngine::drawTextItem(), RenderArea::setFillRule(), and Window::setupShapes().
01280 { 01281 ensureData(); 01282 detach(); 01283 01284 d_func()->fillRule = fillRule; 01285 }
Here is the call graph for this function:

| bool QPainterPath::isEmpty | ( | ) | const [inline] |
Returns true if there are no elements in this path, otherwise returns false.
Definition at line 258 of file qpainterpath.h.
References d_ptr, QPainterPathPrivate::elements, QVector< T >::first(), MoveToElement, QVector< T >::size(), and QPainterPath::Element::type.
Referenced by addPath(), boundingRect(), closeSubpath(), QGraphicsItem::collidesWithPath(), connectPath(), contains(), controlPointRect(), QPainterPrivate::draw_helper(), QX11PaintEngine::drawPath(), fillRule(), intersects(), PaintArea::mousePressEvent(), QGraphicsPathItem::QGraphicsPathItem(), toReversed(), and toSubpathPolygons().
00259 { 00260 return !d_ptr || (d_ptr->elements.size() == 1 && d_ptr->elements.first().type == MoveToElement); 00261 }
Here is the call graph for this function:

| QPainterPath QPainterPath::toReversed | ( | ) | const |
Creates and returns a reversed copy of the path.
It is the order of the elements that is reversed: If a QPainterPath is composed by calling the moveTo(), lineTo() and cubicTo() functions in the specified order, the reversed copy is composed by calling cubicTo(), lineTo() and moveTo().
Definition at line 1474 of file qpainterpath.cpp.
References cubicTo(), CurveToDataElement, CurveToElement, d, i, isEmpty(), lineTo(), LineToElement, moveTo(), MoveToElement, QPainterPath::Element::type, QPainterPath::Element::x, x, QPainterPath::Element::y, and y.
01475 { 01476 Q_D(const QPainterPath); 01477 QPainterPath rev; 01478 01479 if (isEmpty()) { 01480 rev = *this; 01481 return rev; 01482 } 01483 01484 rev.moveTo(d->elements.at(d->elements.size()-1).x, d->elements.at(d->elements.size()-1).y); 01485 01486 for (int i=d->elements.size()-1; i>=1; --i) { 01487 const QPainterPath::Element &elm = d->elements.at(i); 01488 const QPainterPath::Element &prev = d->elements.at(i-1); 01489 switch (elm.type) { 01490 case LineToElement: 01491 rev.lineTo(prev.x, prev.y); 01492 break; 01493 case MoveToElement: 01494 rev.moveTo(prev.x, prev.y); 01495 break; 01496 case CurveToDataElement: 01497 { 01498 Q_ASSERT(i>=3); 01499 const QPainterPath::Element &cp1 = d->elements.at(i-2); 01500 const QPainterPath::Element &sp = d->elements.at(i-3); 01501 Q_ASSERT(prev.type == CurveToDataElement); 01502 Q_ASSERT(cp1.type == CurveToElement); 01503 rev.cubicTo(prev.x, prev.y, cp1.x, cp1.y, sp.x, sp.y); 01504 i -= 2; 01505 break; 01506 } 01507 default: 01508 Q_ASSERT(!"qt_reversed_path"); 01509 break; 01510 } 01511 } 01512 //qt_debug_path(rev); 01513 return rev; 01514 }
Here is the call graph for this function:

Converts the path into a list of polygons using the given transformation matrix, and returns the list.
This function creates one polygon for each subpath regardless of intersecting subpaths (i.e. overlapping bounding rectangles). To make sure that such overlapping subpaths are filled correctly, use the toFillPolygons() function instead.
Definition at line 1529 of file qpainterpath.cpp.
References QVector< T >::clear(), CurveToDataElement, CurveToElement, d, elementCount(), QBezier::fromPoints(), i, isEmpty(), LineToElement, MoveToElement, QVector< T >::reserve(), and QVector< T >::size().
Referenced by toFillPolygon(), and toFillPolygons().
01530 { 01531 Q_D(const QPainterPath); 01532 QList<QPolygonF> flatCurves; 01533 if (isEmpty()) 01534 return flatCurves; 01535 01536 QPolygonF current; 01537 for (int i=0; i<elementCount(); ++i) { 01538 const QPainterPath::Element &e = d->elements.at(i); 01539 switch (e.type) { 01540 case QPainterPath::MoveToElement: 01541 if (current.size() > 1) 01542 flatCurves += current; 01543 current.clear(); 01544 current.reserve(16); 01545 current += QPointF(e.x, e.y) * matrix; 01546 break; 01547 case QPainterPath::LineToElement: 01548 current += QPointF(e.x, e.y) * matrix; 01549 break; 01550 case QPainterPath::CurveToElement: { 01551 Q_ASSERT(d->elements.at(i+1).type == QPainterPath::CurveToDataElement); 01552 Q_ASSERT(d->elements.at(i+2).type == QPainterPath::CurveToDataElement); 01553 QBezier bezier = QBezier::fromPoints(QPointF(d->elements.at(i-1).x, d->elements.at(i-1).y) * matrix, 01554 QPointF(e.x, e.y) * matrix, 01555 QPointF(d->elements.at(i+1).x, d->elements.at(i+1).y) * matrix, 01556 QPointF(d->elements.at(i+2).x, d->elements.at(i+2).y) * matrix); 01557 bezier.addToPolygon(¤t); 01558 i+=2; 01559 break; 01560 } 01561 case QPainterPath::CurveToDataElement: 01562 Q_ASSERT(!"QPainterPath::toSubpathPolygons(), bad element type"); 01563 break; 01564 } 01565 } 01566 01567 if (current.size()>1) 01568 flatCurves += current; 01569 01570 return flatCurves; 01571 }
Here is the call graph for this function:

Converts the path into a list of polygons using the given transformation matrix, and returns the list.
The function differs from the toFillPolygon() function in that it creates several polygons. It is provided because it is usually faster to draw several small polygons than to draw one large polygon, even though the total number of points drawn is the same.
The toFillPolygons() function differs from the toSubpathPolygons() function in that it create only polygon for subpaths that have overlapping bounding rectangles.
Like the toFillPolygon() function, this function uses a rewinding technique to make sure that overlapping subpaths can be filled using the correct fill rule. Note that rewinding inserts addition lines in the polygons so the outline of the fill polygon does not match the outline of the path.
Definition at line 1636 of file qpainterpath.cpp.
References QVector< T >::at(), QList< T >::at(), QPolygonF::boundingRect(), QVector< T >::clear(), QVector< T >::first(), i, j, printf, qDebug(), rect_intersects(), QVector< T >::resize(), QVector< T >::size(), QList< T >::size(), and toSubpathPolygons().
01637 { 01638 QList<QPolygonF> polys; 01639 01640 QList<QPolygonF> subpaths = toSubpathPolygons(matrix); 01641 int count = subpaths.size(); 01642 01643 if (count == 0) 01644 return polys; 01645 01646 QList<QRectF> bounds; 01647 for (int i=0; i<count; ++i) 01648 bounds += subpaths.at(i).boundingRect(); 01649 01650 #ifdef QPP_FILLPOLYGONS_DEBUG 01651 printf("QPainterPath::toFillPolygons, subpathCount=%d\n", count); 01652 for (int i=0; i<bounds.size(); ++i) 01653 qDebug() << " bounds" << i << bounds.at(i); 01654 #endif 01655 01656 QVector< QList<int> > isects; 01657 isects.resize(count); 01658 01659 // find all intersections 01660 for (int j=0; j<count; ++j) { 01661 if (subpaths.at(j).size() <= 2) 01662 continue; 01663 QRectF cbounds = bounds.at(j); 01664 for (int i=0; i<count; ++i) { 01665 if (rect_intersects(cbounds, bounds.at(i))) { 01666 isects[j] << i; 01667 } 01668 } 01669 } 01670 01671 #ifdef QPP_FILLPOLYGONS_DEBUG 01672 printf("Intersections before flattening:\n"); 01673 for (int i = 0; i < count; ++i) { 01674 printf("%d: ", i); 01675 for (int j = 0; j < isects[i].size(); ++j) { 01676 printf("%d ", isects[i][j]); 01677 } 01678 printf("\n"); 01679 } 01680 #endif 01681 01682 // flatten the sets of intersections 01683 for (int i=0; i<count; ++i) { 01684 const QList<int> ¤t_isects = isects.at(i); 01685 for (int j=0; j<current_isects.size(); ++j) { 01686 int isect_j = current_isects.at(j); 01687 if (isect_j == i) 01688 continue; 01689 for (int k=0; k<isects[isect_j].size(); ++k) { 01690 int isect_k = isects[isect_j][k]; 01691 if (isect_k != i && !isects.at(i).contains(isect_k)) { 01692 isects[i] += isect_k; 01693 } 01694 } 01695 isects[isect_j].clear(); 01696 } 01697 } 01698 01699 #ifdef QPP_FILLPOLYGONS_DEBUG 01700 printf("Intersections after flattening:\n"); 01701 for (int i = 0; i < count; ++i) { 01702 printf("%d: ", i); 01703 for (int j = 0; j < isects[i].size(); ++j) { 01704 printf("%d ", isects[i][j]); 01705 } 01706 printf("\n"); 01707 } 01708 #endif 01709 01710 // Join the intersected subpaths as rewinded polygons 01711 for (int i=0; i<count; ++i) { 01712 const QList<int> &subpath_list = isects[i]; 01713 if (!subpath_list.isEmpty()) { 01714 QPolygonF buildUp; 01715 for (int j=0; j<subpath_list.size(); ++j) { 01716 buildUp += subpaths.at(subpath_list.at(j)); 01717 if (!buildUp.isClosed()) 01718 buildUp += buildUp.first(); 01719 } 01720 polys += buildUp; 01721 } 01722 } 01723 01724 return polys; 01725 }
Here is the call graph for this function:

Converts the path into a polygon using the given transformation matrix, and returns the polygon.
The polygon is created by first converting all subpaths to polygons, then using a rewinding technique to make sure that overlapping subpaths can be filled using the correct fill rule.
Note that rewinding inserts addition lines in the polygon so the outline of the fill polygon does not match the outline of the path.
Definition at line 1588 of file qpainterpath.cpp.
References QList< T >::at(), QList< T >::first(), QVector< T >::first(), i, QPolygonF::isClosed(), QList< T >::isEmpty(), QList< T >::size(), and toSubpathPolygons().
Referenced by QGraphicsItem::collidesWithPath(), PieView::itemRegion(), QRasterPaintEngine::updateState(), and QX11PaintEngine::updateState().
01589 { 01590 01591 QList<QPolygonF> flats = toSubpathPolygons(matrix); 01592 QPolygonF polygon; 01593 if (flats.isEmpty()) 01594 return polygon; 01595 QPointF first = flats.first().first(); 01596 for (int i=0; i<flats.size(); ++i) { 01597 polygon += flats.at(i); 01598 if (!flats.at(i).isClosed()) 01599 polygon += flats.at(i).first(); 01600 if (i > 0) 01601 polygon += first; 01602 } 01603 return polygon; 01604 }
Here is the call graph for this function:

| int QPainterPath::elementCount | ( | ) | const [inline] |
Returns the number of path elements in the painter path.
Definition at line 263 of file qpainterpath.h.
References d_ptr, QPainterPathPrivate::elements, and QVector< T >::size().
Referenced by elementAt(), quadTo(), setElementPositionAt(), and toSubpathPolygons().
Here is the call graph for this function:

| const QPainterPath::Element & QPainterPath::elementAt | ( | int | index | ) | const [inline] |
Returns the element at the given index in the painter path.
Definition at line 268 of file qpainterpath.h.
References QVector< T >::at(), d_ptr, elementCount(), and QPainterPathPrivate::elements.
Referenced by QGraphicsItem::collidesWithPath().
00269 { 00270 Q_ASSERT(d_ptr); 00271 Q_ASSERT(i >= 0 && i < elementCount()); 00272 return d_ptr->elements.at(i); 00273 }
Here is the call graph for this function:

| void QPainterPath::setElementPositionAt | ( | int | index, | |
| qreal | x, | |||
| qreal | y | |||
| ) | [inline] |
Definition at line 275 of file qpainterpath.h.
References d_ptr, detach(), elementCount(), QPainterPathPrivate::elements, QPainterPath::Element::x, and QPainterPath::Element::y.
00276 { 00277 Q_ASSERT(d_ptr); 00278 Q_ASSERT(i >= 0 && i < elementCount()); 00279 detach(); 00280 QPainterPath::Element &e = d_ptr->elements[i]; 00281 e.x = x; 00282 e.y = y; 00283 }
Here is the call graph for this function:

| bool QPainterPath::operator== | ( | const QPainterPath & | path | ) | const |
Returns true if this painterpath is equal to the given path.
Note that comparing paths may involve a per element comparison which can be slow for complex paths.
Definition at line 2162 of file qpainterpath.cpp.
References d, d_func(), i, and path.
02163 { 02164 QPainterPathData *d = reinterpret_cast<QPainterPathData *>(d_func()); 02165 if (path.d_func() == d) 02166 return true; 02167 else if (!d || !path.d_func()) 02168 return false; 02169 bool equal = d->fillRule == path.d_func()->fillRule && d->elements.size() == path.d_func()->elements.size(); 02170 for (int i = 0; i < d->elements.size() && equal; ++i) 02171 equal = d->elements.at(i) == path.d_func()->elements.at(i); 02172 return equal; 02173 }
Here is the call graph for this function:

| bool QPainterPath::operator!= | ( | const QPainterPath & | path | ) | const |
Returns true if this painter path differs from the given path.
Note that comparing paths may involve a per element comparison which can be slow for complex paths.
Definition at line 2184 of file qpainterpath.cpp.
References path.
02185 { 02186 return !(*this==path); 02187 }
| void QPainterPath::ensureData | ( | ) | [inline, private] |
Definition at line 138 of file qpainterpath.h.
References d_ptr.
Referenced by addEllipse(), addPath(), addPolygon(), addRect(), addRegion(), addText(), arcTo(), connectPath(), cubicTo(), lineTo(), moveTo(), quadTo(), and setFillRule().
00138 { if (!d_ptr) ensureData_helper(); }
| void QPainterPath::ensureData_helper | ( | ) | [private] |
Definition at line 507 of file qpainterpath.cpp.
References d_ptr, data, MoveToElement, and qAtomicSetPtr().
00508 { 00509 QPainterPathPrivate *data = new QPainterPathData; 00510 data->elements.reserve(16); 00511 QPainterPath::Element e = { 0, 0, QPainterPath::MoveToElement }; 00512 data->elements << e; 00513 data = qAtomicSetPtr(&d_ptr, data); 00514 if (data && !data->ref.deref()) 00515 delete (QPainterPathData *) data; 00516 Q_ASSERT(d_ptr != 0); 00517 }
Here is the call graph for this function:

| void QPainterPath::detach | ( | ) | [inline, private] |
Definition at line 286 of file qpainterpath.h.
References d_ptr, detach_helper(), and QPainterPathPrivate::ref.
Referenced by addEllipse(), addPath(), addPolygon(), addRect(), addRegion(), addText(), arcTo(), closeSubpath(), connectPath(), cubicTo(), lineTo(), moveTo(), quadTo(), setElementPositionAt(), and setFillRule().
00287 { 00288 if (d_ptr->ref != 1) 00289 detach_helper(); 00290 }
Here is the call graph for this function:

| void QPainterPath::detach_helper | ( | ) | [private] |
Definition at line 496 of file qpainterpath.cpp.
References d_func(), d_ptr, data, qAtomicSetPtr(), and QPainterPathData.
Referenced by detach().
00497 { 00498 QPainterPathPrivate *data = new QPainterPathData(*d_func()); 00499 data = qAtomicSetPtr(&d_ptr, data); 00500 if (data && !data->ref.deref()) 00501 delete (QPainterPathData *) data; 00502 }
Here is the call graph for this function:

| QPainterPathData* QPainterPath::d_func | ( | ) | const [inline, private] |
Definition at line 143 of file qpainterpath.h.
References d_ptr.
Referenced by addEllipse(), addPath(), addPolygon(), addRect(), addRegion(), closeSubpath(), connectPath(), contains(), cubicTo(), currentPosition(), detach_helper(), fillRule(), lineTo(), moveTo(), operator=(), operator==(), QPainterPath(), setFillRule(), and ~QPainterPath().
00143 { return reinterpret_cast<QPainterPathData *>(d_ptr); }
friend class QPainterPathData [friend] |
friend class QPainterPathStroker [friend] |
Definition at line 146 of file qpainterpath.h.
friend class QPainterPathStrokerPrivate [friend] |
Definition at line 147 of file qpainterpath.h.
friend class QMatrix [friend] |
Definition at line 148 of file qpainterpath.h.
| QDataStream & operator<< | ( | QDataStream & | stream, | |
| const QPainterPath & | path | |||
| ) | [friend] |
Writes the given painter path to the given stream, and returns a reference to the stream.
Definition at line 2199 of file qpainterpath.cpp.
02200 { 02201 if (p.isEmpty()) { 02202 s << 0; 02203 return s; 02204 } 02205 02206 s << p.elementCount(); 02207 for (int i=0; i < p.d_func()->elements.size(); ++i) { 02208 const QPainterPath::Element &e = p.d_func()->elements.at(i); 02209 s << int(e.type); 02210 s << double(e.x) << double(e.y); 02211 } 02212 s << p.d_func()->cStart; 02213 s << int(p.d_func()->fillRule); 02214 return s; 02215 }
| QDataStream & operator>> | ( | QDataStream & | stream, | |
| QPainterPath & | path | |||
| ) | [friend] |
Reads a painter path from the given stream into the specified path, and returns a reference to the stream.
Definition at line 2226 of file qpainterpath.cpp.
02227 { 02228 int size; 02229 s >> size; 02230 02231 if (size == 0) 02232 return s; 02233 02234 p.ensureData(); // in case if p.d_func() == 0 02235 if (p.d_func()->elements.size() == 1) { 02236 Q_ASSERT(p.d_func()->elements.at(0).type == QPainterPath::MoveToElement); 02237 p.d_func()->elements.clear(); 02238 } 02239 p.d_func()->elements.reserve(p.d_func()->elements.size() + size); 02240 for (int i=0; i<size; ++i) { 02241 int type; 02242 double x, y; 02243 s >> type; 02244 s >> x; 02245 s >> y; 02246 Q_ASSERT(type >= 0 && type <= 3); 02247 #ifndef QT_NO_DEBUG 02248 if (qIsNan(x) || qIsNan(y)) 02249 qWarning("QDataStream::operator>>: Adding a NaN element to path, results are undefined"); 02250 #endif 02251 QPainterPath::Element elm = { x, y, QPainterPath::ElementType(type) }; 02252 p.d_func()->elements.append(elm); 02253 } 02254 s >> p.d_func()->cStart; 02255 int fillRule; 02256 s >> fillRule; 02257 Q_ASSERT(fillRule == Qt::OddEvenFill || Qt::WindingFill); 02258 p.d_func()->fillRule = Qt::FillRule(fillRule); 02259 return s; 02260 }
QPainterPathPrivate* QPainterPath::d_ptr [private] |
Definition at line 136 of file qpainterpath.h.
Referenced by currentPosition(), detach(), detach_helper(), elementAt(), elementCount(), ensureData_helper(), isEmpty(), operator=(), and setElementPositionAt().
1.5.1