diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-02-11 12:05:33 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-02-11 12:37:09 -0800 |
commit | 92bbed3304afeb8e7ef6593f48eae982d799b5f1 (patch) | |
tree | dd01d95c47549aa839f615d51857b4d88a23ef4c /qt-ui/profile/divecartesianaxis.cpp | |
parent | ccb1c33d02b17d72036ed3cfccf565a969774aad (diff) | |
download | subsurface-92bbed3304afeb8e7ef6593f48eae982d799b5f1.tar.gz |
Take the on-canvas position into account for DiveCartesianAxis::valueAt()
We did this right for posAtValue(), but not for the inverse.
Fixes #438
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/profile/divecartesianaxis.cpp')
-rw-r--r-- | qt-ui/profile/divecartesianaxis.cpp | 9 |
1 files changed, 6 insertions, 3 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; } |