aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-06-21 16:28:17 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-06-21 16:28:17 -0300
commit01d1a49d9448a2b4fd6363cf69260cc305b5e9f3 (patch)
tree7df9d41dd56045acdeab485532fe98a7e08e58d6 /qt-ui
parentc9159da43a5971d163340f3c2bb1e916952b8e1a (diff)
downloadsubsurface-01d1a49d9448a2b4fd6363cf69260cc305b5e9f3.tar.gz
Make the plot and handle movement stick to an 'Grid'
Make the plot and the handle stick to a grid, the grid is defined by the integers in the rulers, so a time of 10,2 is converted to 10, and will put the point at 10. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/diveplanner.cpp37
-rw-r--r--qt-ui/diveplanner.h4
2 files changed, 25 insertions, 16 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index d9179b038..5d907a627 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -1,4 +1,5 @@
#include "diveplanner.h"
+#include <cmath>
#include <QMouseEvent>
#include <QDebug>
#include "ui_diveplanner.h"
@@ -19,7 +20,7 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
timeLine = new Ruler();
timeLine->setMinimum(0);
- timeLine->setMaximum(60);
+ timeLine->setMaximum(20);
timeLine->setTickInterval(10);
timeLine->setLine( 10, 90, 99, 90);
timeLine->setOrientation(Qt::Horizontal);
@@ -28,7 +29,7 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
depthLine = new Ruler();
depthLine->setMinimum(0);
- depthLine->setMaximum(400);
+ depthLine->setMaximum(10);
depthLine->setTickInterval(10);
depthLine->setLine( 10, 1, 10, 90);
depthLine->setOrientation(Qt::Vertical);
@@ -57,7 +58,10 @@ void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event)
DiveHandler *item = new DiveHandler ();
item->setRect(-5,-5,10,10);
item->setFlag(QGraphicsItem::ItemIgnoresTransformations);
- item->setPos( mappedPos );
+
+ double xpos = timeLine->posAtValue(rint(timeLine->valueAt(mappedPos)));
+ double ypos = depthLine->posAtValue(rint(depthLine->valueAt(mappedPos)));
+ item->setPos( QPointF(xpos, ypos));
scene()->addItem(item);
handles << item;
@@ -164,41 +168,46 @@ void DivePlannerGraphics::mouseMoveEvent(QMouseEvent* event)
}
}
-void DivePlannerGraphics::moveActiveHandler(QPointF pos)
+void DivePlannerGraphics::moveActiveHandler(const QPointF& pos)
{
int idx = handles.indexOf(activeDraggedHandler);
+
+ double xpos = timeLine->posAtValue(rint(timeLine->valueAt(pos)));
+ double ypos = depthLine->posAtValue(rint(depthLine->valueAt(pos)));
+
+ QPointF newPos(xpos, ypos);
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);
+ if (newPos.x() < handles[1]->x()){
+ activeDraggedHandler->setPos(newPos);
moveLines = true;
}
}else if (idx == handles.count()-1){ // last
- if (pos.x() > handles[idx-1]->x()){
- activeDraggedHandler->setPos(pos);
+ if (newPos.x() > handles[idx-1]->x()){
+ activeDraggedHandler->setPos(newPos);
moveLines = true;
}
}else{ // middle
- if (pos.x() > handles[idx-1]->x() && pos.x() < handles[idx+1]->x()){
- activeDraggedHandler->setPos(pos);
+ if (newPos.x() > handles[idx-1]->x() && newPos.x() < handles[idx+1]->x()){
+ activeDraggedHandler->setPos(newPos);
moveLines = true;
}
}
}else{
- activeDraggedHandler->setPos(pos);
+ activeDraggedHandler->setPos(newPos);
moveLines = true;
}
if (moveLines){
if (activeDraggedHandler->from){
QLineF f = activeDraggedHandler->from->line();
- activeDraggedHandler->from->setLine(f.x1(), f.y1(), pos.x(), pos.y());
+ activeDraggedHandler->from->setLine(f.x1(), f.y1(), newPos.x(), newPos.y());
}
if (activeDraggedHandler->to){
QLineF f = activeDraggedHandler->to->line();
- activeDraggedHandler->to->setLine(pos.x(), pos.y(), f.x2(), f.y2());
+ activeDraggedHandler->to->setLine(newPos.x(), newPos.y(), f.x2(), f.y2());
}
if(activeDraggedHandler == handles.last()){
@@ -208,7 +217,7 @@ void DivePlannerGraphics::moveActiveHandler(QPointF pos)
}
}
-bool DivePlannerGraphics::isPointOutOfBoundaries(QPointF point)
+bool DivePlannerGraphics::isPointOutOfBoundaries(const QPointF& point)
{
double xpos = timeLine->valueAt(point);
double ypos = depthLine->valueAt(point);
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index ce4dd6d4f..621e8a2a5 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -51,11 +51,11 @@ protected:
void clear_generated_deco();
void create_deco_stop();
- bool isPointOutOfBoundaries(QPointF point);
+ bool isPointOutOfBoundaries(const QPointF& point);
private:
- void moveActiveHandler(QPointF pos);
+ void moveActiveHandler(const QPointF& pos);
QList<QGraphicsLineItem*> lines;
QList<DiveHandler *> handles;
QGraphicsLineItem *verticalLine;