Qt 4.8
Public Types | Public Functions | Protected Functions | Properties | List of all members
QSvgAnimateTransform Class Reference

#include <qsvgstyle_p.h>

Inheritance diagram for QSvgAnimateTransform:
QSvgStyleProperty QSvgRefCounted

Public Types

enum  Additive { Sum, Replace }
 
enum  TransformType {
  Empty, Translate, Scale, Rotate,
  SkewX, SkewY
}
 
- Public Types inherited from QSvgStyleProperty
enum  Type {
  QUALITY, FILL, VIEWPORT_FILL, FONT,
  STROKE, SOLID_COLOR, GRADIENT, TRANSFORM,
  ANIMATE_TRANSFORM, ANIMATE_COLOR, OPACITY, COMP_OP
}
 

Public Functions

QSvgAnimateTransform::Additive additiveType () const
 
bool animActive (qreal totalTimeElapsed)
 
virtual void apply (QPainter *p, const QSvgNode *node, QSvgExtraStates &states)
 
void clearTransformApplied ()
 
 QSvgAnimateTransform (int startMs, int endMs, int by=0)
 
virtual void revert (QPainter *p, QSvgExtraStates &states)
 
void setArgs (TransformType type, Additive additive, const QVector< qreal > &args)
 
void setFreeze (bool freeze)
 
void setRepeatCount (qreal repeatCount)
 
bool transformApplied () const
 
virtual Type type () const
 
- Public Functions inherited from QSvgStyleProperty
virtual ~QSvgStyleProperty ()
 
- Public Functions inherited from QSvgRefCounted
void deref ()
 
 QSvgRefCounted ()
 
void ref ()
 
virtual ~QSvgRefCounted ()
 

Protected Functions

void resolveMatrix (const QSvgNode *node)
 

Properties

Additive m_additive
 
QVector< qrealm_args
 
qreal m_by
 
int m_count
 
bool m_finished
 
bool m_freeze
 
qreal m_from
 
QTransform m_oldWorldTransform
 
qreal m_repeatCount
 
qreal m_to
 
qreal m_totalRunningTime
 
QTransform m_transform
 
bool m_transformApplied
 
TransformType m_type
 

Detailed Description

Definition at line 635 of file qsvgstyle_p.h.

Enumerations

◆ Additive

Enumerator
Sum 
Replace 

Definition at line 647 of file qsvgstyle_p.h.

◆ TransformType

Enumerator
Empty 
Translate 
Scale 
Rotate 
SkewX 
SkewY 

Definition at line 638 of file qsvgstyle_p.h.

Constructors and Destructors

◆ QSvgAnimateTransform()

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

Functions

◆ additiveType()

QSvgAnimateTransform::Additive QSvgAnimateTransform::additiveType ( ) const
inline

Definition at line 660 of file qsvgstyle_p.h.

661  {
662  return m_additive;
663  }

◆ animActive()

bool QSvgAnimateTransform::animActive ( qreal  totalTimeElapsed)
inline

Definition at line 665 of file qsvgstyle_p.h.

666  {
667  if (totalTimeElapsed < m_from)
668  return false;
669  if (m_freeze || m_repeatCount < 0) // fill="freeze" or repeat="indefinite"
670  return true;
671  if (m_totalRunningTime == 0)
672  return false;
673  qreal animationFrame = (totalTimeElapsed - m_from) / m_totalRunningTime;
674  if (animationFrame > m_repeatCount)
675  return false;
676  return true;
677  }
double qreal
Definition: qglobal.h:1193

◆ apply()

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

Implements QSvgStyleProperty.

Definition at line 658 of file qsvgstyle.cpp.

659 {
661  resolveMatrix(node);
662  p->setWorldTransform(m_transform, true);
663  m_transformApplied = true;
664 }
QTransform m_oldWorldTransform
Definition: qsvgstyle_p.h:700
const QTransform & worldTransform() const
Returns the world transformation matrix.
Definition: qpainter.cpp:9652
void setWorldTransform(const QTransform &matrix, bool combine=false)
Sets the world transformation matrix.
Definition: qpainter.cpp:9630
QTransform m_transform
Definition: qsvgstyle_p.h:699
void resolveMatrix(const QSvgNode *node)
Definition: qsvgstyle.cpp:672

◆ clearTransformApplied()

void QSvgAnimateTransform::clearTransformApplied ( )
inline

Definition at line 685 of file qsvgstyle_p.h.

686  {
687  m_transformApplied = false;
688  }

◆ resolveMatrix()

void QSvgAnimateTransform::resolveMatrix ( const QSvgNode node)
protected

Definition at line 672 of file qsvgstyle.cpp.

Referenced by apply().

