Qt 4.8
|
The QTimeLine class provides a timeline for controlling animations. More...
#include <qtimeline.h>
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 QObjectList & | children () 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< QByteArray > | dynamicPropertyNames () 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 > | |
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 QMetaObject * | metaObject () 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 |
QObject * | parent () 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... | |
QThread * | thread () const |
Returns the thread in which the object lives. More... | |
QObjectUserData * | userData (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... | |
QObject * | sender () 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< QObjectData > | d_ptr |
Static Protected Variables inherited from QObject | |
static const QMetaObject | staticQtMetaObject |
Related Functions inherited from QObject | |
T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QRegExp ®Exp)() |
T * | qobject_cast (QObject *object) |
QObjectList | |
void * | qt_find_obj_child (QObject *parent, const char *type, const QString &name) |
Returns a pointer to the object named name that inherits type and with a given parent. More... | |
The QTimeLine class provides a timeline for controlling animations.
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:
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.
Definition at line 55 of file qtimeline.h.
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.
Enumerator | |
---|---|
EaseInCurve | |
EaseOutCurve | |
EaseInOutCurve | |
LinearCurve | |
SineCurve | |
CosineCurve |
Definition at line 75 of file qtimeline.h.
enum QTimeLine::Direction |
This enum describes the direction of the timeline when in Running state.
Enumerator | |
---|---|
Forward | |
Backward |
Definition at line 71 of file qtimeline.h.
enum QTimeLine::State |
This enum describes the state of the timeline.
Enumerator | |
---|---|
NotRunning | |
Paused | |
Running |
Definition at line 66 of file qtimeline.h.
|
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.
|
virtual |
Destroys the timeline.
Definition at line 346 of file qtimeline.cpp.
int QTimeLine::currentFrame | ( | ) | const |
Returns the frame corresponding to the current time.
Definition at line 656 of file qtimeline.cpp.
int QTimeLine::currentTime | ( | ) | const |
Referenced by setEasingCurve().
qreal QTimeLine::currentValue | ( | ) | const |
Returns the value corresponding to the current time.
Definition at line 667 of file qtimeline.cpp.
CurveShape QTimeLine::curveShape | ( | ) | const |
Referenced by setUpdateInterval().
Direction QTimeLine::direction | ( | ) | const |
Referenced by setDirection(), and setLoopCount().
int QTimeLine::duration | ( | ) | const |
Referenced by setDirection(), and setDuration().
QEasingCurve QTimeLine::easingCurve | ( | ) | const |
Referenced by setCurveShape().
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).
Definition at line 474 of file qtimeline.cpp.
Referenced by setFrameRange().
|
signal |
This signal is emitted when QTimeLine finishes (i.
e., reaches the end of its time line), and does not loop.
|
signal |
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().
Definition at line 680 of file qtimeline.cpp.
Referenced by currentFrame().
int QTimeLine::loopCount | ( | ) | const |
Referenced by state().
|
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.
Definition at line 748 of file qtimeline.cpp.
|
slot |
Definition at line 642 of file qtimeline.cpp.
void QTimeLine::setCurveShape | ( | CurveShape | shape | ) |
Definition at line 572 of file qtimeline.cpp.
void QTimeLine::setDirection | ( | Direction | direction | ) |
Definition at line 406 of file qtimeline.cpp.
Referenced by toggleDirection().
void QTimeLine::setDuration | ( | int | duration | ) |
Definition at line 434 of file qtimeline.cpp.
Referenced by QTimeLine().
void QTimeLine::setEasingCurve | ( | const QEasingCurve & | curve | ) |
Definition at line 617 of file qtimeline.cpp.
Referenced by setCurveShape().
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.
Definition at line 486 of file qtimeline.cpp.
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.
Definition at line 503 of file qtimeline.cpp.
void QTimeLine::setLoopCount | ( | int | count | ) |
Definition at line 381 of file qtimeline.cpp.
|
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.
Definition at line 783 of file qtimeline.cpp.
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.
Definition at line 462 of file qtimeline.cpp.
void QTimeLine::setUpdateInterval | ( | int | interval | ) |
Definition at line 529 of file qtimeline.cpp.
|
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.
Definition at line 720 of file qtimeline.cpp.
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).
Definition at line 450 of file qtimeline.cpp.
Referenced by setFrameRange().
QTimeLine::State QTimeLine::state | ( | ) | const |
Returns the state of the timeline.
Definition at line 359 of file qtimeline.cpp.
|
signal |
This signal is emitted whenever QTimeLine's state changes.
The new state is newState.
|
slot |
Stops the timeline, causing QTimeLine to enter NotRunning state.
Definition at line 766 of file qtimeline.cpp.
Referenced by ~QTimeLine().
|
protectedvirtual |
Reimplemented Function
Reimplemented from QObject.
Definition at line 819 of file qtimeline.cpp.
|
slot |
Toggles the direction of the timeline.
If the direction was Forward, it becomes Backward, and vice verca.
Definition at line 810 of file qtimeline.cpp.
int QTimeLine::updateInterval | ( | ) | const |
Referenced by setFrameRange().
|
signal |
|
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.
Definition at line 698 of file qtimeline.cpp.
Referenced by currentValue(), and frameForTime().
|
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.
|
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 .
Definition at line 63 of file qtimeline.h.
|
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.
|
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.
Definition at line 58 of file qtimeline.h.
|
private |
Specifies the easing curve that the timeline will use.
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.
|
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.
|
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.