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>
This commit is contained in:
Tomaz Canabrava 2013-06-20 15:15:10 -03:00
parent 607f82ade3
commit 52a0e6c82d
2 changed files with 48 additions and 19 deletions

View file

@ -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()

View file

@ -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;