Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeStroke Class Reference

#include <KoShapeStroke.h>

+ Inheritance diagram for KoShapeStroke:

Public Member Functions

Qt::PenCapStyle capStyle () const
 Returns the lines cap style.
 
QColor color () const
 Returns the color.
 
bool compareFillTo (const KoShapeStrokeModel *other) override
 
bool compareStyleTo (const KoShapeStrokeModel *other) override
 
qreal dashOffset () const
 Returns the dash offset.
 
bool hasTransparency () const override
 
bool isVisible () const override
 
Qt::PenJoinStyle joinStyle () const
 Returns the lines join style.
 
 KoShapeStroke ()
 Constructor for a thin line in black.
 
 KoShapeStroke (const KoShapeStroke &other)
 Copy constructor.
 
 KoShapeStroke (qreal lineWidth, const QColor &color=Qt::black)
 
QBrush lineBrush () const
 Returns the strokes brush.
 
QVector< qreal > lineDashes () const
 Returns the line dashes.
 
Qt::PenStyle lineStyle () const
 Returns the line style.
 
qreal lineWidth () const
 Returns the line width.
 
qreal miterLimit () const
 Returns the miter limit.
 
KoShapeStrokeoperator= (const KoShapeStroke &rhs)
 Assignment operator.
 
void paint (const KoShape *shape, QPainter &painter) const override
 
void paintBorder (const KoShape *shape, QPainter &painter, const QPen &pen) const
 
void paintMarkers (const KoShape *shape, QPainter &painter) const override
 paintMarkers Paints the markers if possible.
 
void paintMarkers (const KoShape *shape, QPainter &painter, const QPen &pen) const
 
 Private (KoShapeStroke *_q)
 
QPen resultLinePen () const
 
void setCapStyle (Qt::PenCapStyle style)
 Sets the lines cap style.
 
void setColor (const QColor &color)
 Sets the color.
 
void setDashOffset (qreal dashOffset)
 Sets the dash offset.
 
void setJoinStyle (Qt::PenJoinStyle style)
 Sets the lines join style.
 
void setLineBrush (const QBrush &brush)
 Sets the strokes brush used to fill strokes of this border.
 
void setLineStyle (Qt::PenStyle style, const QVector< qreal > &dashes)
 Sets the line style.
 
void setLineWidth (qreal lineWidth)
 Sets the line width.
 
void setMiterLimit (qreal miterLimit)
 Sets the miter limit.
 
void strokeInsets (const KoShape *shape, KoInsets &insets) const override
 
qreal strokeMaxMarkersInset (const KoShape *shape) const override
 
 ~KoShapeStroke () override
 
- Public Member Functions inherited from KoShapeStrokeModel
virtual ~KoShapeStrokeModel ()
 

Public Attributes

QBrush brush
 
QColor color
 
QPen pen
 
KoShapeStrokeq
 

Private Attributes

Private *const d
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Additional Inherited Members

- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Detailed Description

A border for shapes that draws a single line around the object.

Definition at line 36 of file KoShapeStroke.cpp.

Constructor & Destructor Documentation

◆ KoShapeStroke() [1/3]

KoShapeStroke::KoShapeStroke ( )

Constructor for a thin line in black.

Definition at line 166 of file KoShapeStroke.cpp.

167 : d(new Private(this))
168{
169 d->color = QColor(Qt::black);
170 // we are not rendering stroke with zero width anymore
171 // so lets use a default width of 1.0
172 d->pen.setWidthF(1.0);
173}
Private *const d

References d.

◆ KoShapeStroke() [2/3]

KoShapeStroke::KoShapeStroke ( const KoShapeStroke & other)

Copy constructor.

Definition at line 175 of file KoShapeStroke.cpp.

176 : KoShapeStrokeModel(), d(new Private(this))
177{
178 d->color = other.d->color;
179 d->pen = other.d->pen;
180 d->brush = other.d->brush;
181}

References d.

◆ KoShapeStroke() [3/3]

KoShapeStroke::KoShapeStroke ( qreal lineWidth,
const QColor & color = Qt::black )
explicit

Constructor for a Stroke

Parameters
lineWidththe width, in pt
colorthe color we draw the outline in.

Definition at line 183 of file KoShapeStroke.cpp.

