From 352cdcc86300f107ba1cce43911e80c29c479043 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 10 Dec 2021 12:15:44 +0100 Subject: [PATCH] profile: fix crosshairs In planner and edit mode, the cursor position is indicated using crosshairs. They broke when changing to absolute scaling. To fix them, remember the plot-area in the profile scene and draw the crosshairs only inside this area (not on top of axes). However, limit the position of the horizontal line to the actual profile (dont paint inside the partial pressure, etc graphs). The vertical line is painted above those graphs, so that a timestamp can be related to partial pressure, tissue loading, etc. Also, set the z-value of the crosshairs. It was painted inconsistently above some and below other chart features. Signed-off-by: Berthold Stoeger --- profile-widget/profilescene.cpp | 3 ++- profile-widget/profilescene.h | 1 + profile-widget/profilewidget2.cpp | 22 ++++++++++------------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/profile-widget/profilescene.cpp b/profile-widget/profilescene.cpp index 5f84d9431..4e6922e45 100644 --- a/profile-widget/profilescene.cpp +++ b/profile-widget/profilescene.cpp @@ -316,7 +316,8 @@ void ProfileScene::updateAxes(bool diveHasHeartBeat, bool simplified) } bottomBorder -= timeAxis->height(); - timeAxis->setPosition(QRectF(leftBorder, topBorder, width, bottomBorder - topBorder)); + profileRegion = QRectF(leftBorder, topBorder, width, bottomBorder - topBorder); + timeAxis->setPosition(profileRegion); if (prefs.tankbar) { bottomBorder -= tankItem->height(); diff --git a/profile-widget/profilescene.h b/profile-widget/profilescene.h index 66ce6d6cb..a222a37c8 100644 --- a/profile-widget/profilescene.h +++ b/profile-widget/profilescene.h @@ -68,6 +68,7 @@ private: int maxdepth; struct plot_info plotInfo; + QRectF profileRegion; // Region inside the axes, where the crosshair is painted in plan and edit mode. DiveCartesianAxis *profileYAxis; DiveCartesianAxis *gasYAxis; DiveCartesianAxis *temperatureAxis; diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index b8dccbae3..2e0b96a3d 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -157,6 +157,8 @@ void ProfileWidget2::setupItemOnScene() toolTipItem->setTimeAxis(profileScene->timeAxis); rulerItem->setZValue(9997); rulerItem->setAxis(profileScene->timeAxis, profileScene->profileYAxis); + mouseFollowerHorizontal->setZValue(9996); + mouseFollowerVertical->setZValue(9995); #endif } @@ -352,14 +354,14 @@ void ProfileWidget2::mouseMoveEvent(QMouseEvent *event) plotDive(d, dc, RenderFlags::Instant | RenderFlags::DontRecalculatePlotInfo); // TODO: animations don't work when scrolling } - double vValue = profileScene->profileYAxis->valueAt(pos); - double hValue = profileScene->timeAxis->valueAt(pos); - - if (profileScene->profileYAxis->maximum() >= vValue && profileScene->profileYAxis->minimum() <= vValue) - mouseFollowerHorizontal->setPos(profileScene->timeAxis->pos().x(), pos.y()); - - if (profileScene->timeAxis->maximum() >= hValue && profileScene->timeAxis->minimum() <= hValue) - mouseFollowerVertical->setPos(pos.x(), profileScene->profileYAxis->line().y1()); + if (currentState == PLAN || currentState == EDIT) { + QRectF rect = profileScene->profileRegion; + auto [miny, maxy] = profileScene->profileYAxis->screenMinMax(); + double x = std::clamp(pos.x(), rect.left(), rect.right()); + double y = std::clamp(pos.y(), miny, maxy); + mouseFollowerHorizontal->setLine(rect.left(), y, rect.right(), y); + mouseFollowerVertical->setLine(x, rect.top(), x, rect.bottom()); + } } bool ProfileWidget2::eventFilter(QObject *object, QEvent *event) @@ -441,8 +443,6 @@ void ProfileWidget2::setEditState(const dive *d, int dc) setProfileState(d, dc); mouseFollowerHorizontal->setVisible(true); mouseFollowerVertical->setVisible(true); - mouseFollowerHorizontal->setLine(profileScene->timeAxis->line()); - mouseFollowerVertical->setLine(QLineF(0, profileScene->profileYAxis->pos().y(), 0, profileScene->timeAxis->pos().y())); disconnectTemporaryConnections(); actionsForKeys[Qt::Key_Left]->setShortcut(Qt::Key_Left); actionsForKeys[Qt::Key_Right]->setShortcut(Qt::Key_Right); @@ -469,8 +469,6 @@ void ProfileWidget2::setPlanState(const dive *d, int dc) setProfileState(d, dc); mouseFollowerHorizontal->setVisible(true); mouseFollowerVertical->setVisible(true); - mouseFollowerHorizontal->setLine(profileScene->timeAxis->line()); - mouseFollowerVertical->setLine(QLineF(0, profileScene->profileYAxis->pos().y(), 0, profileScene->timeAxis->pos().y())); disconnectTemporaryConnections(); actionsForKeys[Qt::Key_Left]->setShortcut(Qt::Key_Left); actionsForKeys[Qt::Key_Right]->setShortcut(Qt::Key_Right);