From 886bdd0fa43a2fcdeca306648b643b623af99f88 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Tue, 9 Feb 2016 17:38:28 -0200 Subject: Added TransitionControl and plot rewinding. New component overlays main view and handles middle clicks/drags to performing rewinding. Also sports smooth transitioning back to current projection whenever the mouse button is lifted. Next up, the same kind of transitions in the displayed values. --- transitioncontrol.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 transitioncontrol.cpp (limited to 'transitioncontrol.cpp') diff --git a/transitioncontrol.cpp b/transitioncontrol.cpp new file mode 100644 index 0000000..cf8f644 --- /dev/null +++ b/transitioncontrol.cpp @@ -0,0 +1,61 @@ +#include "transitioncontrol.h" + +#include +#include + +#include "rewindworkerthread.h" + +// The mouse button used for interaction +static const Qt::MouseButton MOUSE_BUTTON = Qt::MiddleButton; + +TransitionControl::TransitionControl() + : m_t(1.0) + , m_startPos(-1) +{ +} + +void TransitionControl::setT(double t) +{ + if (t < 0.0 || t > 1.0) { + return; + } + + m_t = t; + emit tChanged(m_t); +} + +void TransitionControl::mousePressEvent(QMouseEvent *event) +{ + if (event->button() != MOUSE_BUTTON) { + return; + } + + m_t = 1.0; + m_startPos = event->pos().x(); +} + +void TransitionControl::mouseMoveEvent(QMouseEvent *event) +{ + int x = event->pos().x(); + if (!(event->buttons() & MOUSE_BUTTON) || x > m_startPos || x < 0) { + return; + } + + m_t = double(x) / m_startPos; + emit tChanged(m_t); +} + +void TransitionControl::mouseReleaseEvent(QMouseEvent *event) +{ + if (event->button() != MOUSE_BUTTON) { + return; + } + + // 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(); +} -- cgit v1.2.3