?? qtimeline.cpp
字號:
d->startTime = d->currentTime; d->timer.start();}/*! \property QTimeLine::duration \brief 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().*/int QTimeLine::duration() const{ Q_D(const QTimeLine); return d->duration;}void QTimeLine::setDuration(int duration){ Q_D(QTimeLine); d->duration = duration;}/*! 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). \sa setStartFrame(), setFrameRange()*/int QTimeLine::startFrame() const{ Q_D(const QTimeLine); return d->startFrame;}/*! 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 \a frame. \sa startFrame(), endFrame(), setFrameRange()*/void QTimeLine::setStartFrame(int frame){ Q_D(QTimeLine); d->startFrame = frame;}/*! 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). \sa setEndFrame(), setFrameRange()*/int QTimeLine::endFrame() const{ Q_D(const QTimeLine); return d->endFrame;}/*! 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 \a frame. \sa endFrame(), startFrame(), setFrameRange()*/void QTimeLine::setEndFrame(int frame){ Q_D(QTimeLine); d->endFrame = frame;}/*! Sets the timeline's frame counter to start at \a startFrame, and end and \a 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. \sa startFrame(), endFrame(), start(), currentFrame()*/void QTimeLine::setFrameRange(int startFrame, int endFrame){ Q_D(QTimeLine); d->startFrame = startFrame; d->endFrame = endFrame;}/*! \property QTimeLine::updateInterval \brief 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 QTimeLine::updateInterval() const{ Q_D(const QTimeLine); return d->updateInterval;}void QTimeLine::setUpdateInterval(int interval){ Q_D(QTimeLine); d->updateInterval = interval;}/*! \property QTimeLine::curveShape \brief 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. \sa valueForTime()*/QTimeLine::CurveShape QTimeLine::curveShape() const{ Q_D(const QTimeLine); return d->curveShape;}void QTimeLine::setCurveShape(CurveShape shape){ Q_D(QTimeLine); d->curveShape = shape;}/*! \property QTimeLine::currentTime \brief 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 QTimeLine::currentTime() const{ Q_D(const QTimeLine); return d->currentTime;}void QTimeLine::setCurrentTime(int msec){ Q_D(QTimeLine); d->startTime = 0; d->timer.restart(); d->setCurrentTime(msec);}/*! Returns the frame corresponding to the current time. \sa currentTime(), frameForTime(), setFrameRange()*/int QTimeLine::currentFrame() const{ Q_D(const QTimeLine); return frameForTime(d->currentTime);}/*! Returns the value corresponding to the current time. \sa valueForTime(), currentFrame()*/qreal QTimeLine::currentValue() const{ Q_D(const QTimeLine); return valueForTime(d->currentTime);}/*! Returns the frame corresponding to the time \a msec. This value is calculated using a linear interpolation of the start and end frame, based on the value returned by valueForTime(). \sa valueForTime(), setFrameRange()*/int QTimeLine::frameForTime(int msec) const{ Q_D(const QTimeLine); return d->startFrame + int((d->endFrame - d->startFrame) * valueForTime(msec));}/*! Returns the timeline value for the time \a msec. The returned value, which varies depending on the curve shape, is always between 0 and 1. If \a msec is 0, the default implementation always returns 0. Reimplement this function to provide a custom curve shape for your timeline. \sa CurveShape, frameForTime()*/qreal QTimeLine::valueForTime(int msec) const{ Q_D(const QTimeLine); msec = qMin(qMax(msec, 0), d->duration); // Simple linear interpolation qreal value = msec / qreal(d->duration); switch (d->curveShape) { case EaseInOutCurve: value = qt_sinProgress(value); break; // SmoothBegin blends Smooth and Linear Interpolation. // Progress 0 - 0.3 : Smooth only // Progress 0.3 - ~ 0.5 : Mix of Smooth and Linear // Progress ~ 0.5 - 1 : Linear only case EaseInCurve: { const qreal sinProgress = qt_sinProgress(value); const qreal linearProgress = value; const qreal mix = qt_smoothBeginEndMixFactor(value); value = sinProgress * mix + linearProgress * (1.0 - mix); break; } case EaseOutCurve: { const qreal sinProgress = qt_sinProgress(value); const qreal linearProgress = value; const qreal mix = qt_smoothBeginEndMixFactor(1.0 - value); value = sinProgress * mix + linearProgress * (1.0 - mix); break; } case SineCurve: value = (::sin(((msec * pi * 2) / d->duration) - pi/2.0) + 1.0) / 2.0; break; default: break; } return value;}/*! 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(). \sa updateInterval(), frameChanged(), valueChanged()*/void QTimeLine::start(){ Q_D(QTimeLine); if (d->timerId) { qWarning("QTimeLine::start: already running"); return; } if (d->currentTime == d->duration && d->direction == Forward) d->currentTime = 0; else if (d->currentTime == 0 && d->direction == Backward) d->currentTime = d->duration; d->timerId = startTimer(d->updateInterval); d->startTime = d->currentTime; d->timer.start(); d->setState(Running);}/*! Stops the timeline, causing QTimeLine to enter NotRunning state. \sa start()*/void QTimeLine::stop(){ Q_D(QTimeLine); if (d->timerId) killTimer(d->timerId); d->setState(NotRunning); d->timerId = 0;}/*! If \a 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 \a paused is false, the timeline is resumed and continues where it left. \sa state(), start()*/void QTimeLine::setPaused(bool paused){ Q_D(QTimeLine); if (d->state == NotRunning) { qWarning("QTimeLine::setPaused: Not running"); return; } if (paused && d->state != Paused) { d->startTime = d->currentTime; killTimer(d->timerId); d->timerId = 0; d->setState(Paused); } else if (!paused && d->state == Paused) { d->timerId = startTimer(d->updateInterval); d->setState(Running); }}/*! Toggles the direction of the timeline. If the direction was Forward, it becomes Backward, and vice verca. \sa setDirection()*/void QTimeLine::toggleDirection(){ Q_D(QTimeLine); setDirection(d->direction == Forward ? Backward : Forward);}/*! \reimp*/void QTimeLine::timerEvent(QTimerEvent *event){ Q_D(QTimeLine); if (event->timerId() != d->timerId) { event->ignore(); return; } event->accept(); if (d->direction == Forward) { d->setCurrentTime(d->startTime + d->timer.elapsed()); } else { d->setCurrentTime(d->startTime - d->timer.elapsed()); }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -