From 7d96918246b866a0b4aac6b4dc70e4c049c0ada9 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Thu, 11 Feb 2016 16:12:21 -0200 Subject: RewindWorkerThread renamed to TransitionWorkerThread. Also, added easing curve customization. --- pm.pro | 4 ++-- rewindworkerthread.cpp | 23 ----------------------- rewindworkerthread.h | 21 --------------------- transitioncontrol.cpp | 4 ++-- transitionworkerthread.cpp | 35 +++++++++++++++++++++++++++++++++++ transitionworkerthread.h | 26 ++++++++++++++++++++++++++ 6 files changed, 65 insertions(+), 48 deletions(-) delete mode 100644 rewindworkerthread.cpp delete mode 100644 rewindworkerthread.h create mode 100644 transitionworkerthread.cpp create mode 100644 transitionworkerthread.h diff --git a/pm.pro b/pm.pro index 426cb23..5b91bc0 100644 --- a/pm.pro +++ b/pm.pro @@ -29,7 +29,7 @@ HEADERS += main.h \ historygraph.h \ barchart.h \ transitioncontrol.h \ - rewindworkerthread.h \ + transitionworkerthread.h \ manipulationhandler.h \ mapscalehandler.h \ numericrange.h \ @@ -51,7 +51,7 @@ SOURCES += main.cpp \ historygraph.cpp \ barchart.cpp \ transitioncontrol.cpp \ - rewindworkerthread.cpp \ + transitionworkerthread.cpp \ manipulationhandler.cpp \ mapscalehandler.cpp \ selectionhandler.cpp \ diff --git a/rewindworkerthread.cpp b/rewindworkerthread.cpp deleted file mode 100644 index f9fa999..0000000 --- a/rewindworkerthread.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "rewindworkerthread.h" - -// The full duration (usecs) of the restoration animation -static const double DURATION = 250000; - -// The time to wait (usecs) before the next animation tick -static const double TICK_TIME = DURATION / 60.0; - -// The amount to increase 't' per time step -static const double TICK_SIZE = TICK_TIME / DURATION; - -void RewindWorkerThread::run() -{ - double t = m_control->t(); - - while (t + TICK_SIZE < 1.0) { - t += TICK_SIZE; - m_control->setT(t); - QThread::usleep(TICK_TIME); - } - - m_control->setT(1.0); -} diff --git a/rewindworkerthread.h b/rewindworkerthread.h deleted file mode 100644 index 0bbaeb6..0000000 --- a/rewindworkerthread.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef REWINDWORKERTHREAD_H -#define REWINDWORKERTHREAD_H - -#include "transitioncontrol.h" - -#include -#include - -class RewindWorkerThread - : public QThread -{ - Q_OBJECT -public: - RewindWorkerThread(TransitionControl *control) { m_control = control; } - void run(); - -private: - TransitionControl *m_control; -}; - -#endif // REWINDWORKERTHREAD_H diff --git a/transitioncontrol.cpp b/transitioncontrol.cpp index bd85405..6d3f298 100644 --- a/transitioncontrol.cpp +++ b/transitioncontrol.cpp @@ -3,7 +3,7 @@ #include #include -#include "rewindworkerthread.h" +#include "transitionworkerthread.h" // The mouse button used for interaction static const Qt::MouseButton MOUSE_BUTTON = Qt::MiddleButton; @@ -60,7 +60,7 @@ void TransitionControl::mouseReleaseEvent(QMouseEvent *event) m_shouldRewind = false; // We now have to smoothly go back to m_t == 1.0 - m_rewindThread = new RewindWorkerThread(this); + m_rewindThread = new TransitionWorkerThread(this); connect(m_rewindThread, &QThread::finished, m_rewindThread, &QObject::deleteLater); m_rewindThread->start(); } diff --git a/transitionworkerthread.cpp b/transitionworkerthread.cpp new file mode 100644 index 0000000..2ee1d0e --- /dev/null +++ b/transitionworkerthread.cpp @@ -0,0 +1,35 @@ +#include "transitionworkerthread.h" + +// The full duration (usecs) of the restoration animation +static const double DURATION = 250000; + +// The time to wait (usecs) before the next animation tick +static const double TICK_TIME = DURATION / 60.0; + +// The amount to increase 't' per time step +static const double TICK_SIZE = TICK_TIME / DURATION; + +TransitionWorkerThread::TransitionWorkerThread(TransitionControl *control) + : m_control(control) +{ +} + +TransitionWorkerThread::TransitionWorkerThread(TransitionControl *control, + const QEasingCurve &easing) + : m_control(control) + , m_easing(easing) +{ +} + +void TransitionWorkerThread::run() +{ + double t = m_control->t(); + + while (t + TICK_SIZE < 1.0) { + t += TICK_SIZE; + m_control->setT(m_easing.valueForProgress(t)); + QThread::usleep(TICK_TIME); + } + + m_control->setT(1.0); +} diff --git a/transitionworkerthread.h b/transitionworkerthread.h new file mode 100644 index 0000000..b4d3e95 --- /dev/null +++ b/transitionworkerthread.h @@ -0,0 +1,26 @@ +#ifndef REWINDWORKERTHREAD_H +#define REWINDWORKERTHREAD_H + +#include "transitioncontrol.h" + +#include +#include +#include + +class TransitionWorkerThread + : public QThread +{ + Q_OBJECT +public: + TransitionWorkerThread(TransitionControl *control); + TransitionWorkerThread(TransitionControl *control, const QEasingCurve &easing); + + void setEasing(const QEasingCurve &easing); + void run(); + +private: + TransitionControl *m_control; + QEasingCurve m_easing; +}; + +#endif // REWINDWORKERTHREAD_H -- cgit v1.2.3