673 {
674  static const qreal deg2rad = qreal(0.017453292519943295769);
675  qreal totalTimeElapsed = node->document()->currentElapsed();
676  if (totalTimeElapsed < m_from || m_finished)
677  return;
678 
679  qreal animationFrame = 0;
680  if (m_totalRunningTime != 0) {
681  animationFrame = (totalTimeElapsed - m_from) / m_totalRunningTime;
682 
683  if (m_repeatCount >= 0 && m_repeatCount < animationFrame) {
684  m_finished = true;
685  animationFrame = m_repeatCount;
686  }
687  }
688 
689  qreal percentOfAnimation = animationFrame;
690  if (percentOfAnimation > 1) {
691  percentOfAnimation -= ((int)percentOfAnimation);
692  }
693 
694  qreal currentPosition = percentOfAnimation * (m_count - 1);
695  int startElem = qFloor(currentPosition);
696  int endElem = qCeil(currentPosition);
697 
698  switch(m_type)
699  {
700  case Translate: {
701  startElem *= 3;
702  endElem *= 3;
703  qreal from1, from2;
704  qreal to1, to2;
705  from1 = m_args[startElem++];
706  from2 = m_args[startElem++];
707  to1 = m_args[endElem++];
708  to2 = m_args[endElem++];
709 
710  qreal transXDiff = (to1-from1) * percentOfAnimation;
711  qreal transX = from1 + transXDiff;
712  qreal transYDiff = (to2-from2) * percentOfAnimation;
713  qreal transY = from2 + transYDiff;
715  m_transform.translate(transX, transY);
716  break;
717  }
718  case Scale: {
719  startElem *= 3;
720  endElem *= 3;
721  qreal from1, from2;
722  qreal to1, to2;
723  from1 = m_args[startElem++];
724  from2 = m_args[startElem++];
725  to1 = m_args[endElem++];
726  to2 = m_args[endElem++];
727 
728  qreal transXDiff = (to1-from1) * percentOfAnimation;
729  qreal transX = from1 + transXDiff;
730  qreal transYDiff = (to2-from2) * percentOfAnimation;
731  qreal transY = from2 + transYDiff;
732  if (transY == 0)
733  transY = transX;
735  m_transform.scale(transX, transY);
736  break;
737  }
738  case Rotate: {
739  startElem *= 3;
740  endElem *= 3;
741  qreal from1, from2, from3;
742  qreal to1, to2, to3;
743  from1 = m_args[startElem++];
744  from2 = m_args[startElem++];
745  from3 = m_args[startElem++];
746  to1 = m_args[endElem++];
747  to2 = m_args[endElem++];
748  to3 = m_args[endElem++];
749 
750  qreal rotationDiff = (to1 - from1) * percentOfAnimation;
751  //qreal rotation = from1 + rotationDiff;
752 
753  qreal transXDiff = (to2-from2) * percentOfAnimation;
754  qreal transX = from2 + transXDiff;
755  qreal transYDiff = (to3-from3) * percentOfAnimation;
756  qreal transY = from3 + transYDiff;
758  m_transform.translate(transX, transY);
759  m_transform.rotate(rotationDiff);
760  m_transform.translate(-transX, -transY);
761  break;
762  }
763  case SkewX: {
764  startElem *= 3;
765  endElem *= 3;
766  qreal from1;
767  qreal to1;
768  from1 = m_args[startElem++];
769  to1 = m_args[endElem++];
770 
771  qreal transXDiff = (to1-from1) * percentOfAnimation;
772  qreal transX = from1 + transXDiff;
774  m_transform.shear(qTan(transX * deg2rad), 0);
775  break;
776  }
777  case SkewY: {
778  startElem *= 3;
779  endElem *= 3;
780  qreal from1;
781  qreal to1;
782  from1 = m_args[startElem++];
783  to1 = m_args[endElem++];
784 
785 
786  qreal transYDiff = (to1 - from1) * percentOfAnimation;
787  qreal transY = from1 + transYDiff;
789  m_transform.shear(0, qTan(transY * deg2rad));
790  break;
791  }
792  default:
793  break;
794  }
795 }
double qreal
Definition: qglobal.h:1193
int qCeil(qreal v)
Definition: qmath.h:63
QTransform & shear(qreal sh, qreal sv)
Shears the coordinate system by sh horizontally and sv vertically, and returns a reference to the mat...
Definition: qtransform.cpp:551
int qFloor(qreal v)
Definition: qmath.h:73
QTransform & translate(qreal dx, qreal dy)
Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to t...
Definition: qtransform.cpp:417
TransformType m_type
Definition: qsvgstyle_p.h:695
QTransform & rotate(qreal a, Qt::Axis axis=Qt::ZAxis)
Rotates the coordinate system counterclockwise by the given angle about the specified axis and return...
Definition: qtransform.cpp:615
int currentElapsed() const
const qreal deg2rad
Definition: qmatrix.cpp:970
QVector< qreal > m_args
Definition: qsvgstyle_p.h:697
qreal qTan(qreal v)
Definition: qmath.h:125
QTransform & scale(qreal sx, qreal sy)
Scales the coordinate system by sx horizontally and sy vertically, and returns a reference to the mat...
Definition: qtransform.cpp:485
QTransform m_transform
Definition: qsvgstyle_p.h:699
QSvgTinyDocument * document() const
Definition: qsvgnode.cpp:233
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ revert()

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

