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

#include <qsvgstyle_p.h>

Inheritance diagram for QSvgAnimateColor:
QSvgStyleProperty QSvgRefCounted

Public Functions

virtual void apply (QPainter *p, const QSvgNode *node, QSvgExtraStates &states)
 
 QSvgAnimateColor (int startMs, int endMs, int by=0)
 
virtual void revert (QPainter *p, QSvgExtraStates &states)
 
void setArgs (bool fill, const QList< QColor > &colors)
 
void setFreeze (bool freeze)
 
void setRepeatCount (qreal repeatCount)
 
virtual Type type () const
 
- Public Functions inherited from QSvgStyleProperty
virtual ~QSvgStyleProperty ()
 
- Public Functions inherited from QSvgRefCounted
void deref ()
 
 QSvgRefCounted ()
 
void ref ()
 
virtual ~QSvgRefCounted ()
 

Properties

qreal m_by
 
QList< QColorm_colors
 
bool m_fill
 
bool m_finished
 
bool m_freeze
 
qreal m_from
 
QBrush m_oldBrush
 
QPen m_oldPen
 
qreal m_repeatCount
 
qreal m_to
 
qreal m_totalRunningTime
 

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 708 of file qsvgstyle_p.h.

Constructors and Destructors

◆ QSvgAnimateColor()

QSvgAnimateColor::QSvgAnimateColor ( int  startMs,
int  endMs,
int  by = 0 
)

Definition at line 812 of file qsvgstyle.cpp.

813  : QSvgStyleProperty(),
814  m_from(startMs), m_to(endMs), m_by(byMs),
815  m_finished(false)
816 {
818 }
qreal m_totalRunningTime
Definition: qsvgstyle_p.h:720

Functions

◆ apply()

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

Implements QSvgStyleProperty.

Definition at line 837 of file qsvgstyle.cpp.

838 {
839  qreal totalTimeElapsed = node->document()->currentElapsed();
840  if (totalTimeElapsed < m_from || m_finished)
841  return;
842 
843  qreal animationFrame = 0;
844  if (m_totalRunningTime != 0)
845  animationFrame = (totalTimeElapsed - m_from) / m_totalRunningTime;
846 
847  if (m_repeatCount >= 0 && m_repeatCount < animationFrame) {
848  m_finished = true;
849  animationFrame = m_repeatCount;
850  }
851 
852  qreal percentOfAnimation = animationFrame;
853  if (percentOfAnimation > 1) {
854  percentOfAnimation -= ((int)percentOfAnimation);
855  }
856 
857  qreal currentPosition = percentOfAnimation * (m_colors.count() - 1);
858 
859  int startElem = qFloor(currentPosition);
860  int endElem = qCeil(currentPosition);
861  QColor start = m_colors[startElem];
862  QColor end = m_colors[endElem];
863 
864  qreal percentOfColorMorph = currentPosition;
865  if (percentOfColorMorph > 1) {
866  percentOfColorMorph -= ((int)percentOfColorMorph);
867  }
868 
869  // Interpolate between the two fixed colors start and end
870  qreal aDiff = (end.alpha() - start.alpha()) * percentOfColorMorph;
871  qreal rDiff = (end.red() - start.red()) * percentOfColorMorph;
872  qreal gDiff = (end.green() - start.green()) * percentOfColorMorph;
873  qreal bDiff = (end.blue() - start.blue()) * percentOfColorMorph;
874 
875  int alpha = int(start.alpha() + aDiff);
876  int red = int(start.red() + rDiff);
877  int green = int(start.green() + gDiff);
878  int blue = int(start.blue() + bDiff);
879 
880  QColor color(red, green, blue, alpha);
881 
882  if (m_fill) {
883  QBrush b = p->brush();
884  m_oldBrush = b;
885  b.setColor(color);
886  p->setBrush(b);
887  } else {
888  QPen pen = p->pen();
889  m_oldPen = pen;
890  pen.setColor(color);
891  p->setPen(pen);
892  }
893 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double qreal
Definition: qglobal.h:1193
int qCeil(qreal v)
Definition: qmath.h:63
int qFloor(qreal v)
Definition: qmath.h:73
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
ushort red
Returns the red color component of this color.
Definition: qcolor.h:243
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
void setColor(const QColor &color)
Sets the color of this pen&#39;s brush to the given color.
Definition: qpen.cpp:787
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
int currentElapsed() const
QList< QColor > m_colors
Definition: qsvgstyle_p.h:721
const QBrush & brush() const
Returns the painter&#39;s current brush.
Definition: qpainter.cpp:4232
void setColor(const QColor &color)
Sets the brush color to the given color.
Definition: qbrush.cpp:725
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
ushort blue
Returns the blue color component of this color.
Definition: qcolor.h:245
ushort alpha
Returns the alpha color component of this color.
Definition: qcolor.h:242
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
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
QSvgTinyDocument * document() const
Definition: qsvgnode.cpp:233
static const KeyPair *const end
ushort green
Returns the green color component of this color.
Definition: qcolor.h:244
qreal m_totalRunningTime
Definition: qsvgstyle_p.h:720

◆ revert()

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

Implements QSvgStyleProperty.

Definition at line 895 of file qsvgstyle.cpp.

896 {
897  if (m_fill) {
898  p->setBrush(m_oldBrush);
899  } else {
900  p->setPen(m_oldPen);
901  }
902 }
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
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

◆ setArgs()

void QSvgAnimateColor::setArgs ( bool  fill,
const QList< QColor > &  colors 
)

Definition at line 820 of file qsvgstyle.cpp.

Referenced by parseAnimateColorNode().

822 {
823  m_fill = fill;
824  m_colors = colors;
825 }
QList< QColor > m_colors
Definition: qsvgstyle_p.h:721

◆ setFreeze()

void QSvgAnimateColor::setFreeze ( bool  freeze)

Definition at line 827 of file qsvgstyle.cpp.

Referenced by parseAnimateColorNode().

828 {
829  m_freeze = freeze;
830 }

◆ setRepeatCount()

void QSvgAnimateColor::setRepeatCount ( qreal  repeatCount)

Definition at line 832 of file qsvgstyle.cpp.

Referenced by parseAnimateColorNode().

833 {
834  m_repeatCount = repeatCount;
835 }

◆ type()

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

Implements QSvgStyleProperty.

Definition at line 904 of file qsvgstyle.cpp.

905 {
906  return ANIMATE_COLOR;
907 }

Properties

◆ m_by

qreal QSvgAnimateColor::m_by
private

Definition at line 719 of file qsvgstyle_p.h.

◆ m_colors

QList<QColor> QSvgAnimateColor::m_colors
private

Definition at line 721 of file qsvgstyle_p.h.

Referenced by apply(), and setArgs().

◆ m_fill

bool QSvgAnimateColor::m_fill
private

Definition at line 724 of file qsvgstyle_p.h.

Referenced by apply(), revert(), and setArgs().

◆ m_finished

bool QSvgAnimateColor::m_finished
private

Definition at line 725 of file qsvgstyle_p.h.

Referenced by apply().

◆ m_freeze

bool QSvgAnimateColor::m_freeze
private

Definition at line 726 of file qsvgstyle_p.h.

Referenced by setFreeze().

◆ m_from

qreal QSvgAnimateColor::m_from
private

Definition at line 719 of file qsvgstyle_p.h.

Referenced by apply(), and QSvgAnimateColor().

◆ m_oldBrush

QBrush QSvgAnimateColor::m_oldBrush
private

Definition at line 722 of file qsvgstyle_p.h.

Referenced by apply(), and revert().

◆ m_oldPen

QPen QSvgAnimateColor::m_oldPen
private

Definition at line 723 of file qsvgstyle_p.h.

Referenced by apply(), and revert().

◆ m_repeatCount

qreal QSvgAnimateColor::m_repeatCount
private

Definition at line 727 of file qsvgstyle_p.h.

Referenced by apply(), and setRepeatCount().

◆ m_to

qreal QSvgAnimateColor::m_to
private

Definition at line 719 of file qsvgstyle_p.h.

Referenced by QSvgAnimateColor().

◆ m_totalRunningTime

qreal QSvgAnimateColor::m_totalRunningTime
private

Definition at line 720 of file qsvgstyle_p.h.

Referenced by apply(), and QSvgAnimateColor().


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