Qt 4.8
Classes | Public Types | Public Functions | Private Functions | Properties | Friends | List of all members
QPainterPath Class Reference

The QPainterPath class provides a container for painting operations, enabling graphical shapes to be constructed and reused. More...

#include <qpainterpath.h>

Classes

class  Element
 The QPainterPath::Element class specifies the position and type of a subpath. More...
 

Public Types

enum  ElementType { MoveToElement, LineToElement, CurveToElement, CurveToDataElement }
 This enum describes the types of elements used to connect vertices in subpaths. More...
 

Public Functions

void addEllipse (const QRectF &rect)
 Creates an ellipse within the specified boundingRectangle and adds it to the painter path as a closed subpath. More...
 
void addEllipse (qreal x, qreal y, qreal w, qreal h)
 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. More...
 
void addEllipse (const QPointF &center, qreal rx, qreal ry)
 Creates an ellipse positioned at {center} with radii {rx} and {ry}, and adds it to the painter path as a closed subpath. More...
 
void addPath (const QPainterPath &path)
 Adds the given path to this path as a closed subpath. More...
 
void addPolygon (const QPolygonF &polygon)
 Adds the given polygon to the path as an (unclosed) subpath. More...
 
void addRect (const QRectF &rect)
 Adds the given rectangle to this path as a closed subpath. More...
 
void addRect (qreal x, qreal y, qreal w, qreal h)
 Adds a rectangle at position ({x}, {y}), with the given width and height, as a closed subpath. More...
 
void addRegion (const QRegion &region)
 Adds the given region to the path by adding each rectangle in the region as a separate closed subpath. More...
 
void addRoundedRect (const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
 Adds the given rectangle rect with rounded corners to the path. More...
 
void addRoundedRect (qreal x, qreal y, qreal w, qreal h, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
 Adds the given rectangle x, y, w, h with rounded corners to the path. More...
 
void addRoundRect (const QRectF &rect, int xRnd, int yRnd)
 Adds a rectangle r with rounded corners to the path. More...
 
void addRoundRect (qreal x, qreal y, qreal w, qreal h, int xRnd, int yRnd)
 Adds a rectangle with rounded corners to the path. More...
 
void addRoundRect (const QRectF &rect, int roundness)
 Adds a rounded rectangle, rect, to the path. More...
 
void addRoundRect (qreal x, qreal y, qreal w, qreal h, int roundness)
 Adds a rounded rectangle to the path, defined by the coordinates x and y with the specified width and height. More...
 
void addText (const QPointF &point, const QFont &f, const QString &text)
 Adds the given text to this path as a set of closed subpaths created from the font supplied. More...
 
void addText (qreal x, qreal y, const QFont &f, const QString &text)
 Adds the given text to this path as a set of closed subpaths created from the font supplied. More...
 
qreal angleAtPercent (qreal t) const
 Returns the angle of the path tangent at the percentage t. More...
 
void arcMoveTo (const QRectF &rect, qreal angle)
 Creates a move to that lies on the arc that occupies the given rectangle at angle. More...
 
void arcMoveTo (qreal x, qreal y, qreal w, qreal h, qreal angle)
 Creates a move to that lies on the arc that occupies the QRectF(x, y, width, height) at angle. More...
 
void arcTo (const QRectF &rect, qreal startAngle, qreal arcLength)
 Creates an arc that occupies the given rectangle, beginning at the specified startAngle and extending sweepLength degrees counter-clockwise. More...
 
void arcTo (qreal x, qreal y, qreal w, qreal h, qreal startAngle, qreal arcLength)
 
QRectF boundingRect () const
 Returns the bounding rectangle of this painter path as a rectangle with floating point precision. More...
 
void closeSubpath ()
 Closes the current subpath by drawing a line to the beginning of the subpath, automatically starting a new path. More...
 
void 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. More...
 
bool contains (const QPointF &pt) const
 Returns true if the given point is inside the path, otherwise returns false. More...
 
bool contains (const QRectF &rect) const
 Returns true if the given rectangle is inside the path, otherwise returns false. More...
 
bool contains (const QPainterPath &p) const
 Returns true if the given path p is contained within the current path. More...
 
QRectF controlPointRect () const
 Returns the rectangle containing all the points and control points in this path. More...
 
void cubicTo (const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt)
 Adds a cubic Bezier curve between the current position and the given endPoint using the control points specified by c1, and c2. More...
 
void cubicTo (qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y, qreal endPtx, qreal endPty)
 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}). More...
 
QPointF currentPosition () const
 Returns the current position of the path. More...
 
const QPainterPath::ElementelementAt (int i) const
 Returns the element at the given index in the painter path. More...
 
int elementCount () const
 Returns the number of path elements in the painter path. More...
 
Qt::FillRule fillRule () const
 Returns the painter path's currently set fill rule. More...
 
QPainterPath intersected (const QPainterPath &r) const
 Returns a path which is the intersection of this path's fill area and p's fill area. More...
 
bool intersects (const QRectF &rect) const
 Returns true if any point in the given rectangle intersects the path; otherwise returns false. More...
 
bool intersects (const QPainterPath &p) const
 Returns true if the current path intersects at any point the given path p. More...
 
bool isEmpty () const
 Returns true if either there are no elements in this path, or if the only element is a MoveToElement; otherwise returns false. More...
 
qreal length () const
 Returns the length of the current path. More...
 
void lineTo (const QPointF &p)
 Adds a straight line from the current position to the given endPoint. More...
 
void lineTo (qreal x, qreal y)
 Draws a line from the current position to the point ({x}, {y}). More...
 
void moveTo (const QPointF &p)
 Moves the current point to the given point, implicitly starting a new subpath and closing the previous one. More...
 
void moveTo (qreal x, qreal y)
 Moves the current position to ({x}, {y}) and starts a new subpath, implicitly closing the previous path. More...
 
QPainterPath operator & (const QPainterPath &other) const
 
QPainterPathoperator &= (const QPainterPath &other)
 
bool operator!= (const QPainterPath &other) const
 Returns true if this painter path differs from the given path. More...
 
QPainterPath operator+ (const QPainterPath &other) const
 Returns the union of this path and the other path. More...
 
QPainterPathoperator+= (const QPainterPath &other)
 Unites this path with other, and returns a reference to this path. More...
 
QPainterPath operator- (const QPainterPath &other) const
 Subtracts the other path from a copy of this path, and returns the copy. More...
 
QPainterPathoperator-= (const QPainterPath &other)
 Subtracts other from this path, and returns a reference to this path. More...
 
QPainterPathoperator= (const QPainterPath &other)
 Assigns the given path to this painter path. More...
 
bool operator== (const QPainterPath &other) const
 Returns true if this painterpath is equal to the given path. More...
 
QPainterPath operator| (const QPainterPath &other) const
 Returns the union of this path and the other path. More...
 
QPainterPathoperator|= (const QPainterPath &other)
 Unites this path with other and returns a reference to this path. More...
 
qreal percentAtLength (qreal t) const
 Returns percentage of the whole path at the specified length len. More...
 
QPointF pointAtPercent (qreal t) const
 Returns the point at at the percentage t of the current path. More...
 
 QPainterPath ()
 Constructs an empty QPainterPath object. More...
 
 QPainterPath (const QPointF &startPoint)
 Creates a QPainterPath object with the given startPoint as its current position. More...
 
 QPainterPath (const QPainterPath &other)
 Creates a QPainterPath object that is a copy of the given path. More...
 
void quadTo (const QPointF &ctrlPt, const QPointF &endPt)
 Adds a quadratic Bezier curve between the current position and the given endPoint with the control point specified by c. More...
 
void quadTo (qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty)
 Adds a quadratic Bezier curve between the current point and the endpoint ({endPointX}, {endPointY}) with the control point specified by ({cx}, {cy}). More...
 
void setElementPositionAt (int i, qreal x, qreal y)
 Sets the x and y coordinate of the element at index index to x and y. More...
 
void setFillRule (Qt::FillRule fillRule)
 Sets the fill rule of the painter path to the given fillRule. More...
 
QPainterPath simplified () const
 Returns a simplified version of this path. More...
 
qreal slopeAtPercent (qreal t) const
 Returns the slope of the path at the percentage t. More...
 
QPainterPath subtracted (const QPainterPath &r) const
 Returns a path which is p's fill area subtracted from this path's fill area. More...
 
QPainterPath subtractedInverted (const QPainterPath &r) const
 Use subtracted() instead. More...
 
void swap (QPainterPath &other)
 Swaps painter path other with this painter path. More...
 
