Qt 4.8
Public Functions | Properties | Friends | List of all members
QPainterPathStroker Class Reference

The QPainterPathStroker class is used to generate fillable outlines for a given painter path. More...

#include <qpainterpath.h>

Public Functions

Qt::PenCapStyle capStyle () const
 Returns the cap style of the generated outlines. More...
 
QPainterPath createStroke (const QPainterPath &path) const
 Generates a new path that is a fillable area representing the outline of the given path. More...
 
qreal curveThreshold () const
 Returns the curve flattening threshold for the generated outlines. More...
 
qreal dashOffset () const
 Returns the dash offset for the generated outlines. More...
 
QVector< qrealdashPattern () const
 Returns the dash pattern for the generated outlines. More...
 
Qt::PenJoinStyle joinStyle () const
 Returns the join style of the generated outlines. More...
 
qreal miterLimit () const
 Returns the miter limit for the generated outlines. More...
 
 QPainterPathStroker ()
 Creates a new stroker. More...
 
void setCapStyle (Qt::PenCapStyle style)
 Sets the cap style of the generated outlines to style. More...
 
void setCurveThreshold (qreal threshold)
 Specifies the curve flattening threshold, controlling the granularity with which the generated outlines' curve is drawn. More...
 
void setDashOffset (qreal offset)
 Sets the dash offset for the generated outlines to offset. More...
 
void setDashPattern (Qt::PenStyle)
 Sets the dash pattern for the generated outlines to style. More...
 
void setDashPattern (const QVector< qreal > &dashPattern)
 Sets the dash pattern for the generated outlines to dashPattern. More...
 
void setJoinStyle (Qt::PenJoinStyle style)
 Sets the join style of the generated outlines to style. More...
 
void setMiterLimit (qreal length)
 Sets the miter limit of the generated outlines to limit. More...
 
void setWidth (qreal width)
 Sets the width of the generated outline painter path to width. More...
 
qreal width () const
 Returns the width of the generated outlines. More...
 
 ~QPainterPathStroker ()
 Destroys the stroker. More...
 

Properties

QScopedPointer< QPainterPathStrokerPrivated_ptr
 

Friends

class QX11PaintEngine
 

Detailed Description

The QPainterPathStroker class is used to generate fillable outlines for a given painter path.

Since
4.1

By calling the createStroke() function, passing a given QPainterPath as argument, a new painter path representing the outline of the given path is created. The newly created painter path can then be filled to draw the original painter path's outline.

You can control the various design aspects (width, cap styles, join styles and dash pattern) of the outlining using the following functions:

The setDashPattern() function accepts both a Qt::PenStyle object and a vector representation of the pattern as argument.

In addition you can specify a curve's threshold, controlling the granularity with which a curve is drawn, using the setCurveThreshold() function. The default threshold is a well adjusted value (0.25), and normally you should not need to modify it. However, you can make the curve's appearance smoother by decreasing its value.

You can also control the miter limit for the generated outline using the setMiterLimit() function. The miter limit describes how far from each join the miter join can extend. The limit is specified in the units of width so the pixelwise miter limit will be {miterlimit * width}. This value is only used if the join style is Qt::MiterJoin.

The painter path generated by the createStroke() function should only be used for outlining the given painter path. Otherwise it may cause unexpected behavior. Generated outlines also require the Qt::WindingFill rule which is set by default.

See also
QPen, QBrush

Definition at line 264 of file qpainterpath.h.

Constructors and Destructors

◆ QPainterPathStroker()

QPainterPathStroker::QPainterPathStroker ( )

Creates a new stroker.

Definition at line 2669 of file qpainterpath.cpp.

2671 {
2672 }
QScopedPointer< QPainterPathStrokerPrivate > d_ptr
Definition: qpainterpath.h:300

◆ ~QPainterPathStroker()

QPainterPathStroker::~QPainterPathStroker ( )

Destroys the stroker.

Definition at line 2677 of file qpainterpath.cpp.

2678 {
2679 }

Functions

◆ capStyle()

Qt::PenCapStyle QPainterPathStroker::capStyle ( ) const

Returns the cap style of the generated outlines.

Definition at line 2751 of file qpainterpath.cpp.

2752 {
2753  return d_func()->stroker.capStyle();
2754 }

◆ createStroke()

QPainterPath QPainterPathStroker::createStroke ( const QPainterPath path) const

Generates a new path that is a fillable area representing the outline of the given path.

The various design aspects of the outline are based on the stroker's properties: width(), capStyle(), joinStyle(), dashPattern(), curveThreshold() and miterLimit().

The generated path should only be used for outlining the given painter path. Otherwise it may cause unexpected behavior. Generated outlines also require the Qt::WindingFill rule which is set by default.

Definition at line 2695 of file qpainterpath.cpp.

