Qt 4.8
Classes | Public Types | Public Functions | Public Variables | List of all members
QDeclarativeSpringAnimationPrivate Class Reference
Inheritance diagram for QDeclarativeSpringAnimationPrivate:
QDeclarativePropertyAnimationPrivate QDeclarativeAbstractAnimationPrivate QObjectPrivate QObjectData

Classes

struct  SpringAnimation
 

Public Types

typedef QTickAnimationProxy< QDeclarativeSpringAnimationPrivate, &QDeclarativeSpringAnimationPrivate::tickClock
 
enum  Mode { Track, Velocity, Spring }
 
- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 

Public Functions

bool animate (const QDeclarativeProperty &property, SpringAnimation &animation, int elapsed)
 
 QDeclarativeSpringAnimationPrivate ()
 
void tick (int time)
 
void updateMode ()
 
- Public Functions inherited from QDeclarativePropertyAnimationPrivate
void init ()
 
 QDeclarativePropertyAnimationPrivate ()
 
- Public Functions inherited from QDeclarativeAbstractAnimationPrivate
void commence ()
 
 QDeclarativeAbstractAnimationPrivate ()
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Public Variables

QHash< QDeclarativeProperty, SpringAnimationactiveAnimations
 
Clockclock
 
qreal damping
 
qreal epsilon
 
bool haveModulus: 1
 
int lastTime
 
qreal mass
 
qreal maxVelocity
 
Mode mode
 
qreal modulus
 
qreal spring
 
bool useMass: 1
 
qreal velocityms
 
- Public Variables inherited from QDeclarativePropertyAnimationPrivate
QDeclarativeStateActionsactions
 
QString defaultProperties
 
bool defaultToInterpolatorType:1
 
QList< QObject * > exclude
 
QVariant from
 
bool fromIsDefined:1
 
bool fromSourced
 
QVariantAnimation::Interpolator interpolator
 
int interpolatorType
 
QString properties
 
QString propertyName
 
bool rangeIsSet:1
 
QObjecttarget
 
QList< QObject * > targets
 
QVariant to
 
bool toIsDefined:1
 
QDeclarativeBulkValueAnimatorva
 
- Public Variables inherited from QDeclarativeAbstractAnimationPrivate
bool alwaysRunToEnd:1
 
bool avoidPropertyValueSourceStart:1
 
bool componentComplete:1
 
bool connectedTimeLine:1
 
QDeclarativeProperty defaultProperty
 
bool disableUserControl:1
 
QDeclarativeAnimationGroupgroup
 
int loopCount
 
bool paused:1
 
bool registered:1
 
bool running:1
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Additional Inherited Members

- Static Public Functions inherited from QDeclarativePropertyAnimationPrivate
static void convertVariant (QVariant &variant, int type)
 
static QVariant interpolateVariant (const QVariant &from, const QVariant &to, qreal progress)
 
- Static Public Functions inherited from QDeclarativeAbstractAnimationPrivate
static QDeclarativeProperty createProperty (QObject *obj, const QString &str, QObject *infoObj)
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Detailed Description

Definition at line 57 of file qdeclarativespringanimation.cpp.

Typedefs

◆ Clock

Definition at line 104 of file qdeclarativespringanimation.cpp.

Enumerations

◆ Mode

Constructors and Destructors

◆ QDeclarativeSpringAnimationPrivate()

QDeclarativeSpringAnimationPrivate::QDeclarativeSpringAnimationPrivate ( )
inline

Definition at line 93 of file qdeclarativespringanimation.cpp.

94  : maxVelocity(0), velocityms(0), lastTime(0)
95  , mass(1.0), spring(0.), damping(0.), epsilon(0.01)
96  , modulus(0.0), useMass(false), haveModulus(false)
97  , mode(Track), clock(0)
98  { }

Functions

◆ animate()

bool QDeclarativeSpringAnimationPrivate::animate ( const QDeclarativeProperty property,
SpringAnimation animation,
int  elapsed 
)

Definition at line 138 of file qdeclarativespringanimation.cpp.

