Qt 4.8
Public Types | Public Slots | Signals | Public Functions | Protected Functions | Properties | List of all members
QTimeLine Class Reference

The QTimeLine class provides a timeline for controlling animations. More...

#include <qtimeline.h>

Inheritance diagram for QTimeLine:
QObject

Public Types

enum  CurveShape {
  EaseInCurve, EaseOutCurve, EaseInOutCurve, LinearCurve,
  SineCurve, CosineCurve
}
 This enum describes the default shape of QTimeLine's value curve. More...
 
enum  Direction { Forward, Backward }
 This enum describes the direction of the timeline when in Running state. More...
 
enum  State { NotRunning, Paused, Running }
 This enum describes the state of the timeline. More...
 

Public Slots

void resume ()
 Resumes the timeline from the current time. More...
 
void setCurrentTime (int msec)
 
void setPaused (bool paused)
 If paused is true, the timeline is paused, causing QTimeLine to enter Paused state. More...
 
void start ()
 Starts the timeline. More...
 
void stop ()
 Stops the timeline, causing QTimeLine to enter NotRunning state. More...
 
void toggleDirection ()
 Toggles the direction of the timeline. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Signals

void finished ()
 This signal is emitted when QTimeLine finishes (i. More...
 
void frameChanged (int)
 QTimeLine emits this signal at regular intervals when in Running state, but only if the current frame changes. More...
 
void stateChanged (QTimeLine::State newState)
 This signal is emitted whenever QTimeLine's state changes. More...
 
void valueChanged (qreal x)
 QTimeLine emits this signal at regular intervals when in Running state, but only if the current value changes. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

int currentFrame () const
 Returns the frame corresponding to the current time. More...
 
int currentTime () const
 
qreal currentValue () const
 Returns the value corresponding to the current time. More...
 
CurveShape curveShape () const
 
Direction direction () const
 
int duration () const
 
QEasingCurve easingCurve () const
 
int endFrame () const
 Returns the end frame, which is the frame corresponding to the end of the timeline (i.e., the frame for which the current value is 1). More...
 
int frameForTime (int msec) const
 Returns the frame corresponding to the time msec. More...
 
int loopCount () const
 
 QTimeLine (int duration=1000, QObject *parent=0)
 Constructs a timeline with a duration of duration milliseconds. More...
 
void setCurveShape (CurveShape shape)
 
void setDirection (Direction direction)
 
void setDuration (int duration)
 
void setEasingCurve (const QEasingCurve &curve)
 
void setEndFrame (int frame)
 Sets the end frame, which is the frame corresponding to the end of the timeline (i.e., the frame for which the current value is 1), to frame. More...
 
void setFrameRange (int startFrame, int endFrame)
 Sets the timeline's frame counter to start at startFrame, and end and endFrame. More...
 
void setLoopCount (int count)
 
void setStartFrame (int frame)
 Sets the start frame, which is the frame corresponding to the start of the timeline (i.e., the frame for which the current value is 0), to frame. More...
 
void setUpdateInterval (int interval)
 
int startFrame () const
 Returns the start frame, which is the frame corresponding to the start of the timeline (i.e., the frame for which the current value is 0). More...
 
State state () const
 Returns the state of the timeline. More...
 
int updateInterval () const
 
virtual qreal valueForTime (int msec) const
 Returns the timeline value for the time msec. More...
 
virtual ~QTimeLine ()
 Destroys the timeline. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Functions

void timerEvent (QTimerEvent *event)
 Reimplemented Function More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 

Properties

int currentTime
 the current time of the time line. More...
 
CurveShape curveShape
 the shape of the timeline curve. More...
 
Direction direction
 the direction of the timeline when QTimeLine is in Running state. More...
 
int duration
 the total duration of the timeline in milliseconds. More...
 
QEasingCurve easingCurve
 Specifies the easing curve that the timeline will use. More...
 
int loopCount
 the number of times the timeline should loop before it's finished. More...
 
int updateInterval
 the time in milliseconds between each time QTimeLine updates its current time. More...
 

Additional Inherited Members

- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

The QTimeLine class provides a timeline for controlling animations.

Since
4.2

It's most commonly used to animate a GUI control by calling a slot periodically. You can construct a timeline by passing its duration in milliseconds to QTimeLine's constructor. The timeline's duration describes for how long the animation will run. Then you set a suitable frame range by calling setFrameRange(). Finally connect the frameChanged() signal to a suitable slot in the widget you wish to animate (e.g., setValue() in QProgressBar). When you proceed to calling start(), QTimeLine will enter Running state, and start emitting frameChanged() at regular intervals, causing your widget's connected property's value to grow from the lower end to the upper and of your frame range, at a steady rate. You can specify the update interval by calling setUpdateInterval(). When done, QTimeLine enters NotRunning state, and emits finished().

Example:

...
progressBar = new QProgressBar(this);
progressBar->setRange(0, 100);
// Construct a 1-second timeline with a frame range of 0 - 100
QTimeLine *timeLine = new QTimeLine(1000, this);
timeLine->setFrameRange(0, 100);
connect(timeLine, SIGNAL(frameChanged(int)), progressBar, SLOT(setValue(int)));
// Clicking the push button will start the progress bar animation
pushButton = new QPushButton(tr("Start animation"), this);
connect(pushButton, SIGNAL(clicked()), timeLine, SLOT(start()));
...

You can also use QTimeLine with the Graphics View{Graphics View framework} for animations. The QGraphicsItemAnimation class implements animation of QGraphicsItems with a timeline.

By default the timeline runs once, from the beginning and towards the end, upon which you must call start() again to restart from the beginning. To make the timeline loop, you can call setLoopCount(), passing the number of times the timeline should run before finishing. The direction can also be changed, causing the timeline to run backward, by calling setDirection(). You can also pause and unpause the timeline while it's running by calling setPaused(). For interactive control, the setCurrentTime() function is provided, which sets the time position of the time line directly. Although most useful in NotRunning state, (e.g., connected to a valueChanged() signal in a QSlider,) this function can be called at any time.

The frame interface is useful for standard widgets, but QTimeLine can be used to control any type of animation. The heart of QTimeLine lies in the valueForTime() function, which generates a value between 0 and 1 for a given time. This value is typically used to describe the steps of an animation, where 0 is the first step of an animation, and 1 is the last step. When running, QTimeLine generates values between 0 and 1 by calling valueForTime() and emitting valueChanged(). By default, valueForTime() applies an interpolation algorithm to generate these value. You can choose from a set of predefined timeline algorithms by calling setCurveShape().

Note that by default, QTimeLine uses the EaseInOut curve shape, which provides a value that grows slowly, then grows steadily, and finally grows slowly. For a custom timeline, you can reimplement valueForTime(), in which case QTimeLine's curveShape property is ignored.

See also
QProgressBar, QProgressDialog, QGraphicsItemAnimation

Definition at line 55 of file qtimeline.h.

Enumerations

◆ CurveShape

This enum describes the default shape of QTimeLine's value curve.

The default, shape is EaseInOutCurve. The curve defines the relation between the value and the timeline.

  • EaseInCurve The value starts growing slowly, then increases in speed.
  • EaseOutCurve The value starts growing steadily, then ends slowly.
  • EaseInOutCurve The value starts growing slowly, then runs steadily, then grows slowly again.
  • LinearCurve The value grows linearly (e.g., if the duration is 1000 ms, the value at time 500 ms is 0.5).
  • SineCurve The value grows sinusoidally.
  • CosineCurve The value grows cosinusoidally.
See also
setCurveShape()
Enumerator
EaseInCurve 
EaseOutCurve 
EaseInOutCurve 
LinearCurve 
SineCurve 
CosineCurve 

Definition at line 75 of file qtimeline.h.

◆ Direction

This enum describes the direction of the timeline when in Running state.

  • Forward The current time of the timeline increases with time (i.e., moves from 0 and towards the end / duration).
  • Backward The current time of the timeline decreases with time (i.e., moves from the end / duration and towards 0).
See also
setDirection()
Enumerator
Forward 
Backward 

Definition at line 71 of file qtimeline.h.

71  {
72  Forward,
73  Backward
74  };

◆ State

This enum describes the state of the timeline.

  • NotRunning The timeline is not running. This is the initial state of QTimeLine, and the state QTimeLine reenters when finished. The current time, frame and value remain unchanged until either setCurrentTime() is called, or the timeline is started by calling start().
  • Paused The timeline is paused (i.e., temporarily suspended). Calling setPaused(false) will resume timeline activity.
  • Running The timeline is running. While control is in the event loop, QTimeLine will update its current time at regular intervals, emitting valueChanged() and frameChanged() when appropriate.
See also
state(), stateChanged()
Enumerator
NotRunning 
Paused 
Running 

Definition at line 66 of file qtimeline.h.

Constructors and Destructors

◆ QTimeLine()

QTimeLine::QTimeLine ( int  duration = 1000,
QObject parent = 0 
)
explicit

Constructs a timeline with a duration of duration milliseconds.

parent is passed to QObject's constructor. The default duration is 1000 milliseconds.

Definition at line 337 of file qtimeline.cpp.

338  : QObject(*new QTimeLinePrivate, parent)
339 {
341 }
void setDuration(int duration)
Definition: qtimeline.cpp:434
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
int duration() const

◆ ~QTimeLine()

QTimeLine::~QTimeLine ( )
virtual

Destroys the timeline.

Definition at line 346 of file qtimeline.cpp.

347 {
348  Q_D(QTimeLine);
349 
350  if (d->state == Running)
351  stop();
352 }
double d
Definition: qnumeric_p.h:62
void stop()
Stops the timeline, causing QTimeLine to enter NotRunning state.
Definition: qtimeline.cpp:766
#define Q_D(Class)
Definition: qglobal.h:2482
The QTimeLine class provides a timeline for controlling animations.
Definition: qtimeline.h:55

Functions

◆ currentFrame()

int QTimeLine::currentFrame ( ) const

Returns the frame corresponding to the current time.

See also
currentTime(), frameForTime(), setFrameRange()

Definition at line 656 of file qtimeline.cpp.

657 {
658  Q_D(const QTimeLine);
659  return frameForTime(d->currentTime);
660 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTimeLine class provides a timeline for controlling animations.
Definition: qtimeline.h:55
int frameForTime(int msec) const
Returns the frame corresponding to the time msec.
Definition: qtimeline.cpp:680

◆ currentTime()

int QTimeLine::currentTime ( ) const

Referenced by setEasingCurve().

◆ currentValue()

qreal QTimeLine::currentValue ( ) const

Returns the value corresponding to the current time.

See also
valueForTime(), currentFrame()

Definition at line 667 of file qtimeline.cpp.

668 {
669  Q_D(const QTimeLine);
670  return valueForTime(d->currentTime);
671 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTimeLine class provides a timeline for controlling animations.
Definition: qtimeline.h:55
virtual qreal valueForTime(int msec) const
Returns the timeline value for the time msec.
Definition: qtimeline.cpp:698

◆ curveShape()

CurveShape QTimeLine::curveShape ( ) const

Referenced by setUpdateInterval().

◆ direction()

Direction QTimeLine::direction ( ) const

Referenced by setDirection(), and setLoopCount().

◆ duration()

int QTimeLine::duration ( ) const

Referenced by setDirection(), and setDuration().

◆ easingCurve()

QEasingCurve QTimeLine::easingCurve ( ) const

Referenced by setCurveShape().

◆ endFrame()

int QTimeLine::endFrame ( ) const

Returns the end frame, which is the frame corresponding to the end of the timeline (i.e., the frame for which the current value is 1).

See also
setEndFrame(), setFrameRange()

Definition at line 474 of file qtimeline.cpp.

Referenced by setFrameRange().

475 {
476  Q_D(const QTimeLine);
477  return d->endFrame;
478 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTimeLine class provides a timeline for controlling animations.
Definition: qtimeline.h:55

◆ finished

QTimeLine::finished ( )
signal

This signal is emitted when QTimeLine finishes (i.

e., reaches the end of its time line), and does not loop.

◆ frameChanged

QTimeLine::frameChanged ( int  frame)
signal

QTimeLine emits this signal at regular intervals when in Running state, but only if the current frame changes.

frame is the current frame number.

See also
QTimeLine::setFrameRange(), QTimeLine::updateInterval

◆ frameForTime()

int QTimeLine::frameForTime ( int  msec) const

Returns the frame corresponding to the time msec.

This value is calculated using a linear interpolation of the start and end frame, based on the value returned by valueForTime().

See also
valueForTime(), setFrameRange()

Definition at line 680 of file qtimeline.cpp.

Referenced by currentFrame().

681 {
682  Q_D(const QTimeLine);
683  if (d->direction == Forward)
684  return d->startFrame + int((d->endFrame - d->startFrame) * valueForTime(msec));
685  return d->startFrame + qCeil((d->endFrame - d->startFrame) * valueForTime(msec));
686 }
double d
Definition: qnumeric_p.h:62
int qCeil(qreal v)
Definition: qmath.h:63
#define Q_D(Class)
Definition: qglobal.h:2482
The QTimeLine class provides a timeline for controlling animations.
Definition: qtimeline.h:55
virtual qreal valueForTime(int msec) const
Returns the timeline value for the time msec.
Definition: qtimeline.cpp:698

◆ loopCount()

int QTimeLine::loopCount ( ) const

Referenced by state().

◆ resume

void QTimeLine::resume ( )
slot

Resumes the timeline from the current time.

QTimeLine will reenter Running state, and once it enters the event loop, it will update its current time, frame and value at regular intervals.

In contrast to start(), this function does not restart the timeline before it resumes.

See also
start(), updateInterval(), frameChanged(), valueChanged()

Definition at line 748 of file qtimeline.cpp.

749 {
750  Q_D(QTimeLine);
751  if (d->timerId) {
752  qWarning("QTimeLine::resume: already running");
753  return;
754  }
755  d->timerId = startTimer(d->updateInterval);
756  d->startTime = d->currentTime;
757  d->timer.start();
758  d->setState(Running);
759 }
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
Definition: qobject.cpp:1623
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTimeLine class provides a timeline for controlling animations.
Definition: qtimeline.h:55
Q_CORE_EXPORT void qWarning(const char *,...)

◆ setCurrentTime

void QTimeLine::setCurrentTime ( int  msec)
slot

Definition at line 642 of file qtimeline.cpp.

643 {
644  Q_D(QTimeLine);
645  d->startTime = 0;
646  d->currentLoopCount = 0;
647  d->timer.restart();
648  d->setCurrentTime(msec);
649 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTimeLine class provides a timeline for controlling animations.
Definition: qtimeline.h:55

◆ setCurveShape()

void QTimeLine::setCurveShape ( CurveShape  shape)

Definition at line 572 of file qtimeline.cpp.

573 {
574  switch (shape) {
575  default:
576  case EaseInOutCurve:
578  break;
579  case EaseInCurve:
581  break;
582  case EaseOutCurve:
584  break;
585  case LinearCurve:
587  break;
588  case SineCurve:
590  break;
591  case CosineCurve:
593  break;
594  }
595 }
The QEasingCurve class provides easing curves for controlling animation.
Definition: qeasingcurve.h:55
void setEasingCurve(const QEasingCurve &curve)
Definition: qtimeline.cpp:617

◆ setDirection()

void QTimeLine::setDirection ( Direction  direction)

Definition at line 406 of file qtimeline.cpp.

Referenced by toggleDirection().

407 {
408  Q_D(QTimeLine);
409  d->direction = direction;
410  d->startTime = d->currentTime;
411  d->timer.start();
412 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Direction direction() const
The QTimeLine class provides a timeline for controlling animations.
Definition: qtimeline.h:55

◆ setDuration()

void QTimeLine::setDuration ( int  duration)

Definition at line 434 of file qtimeline.cpp.

Referenced by QTimeLine().

435 {
436  Q_D(QTimeLine);
437  if (duration <= 0) {
438  qWarning("QTimeLine::setDuration: cannot set duration <= 0");
439  return;
440  }
441  d->duration = duration;
442 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTimeLine class provides a timeline for controlling animations.
Definition: qtimeline.h:55
Q_CORE_EXPORT void qWarning(const char *,...)
int duration() const

◆ setEasingCurve()

void QTimeLine::setEasingCurve ( const QEasingCurve curve)

Definition at line 617 of file qtimeline.cpp.

Referenced by setCurveShape().

618 {
619  Q_D(QTimeLine);
620  d->easingCurve = curve;
621 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTimeLine class provides a timeline for controlling animations.
Definition: qtimeline.h:55

◆ setEndFrame()

void QTimeLine::setEndFrame ( int  frame)

Sets the end frame, which is the frame corresponding to the end of the timeline (i.e., the frame for which the current value is 1), to frame.

See also
endFrame(), startFrame(), setFrameRange()

Definition at line 486 of file qtimeline.cpp.

487 {
488  Q_D(QTimeLine);
489  d->endFrame = frame;
490 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTimeLine class provides a timeline for controlling animations.
Definition: qtimeline.h:55

◆ setFrameRange()

void QTimeLine::setFrameRange ( int  startFrame,
int  endFrame 
)

Sets the timeline's frame counter to start at startFrame, and end and endFrame.

For each time value, QTimeLine will find the corresponding frame when you call currentFrame() or frameForTime() by interpolating, using the return value of valueForTime().

When in Running state, QTimeLine also emits the frameChanged() signal when the frame changes.

See also
startFrame(), endFrame(), start(), currentFrame()

Definition at line 503 of file qtimeline.cpp.

504 {
505  Q_D(QTimeLine);
506  d->startFrame = startFrame;
507  d->endFrame = endFrame;
508 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTimeLine class provides a timeline for controlling animations.
Definition: qtimeline.h:55
int endFrame() const
Returns the end frame, which is the frame corresponding to the end of the timeline (i...
Definition: qtimeline.cpp:474
int startFrame() const
Returns the start frame, which is the frame corresponding to the start of the timeline (i...
Definition: qtimeline.cpp:450

◆ setLoopCount()

void QTimeLine::setLoopCount ( int  count)

Definition at line 381 of file qtimeline.cpp.

382 {
383  Q_D(QTimeLine);
384  d->totalLoopCount = count;
385 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTimeLine class provides a timeline for controlling animations.
Definition: qtimeline.h:55

◆ setPaused

void QTimeLine::setPaused ( bool  paused)
slot

If paused is true, the timeline is paused, causing QTimeLine to enter Paused state.

No updates will be signaled until either start() or setPaused(false) is called. If paused is false, the timeline is resumed and continues where it left.

See also
state(), start()

Definition at line 783 of file qtimeline.cpp.

784 {
785  Q_D(QTimeLine);
786  if (d->state == NotRunning) {
787  qWarning("QTimeLine::setPaused: Not running");
788  return;
789  }
790  if (paused && d->state != Paused) {
791  d->startTime = d->currentTime;
792  killTimer(d->timerId);
793  d->timerId = 0;
794  d->setState(Paused);
795  } else if (!paused && d->state == Paused) {
796  // Same as resume()
797  d->timerId = startTimer(d->updateInterval);
798  d->startTime = d->currentTime;
799  d->timer.start();
800  d->setState(Running);
801  }
802 }
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
Definition: qobject.cpp:1623
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTimeLine class provides a timeline for controlling animations.
Definition: qtimeline.h:55
Q_CORE_EXPORT void qWarning(const char *,...)
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650

◆ setStartFrame()

void QTimeLine::setStartFrame ( int  frame)

Sets the start frame, which is the frame corresponding to the start of the timeline (i.e., the frame for which the current value is 0), to frame.

See also
startFrame(), endFrame(), setFrameRange()

Definition at line 462 of file qtimeline.cpp.

463 {
464  Q_D(QTimeLine);
465  d->startFrame = frame;
466 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTimeLine class provides a timeline for controlling animations.
Definition: qtimeline.h:55

◆ setUpdateInterval()

void QTimeLine::setUpdateInterval ( int  interval)

Definition at line 529 of file qtimeline.cpp.

530 {
531  Q_D(QTimeLine);
532  d->updateInterval = interval;
533 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTimeLine class provides a timeline for controlling animations.
Definition: qtimeline.h:55

◆ start

void QTimeLine::start ( )
slot

Starts the timeline.

QTimeLine will enter Running state, and once it enters the event loop, it will update its current time, frame and value at regular intervals. The default interval is 40 ms (i.e., 25 times per second). You can change the update interval by calling setUpdateInterval().

The timeline will start from position 0, or the end if going backward. If you want to resume a stopped timeline without restarting, you can call resume() instead.

See also
resume(), updateInterval(), frameChanged(), valueChanged()

Definition at line 720 of file qtimeline.cpp.

721 {
722  Q_D(QTimeLine);
723  if (d->timerId) {
724  qWarning("QTimeLine::start: already running");
725  return;
726  }
727  int curTime = 0;
728  if (d->direction == Backward)
729  curTime = d->duration;
730  d->timerId = startTimer(d->updateInterval);
731  d->startTime = curTime;
732  d->currentLoopCount = 0;
733  d->timer.start();
734  d->setState(Running);
735  d->setCurrentTime(curTime);
736 }
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
Definition: qobject.cpp:1623
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTimeLine class provides a timeline for controlling animations.
Definition: qtimeline.h:55
Q_CORE_EXPORT void qWarning(const char *,...)

◆ startFrame()

int QTimeLine::startFrame ( ) const

Returns the start frame, which is the frame corresponding to the start of the timeline (i.e., the frame for which the current value is 0).

See also
setStartFrame(), setFrameRange()

Definition at line 450 of file qtimeline.cpp.

Referenced by setFrameRange().

451 {
452  Q_D(const QTimeLine);
453  return d->startFrame;
454 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTimeLine class provides a timeline for controlling animations.
Definition: qtimeline.h:55

◆ state()

QTimeLine::State QTimeLine::state ( ) const

Returns the state of the timeline.

See also
start(), setPaused(), stop()

Definition at line 359 of file qtimeline.cpp.

360 {
361  Q_D(const QTimeLine);
362  return d->state;
363 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTimeLine class provides a timeline for controlling animations.
Definition: qtimeline.h:55

◆ stateChanged

QTimeLine::stateChanged ( QTimeLine::State  newState)
signal

This signal is emitted whenever QTimeLine's state changes.

The new state is newState.

◆ stop

void QTimeLine::stop ( )
slot

Stops the timeline, causing QTimeLine to enter NotRunning state.

See also
start()

Definition at line 766 of file qtimeline.cpp.

Referenced by ~QTimeLine().

767 {
768  Q_D(QTimeLine);
769  if (d->timerId)
770  killTimer(d->timerId);
771  d->setState(NotRunning);
772  d->timerId = 0;
773 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTimeLine class provides a timeline for controlling animations.
Definition: qtimeline.h:55
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650

◆ timerEvent()

void QTimeLine::timerEvent ( QTimerEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QObject.

Definition at line 819 of file qtimeline.cpp.

820 {
821  Q_D(QTimeLine);
822  if (event->timerId() != d->timerId) {
823  event->ignore();
824  return;
825  }
826  event->accept();
827 
828  if (d->direction == Forward) {
829  d->setCurrentTime(d->startTime + d->timer.elapsed());
830  } else {
831  d->setCurrentTime(d->startTime - d->timer.elapsed());
832  }
833 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QTimeLine class provides a timeline for controlling animations.
Definition: qtimeline.h:55
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition: qcoreevent.h:346

◆ toggleDirection

void QTimeLine::toggleDirection ( )
slot

Toggles the direction of the timeline.

If the direction was Forward, it becomes Backward, and vice verca.

See also
setDirection()

Definition at line 810 of file qtimeline.cpp.

811 {
812  Q_D(QTimeLine);
813  setDirection(d->direction == Forward ? Backward : Forward);
814 }
double d
Definition: qnumeric_p.h:62
void setDirection(Direction direction)
Definition: qtimeline.cpp:406
#define Q_D(Class)
Definition: qglobal.h:2482
The QTimeLine class provides a timeline for controlling animations.
Definition: qtimeline.h:55

◆ updateInterval()

int QTimeLine::updateInterval ( ) const

Referenced by setFrameRange().

◆ valueChanged

QTimeLine::valueChanged ( qreal  value)
signal

QTimeLine emits this signal at regular intervals when in Running state, but only if the current value changes.

value is the current value. value is a number between 0.0 and 1.0

See also
QTimeLine::setDuration(), QTimeLine::valueForTime(), QTimeLine::updateInterval

◆ valueForTime()

qreal QTimeLine::valueForTime ( int  msec) const
virtual

Returns the timeline value for the time msec.

The returned value, which varies depending on the curve shape, is always between 0 and 1. If msec is 0, the default implementation always returns 0.

Reimplement this function to provide a custom curve shape for your timeline.

See also
CurveShape, frameForTime()

Definition at line 698 of file qtimeline.cpp.

Referenced by currentValue(), and frameForTime().

699 {
700  Q_D(const QTimeLine);
701  msec = qMin(qMax(msec, 0), d->duration);
702 
703  qreal value = msec / qreal(d->duration);
704  return d->easingCurve.valueForProgress(value);
705 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
#define Q_D(Class)
Definition: qglobal.h:2482
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
The QTimeLine class provides a timeline for controlling animations.
Definition: qtimeline.h:55

Properties

◆ currentTime

int QTimeLine::currentTime
private

the current time of the time line.

When QTimeLine is in Running state, this value is updated continuously as a function of the duration and direction of the timeline. Otherwise, it is value that was current when stop() was called last, or the value set by setCurrentTime().

By default, this property contains a value of 0.

Definition at line 60 of file qtimeline.h.

◆ curveShape

QTimeLine::CurveShape QTimeLine::curveShape
private

the shape of the timeline curve.

The curve shape describes the relation between the time and value for the base implementation of valueForTime().

If you have reimplemented valueForTime(), this value is ignored.

By default, this property is set to EaseInOutCurve .

See also
valueForTime()

Definition at line 63 of file qtimeline.h.

◆ direction

QTimeLine::Direction QTimeLine::direction
private

the direction of the timeline when QTimeLine is in Running state.

This direction indicates whether the time moves from 0 towards the timeline duration, or from the value of the duration and towards 0 after start() has been called.

By default, this property is set to Forward .

Definition at line 61 of file qtimeline.h.

◆ duration

int QTimeLine::duration
private

the total duration of the timeline in milliseconds.

By default, this value is 1000 (i.e., 1 second), but you can change this by either passing a duration to QTimeLine's constructor, or by calling setDuration(). The duration must be larger than 0.

Note
Changing the duration does not cause the current time to be reset to zero or the new duration. You also need to call setCurrentTime() with the desired value.

Definition at line 58 of file qtimeline.h.

◆ easingCurve

QEasingCurve QTimeLine::easingCurve
private

Specifies the easing curve that the timeline will use.

Since
4.6

If both easing curve and curveShape are set, the last set property will override the previous one. (If valueForTime() is reimplemented it will override both)

Definition at line 64 of file qtimeline.h.

◆ loopCount

int QTimeLine::loopCount
private

the number of times the timeline should loop before it's finished.

A loop count of of 0 means that the timeline will loop forever.

By default, this property contains a value of 1.

Definition at line 62 of file qtimeline.h.

◆ updateInterval

int QTimeLine::updateInterval
private

the time in milliseconds between each time QTimeLine updates its current time.

When updating the current time, QTimeLine will emit valueChanged() if the current value changed, and frameChanged() if the frame changed.

By default, the interval is 40 ms, which corresponds to a rate of 25 updates per second.

Definition at line 59 of file qtimeline.h.


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