Referenced by QAlphaPaintEnginePrivate::addPenWidth(), boundsOnStroke(), QPainterPrivate::draw_helper(), QX11PaintEngine::drawPath(), QMacStyle::drawPrimitive(), QPainterPrivate::drawStretchedGradient(), qt_graphicsItem_shapeFromPath(), strokeForPath(), and QWin32PrintEnginePrivate::strokePath().

2696 {
2697  QPainterPathStrokerPrivate *d = const_cast<QPainterPathStrokerPrivate *>(d_func());
2698  QPainterPath stroke;
2699  if (path.isEmpty())
2700  return path;
2701  if (d->dashPattern.isEmpty()) {
2702  d->stroker.strokePath(path, &stroke, QTransform());
2703  } else {
2704  QDashStroker dashStroker(&d->stroker);
2705  dashStroker.setDashPattern(d->dashPattern);
2706  dashStroker.setDashOffset(d->dashOffset);
2707  dashStroker.setClipRect(d->stroker.clipRect());
2708  dashStroker.strokePath(path, &stroke, QTransform());
2709  }
2710  stroke.setFillRule(Qt::WindingFill);
2711  return stroke;
2712 }
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
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
void setFillRule(Qt::FillRule fillRule)
Sets the fill rule of the painter path to the given fillRule.
QVector< qfixed > dashPattern
void strokePath(const QPainterPath &path, void *data, const QTransform &matrix)
Convenience function that decomposes path into begin(), moveTo(), lineTo(), curevTo() and end() calls...
Definition: qstroker.cpp:242
QRectF clipRect() const
Definition: qstroker_p.h:164
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ curveThreshold()

qreal QPainterPathStroker::curveThreshold ( ) const

Returns the curve flattening threshold for the generated outlines.

Definition at line 2813 of file qpainterpath.cpp.

2814 {
2815  return qt_fixed_to_real(d_func()->stroker.curveThreshold());
2816 }
#define qt_fixed_to_real(fixed)
Definition: qstroker_p.h:102

◆ dashOffset()

qreal QPainterPathStroker::dashOffset ( ) const

Returns the dash offset for the generated outlines.

Definition at line 2863 of file qpainterpath.cpp.

2864 {
2865  return d_func()->dashOffset;
2866 }

◆ dashPattern()

QVector< qreal > QPainterPathStroker::dashPattern ( ) const

Returns the dash pattern for the generated outlines.

Definition at line 2855 of file qpainterpath.cpp.

2856 {
2857  return d_func()->dashPattern;
2858 }

◆ joinStyle()

Qt::PenJoinStyle QPainterPathStroker::joinStyle ( ) const

Returns the join style of the generated outlines.

Definition at line 2767 of file qpainterpath.cpp.

2768 {
2769  return d_func()->stroker.joinStyle();
2770 }

◆ miterLimit()

qreal QPainterPathStroker::miterLimit ( ) const

Returns the miter limit for the generated outlines.

Definition at line 2790 of file qpainterpath.cpp.

2791 {
2792  return qt_fixed_to_real(d_func()->stroker.miterLimit());
2793 }
#define qt_fixed_to_real(fixed)
Definition: qstroker_p.h:102

◆ setCapStyle()

void QPainterPathStroker::setCapStyle ( Qt::PenCapStyle  style)

Sets the cap style of the generated outlines to style.

If a dash pattern is set, each segment of the pattern is subject to the cap style.

Definition at line 2742 of file qpainterpath.cpp.

Referenced by QAlphaPaintEnginePrivate::addPenWidth(), QPainterPrivate::draw_helper(), QX11PaintEngine::drawPath(), QMacStyle::drawPrimitive(), QPainterPrivate::drawStretchedGradient(), qt_graphicsItem_shapeFromPath(), strokeForPath(), and QWin32PrintEnginePrivate::strokePath().

2743 {
2744  d_func()->stroker.setCapStyle(style);
2745 }

◆ setCurveThreshold()

void QPainterPathStroker::setCurveThreshold ( qreal  threshold)

Specifies the curve flattening threshold, controlling the granularity with which the generated outlines' curve is drawn.

The default threshold is a well adjusted value (0.25), and normally you should not need to modify it. However, you can make the curve's appearance smoother by decreasing its value.

Definition at line 2804 of file qpainterpath.cpp.

2805 {
2806  d_func()->stroker.setCurveThreshold(qt_real_to_fixed(threshold));
2807 }
#define qt_real_to_fixed(real)
Definition: qstroker_p.h:101

◆ setDashOffset()

void QPainterPathStroker::setDashOffset ( qreal  offset)

Sets the dash offset for the generated outlines to offset.

See the documentation for QPen::setDashOffset() for a description of the dash offset.

Definition at line 2874 of file qpainterpath.cpp.

Referenced by QX11PaintEngine::drawPath(), strokeForPath(), and QWin32PrintEnginePrivate::strokePath().