184 : d(new Private(this))
185{
186 d->pen.setWidthF(qMax(qreal(0.0), lineWidth));
187 d->pen.setJoinStyle(Qt::MiterJoin);
188 d->color = color;
189}
qreal lineWidth() const
Returns the line width.

References color, d, and lineWidth().

◆ ~KoShapeStroke()

KoShapeStroke::~KoShapeStroke ( )
override

Definition at line 191 of file KoShapeStroke.cpp.

192{
193 delete d;
194}

References d.

Member Function Documentation

◆ capStyle()

Qt::PenCapStyle KoShapeStroke::capStyle ( ) const

Returns the lines cap style.

Definition at line 326 of file KoShapeStroke.cpp.

327{
328 return d->pen.capStyle();
329}

References d.

◆ color()

QColor KoShapeStroke::color ( ) const

Returns the color.

◆ compareFillTo()

bool KoShapeStroke::compareFillTo ( const KoShapeStrokeModel * other)
overridevirtual

Implements KoShapeStrokeModel.

Definition at line 287 of file KoShapeStroke.cpp.

288{
289 if (!other) return false;
290
291 const KoShapeStroke *stroke = dynamic_cast<const KoShapeStroke*>(other);
292 if (!stroke) return false;
293
294 return (d->brush.gradient() && d->brush == stroke->d->brush) ||
295 (!d->brush.gradient() && d->color == stroke->d->color);
296}

References d.

◆ compareStyleTo()

bool KoShapeStroke::compareStyleTo ( const KoShapeStrokeModel * other)
overridevirtual

Implements KoShapeStrokeModel.

Definition at line 298 of file KoShapeStroke.cpp.

299{
300 if (!other) return false;
301
302 const KoShapeStroke *stroke = dynamic_cast<const KoShapeStroke*>(other);
303 if (!stroke) return false;
304
305 QPen pen1 = d->pen;
306 QPen pen2 = stroke->d->pen;
307
308 // just a random color top avoid comparison of that property
309 pen1.setColor(Qt::magenta);
310 pen2.setColor(Qt::magenta);
311
312 return pen1 == pen2;
313}

References d.

◆ dashOffset()

qreal KoShapeStroke::dashOffset ( ) const

Returns the dash offset.

Definition at line 395 of file KoShapeStroke.cpp.

396{
397 return d->pen.dashOffset();
398}

References d.

◆ hasTransparency()

bool KoShapeStroke::hasTransparency ( ) const
overridevirtual

Returns true if there is some transparency, false if the stroke is fully opaque.

Returns
if the stroke is transparent.

Implements KoShapeStrokeModel.

Definition at line 255 of file KoShapeStroke.cpp.

256{
257 return d->color.alpha() > 0;
258}

References d.

◆ isVisible()

bool KoShapeStroke::isVisible ( ) const
overridevirtual

Implements KoShapeStrokeModel.

Definition at line 315 of file KoShapeStroke.cpp.

316{
317 return d->pen.widthF() > 0 &&
318 (d->brush.gradient() || d->color.alpha() > 0);
319}

References d.

◆ joinStyle()

Qt::PenJoinStyle KoShapeStroke::joinStyle ( ) const

Returns the lines join style.

Definition at line 336 of file KoShapeStroke.cpp.

337{
338 return d->pen.joinStyle();
339}

References d.

◆ lineBrush()

QBrush KoShapeStroke::lineBrush ( ) const

Returns the strokes brush.

Definition at line 405 of file KoShapeStroke.cpp.

406{
407 return d->brush;
408}

References d.

◆ lineDashes()

QVector< qreal > KoShapeStroke::lineDashes ( ) const

Returns the line dashes.

Definition at line 385 of file KoShapeStroke.cpp.

386{
387 return d->pen.dashPattern();
388}

References d.

◆ lineStyle()

Qt::PenStyle KoShapeStroke::lineStyle ( ) const

Returns the line style.

Definition at line 380 of file KoShapeStroke.cpp.

381{
382 return d->pen.style();
383}

References d.

◆ lineWidth()

qreal KoShapeStroke::lineWidth ( ) const

Returns the line width.

Definition at line 346 of file KoShapeStroke.cpp.

347{
348 return d->pen.widthF();
349}

References d.

◆ miterLimit()

qreal KoShapeStroke::miterLimit ( ) const

Returns the miter limit.

Definition at line 356 of file KoShapeStroke.cpp.

357{
358 return d->pen.miterLimit();
359}

