aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-07-04 10:29:28 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-07-04 10:29:28 -0300
commit20ec98f2a5e31a91cc779666fa72ac2961bc87df (patch)
treee2e5e8eaef38c2fd07b44103218e23ebf61617e0
parent603d2f5cb3c748bbb64711a99d1c115f6407d09e (diff)
downloadsubsurface-20ec98f2a5e31a91cc779666fa72ac2961bc87df.tar.gz
Make it possible to drag a handle between handlers
Make it possible to drag a handle between handlers, this way the configuration of the dive is more acurate and easyer to make. I'v discovered a problem where it's a bit hard to 'grab' the handler, investigating it now. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
-rw-r--r--qt-ui/diveplanner.cpp53
-rw-r--r--qt-ui/diveplanner.h6
2 files changed, 26 insertions, 33 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index d4c6e9561..5de5ffe6b 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -22,8 +22,7 @@ bool handlerLessThenMinutes(DiveHandler *d1, DiveHandler *d2){
return d1->sec < d2->sec;
}
-DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0),
- lastValidPos(0.0, 0.0)
+DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0)
{
fill_profile_color();
setBackgroundBrush(profile_color[BACKGROUND].at(0));
@@ -185,7 +184,6 @@ void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event)
item->setPos(QPointF(xpos, ypos));
scene()->addItem(item);
handles << item;
- qSort(handles.begin(), handles.end(), handlerLessThenMinutes);
createDecoStops();
}
@@ -193,6 +191,7 @@ void DivePlannerGraphics::createDecoStops()
{
qDeleteAll(lines);
lines.clear();
+ qSort(handles.begin(), handles.end(), handlerLessThenMinutes);
// This needs to be done in the following steps:
// Get the user-input and calculate the dive info
@@ -340,33 +339,9 @@ void DivePlannerGraphics::mouseMoveEvent(QMouseEvent* event)
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);
- // do not allow it to move between handlers.
- if (handles.count() > 1) {
- 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;
- }
+ activeDraggedHandler->setPos(QPointF(xpos, ypos));
qDeleteAll(lines);
lines.clear();
}
@@ -393,6 +368,7 @@ void DivePlannerGraphics::mousePressEvent(QMouseEvent* event)
if (DiveHandler *h = qgraphicsitem_cast<DiveHandler*>(item)) {
activeDraggedHandler = h;
activeDraggedHandler->setBrush(Qt::red);
+ originalHandlerPos = activeDraggedHandler->pos();
}
}
QGraphicsView::mousePressEvent(event);
@@ -401,9 +377,26 @@ void DivePlannerGraphics::mousePressEvent(QMouseEvent* event)
void DivePlannerGraphics::mouseReleaseEvent(QMouseEvent* event)
{
if (activeDraggedHandler) {
- activeDraggedHandler->sec = rint(timeLine->valueAt(lastValidPos)) * 60;
- activeDraggedHandler->mm = rint(depthLine->valueAt(lastValidPos)) * 1000;
+ QPointF mappedPos = mapToScene(event->pos());
+ int minutes = rint(timeLine->valueAt(mappedPos));
+ int meters = rint(depthLine->valueAt(mappedPos));
+ double xpos = timeLine->posAtValue(minutes);
+ double ypos = depthLine->posAtValue(meters);
+ Q_FOREACH(DiveHandler* handler, handles){
+ if (xpos == handler->pos().x() && handler != activeDraggedHandler){
+ qDebug() << "There's already an point at that place.";
+ //TODO: Move this later to a KMessageWidget.
+ activeDraggedHandler->setPos(originalHandlerPos);
+ activeDraggedHandler = NULL;
+ return;
+ }
+ }
+
+ activeDraggedHandler->sec = rint(timeLine->valueAt(mappedPos)) * 60;
+ activeDraggedHandler->mm = rint(depthLine->valueAt(mappedPos)) * 1000;
activeDraggedHandler->setBrush(QBrush(Qt::white));
+ activeDraggedHandler->setPos(QPointF(xpos, ypos));
+
createDecoStops();
activeDraggedHandler = 0;
}
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index e9dfd91e9..547e38727 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -73,7 +73,6 @@ protected:
bool isPointOutOfBoundaries(const QPointF& point);
void deleteTemporaryDivePlan(struct divedatapoint* dp);
qreal fromPercent(qreal percent, Qt::Orientation orientation);
-
private slots:
void increaseTime();
void increaseDepth();
@@ -96,8 +95,9 @@ private:
/* This is the handler that's being dragged. */
DiveHandler *activeDraggedHandler;
- // helper to save the positions where the drag-handler is valid.
- QPointF lastValidPos;
+ // When we start to move the handler, this pos is saved.
+ // so we can revert it later.
+ QPointF originalHandlerPos;
/* this is the background of the dive, the blue-gradient. */
QGraphicsPolygonItem *diveBg;