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>
This commit is contained in:
Tomaz Canabrava 2013-11-19 21:07:06 -02:00 committed by Dirk Hohndel
parent 82ac9ef9c6
commit 732f7a69b0

View file

@ -557,16 +557,30 @@ void DivePlannerGraphics::showEvent(QShowEvent* event)
void DivePlannerGraphics::mouseMoveEvent(QMouseEvent* event) void DivePlannerGraphics::mouseMoveEvent(QMouseEvent* event)
{ {
QPointF mappedPos = mapToScene(event->pos()); QPointF mappedPos = mapToScene(event->pos());
if (isPointOutOfBoundaries(mappedPos))
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; return;
verticalLine->setPos(mappedPos.x(), fromPercent(0, Qt::Vertical));
horizontalLine->setPos(fromPercent(0, Qt::Horizontal), mappedPos.y());
depthString->setText(get_depth_string(depthLine->valueAt(mappedPos), true, false)); 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->setText(QString::number(rint(timeLine->valueAt(mappedPos))) + "min");
timeString->setPos(mappedPos.x()+1, fromPercent(95, Qt::Vertical));
// calculate the correct color for the depthString. // calculate the correct color for the depthString.
// QGradient doesn't returns it's interpolation, meh. // QGradient doesn't returns it's interpolation, meh.