References d.

◆ operator=()

KoShapeStroke & KoShapeStroke::operator= ( const KoShapeStroke & rhs)

Assignment operator.

Definition at line 196 of file KoShapeStroke.cpp.

197{
198 if (this == &rhs)
199 return *this;
200
201 d->pen = rhs.d->pen;
202 d->color = rhs.d->color;
203 d->brush = rhs.d->brush;
204
205 return *this;
206}

References d.

◆ paint()

void KoShapeStroke::paint ( const KoShape * shape,
QPainter & painter ) const
overridevirtual

Paint the stroke. This method should paint the stroke around shape.

Parameters
shapethe shape to paint around
painterthe painter to paint to, the painter will have the topleft of the shape as its start coordinate.

Implements KoShapeStrokeModel.

Definition at line 273 of file KoShapeStroke.cpp.

274{
275 KisQPainterStateSaver saver(&painter);
276
277 d->paintBorder(shape, painter, resultLinePen());
278}
QPen resultLinePen() const

References d, and resultLinePen().

◆ paintBorder()

void KoShapeStroke::paintBorder ( const KoShape * shape,
QPainter & painter,
const QPen & pen ) const

◆ paintMarkers() [1/2]

void KoShapeStroke::paintMarkers ( const KoShape * shape,
QPainter & painter ) const
overridevirtual

paintMarkers Paints the markers if possible.

See also
paint()

Implements KoShapeStrokeModel.

Definition at line 280 of file KoShapeStroke.cpp.

281{
282 KisQPainterStateSaver saver(&painter);
283
284 d->paintMarkers(shape, painter, resultLinePen());
285}

References d, and resultLinePen().

◆ paintMarkers() [2/2]

void KoShapeStroke::paintMarkers ( const KoShape * shape,
QPainter & painter,
const QPen & pen ) const

◆ Private()

KoShapeStroke::Private ( KoShapeStroke * _q)
inline

Definition at line 39 of file KoShapeStroke.cpp.

39: q(_q) {}
KoShapeStroke * q

◆ resultLinePen()

QPen KoShapeStroke::resultLinePen ( ) const

Definition at line 260 of file KoShapeStroke.cpp.

261{
262 QPen pen = d->pen;
263
264 if (d->brush.gradient()) {
265 pen.setBrush(d->brush);
266 } else {
267 pen.setColor(d->color.isValid() ? d->color : Qt::transparent);
268 }
269
270 return pen;
271}

References d, and pen.

◆ setCapStyle()

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

Sets the lines cap style.

Definition at line 321 of file KoShapeStroke.cpp.

322{
323 d->pen.setCapStyle(style);
324}

References d.

◆ setColor()

void KoShapeStroke::setColor ( const QColor & color)

Sets the color.

Definition at line 366 of file KoShapeStroke.cpp.

367{
368 d->color = color;
369}

References color, and d.

◆ setDashOffset()

void KoShapeStroke::setDashOffset ( qreal dashOffset)

Sets the dash offset.

Definition at line 390 of file KoShapeStroke.cpp.

391{
392 d->pen.setDashOffset(dashOffset);
393}
qreal dashOffset() const
Returns the dash offset.

References d, and dashOffset().

◆ setJoinStyle()

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

Sets the lines join style.

Definition at line 331 of file KoShapeStroke.cpp.

332{
333 d->pen.setJoinStyle(style);
334}

References d.

◆ setLineBrush()

void KoShapeStroke::setLineBrush ( const QBrush & brush)

Sets the strokes brush used to fill strokes of this border.

Definition at line 400 of file KoShapeStroke.cpp.

401{
402 d->brush = brush;
403}

References brush, and d.

◆ setLineStyle()

void KoShapeStroke::setLineStyle ( Qt::PenStyle style,
const QVector< qreal > & dashes )

Sets the line style.

Definition at line 371 of file KoShapeStroke.cpp.

372{
373 if (style < Qt::CustomDashLine) {
374 d->pen.setStyle(style);
375 } else {
376 d->pen.setDashPattern(dashes);
377 }
378}

References d.

◆ setLineWidth()

void KoShapeStroke::setLineWidth ( qreal lineWidth)

Sets the line width.

Definition at line 341 of file KoShapeStroke.cpp.

342{
343 d->pen.setWidthF(qMax(qreal(0.0), lineWidth));
344}

References d, and lineWidth().

