diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index d64eab18f..9fead0191 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -98,24 +98,8 @@ void DivePlanner::mouseMoveEvent(QMouseEvent* event) verticalLine->setLine(mappedPos.x(), 0, mappedPos.x(), 100); horizontalLine->setLine(0, mappedPos.y(), 100, mappedPos.y()); - if (activeDraggedHandler){ - int idx = handles.indexOf(activeDraggedHandler); - activeDraggedHandler->setPos(mappedPos); - if (activeDraggedHandler->from){ - QLineF f = activeDraggedHandler->from->line(); - activeDraggedHandler->from->setLine(f.x1(), f.y1(), mappedPos.x(), mappedPos.y()); - } - - if(activeDraggedHandler == handles.last()){ - clear_generated_deco(); - create_deco_stop(); - } - - if (activeDraggedHandler->to){ - QLineF f = activeDraggedHandler->to->line(); - activeDraggedHandler->to->setLine(mappedPos.x(), mappedPos.y(), f.x2(), f.y2()); - } - } + if(activeDraggedHandler) + moveActiveHandler(mappedPos); if (!handles.count()) return; @@ -129,6 +113,50 @@ void DivePlanner::mouseMoveEvent(QMouseEvent* event) } } +void DivePlanner::moveActiveHandler(QPointF pos) +{ + int idx = handles.indexOf(activeDraggedHandler); + bool moveLines = false;; + // do not allow it to move between handlers. + if (handles.count() > 1){ + if (idx == 0 ){ // first + if (pos.x() < handles[1]->x()){ + activeDraggedHandler->setPos(pos); + moveLines = true; + } + }else if (idx == handles.count()-1){ // last + if (pos.x() > handles[idx-1]->x()){ + activeDraggedHandler->setPos(pos); + moveLines = true; + } + }else{ // middle + if (pos.x() > handles[idx-1]->x() && pos.x() < handles[idx+1]->x()){ + activeDraggedHandler->setPos(pos); + moveLines = true; + } + } + }else{ + activeDraggedHandler->setPos(pos); + moveLines = true; + } + if (moveLines){ + if (activeDraggedHandler->from){ + QLineF f = activeDraggedHandler->from->line(); + activeDraggedHandler->from->setLine(f.x1(), f.y1(), pos.x(), pos.y()); + } + + if (activeDraggedHandler->to){ + QLineF f = activeDraggedHandler->to->line(); + activeDraggedHandler->to->setLine(pos.x(), pos.y(), f.x2(), f.y2()); + } + + if(activeDraggedHandler == handles.last()){ + clear_generated_deco(); + create_deco_stop(); + } + } +} + bool DivePlanner::isPointOutOfBoundaries(QPointF point) { if (point.x() > sceneRect().width() diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index db94900c1..48f254bcd 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -22,13 +22,14 @@ protected: virtual void mouseMoveEvent(QMouseEvent* event); virtual void mousePressEvent(QMouseEvent* event); virtual void mouseReleaseEvent(QMouseEvent* event); - + void clear_generated_deco(); void create_deco_stop(); bool isPointOutOfBoundaries(QPointF point); private: DivePlanner(QWidget* parent = 0); + void moveActiveHandler(QPointF pos); QList lines; QList handles; QGraphicsLineItem *verticalLine;