2875 {
2876  d_func()->dashOffset = offset;
2877 }

◆ setDashPattern() [1/2]

void QPainterPathStroker::setDashPattern ( Qt::PenStyle  style)

Sets the dash pattern for the generated outlines to style.

Definition at line 2821 of file qpainterpath.cpp.

Referenced by QX11PaintEngine::drawPath(), QMacStyle::drawPrimitive(), QPainterPrivate::drawStretchedGradient(), strokeForPath(), and QWin32PrintEnginePrivate::strokePath().

2822 {
2823  d_func()->dashPattern = QDashStroker::patternForStyle(style);
2824 }
static QVector< qfixed > patternForStyle(Qt::PenStyle style)
Definition: qstroker.cpp:1034

◆ setDashPattern() [2/2]

void QPainterPathStroker::setDashPattern ( const QVector< qreal > &  dashPattern)

Sets the dash pattern for the generated outlines to dashPattern.

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

This function makes it possible to specify custom dash patterns.

Each element in the vector contains the lengths of the dashes and spaces in the stroke, beginning with the first dash in the first element, the first space in the second element, and alternating between dashes and spaces for each following pair of elements.

The vector can contain an odd number of elements, in which case the last element will be extended by the length of the first element when the pattern repeats.

Definition at line 2845 of file qpainterpath.cpp.

2846 {
2847  d_func()->dashPattern.clear();
2848  for (int i=0; i<dashPattern.size(); ++i)
2849  d_func()->dashPattern << qt_real_to_fixed(dashPattern.at(i));
2850 }
#define qt_real_to_fixed(real)
Definition: qstroker_p.h:101
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 vector.
Definition: qvector.h:137

◆ setJoinStyle()

void QPainterPathStroker::setJoinStyle ( Qt::PenJoinStyle  style)

Sets the join style of the generated outlines to style.

Definition at line 2759 of file qpainterpath.cpp.

Referenced by QAlphaPaintEnginePrivate::addPenWidth(), QPainterPrivate::draw_helper(), QX11PaintEngine::drawPath(), QPainterPrivate::drawStretchedGradient(), qt_graphicsItem_shapeFromPath(), strokeForPath(), and QWin32PrintEnginePrivate::strokePath().

2760 {
2761  d_func()->stroker.setJoinStyle(style);
2762 }

◆ setMiterLimit()

void QPainterPathStroker::setMiterLimit ( qreal  limit)

Sets the miter limit of the generated outlines to limit.

The miter limit describes how far from each join the miter join can extend. The limit is specified in units of the currently set width. So the pixelwise miter limit will be { miterlimit * width}.

This value is only used if the join style is Qt::MiterJoin.

Definition at line 2782 of file qpainterpath.cpp.

Referenced by QPainterPrivate::drawStretchedGradient(), qt_graphicsItem_shapeFromPath(), strokeForPath(), and QWin32PrintEnginePrivate::strokePath().

2783 {
2784  d_func()->stroker.setMiterLimit(qt_real_to_fixed(limit));
2785 }
#define qt_real_to_fixed(real)
Definition: qstroker_p.h:101

◆ setWidth()

void QPainterPathStroker::setWidth ( qreal  width)

Sets the width of the generated outline painter path to width.

The generated outlines will extend approximately 50% of width to each side of the given input path's original outline.

Definition at line 2720 of file qpainterpath.cpp.

Referenced by QAlphaPaintEnginePrivate::addPenWidth(), boundsOnStroke(), QPainterPrivate::draw_helper(), QX11PaintEngine::drawPath(), QPainterPrivate::drawStretchedGradient(), qt_graphicsItem_shapeFromPath(), strokeForPath(), and QWin32PrintEnginePrivate::strokePath().

2721 {
2723  if (width <= 0)
2724  width = 1;
2725  d->stroker.setStrokeWidth(qt_real_to_fixed(width));
2726 }
double d
Definition: qnumeric_p.h:62
#define qt_real_to_fixed(real)
Definition: qstroker_p.h:101
qreal width() const
Returns the width of the generated outlines.
#define Q_D(Class)
Definition: qglobal.h:2482
The QPainterPathStroker class is used to generate fillable outlines for a given painter path...
Definition: qpainterpath.h:264

◆ width()

qreal QPainterPathStroker::width ( ) const

Returns the width of the generated outlines.

Definition at line 2731 of file qpainterpath.cpp.

2732 {
2733  return qt_fixed_to_real(d_func()->stroker.strokeWidth());
2734 }
#define qt_fixed_to_real(fixed)
Definition: qstroker_p.h:102

Friends and Related Functions

◆ QX11PaintEngine

friend class QX11PaintEngine
friend

Definition at line 298 of file qpainterpath.h.

Properties

◆ d_ptr

QScopedPointer<QPainterPathStrokerPrivate> QPainterPathStroker::d_ptr
private

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