]> cloud.milkyroute.net Git - dolphin.git/commitdiff
assure that the current index stays visible, when the user explicitly changed it...
authorPeter Penz <peter.penz19@gmail.com>
Thu, 11 Dec 2008 07:15:59 +0000 (07:15 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Thu, 11 Dec 2008 07:15:59 +0000 (07:15 +0000)
BUG: 165531

svn path=/trunk/KDE/kdebase/apps/; revision=895599

src/dolphinviewautoscroller.cpp
src/dolphinviewautoscroller.h

index 5e9e17f1fcdfc32956ca69e61042e3d55ad73ae5..67bc696cc63e319fda7d63eccca2255b5c62f2fc 100644 (file)
@@ -36,6 +36,7 @@ DolphinViewAutoScroller::DolphinViewAutoScroller(QAbstractItemView* parent) :
 {
     m_itemView->setAutoScroll(false);
     m_itemView->viewport()->installEventFilter(this);
+    m_itemView->installEventFilter(this);
     
     m_timer = new QTimer(this);
     m_timer->setSingleShot(false);
@@ -83,7 +84,15 @@ bool DolphinViewAutoScroller::eventFilter(QObject* watched, QEvent* event)
         default:
             break;
         }
-    }
+    } else if ((watched == m_itemView) && (event->type() == QEvent::KeyPress)) {
+        const int key = static_cast<QKeyEvent*>(event)->key();
+        const bool arrowKeyPressed = (key == Qt::Key_Up)   || (key == Qt::Key_Down) ||
+                                     (key == Qt::Key_Left) || (key == Qt::Key_Right);
+        if (arrowKeyPressed) {
+            QMetaObject::invokeMethod(this, "scrollToCurrentIndex", Qt::QueuedConnection);
+        }
+    } 
+    
 
     return QObject::eventFilter(watched, event);
 }
@@ -114,6 +123,12 @@ void DolphinViewAutoScroller::scrollViewport()
     }
 }
 
+void DolphinViewAutoScroller::scrollToCurrentIndex()
+{
+     const QModelIndex index = m_itemView->currentIndex();
+     m_itemView->scrollTo(index);
+}
+
 void DolphinViewAutoScroller::triggerAutoScroll()
 {
     const bool verticalScrolling = (m_itemView->verticalScrollBar() != 0) &&
index c04e22e287b372bd3868c533c381f80aa75e2e4d..177c6ee0f4cde03aa001d94a058cec58d451aec2 100644 (file)
@@ -44,6 +44,7 @@ protected:
 
 private slots:
     void scrollViewport();
+    void scrollToCurrentIndex();
     
 private:
     void triggerAutoScroll();