mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
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>
This commit is contained in:
parent
47e6e555cc
commit
3cdf8dc4c1
2 changed files with 9 additions and 4 deletions
|
@ -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;
|
||||
|
|
|
@ -87,6 +87,7 @@ private:
|
|||
Button *lessTime;
|
||||
Button *lessDepth;
|
||||
|
||||
QPointF lastValidPos;
|
||||
};
|
||||
|
||||
namespace Ui{
|
||||
|
|
Loading…
Reference in a new issue