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

#include <qsvgstyle_p.h>

Inheritance diagram for QSvgStrokeStyle:
QSvgStyleProperty QSvgRefCounted

Public Functions

virtual void apply (QPainter *p, const QSvgNode *node, QSvgExtraStates &states)
 
QString gradientId () const
 
bool isGradientResolved () const
 
 QSvgStrokeStyle ()
 
virtual void revert (QPainter *p, QSvgExtraStates &states)
 
void setDashArray (const QVector< qreal > &dashes)
 
void setDashArrayNone ()
 
void setDashOffset (qreal offset)
 
void setGradientId (const QString &Id)
 
void setGradientResolved (bool resolved)
 
void setLineCap (Qt::PenCapStyle cap)
 
void setLineJoin (Qt::PenJoinStyle join)
 
void setMiterLimit (qreal limit)
 
void setOpacity (qreal opacity)
 
void setStroke (QBrush brush)
 
void setStyle (QSvgFillStyleProperty *style)
 
void setVectorEffect (bool nonScalingStroke)
 
void setWidth (qreal width)
 
QPen stroke () const
 
QSvgFillStylePropertystyle () const
 
virtual Type type () const
 
qreal width ()
 
- Public Functions inherited from QSvgStyleProperty
virtual ~QSvgStyleProperty ()
 
- Public Functions inherited from QSvgRefCounted
void deref ()
 
 QSvgRefCounted ()
 
void ref ()
 
virtual ~QSvgRefCounted ()
 

Properties

QString m_gradientId
 
uint m_gradientResolved: 1
 
QPen m_oldStroke
 
qreal m_oldStrokeDashOffset
 
qreal m_oldStrokeOpacity
 
uint m_oldVectorEffect: 1
 
QPen m_stroke
 
uint m_strokeDashArraySet: 1
 
qreal m_strokeDashOffset
 
uint m_strokeDashOffsetSet: 1
 
uint m_strokeLineCapSet: 1
 
uint m_strokeLineJoinSet: 1
 
uint m_strokeMiterLimitSet: 1
 
qreal m_strokeOpacity
 
uint m_strokeOpacitySet: 1
 
uint m_strokeSet: 1
 
uint m_strokeWidthSet: 1
 
QSvgFillStylePropertym_style
 
uint m_vectorEffect: 1
 
uint m_vectorEffectSet: 1
 

Additional Inherited Members

- Public Types inherited from QSvgStyleProperty
enum  Type {
  QUALITY, FILL, VIEWPORT_FILL, FONT,
  STROKE, SOLID_COLOR, GRADIENT, TRANSFORM,
  ANIMATE_TRANSFORM, ANIMATE_COLOR, OPACITY, COMP_OP
}
 

Detailed Description

Definition at line 409 of file qsvgstyle_p.h.

Constructors and Destructors

◆ QSvgStrokeStyle()

QSvgStrokeStyle::QSvgStrokeStyle ( )

Definition at line 274 of file qsvgstyle.cpp.

275  : m_strokeOpacity(1.0)
276  , m_oldStrokeOpacity(0.0)
277  , m_strokeDashOffset(0)
279  , m_style(0)
280  , m_gradientResolved(1)
281  , m_vectorEffect(0)
282  , m_oldVectorEffect(0)
283  , m_strokeSet(0)
286  , m_strokeLineCapSet(0)
289  , m_strokeOpacitySet(0)
290  , m_strokeWidthSet(0)
291  , m_vectorEffectSet(0)
292 {
293 }
uint m_gradientResolved
Definition: qsvgstyle_p.h:534
qreal m_strokeDashOffset
Definition: qsvgstyle_p.h:529
uint m_strokeDashArraySet
Definition: qsvgstyle_p.h:539
qreal m_oldStrokeDashOffset
Definition: qsvgstyle_p.h:530
uint m_strokeOpacitySet
Definition: qsvgstyle_p.h:544
uint m_strokeDashOffsetSet
Definition: qsvgstyle_p.h:540
QSvgFillStyleProperty * m_style
Definition: qsvgstyle_p.h:532
uint m_vectorEffectSet
Definition: qsvgstyle_p.h:546
uint m_strokeLineCapSet
Definition: qsvgstyle_p.h:541
qreal m_oldStrokeOpacity
Definition: qsvgstyle_p.h:528
qreal m_strokeOpacity
Definition: qsvgstyle_p.h:527
uint m_strokeMiterLimitSet
Definition: qsvgstyle_p.h:543
uint m_strokeLineJoinSet
Definition: qsvgstyle_p.h:542
uint m_oldVectorEffect
Definition: qsvgstyle_p.h:536

Functions

◆ apply()

void QSvgStrokeStyle::apply ( QPainter p,
const QSvgNode node,
QSvgExtraStates states 
)
virtual

Implements QSvgStyleProperty.

Definition at line 295 of file qsvgstyle.cpp.

296 {
297  m_oldStroke = p->pen();
301 
302  QPen pen = p->pen();
303 
304  qreal oldWidth = pen.widthF();
306  if (oldWidth == 0)
307  oldWidth = 1;
308  if (width == 0)
309  width = 1;
310  qreal scale = oldWidth / width;
311 
312  if (m_strokeOpacitySet)
314 
315  if (m_vectorEffectSet)
316  states.vectorEffect = m_vectorEffect;
317 
318  if (m_strokeSet) {
319  if (m_style)
320  pen.setBrush(m_style->brush(p, states));
321  else
322  pen.setBrush(m_stroke.brush());
323  }
324 
325  if (m_strokeWidthSet)
326  pen.setWidthF(m_stroke.widthF());
327 
328  bool setDashOffsetNeeded = false;
329 
330  if (m_strokeDashOffsetSet) {
332  setDashOffsetNeeded = true;
333  }
334 
335  if (m_strokeDashArraySet) {
336  if (m_stroke.style() == Qt::SolidLine) {
337  pen.setStyle(Qt::SolidLine);
338  } else if (m_strokeWidthSet || oldWidth == 1) {
339  // If both width and dash array was set, the dash array is already scaled correctly.
341  setDashOffsetNeeded = true;
342  } else {
343  // If dash array was set, but not the width, the dash array has to be scaled with respect to the old width.
345  for (int i = 0; i < dashes.size(); ++i)
346  dashes[i] /= oldWidth;
347  pen.setDashPattern(dashes);
348  setDashOffsetNeeded = true;
349  }
350  } else if (m_strokeWidthSet && pen.style() != Qt::SolidLine && scale != 1) {
351  // If the width was set, but not the dash array, the old dash array must be scaled with respect to the new width.
352  QVector<qreal> dashes = pen.dashPattern();
353  for (int i = 0; i < dashes.size(); ++i)
354  dashes[i] *= scale;
355  pen.setDashPattern(dashes);
356  setDashOffsetNeeded = true;
357  }
358 
359  if (m_strokeLineCapSet)
365 
366  // You can have dash offset on solid strokes in SVG files, but not in Qt.
367  // QPen::setDashOffset() will set the pen style to Qt::CustomDashLine,
368  // so don't call the method if the pen is solid.
369  if (setDashOffsetNeeded && pen.style() != Qt::SolidLine) {
370  qreal currentWidth = pen.widthF();
371  if (currentWidth == 0)
372  currentWidth = 1;
373  pen.setDashOffset(states.strokeDashOffset / currentWidth);
374  }
375 
376  pen.setCosmetic(states.vectorEffect);
377 
378  p->setPen(pen);
379 }
double qreal
Definition: qglobal.h:1193
void setBrush(const QBrush &brush)
Sets the brush used to fill strokes generated with this pen to the given brush.
Definition: qpen.cpp:808
qreal m_strokeDashOffset
Definition: qsvgstyle_p.h:529
void setCapStyle(Qt::PenCapStyle pcs)
Sets the pen&#39;s cap style to the given style.
Definition: qpen.cpp:723
Qt::PenStyle style() const
Returns the pen style.
Definition: qpen.cpp:428
uint m_strokeDashArraySet
Definition: qsvgstyle_p.h:539
qreal strokeDashOffset
Definition: qsvgstyle_p.h:151
void setCosmetic(bool cosmetic)
Sets this pen to cosmetic or non-cosmetic, depending on the value of cosmetic.
Definition: qpen.cpp:854
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
QVector< qreal > dashPattern() const
Returns the dash pattern of this pen.
Definition: qpen.cpp:466
void setDashPattern(const QVector< qreal > &pattern)
Sets the dash pattern for this pen to the given pattern.
Definition: qpen.cpp:525
qreal m_oldStrokeDashOffset
Definition: qsvgstyle_p.h:530
virtual QBrush brush(QPainter *p, QSvgExtraStates &states)=0
uint m_strokeOpacitySet
Definition: qsvgstyle_p.h:544
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
uint m_strokeDashOffsetSet
Definition: qsvgstyle_p.h:540
Qt::PenJoinStyle joinStyle() const
Returns the pen&#39;s join style.
Definition: qpen.cpp:736
void setDashOffset(qreal doffset)
Sets the dash offset (the starting point on the dash pattern) for this pen to the offset specified...
Definition: qpen.cpp:570
void setJoinStyle(Qt::PenJoinStyle pcs)
Sets the pen&#39;s join style to the given style.
Definition: qpen.cpp:753
QBrush brush() const
Returns the brush used to fill strokes generated with this pen.
Definition: qpen.cpp:797
QSvgFillStyleProperty * m_style
Definition: qsvgstyle_p.h:532
uint m_vectorEffectSet
Definition: qsvgstyle_p.h:546
uint m_strokeLineCapSet
Definition: qsvgstyle_p.h:541
qreal m_oldStrokeOpacity
Definition: qsvgstyle_p.h:528
void setWidthF(qreal width)
Sets the pen width to the given width in pixels with floating point precision.
Definition: qpen.cpp:690
qreal miterLimit() const
Returns the miter limit of the pen.
Definition: qpen.cpp:589
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
qreal widthF() const
Returns the pen width with floating point precision.
Definition: qpen.cpp:645
qreal m_strokeOpacity
Definition: qsvgstyle_p.h:527
uint m_strokeMiterLimitSet
Definition: qsvgstyle_p.h:543
Qt::PenCapStyle capStyle() const
Returns the pen&#39;s cap style.
Definition: qpen.cpp:706
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
uint m_strokeLineJoinSet
Definition: qsvgstyle_p.h:542
void setStyle(Qt::PenStyle)
Sets the pen style to the given style.
Definition: qpen.cpp:450
void setMiterLimit(qreal limit)
Sets the miter limit of this pen to the given limit.
Definition: qpen.cpp:611
uint m_oldVectorEffect
Definition: qsvgstyle_p.h:536

