void DolphinColumnWidget::currentChanged(const QModelIndex& current, const QModelIndex& previous)
{
QListView::currentChanged(current, previous);
- if (current.isValid() && !m_autoScroller->isActive()) {
- scrollTo(current);
- }
+ m_autoScroller->handleCurrentIndexChange(current, previous);
}
void DolphinColumnWidget::slotEntered(const QModelIndex& index)
void DolphinDetailsView::currentChanged(const QModelIndex& current, const QModelIndex& previous)
{
QTreeView::currentChanged(current, previous);
- if (current.isValid() && !m_autoScroller->isActive()) {
- scrollTo(current);
- }
+ m_autoScroller->handleCurrentIndexChange(current, previous);
// Stay consistent with QListView: When changing the current index by key presses,
// also change the selection.
void DolphinIconsView::currentChanged(const QModelIndex& current, const QModelIndex& previous)
{
KCategorizedView::currentChanged(current, previous);
- if (current.isValid() && !m_autoScroller->isActive()) {
- scrollTo(current);
- }
+ m_autoScroller->handleCurrentIndexChange(current, previous);
}
void DolphinIconsView::resizeEvent(QResizeEvent* event)
return m_timer->isActive();
}
+void DolphinViewAutoScroller::handleCurrentIndexChange(const QModelIndex& current,
+ const QModelIndex& previous)
+{
+ // When the autoscroller is inactive and a key has been pressed, it must be
+ // assured that the current item stays visible. The check whether the previous
+ // item is valid is important because of #197951.
+ if (current.isValid() && previous.isValid() && !isActive()) {
+ m_itemView->scrollTo(current);
+ }
+}
+
bool DolphinViewAutoScroller::eventFilter(QObject* watched, QEvent* event)
{
if (watched == m_itemView->viewport()) {
#include <QObject>
class QAbstractItemView;
+class QModelIndex;
class QTimer;
/**
virtual ~DolphinViewAutoScroller();
bool isActive() const;
+ /**
+ * Must be invoked by the parent item view, when QAbstractItemView::currentChanged()
+ * has been called. Assures that the current item stays visible when it has been
+ * changed by the keyboard.
+ */
+ void handleCurrentIndexChange(const QModelIndex& current, const QModelIndex& previous);
+
protected:
virtual bool eventFilter(QObject* watched, QEvent* event);