summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-11-19 21:07:06 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-11-19 15:43:12 -0800
commit732f7a69b08e279c88f3ce7d946e986734d0e3f7 (patch)
tree71d226b3060d4c74266383699bca8d46323414fd
parent82ac9ef9c6062f06494a3725061ab7ae99c31e88 (diff)
downloadsubsurface-732f7a69b08e279c88f3ce7d946e986734d0e3f7.tar.gz
Better handle the mouse movements on the Add Dive profile
Better handle the mouse movements on the add dive profile, when outside of the canvas boundaries. It had bugged me for quite a while, but this is so much better. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-ui/diveplanner.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index f0dad6ca4..f772a1c28 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -557,16 +557,30 @@ void DivePlannerGraphics::showEvent(QShowEvent* event)
void DivePlannerGraphics::mouseMoveEvent(QMouseEvent* event)
{
QPointF mappedPos = mapToScene(event->pos());
- if (isPointOutOfBoundaries(mappedPos))
- return;
- verticalLine->setPos(mappedPos.x(), fromPercent(0, Qt::Vertical));
- horizontalLine->setPos(fromPercent(0, Qt::Horizontal), mappedPos.y());
+
+ double xpos = timeLine->valueAt(mappedPos);
+ double ypos = depthLine->valueAt(mappedPos);
+
+ xpos = (xpos > timeLine->maximum()) ? timeLine->posAtValue(timeLine->maximum())
+ : (xpos < timeLine->minimum()) ? timeLine->posAtValue(timeLine->minimum())
+ : timeLine->posAtValue(xpos);
+
+ ypos = (ypos > depthLine->maximum()) ? depthLine->posAtValue(depthLine->maximum())
+ : ( ypos < depthLine->minimum()) ? depthLine->posAtValue(depthLine->minimum())
+ : depthLine->posAtValue(ypos);
+
+ verticalLine->setPos(xpos, fromPercent(0, Qt::Vertical));
+ horizontalLine->setPos(fromPercent(0, Qt::Horizontal), ypos);
+
+ depthString->setPos(fromPercent(1, Qt::Horizontal), ypos);
+ timeString->setPos(xpos+1, fromPercent(95, Qt::Vertical));
+
+ if(isPointOutOfBoundaries(mappedPos))
+ return;
depthString->setText(get_depth_string(depthLine->valueAt(mappedPos), true, false));
- depthString->setPos(fromPercent(1, Qt::Horizontal), mappedPos.y());
timeString->setText(QString::number(rint(timeLine->valueAt(mappedPos))) + "min");
- timeString->setPos(mappedPos.x()+1, fromPercent(95, Qt::Vertical));
// calculate the correct color for the depthString.
// QGradient doesn't returns it's interpolation, meh.