Qt:Документация 4.3.2/qtimeline

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск
40px Внимание: Актуальная версия перевода документации находится здесь

__NOTOC__

Image:qt-logo.png

Главная · Все классы · Основные классы · Классы по группам · Модули · Функции

Image:trolltech-logo.png

Содержание

[править] QTimeLine Class Reference
[модуль QtCore ]

The QTimeLine class provides a timeline for controlling animations. Далее...

 #include <QTimeLine>

Inherits QObject.

Класс был добавлен в Qt 4.2.

[править] Открытые типы

  • enum CurveShape { EaseInCurve, EaseOutCurve, EaseInOutCurve, LinearCurve, SineCurve }
  • enum Direction { Forward, Backward }
  • enum State { NotRunning, Paused, Running }

[править] Свойства

  • 1 свойство, унаследованное от QObject

[править] Открытые функции

  • 29 открытых функций, унаследованных от QObject

[править] Открытые слоты

  • 1 открытый слот, унаследованный от QObject

[править] Сигналы

  • 1 сигнал, унаследованный от QObject

[править] Дополнительные унаследованные члены

  • 5 статических открытых членов, унаследованных от QObject
  • 7 защищенных функций, унаследованных от QObject

[править] Подробное описание

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().

Пример:

 ...
 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 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(). 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, and QGraphicsItemAnimation.


[править] Описание типов

[править]
enum QTimeLine::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.


Константа Значение Описание
QTimeLine::EaseInCurve 0 The value starts growing slowly, then increases in speed.
QTimeLine::EaseOutCurve 1 The value starts growing steadily, then ends slowly.
QTimeLine::EaseInOutCurve 2 The value starts growing slowly, the runs steadily, then grows slowly again.
QTimeLine::LinearCurve 3 The value grows linearly (e.g., if the duration is 1000 ms, the value at time 500 ms is 0.5).
QTimeLine::SineCurve 4 The value grows sinusoidally.

See also setCurveShape().

[править]
enum QTimeLine::Direction

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


Константа Значение Описание
QTimeLine::Forward 0 The current time of the timeline increases with time (i.e., moves from 0 and towards the end / duration).
QTimeLine::Backward 1 The current time of the timeline decreases with time (i.e., moves from the end / duration and towards 0).

See also setDirection().

[править]
enum QTimeLine::State

This enum describes the state of the timeline.


Константа Значение Описание
QTimeLine::NotRunning 0 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().
QTimeLine::Paused 1 The timeline is paused (i.e., temporarily suspended). Calling setPaused(false) will resume timeline activity.
QTimeLine::Running 2 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() and stateChanged().


[править] Описание cвойств

[править]
currentTime : int

This property holds 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().

Функции доступа:

  • int currentTime () const
  • void setCurrentTime ( int msec )

[править]
curveShape : CurveShape

This property holds 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.

Функции доступа:

  • CurveShape curveShape () const
  • void setCurveShape ( CurveShape shape )

See also valueForTime().

[править]
direction : Direction

This property holds 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.

Функции доступа:

  • Direction direction () const
  • void setDirection ( Direction direction )

[править]
duration : int

This property holds 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.

Функции доступа:

  • int duration () const
  • void setDuration ( int duration )

[править]
loopCount : int

This property holds 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.

Функции доступа:

  • int loopCount () const
  • void setLoopCount ( int count )

[править]
updateInterval : int

This property holds 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.

Функции доступа:

  • int updateInterval () const
  • void setUpdateInterval ( int interval )

[править] Описание функций-членов

[править]
QTimeLine::QTimeLine ( int duration = 1000, QObject * parent = 0 )

Constructs a timeline with a duration of duration milliseconds. parent is passed to QObject's constructor. The default duration is 1000 milliseconds.

[править]
QTimeLine::~QTimeLine () [virtual]

Destroys the timeline.

[править]
int QTimeLine::currentFrame () const

Returns the frame corresponding to the current time.

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

[править]
qreal QTimeLine::currentValue () const

Returns the value corresponding to the current time.

See also valueForTime() and currentFrame().

[править]
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() and setFrameRange().

[править]
void QTimeLine::finished () [signal]

This signal is emitted when QTimeLine finishes (i.e., reaches the end of its time line), and does not loop.

[править]
void 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() and QTimeLine::updateInterval.

[править]
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() and setFrameRange().

[править]
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 is resumes.

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

[править]
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(), and 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(), and currentFrame().

[править]
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() and start().

[править]
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(), and setFrameRange().

[править]
void QTimeLine::start () [slot]

Starts or restarts 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().

If you want to resume a stopped timeline without restarting, you can call resume() instead.

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

[править]
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() and setFrameRange().

[править]
State QTimeLine::state () const

Returns the state of the timeline.

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

[править]
void QTimeLine::stateChanged ( QTimeLine::State newState ) [signal]

This signal is emitted whenever QTimeLine's state changes. The new state is newState.

[править]
void QTimeLine::stop () [slot]

Stops the timeline, causing QTimeLine to enter NotRunning state.

Смотрите также start().

[править]
void QTimeLine::toggleDirection () [slot]

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

See also setDirection().

[править]
void 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(), and QTimeLine::updateInterval.

[править]
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 and frameForTime().



Copyright © 2007 Trolltech Trademarks
Qt 4.3.2