QPolygonF toFillPolygon (const QMatrix &matrix=QMatrix()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
QPolygonF toFillPolygon (const QTransform &matrix) const
 Converts the path into a polygon using the QTransform matrix, and returns the polygon. More...
 
QList< QPolygonFtoFillPolygons (const QMatrix &matrix=QMatrix()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
QList< QPolygonFtoFillPolygons (const QTransform &matrix) const
 Converts the path into a list of polygons using the QTransform matrix, and returns the list. More...
 
QPainterPath toReversed () const
 Creates and returns a reversed copy of the path. More...
 
QList< QPolygonFtoSubpathPolygons (const QMatrix &matrix=QMatrix()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
QList< QPolygonFtoSubpathPolygons (const QTransform &matrix) const
 Converts the path into a list of polygons using the QTransform matrix, and returns the list. More...
 
void translate (qreal dx, qreal dy)
 Translates all elements in the path by ({dx}, {dy}). More...
 
void translate (const QPointF &offset)
 Translates all elements in the path by the given offset. More...
 
QPainterPath translated (qreal dx, qreal dy) const
 Returns a copy of the path that is translated by ({dx}, {dy}). More...
 
QPainterPath translated (const QPointF &offset) const
 Returns a copy of the path that is translated by the given offset. More...
 
QPainterPath united (const QPainterPath &r) const
 Returns a path which is the union of this path's fill area and p's fill area. More...
 
 ~QPainterPath ()
 Destroys this QPainterPath object. More...
 

Private Functions

void computeBoundingRect () const
 
void computeControlPointRect () const
 
QPainterPathDatad_func () const
 
void detach ()
 
void detach_helper ()
 
void ensureData ()
 
void ensureData_helper ()
 
void setDirty (bool)
 

Properties

QScopedPointer< QPainterPathPrivate, QPainterPathPrivateDeleterd_ptr
 

Friends

Q_GUI_EXPORT QDataStreamoperator<< (QDataStream &, const QPainterPath &)
 Writes the given painter path to the given stream, and returns a reference to the stream. More...
 
Q_GUI_EXPORT QDataStreamoperator>> (QDataStream &, QPainterPath &)
 Reads a painter path from the given stream into the specified path, and returns a reference to the stream. More...
 
class QMatrix
 
class QPainterPathData
 
class QPainterPathStroker
 
class QPainterPathStrokerPrivate
 
class QTransform
 
Q_GUI_EXPORT const QVectorPathqtVectorPathForPath (const QPainterPath &)
 
class QVectorPath
 

Detailed Description

The QPainterPath class provides a container for painting operations, enabling graphical shapes to be constructed and reused.

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.

Composing a QPainterPath

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 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:

qpainterpath-construction.png
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,
painter.setBrush(QColor(122, 163, 39));
painter.drawPath(path);

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:

Qt::OddEvenFill Qt::WindingFill
qt-fillrule-oddeven.png
qt-fillrule-winding.png

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.

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 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.

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 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.

Examples

Qt provides the painting/painterpaths{Painter Paths Example} and the demos/deform{Vector Deformation Demo} which are located in Qt's example and demo directories respectively.

The 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 demos/deform{Vector Deformation Demo} shows how to use QPainterPath to draw text.

painting/painterpaths{Painter Paths Example} demos/deform{Vector Deformation Demo}
qpainterpath-example.png
qpainterpath-demo.png
See also
QPainterPathStroker, QPainter, QRegion, {Painter Paths Example}

Definition at line 67 of file qpainterpath.h.

Enumerations

◆ ElementType

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.
See also
elementAt(), elementCount()
Enumerator
MoveToElement 
LineToElement 
CurveToElement 
CurveToDataElement 

Definition at line 70 of file qpainterpath.h.

Constructors and Destructors

◆ QPainterPath() [1/3]

QPainterPath::QPainterPath ( )

Constructs an empty QPainterPath object.

Definition at line 560 of file qpainterpath.cpp.

561  : d_ptr(0)
562 {
563 }
QScopedPointer< QPainterPathPrivate, QPainterPathPrivateDeleter > d_ptr
Definition: qpainterpath.h:211

◆ QPainterPath() [2/3]

QPainterPath::QPainterPath ( const QPointF startPoint)
explicit

Creates a QPainterPath object with the given startPoint as its current position.

Definition at line 587 of file qpainterpath.cpp.

588  : d_ptr(new QPainterPathData)
589 {
590  Element e = { startPoint.x(), startPoint.y(), MoveToElement };
591  d_func()->elements << e;
592 }
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
QScopedPointer< QPainterPathPrivate, QPainterPathPrivateDeleter > d_ptr
Definition: qpainterpath.h:211

◆ QPainterPath() [3/3]

QPainterPath::QPainterPath ( const QPainterPath path)

Creates a QPainterPath object that is a copy of the given path.

See also
operator=()

Definition at line 575 of file qpainterpath.cpp.

576  : d_ptr(other.d_ptr.data())
577 {
578  if (d_ptr)
579  d_ptr->ref.ref();
580 }
bool ref()
Atomically increments the value of this QAtomicInt.
QScopedPointer< QPainterPathPrivate, QPainterPathPrivateDeleter > d_ptr
Definition: qpainterpath.h:211

◆ ~QPainterPath()

QPainterPath::~QPainterPath ( )

Destroys this QPainterPath object.

Definition at line 651 of file qpainterpath.cpp.

652 {
653 }

Functions

◆ addEllipse() [1/3]

void QPainterPath::addEllipse ( const QRectF boundingRectangle)

Creates an ellipse within 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).

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);
See also
arcTo(), QPainter::drawEllipse(), {QPainterPath::Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 1169 of file qpainterpath.cpp.

Referenced by QSvgEllipse::bounds(), QX11PaintEngine::drawEllipse(), QOpenGLPaintEngine::drawEllipse(), QPaintEngine::drawEllipse(), QPainter::drawEllipse(), ellipseRectToPath(), QRegion::QRegion(), qt_bitmapToRegion(), and QGraphicsEllipseItem::shape().

1170 {
1173 #ifndef QT_NO_DEBUG
1174  qWarning("QPainterPath::addEllipse: Adding ellipse where a parameter is NaN or Inf, ignoring call");
1175 #endif
1176  return;
1177  }
1178 
1179  if (boundingRect.isNull())
1180  return;
1181 
1182  ensureData();
1183  detach();
1184 
1185  Q_D(QPainterPath);
1186  bool first = d_func()->elements.size() < 2;
1187  d->elements.reserve(d->elements.size() + 13);
1188 
1189  QPointF pts[12];
1190  int point_count;
1191  QPointF start = qt_curves_for_arc(boundingRect, 0, -360, pts, &point_count);
1192 
1193  moveTo(start);
1194  cubicTo(pts[0], pts[1], pts[2]); // 0 -> 270
1195  cubicTo(pts[3], pts[4], pts[5]); // 270 -> 180
1196  cubicTo(pts[6], pts[7], pts[8]); // 180 -> 90
1197  cubicTo(pts[9], pts[10], pts[11]); // 90 - >0
1198  d_func()->require_moveTo = true;
1199 
1200  d_func()->convex = first;
1201 }
double d
Definition: qnumeric_p.h:62
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define Q_D(Class)
Definition: qglobal.h:2482
void moveTo(const QPointF &p)
Moves the current point to the given point, implicitly starting a new subpath and closing the previou...
QRectF boundingRect() const
Returns the bounding rectangle of this painter path as a rectangle with floating point precision...
void ensureData()
Definition: qpainterpath.h:213
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
Q_CORE_EXPORT void qWarning(const char *,...)
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
void cubicTo(const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt)
Adds a cubic Bezier curve between the current position and the given endPoint using the control point...
QPointF qt_curves_for_arc(const QRectF &rect, qreal startAngle, qreal sweepLength, QPointF *curves, int *point_count)
Creates a number of curves for a given arc definition.
Definition: qstroker.cpp:859
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:655
static bool qt_is_finite(double d)
Definition: qnumeric_p.h:197

◆ addEllipse() [2/3]

void QPainterPath::addEllipse ( qreal  x,
qreal  y,
qreal  width,
qreal  height 
)
inline

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.

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 335 of file qpainterpath.h.

336 {
337  addEllipse(QRectF(x, y, w, h));
338 }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void addEllipse(const QRectF &rect)
Creates an ellipse within the specified boundingRectangle and adds it to the painter path as a closed...

◆ addEllipse() [3/3]

void QPainterPath::addEllipse ( const QPointF center,
qreal  rx,
qreal  ry 
)
inline

Creates an ellipse positioned at {center} with radii {rx} and {ry}, and adds it to the painter path as a closed subpath.

Since
4.4

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 340 of file qpainterpath.h.

341 {
342  addEllipse(QRectF(center.x() - rx, center.y() - ry, 2 * rx, 2 * ry));
343 }
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
void addEllipse(const QRectF &rect)
Creates an ellipse within the specified boundingRectangle and adds it to the painter path as a closed...

◆ addPath()

void QPainterPath::addPath ( const QPainterPath path)

Adds the given path to this path as a closed subpath.

See also
connectPath(), {QPainterPath::Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 1295 of file qpainterpath.cpp.

Referenced by QPathClipper::clip(), and qt_graphicsItem_shapeFromPath().

1296 {
1297  if (other.isEmpty())
1298  return;
1299 
1300  ensureData();
1301  detach();
1302 
1303  QPainterPathData *d = reinterpret_cast<QPainterPathData *>(d_func());
1304  // Remove last moveto so we don't get multiple moveto's
1305  if (d->elements.last().type == MoveToElement)
1306  d->elements.remove(d->elements.size()-1);
1307 
1308  // Locate where our own current subpath will start after the other path is added.
1309  int cStart = d->elements.size() + other.d_func()->cStart;
1310  d->elements += other.d_func()->elements;
1311  d->cStart = cStart;
1312 
1313  d->require_moveTo = other.d_func()->isClosed();
1314 }
double d
Definition: qnumeric_p.h:62
void ensureData()
Definition: qpainterpath.h:213
QPainterPathData * d_func() const
Definition: qpainterpath.h:221

◆ addPolygon()

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.

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);
See also
lineTo(), {QPainterPath::Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 1131 of file qpainterpath.cpp.

Referenced by QSvgPolygon::bounds(), QSvgPolyline::bounds(), QCommonStyle::drawControl(), QAlphaPaintEngine::drawPolygon(), QPolygon::intersected(), QPolygonF::intersected(), QGraphicsSceneIndex::items(), mapProjective(), QGraphicsView::mouseMoveEvent(), QGraphicsView::render(), QGraphicsPolygonItem::shape(), QPolygon::subtracted(), QPolygonF::subtracted(), QPolygon::united(), and QPolygonF::united().

1132 {
1133  if (polygon.isEmpty())
1134  return;
1135 
1136  ensureData();
1137  detach();
1138 
1139  d_func()->elements.reserve(d_func()->elements.size() + polygon.size());
1140 
1141  moveTo(polygon.first());
1142  for (int i=1; i<polygon.size(); ++i) {
1143  Element elm = { polygon.at(i).x(), polygon.at(i).y(), LineToElement };
1144  d_func()->elements << elm;
1145  }
1146 }
T & first()
Returns a reference to the first item in the vector.
Definition: qvector.h:260
void moveTo(const QPointF &p)
Moves the current point to the given point, implicitly starting a new subpath and closing the previou...
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
void ensureData()
Definition: qpainterpath.h:213
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
static const QTextHtmlElement elements[Html_NumElements]
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ addRect() [1/2]

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.

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);
See also
addRegion(), lineTo(), {QPainterPath::Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 1085 of file qpainterpath.cpp.

Referenced by QGraphicsTextItemPrivate::_q_mouseOnEdge(), QFontEngineBox::addOutlineToPath(), addRegion(), addSelectedRegionsToPath(), addText(), QSvgRect::bounds(), QPathClipper::clip(), QGL2PaintEngineEx::clip(), QOutlineMapper::clipElements(), QPainter::clipPath(), QGraphicsItem::clipPath(), QGraphicsItem::collidesWithPath(), QTextLayout::draw(), QTextLine::draw(), QCDEStyle::drawControl(), QRasterPaintEngine::drawImage(), QOpenGLPaintEnginePrivate::drawImageAsPath(), QMacStyle::drawPrimitive(), QX11PaintEngine::drawRects(), QOpenGLPaintEngine::drawRects(), QPaintEngine::drawRects(), QPdfBaseEngine::drawRects(), QPainter::drawRects(), QOpenGLPaintEnginePrivate::drawTiledImageAsPath(), QRasterPaintEngine::drawTiledPixmap(), QX11PaintEnginePrivate::fillPath(), QRasterPaintEngine::fillRect(), QGraphicsSceneIndexRectIntersector::intersect(), QGraphicsSceneIndexPointIntersector::intersect(), QGraphicsSceneIndexPrivate::itemCollidesWithPath(), QTransform::mapRect(), QGraphicsWidget::paintWindowFrame(), path_for_glyphs(), qt_regionToPath(), QmlJSDebugger::regionToPolygon(), QPainter::setClipRect(), QGraphicsWidget::shape(), QGraphicsItem::shape(), QGraphicsRectItem::shape(), QGraphicsTextItem::shape(), QGraphicsSimpleTextItem::shape(), QFontSubset::toTruetype(), QPdfBaseEngine::updateClipPath(), QOpenGLPaintEngine::updateClipRegion(), QGraphicsPixmapItemPrivate::updateShape(), and QPdfBaseEngine::updateState().

1086 {
1087  if (!qt_is_finite(r.x()) || !qt_is_finite(r.y()) || !qt_is_finite(r.width()) || !qt_is_finite(r.height())) {
1088 #ifndef QT_NO_DEBUG
1089  qWarning("QPainterPath::addRect: Adding rect where a parameter is NaN or Inf, ignoring call");
1090 #endif
1091  return;
1092  }
1093 
1094  if (r.isNull())
1095  return;
1096 
1097  ensureData();
1098  detach();
1099 
1100  bool first = d_func()->elements.size() < 2;
1101 
1102  d_func()->elements.reserve(d_func()->elements.size() + 5);
1103  moveTo(r.x(), r.y());
1104 
1105  Element l1 = { r.x() + r.width(), r.y(), LineToElement };
1106  Element l2 = { r.x() + r.width(), r.y() + r.height(), LineToElement };
1107  Element l3 = { r.x(), r.y() + r.height(), LineToElement };
1108  Element l4 = { r.x(), r.y(), LineToElement };
1109 
1110  d_func()->elements << l1 << l2 << l3 << l4;
1111  d_func()->require_moveTo = true;
1112  d_func()->convex = first;
1113 }
void moveTo(const QPointF &p)
Moves the current point to the given point, implicitly starting a new subpath and closing the previou...
void ensureData()
Definition: qpainterpath.h:213
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
Q_CORE_EXPORT void qWarning(const char *,...)
static const QTextHtmlElement elements[Html_NumElements]
static bool qt_is_finite(double d)
Definition: qnumeric_p.h:197

◆ addRect() [2/2]

void QPainterPath::addRect ( qreal  x,
qreal  y,
qreal  width,
qreal  height 
)
inline

Adds a rectangle at position ({x}, {y}), with the given width and height, as a closed subpath.

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 345 of file qpainterpath.h.

346 {
347  addRect(QRectF(x, y, w, h));
348 }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.

◆ addRegion()

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.

See also
addRect(), {QPainterPath::Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 1367 of file qpainterpath.cpp.

Referenced by QGL2PaintEngineEx::clip(), and QGL2PaintEngineExPrivate::systemStateChanged().

1368 {
1369  ensureData();
1370  detach();
1371 
1372  QVector<QRect> rects = region.rects();
1373  d_func()->elements.reserve(rects.size() * 5);
1374  for (int i=0; i<rects.size(); ++i)
1375  addRect(rects.at(i));
1376 }
void ensureData()
Definition: qpainterpath.h:213
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ addRoundedRect() [1/2]

void QPainterPath::addRoundedRect ( const QRectF rect,
qreal  xRadius,
qreal  yRadius,
Qt::SizeMode  mode = Qt::AbsoluteSize 
)

Adds the given rectangle rect with rounded corners to the path.

Since
4.4

The xRadius and yRadius arguments specify the radii of the ellipses defining the corners of the rounded rectangle. When mode is Qt::RelativeSize, xRadius and yRadius are specified in percentage of half the rectangle's width and height respectively, and should be in the range 0.0 to 100.0.

See also
addRect()

Definition at line 3209 of file qpainterpath.cpp.

Referenced by QPainter::drawRoundedRect().

3211 {
3212  QRectF r = rect.normalized();
3213 
3214  if (r.isNull())
3215  return;
3216 
3217  if (mode == Qt::AbsoluteSize) {
3218  qreal w = r.width() / 2;
3219  qreal h = r.height() / 2;
3220 
3221  if (w == 0) {
3222  xRadius = 0;
3223  } else {
3224  xRadius = 100 * qMin(xRadius, w) / w;
3225  }
3226  if (h == 0) {
3227  yRadius = 0;
3228  } else {
3229  yRadius = 100 * qMin(yRadius, h) / h;
3230  }
3231  } else {
3232  if (xRadius > 100) // fix ranges
3233  xRadius = 100;
3234 
3235  if (yRadius > 100)
3236  yRadius = 100;
3237  }
3238 
3239  if (xRadius <= 0 || yRadius <= 0) { // add normal rectangle
3240  addRect(r);
3241  return;
3242  }
3243 
3244  qreal x = r.x();
3245  qreal y = r.y();
3246  qreal w = r.width();
3247  qreal h = r.height();
3248  qreal rxx2 = w*xRadius/100;
3249  qreal ryy2 = h*yRadius/100;
3250 
3251  ensureData();
3252  detach();
3253 
3254  bool first = d_func()->elements.size() < 2;
3255 
3256  arcMoveTo(x, y, rxx2, ryy2, 180);
3257  arcTo(x, y, rxx2, ryy2, 180, -90);
3258  arcTo(x+w-rxx2, y, rxx2, ryy2, 90, -90);
3259  arcTo(x+w-rxx2, y+h-ryy2, rxx2, ryy2, 0, -90);
3260  arcTo(x, y+h-ryy2, rxx2, ryy2, 270, -90);
3261  closeSubpath();
3262 
3263  d_func()->require_moveTo = true;
3264  d_func()->convex = first;
3265 }
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
void closeSubpath()
Closes the current subpath by drawing a line to the beginning of the subpath, automatically starting ...
void arcMoveTo(const QRectF &rect, qreal angle)
Creates a move to that lies on the arc that occupies the given rectangle at angle.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void ensureData()
Definition: qpainterpath.h:213
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
void arcTo(const QRectF &rect, qreal startAngle, qreal arcLength)
Creates an arc that occupies the given rectangle, beginning at the specified startAngle and extending...
QRectF normalized() const
Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height...
Definition: qrect.cpp:1822
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:655

◆ addRoundedRect() [2/2]

void QPainterPath::addRoundedRect ( qreal  x,
qreal  y,
qreal  w,
qreal  h,
qreal  xRadius,
qreal  yRadius,
Qt::SizeMode  mode = Qt::AbsoluteSize 
)
inline

Adds the given rectangle x, y, w, h with rounded corners to the path.

Since
4.4 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 350 of file qpainterpath.h.

353 {
354  addRoundedRect(QRectF(x, y, w, h), xRadius, yRadius, mode);
355 }
void addRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
Adds the given rectangle rect with rounded corners to the path.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ addRoundRect() [1/4]

void QPainterPath::addRoundRect ( const QRectF r,
int  xRnd,
int  yRnd 
)

Adds a rectangle r with rounded corners to the path.

The xRnd and yRnd arguments specify how rounded the corners should be. 0 is angled corners, 99 is maximum roundedness.

See also
addRoundedRect()

Definition at line 3291 of file qpainterpath.cpp.

3292 {
3293  if(xRnd >= 100) // fix ranges
3294  xRnd = 99;
3295  if(yRnd >= 100)
3296  yRnd = 99;
3297  if(xRnd <= 0 || yRnd <= 0) { // add normal rectangle
3298  addRect(r);
3299  return;
3300  }
3301 
3302  QRectF rect = r.normalized();
3303 
3304  if (rect.isNull())
3305  return;
3306 
3307  qreal x = rect.x();
3308  qreal y = rect.y();
3309  qreal w = rect.width();
3310  qreal h = rect.height();
3311  qreal rxx2 = w*xRnd/100;
3312  qreal ryy2 = h*yRnd/100;
3313 
3314  ensureData();
3315  detach();
3316 
3317  bool first = d_func()->elements.size() < 2;
3318 
3319  arcMoveTo(x, y, rxx2, ryy2, 180);
3320  arcTo(x, y, rxx2, ryy2, 180, -90);
3321  arcTo(x+w-rxx2, y, rxx2, ryy2, 90, -90);
3322  arcTo(x+w-rxx2, y+h-ryy2, rxx2, ryy2, 0, -90);
3323  arcTo(x, y+h-ryy2, rxx2, ryy2, 270, -90);
3324  closeSubpath();
3325 
3326  d_func()->require_moveTo = true;
3327  d_func()->convex = first;
3328 }
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
double qreal
Definition: qglobal.h:1193
void closeSubpath()
Closes the current subpath by drawing a line to the beginning of the subpath, automatically starting ...
void arcMoveTo(const QRectF &rect, qreal angle)
Creates a move to that lies on the arc that occupies the given rectangle at angle.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void ensureData()
Definition: qpainterpath.h:213
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
void arcTo(const QRectF &rect, qreal startAngle, qreal arcLength)
Creates an arc that occupies the given rectangle, beginning at the specified startAngle and extending...
QRectF normalized() const
Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height...
Definition: qrect.cpp:1822
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:655

◆ addRoundRect() [2/4]

void QPainterPath::addRoundRect ( qreal  x,
qreal  y,
qreal  w,
qreal  h,
int  xRnd,
int  yRnd 
)
inline

Adds a rectangle with rounded corners to the path.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The rectangle is constructed from x, y, and the width and height w and h.

The xRnd and yRnd arguments specify how rounded the corners should be. 0 is angled corners, 99 is maximum roundedness.

See also
addRoundedRect()

Definition at line 357 of file qpainterpath.h.

359 {
360  addRoundRect(QRectF(x, y, w, h), xRnd, yRnd);
361 }
void addRoundRect(const QRectF &rect, int xRnd, int yRnd)
Adds a rectangle r with rounded corners to the path.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ addRoundRect() [3/4]

void QPainterPath::addRoundRect ( const QRectF rect,
int  roundness 
)
inline

Adds a rounded rectangle, rect, to the path.

Since
4.3 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The roundness argument specifies uniform roundness for the rectangle. Vertical and horizontal roundness factors will be adjusted accordingly to act uniformly around both axes. Use this method if you want a rectangle equally rounded across both the X and Y axis.

See also
addRoundedRect()

Definition at line 363 of file qpainterpath.h.

365 {
366  int xRnd = roundness;
367  int yRnd = roundness;
368  if (rect.width() > rect.height())
369  xRnd = int(roundness * rect.height()/rect.width());
370  else
371  yRnd = int(roundness * rect.width()/rect.height());
372  addRoundRect(rect, xRnd, yRnd);
373 }
void addRoundRect(const QRectF &rect, int xRnd, int yRnd)
Adds a rectangle r with rounded corners to the path.
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707

◆ addRoundRect() [4/4]

void QPainterPath::addRoundRect ( qreal  x,
qreal  y,
qreal  width,
qreal  height,
int  roundness 
)
inline

Adds a rounded rectangle to the path, defined by the coordinates x and y with the specified width and height.

Since
4.3 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The roundness argument specifies uniform roundness for the rectangle. Vertical and horizontal roundness factors will be adjusted accordingly to act uniformly around both axes. Use this method if you want a rectangle equally rounded across both the X and Y axis.

See also
addRoundedRect()

Definition at line 375 of file qpainterpath.h.

377 {
378  addRoundRect(QRectF(x, y, w, h), roundness);
379 }
void addRoundRect(const QRectF &rect, int xRnd, int yRnd)
Adds a rectangle r with rounded corners to the path.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ addText() [1/2]

void QPainterPath::addText ( const QPointF point,
const QFont font,
const QString text 
)

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.

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);
See also
QPainter::drawText(), {QPainterPath::Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 1223 of file qpainterpath.cpp.

1224 {
1225  if (text.isEmpty())
1226  return;
1227 
1228  ensureData();
1229  detach();
1230 
1231  QTextLayout layout(text, f);
1232  layout.setCacheEnabled(true);
1233  QTextEngine *eng = layout.engine();
1234  layout.beginLayout();
1235  QTextLine line = layout.createLine();
1236  Q_UNUSED(line);
1237  layout.endLayout();
1238  const QScriptLine &sl = eng->lines[0];
1239  if (!sl.length || !eng->layoutData)
1240  return;
1241 
1242  int nItems = eng->layoutData->items.size();
1243 
1244  qreal x(point.x());
1245  qreal y(point.y());
1246 
1247  QVarLengthArray<int> visualOrder(nItems);
1248  QVarLengthArray<uchar> levels(nItems);
1249  for (int i = 0; i < nItems; ++i)
1250  levels[i] = eng->layoutData->items[i].analysis.bidiLevel;
1251  QTextEngine::bidiReorder(nItems, levels.data(), visualOrder.data());
1252 
1253  for (int i = 0; i < nItems; ++i) {
1254  int item = visualOrder[i];
1255  QScriptItem &si = eng->layoutData->items[item];
1256 
1258  QGlyphLayout glyphs = eng->shapedGlyphs(&si);
1259  QFontEngine *fe = f.d->engineForScript(si.analysis.script);
1260  Q_ASSERT(fe);
1261  fe->addOutlineToPath(x, y, glyphs, this,
1262  si.analysis.bidiLevel % 2
1263  ? QTextItem::RenderFlags(QTextItem::RightToLeft)
1264  : QTextItem::RenderFlags(0));
1265 
1266  const qreal lw = fe->lineThickness().toReal();
1267  if (f.d->underline) {
1268  qreal pos = fe->underlinePosition().toReal();
1269  addRect(x, y + pos, si.width.toReal(), lw);
1270  }
1271  if (f.d->overline) {
1272  qreal pos = fe->ascent().toReal() + 1;
1273  addRect(x, y - pos, si.width.toReal(), lw);
1274  }
1275  if (f.d->strikeOut) {
1276  qreal pos = fe->ascent().toReal() / 3;
1277  addRect(x, y - pos, si.width.toReal(), lw);
1278  }
1279  }
1280  x += si.width.toReal();
1281  }
1282 }
virtual QFixed lineThickness() const
double qreal
Definition: qglobal.h:1193
virtual void addOutlineToPath(qreal, qreal, const QGlyphLayout &, QPainterPath *, QTextItem::RenderFlags flags)
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
QScriptItemArray items
LayoutData * layoutData
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
void ensureData()
Definition: qpainterpath.h:213
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QGlyphLayout shapedGlyphs(const QScriptItem *si) const
virtual QFixed ascent() const =0
const char * layout
unsigned short bidiLevel
static void bidiReorder(int numRuns, const quint8 *levels, int *visualOrder)
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
QScriptLineArray lines
unsigned short flags
The QTextLayout class is used to lay out and render text.
Definition: qtextlayout.h:105
unsigned short script
qreal toReal() const
Definition: qfixed_p.h:77
signed int length
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
virtual QFixed underlinePosition() const
QScriptAnalysis analysis

◆ addText() [2/2]

void QPainterPath::addText ( qreal  x,
qreal  y,
const QFont font,
const QString text 
)
inline

Adds the given text to this path as a set of closed subpaths created from the font supplied.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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 381 of file qpainterpath.h.

382 {
383  addText(QPointF(x, y), f, text);
384 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void addText(const QPointF &point, const QFont &f, const QString &text)
Adds the given text to this path as a set of closed subpaths created from the font supplied...

◆ angleAtPercent()

qreal QPainterPath::angleAtPercent ( qreal  t) const

Returns the angle of the path tangent at the percentage t.

The argument t has to be between 0 and 1.

Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position.

Note that similarly to the other percent methods, the percentage measurement is not linear with regards to the length if curves are present in the path. When curves are present the percentage argument is mapped to the t parameter of the Bezier equations.

Definition at line 3124 of file qpainterpath.cpp.

3125 {
3126  if (t < 0 || t > 1) {
3127  qWarning("QPainterPath::angleAtPercent accepts only values between 0 and 1");
3128  return 0;
3129  }
3130 
3131  qreal totalLength = length();
3132  qreal curLen = 0;
3133  qreal bezierLen = 0;
3134  QBezier bez = bezierAtT(*this, t, &curLen, &bezierLen);
3135  qreal realT = (totalLength * t - curLen) / bezierLen;
3136 
3137  qreal m1 = slopeAt(realT, bez.x1, bez.x2, bez.x3, bez.x4);
3138  qreal m2 = slopeAt(realT, bez.y1, bez.y2, bez.y3, bez.y4);
3139 
3140  return QLineF(0, 0, m1, m2).angle();
3141 }
double qreal
Definition: qglobal.h:1193
static QBezier bezierAtT(const QPainterPath &path, qreal t, qreal *startingLength, qreal *bezierLength)
static qreal slopeAt(qreal t, qreal a, qreal b, qreal c, qreal d)
qreal x2
Definition: qbezier_p.h:116
qreal y2
Definition: qbezier_p.h:116
qreal x4
Definition: qbezier_p.h:116
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
Q_CORE_EXPORT void qWarning(const char *,...)
qreal angle() const
Returns the angle of the line in degrees.
Definition: qline.cpp:719
qreal y4
Definition: qbezier_p.h:116
qreal length() const
Returns the length of the current path.
qreal x3
Definition: qbezier_p.h:116
qreal x1
Definition: qbezier_p.h:116
qreal y1
Definition: qbezier_p.h:116
qreal y3
Definition: qbezier_p.h:116

◆ arcMoveTo() [1/2]

void QPainterPath::arcMoveTo ( const QRectF rectangle,
qreal  angle 
)

Creates a move to that lies on the arc that occupies the given rectangle at angle.

Since
4.2

Angles are specified in degrees. Clockwise arcs can be specified using negative angles.

See also
moveTo(), arcTo()

Definition at line 1024 of file qpainterpath.cpp.

Referenced by QPainter::drawArc(), and QPainter::drawChord().

1025 {
1026  if (rect.isNull())
1027  return;
1028 
1029  QPointF pt;
1030  qt_find_ellipse_coords(rect, angle, 0, &pt, 0);
1031  moveTo(pt);
1032 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void moveTo(const QPointF &p)
Moves the current point to the given point, implicitly starting a new subpath and closing the previou...
qreal angle(const QPointF &p1, const QPointF &p2)
void qt_find_ellipse_coords(const QRectF &r, qreal angle, qreal length, QPointF *startPoint, QPointF *endPoint)

◆ arcMoveTo() [2/2]

void QPainterPath::arcMoveTo ( qreal  x,
qreal  y,
qreal  width,
qreal  height,
qreal  angle 
)
inline

Creates a move to that lies on the arc that occupies the QRectF(x, y, width, height) at angle.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.2

Definition at line 318 of file qpainterpath.h.

319 {
320  arcMoveTo(QRectF(x, y, w, h), angle);
321 }
void arcMoveTo(const QRectF &rect, qreal angle)
Creates a move to that lies on the arc that occupies the given rectangle at angle.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal angle(const QPointF &p1, const QPointF &p2)

◆ arcTo() [1/2]

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.

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);
See also
arcMoveTo(), addEllipse(), QPainter::drawArc(), QPainter::drawPie(), {QPainterPath::Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 960 of file qpainterpath.cpp.

Referenced by QBalloonTip::balloon(), QRenderRule::borderClip(), QPainter::drawArc(), QPainter::drawChord(), QPainter::drawPie(), and QGraphicsEllipseItem::shape().

961 {
962 #ifdef QPP_DEBUG
963  printf("QPainterPath::arcTo() (%.2f, %.2f, %.2f, %.2f, angle=%.2f, sweep=%.2f\n",
964  rect.x(), rect.y(), rect.width(), rect.height(), startAngle, sweepLength);
965 #endif
966 
967  if ((!qt_is_finite(rect.x()) && !qt_is_finite(rect.y())) || !qt_is_finite(rect.width()) || !qt_is_finite(rect.height())
968  || !qt_is_finite(startAngle) || !qt_is_finite(sweepLength)) {
969 #ifndef QT_NO_DEBUG
970  qWarning("QPainterPath::arcTo: Adding arc where a parameter is NaN or Inf, ignoring call");
971 #endif
972  return;
973  }
974 
975  if (rect.isNull())
976  return;
977 
978  ensureData();
979  detach();
980 
981  int point_count;
982  QPointF pts[15];
983  QPointF curve_start = qt_curves_for_arc(rect, startAngle, sweepLength, pts, &point_count);
984 
985  lineTo(curve_start);
986  for (int i=0; i<point_count; i+=3) {
987  cubicTo(pts[i].x(), pts[i].y(),
988  pts[i+1].x(), pts[i+1].y(),
989  pts[i+2].x(), pts[i+2].y());
990  }
991 
992 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void lineTo(const QPointF &p)
Adds a straight line from the current position to the given endPoint.
void ensureData()
Definition: qpainterpath.h:213
Q_CORE_EXPORT void qWarning(const char *,...)
void cubicTo(const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt)
Adds a cubic Bezier curve between the current position and the given endPoint using the control point...
QPointF qt_curves_for_arc(const QRectF &rect, qreal startAngle, qreal sweepLength, QPointF *curves, int *point_count)
Creates a number of curves for a given arc definition.
Definition: qstroker.cpp:859
static bool qt_is_finite(double d)
Definition: qnumeric_p.h:197

◆ arcTo() [2/2]

void QPainterPath::arcTo ( qreal  x,
qreal  y,
qreal  w,
qreal  h,
qreal  startAngle,
qreal  arcLength 
)
inline

Definition at line 313 of file qpainterpath.h.

314 {
315  arcTo(QRectF(x, y, w, h), startAngle, arcLength);
316 }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void arcTo(const QRectF &rect, qreal startAngle, qreal arcLength)
Creates an arc that occupies the given rectangle, beginning at the specified startAngle and extending...

◆ boundingRect()

QRectF QPainterPath::boundingRect ( ) const

Returns the bounding rectangle of this painter path as a rectangle with floating point precision.

See also
controlPointRect()

Definition at line 1528 of file qpainterpath.cpp.

Referenced by QPathClipper::clip(), QPainter::clipBoundingRect(), QPainterPrivate::draw_helper(), QWin32PrintEngine::drawPath(), QPicturePaintEngine::drawPath(), QPainter::drawPath(), QPainterPrivate::drawStretchedGradient(), QRasterPaintEngine::fillPath(), QWin32PrintEnginePrivate::fillPath_dev(), QGraphicsView::fitInView(), QBlittablePixmapData::markRasterOverlay(), operator==(), QPainter::setClipPath(), and QPicturePaintEngine::updateClipPath().

1529 {
1530  if (!d_ptr)
1531  return QRectF();
1532  QPainterPathData *d = d_func();
1533 
1534  if (d->dirtyBounds)
1536  return d->bounds;
1537 }
double d
Definition: qnumeric_p.h:62
void computeBoundingRect() const
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
QScopedPointer< QPainterPathPrivate, QPainterPathPrivateDeleter > d_ptr
Definition: qpainterpath.h:211

◆ closeSubpath()

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.

See also
moveTo(), {QPainterPath::Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 666 of file qpainterpath.cpp.

Referenced by QFreetypeFace::addGlyphToPath(), addGlyphToPath(), QRenderRule::borderClip(), QMacFontPath::closePath(), collectSingleContour(), QPainter::drawChord(), QPainter::drawConvexPolygon(), QPainter::drawPie(), QWin32PrintEngine::drawPolygon(), QX11PaintEngine::drawPolygon(), QSvgPaintEngine::drawPolygon(), QPdfBaseEngine::drawPolygon(), QPainter::drawPolygon(), QCommonStyle::drawPrimitive(), QGraphicsView::mouseMoveEvent(), parsePathDataFast(), and QGraphicsView::render().

667 {
668 #ifdef QPP_DEBUG
669  printf("QPainterPath::closeSubpath()\n");
670 #endif
671  if (isEmpty())
672  return;
673  detach();
674 
675  d_func()->close();
676 }
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392
QPainterPathData * d_func() const
Definition: qpainterpath.h:221

◆ computeBoundingRect()

void QPainterPath::computeBoundingRect ( ) const
private

Definition at line 3548 of file qpainterpath.cpp.

Referenced by boundingRect().

3549 {
3550  QPainterPathData *d = d_func();
3551  d->dirtyBounds = false;
3552  if (!d_ptr) {
3553  d->bounds = QRect();
3554  return;
3555  }
3556 
3557  qreal minx, maxx, miny, maxy;
3558  minx = maxx = d->elements.at(0).x;
3559  miny = maxy = d->elements.at(0).y;
3560  for (int i=1; i<d->elements.size(); ++i) {
3561  const Element &e = d->elements.at(i);
3562 
3563  switch (e.type) {
3564  case MoveToElement:
3565  case LineToElement:
3566  if (e.x > maxx) maxx = e.x;
3567  else if (e.x < minx) minx = e.x;
3568  if (e.y > maxy) maxy = e.y;
3569  else if (e.y < miny) miny = e.y;
3570  break;
3571  case CurveToElement:
3572  {
3573  QBezier b = QBezier::fromPoints(d->elements.at(i-1),
3574  e,
3575  d->elements.at(i+1),
3576  d->elements.at(i+2));
3578  qreal right = r.right();
3579  qreal bottom = r.bottom();
3580  if (r.x() < minx) minx = r.x();
3581  if (right > maxx) maxx = right;
3582  if (r.y() < miny) miny = r.y();
3583  if (bottom > maxy) maxy = bottom;
3584  i += 2;
3585  }
3586  break;
3587  default:
3588  break;
3589  }
3590  }
3591  d->bounds = QRectF(minx, miny, maxx - minx, maxy - miny);
3592 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
static QRectF qt_painterpath_bezier_extrema(const QBezier &b)
static QBezier fromPoints(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4)
Definition: qbezier.cpp:71
QTextStream & right(QTextStream &stream)
Calls QTextStream::setFieldAlignment(QTextStream::AlignRight) on stream and returns stream...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QScopedPointer< QPainterPathPrivate, QPainterPathPrivateDeleter > d_ptr
Definition: qpainterpath.h:211

◆ computeControlPointRect()

void QPainterPath::computeControlPointRect ( ) const
private

Definition at line 3595 of file qpainterpath.cpp.

Referenced by controlPointRect().

3596 {
3597  QPainterPathData *d = d_func();
3598  d->dirtyControlBounds = false;
3599  if (!d_ptr) {
3600  d->controlBounds = QRect();
3601  return;
3602  }
3603 
3604  qreal minx, maxx, miny, maxy;
3605  minx = maxx = d->elements.at(0).x;
3606  miny = maxy = d->elements.at(0).y;
3607  for (int i=1; i<d->elements.size(); ++i) {
3608  const Element &e = d->elements.at(i);
3609  if (e.x > maxx) maxx = e.x;
3610  else if (e.x < minx) minx = e.x;
3611  if (e.y > maxy) maxy = e.y;
3612  else if (e.y < miny) miny = e.y;
3613  }
3614  d->controlBounds = QRectF(minx, miny, maxx - minx, maxy - miny);
3615 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QScopedPointer< QPainterPathPrivate, QPainterPathPrivateDeleter > d_ptr
Definition: qpainterpath.h:211

◆ connectPath()

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.

See also
addPath(), {QPainterPath::Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 1329 of file qpainterpath.cpp.

1330 {
1331  if (other.isEmpty())
1332  return;
1333 
1334  ensureData();
1335  detach();
1336 
1337  QPainterPathData *d = reinterpret_cast<QPainterPathData *>(d_func());
1338  // Remove last moveto so we don't get multiple moveto's
1339  if (d->elements.last().type == MoveToElement)
1340  d->elements.remove(d->elements.size()-1);
1341 
1342  // Locate where our own current subpath will start after the other path is added.
1343  int cStart = d->elements.size() + other.d_func()->cStart;
1344  int first = d->elements.size();
1345  d->elements += other.d_func()->elements;
1346 
1347  if (first != 0)
1348  d->elements[first].type = LineToElement;
1349 
1350  // avoid duplicate points
1351  if (first > 0 && QPointF(d->elements[first]) == QPointF(d->elements[first - 1])) {
1352  d->elements.remove(first--);
1353  --cStart;
1354  }
1355 
1356  if (cStart != first)
1357  d->cStart = cStart;
1358 }
double d
Definition: qnumeric_p.h:62
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void ensureData()
Definition: qpainterpath.h:213
QPainterPathData * d_func() const
Definition: qpainterpath.h:221

◆ contains() [1/3]

bool QPainterPath::contains ( const QPointF point) const

Returns true if the given point is inside the path, otherwise returns false.

See also
intersects()

Definition at line 1891 of file qpainterpath.cpp.

Referenced by QGraphicsTextItemPrivate::_q_mouseOnEdge(), QGraphicsItem::collidesWithPath(), contains(), QGraphicsItem::contains(), QGraphicsSceneIndexPathIntersector::intersect(), intersects(), QGraphicsSceneIndexPrivate::itemCollidesWithPath(), and QOpenGLPaintEngine::updateClipRegion().

1892 {
1893  if (isEmpty() || !controlPointRect().contains(pt))
1894  return false;
1895 
1896  QPainterPathData *d = d_func();
1897 
1898  int winding_number = 0;
1899 
1900  QPointF last_pt;
1901  QPointF last_start;
1902  for (int i=0; i<d->elements.size(); ++i) {
1903  const Element &e = d->elements.at(i);
1904 
1905  switch (e.type) {
1906 
1907  case MoveToElement:
1908  if (i > 0) // implicitly close all paths.
1909  qt_painterpath_isect_line(last_pt, last_start, pt, &winding_number);
1910  last_start = last_pt = e;
1911  break;
1912 
1913  case LineToElement:
1914  qt_painterpath_isect_line(last_pt, e, pt, &winding_number);
1915  last_pt = e;
1916  break;
1917 
1918  case CurveToElement:
1919  {
1920  const QPainterPath::Element &cp2 = d->elements.at(++i);
1921  const QPainterPath::Element &ep = d->elements.at(++i);
1922  qt_painterpath_isect_curve(QBezier::fromPoints(last_pt, e, cp2, ep),
1923  pt, &winding_number);
1924  last_pt = ep;
1925 
1926  }
1927  break;
1928 
1929  default:
1930  break;
1931  }
1932  }
1933 
1934  // implicitly close last subpath
1935  if (last_pt != last_start)
1936  qt_painterpath_isect_line(last_pt, last_start, pt, &winding_number);
1937 
1938  return (d->fillRule == Qt::WindingFill
1939  ? (winding_number != 0)
1940  : ((winding_number % 2) != 0));
1941 }
double d
Definition: qnumeric_p.h:62
The QPainterPath::Element class specifies the position and type of a subpath.
Definition: qpainterpath.h:77
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392
static void qt_painterpath_isect_curve(const QBezier &bezier, const QPointF &pt, int *winding, int depth=0)
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
bool contains(const QPointF &pt) const
Returns true if the given point is inside the path, otherwise returns false.
static void qt_painterpath_isect_line(const QPointF &p1, const QPointF &p2, const QPointF &pos, int *winding)
static QBezier fromPoints(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4)
Definition: qbezier.cpp:71
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
Qt::FillRule fillRule
QRectF controlPointRect() const
Returns the rectangle containing all the points and control points in this path.

◆ contains() [2/3]

bool QPainterPath::contains ( const QRectF rect) const

Returns true if the given rectangle is inside the path, otherwise returns false.

Definition at line 2244 of file qpainterpath.cpp.

2245 {
2246  Q_D(QPainterPath);
2247 
2248  // the path is empty or the control point rect doesn't completely
2249  // cover the rectangle we abort stratight away.
2250  if (isEmpty() || !controlPointRect().contains(rect))
2251  return false;
2252 
2253  // if there are intersections, chances are that the rect is not
2254  // contained, except if we have winding rule, in which case it
2255  // still might.
2256  if (qt_painterpath_check_crossing(this, rect)) {
2257  if (fillRule() == Qt::OddEvenFill) {
2258  return false;
2259  } else {
2260  // Do some wague sampling in the winding case. This is not
2261  // precise but it should mostly be good enough.
2262  if (!contains(rect.topLeft()) ||
2263  !contains(rect.topRight()) ||
2264  !contains(rect.bottomRight()) ||
2265  !contains(rect.bottomLeft()))
2266  return false;
2267  }
2268  }
2269 
2270  // If there exists a point inside that is not part of the path its
2271  // because: rectangle lies completely outside path or a subpath
2272  // excludes parts of the rectangle. Both cases mean that the rect
2273  // is not contained
2274  if (!contains(rect.center()))
2275  return false;
2276 
2277  // If there are any subpaths inside this rectangle we need to
2278  // check if they are still contained as a result of the fill
2279  // rule. This can only be the case for WindingFill though. For
2280  // OddEvenFill the rect will never be contained if it surrounds a
2281  // subpath. (the case where two subpaths are completely identical
2282  // can be argued but we choose to neglect it).
2283  for (int i=0; i<d->elements.size(); ++i) {
2284  const Element &e = d->elements.at(i);
2285  if (e.type == QPainterPath::MoveToElement && rect.contains(e)) {
2286  if (fillRule() == Qt::OddEvenFill)
2287  return false;
2288 
2289  bool stop = false;
2290  for (; !stop && i<d->elements.size(); ++i) {
2291  const Element &el = d->elements.at(i);
2292  switch (el.type) {
2293  case MoveToElement:
2294  stop = true;
2295  break;
2296  case LineToElement:
2297  if (!contains(el))
2298  return false;
2299  break;
2300  case CurveToElement:
2301  if (!contains(d->elements.at(i+2)))
2302  return false;
2303  i += 2;
2304  break;
2305  default:
2306  break;
2307  }
2308  }
2309 
2310  // compensate for the last ++i in the inner for
2311  --i;
2312  }
2313  }
2314 
2315  return true;
2316 }
double d
Definition: qnumeric_p.h:62
QPointF bottomRight() const
Returns the position of the rectangle&#39;s bottom-right corner.
Definition: qrect.h:540
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
QPointF topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:539
QPointF bottomLeft() const
Returns the position of the rectangle&#39;s bottom-left corner.
Definition: qrect.h:542
bool contains(const QPointF &pt) const
Returns true if the given point is inside the path, otherwise returns false.
#define Q_D(Class)
Definition: qglobal.h:2482
bool contains(const QPointF &p) const
Returns true if the given point is inside or on the edge of the rectangle; otherwise returns false...
Definition: qrect.cpp:2349
Qt::FillRule fillRule() const
Returns the painter path&#39;s currently set fill rule.
static bool qt_painterpath_check_crossing(const QPainterPath *path, const QRectF &rect)
QRectF controlPointRect() const
Returns the rectangle containing all the points and control points in this path.
QPointF topRight() const
Returns the position of the rectangle&#39;s top-right corner.
Definition: qrect.h:541
QPointF center() const
Returns the center point of the rectangle.
Definition: qrect.h:686

◆ contains() [3/3]

bool QPainterPath::contains ( const QPainterPath p) const

Returns true if the given path p is contained within the current path.

Since
4.3

Returns false if any edges of the current path and p intersect.

Set operations on paths will treat the paths as areas. Non-closed paths will be treated as implicitly closed.

See also
intersects()

Definition at line 3529 of file qpainterpath.cpp.

3530 {
3531  if (p.elementCount() == 1)
3532  return contains(p.elementAt(0));
3533  if (isEmpty() || p.isEmpty())
3534  return false;
3535  QPathClipper clipper(*this, p);
3536  return clipper.contains();
3537 }
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392
bool contains(const QPointF &pt) const
Returns true if the given point is inside the path, otherwise returns false.
const QPainterPath::Element & elementAt(int i) const
Returns the element at the given index in the painter path.
Definition: qpainterpath.h:402
int elementCount() const
Returns the number of path elements in the painter path.
Definition: qpainterpath.h:397

◆ controlPointRect()

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().

See also
boundingRect()

Definition at line 1549 of file qpainterpath.cpp.

Referenced by QAlphaPaintEnginePrivate::addPenWidth(), QGraphicsPathItem::boundingRect(), QGraphicsEllipseItem::boundingRect(), QGraphicsPolygonItem::boundingRect(), QGraphicsLineItem::boundingRect(), QGraphicsItem::collidesWithPath(), QGLLineMaskGenerator::computeScreenRect(), QGLRectMaskGenerator::computeScreenRect(), contains(), QRasterPaintEngine::fillPath(), intersects(), QGraphicsSceneIndex::items(), QRasterizer::rasterize(), QGraphicsSceneIndexPrivate::recursive_items_helper(), and QOpenGLPaintEnginePrivate::strokePathFastPen().

1550 {
1551  if (!d_ptr)
1552  return QRectF();
1553  QPainterPathData *d = d_func();
1554 
1555  if (d->dirtyControlBounds)
1557  return d->controlBounds;
1558 }
double d
Definition: qnumeric_p.h:62
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
QScopedPointer< QPainterPathPrivate, QPainterPathPrivateDeleter > d_ptr
Definition: qpainterpath.h:211
void computeControlPointRect() const

◆ cubicTo() [1/2]

void QPainterPath::cubicTo ( const QPointF c1,
const QPointF c2,
const QPointF endPoint 
)

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.

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);
See also
quadTo(), {QPainterPath::Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 821 of file qpainterpath.cpp.

Referenced by addEllipse(), QFreetypeFace::addGlyphToPath(), addGlyphToPath(), QDeclarativePathCubic::addToPath(), arcTo(), QOpenGLPaintEngine::clip(), QOutlineMapper::clipElements(), QMacFontPath::cubicTo(), QPicture::exec(), QPathClipper::handleCrossingEdges(), parsePathDataFast(), pathArcSegment(), qt_painterPathFromVectorPath(), quadTo(), QPainter::setViewTransformEnabled(), and toReversed().

822 {
823 #ifdef QPP_DEBUG
824  printf("QPainterPath::cubicTo() (%.2f,%.2f), (%.2f,%.2f), (%.2f,%.2f)\n",
825  c1.x(), c1.y(), c2.x(), c2.y(), e.x(), e.y());
826 #endif
827 
828  if (!qt_is_finite(c1.x()) || !qt_is_finite(c1.y()) || !qt_is_finite(c2.x()) || !qt_is_finite(c2.y())
829  || !qt_is_finite(e.x()) || !qt_is_finite(e.y())) {
830 #ifndef QT_NO_DEBUG
831  qWarning("QPainterPath::cubicTo: Adding point where x or y is NaN or Inf, ignoring call");
832 #endif
833  return;
834  }
835 
836  ensureData();
837  detach();
838 
840  Q_ASSERT(!d->elements.isEmpty());
841 
842 
843  // Abort on empty curve as a stroker cannot handle this and the
844  // curve is irrelevant anyway.
845  if (d->elements.last() == c1 && c1 == c2 && c2 == e)
846  return;
847 
848  d->maybeMoveTo();
849 
850  Element ce1 = { c1.x(), c1.y(), CurveToElement };
851  Element ce2 = { c2.x(), c2.y(), CurveToDataElement };
852  Element ee = { e.x(), e.y(), CurveToDataElement };
853  d->elements << ce1 << ce2 << ee;
854 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
void ensureData()
Definition: qpainterpath.h:213
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
Q_CORE_EXPORT void qWarning(const char *,...)
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
static bool qt_is_finite(double d)
Definition: qnumeric_p.h:197

◆ cubicTo() [2/2]

void QPainterPath::cubicTo ( qreal  c1X,
qreal  c1Y,
qreal  c2X,
qreal  c2Y,
qreal  endPointX,
qreal  endPointY 
)
inline

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}).

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 323 of file qpainterpath.h.

325 {
326  cubicTo(QPointF(ctrlPt1x, ctrlPt1y), QPointF(ctrlPt2x, ctrlPt2y),
327  QPointF(endPtx, endPty));
328 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void cubicTo(const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt)
Adds a cubic Bezier curve between the current position and the given endPoint using the control point...

◆ currentPosition()

QPointF QPainterPath::currentPosition ( ) const

Returns the current position of the path.

Definition at line 1044 of file qpainterpath.cpp.

1045 {
1046  return !d_ptr || d_func()->elements.isEmpty()
1047  ? QPointF()
1048  : QPointF(d_func()->elements.last().x, d_func()->elements.last().y);
1049 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
static const QTextHtmlElement elements[Html_NumElements]
QScopedPointer< QPainterPathPrivate, QPainterPathPrivateDeleter > d_ptr
Definition: qpainterpath.h:211

◆ d_func()

QPainterPathData* QPainterPath::d_func ( ) const
inlineprivate

Definition at line 221 of file qpainterpath.h.

Referenced by addEllipse(), addPath(), addPolygon(), addRect(), addRegion(), boundingRect(), closeSubpath(), connectPath(), contains(), controlPointRect(), QVectorPath::convertToPainterPath(), cubicTo(), currentPosition(), detach_helper(), fillRule(), lineTo(), moveTo(), operator<<(), operator=(), operator==(), operator>>(), QPainterPath(), qtVectorPathForPath(), setFillRule(), and translate().

221 { return reinterpret_cast<QPainterPathData *>(d_ptr.data()); }
T * data() const
Returns the value of the pointer referenced by this object.
QScopedPointer< QPainterPathPrivate, QPainterPathPrivateDeleter > d_ptr
Definition: qpainterpath.h:211

◆ detach()

void QPainterPath::detach ( )
inlineprivate

Definition at line 420 of file qpainterpath.h.

Referenced by addEllipse(), addPath(), addPolygon(), addRect(), addRegion(), addText(), arcTo(), closeSubpath(), connectPath(), cubicTo(), lineTo(), QMatrix::map(), QTransform::map(), moveTo(), quadTo(), setFillRule(), and translate().

421 {
422  if (d_ptr->ref != 1)
423  detach_helper();
424  setDirty(true);
425 }
void detach_helper()
void setDirty(bool)
QScopedPointer< QPainterPathPrivate, QPainterPathPrivateDeleter > d_ptr
Definition: qpainterpath.h:211

◆ detach_helper()

void QPainterPath::detach_helper ( )
private
Warning
This function is not part of the public interface.

Definition at line 597 of file qpainterpath.cpp.

598 {
600  d_ptr.reset(data);
601 }
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
friend class QPainterPathData
Definition: qpainterpath.h:223
static const char * data(const QByteArray &arr)
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
QScopedPointer< QPainterPathPrivate, QPainterPathPrivateDeleter > d_ptr
Definition: qpainterpath.h:211

◆ elementAt()

const QPainterPath::Element & QPainterPath::elementAt ( int  index) const
inline

Returns the element at the given index in the painter path.

See also
ElementType, elementCount(), isEmpty()

Definition at line 402 of file qpainterpath.h.

Referenced by addGlyphToPath(), addLineTo(), QPathSegments::addPath(), bezierAtT(), charString(), QWin32PrintEnginePrivate::composeGdiPath(), contains(), QOutlineMapper::convertPath(), convertPath(), QX11PaintEngine::drawFreetype(), QSvgPaintEngine::drawPath(), QDirectFBPaintEngine::fill(), QPdf::generatePath(), QGLLineMaskGenerator::generateTrapezoids(), QGLRectMaskGenerator::generateTrapezoids(), QGLStrokeCache::getStrokedPath(), QPathClipper::handleCrossingEdges(), QGLMaskTextureCache::hash(), intersects(), QGraphicsSceneIndexPrivate::itemCollidesWithPath(), mapProjective(), nextBezier(), operator<<(), QVGPaintEnginePrivate::painterPathToVGPath(), pathClosed(), QPathClipper::pathToRect(), QOpenGLPaintEnginePrivate::pathToVertexArrays(), qt_find_ellipse_coords(), qt_ft_outline_cubic_to(), qt_mac_compose_path(), qt_painterpath_check_crossing(), qt_vg_pathToRect(), QRasterizer::rasterize(), QStrokerOps::strokePath(), and QOpenGLPaintEnginePrivate::strokePathFastPen().

403 {
404  Q_ASSERT(d_ptr);
405  Q_ASSERT(i >= 0 && i < elementCount());
406  return d_ptr->elements.at(i);
407 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QVector< QPainterPath::Element > elements
Definition: qpainterpath.h:254
int elementCount() const
Returns the number of path elements in the painter path.
Definition: qpainterpath.h:397
QScopedPointer< QPainterPathPrivate, QPainterPathPrivateDeleter > d_ptr
Definition: qpainterpath.h:211

◆ elementCount()

int QPainterPath::elementCount ( ) const
inline

Returns the number of path elements in the painter path.

See also
ElementType, elementAt(), isEmpty()

Definition at line 397 of file qpainterpath.h.

Referenced by addGlyphToPath(), addLineTo(), QPathSegments::addPath(), bezierAtT(), charString(), QWin32PrintEnginePrivate::composeGdiPath(), contains(), QOutlineMapper::convertPath(), convertPath(), QX11PaintEngine::drawFreetype(), QSvgPaintEngine::drawPath(), QPainter::drawPath(), generateGlyph(), QPdf::generatePath(), QGLLineMaskGenerator::generateTrapezoids(), QGLRectMaskGenerator::generateTrapezoids(), QGLStrokeCache::getStrokedPath(), QPathClipper::handleCrossingEdges(), QGLMaskTextureCache::hash(), intersects(), QMatrix::map(), QTransform::map(), mapProjective(), nextBezier(), operator<<(), QVGPaintEnginePrivate::painterPathToVGPath(), pathClosed(), QPathClipper::pathToRect(), QOpenGLPaintEnginePrivate::pathToVertexArrays(), qt_find_ellipse_coords(), qt_ft_outline_cubic_to(), qt_mac_compose_path(), qt_painterpath_check_crossing(), qt_vg_pathToRect(), quadTo(), QRasterizer::rasterize(), QPainter::setClipPath(), QStrokerOps::strokePath(), QOpenGLPaintEnginePrivate::strokePathFastPen(), and toSubpathPolygons().

398 {
399  return d_ptr ? d_ptr->elements.size() : 0;
400 }
QVector< QPainterPath::Element > elements
Definition: qpainterpath.h:254
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QScopedPointer< QPainterPathPrivate, QPainterPathPrivateDeleter > d_ptr
Definition: qpainterpath.h:211

◆ ensureData()

void QPainterPath::ensureData ( )
inlineprivate

Definition at line 213 of file qpainterpath.h.

Referenced by addEllipse(), addPath(), addPolygon(), addRect(), addRegion(), addText(), arcTo(), connectPath(), QVectorPath::convertToPainterPath(), cubicTo(), lineTo(), moveTo(), operator>>(), quadTo(), and setFillRule().

213 { if (!d_ptr) ensureData_helper(); }
void ensureData_helper()
QScopedPointer< QPainterPathPrivate, QPainterPathPrivateDeleter > d_ptr
Definition: qpainterpath.h:211

◆ ensureData_helper()

void QPainterPath::ensureData_helper ( )
private
Warning
This function is not part of the public interface.

Definition at line 606 of file qpainterpath.cpp.

607 {
609  data->elements.reserve(16);
611  data->elements << e;
612  d_ptr.reset(data);
613  Q_ASSERT(d_ptr != 0);
614 }
The QPainterPath::Element class specifies the position and type of a subpath.
Definition: qpainterpath.h:77
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
friend class QPainterPathData
Definition: qpainterpath.h:223
static const char * data(const QByteArray &arr)
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
QVector< QPainterPath::Element > elements
Definition: qpainterpath.h:254
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339
QScopedPointer< QPainterPathPrivate, QPainterPathPrivateDeleter > d_ptr
Definition: qpainterpath.h:211

◆ fillRule()

Qt::FillRule QPainterPath::fillRule ( ) const

◆ intersected()

QPainterPath QPainterPath::intersected ( const QPainterPath p) const

Returns a path which is the intersection of this path's fill area and p's fill area.

Since
4.3

Bezier curves may be flattened to line segments due to numerical instability of doing bezier curve intersections.

Definition at line 3425 of file qpainterpath.cpp.

Referenced by QOutlineMapper::clipElements(), QGraphicsItem::clipPath(), QX11PaintEnginePrivate::fillPath(), QPolygon::intersected(), QPolygonF::intersected(), operator!=(), and QPdfBaseEngine::updateClipPath().

3426 {
3427  if (isEmpty() || p.isEmpty())
3428  return QPainterPath();
3429  QPathClipper clipper(*this, p);
3430  return clipper.clip(QPathClipper::BoolAnd);
3431 }
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392
QPainterPath()
Constructs an empty QPainterPath object.

◆ intersects() [1/2]

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.

See also
contains()

Definition at line 2134 of file qpainterpath.cpp.

Referenced by QGraphicsItem::collidesWithPath(), QGraphicsSceneIndexPathIntersector::intersect(), and QGraphicsSceneIndexPrivate::itemCollidesWithPath().

2135 {
2136  if (elementCount() == 1 && rect.contains(elementAt(0)))
2137  return true;
2138 
2139  if (isEmpty())
2140  return false;
2141 
2142  QRectF cp = controlPointRect();
2143  QRectF rn = rect.normalized();
2144 
2145  // QRectF::intersects returns false if one of the rects is a null rect
2146  // which would happen for a painter path consisting of a vertical or
2147  // horizontal line
2148  if (qMax(rn.left(), cp.left()) > qMin(rn.right(), cp.right())
2149  || qMax(rn.top(), cp.top()) > qMin(rn.bottom(), cp.bottom()))
2150  return false;
2151 
2152  // If any path element cross the rect its bound to be an intersection
2153  if (qt_painterpath_check_crossing(this, rect))
2154  return true;
2155 
2156  if (contains(rect.center()))
2157  return true;
2158 
2159  Q_D(QPainterPath);
2160 
2161  // Check if the rectangle surounds any subpath...
2162  for (int i=0; i<d->elements.size(); ++i) {
2163  const Element &e = d->elements.at(i);
2164  if (e.type == QPainterPath::MoveToElement && rect.contains(e))
2165  return true;
2166  }
2167 
2168  return false;
2169 }
double d
Definition: qnumeric_p.h:62
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
bool contains(const QPointF &pt) const
Returns true if the given point is inside the path, otherwise returns false.
#define Q_D(Class)
Definition: qglobal.h:2482
const QPainterPath::Element & elementAt(int i) const
Returns the element at the given index in the painter path.
Definition: qpainterpath.h:402
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
static bool qt_painterpath_check_crossing(const QPainterPath *path, const QRectF &rect)
QRectF controlPointRect() const
Returns the rectangle containing all the points and control points in this path.
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
int elementCount() const
Returns the number of path elements in the painter path.
Definition: qpainterpath.h:397
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
QRectF normalized() const
Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height...
Definition: qrect.cpp:1822

◆ intersects() [2/2]

bool QPainterPath::intersects ( const QPainterPath p) const

Returns true if the current path intersects at any point the given path p.

Since
4.3

Also returns true if the current path contains or is contained by any part of p.

Set operations on paths will treat the paths as areas. Non-closed paths will be treated as implicitly closed.

See also
contains()

Definition at line 3504 of file qpainterpath.cpp.

3505 {
3506  if (p.elementCount() == 1)
3507  return contains(p.elementAt(0));
3508  if (isEmpty() || p.isEmpty())
3509  return false;
3510  QPathClipper clipper(*this, p);
3511  return clipper.intersect();
3512 }
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392
bool contains(const QPointF &pt) const
Returns true if the given point is inside the path, otherwise returns false.
const QPainterPath::Element & elementAt(int i) const
Returns the element at the given index in the painter path.
Definition: qpainterpath.h:402
int elementCount() const
Returns the number of path elements in the painter path.
Definition: qpainterpath.h:397

◆ isEmpty()

bool QPainterPath::isEmpty ( ) const
inline

Returns true if either there are no elements in this path, or if the only element is a MoveToElement; otherwise returns false.

See also
elementCount()

Definition at line 392 of file qpainterpath.h.

Referenced by addPath(), QTextureGlyphCache::calculateSubPixelPositionCount(), QPaintEngineEx::clip(), QOutlineMapper::clipElements(), QGraphicsItem::clipPath(), closeSubpath(), QGraphicsItem::collidesWithPath(), connectPath(), contains(), QOutlineMapper::convertPath(), QPainterPathStroker::createStroke(), QTextLayout::draw(), QPainterPrivate::draw_helper(), QRenderRule::drawBackground(), QX11PaintEngine::drawPath(), QOpenGLPaintEngine::drawPath(), QPaintEngineEx::drawPath(), QPaintEngine::drawRects(), QPaintEngineEx::drawStaticTextItem(), QPaintEngine::drawTextItem(), QPainter::fillPath(), QOpenGLPaintEnginePrivate::fillPath(), fillRule(), QVGFontEngineCleaner::fontEngineDestroyed(), QPathClipper::handleCrossingEdges(), intersected(), intersects(), QMatrix::map(), operator<<(), QGraphicsPathItem::QGraphicsPathItem(), qt_mac_compose_path(), QRasterizer::rasterize(), QRenderRule::setClip(), QStrokerOps::strokePath(), QWin32PrintEnginePrivate::strokePath(), QPainter::strokePath(), subtracted(), toReversed(), toSubpathPolygons(), united(), QRenderRule::unsetClip(), QWin32PrintEngine::updateClipPath(), QCoreGraphicsPaintEngine::updateClipPath(), and QPdfBaseEngine::updateClipPath().

393 {
394  return !d_ptr || (d_ptr->elements.size() == 1 && d_ptr->elements.first().type == MoveToElement);
395 }
ElementType type
the type of element
Definition: qpainterpath.h:81
T & first()
Returns a reference to the first item in the vector.
Definition: qvector.h:260
QVector< QPainterPath::Element > elements
Definition: qpainterpath.h:254
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QScopedPointer< QPainterPathPrivate, QPainterPathPrivateDeleter > d_ptr
Definition: qpainterpath.h:211

◆ length()

qreal QPainterPath::length ( ) const

Returns the length of the current path.

Definition at line 2930 of file qpainterpath.cpp.

Referenced by bezierAtT().

2931 {
2932  Q_D(QPainterPath);
2933  if (isEmpty())
2934  return 0;
2935 
2936  qreal len = 0;
2937  for (int i=1; i<d->elements.size(); ++i) {
2938  const Element &e = d->elements.at(i);
2939 
2940  switch (e.type) {
2941  case MoveToElement:
2942  break;
2943  case LineToElement:
2944  {
2945  len += QLineF(d->elements.at(i-1), e).length();
2946  break;
2947  }
2948  case CurveToElement:
2949  {
2950  QBezier b = QBezier::fromPoints(d->elements.at(i-1),
2951  e,
2952  d->elements.at(i+1),
2953  d->elements.at(i+2));
2954  len += b.length();
2955  i += 2;
2956  break;
2957  }
2958  default:
2959  break;
2960  }
2961  }
2962  return len;
2963 }
double d
Definition: qnumeric_p.h:62
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392
double qreal
Definition: qglobal.h:1193
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
qreal length(qreal error=0.01) const
Definition: qbezier.cpp:529
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
static QBezier fromPoints(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4)
Definition: qbezier.cpp:71
qreal length() const
Returns the length of the current path.

◆ lineTo() [1/2]

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.

See also
addPolygon(), addRect(), {QPainterPath::Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 758 of file qpainterpath.cpp.

Referenced by QFreetypeFace::addGlyphToPath(), addGlyphToPath(), addLineTo(), QDeclarativePathLine::addToPath(), arcTo(), QBalloonTip::balloon(), QRenderRule::borderClip(), QSvgLine::bounds(), QOpenGLPaintEngine::clip(), QOutlineMapper::clipElements(), collectSingleContour(), QPainter::drawChord(), QPlastiqueStyle::drawComplexControl(), QPainter::drawConvexPolygon(), QOpenGLPaintEnginePrivate::drawFastRect(), QX11PaintEngine::drawLines(), QOpenGLPaintEngine::drawLines(), QPdfBaseEngine::drawLines(), QPainter::drawLines(), QX11PaintEngine::drawPoints(), QPdfBaseEngine::drawPoints(), QPainter::drawPoints(), QWin32PrintEngine::drawPolygon(), QX11PaintEngine::drawPolygon(), QOpenGLPaintEngine::drawPolygon(), QSvgPaintEngine::drawPolygon(), QPdfBaseEngine::drawPolygon(), QPainter::drawPolygon(), QPainter::drawPolyline(), QWindowsCEStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QPathClipper::handleCrossingEdges(), QRegion::intersects(), QMacFontPath::lineTo(), lineTo_clipped(), parsePathDataFast(), qt_painterPathFromVectorPath(), QGraphicsLineItem::shape(), and toReversed().

759 {
760 #ifdef QPP_DEBUG
761  printf("QPainterPath::lineTo() (%.2f,%.2f)\n", p.x(), p.y());
762 #endif
763 
764  if (!qt_is_finite(p.x()) || !qt_is_finite(p.y())) {
765 #ifndef QT_NO_DEBUG
766  qWarning("QPainterPath::lineTo: Adding point where x or y is NaN or Inf, ignoring call");
767 #endif
768  return;
769  }
770 
771  ensureData();
772  detach();
773 
775  Q_ASSERT(!d->elements.isEmpty());
776  d->maybeMoveTo();
777  if (p == QPointF(d->elements.last()))
778  return;
779  Element elm = { p.x(), p.y(), LineToElement };
780  d->elements.append(elm);
781 
782  d->convex = d->elements.size() == 3 || (d->elements.size() == 4 && d->isClosed());
783 }
double d
Definition: qnumeric_p.h:62
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void ensureData()
Definition: qpainterpath.h:213
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
Q_CORE_EXPORT void qWarning(const char *,...)
bool isClosed() const
static bool qt_is_finite(double d)
Definition: qnumeric_p.h:197

◆ lineTo() [2/2]

void QPainterPath::lineTo ( qreal  x,
qreal  y 
)
inline

Draws a line from the current position to the point ({x}, {y}).

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 308 of file qpainterpath.h.

309 {
310  lineTo(QPointF(x, y));
311 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void lineTo(const QPointF &p)
Adds a straight line from the current position to the given endPoint.

◆ moveTo() [1/2]

void QPainterPath::moveTo ( const QPointF point)

Moves the current point to the given point, implicitly starting a new subpath and closing the previous one.

See also
closeSubpath(), {QPainterPath::Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 702 of file qpainterpath.cpp.

Referenced by add(), addEllipse(), QFreetypeFace::addGlyphToPath(), addGlyphToPath(), addPolygon(), addRect(), arcMoveTo(), QBalloonTip::balloon(), QRenderRule::borderClip(), QSvgLine::bounds(), QOpenGLPaintEngine::clip(), QOutlineMapper::clipElements(), collectSingleContour(), QPainter::drawChord(), QPlastiqueStyle::drawComplexControl(), QOpenGLPaintEnginePrivate::drawFastRect(), QOpenGLPaintEngine::drawLines(), QPdfBaseEngine::drawLines(), QPainter::drawLines(), QPainter::drawPie(), QX11PaintEngine::drawPoints(), QPdfBaseEngine::drawPoints(), QPainter::drawPoints(), QOpenGLPaintEngine::drawPolygon(), QPdfBaseEngine::drawPolygon(), QWindowsCEStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QPicture::exec(), QPathClipper::handleCrossingEdges(), QRegion::intersects(), lineTo_clipped(), QMacFontPath::moveTo(), parsePathDataFast(), qt_painterPathFromVectorPath(), QPainter::setViewTransformEnabled(), QGraphicsEllipseItem::shape(), QGraphicsLineItem::shape(), and toReversed().

703 {
704 #ifdef QPP_DEBUG
705  printf("QPainterPath::moveTo() (%.2f,%.2f)\n", p.x(), p.y());
706 #endif
707 
708  if (!qt_is_finite(p.x()) || !qt_is_finite(p.y())) {
709 #ifndef QT_NO_DEBUG
710  qWarning("QPainterPath::moveTo: Adding point where x or y is NaN or Inf, ignoring call");
711 #endif
712  return;
713  }
714 
715  ensureData();
716  detach();
717 
719  Q_ASSERT(!d->elements.isEmpty());
720 
721  d->require_moveTo = false;
722 
723  if (d->elements.last().type == MoveToElement) {
724  d->elements.last().x = p.x();
725  d->elements.last().y = p.y();
726  } else {
727  Element elm = { p.x(), p.y(), MoveToElement };
728  d->elements.append(elm);
729  }
730  d->cStart = d->elements.size() - 1;
731 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void ensureData()
Definition: qpainterpath.h:213
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
Q_CORE_EXPORT void qWarning(const char *,...)
static bool qt_is_finite(double d)
Definition: qnumeric_p.h:197

◆ moveTo() [2/2]

void QPainterPath::moveTo ( qreal  x,
qreal  y 
)
inline

Moves the current position to ({x}, {y}) and starts a new subpath, implicitly closing the previous path.

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 303 of file qpainterpath.h.

304 {
305  moveTo(QPointF(x, y));
306 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void moveTo(const QPointF &p)
Moves the current point to the given point, implicitly starting a new subpath and closing the previou...

◆ operator &()

QPainterPath QPainterPath::operator& ( const QPainterPath other) const

Referenced by operator!=().

◆ operator &=()

QPainterPath& QPainterPath::operator&= ( const QPainterPath other)

Referenced by operator-().

◆ operator!=()

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.

See also
operator==()

Definition at line 2368 of file qpainterpath.cpp.

2369 {
2370  return !(*this==path);
2371 }

◆ operator+()

QPainterPath QPainterPath::operator+ ( const QPainterPath other) const

Returns the union of this path and the other path.

Since
4.5

This function is equivalent to operator|().

See also
united(), operator+=(), operator-()

Definition at line 2414 of file qpainterpath.cpp.

2415 {
2416  return united(other);
2417 }
QPainterPath united(const QPainterPath &r) const
Returns a path which is the union of this path&#39;s fill area and p&#39;s fill area.

◆ operator+=()

QPainterPath & QPainterPath::operator+= ( const QPainterPath other)

Unites this path with other, and returns a reference to this path.

Since
4.5

This is equivalent to operator|=().

See also
united(), operator+(), operator-=()

Definition at line 2475 of file qpainterpath.cpp.

2476 {
2477  return *this = (*this + other);
2478 }

◆ operator-()

QPainterPath QPainterPath::operator- ( const QPainterPath other) const

Subtracts the other path from a copy of this path, and returns the copy.

Since
4.5
See also
subtracted(), operator-=(), operator+()

Definition at line 2429 of file qpainterpath.cpp.

2430 {
2431  return subtracted(other);
2432 }
QPainterPath subtracted(const QPainterPath &r) const
Returns a path which is p&#39;s fill area subtracted from this path&#39;s fill area.

◆ operator-=()

QPainterPath & QPainterPath::operator-= ( const QPainterPath other)

Subtracts other from this path, and returns a reference to this path.

Since
4.5
See also
subtracted(), operator-(), operator+=()

Definition at line 2491 of file qpainterpath.cpp.

2492 {
2493  return *this = (*this - other);
2494 }

◆ operator=()

QPainterPath & QPainterPath::operator= ( const QPainterPath path)

Assigns the given path to this painter path.

See also
QPainterPath()

Definition at line 626 of file qpainterpath.cpp.

627 {
628  if (other.d_func() != d_func()) {
629  QPainterPathPrivate *data = other.d_func();
630  if (data)
631  data->ref.ref();
632  d_ptr.reset(data);
633  }
634  return *this;
635 }
bool ref()
Atomically increments the value of this QAtomicInt.
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
static const char * data(const QByteArray &arr)
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
QScopedPointer< QPainterPathPrivate, QPainterPathPrivateDeleter > d_ptr
Definition: qpainterpath.h:211

◆ operator==()

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.

See also
operator!=()

Definition at line 2333 of file qpainterpath.cpp.

2334 {
2335  QPainterPathData *d = reinterpret_cast<QPainterPathData *>(d_func());
2336  if (path.d_func() == d)
2337  return true;
2338  else if (!d || !path.d_func())
2339  return false;
2340  else if (d->fillRule != path.d_func()->fillRule)
2341  return false;
2342  else if (d->elements.size() != path.d_func()->elements.size())
2343  return false;
2344 
2345  const qreal qt_epsilon = sizeof(qreal) == sizeof(double) ? 1e-12 : qreal(1e-5);
2346 
2347  QSizeF epsilon = boundingRect().size();
2348  epsilon.rwidth() *= qt_epsilon;
2349  epsilon.rheight() *= qt_epsilon;
2350 
2351  for (int i = 0; i < d->elements.size(); ++i)
2352  if (d->elements.at(i).type != path.d_func()->elements.at(i).type
2353  || !epsilonCompare(d->elements.at(i), path.d_func()->elements.at(i), epsilon))
2354  return false;
2355 
2356  return true;
2357 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
QRectF boundingRect() const
Returns the bounding rectangle of this painter path as a rectangle with floating point precision...
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
static bool epsilonCompare(const QPointF &a, const QPointF &b, const QSizeF &epsilon)
Qt::FillRule fillRule
QSizeF size() const
Returns the size of the rectangle.
Definition: qrect.h:713
qreal & rheight()
Returns a reference to the height.
Definition: qsize.h:302
qreal & rwidth()
Returns a reference to the width.
Definition: qsize.h:299

◆ operator|()

QPainterPath QPainterPath::operator| ( const QPainterPath other) const

Returns the union of this path and the other path.

Since
4.5
See also
united(), operator|=(), intersected(), operator&()

Definition at line 2398 of file qpainterpath.cpp.

2399 {
2400  return united(other);
2401 }
QPainterPath united(const QPainterPath &r) const
Returns a path which is the union of this path&#39;s fill area and p&#39;s fill area.

◆ operator|=()

QPainterPath & QPainterPath::operator|= ( const QPainterPath other)

Unites this path with other and returns a reference to this path.

Since
4.5
See also
united(), operator|(), operator&=()

Definition at line 2459 of file qpainterpath.cpp.

2460 {
2461  return *this = (*this | other);
2462 }

◆ percentAtLength()

qreal QPainterPath::percentAtLength ( qreal  len) const

Returns percentage of the whole path at the specified length len.

Note that similarly to other percent methods, the percentage measurement is not linear with regards to the length, if curves are present in the path. When curves are present the percentage argument is mapped to the t parameter of the Bezier equations.

Definition at line 2973 of file qpainterpath.cpp.

2974 {
2975  Q_D(QPainterPath);
2976  if (isEmpty() || len <= 0)
2977  return 0;
2978 
2979  qreal totalLength = length();
2980  if (len > totalLength)
2981  return 1;
2982 
2983  qreal curLen = 0;
2984  for (int i=1; i<d->elements.size(); ++i) {
2985  const Element &e = d->elements.at(i);
2986 
2987  switch (e.type) {
2988  case MoveToElement:
2989  break;
2990  case LineToElement:
2991  {
2992  QLineF line(d->elements.at(i-1), e);
2993  qreal llen = line.length();
2994  curLen += llen;
2995  if (curLen >= len) {
2996  return len/totalLength ;
2997  }
2998 
2999  break;
3000  }
3001  case CurveToElement:
3002  {
3003  QBezier b = QBezier::fromPoints(d->elements.at(i-1),
3004  e,
3005  d->elements.at(i+1),
3006  d->elements.at(i+2));
3007  qreal blen = b.length();
3008  qreal prevLen = curLen;
3009  curLen += blen;
3010 
3011  if (curLen >= len) {
3012  qreal res = b.tAtLength(len - prevLen);
3013  return (res * blen + prevLen)/totalLength;
3014  }
3015 
3016  i += 2;
3017  break;
3018  }
3019  default:
3020  break;
3021  }
3022  }
3023 
3024  return 0;
3025 }
double d
Definition: qnumeric_p.h:62
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392
double qreal
Definition: qglobal.h:1193
qreal length() const
Returns the length of the line.
Definition: qline.cpp:698
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
qreal length(qreal error=0.01) const
Definition: qbezier.cpp:529
#define Q_D(Class)
Definition: qglobal.h:2482
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
static QBezier fromPoints(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4)
Definition: qbezier.cpp:71
qreal tAtLength(qreal len) const
Definition: qbezier.cpp:654
qreal length() const
Returns the length of the current path.

◆ pointAtPercent()

QPointF QPainterPath::pointAtPercent ( qreal  t) const

Returns the point at at the percentage t of the current path.

The argument t has to be between 0 and 1.

Note that similarly to other percent methods, the percentage measurement is not linear with regards to the length, if curves are present in the path. When curves are present the percentage argument is mapped to the t parameter of the Bezier equations.

Definition at line 3090 of file qpainterpath.cpp.

3091 {
3092  if (t < 0 || t > 1) {
3093  qWarning("QPainterPath::pointAtPercent accepts only values between 0 and 1");
3094  return QPointF();
3095  }
3096 
3097  if (!d_ptr || d_ptr->elements.size() == 0)
3098  return QPointF();
3099 
3100  if (d_ptr->elements.size() == 1)
3101  return d_ptr->elements.at(0);
3102 
3103  qreal totalLength = length();
3104  qreal curLen = 0;
3105  qreal bezierLen = 0;
3106  QBezier b = bezierAtT(*this, t, &curLen, &bezierLen);
3107  qreal realT = (totalLength * t - curLen) / bezierLen;
3108 
3109  return b.pointAt(qBound(qreal(0), realT, qreal(1)));
3110 }
double qreal
Definition: qglobal.h:1193
static QBezier bezierAtT(const QPainterPath &path, qreal t, qreal *startingLength, qreal *bezierLength)
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QPointF pointAt(qreal t) const
Definition: qbezier_p.h:163
Q_CORE_EXPORT void qWarning(const char *,...)
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
qreal length() const
Returns the length of the current path.
QVector< QPainterPath::Element > elements
Definition: qpainterpath.h:254
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QScopedPointer< QPainterPathPrivate, QPainterPathPrivateDeleter > d_ptr
Definition: qpainterpath.h:211

◆ quadTo() [1/2]

void QPainterPath::quadTo ( const QPointF c,
const QPointF endPoint 
)

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.

See also
cubicTo(), {QPainterPath::Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 884 of file qpainterpath.cpp.

Referenced by addGlyphToPath(), QDeclarativePathQuad::addToPath(), generateWavyPixmap(), and parsePathDataFast().

885 {
886 #ifdef QPP_DEBUG
887  printf("QPainterPath::quadTo() (%.2f,%.2f), (%.2f,%.2f)\n",
888  c.x(), c.y(), e.x(), e.y());
889 #endif
890 
891  if (!qt_is_finite(c.x()) || !qt_is_finite(c.y()) || !qt_is_finite(e.x()) || !qt_is_finite(e.y())) {
892 #ifndef QT_NO_DEBUG
893  qWarning("QPainterPath::quadTo: Adding point where x or y is NaN or Inf, ignoring call");
894 #endif
895  return;
896  }
897 
898  ensureData();
899  detach();
900 
901  Q_D(QPainterPath);
902  Q_ASSERT(!d->elements.isEmpty());
903  const QPainterPath::Element &elm = d->elements.at(elementCount()-1);
904  QPointF prev(elm.x, elm.y);
905 
906  // Abort on empty curve as a stroker cannot handle this and the
907  // curve is irrelevant anyway.
908  if (prev == c && c == e)
909  return;
910 
911  QPointF c1((prev.x() + 2*c.x()) / 3, (prev.y() + 2*c.y()) / 3);
912  QPointF c2((e.x() + 2*c.x()) / 3, (e.y() + 2*c.y()) / 3);
913  cubicTo(c1, c2, e);
914 }
double d
Definition: qnumeric_p.h:62
The QPainterPath::Element class specifies the position and type of a subpath.
Definition: qpainterpath.h:77
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
void ensureData()
Definition: qpainterpath.h:213
Q_CORE_EXPORT void qWarning(const char *,...)
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
void cubicTo(const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt)
Adds a cubic Bezier curve between the current position and the given endPoint using the control point...
int elementCount() const
Returns the number of path elements in the painter path.
Definition: qpainterpath.h:397
static bool qt_is_finite(double d)
Definition: qnumeric_p.h:197

◆ quadTo() [2/2]

void QPainterPath::quadTo ( qreal  cx,
qreal  cy,
qreal  endPointX,
qreal  endPointY 
)
inline

Adds a quadratic Bezier curve between the current point and the endpoint ({endPointX}, {endPointY}) with the control point specified by ({cx}, {cy}).

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 330 of file qpainterpath.h.

331 {
332  quadTo(QPointF(ctrlPtx, ctrlPty), QPointF(endPtx, endPty));
333 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void quadTo(const QPointF &ctrlPt, const QPointF &endPt)
Adds a quadratic Bezier curve between the current position and the given endPoint with the control po...

◆ setDirty()

void QPainterPath::setDirty ( bool  dirty)
private

Definition at line 3539 of file qpainterpath.cpp.

3540 {
3541  d_func()->dirtyBounds = dirty;
3542  d_func()->dirtyControlBounds = dirty;
3543  delete d_func()->pathConverter;
3544  d_func()->pathConverter = 0;
3545  d_func()->convex = false;
3546 }
QVectorPathConverter * pathConverter
QPainterPathData * d_func() const
Definition: qpainterpath.h:221

◆ setElementPositionAt()

void QPainterPath::setElementPositionAt ( int  index,
qreal  x,
qreal  y 
)
inline

Sets the x and y coordinate of the element at index index to x and y.

Since
4.2

Definition at line 409 of file qpainterpath.h.

Referenced by addLineTo().

410 {
411  Q_ASSERT(d_ptr);
412  Q_ASSERT(i >= 0 && i < elementCount());
413  detach();
415  e.x = x;
416  e.y = y;
417 }
The QPainterPath::Element class specifies the position and type of a subpath.
Definition: qpainterpath.h:77
qreal y
the y coordinate of the element&#39;s position.
Definition: qpainterpath.h:80
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QVector< QPainterPath::Element > elements
Definition: qpainterpath.h:254
qreal x
the x coordinate of the element&#39;s position.
Definition: qpainterpath.h:79
int elementCount() const
Returns the number of path elements in the painter path.
Definition: qpainterpath.h:397
QScopedPointer< QPainterPathPrivate, QPainterPathPrivateDeleter > d_ptr
Definition: qpainterpath.h:211

◆ setFillRule()

void QPainterPath::setFillRule ( Qt::FillRule  fillRule)

◆ simplified()

QPainterPath QPainterPath::simplified ( ) const

Returns a simplified version of this path.

Since
4.4

This implies merging all subpaths that intersect, and returning a path containing no intersecting edges. Consecutive parallel lines will also be merged. The simplified path will always use the default fill rule, Qt::OddEvenFill. Bezier curves may be flattened to line segments due to numerical instability of doing bezier curve intersections.

Definition at line 3482 of file qpainterpath.cpp.

Referenced by QPathClipper::clip().

3483 {
3484  if(isEmpty())
3485  return *this;
3486  QPathClipper clipper(*this, QPainterPath());
3487  return clipper.clip(QPathClipper::Simplify);
3488 }
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392
QPainterPath()
Constructs an empty QPainterPath object.

◆ slopeAtPercent()

qreal QPainterPath::slopeAtPercent ( qreal  t) const

Returns the slope of the path at the percentage t.

The argument t has to be between 0 and 1.

Note that similarly to other percent methods, the percentage measurement is not linear with regards to the length, if curves are present in the path. When curves are present the percentage argument is mapped to the t parameter of the Bezier equations.

Definition at line 3156 of file qpainterpath.cpp.

3157 {
3158  if (t < 0 || t > 1) {
3159  qWarning("QPainterPath::slopeAtPercent accepts only values between 0 and 1");
3160  return 0;
3161  }
3162 
3163  qreal totalLength = length();
3164  qreal curLen = 0;
3165  qreal bezierLen = 0;
3166  QBezier bez = bezierAtT(*this, t, &curLen, &bezierLen);
3167  qreal realT = (totalLength * t - curLen) / bezierLen;
3168 
3169  qreal m1 = slopeAt(realT, bez.x1, bez.x2, bez.x3, bez.x4);
3170  qreal m2 = slopeAt(realT, bez.y1, bez.y2, bez.y3, bez.y4);
3171  //tangent line
3172  qreal slope = 0;
3173 
3174 #define SIGN(x) ((x < 0)?-1:1)
3175  if (m1)
3176  slope = m2/m1;
3177  else {
3178  //windows doesn't define INFINITY :(
3179 #ifdef INFINITY
3180  slope = INFINITY*SIGN(m2);
3181 #else
3182  if (sizeof(qreal) == sizeof(double)) {
3183  return 1.79769313486231570e+308;
3184  } else {
3185  return ((qreal)3.40282346638528860e+38);
3186  }
3187 #endif
3188  }
3189 
3190  return slope;
3191 }
double qreal
Definition: qglobal.h:1193
static QBezier bezierAtT(const QPainterPath &path, qreal t, qreal *startingLength, qreal *bezierLength)
static qreal slopeAt(qreal t, qreal a, qreal b, qreal c, qreal d)
qreal x2
Definition: qbezier_p.h:116
qreal y2
Definition: qbezier_p.h:116
qreal x4
Definition: qbezier_p.h:116
Q_CORE_EXPORT void qWarning(const char *,...)
qreal y4
Definition: qbezier_p.h:116
qreal length() const
Returns the length of the current path.
qreal x3
Definition: qbezier_p.h:116
qreal x1
Definition: qbezier_p.h:116
qreal y1
Definition: qbezier_p.h:116
qreal y3
Definition: qbezier_p.h:116
#define SIGN(x)

◆ subtracted()

QPainterPath QPainterPath::subtracted ( const QPainterPath p) const

Returns a path which is p's fill area subtracted from this path's fill area.

Since
4.3

Set operations on paths will treat the paths as areas. Non-closed paths will be treated as implicitly closed. Bezier curves may be flattened to line segments due to numerical instability of doing bezier curve intersections.

Definition at line 3446 of file qpainterpath.cpp.

Referenced by QGraphicsTextItemPrivate::_q_mouseOnEdge(), operator-(), QPolygon::subtracted(), QPolygonF::subtracted(), subtractedInverted(), and QPdfBaseEngine::updateClipPath().

3447 {
3448  if (isEmpty() || p.isEmpty())
3449  return *this;
3450  QPathClipper clipper(*this, p);
3451  return clipper.clip(QPathClipper::BoolSub);
3452 }
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392

◆ subtractedInverted()

QPainterPath QPainterPath::subtractedInverted ( const QPainterPath p) const

Use subtracted() instead.

Since
4.3
See also
subtracted()

Definition at line 3465 of file qpainterpath.cpp.

3466 {
3467  return p.subtracted(*this);
3468 }
QPainterPath subtracted(const QPainterPath &r) const
Returns a path which is p&#39;s fill area subtracted from this path&#39;s fill area.

◆ swap()

void QPainterPath::swap ( QPainterPath other)
inline

Swaps painter path other with this painter path.

Since
4.8

This operation is very fast and never fails.

Definition at line 103 of file qpainterpath.h.

103 { d_ptr.swap(other.d_ptr); }
void swap(QScopedPointer< T, Cleanup > &other)
Swap this pointer with other.
QScopedPointer< QPainterPathPrivate, QPainterPathPrivateDeleter > d_ptr
Definition: qpainterpath.h:211

◆ toFillPolygon() [1/2]

QPolygonF QPainterPath::toFillPolygon ( const QMatrix matrix = QMatrix()) const

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 2915 of file qpainterpath.cpp.

Referenced by QOpenGLPaintEngine::clip(), clipTransformIsSimple(), QGLPathMaskGenerator::computeScreenRect(), QPaintEngine::drawEllipse(), QOpenGLPaintEnginePrivate::fillPath(), QPolygon::intersected(), QPolygonF::intersected(), QMatrix::map(), QTransform::map(), QmlJSDebugger::regionToPolygon(), QPolygon::subtracted(), QPolygonF::subtracted(), QX11PaintEnginePrivate::systemStateChanged(), QPolygon::united(), QPolygonF::united(), QCoreGraphicsPaintEngine::updateClipPath(), QX11PaintEngine::updateState(), and QOpenGLPaintEngine::updateState().

2916 {
2917  return toFillPolygon(QTransform(matrix));
2918 }
QPolygonF toFillPolygon(const QMatrix &matrix=QMatrix()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend class QTransform
Definition: qpainterpath.h:227

◆ toFillPolygon() [2/2]

QPolygonF QPainterPath::toFillPolygon ( const QTransform matrix) const

Converts the path into a polygon using the QTransform 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.

See also
toSubpathPolygons(), toFillPolygons(), {QPainterPath::QPainterPath Conversion}{QPainterPath Conversion}

Definition at line 2894 of file qpainterpath.cpp.

2895 {
2896 
2897  QList<QPolygonF> flats = toSubpathPolygons(matrix);
2898  QPolygonF polygon;
2899  if (flats.isEmpty())
2900  return polygon;
2901  QPointF first = flats.first().first();
2902  for (int i=0; i<flats.size(); ++i) {
2903  polygon += flats.at(i);
2904  if (!flats.at(i).isClosed())
2905  polygon += flats.at(i).first();
2906  if (i > 0)
2907  polygon += first;
2908  }
2909  return polygon;
2910 }
T & first()
Returns a reference to the first item in the vector.
Definition: qvector.h:260
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QPolygonF class provides a vector of points using floating point precision.
Definition: qpolygon.h:134
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QList< QPolygonF > toSubpathPolygons(const QMatrix &matrix=QMatrix()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isClosed() const
Returns true if the polygon is closed; otherwise returns false.
Definition: qpolygon.h:154
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ toFillPolygons() [1/2]

QList< QPolygonF > QPainterPath::toFillPolygons ( const QMatrix matrix = QMatrix()) const

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 1808 of file qpainterpath.cpp.

Referenced by QX11PaintEnginePrivate::fillPath().

1809 {
1810  return toFillPolygons(QTransform(matrix));
1811 }
QList< QPolygonF > toFillPolygons(const QMatrix &matrix=QMatrix()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend class QTransform
Definition: qpainterpath.h:227

◆ toFillPolygons() [2/2]

QList< QPolygonF > QPainterPath::toFillPolygons ( const QTransform matrix) const

Converts the path into a list of polygons using the QTransform 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.

See also
toSubpathPolygons(), toFillPolygon(), {QPainterPath::QPainterPath Conversion}{QPainterPath Conversion}

Definition at line 1710 of file qpainterpath.cpp.

1711 {
1712 
1713  QList<QPolygonF> polys;
1714 
1715  QList<QPolygonF> subpaths = toSubpathPolygons(matrix);
1716  int count = subpaths.size();
1717 
1718  if (count == 0)
1719  return polys;
1720 
1721  QList<QRectF> bounds;
1722  for (int i=0; i<count; ++i)
1723  bounds += subpaths.at(i).boundingRect();
1724 
1725 #ifdef QPP_FILLPOLYGONS_DEBUG
1726  printf("QPainterPath::toFillPolygons, subpathCount=%d\n", count);
1727  for (int i=0; i<bounds.size(); ++i)
1728  qDebug() << " bounds" << i << bounds.at(i);
1729 #endif
1730 
1731  QVector< QList<int> > isects;
1732  isects.resize(count);
1733 
1734  // find all intersections
1735  for (int j=0; j<count; ++j) {
1736  if (subpaths.at(j).size() <= 2)
1737  continue;
1738  QRectF cbounds = bounds.at(j);
1739  for (int i=0; i<count; ++i) {
1740  if (cbounds.intersects(bounds.at(i))) {
1741  isects[j] << i;
1742  }
1743  }
1744  }
1745 
1746 #ifdef QPP_FILLPOLYGONS_DEBUG
1747  printf("Intersections before flattening:\n");
1748  for (int i = 0; i < count; ++i) {
1749  printf("%d: ", i);
1750  for (int j = 0; j < isects[i].size(); ++j) {
1751  printf("%d ", isects[i][j]);
1752  }
1753  printf("\n");
1754  }
1755 #endif
1756 
1757  // flatten the sets of intersections
1758  for (int i=0; i<count; ++i) {
1759  const QList<int> &current_isects = isects.at(i);
1760  for (int j=0; j<current_isects.size(); ++j) {
1761  int isect_j = current_isects.at(j);
1762  if (isect_j == i)
1763  continue;
1764  for (int k=0; k<isects[isect_j].size(); ++k) {
1765  int isect_k = isects[isect_j][k];
1766  if (isect_k != i && !isects.at(i).contains(isect_k)) {
1767  isects[i] += isect_k;
1768  }
1769  }
1770  isects[isect_j].clear();
1771  }
1772  }
1773 
1774 #ifdef QPP_FILLPOLYGONS_DEBUG
1775  printf("Intersections after flattening:\n");
1776  for (int i = 0; i < count; ++i) {
1777  printf("%d: ", i);
1778  for (int j = 0; j < isects[i].size(); ++j) {
1779  printf("%d ", isects[i][j]);
1780  }
1781  printf("\n");
1782  }
1783 #endif
1784 
1785  // Join the intersected subpaths as rewinded polygons
1786  for (int i=0; i<count; ++i) {
1787  const QList<int> &subpath_list = isects[i];
1788  if (!subpath_list.isEmpty()) {
1789  QPolygonF buildUp;
1790  for (int j=0; j<subpath_list.size(); ++j) {
1791  const QPolygonF &subpath = subpaths.at(subpath_list.at(j));
1792  buildUp += subpath;
1793  if (!subpath.isClosed())
1794  buildUp += subpath.first();
1795  if (!buildUp.isClosed())
1796  buildUp += buildUp.first();
1797  }
1798  polys += buildUp;
1799  }
1800  }
1801 
1802  return polys;
1803 }
T & first()
Returns a reference to the first item in the vector.
Definition: qvector.h:260
bool intersects(const QRectF &r) const
Returns true if this rectangle intersects with the given rectangle (i.
Definition: qrect.cpp:2744
QRectF boundingRect() const
Returns the bounding rectangle of the polygon, or QRectF(0,0,0,0) if the polygon is empty...
Definition: qpolygon.cpp:742
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
Q_CORE_EXPORT void qDebug(const char *,...)
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QPolygonF class provides a vector of points using floating point precision.
Definition: qpolygon.h:134
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QList< QPolygonF > toSubpathPolygons(const QMatrix &matrix=QMatrix()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isClosed() const
Returns true if the polygon is closed; otherwise returns false.
Definition: qpolygon.h:154
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ toReversed()

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 1581 of file qpainterpath.cpp.

1582 {
1583  Q_D(const QPainterPath);
1584  QPainterPath rev;
1585 
1586  if (isEmpty()) {
1587  rev = *this;
1588  return rev;
1589  }
1590 
1591  rev.moveTo(d->elements.at(d->elements.size()-1).x, d->elements.at(d->elements.size()-1).y);
1592 
1593  for (int i=d->elements.size()-1; i>=1; --i) {
1594  const QPainterPath::Element &elm = d->elements.at(i);
1595  const QPainterPath::Element &prev = d->elements.at(i-1);
1596  switch (elm.type) {
1597  case LineToElement:
1598  rev.lineTo(prev.x, prev.y);
1599  break;
1600  case MoveToElement:
1601  rev.moveTo(prev.x, prev.y);
1602  break;
1603  case CurveToDataElement:
1604  {
1605  Q_ASSERT(i>=3);
1606  const QPainterPath::Element &cp1 = d->elements.at(i-2);
1607  const QPainterPath::Element &sp = d->elements.at(i-3);
1608  Q_ASSERT(prev.type == CurveToDataElement);
1609  Q_ASSERT(cp1.type == CurveToElement);
1610  rev.cubicTo(prev.x, prev.y, cp1.x, cp1.y, sp.x, sp.y);
1611  i -= 2;
1612  break;
1613  }
1614  default:
1615  Q_ASSERT(!"qt_reversed_path");
1616  break;
1617  }
1618  }
1619  //qt_debug_path(rev);
1620  return rev;
1621 }
ElementType type
the type of element
Definition: qpainterpath.h:81
double d
Definition: qnumeric_p.h:62
The QPainterPath::Element class specifies the position and type of a subpath.
Definition: qpainterpath.h:77
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
qreal y
the y coordinate of the element&#39;s position.
Definition: qpainterpath.h:80
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
void moveTo(const QPointF &p)
Moves the current point to the given point, implicitly starting a new subpath and closing the previou...
void lineTo(const QPointF &p)
Adds a straight line from the current position to the given endPoint.
qreal x
the x coordinate of the element&#39;s position.
Definition: qpainterpath.h:79
void cubicTo(const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt)
Adds a cubic Bezier curve between the current position and the given endPoint using the control point...

◆ toSubpathPolygons() [1/2]

QList< QPolygonF > QPainterPath::toSubpathPolygons ( const QMatrix matrix = QMatrix()) const

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 1683 of file qpainterpath.cpp.

Referenced by QX11PaintEngine::drawPath(), QRegion::QRegion(), qt_bitmapToRegion(), and toFillPolygons().

1684 {
1685  return toSubpathPolygons(QTransform(matrix));
1686 }
friend class QTransform
Definition: qpainterpath.h:227
QList< QPolygonF > toSubpathPolygons(const QMatrix &matrix=QMatrix()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...

◆ toSubpathPolygons() [2/2]

QList< QPolygonF > QPainterPath::toSubpathPolygons ( const QTransform matrix) const

Converts the path into a list of polygons using the QTransform 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.

See also
toFillPolygons(), toFillPolygon(), {QPainterPath::QPainterPath Conversion}{QPainterPath Conversion}

Definition at line 1635 of file qpainterpath.cpp.

1636 {
1637 
1638  Q_D(const QPainterPath);
1639  QList<QPolygonF> flatCurves;
1640  if (isEmpty())
1641  return flatCurves;
1642 
1643  QPolygonF current;
1644  for (int i=0; i<elementCount(); ++i) {
1645  const QPainterPath::Element &e = d->elements.at(i);
1646  switch (e.type) {
1648  if (current.size() > 1)
1649  flatCurves += current;
1650  current.clear();
1651  current.reserve(16);
1652  current += QPointF(e.x, e.y) * matrix;
1653  break;
1655  current += QPointF(e.x, e.y) * matrix;
1656  break;
1658  Q_ASSERT(d->elements.at(i+1).type == QPainterPath::CurveToDataElement);
1659  Q_ASSERT(d->elements.at(i+2).type == QPainterPath::CurveToDataElement);
1660  QBezier bezier = QBezier::fromPoints(QPointF(d->elements.at(i-1).x, d->elements.at(i-1).y) * matrix,
1661  QPointF(e.x, e.y) * matrix,
1662  QPointF(d->elements.at(i+1).x, d->elements.at(i+1).y) * matrix,
1663  QPointF(d->elements.at(i+2).x, d->elements.at(i+2).y) * matrix);
1664  bezier.addToPolygon(&current);
1665  i+=2;
1666  break;
1667  }
1669  Q_ASSERT(!"QPainterPath::toSubpathPolygons(), bad element type");
1670  break;
1671  }
1672  }
1673 
1674  if (current.size()>1)
1675  flatCurves += current;
1676 
1677  return flatCurves;
1678 }
ElementType type
the type of element
Definition: qpainterpath.h:81
double d
Definition: qnumeric_p.h:62
The QPainterPath::Element class specifies the position and type of a subpath.
Definition: qpainterpath.h:77
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal y
the y coordinate of the element&#39;s position.
Definition: qpainterpath.h:80
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
static QBezier fromPoints(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4)
Definition: qbezier.cpp:71
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
The QPolygonF class provides a vector of points using floating point precision.
Definition: qpolygon.h:134
qreal x
the x coordinate of the element&#39;s position.
Definition: qpainterpath.h:79
int elementCount() const
Returns the number of path elements in the painter path.
Definition: qpainterpath.h:397
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ translate() [1/2]

void QPainterPath::translate ( qreal  dx,
qreal  dy 
)

Translates all elements in the path by ({dx}, {dy}).

Since
4.6
See also
translated()

Definition at line 2177 of file qpainterpath.cpp.

Referenced by QGraphicsView::fitInView(), QGraphicsSceneIndexRectIntersector::intersect(), QTransform::map(), and translated().

2178 {
2179  if (!d_ptr || (dx == 0 && dy == 0))
2180  return;
2181 
2182  int elementsLeft = d_ptr->elements.size();
2183  if (elementsLeft <= 0)
2184  return;
2185 
2186  detach();
2187  QPainterPath::Element *element = d_func()->elements.data();
2188  Q_ASSERT(element);
2189  while (elementsLeft--) {
2190  element->x += dx;
2191  element->y += dy;
2192  ++element;
2193  }
2194 }
The QPainterPath::Element class specifies the position and type of a subpath.
Definition: qpainterpath.h:77
qreal y
the y coordinate of the element&#39;s position.
Definition: qpainterpath.h:80
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
QVector< QPainterPath::Element > elements
Definition: qpainterpath.h:254
qreal x
the x coordinate of the element&#39;s position.
Definition: qpainterpath.h:79
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QScopedPointer< QPainterPathPrivate, QPainterPathPrivateDeleter > d_ptr
Definition: qpainterpath.h:211

◆ translate() [2/2]

void QPainterPath::translate ( const QPointF offset)
inline

Translates all elements in the path by the given offset.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.6
See also
translated()

Definition at line 386 of file qpainterpath.h.

387 { translate(offset.x(), offset.y()); }
void translate(qreal dx, qreal dy)
Translates all elements in the path by ({dx}, {dy}).
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ translated() [1/2]

QPainterPath QPainterPath::translated ( qreal  dx,
qreal  dy 
) const

Returns a copy of the path that is translated by ({dx}, {dy}).

Since
4.6
See also
translate()

Definition at line 2215 of file qpainterpath.cpp.

Referenced by QGraphicsItem::mapFromParent(), QGraphicsItem::mapFromScene(), QGraphicsItem::mapToParent(), QGraphicsItem::mapToScene(), and QGraphicsSceneIndexPrivate::recursive_items_helper().

2216 {
2217  QPainterPath copy(*this);
2218  copy.translate(dx, dy);
2219  return copy;
2220 }
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67

◆ translated() [2/2]

QPainterPath QPainterPath::translated ( const QPointF offset) const
inline

Returns a copy of the path that is translated by the given offset.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.6
See also
translate()

Definition at line 389 of file qpainterpath.h.

390 { return translated(offset.x(), offset.y()); }
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
QPainterPath translated(qreal dx, qreal dy) const
Returns a copy of the path that is translated by ({dx}, {dy}).

◆ united()

QPainterPath QPainterPath::united ( const QPainterPath p) const

Returns a path which is the union of this path's fill area and p's fill area.

Since
4.3

Set operations on paths will treat the paths as areas. Non-closed paths will be treated as implicitly closed. Bezier curves may be flattened to line segments due to numerical instability of doing bezier curve intersections.

See also
intersected(), subtracted()

Definition at line 3407 of file qpainterpath.cpp.

Referenced by operator+(), operator|(), QPolygon::united(), and QPolygonF::united().

3408 {
3409  if (isEmpty() || p.isEmpty())
3410  return isEmpty() ? p : *this;
3411  QPathClipper clipper(*this, p);
3412  return clipper.clip(QPathClipper::BoolOr);
3413 }
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392

Friends and Related Functions

◆ operator<<

QDataStream & operator<< ( QDataStream stream,
const QPainterPath path 
)
friend

Writes the given painter path to the given stream, and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 2509 of file qpainterpath.cpp.

2510 {
2511  if (p.isEmpty()) {
2512  s << 0;
2513  return s;
2514  }
2515 
2516  s << p.elementCount();
2517  for (int i=0; i < p.d_func()->elements.size(); ++i) {
2518  const QPainterPath::Element &e = p.d_func()->elements.at(i);
2519  s << int(e.type);
2520  s << double(e.x) << double(e.y);
2521  }
2522  s << p.d_func()->cStart;
2523  s << int(p.d_func()->fillRule);
2524  return s;
2525 }
ElementType type
the type of element
Definition: qpainterpath.h:81
The QPainterPath::Element class specifies the position and type of a subpath.
Definition: qpainterpath.h:77
qreal y
the y coordinate of the element&#39;s position.
Definition: qpainterpath.h:80
qreal x
the x coordinate of the element&#39;s position.
Definition: qpainterpath.h:79

◆ operator>>

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.

See also
{Serializing Qt Data Types}

Definition at line 2539 of file qpainterpath.cpp.

2540 {
2541  int size;
2542  s >> size;
2543 
2544  if (size == 0)
2545  return s;
2546 
2547  p.ensureData(); // in case if p.d_func() == 0
2548  if (p.d_func()->elements.size() == 1) {
2549  Q_ASSERT(p.d_func()->elements.at(0).type == QPainterPath::MoveToElement);
2550  p.d_func()->elements.clear();
2551  }
2552  p.d_func()->elements.reserve(p.d_func()->elements.size() + size);
2553  for (int i=0; i<size; ++i) {
2554  int type;
2555  double x, y;
2556  s >> type;
2557  s >> x;
2558  s >> y;
2559  Q_ASSERT(type >= 0 && type <= 3);
2560  if (!qt_is_finite(x) || !qt_is_finite(y)) {
2561 #ifndef QT_NO_DEBUG
2562  qWarning("QDataStream::operator>>: NaN or Inf element found in path, skipping it");
2563 #endif
2564  continue;
2565  }
2567  p.d_func()->elements.append(elm);
2568  }
2569  s >> p.d_func()->cStart;
2570  int fillRule;
2571  s >> fillRule;
2572  Q_ASSERT(fillRule == Qt::OddEvenFill || Qt::WindingFill);
2573  p.d_func()->fillRule = Qt::FillRule(fillRule);
2574  p.d_func()->dirtyBounds = true;
2575  p.d_func()->dirtyControlBounds = true;
2576  return s;
2577 }
The QPainterPath::Element class specifies the position and type of a subpath.
Definition: qpainterpath.h:77
ElementType
This enum describes the types of elements used to connect vertices in subpaths.
Definition: qpainterpath.h:70
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
FillRule
Definition: qnamespace.h:1485
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Q_CORE_EXPORT void qWarning(const char *,...)
Qt::FillRule fillRule() const
Returns the painter path&#39;s currently set fill rule.
static bool qt_is_finite(double d)
Definition: qnumeric_p.h:197

◆ QMatrix

friend class QMatrix
friend

Definition at line 226 of file qpainterpath.h.

◆ QPainterPathData

friend class QPainterPathData
friend

Definition at line 223 of file qpainterpath.h.

Referenced by detach_helper(), and ensureData_helper().

◆ QPainterPathStroker

friend class QPainterPathStroker
friend

Definition at line 224 of file qpainterpath.h.

◆ QPainterPathStrokerPrivate

Definition at line 225 of file qpainterpath.h.

◆ QTransform

friend class QTransform
friend

Definition at line 227 of file qpainterpath.h.

Referenced by toFillPolygons(), and toSubpathPolygons().

◆ qtVectorPathForPath

Q_GUI_EXPORT const QVectorPath& qtVectorPathForPath ( const QPainterPath )
friend

Definition at line 129 of file qpaintengineex.cpp.

130 {
131  Q_ASSERT(path.d_func());
132  return path.d_func()->vectorPath();
133 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QPainterPathData * d_func() const
Definition: qpainterpath.h:221
const QVectorPath & vectorPath()

◆ QVectorPath

friend class QVectorPath
friend

Definition at line 228 of file qpainterpath.h.

Properties

◆ d_ptr


The documentation for this class was generated from the following files: