From 710e5d87d285ac4d3123597fe012ba7951d6542f Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Thu, 11 Feb 2016 03:11:06 -0200 Subject: TransitionControl: only rewind when needed. --- transitioncontrol.cpp | 14 ++++++++++---- transitioncontrol.h | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/transitioncontrol.cpp b/transitioncontrol.cpp index cf8f644..bd85405 100644 --- a/transitioncontrol.cpp +++ b/transitioncontrol.cpp @@ -11,6 +11,7 @@ static const Qt::MouseButton MOUSE_BUTTON = Qt::MiddleButton; TransitionControl::TransitionControl() : m_t(1.0) , m_startPos(-1) + , m_shouldRewind(false) { } @@ -41,6 +42,7 @@ void TransitionControl::mouseMoveEvent(QMouseEvent *event) return; } + m_shouldRewind = true; m_t = double(x) / m_startPos; emit tChanged(m_t); } @@ -54,8 +56,12 @@ void TransitionControl::mouseReleaseEvent(QMouseEvent *event) // Back to initial state m_startPos = -1; - // We now have to smoothly go back to m_t == 1.0 - m_rewindThread = new RewindWorkerThread(this); - connect(m_rewindThread, &QThread::finished, m_rewindThread, &QObject::deleteLater); - m_rewindThread->start(); + if (m_shouldRewind) { + m_shouldRewind = false; + + // We now have to smoothly go back to m_t == 1.0 + m_rewindThread = new RewindWorkerThread(this); + connect(m_rewindThread, &QThread::finished, m_rewindThread, &QObject::deleteLater); + m_rewindThread->start(); + } } diff --git a/transitioncontrol.h b/transitioncontrol.h index ac84786..4c76e8c 100644 --- a/transitioncontrol.h +++ b/transitioncontrol.h @@ -34,6 +34,8 @@ private: // The x pos where interaction started int m_startPos; + bool m_shouldRewind; + // Controls the smooth rewind transition QThread *m_rewindThread; }; -- cgit v1.2.3