X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/148282e2d856b47ceb191eeef4c834118c8cdffd..4e82b359897def33c90cd5465cda3ed10b5aa01a:/src/dolphinviewautoscroller.cpp 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) &&