◆ gradientId()

QString QSvgStrokeStyle::gradientId ( ) const
inline

Definition at line 496 of file qsvgstyle_p.h.

Referenced by QSvgHandler::resolveGradients().

497  {
498  return m_gradientId;
499  }
QString m_gradientId
Definition: qsvgstyle_p.h:533

◆ isGradientResolved()

bool QSvgStrokeStyle::isGradientResolved ( ) const
inline

Definition at line 506 of file qsvgstyle_p.h.

Referenced by QSvgHandler::resolveGradients().

507  {
508  return m_gradientResolved;
509  }
uint m_gradientResolved
Definition: qsvgstyle_p.h:534

◆ revert()

void QSvgStrokeStyle::revert ( QPainter p,
QSvgExtraStates states 
)
virtual

Implements QSvgStyleProperty.

Definition at line 381 of file qsvgstyle.cpp.

382 {
383  p->setPen(m_oldStroke);
387 }
qreal strokeDashOffset
Definition: qsvgstyle_p.h:151
qreal m_oldStrokeDashOffset
Definition: qsvgstyle_p.h:530
qreal m_oldStrokeOpacity
Definition: qsvgstyle_p.h:528
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
uint m_oldVectorEffect
Definition: qsvgstyle_p.h:536

◆ setDashArray()

