┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2008-12-11 07:15:59 +0000
committerPeter Penz <[email protected]>2008-12-11 07:15:59 +0000
commit4e82b359897def33c90cd5465cda3ed10b5aa01a (patch)
treeb5b13c6df1e816a661b05644b8c9fd23da5cdefd
parent148282e2d856b47ceb191eeef4c834118c8cdffd (diff)
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
-rw-r--r--src/dolphinviewautoscroller.cpp17
-rw-r--r--src/dolphinviewautoscroller.h1
2 files changed, 17 insertions, 1 deletions
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<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) &&
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();