diff options
author | Samuel Fadel <samuelfadel@gmail.com> | 2015-10-14 10:04:50 -0300 |
---|---|---|
committer | Samuel Fadel <samuelfadel@gmail.com> | 2015-10-14 10:04:50 -0300 |
commit | 99ac0af03e1695ba4de2c42e949fce61b84850e5 (patch) | |
tree | 8fb0dcb6af793a0f4aa59c4071fc83ee6215de1c | |
parent | 013963a9904258696b97e303f4b447bb3c4a26b3 (diff) |
Improved handling of autoscroll (HistoryGraph).
-rw-r--r-- | historygraph.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
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(); |