From 99ac0af03e1695ba4de2c42e949fce61b84850e5 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Wed, 14 Oct 2015 10:04:50 -0300 Subject: Improved handling of autoscroll (HistoryGraph). --- historygraph.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/historygraph.cpp b/historygraph.cpp index a6706f9..0f05642 100644 --- a/historygraph.cpp +++ b/historygraph.cpp @@ -272,6 +272,17 @@ HistoryGraph::HistoryItemNode *HistoryGraph::nodeAt(const QPointF &pos, HistoryG return 0; } +static inline float clamp(float x, float min, float max) +{ + if (x < min) { + return min; + } else if (x > max) { + return max; + } + + return x; +} + void HistoryGraph::hoverMoveEvent(QHoverEvent *event) { if (m_currentWidth < width()) { @@ -280,7 +291,8 @@ void HistoryGraph::hoverMoveEvent(QHoverEvent *event) const QPointF &pos = event->posF(); float margin = MARGIN * height(); - float prop = (pos.x() - margin) / (width() - 2*margin); + float prop = (pos.x() - 2*margin) / (width() - 4*margin); + prop = clamp(prop, 0.0f, 1.0f); float displ = m_currentWidth - width() + margin; m_viewportTransform.setToIdentity(); -- cgit v1.2.3