aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntti Määttä <antti.maatta@qt.io>2021-11-22 13:32:14 +0200
committerAntti Määttä <antti.maatta@qt.io>2021-12-02 05:32:45 +0000
commiteadc9cb0e3f7c007c79e01dd96e4bd0a56066f3b (patch)
tree11ec8d1d39f72d70008bc2f4d8797c69958160d0
parentbeb167a963b1d9161c26769aa08be4670206249e (diff)
Improve particle system animation driver
- Do not automatically restart particle system animation when pressing the restart button if the animation is paused. - Use own QElapsedTimer in AnimationDriver and properly handle animation driver pausing. Change-Id: Ic2924fb66fddffb8878625be8fa766f06219ca61 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/instances/animationdriver.cpp13
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/instances/animationdriver.h27
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp14
-rw-r--r--src/plugins/qmldesigner/components/edit3d/edit3dview.cpp8
4 files changed, 39 insertions, 23 deletions
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/animationdriver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/animationdriver.cpp
index 4f32513b7e..d8ef223104 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/animationdriver.cpp
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/animationdriver.cpp
@@ -31,8 +31,6 @@ AnimationDriver::AnimationDriver(QObject *parent)
{
setProperty("allowNegativeDelta", true);
install();
- connect(this, SIGNAL(started()), this, SLOT(startTimer()));
- connect(this, SIGNAL(stopped()), this, SLOT(stopTimer()));
}
AnimationDriver::~AnimationDriver()
@@ -49,10 +47,13 @@ void AnimationDriver::timerEvent(QTimerEvent *e)
// Provide same time for all users
if (m_seekerEnabled) {
m_seekerElapsed += (m_seekerPos * 100) / 30;
- if (m_seekerElapsed + m_elapsed < -100) // -100 to allow small negative value
- m_seekerElapsed = -m_elapsed - 100;
+ if (m_seekerElapsed + m_elapsed - m_pauseTime < -100) // -100 to allow small negative value
+ m_seekerElapsed = -(m_elapsed - m_pauseTime) - 100;
} else {
- m_elapsed = QAnimationDriver::elapsed();
+ if (!m_elapsedTimer.isValid())
+ m_elapsedTimer.restart();
+ else
+ m_elapsed = m_elapsedTimer.elapsed();
}
m_delta = elapsed() - old;
advance();
@@ -75,7 +76,7 @@ void AnimationDriver::setSeekerPosition(int position)
return;
if (!m_timer.isActive())
- restart();
+ startTimer();
m_seekerPos = position;
}
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/animationdriver.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/animationdriver.h
index f4f50f0afc..e8e84d7dfd 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/animationdriver.h
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/animationdriver.h
@@ -27,6 +27,7 @@
#include <qabstractanimation.h>
#include <QtCore/qbasictimer.h>
+#include <QtCore/qelapsedtimer.h>
#include <QtCore/qmath.h>
class AnimationDriver : public QAnimationDriver
@@ -46,17 +47,34 @@ public:
}
void reset()
{
- stop();
+ m_elapsedTimer.invalidate();
+ m_pauseBegin = 0;
+ m_pauseTime = 0;
+ m_elapsed = 0;
+ m_seekerElapsed = 0;
stopTimer();
}
void restart()
{
- start();
+ m_pauseTime = 0;
+ m_elapsed = 0;
+ m_seekerElapsed = 0;
+ startTimer();
+ }
+ void pause()
+ {
+ m_pauseBegin = m_elapsedTimer.elapsed();
+ stopTimer();
+ }
+ void play()
+ {
+ if (m_elapsedTimer.isValid())
+ m_pauseTime += m_elapsedTimer.elapsed() - m_pauseBegin;
startTimer();
}
qint64 elapsed() const override
{
- return m_elapsed + m_seekerElapsed;
+ return m_elapsed + m_seekerElapsed - m_pauseTime;
}
void setSeekerPosition(int position);
void setSeekerEnabled(bool enable)
@@ -79,10 +97,13 @@ private:
Q_SLOT void stopTimer();
QBasicTimer m_timer;
+ QElapsedTimer m_elapsedTimer;
int m_interval = 16;
int m_seekerPos = 0;
bool m_seekerEnabled = false;
qint64 m_elapsed = 0;
qint64 m_seekerElapsed = 0;
qint64 m_delta = 0;
+ qint64 m_pauseTime = 0;
+ qint64 m_pauseBegin = 0;
};
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp
index afc4adcae0..16dc3dbe5f 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp
@@ -2078,21 +2078,21 @@ void Qt5InformationNodeInstanceServer::view3DAction(const View3DActionCommand &c
m_particleAnimationPlaying = command.isEnabled();
updatedState.insert("particlePlay", command.isEnabled());
if (m_particleAnimationPlaying) {
- m_particleAnimationDriver->reset();
- m_particleAnimationDriver->restart();
+ m_particleAnimationDriver->play();
m_particleAnimationDriver->setSeekerEnabled(false);
m_particleAnimationDriver->setSeekerPosition(0);
} else {
- m_particleAnimationDriver->reset();
+ m_particleAnimationDriver->pause();
m_particleAnimationDriver->setSeekerEnabled(true);
}
break;
case View3DActionCommand::ParticlesRestart:
resetParticleSystem();
- m_particleAnimationPlaying = true;
- m_particleAnimationDriver->restart();
- m_particleAnimationDriver->setSeekerEnabled(false);
- m_particleAnimationDriver->setSeekerPosition(0);
+ if (m_particleAnimationPlaying) {
+ m_particleAnimationDriver->restart();
+ m_particleAnimationDriver->setSeekerEnabled(false);
+ m_particleAnimationDriver->setSeekerPosition(0);
+ }
break;
case View3DActionCommand::ParticlesSeek:
m_particleAnimationDriver->setSeekerPosition(static_cast<const View3DSeekActionCommand &>(command).position());
diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp b/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp
index 1c944f49a9..ba5ac595fb 100644
--- a/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp
+++ b/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp
@@ -305,12 +305,6 @@ void Edit3DView::createEdit3DActions()
resetPuppet();
};
- SelectionContextOperation particlesRestartTrigger = [this](const SelectionContext &) {
- m_particlesPlayAction->action()->setChecked(true);
- if (m_seeker)
- m_seeker->setEnabled(false);
- };
-
SelectionContextOperation particlesPlayTrigger = [this](const SelectionContext &) {
if (m_seeker)
m_seeker->setEnabled(!m_particlesPlayAction->action()->isChecked());
@@ -334,7 +328,7 @@ void Edit3DView::createEdit3DActions()
QmlDesigner::Constants::EDIT3D_PARTICLES_RESTART, View3DActionCommand::ParticlesRestart,
QCoreApplication::translate("ParticlesRestartAction", "Restart Particles"),
QKeySequence(Qt::Key_E), false, false, Icons::EDIT3D_PARTICLE_RESTART.icon(),
- Icons::EDIT3D_PARTICLE_RESTART.icon(), particlesRestartTrigger);
+ Icons::EDIT3D_PARTICLE_RESTART.icon());
m_particlesPlayAction->action()->setEnabled(particlemode);
m_particlesRestartAction->action()->setEnabled(particlemode);
m_resetAction