Implements QSvgStyleProperty.

Definition at line 666 of file qsvgstyle.cpp.

667 {
668  p->setWorldTransform(m_oldWorldTransform, false /* don't combine */);
669  m_transformApplied = false;
670 }
QTransform m_oldWorldTransform
Definition: qsvgstyle_p.h:700
void setWorldTransform(const QTransform &matrix, bool combine=false)
Sets the world transformation matrix.
Definition: qpainter.cpp:9630

◆ setArgs()

void QSvgAnimateTransform::setArgs ( TransformType  type,
Additive  additive,
const QVector< qreal > &  args 
)

Definition at line 649 of file qsvgstyle.cpp.

Referenced by parseAnimateTransformNode().

650 {
651  m_type = type;
652  m_args = args;
653  m_additive = additive;
654  Q_ASSERT(!(args.count()%3));
655  m_count = args.count() / 3;
656 }
virtual Type type() const
Definition: qsvgstyle.cpp:797
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
TransformType m_type
Definition: qsvgstyle_p.h:695
QVector< qreal > m_args
Definition: qsvgstyle_p.h:697

◆ setFreeze()

void QSvgAnimateTransform::setFreeze ( bool  freeze)

Definition at line 802 of file qsvgstyle.cpp.

Referenced by parseAnimateTransformNode().

803 {
804  m_freeze = freeze;
805 }

◆ setRepeatCount()

void QSvgAnimateTransform::setRepeatCount ( qreal  repeatCount)

Definition at line 807 of file qsvgstyle.cpp.

Referenced by parseAnimateTransformNode().

808 {
809  m_repeatCount = repeatCount;
810 }

◆ transformApplied()

bool QSvgAnimateTransform::transformApplied ( ) const
inline

Definition at line 679 of file qsvgstyle_p.h.

680  {
681  return m_transformApplied;
682  }

◆ type()

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

Implements QSvgStyleProperty.

Definition at line 797 of file qsvgstyle.cpp.

Referenced by setArgs().

Properties

◆ m_additive

Additive QSvgAnimateTransform::m_additive
private

Definition at line 696 of file qsvgstyle_p.h.

Referenced by setArgs().

◆ m_args

QVector<qreal> QSvgAnimateTransform::m_args
private

Definition at line 697 of file qsvgstyle_p.h.

Referenced by resolveMatrix(), and setArgs().

◆ m_by

qreal QSvgAnimateTransform::m_by
private

Definition at line 693 of file qsvgstyle_p.h.

◆ m_count

int QSvgAnimateTransform::m_count
private

Definition at line 698 of file qsvgstyle_p.h.

Referenced by resolveMatrix(), and setArgs().

◆ m_finished

bool QSvgAnimateTransform::m_finished
private

Definition at line 701 of file qsvgstyle_p.h.

Referenced by resolveMatrix().

◆ m_freeze

bool QSvgAnimateTransform::m_freeze
private

Definition at line 702 of file qsvgstyle_p.h.

Referenced by setFreeze().

◆ m_from

qreal QSvgAnimateTransform::m_from
private

Definition at line 693 of file qsvgstyle_p.h.

Referenced by QSvgAnimateTransform(), and resolveMatrix().

◆ m_oldWorldTransform

QTransform QSvgAnimateTransform::m_oldWorldTransform
private

Definition at line 700 of file qsvgstyle_p.h.

Referenced by apply(), and revert().

◆ m_repeatCount

qreal QSvgAnimateTransform::m_repeatCount
private

Definition at line 703 of file qsvgstyle_p.h.

Referenced by resolveMatrix(), and setRepeatCount().

◆ m_to

qreal QSvgAnimateTransform::m_to
private

Definition at line 693 of file qsvgstyle_p.h.

Referenced by QSvgAnimateTransform().

◆ m_totalRunningTime

qreal QSvgAnimateTransform::m_totalRunningTime
private

Definition at line 694 of file qsvgstyle_p.h.

Referenced by QSvgAnimateTransform(), and resolveMatrix().

◆ m_transform

QTransform QSvgAnimateTransform::m_transform
private

Definition at line 699 of file qsvgstyle_p.h.

Referenced by apply(), and resolveMatrix().

◆ m_transformApplied

bool QSvgAnimateTransform::m_transformApplied
private

Definition at line 704 of file qsvgstyle_p.h.

Referenced by apply(), and revert().

◆ m_type

TransformType QSvgAnimateTransform::m_type
private

Definition at line 695 of file qsvgstyle_p.h.

Referenced by resolveMatrix(), and setArgs().


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