From 2e3db467e0a5e2d4879358eaef69cbb32b4ca8b7 2012-10-17 07:46:30 From: sauimone Date: 2012-10-17 07:46:30 Subject: [PATCH] accurate speed calculation to kinetic scrolling --- diff --git a/src/scroller.cpp b/src/scroller.cpp index 385688a..22d0027 100644 --- a/src/scroller.cpp +++ b/src/scroller.cpp @@ -63,8 +63,12 @@ void Scroller::release(const QPointF &delta) if ((m_timeStamp.elapsed() > m_timeTresholdMin) && (m_timeStamp.msecsTo(QTime::currentTime()) < m_timeTresholdMax)) { // Release was quick enough. Start scrolling. - // Magic number is to make scroll bit slower (the resolution of screen may affect this) - m_speed = delta / 5; + qreal interval = 25; + qreal time = m_timeStamp.msecsTo(QTime::currentTime()); + if (qFuzzyIsNull(time)) + m_speed = delta / 5; + else + m_speed = delta * interval / time; qreal fraction = qMax(qAbs(m_speed.x()), qAbs(m_speed.y())); @@ -75,7 +79,7 @@ void Scroller::release(const QPointF &delta) m_fraction.setX(1); m_fraction.setY(1); } - startTicker(25); + startTicker(interval); m_state = Scroll; } else { stopTicker(); // Stop ticker, if one is running.