diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-06-27 21:38:12 +0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-06-27 21:38:12 +0800 |
commit | 3cdf8dc4c18cb4e4d2c0fe3908a03a51ff34ce04 (patch) | |
tree | b2497f4c98da22b7730eff016f374b1344e5fce1 /qt-ui/diveplanner.cpp | |
parent | 47e6e555cc842f23e93f0f251e9aede36004289f (diff) | |
download | subsurface-3cdf8dc4c18cb4e4d2c0fe3908a03a51ff34ce04.tar.gz |
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 <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/diveplanner.cpp')
-rw-r--r-- | qt-ui/diveplanner.cpp | 12 |
1 files changed, 8 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 <QDebug> #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; |