void QSvgStrokeStyle::setDashArray ( const QVector< qreal > &  dashes)

Definition at line 389 of file qsvgstyle.cpp.

Referenced by parsePen().

390 {
391  if (m_strokeWidthSet) {
392  QVector<qreal> d = dashes;
393  qreal w = m_stroke.widthF();
394  if (w != 0 && w != 1) {
395  for (int i = 0; i < d.size(); ++i)
396  d[i] /= w;
397  }
399  } else {
400  m_stroke.setDashPattern(dashes);
401  }
403 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
uint m_strokeDashArraySet
Definition: qsvgstyle_p.h:539
void setDashPattern(const QVector< qreal > &pattern)
Sets the dash pattern for this pen to the given pattern.
Definition: qpen.cpp:525
qreal widthF() const
Returns the pen width with floating point precision.
Definition: qpen.cpp:645
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ setDashArrayNone()

void QSvgStrokeStyle::setDashArrayNone ( )
inline

Definition at line 432 of file qsvgstyle_p.h.

Referenced by parsePen().

433  {
436  }
uint m_strokeDashArraySet
Definition: qsvgstyle_p.h:539
void setStyle(Qt::PenStyle)
Sets the pen style to the given style.
Definition: qpen.cpp:450

◆ setDashOffset()

void QSvgStrokeStyle::setDashOffset ( qreal  offset)
inline

Definition at line 438 of file qsvgstyle_p.h.

Referenced by parsePen().

439  {
440  m_strokeDashOffset = offset;
442  }
qreal m_strokeDashOffset
Definition: qsvgstyle_p.h:529
uint m_strokeDashOffsetSet
Definition: qsvgstyle_p.h:540

◆ setGradientId()

void QSvgStrokeStyle::setGradientId ( const QString Id)
inline

Definition at line 491 of file qsvgstyle_p.h.

Referenced by parsePen().

492  {
493  m_gradientId = Id;
494  }
QString m_gradientId
Definition: qsvgstyle_p.h:533

◆ setGradientResolved()

void QSvgStrokeStyle::setGradientResolved ( bool  resolved)
inline

Definition at line 501 of file qsvgstyle_p.h.

Referenced by parsePen().

502  {
503  m_gradientResolved = resolved;
504  }
uint m_gradientResolved
Definition: qsvgstyle_p.h:534

◆ setLineCap()

void QSvgStrokeStyle::setLineCap ( Qt::PenCapStyle  cap)
inline

Definition at line 444 of file qsvgstyle_p.h.

Referenced by parsePen().

445  {
446  m_stroke.setCapStyle(cap);
447  m_strokeLineCapSet = 1;
448  }
void setCapStyle(Qt::PenCapStyle pcs)
Sets the pen&#39;s cap style to the given style.
Definition: qpen.cpp:723
uint m_strokeLineCapSet
Definition: qsvgstyle_p.h:541

◆ setLineJoin()

void QSvgStrokeStyle::setLineJoin ( Qt::PenJoinStyle  join)
inline

Definition at line 450 of file qsvgstyle_p.h.

Referenced by parsePen().

451  {
452  m_stroke.setJoinStyle(join);
454  }
void setJoinStyle(Qt::PenJoinStyle pcs)
Sets the pen&#39;s join style to the given style.
Definition: qpen.cpp:753
uint m_strokeLineJoinSet
Definition: qsvgstyle_p.h:542

◆ setMiterLimit()

void QSvgStrokeStyle::setMiterLimit ( qreal  limit)
inline

Definition at line 456 of file qsvgstyle_p.h.

Referenced by parsePen().

457  {
458  m_stroke.setMiterLimit(limit);
460  }
uint m_strokeMiterLimitSet
Definition: qsvgstyle_p.h:543
void setMiterLimit(qreal limit)
Sets the miter limit of this pen to the given limit.
Definition: qpen.cpp:611

◆ setOpacity()

void QSvgStrokeStyle::setOpacity ( qreal  opacity)
inline

Definition at line 462 of file qsvgstyle_p.h.

Referenced by parsePen().

463  {
464  m_strokeOpacity = opacity;
465  m_strokeOpacitySet = 1;
466  }
uint m_strokeOpacitySet
Definition: qsvgstyle_p.h:544
qreal m_strokeOpacity
Definition: qsvgstyle_p.h:527

◆ setStroke()

void QSvgStrokeStyle::setStroke ( QBrush  brush)
inline

Definition at line 417 of file qsvgstyle_p.h.

Referenced by parsePen(), and QSvgHandler::resolveGradients().

418  {
419  m_stroke.setBrush(brush);
420  m_style = 0;
421  m_strokeSet = 1;
422  }
void setBrush(const QBrush &brush)
Sets the brush used to fill strokes generated with this pen to the given brush.
Definition: qpen.cpp:808
QSvgFillStyleProperty * m_style
Definition: qsvgstyle_p.h:532

◆ setStyle()

void QSvgStrokeStyle::setStyle ( QSvgFillStyleProperty style)
inline

Definition at line 424 of file qsvgstyle_p.h.

Referenced by parsePen(), and QSvgHandler::resolveGradients().

425  {
426  m_style = style;
427  m_strokeSet = 1;
428  }
QSvgFillStyleProperty * style() const
Definition: qsvgstyle_p.h:486
QSvgFillStyleProperty * m_style
Definition: qsvgstyle_p.h:532

◆ setVectorEffect()

void QSvgStrokeStyle::setVectorEffect ( bool  nonScalingStroke)
inline

Definition at line 480 of file qsvgstyle_p.h.

Referenced by parsePen().

481  {
482  m_vectorEffect = nonScalingStroke;
483  m_vectorEffectSet = 1;
484  }
uint m_vectorEffectSet
Definition: qsvgstyle_p.h:546

◆ setWidth()

void QSvgStrokeStyle::setWidth ( qreal  width)
inline

Definition at line 468 of file qsvgstyle_p.h.

Referenced by parsePen().

469  {
471  m_strokeWidthSet = 1;
472  Q_ASSERT(!m_strokeDashArraySet); // set width before dash array.
473  }
uint m_strokeDashArraySet
Definition: qsvgstyle_p.h:539
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void setWidthF(qreal width)
Sets the pen width to the given width in pixels with floating point precision.
Definition: qpen.cpp:690

◆ stroke()

QPen QSvgStrokeStyle::stroke ( ) const
inline

Definition at line 511 of file qsvgstyle_p.h.

512  {
513  return m_stroke;
514  }

◆ style()

QSvgFillStyleProperty* QSvgStrokeStyle::style ( ) const
inline

Definition at line 486 of file qsvgstyle_p.h.

487  {
488  return m_style;
489  }
QSvgFillStyleProperty * m_style
Definition: qsvgstyle_p.h:532

◆ type()

QSvgStyleProperty::Type QSvgStrokeStyle::type ( ) const
virtual

Implements QSvgStyleProperty.

Definition at line 477 of file qsvgstyle.cpp.

478 {
479  return STROKE;
480 }

◆ width()

qreal QSvgStrokeStyle::width ( )
inline

Definition at line 475 of file qsvgstyle_p.h.

Referenced by apply().

476  {
477  return m_stroke.widthF();
478  }
qreal widthF() const
Returns the pen width with floating point precision.
Definition: qpen.cpp:645

Properties

◆ m_gradientId

QString QSvgStrokeStyle::m_gradientId
private

Definition at line 533 of file qsvgstyle_p.h.

◆ m_gradientResolved

uint QSvgStrokeStyle::m_gradientResolved
private

Definition at line 534 of file qsvgstyle_p.h.

◆ m_oldStroke

QPen QSvgStrokeStyle::m_oldStroke
private

Definition at line 526 of file qsvgstyle_p.h.

Referenced by apply(), and revert().

◆ m_oldStrokeDashOffset

qreal QSvgStrokeStyle::m_oldStrokeDashOffset
private

Definition at line 530 of file qsvgstyle_p.h.

Referenced by apply(), and revert().

◆ m_oldStrokeOpacity

qreal QSvgStrokeStyle::m_oldStrokeOpacity
private

Definition at line 528 of file qsvgstyle_p.h.

Referenced by apply(), and revert().

◆ m_oldVectorEffect

uint QSvgStrokeStyle::m_oldVectorEffect
private

Definition at line 536 of file qsvgstyle_p.h.

Referenced by apply(), and revert().

◆ m_stroke

QPen QSvgStrokeStyle::m_stroke
private

Definition at line 525 of file qsvgstyle_p.h.

Referenced by apply(), and setDashArray().

◆ m_strokeDashArraySet

uint QSvgStrokeStyle::m_strokeDashArraySet
private

Definition at line 539 of file qsvgstyle_p.h.

Referenced by apply(), and setDashArray().

◆ m_strokeDashOffset

qreal QSvgStrokeStyle::m_strokeDashOffset
private

Definition at line 529 of file qsvgstyle_p.h.

Referenced by apply().

◆ m_strokeDashOffsetSet

uint QSvgStrokeStyle::m_strokeDashOffsetSet
private

Definition at line 540 of file qsvgstyle_p.h.

Referenced by apply().

◆ m_strokeLineCapSet

uint QSvgStrokeStyle::m_strokeLineCapSet
private

Definition at line 541 of file qsvgstyle_p.h.

Referenced by apply().

◆ m_strokeLineJoinSet

uint QSvgStrokeStyle::m_strokeLineJoinSet
private

Definition at line 542 of file qsvgstyle_p.h.

Referenced by apply().

◆ m_strokeMiterLimitSet

uint QSvgStrokeStyle::m_strokeMiterLimitSet
private

Definition at line 543 of file qsvgstyle_p.h.

Referenced by apply().

◆ m_strokeOpacity

qreal QSvgStrokeStyle::m_strokeOpacity
private

Definition at line 527 of file qsvgstyle_p.h.

Referenced by apply().

◆ m_strokeOpacitySet

uint QSvgStrokeStyle::m_strokeOpacitySet
private

Definition at line 544 of file qsvgstyle_p.h.

Referenced by apply().

◆ m_strokeSet

uint QSvgStrokeStyle::m_strokeSet
private

Definition at line 538 of file qsvgstyle_p.h.

Referenced by apply().

◆ m_strokeWidthSet

uint QSvgStrokeStyle::m_strokeWidthSet
private

Definition at line 545 of file qsvgstyle_p.h.

Referenced by apply(), and setDashArray().

◆ m_style

QSvgFillStyleProperty* QSvgStrokeStyle::m_style
private

Definition at line 532 of file qsvgstyle_p.h.

Referenced by apply().

◆ m_vectorEffect

uint QSvgStrokeStyle::m_vectorEffect
private

Definition at line 535 of file qsvgstyle_p.h.

Referenced by apply().

◆ m_vectorEffectSet

uint QSvgStrokeStyle::m_vectorEffectSet
private

Definition at line 546 of file qsvgstyle_p.h.

Referenced by apply().


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