mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 20:23:25 +00:00
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>
This commit is contained in:
parent
ccb1c33d02
commit
92bbed3304
2 changed files with 7 additions and 4 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue