From 732f7a69b08e279c88f3ce7d946e986734d0e3f7 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 19 Nov 2013 21:07:06 -0200 Subject: 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 Signed-off-by: Dirk Hohndel --- qt-ui/diveplanner.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'qt-ui') 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. -- cgit v1.2.3-70-g09d2