diff options
Diffstat (limited to 'qt-ui/profile')
-rw-r--r-- | qt-ui/profile/divecartesianaxis.cpp | 9 | ||||
-rw-r--r-- | qt-ui/profile/divecartesianaxis.h | 2 |
2 files changed, 7 insertions, 4 deletions
diff --git a/qt-ui/profile/divecartesianaxis.cpp b/qt-ui/profile/divecartesianaxis.cpp index c780b7a63..3fdafa375 100644 --- a/qt-ui/profile/divecartesianaxis.cpp +++ b/qt-ui/profile/divecartesianaxis.cpp @@ -187,12 +187,15 @@ void DiveCartesianAxis::setTickInterval(double i) interval = i; } -qreal DiveCartesianAxis::valueAt(const QPointF& p) +qreal DiveCartesianAxis::valueAt(const QPointF& p) const { QLineF m = line(); + QPointF relativePosition = p; + relativePosition -= pos(); // normalize p based on the axis' offset on screen + double retValue = (orientation == LeftToRight || orientation == RightToLeft) ? - max * (p.x() - m.x1()) / (m.x2() - m.x1()) : - max * (p.y() - m.y1()) / (m.y2() - m.y1()); + max * (relativePosition.x() - m.x1()) / (m.x2() - m.x1()) : + max * (relativePosition.y() - m.y1()) / (m.y2() - m.y1()); return retValue; } diff --git a/qt-ui/profile/divecartesianaxis.h b/qt-ui/profile/divecartesianaxis.h index fe34e3c62..2327a328f 100644 --- a/qt-ui/profile/divecartesianaxis.h +++ b/qt-ui/profile/divecartesianaxis.h @@ -29,7 +29,7 @@ public: double maximum() const; double tickInterval() const; double tickSize() const; - qreal valueAt(const QPointF& p); + qreal valueAt(const QPointF& p) const; qreal percentAt(const QPointF& p); qreal posAtValue(qreal value); void setColor(const QColor& color); |