diff options
Diffstat (limited to 'src/corelib/tools/qtimeline.cpp')
-rw-r--r-- | src/corelib/tools/qtimeline.cpp | 84 |
1 files changed, 25 insertions, 59 deletions
diff --git a/src/corelib/tools/qtimeline.cpp b/src/corelib/tools/qtimeline.cpp index 8a01dbe685..5512da867f 100644 --- a/src/corelib/tools/qtimeline.cpp +++ b/src/corelib/tools/qtimeline.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qtimeline.h" @@ -91,16 +55,16 @@ void QTimeLinePrivate::setCurrentTime(int msecs) { Q_Q(QTimeLine); currentTime.removeBindingUnlessInWrapper(); - auto previousCurrentTime = currentTime.value(); + const auto previousCurrentTime = currentTime.valueBypassingBindings(); - qreal lastValue = q->currentValue(); - int lastFrame = q->currentFrame(); + const qreal lastValue = q->valueForTime(previousCurrentTime); + const int lastFrame = q->frameForTime(previousCurrentTime); // Determine if we are looping. - int elapsed = (direction == QTimeLine::Backward) ? (-msecs + duration) : msecs; - int loopCountNow = elapsed / duration; + const int elapsed = (direction == QTimeLine::Backward) ? (-msecs + duration) : msecs; + const int loopCountNow = elapsed / duration; - bool looping = (loopCountNow != currentLoopCount); + const bool looping = (loopCountNow != currentLoopCount); #ifdef QTIMELINE_DEBUG qDebug() << "QTimeLinePrivate::setCurrentTime:" << msecs << duration << "with loopCountNow" << loopCountNow << "currentLoopCount" << currentLoopCount << "looping" << looping; @@ -111,7 +75,7 @@ void QTimeLinePrivate::setCurrentTime(int msecs) // Normalize msecs to be between 0 and duration, inclusive. currentTime.setValueBypassingBindings(elapsed % duration); if (direction.value() == QTimeLine::Backward) - currentTime.setValueBypassingBindings(duration - currentTime); + currentTime.setValueBypassingBindings(duration - currentTime.valueBypassingBindings()); // Check if we have reached the end of loopcount. bool finished = false; @@ -121,12 +85,14 @@ void QTimeLinePrivate::setCurrentTime(int msecs) currentLoopCount = loopCount - 1; } - int currentFrame = q->frameForTime(currentTime); + const int currentFrame = q->frameForTime(currentTime.valueBypassingBindings()); #ifdef QTIMELINE_DEBUG - qDebug() << "QTimeLinePrivate::setCurrentTime: frameForTime" << currentTime << currentFrame; + qDebug() << "QTimeLinePrivate::setCurrentTime: frameForTime" + << currentTime.valueBypassingBindings() << currentFrame; #endif - if (!qFuzzyCompare(lastValue, q->currentValue())) - emit q->valueChanged(q->currentValue(), QTimeLine::QPrivateSignal()); + const qreal currentValue = q->valueForTime(currentTime.valueBypassingBindings()); + if (!qFuzzyCompare(lastValue, currentValue)) + emit q->valueChanged(currentValue, QTimeLine::QPrivateSignal()); if (lastFrame != currentFrame) { const int transitionframe = (direction == QTimeLine::Forward ? endFrame : startFrame); if (looping && !finished && transitionframe != currentFrame) { @@ -159,7 +125,7 @@ void QTimeLinePrivate::setCurrentTime(int msecs) q->stop(); emit q->finished(QTimeLine::QPrivateSignal()); } - if (currentTime.value() != previousCurrentTime) + if (currentTime.valueBypassingBindings() != previousCurrentTime) currentTime.notify(); } QBindable<int> QTimeLine::bindableCurrentTime() @@ -326,7 +292,7 @@ QTimeLine::State QTimeLine::state() const \property QTimeLine::loopCount \brief 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. + A loop count of 0 means that the timeline will loop forever. By default, this property contains a value of 1. */ @@ -370,11 +336,12 @@ QTimeLine::Direction QTimeLine::direction() const void QTimeLine::setDirection(Direction direction) { Q_D(QTimeLine); - auto previousDirection = d->direction.value(); - d->direction.setValue(direction); + d->direction.removeBindingUnlessInWrapper(); + const auto previousDirection = d->direction.valueBypassingBindings(); + d->direction.setValueBypassingBindings(direction); d->startTime = d->currentTime; d->timer.start(); - if (previousDirection != d->direction.value()) + if (previousDirection != d->direction.valueBypassingBindings()) d->direction.notify(); } @@ -408,12 +375,11 @@ void QTimeLine::setDuration(int duration) qWarning("QTimeLine::setDuration: cannot set duration <= 0"); return; } - if (duration == d->duration) { - d->duration.removeBindingUnlessInWrapper(); - return; + d->duration.removeBindingUnlessInWrapper(); + if (duration != d->duration.valueBypassingBindings()) { + d->duration.setValueBypassingBindings(duration); + d->duration.notify(); } - d->duration.setValue(duration); - d->duration.notify(); } QBindable<int> QTimeLine::bindableDuration() |