Qt 4.8
Classes | Public Types | Public Functions | Public Variables | List of all members
QDeclarativeTimeLinePrivate Struct Reference

Classes

struct  Op
 
struct  TimeLine
 

Public Types

typedef QHash< QDeclarativeTimeLineObject *, TimeLineOps
 

Public Functions

void add (QDeclarativeTimeLineObject &, const Op &)
 
int advance (int)
 
 QDeclarativeTimeLinePrivate (QDeclarativeTimeLine *)
 
qreal value (const Op &op, int time, qreal base, bool *) const
 

Public Variables

bool clockRunning
 
int length
 
Ops ops
 
int order
 
int prevTime
 
QDeclarativeTimeLineq
 
int syncAdj
 
QDeclarativeTimeLine::SyncMode syncMode
 
int syncPoint
 
QList< QPair< int, Update > > * updateQueue
 

Detailed Description

Definition at line 66 of file qdeclarativetimeline.cpp.

Typedefs

◆ Ops

Definition at line 115 of file qdeclarativetimeline.cpp.

Constructors and Destructors

◆ QDeclarativeTimeLinePrivate()

QDeclarativeTimeLinePrivate::QDeclarativeTimeLinePrivate ( QDeclarativeTimeLine parent)

Functions

◆ add()

void QDeclarativeTimeLinePrivate::add ( QDeclarativeTimeLineObject g,
const Op o 
)

Definition at line 139 of file qdeclarativetimeline.cpp.

Referenced by QDeclarativeTimeLine::accel(), QDeclarativeTimeLine::accelDistance(), QDeclarativeTimeLine::callback(), QDeclarativeTimeLine::move(), QDeclarativeTimeLine::moveBy(), QDeclarativeTimeLine::pause(), and QDeclarativeTimeLine::set().

140 {
141  if (g._t && g._t != q) {
142  qWarning() << "QDeclarativeTimeLine: Cannot modify a QDeclarativeTimeLineValue owned by"
143  << "another timeline.";
144  return;
145  }
146  g._t = q;
147 
148  Ops::Iterator iter = ops.find(&g);
149  if (iter == ops.end()) {
150  iter = ops.insert(&g, TimeLine());
151  if (syncPoint > 0)
152  q->pause(g, syncPoint);
153  }
154  if (!iter->ops.isEmpty() &&
155  o.type == Op::Pause &&
156  iter->ops.last().type == Op::Pause) {
157  iter->ops.last().length += o.length;
158  iter->length += o.length;
159  } else {
160  iter->ops.append(o);
161  iter->length += o.length;
162  }
163 
164  if (iter->length > length)
165  length = iter->length;
166 
167  if (!clockRunning) {
168  q->stop();
169  prevTime = 0;
170  clockRunning = true;
171 
173  syncAdj = -1;
174  } else {
175  syncAdj = 0;
176  }
177  q->start();
178 /* q->tick(0);
179  if (syncMode == QDeclarativeTimeLine::LocalSync) {
180  syncAdj = -1;
181  } else {
182  syncAdj = 0;
183  }
184  */
185  }
186 }
QDeclarativeTimeLine::SyncMode syncMode
void start(QAbstractAnimation::DeletionPolicy policy=KeepWhenStopped)
Starts the animation.
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.
Definition: qhash.h:753
Q_CORE_EXPORT void qWarning(const char *,...)
void pause(QDeclarativeTimeLineObject &, int)
Pause obj for time milliseconds.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865
iterator Iterator
Qt-style synonym for QHash::iterator.
Definition: qhash.h:473

◆ advance()

int QDeclarativeTimeLinePrivate::advance ( int  t)

Definition at line 741 of file qdeclarativetimeline.cpp.

Referenced by QDeclarativeTimeLine::complete(), and QDeclarativeTimeLine::updateCurrentTime().

742 {
743  int pauseTime = -1;
744 
745  // XXX - surely there is a more efficient way?
746  do {
747  pauseTime = -1;
748  // Minimal advance time
749  int advanceTime = t;
750  for (Ops::Iterator iter = ops.begin(); iter != ops.end(); ++iter) {
751  TimeLine &tl = *iter;
752  Op &op = tl.ops.first();
753  int length = op.length - tl.consumedOpLength;
754 
755  if (length < advanceTime) {
756  advanceTime = length;
757  if (advanceTime == 0)
758  break;
759  }
760  }
761  t -= advanceTime;
762 
763  // Process until then. A zero length advance time will only process
764  // sets.
765  QList<QPair<int, Update> > updates;
766 
767  for (Ops::Iterator iter = ops.begin(); iter != ops.end(); ) {
768  QDeclarativeTimeLineValue *v = static_cast<QDeclarativeTimeLineValue *>(iter.key());
769  TimeLine &tl = *iter;
770  Q_ASSERT(!tl.ops.isEmpty());
771 
772  do {
773  Op &op = tl.ops.first();
774  if (advanceTime == 0 && op.length != 0)
775  continue;
776 
777  if (tl.consumedOpLength == 0 &&
778  op.type != Op::Pause &&
779  op.type != Op::Execute)
780  tl.base = v->value();
781 
782  if ((tl.consumedOpLength + advanceTime) == op.length) {
783  if (op.type == Op::Execute) {
784  updates << qMakePair(op.order, Update(op.event));
785  } else {
786  bool changed = false;
787  qreal val = value(op, op.length, tl.base, &changed);
788  if (changed)
789  updates << qMakePair(op.order, Update(v, val));
790  }
791  tl.length -= qMin(advanceTime, tl.length);
792  tl.consumedOpLength = 0;
793  tl.ops.removeFirst();
794  } else {
795  tl.consumedOpLength += advanceTime;
796  bool changed = false;
797  qreal val = value(op, tl.consumedOpLength, tl.base, &changed);
798  if (changed)
799  updates << qMakePair(op.order, Update(v, val));
800  tl.length -= qMin(advanceTime, tl.length);
801  break;
802  }
803 
804  } while(!tl.ops.isEmpty() && advanceTime == 0 && tl.ops.first().length == 0);
805 
806 
807  if (tl.ops.isEmpty()) {
808  iter = ops.erase(iter);
809  v->_t = 0;
810  } else {
811  if (tl.ops.first().type == Op::Pause && pauseTime != 0) {
812  int opPauseTime = tl.ops.first().length - tl.consumedOpLength;
813  if (pauseTime == -1 || opPauseTime < pauseTime)
814  pauseTime = opPauseTime;
815  } else {
816  pauseTime = 0;
817  }
818  ++iter;
819  }
820  }
821 
822  length -= qMin(length, advanceTime);
823  syncPoint -= advanceTime;
824 
825  qSort(updates.begin(), updates.end());
826  updateQueue = &updates;
827  for (int ii = 0; ii < updates.count(); ++ii) {
828  const Update &v = updates.at(ii).second;
829  if (v.g) {
830  v.g->setValue(v.v);
831  } else {
832  v.e.d0(v.e.d1);
833  }
834  }
835  updateQueue = 0;
836  } while(t);
837 
838  return pauseTime;
839 }
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QDeclarativeTimeLineCallback e
The QDeclarativeTimeLineValue class provides a value that can be modified by QDeclarativeTimeLine.
QList< QPair< int, Update > > * updateQueue
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
virtual qreal value() const
Return the current value.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
qreal value(const Op &op, int time, qreal base, bool *) const
QDeclarativeTimeLineValue * g
virtual void setValue(qreal v)
Set the current value.
iterator erase(iterator it)
Removes the (key, value) pair associated with the iterator pos from the hash, and returns an iterator...
Definition: qhash.h:827
iterator Iterator
Qt-style synonym for QHash::iterator.
Definition: qhash.h:473
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ value()

qreal QDeclarativeTimeLinePrivate::value ( const Op op,
int  time,
qreal  base,
bool *  changed 
) const

Definition at line 188 of file qdeclarativetimeline.cpp.

189 {
190  Q_ASSERT(time >= 0);
191  Q_ASSERT(time <= op.length);
192  *changed = true;
193 
194  switch(op.type) {
195  case Op::Pause:
196  *changed = false;
197  return base;
198  case Op::Set:
199  return op.value;
200  case Op::Move:
201  if (time == 0) {
202  return base;
203  } else if (time == (op.length)) {
204  return op.value;
205  } else {
206  qreal delta = op.value - base;
207  qreal pTime = (qreal)(time) / (qreal)op.length;
208  if (op.easing.type() == QEasingCurve::Linear)
209  return base + delta * pTime;
210  else
211  return base + delta * op.easing.valueForProgress(pTime);
212  }
213  case Op::MoveBy:
214  if (time == 0) {
215  return base;
216  } else if (time == (op.length)) {
217  return base + op.value;
218  } else {
219  qreal delta = op.value;
220  qreal pTime = (qreal)(time) / (qreal)op.length;
221  if (op.easing.type() == QEasingCurve::Linear)
222  return base + delta * pTime;
223  else
224  return base + delta * op.easing.valueForProgress(pTime);
225  }
226  case Op::Accel:
227  if (time == 0) {
228  return base;
229  } else {
230  qreal t = (qreal)(time) / 1000.0f;
231  qreal delta = op.value * t + 0.5f * op.value2 * t * t;
232  return base + delta;
233  }
234  case Op::AccelDistance:
235  if (time == 0) {
236  return base;
237  } else if (time == (op.length)) {
238  return base + op.value2;
239  } else {
240  qreal t = (qreal)(time) / 1000.0f;
241  qreal accel = -1.0f * 1000.0f * op.value / (qreal)op.length;
242  qreal delta = op.value * t + 0.5f * accel * t * t;
243  return base + delta;
244 
245  }
246  case Op::Execute:
247  op.event.d0(op.event.d1);
248  *changed = false;
249  return -1;
250  }
251 
252  return base;
253 }
double qreal
Definition: qglobal.h:1193
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static const uint base
Definition: qurl.cpp:268
if(void) toggleToolbarShown

Properties

◆ clockRunning

bool QDeclarativeTimeLinePrivate::clockRunning

◆ length

int QDeclarativeTimeLinePrivate::length

◆ ops

Ops QDeclarativeTimeLinePrivate::ops

◆ order

int QDeclarativeTimeLinePrivate::order

◆ prevTime

int QDeclarativeTimeLinePrivate::prevTime

◆ q

QDeclarativeTimeLine* QDeclarativeTimeLinePrivate::q

Definition at line 117 of file qdeclarativetimeline.cpp.

Referenced by add().

◆ syncAdj

int QDeclarativeTimeLinePrivate::syncAdj

◆ syncMode

QDeclarativeTimeLine::SyncMode QDeclarativeTimeLinePrivate::syncMode

◆ syncPoint

int QDeclarativeTimeLinePrivate::syncPoint

◆ updateQueue

QList<QPair<int, Update> >* QDeclarativeTimeLinePrivate::updateQueue

Definition at line 131 of file qdeclarativetimeline.cpp.

Referenced by QDeclarativeTimeLine::remove().


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