44 #include <private/qobject_p.h> 45 #include <QtCore/qcoreevent.h> 46 #include <QtCore/qmath.h> 47 #include <QtCore/qelapsedtimer.h> 81 if (newState != state)
82 emit q->stateChanged(state = newState);
95 qreal lastValue = q->currentValue();
96 int lastFrame = q->currentFrame();
103 #ifdef QTIMELINE_DEBUG 104 qDebug() <<
"QTimeLinePrivate::setCurrentTime:" << msecs <<
duration <<
"with loopCount" << loopCount
106 <<
"looping" << looping;
117 bool finished =
false;
124 int currentFrame = q->frameForTime(currentTime);
125 #ifdef QTIMELINE_DEBUG 126 qDebug() <<
"QTimeLinePrivate::setCurrentTime: frameForTime" << currentTime << currentFrame;
129 emit q->valueChanged(q->currentValue());
130 if (lastFrame != currentFrame) {
132 if (looping && !finished && transitionframe != currentFrame) {
133 #ifdef QTIMELINE_DEBUG 134 qDebug() <<
"QTimeLinePrivate::setCurrentTime: transitionframe";
136 emit q->frameChanged(transitionframe);
138 #ifdef QTIMELINE_DEBUG 142 reason +=
" not looping";
146 reason +=
" finished";
148 if (transitionframe == currentFrame) {
151 reason +=
" transitionframe is equal to currentFrame: " +
QByteArray::number(currentFrame);
153 qDebug(
"QTimeLinePrivate::setCurrentTime: not transitionframe because %s", reason.
constData());
156 emit q->frameChanged(currentFrame);
379 return d->totalLoopCount;
384 d->totalLoopCount = count;
410 d->startTime =
d->currentTime;
438 qWarning(
"QTimeLine::setDuration: cannot set duration <= 0");
453 return d->startFrame;
465 d->startFrame = frame;
527 return d->updateInterval;
532 d->updateInterval = interval;
554 switch (
d->easingCurve.type()) {
614 return d->easingCurve;
620 d->easingCurve = curve;
640 return d->currentTime;
646 d->currentLoopCount = 0;
648 d->setCurrentTime(msec);
684 return d->startFrame + int((
d->endFrame -
d->startFrame) *
valueForTime(msec));
704 return d->easingCurve.valueForProgress(value);
724 qWarning(
"QTimeLine::start: already running");
729 curTime =
d->duration;
731 d->startTime = curTime;
732 d->currentLoopCount = 0;
735 d->setCurrentTime(curTime);
752 qWarning(
"QTimeLine::resume: already running");
756 d->startTime =
d->currentTime;
787 qWarning(
"QTimeLine::setPaused: Not running");
790 if (paused &&
d->state !=
Paused) {
791 d->startTime =
d->currentTime;
795 }
else if (!paused &&
d->state ==
Paused) {
798 d->startTime =
d->currentTime;
822 if (event->
timerId() !=
d->timerId) {
829 d->setCurrentTime(
d->startTime +
d->timer.elapsed());
831 d->setCurrentTime(
d->startTime -
d->timer.elapsed());
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
void start()
Starts the timeline.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
static double elapsed(qint64 after, qint64 before)
void setCurrentTime(int msec)
#define QT_END_NAMESPACE
This macro expands to.
The QEasingCurve class provides easing curves for controlling animation.
void setFrameRange(int startFrame, int endFrame)
Sets the timeline's frame counter to start at startFrame, and end and endFrame.
CurveShape
This enum describes the default shape of QTimeLine's value curve.
void setPaused(bool paused)
If paused is true, the timeline is paused, causing QTimeLine to enter Paused state.
The QByteArray class provides an array of bytes.
void setDirection(Direction direction)
void timerEvent(QTimerEvent *event)
Reimplemented Function
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.
void stop()
Stops the timeline, causing QTimeLine to enter NotRunning state.
State state() const
Returns the state of the timeline.
static Q_DECL_CONSTEXPR bool qFuzzyCompare(double p1, double p2)
State
This enum describes the state of the timeline.
int currentFrame() const
Returns the frame corresponding to the current time.
CurveShape curveShape() const
The QObject class is the base class of all Qt objects.
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
The QElapsedTimer class provides a fast way to calculate elapsed times.
virtual ~QTimeLine()
Destroys the timeline.
Direction direction() const
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
The QTimeLine class provides a timeline for controlling animations.
Q_CORE_EXPORT void qDebug(const char *,...)
int frameForTime(int msec) const
Returns the frame corresponding to the time msec.
#define QT_BEGIN_NAMESPACE
This macro expands to.
void setEasingCurve(const QEasingCurve &curve)
QTimeLine::Direction direction
Q_CORE_EXPORT void qWarning(const char *,...)
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
void setCurrentTime(int msecs)
void setUpdateInterval(int interval)
Direction
This enum describes the direction of the timeline when in Running state.
void setLoopCount(int count)
void setDuration(int duration)
const char * constData() const
Returns a pointer to the data stored in the byte array.
void toggleDirection()
Toggles the direction of the timeline.
#define Q_DECLARE_PUBLIC(Class)
int endFrame() const
Returns the end frame, which is the frame corresponding to the end of the timeline (i...
The QTimerEvent class contains parameters that describe a timer event.
virtual qreal valueForTime(int msec) const
Returns the timeline value for the time msec.
qreal currentValue() const
Returns the value corresponding to the current time.
QEasingCurve easingCurve() const
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
QTimeLine(int duration=1000, QObject *parent=0)
Constructs a timeline with a duration of duration milliseconds.
int updateInterval() const
void resume()
Resumes the timeline from the current time.
void setState(QTimeLine::State newState)
void setCurveShape(CurveShape shape)
int startFrame() const
Returns the start frame, which is the frame corresponding to the start of the timeline (i...
static QByteArray number(int, int base=10)
Returns a byte array containing the string equivalent of the number n to base base (10 by default)...
void setStartFrame(int frame)
Sets the start frame, which is the frame corresponding to the start of the timeline (i...
void killTimer(int id)
Kills the timer with timer identifier, id.