]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Keep the current item visible in the view
authorFrank Reininghaus <frank78ac@googlemail.com>
Sun, 14 Aug 2011 15:20:33 +0000 (17:20 +0200)
committerFrank Reininghaus <frank78ac@googlemail.com>
Sun, 14 Aug 2011 15:21:18 +0000 (17:21 +0200)
src/kitemviews/kitemlistcontainer.cpp
src/kitemviews/kitemlistview.cpp
src/kitemviews/kitemlistview.h

index 28e526a6f04def5e1055c53ecd102a0bf1d2a64a..b8d05dc340956f9457f9dc08d9dcefb39faffc44 100644 (file)
@@ -267,6 +267,11 @@ void KItemListContainer::updateScrollBars()
     scrollBar->setMaximum(maximum);
     scrollBar->setValue(value);
 
+    disconnect(view, SIGNAL(scrollTo(int)),
+               otherScrollBar, SLOT(setValue(int)));
+    connect(view, SIGNAL(scrollTo(int)),
+            scrollBar, SLOT(setValue(int)));
+
     // Make sure that the other scroll bar is hidden
     otherScrollBar->setMaximum(0);
     otherScrollBar->setValue(0);
index 3c343955269adeaa5b7d2e01d164f1c368c1ed64..81b46b1d2e801190c6a4d623f61f1c125c59b7dc 100644 (file)
@@ -611,6 +611,32 @@ void KItemListView::slotCurrentChanged(int current, int previous)
         Q_ASSERT(!currentWidget->isCurrent());
         currentWidget->setCurrent(true);
     }
+
+    const QRectF viewGeometry = geometry();
+    const QRectF currentBoundingRect = itemBoundingRect(current);
+
+    if (!viewGeometry.contains(currentBoundingRect)) {
+        // Make sure that the new current item is fully visible in the view.
+        qreal newOffset = offset();
+        if (currentBoundingRect.top() < viewGeometry.top()) {
+            Q_ASSERT(scrollOrientation() == Qt::Vertical);
+            newOffset += currentBoundingRect.top() - viewGeometry.top();
+        }
+        else if ((currentBoundingRect.bottom() > viewGeometry.bottom())) {
+            Q_ASSERT(scrollOrientation() == Qt::Vertical);
+            newOffset += currentBoundingRect.bottom() - viewGeometry.bottom();
+        }
+        else if (currentBoundingRect.left() < viewGeometry.left()) {
+            Q_ASSERT(scrollOrientation() == Qt::Horizontal);
+            newOffset += currentBoundingRect.left() - viewGeometry.left();
+        }
+        else if ((currentBoundingRect.right() > viewGeometry.right())) {
+            Q_ASSERT(scrollOrientation() == Qt::Horizontal);
+            newOffset += currentBoundingRect.right() - viewGeometry.right();
+        }
+
+        emit scrollTo(newOffset);
+    }
 }
 
 void KItemListView::slotSelectionChanged(const QSet<int>& current, const QSet<int>& previous)
index 47426b5fa5f31523d69527d3019f70259173c250..974a9baaf537665e645650e0233dbd116ae278aa 100644 (file)
@@ -145,6 +145,7 @@ public:
 signals:
     void offsetChanged(int current, int previous);
     void maximumOffsetChanged(int current, int previous);
+    void scrollTo(int newOffset);
 
 protected:
     virtual void initializeItemListWidget(KItemListWidget* item);