Referenced by QDeclarativeSpringAnimationPrivate(), and tick().

139 {
140  qreal srcVal = animation.to;
141 
142  bool stop = false;
143 
144  if (haveModulus) {
145  animation.currentValue = fmod(animation.currentValue, modulus);
146  srcVal = fmod(srcVal, modulus);
147  }
148  if (mode == Spring) {
149  // Real men solve the spring DEs using RK4.
150  // We'll do something much simpler which gives a result that looks fine.
151  int count = elapsed / 16;
152  for (int i = 0; i < count; ++i) {
153  qreal diff = srcVal - animation.currentValue;
154  if (haveModulus && qAbs(diff) > modulus / 2) {
155  if (diff < 0)
156  diff += modulus;
157  else
158  diff -= modulus;
159  }
160  if (useMass)
161  animation.velocity = animation.velocity + (spring * diff - damping * animation.velocity) / mass;
162  else
163  animation.velocity = animation.velocity + spring * diff - damping * animation.velocity;
164  if (maxVelocity > qreal(0.)) {
165  // limit velocity
166  if (animation.velocity > maxVelocity)
167  animation.velocity = maxVelocity;
168  else if (animation.velocity < -maxVelocity)
169  animation.velocity = -maxVelocity;
170  }
171  animation.currentValue += animation.velocity * qreal(16.0) / qreal(1000.0);
172  if (haveModulus) {
173  animation.currentValue = fmod(animation.currentValue, modulus);
174  if (animation.currentValue < qreal(0.0))
175  animation.currentValue += modulus;
176  }
177  }
178  if (qAbs(animation.velocity) < epsilon && qAbs(srcVal - animation.currentValue) < epsilon) {
179  animation.velocity = 0.0;
180  animation.currentValue = srcVal;
181  stop = true;
182  }
183  } else {
184  qreal moveBy = elapsed * velocityms;
185  qreal diff = srcVal - animation.currentValue;
186  if (haveModulus && qAbs(diff) > modulus / 2) {
187  if (diff < 0)
188  diff += modulus;
189  else
190  diff -= modulus;
191  }
192  if (diff > 0) {
193  animation.currentValue += moveBy;
194  if (haveModulus)
195  animation.currentValue = fmod(animation.currentValue, modulus);
196  } else {
197  animation.currentValue -= moveBy;
198  if (haveModulus && animation.currentValue < qreal(0.0))
199  animation.currentValue = fmod(animation.currentValue, modulus) + modulus;
200  }
201  if (lastTime - animation.start >= animation.duration) {
202  animation.currentValue = animation.to;
203  stop = true;
204  }
205  }
206 
207  qreal old_to = animation.to;
208 
209  QDeclarativePropertyPrivate::write(property, animation.currentValue,
212 
213  return (stop && old_to == animation.to); // do not stop if we got restarted
214 }
double qreal
Definition: qglobal.h:1193
static double elapsed(qint64 after, qint64 before)
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
static Bigint * diff(Bigint *a, Bigint *b)
static bool write(QObject *, const QDeclarativePropertyCache::Data &, const QVariant &, QDeclarativeContextData *, WriteFlags flags=0)

◆ tick()

void QDeclarativeSpringAnimationPrivate::tick ( int  time)

Definition at line 108 of file qdeclarativespringanimation.cpp.

Referenced by QDeclarativeSpringAnimationPrivate().

109 {
110  if (mode == Track) {
111  clock->stop();
112  return;
113  }
114  int elapsed = time - lastTime;
115  if (!elapsed)
116  return;
117 
118  if (mode == Spring) {
119  if (elapsed < 16) // capped at 62fps.
120  return;
121  int count = elapsed / 16;
122  lastTime = time - (elapsed - count * 16);
123  } else {
124  lastTime = time;
125  }
126 
127  QMutableHashIterator<QDeclarativeProperty, SpringAnimation> it(activeAnimations);
128  while (it.hasNext()) {
129  it.next();
130  if (animate(it.key(), it.value(), elapsed))
131  it.remove();
132  }
133 
134  if (activeAnimations.isEmpty())
135  clock->stop();
136 }
static double elapsed(qint64 after, qint64 before)
#define it(className, varName)
void stop()
Stops the animation.
bool animate(const QDeclarativeProperty &property, SpringAnimation &animation, int elapsed)
QHash< QDeclarativeProperty, SpringAnimation > activeAnimations

◆ updateMode()

void QDeclarativeSpringAnimationPrivate::updateMode ( )

Definition at line 216 of file qdeclarativespringanimation.cpp.

Referenced by QDeclarativeSpringAnimationPrivate().

217 {
218  if (spring == 0. && maxVelocity == 0.)
219  mode = Track;
220  else if (spring > 0.)
221  mode = Spring;
222  else {
223  mode = Velocity;
225  for (it = activeAnimations.begin(); it != activeAnimations.end(); ++it) {
226  SpringAnimation &animation = *it;
227  animation.start = lastTime;
228  qreal dist = qAbs(animation.currentValue - animation.to);
229  if (haveModulus && dist > modulus / 2)
230  dist = modulus - fmod(dist, modulus);
231  animation.duration = dist / velocityms;
232  }
233  }
234 }
double qreal
Definition: qglobal.h:1193
#define it(className, varName)
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
The SpringAnimation element allows a property to track a value in a spring-like motion.
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
Definition: qhash.h:330
QHash< QDeclarativeProperty, SpringAnimation > activeAnimations

Properties

◆ activeAnimations

QHash<QDeclarativeProperty, SpringAnimation> QDeclarativeSpringAnimationPrivate::activeAnimations

Definition at line 72 of file qdeclarativespringanimation.cpp.

Referenced by tick(), and updateMode().

◆ clock

Clock* QDeclarativeSpringAnimationPrivate::clock

Definition at line 105 of file qdeclarativespringanimation.cpp.

Referenced by tick().

◆ damping

qreal QDeclarativeSpringAnimationPrivate::damping

Definition at line 79 of file qdeclarativespringanimation.cpp.

Referenced by animate().

◆ epsilon

qreal QDeclarativeSpringAnimationPrivate::epsilon

Definition at line 80 of file qdeclarativespringanimation.cpp.

Referenced by animate().

◆ haveModulus

bool QDeclarativeSpringAnimationPrivate::haveModulus

Definition at line 84 of file qdeclarativespringanimation.cpp.

Referenced by animate(), and updateMode().

◆ lastTime

int QDeclarativeSpringAnimationPrivate::lastTime

Definition at line 76 of file qdeclarativespringanimation.cpp.

Referenced by animate(), tick(), and updateMode().

◆ mass

qreal QDeclarativeSpringAnimationPrivate::mass

Definition at line 77 of file qdeclarativespringanimation.cpp.

Referenced by animate().

◆ maxVelocity

qreal QDeclarativeSpringAnimationPrivate::maxVelocity

Definition at line 74 of file qdeclarativespringanimation.cpp.

Referenced by animate(), and updateMode().

◆ mode

Mode QDeclarativeSpringAnimationPrivate::mode

Definition at line 91 of file qdeclarativespringanimation.cpp.

Referenced by animate(), tick(), and updateMode().

◆ modulus

qreal QDeclarativeSpringAnimationPrivate::modulus

Definition at line 81 of file qdeclarativespringanimation.cpp.

Referenced by animate(), and updateMode().

◆ spring

qreal QDeclarativeSpringAnimationPrivate::spring

Definition at line 78 of file qdeclarativespringanimation.cpp.

Referenced by animate(), and updateMode().

◆ useMass

bool QDeclarativeSpringAnimationPrivate::useMass

Definition at line 83 of file qdeclarativespringanimation.cpp.

Referenced by animate().

◆ velocityms

qreal QDeclarativeSpringAnimationPrivate::velocityms

Definition at line 75 of file qdeclarativespringanimation.cpp.

Referenced by animate(), and updateMode().


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