42 #include <private/qproperty_p.h>
43 #include <private/qobject_p.h>
44 #include <QtCore/qcoreevent.h>
45 #include <QtCore/qmath.h>
46 #include <QtCore/qelapsedtimer.h>
59 void setDuration(
int duration) { q_func()->setDuration(duration); }
93 currentTime.removeBindingUnlessInWrapper();
94 auto previousCurrentTime = currentTime.value();
96 qreal lastValue =
q->currentValue();
97 int lastFrame =
q->currentFrame();
101 int loopCountNow = elapsed / duration;
104 #ifdef QTIMELINE_DEBUG
105 qDebug() <<
"QTimeLinePrivate::setCurrentTime:" << msecs << duration <<
"with loopCountNow"
106 << loopCountNow <<
"currentLoopCount" <<
currentLoopCount <<
"looping" << looping;
112 currentTime.setValueBypassingBindings(elapsed % duration);
114 currentTime.setValueBypassingBindings(duration - currentTime);
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(), QTimeLine::QPrivateSignal());
130 if (lastFrame != currentFrame) {
132 if (looping && !finished && transitionframe != currentFrame) {
133 #ifdef QTIMELINE_DEBUG
134 qDebug(
"QTimeLinePrivate::setCurrentTime: transitionframe");
136 emit q->frameChanged(transitionframe, QTimeLine::QPrivateSignal());
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, QTimeLine::QPrivateSignal());
160 emit q->finished(QTimeLine::QPrivateSignal());
162 if (currentTime.value() != previousCurrentTime)
163 currentTime.notify();
168 return &
d->currentTime;
348 return &
d->loopCount;
373 auto previousDirection =
d->direction.value();
375 d->startTime =
d->currentTime;
377 if (previousDirection !=
d->direction.value())
378 d->direction.notify();
384 return &
d->direction;
408 qWarning(
"QTimeLine::setDuration: cannot set duration <= 0");
412 d->duration.removeBindingUnlessInWrapper();
416 d->duration.notify();
434 return d->startFrame;
505 return d->updateInterval;
510 d->updateInterval = interval;
515 return &
d->updateInterval;
532 return d->easingCurve;
538 d->easingCurve = curve;
544 return &
d->easingCurve;
565 return d->currentTime;
571 d->currentLoopCount = 0;
573 d->setCurrentTime(msec);
609 return d->startFrame + int((
d->endFrame -
d->startFrame) *
valueForTime(msec));
626 msec = qBound(0, msec,
d->duration.value());
629 return d->easingCurve.value().valueForProgress(
value);
649 qWarning(
"QTimeLine::start: already running");
654 curTime =
d->duration;
656 d->startTime = curTime;
657 d->currentLoopCount = 0;
660 d->setCurrentTime(curTime);
677 qWarning(
"QTimeLine::resume: already running");
681 d->startTime =
d->currentTime;
712 qWarning(
"QTimeLine::setPaused: Not running");
715 if (paused &&
d->state !=
Paused) {
716 d->startTime =
d->currentTime;
720 }
else if (!paused &&
d->state ==
Paused) {
723 d->startTime =
d->currentTime;
749 if (
event->timerId() !=
d->timerId) {
756 d->setCurrentTime(
d->startTime +
d->timer.elapsed());
758 d->setCurrentTime(
d->startTime -
d->timer.elapsed());
764 #include "moc_qtimeline.cpp"
QBindable is a wrapper class around binding-enabled properties. It allows type-safe operations while ...
The QByteArray class provides an array of bytes.
const char * constData() const noexcept
bool isEmpty() const noexcept
static QByteArray number(int, int base=10)
The QEasingCurve class provides easing curves for controlling animation.
The QElapsedTimer class provides a fast way to calculate elapsed times.
The QObject class is the base class of all Qt objects.
int startTimer(int interval, Qt::TimerType timerType=Qt::CoarseTimer)
The QTimeLine class provides a timeline for controlling animations.
int currentTime
the current time of the time line.
int loopCount
the number of times the timeline should loop before it's finished.
void timerEvent(QTimerEvent *event) override
QTimeLine(int duration=1000, QObject *parent=nullptr)
qreal currentValue() const
void setPaused(bool paused)
int duration
the total duration of the timeline in milliseconds.
QBindable< int > bindableCurrentTime()
int frameForTime(int msec) const
void setEasingCurve(const QEasingCurve &curve)
void setUpdateInterval(int interval)
QBindable< QEasingCurve > bindableEasingCurve()
int updateInterval
the time in milliseconds between each time QTimeLine updates its current time.
QBindable< int > bindableLoopCount()
virtual qreal valueForTime(int msec) const
QBindable< int > bindableDuration()
void setLoopCount(int count)
void setDirection(Direction direction)
void setStartFrame(int frame)
Direction direction
the direction of the timeline when QTimeLine is in \l Running state.
QBindable< int > bindableUpdateInterval()
void setFrameRange(int startFrame, int endFrame)
void setCurrentTime(int msec)
QBindable< Direction > bindableDirection()
void setDuration(int duration)
void setEndFrame(int frame)
void setCurrentTimeForwardToQ(int time)
Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QTimeLinePrivate, int, duration, &QTimeLinePrivate::setDuration, 1000) int startFrame=0
void setDirection(QTimeLine::Direction direction)
Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QTimeLinePrivate, QEasingCurve, easingCurve, QEasingCurve::InOutSine) int startTime=0
void setCurrentTime(int msecs)
Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QTimeLinePrivate, int, currentTime, &QTimeLinePrivate::setCurrentTimeForwardToQ, 0) int timerId=0
void setDuration(int duration)
Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QTimeLinePrivate, QTimeLine::Direction, direction, &QTimeLinePrivate::setDirection, QTimeLine::Forward) QTimeLine void setState(QTimeLine::State newState)
The QTimerEvent class contains parameters that describe a timer event.
void newState(QList< State > &states, const char *token, const char *lexem, bool pre)
EGLOutputLayerEXT EGLint EGLAttrib value
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
QT_END_INCLUDE_NAMESPACE typedef double qreal
GLenum GLenum GLsizei count
GLdouble GLdouble GLdouble GLdouble q
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent