aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-06-20 15:15:10 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-06-20 15:15:10 -0300
commit52a0e6c82d60076361fd0a3de7d2417c3fbc2e99 (patch)
tree788502f7339f09b4b37cbe546c35b7483f050ef4
parent607f82ade30e7d72370654a158e1d58f6444d67e (diff)
downloadsubsurface-52a0e6c82d60076361fd0a3de7d2417c3fbc2e99.tar.gz
Make the plan handlers to not move across other handlers.
This patch disables the hability to move handlers across the others, making a 'zigzag' in the time line. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
-rw-r--r--qt-ui/diveplanner.cpp64
-rw-r--r--qt-ui/diveplanner.h3
2 files changed, 48 insertions, 19 deletions
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<QGraphicsLineItem*> lines;
QList<DiveHandler *> handles;
QGraphicsLineItem *verticalLine;