◆ setMiterLimit()

void KoShapeStroke::setMiterLimit ( qreal miterLimit)

Sets the miter limit.

Definition at line 351 of file KoShapeStroke.cpp.

352{
353 d->pen.setMiterLimit(miterLimit);
354}
qreal miterLimit() const
Returns the miter limit.

References d, and miterLimit().

◆ strokeInsets()

void KoShapeStroke::strokeInsets ( const KoShape * shape,
KoInsets & insets ) const
overridevirtual

Return a strokeInsets object filled with the size inside the shape that this stroke takes.

Parameters
shapethe shape the insets will be calculated for
insetsthe insets object that will be filled and returned.

Implements KoShapeStrokeModel.

Definition at line 208 of file KoShapeStroke.cpp.

209{
210 Q_UNUSED(shape);
211
212 // '0.5' --- since we draw a line half inside, and half outside the object.
213 qreal extent = 0.5 * (d->pen.widthF() >= 0 ? d->pen.widthF() : 1.0);
214
215 // if we have square cap, we need a little more space
216 // -> sqrt((0.5*penWidth)^2 + (0.5*penWidth)^2)
217 if (capStyle() == Qt::SquareCap) {
218 extent *= M_SQRT2;
219 }
220
221 if (joinStyle() == Qt::MiterJoin) {
222 // miter limit in Qt is normalized by the line width (and not half-width)
223 extent = qMax(extent, d->pen.widthF() * miterLimit());
224 }
225
226 insets.top = extent;
227 insets.bottom = extent;
228 insets.left = extent;
229 insets.right = extent;
230}
Qt::PenCapStyle capStyle() const
Returns the lines cap style.
Qt::PenJoinStyle joinStyle() const
Returns the lines join style.
qreal bottom
Bottom inset.
Definition KoInsets.h:50
qreal right
Right inset.
Definition KoInsets.h:52
qreal top
Top inset.
Definition KoInsets.h:49
qreal left
Left inset.
Definition KoInsets.h:51

References KoInsets::bottom, capStyle(), d, joinStyle(), KoInsets::left, miterLimit(), KoInsets::right, and KoInsets::top.

◆ strokeMaxMarkersInset()

qreal KoShapeStroke::strokeMaxMarkersInset ( const KoShape * shape) const
overridevirtual

Return a maximum distance that the markers of the shape can take outside the shape itself

Implements KoShapeStrokeModel.

Definition at line 232 of file KoShapeStroke.cpp.

233{
234 qreal result = 0.0;
235
236 const KoPathShape *pathShape = dynamic_cast<const KoPathShape *>(shape);
237 if (pathShape && pathShape->hasMarkers()) {
238 const qreal lineWidth = d->pen.widthF();
239
241 markers << pathShape->marker(KoFlake::StartMarker);
242 markers << pathShape->marker(KoFlake::MidMarker);
243 markers << pathShape->marker(KoFlake::EndMarker);
244
245 Q_FOREACH (const KoMarker *marker, markers) {
246 if (marker) {
247 result = qMax(result, marker->maxInset(lineWidth));
248 }
249 }
250 }
251
252 return result;
253}
qreal maxInset(qreal strokeWidth) const
Definition KoMarker.cpp:243
The position of a path point within a path shape.
Definition KoPathShape.h:63
KoMarker * marker(KoFlake::MarkerPosition pos) const
bool hasMarkers() const
@ EndMarker
Definition KoFlake.h:44
@ StartMarker
Definition KoFlake.h:42
@ MidMarker
Definition KoFlake.h:43

References d, KoFlake::EndMarker, KoPathShape::hasMarkers(), lineWidth(), KoPathShape::marker(), KoMarker::maxInset(), KoFlake::MidMarker, and KoFlake::StartMarker.

Member Data Documentation

◆ brush

QBrush KoShapeStroke::brush

Definition at line 46 of file KoShapeStroke.cpp.

◆ color

QColor KoShapeStroke::color

Definition at line 44 of file KoShapeStroke.cpp.

◆ d

Private* const KoShapeStroke::d
private

Definition at line 104 of file KoShapeStroke.h.

◆ pen

QPen KoShapeStroke::pen

Definition at line 45 of file KoShapeStroke.cpp.

◆ q

KoShapeStroke* KoShapeStroke::q

Definition at line 40 of file KoShapeStroke.cpp.


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