42 #include "private/qdeclarativetimeline_p_p.h" 47 #include <QWaitCondition> 49 #include <QCoreApplication> 50 #include <QEasingCurve> 59 :
g(0),
v(0),
e(_e) {}
83 :
type(t), length(l), value(v), value2(v2), order(o),
event(ev),
86 :
type(o.
type), length(o.length), value(o.value), value2(o.value2),
87 order(o.order),
event(o.
event), easing(o.easing) {}
135 : length(0), syncPoint(0), q(parent), clockRunning(false), prevTime(0), order(0), syncMode(
QDeclarativeTimeLine::LocalSync), syncAdj(0), updateQueue(0)
141 if (g.
_t && g.
_t !=
q) {
142 qWarning() <<
"QDeclarativeTimeLine: Cannot modify a QDeclarativeTimeLineValue owned by" 143 <<
"another timeline.";
154 if (!iter->ops.isEmpty() &&
157 iter->ops.last().length += o.
length;
164 if (iter->length >
length)
203 }
else if (time == (op.
length)) {
209 return base + delta * pTime;
216 }
else if (time == (op.
length)) {
217 return base + op.
value;
222 return base + delta * pTime;
237 }
else if (time == (op.
length)) {
242 qreal delta = op.
value * t + 0.5f * accel * t * t;
361 if (time <= 0)
return;
381 d->
add(timeLineValue, op);
392 if (acceleration == 0.0f)
395 if ((velocity > 0.0f) == (acceleration > 0.0f))
396 acceleration = acceleration * -1.0f;
398 int time =
static_cast<int>(-1000 * velocity / acceleration);
401 d->
add(timeLineValue, op);
421 if (maxDistance == 0.0f || acceleration == 0.0f)
424 Q_ASSERT(acceleration > 0.0f && maxDistance > 0.0f);
426 qreal maxAccel = (velocity * velocity) / (2.0f * maxDistance);
427 if (maxAccel > acceleration)
428 acceleration = maxAccel;
430 if ((velocity > 0.0f) == (acceleration > 0.0f))
431 acceleration = acceleration * -1.0f;
433 int time =
static_cast<int>(-1000 * velocity / acceleration);
436 d->
add(timeLineValue, op);
450 if (distance == 0.0f || velocity == 0.0f)
453 Q_ASSERT((distance >= 0.0f) == (velocity >= 0.0f));
455 int time =
static_cast<int>(1000 * (2.0f *
distance) / velocity);
458 d->
add(timeLineValue, op);
469 if (time <= 0)
return;
471 d->
add(timeLineValue, op);
480 if (time <= 0)
return;
482 d->
add(timeLineValue, op);
491 if (time <= 0)
return;
493 d->
add(timeLineValue, op);
502 if (time <= 0)
return;
504 d->
add(timeLineValue, op);
512 if (!timeLineValue.
_t)
514 if (timeLineValue.
_t !=
this) {
515 qWarning() <<
"QDeclarativeTimeLine: Cannot reset a QDeclarativeTimeLineValue owned by another timeline.";
518 remove(&timeLineValue);
519 timeLineValue.
_t = 0;
543 int length = iter->length;
547 pause(timeLineValue, length);
549 int glength = iter->length;
550 pause(timeLineValue, length - glength);
735 bool operator<(const QPair<int, Update> &lhs,
738 return lhs.
first < rhs.first;
750 for (
Ops::Iterator iter = ops.begin(); iter != ops.end(); ++iter) {
752 Op &op = tl.
ops.first();
755 if (length < advanceTime) {
756 advanceTime = length;
757 if (advanceTime == 0)
767 for (
Ops::Iterator iter = ops.begin(); iter != ops.end(); ) {
773 Op &op = tl.
ops.first();
774 if (advanceTime == 0 && op.
length != 0)
779 op.
type != Op::Execute)
783 if (op.
type == Op::Execute) {
786 bool changed =
false;
793 tl.
ops.removeFirst();
796 bool changed =
false;
804 }
while(!tl.
ops.isEmpty() && advanceTime == 0 && tl.
ops.first().length == 0);
807 if (tl.
ops.isEmpty()) {
808 iter = ops.erase(iter);
811 if (tl.
ops.first().type ==
Op::Pause && pauseTime != 0) {
813 if (pauseTime == -1 || opPauseTime < pauseTime)
814 pauseTime = opPauseTime;
822 length -=
qMin(length, advanceTime);
826 updateQueue = &updates;
827 for (
int ii = 0; ii < updates.
count(); ++ii) {
828 const Update &v = updates.
at(ii).second;
846 int len = iter->length;
947 : d0(0), d1(0), d2(0)
~QDeclarativeTimeLine()
Destroys the time line.
QDeclarativeTimeLineObject * d2
int accelDistance(QDeclarativeTimeLineValue &, qreal velocity, qreal distance)
Decelerate timeLineValue from the starting velocity to zero over the given distance.
virtual IFMETHOD Pause(DWORD __RPC_FAR *pdwCookie)=0
friend struct QDeclarativeTimeLinePrivate
qreal valueForProgress(qreal progress) const
Return the effective progress for the easing curve at progress.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
int syncPoint() const
Temporary hack.
void clear()
Removes all items from the hash.
The QEasingCurve class provides easing curves for controlling animation.
QDeclarativeTimeLineCallback & operator=(const QDeclarativeTimeLineCallback &o)
int accel(QDeclarativeTimeLineValue &, qreal velocity, qreal accel)
Decelerate timeLineValue from the starting velocity to zero at the given acceleration rate...
Op(Type t, int l, qreal v, qreal v2, int o, const QDeclarativeTimeLineCallback &ev=QDeclarativeTimeLineCallback(), const QEasingCurve &es=QEasingCurve())
QDeclarativeTimeLine::SyncMode syncMode
void setSyncPoint(int)
Temporary hack.
void move(QDeclarativeTimeLineValue &, qreal destination, int time=500)
Linearly change the timeLineValue from its current value to the given destination value over time mil...
void setSyncMode(SyncMode)
Set the timeline's synchronization mode to syncMode.
const_iterator ConstIterator
Qt-style synonym for QHash::const_iterator.
QHash< QDeclarativeTimeLineObject *, TimeLine > Ops
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
QDeclarativeTimeLine(QObject *parent=0)
Construct a new QDeclarativeTimeLine with the specified parent.
void start(QAbstractAnimation::DeletionPolicy policy=KeepWhenStopped)
Starts the animation.
void reset(QDeclarativeTimeLineValue &)
Cancel (but don't complete) all scheduled actions for timeLineValue.
int count(const T &t) const
Returns the number of occurrences of value in the list.
void remove(QDeclarativeTimeLineObject *)
The QObject class is the base class of all Qt objects.
virtual void updateCurrentTime(int)
This pure virtual function is called every time the animation's currentTime changes.
QDeclarativeTimeLineCallback e
virtual int duration() const
void stop()
Stops the animation.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
The QDeclarativeTimeLineValue class provides a value that can be modified by QDeclarativeTimeLine.
bool isActive() const
Returns true if the timeline is active.
void clear()
Resets the timeline.
Update(const QDeclarativeTimeLineCallback &_e)
QList< QPair< int, Update > > * updateQueue
Type type() const
Returns the type of the easing curve.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Update(QDeclarativeTimeLineValue *_g, qreal _v)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
virtual qreal value() const
Return the current value.
const T & at(int i) const
Returns the item at index position i in the list.
bool isEmpty() const
Returns true if the hash contains no items; otherwise returns false.
Q_CORE_EXPORT void qWarning(const char *,...)
void moveBy(QDeclarativeTimeLineValue &, qreal change, int time=500)
Linearly change the timeLineValue from its current value by the change amount over time milliseconds...
The QAbstractAnimation class is the base of all animations.
void set(QDeclarativeTimeLineValue &, qreal)
Set the value of timeLineValue.
void qSort(RandomAccessIterator start, RandomAccessIterator end)
QDeclarativeTimeLine * _t
SyncMode syncMode() const
Return the timeline's synchronization mode.
void pause(QDeclarativeTimeLineObject &, int)
Pause obj for time milliseconds.
void updated()
Emitted each time the timeline modifies QDeclarativeTimeLineValues.
QDeclarativeTimeLinePrivate * d
void complete()
Completes the timeline.
QDeclarativeTimeLineObject * callbackObject() const
QDeclarativeTimeLineCallback()
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Op & operator=(const Op &o)
if(void) toggleToolbarShown
The QDeclarativeTimeLine class provides a timeline for controlling animations.
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
void pause()
Pauses the animation.
void add(QDeclarativeTimeLineObject &, const Op &)
virtual ~QDeclarativeTimeLineObject()
qreal value(const Op &op, int time, qreal base, bool *) const
QDeclarativeTimeLineObject()
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
QDeclarativeTimeLineValue * g
virtual void setValue(qreal v)
Set the current value.
QDeclarativeTimeLineCallback event
void callback(const QDeclarativeTimeLineCallback &)
Execute the event.
iterator erase(iterator it)
Removes the (key, value) pair associated with the iterator pos from the hash, and returns an iterator...
QDeclarativeTimeLinePrivate(QDeclarativeTimeLine *)
iterator Iterator
Qt-style synonym for QHash::iterator.
The QList class is a template class that provides lists.
void removeAt(int i)
Removes the item at index position i.