]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinviewautoscroller.cpp
Same change as in r995015, but for usage in konq: Don't connect to KDirLister::itemDe...
[dolphin.git] / src / dolphinviewautoscroller.cpp
index 767a5b45814fce33c1c1f55e8f073246a62826ab..ea9b1a2d6bb2103007baa3bf0c558d17164304b2 100644 (file)
@@ -26,6 +26,7 @@
 #include <QMouseEvent>
 #include <QScrollBar>
 #include <QTimer>
+#include <math.h>
 
 DolphinViewAutoScroller::DolphinViewAutoScroller(QAbstractItemView* parent) :
     QObject(parent),
@@ -33,7 +34,7 @@ DolphinViewAutoScroller::DolphinViewAutoScroller(QAbstractItemView* parent) :
     m_horizontalScrollInc(0),
     m_verticalScrollInc(0),
     m_itemView(parent),
-    m_timer()
+    m_timer(0)
 {
     m_itemView->setAutoScroll(false);
     m_itemView->viewport()->installEventFilter(this);
@@ -48,6 +49,22 @@ DolphinViewAutoScroller::~DolphinViewAutoScroller()
 {
 }
 
+bool DolphinViewAutoScroller::isActive() const
+{
+    return m_timer->isActive();
+}
+
+void DolphinViewAutoScroller::handleCurrentIndexChange(const QModelIndex& current,
+                                                       const QModelIndex& previous)
+{
+    // When the autoscroller is inactive and a key has been pressed, it must be
+    // assured that the current item stays visible. The check whether the previous
+    // item is valid is important because of #197951.
+    if (current.isValid() && previous.isValid() && !isActive()) {
+        m_itemView->scrollTo(current);
+    }
+}
+
 bool DolphinViewAutoScroller::eventFilter(QObject* watched, QEvent* event)
 {
     if (watched == m_itemView->viewport()) {
@@ -155,18 +172,18 @@ int DolphinViewAutoScroller::calculateScrollIncrement(int cursorPos, int rangeSi
 {
     int inc = 0;
 
-    const int minSpeed = 2;
-    const int maxSpeed = 32;
-    const int speedLimiter = 8;
-    const int autoScrollBorder = 32;
+    const int minSpeed = 4;
+    const int maxSpeed = 768;
+    const int speedLimiter = 48;
+    const int autoScrollBorder = 64;
 
     if (cursorPos < autoScrollBorder) {
-        inc = -minSpeed + (cursorPos - autoScrollBorder) / speedLimiter;
+        inc = -minSpeed + qAbs(cursorPos - autoScrollBorder) * (cursorPos - autoScrollBorder) / speedLimiter;
         if (inc < -maxSpeed) {
             inc = -maxSpeed;
         }
     } else if (cursorPos > rangeSize - autoScrollBorder) {
-        inc = minSpeed + (cursorPos - rangeSize + autoScrollBorder) / speedLimiter;
+        inc = minSpeed + qAbs(cursorPos - rangeSize + autoScrollBorder) * (cursorPos - rangeSize + autoScrollBorder) / speedLimiter;
         if (inc > maxSpeed) {
             inc = maxSpeed;
         }