]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistview.cpp
Respect rubberband direction when autoscrolling
[dolphin.git] / src / kitemviews / kitemlistview.cpp
index f6cfed98418a7d80b9b7463d9363091bc64f9682..9189cbda3975d98df7b1800e16c6d8f3ecf349f9 100644 (file)
@@ -785,9 +785,27 @@ void KItemListView::triggerAutoScrolling()
     }
 
     const int inc = calculateAutoScrollingIncrement(pos, visibleSize);
-    if (inc != 0) {
-        emit scrollTo(offset() + inc);
+    if (inc == 0) {
+        // The mouse position is not above an autoscroll margin
+        return;
     }
+
+    if (m_rubberBand->isActive()) {
+        // If a rubberband selection is ongoing the autoscrolling may only get triggered
+        // if the direction of the rubberband is similar to the autoscroll direction.
+
+        const qreal minDiff = 4; // Ignore any autoscrolling if the rubberband is very small
+        const qreal diff = (scrollOrientation() == Qt::Vertical)
+                           ? m_rubberBand->endPosition().y() - m_rubberBand->startPosition().y()
+                           : m_rubberBand->endPosition().x() - m_rubberBand->startPosition().x();
+        if (qAbs(diff) < minDiff || (inc < 0 && diff > 0) || (inc > 0 && diff < 0)) {
+            // The rubberband direction is different from the scroll direction (e.g. the rubberband has
+            // been moved up although the autoscroll direction might be down)
+            return;
+        }
+    }
+
+    emit scrollTo(offset() + inc);
 }
 
 void KItemListView::setController(KItemListController* controller)