From 4e82b359897def33c90cd5465cda3ed10b5aa01a Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Thu, 11 Dec 2008 07:15:59 +0000 Subject: [PATCH] assure that the current index stays visible, when the user explicitly changed it by using the arrow keys BUG: 165531 svn path=/trunk/KDE/kdebase/apps/; revision=895599 --- src/dolphinviewautoscroller.cpp | 17 ++++++++++++++++- src/dolphinviewautoscroller.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/dolphinviewautoscroller.cpp b/src/dolphinviewautoscroller.cpp index 5e9e17f1f..67bc696cc 100644 --- a/src/dolphinviewautoscroller.cpp +++ b/src/dolphinviewautoscroller.cpp @@ -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(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) && diff --git a/src/dolphinviewautoscroller.h b/src/dolphinviewautoscroller.h index c04e22e28..177c6ee0f 100644 --- a/src/dolphinviewautoscroller.h +++ b/src/dolphinviewautoscroller.h @@ -44,6 +44,7 @@ protected: private slots: void scrollViewport(); + void scrollToCurrentIndex(); private: void triggerAutoScroll(); -- 2.47.3