From 3cdf8dc4c18cb4e4d2c0fe3908a03a51ff34ce04 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Thu, 27 Jun 2013 21:38:12 +0800 Subject: [PATCH] Correctly prevent time travel in planner Prior to this change the visual feedback (the handle that is drawn when the user moves the mouse while pressing the left mouse button) would not move to an illegal position (one that is impossible without time travel), but it the user moved the mouse to such an illegal position and then released the mouse button, we still added that illegal position to the plan. Signed-off-by: Dirk Hohndel --- qt-ui/diveplanner.cpp | 12 ++++++++---- qt-ui/diveplanner.h | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index c80b7c711..4b8dd84d9 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -5,7 +5,8 @@ #include #include "ui_diveplanner.h" -DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0) +DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0), + lastValidPos(0.0, 0.0) { setMouseTracking(true); setScene(new QGraphicsScene()); @@ -213,18 +214,22 @@ void DivePlannerGraphics::moveActiveHandler(const QPointF& pos) if (idx == 0 ) { // first if (newPos.x() < handles[1]->x()) { activeDraggedHandler->setPos(newPos); + lastValidPos = newPos; } } else if (idx == handles.count()-1) { // last if (newPos.x() > handles[idx-1]->x()) { activeDraggedHandler->setPos(newPos); + lastValidPos = newPos; } } else { // middle if (newPos.x() > handles[idx-1]->x() && newPos.x() < handles[idx+1]->x()) { activeDraggedHandler->setPos(newPos); + lastValidPos = newPos; } } } else { activeDraggedHandler->setPos(newPos); + lastValidPos = newPos; } qDeleteAll(lines); lines.clear(); @@ -260,9 +265,8 @@ void DivePlannerGraphics::mousePressEvent(QMouseEvent* event) void DivePlannerGraphics::mouseReleaseEvent(QMouseEvent* event) { if (activeDraggedHandler) { - QPointF mappedPos = mapToScene(event->pos()); - activeDraggedHandler->sec = rint(timeLine->valueAt(mappedPos)) * 60; - activeDraggedHandler->mm = rint(depthLine->valueAt(mappedPos)) * 1000; + activeDraggedHandler->sec = rint(timeLine->valueAt(lastValidPos)) * 60; + activeDraggedHandler->mm = rint(depthLine->valueAt(lastValidPos)) * 1000; activeDraggedHandler->setBrush(QBrush()); createDecoStops(); activeDraggedHandler = 0; diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 4553c3b94..8669217a1 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -87,6 +87,7 @@ private: Button *lessTime; Button *lessDepth; + QPointF lastValidPos; }; namespace Ui{