From d3749eace9e3eed82f620a4f271c539c032f5e60 Mon Sep 17 00:00:00 2001 From: David Sansome Date: Tue, 14 Jan 2014 20:07:03 +1100 Subject: [PATCH] Select the current item if the selection is empty when using Tab to move from the playlist filter to the playlist view. Fixes #4116 --- src/playlist/playlistview.cpp | 21 +++++++++++++++++++++ src/playlist/playlistview.h | 1 + 2 files changed, 22 insertions(+) diff --git a/src/playlist/playlistview.cpp b/src/playlist/playlistview.cpp index 87f9cc8eb..e3e97782b 100644 --- a/src/playlist/playlistview.cpp +++ b/src/playlist/playlistview.cpp @@ -1254,3 +1254,24 @@ void PlaylistView::FadePreviousBackgroundImage(qreal value) { void PlaylistView::PlayerStopped() { CurrentSongChanged(Song(), QString(), QImage()); } + +void PlaylistView::focusInEvent(QFocusEvent* event) { + QTreeView::focusInEvent(event); + + if (event->reason() == Qt::TabFocusReason || + event->reason() == Qt::BacktabFocusReason) { + // If there's a current item but no selection it probably means the list was + // filtered, and the selected item does not match the filter. If there's + // only 1 item in the view it is now impossible to select that item without + // using the mouse. + const QModelIndex& current = selectionModel()->currentIndex(); + if (current.isValid() && + selectionModel()->selectedIndexes().isEmpty()) { + QItemSelection new_selection( + current.sibling(current.row(), 0), + current.sibling(current.row(), + current.model()->columnCount(current.parent()) - 1)); + selectionModel()->select(new_selection, QItemSelectionModel::Select); + } + } +} diff --git a/src/playlist/playlistview.h b/src/playlist/playlistview.h index 6b897188c..8fdc1a6c8 100644 --- a/src/playlist/playlistview.h +++ b/src/playlist/playlistview.h @@ -134,6 +134,7 @@ class PlaylistView : public QTreeView { void dropEvent(QDropEvent *event); void resizeEvent(QResizeEvent* event); bool eventFilter(QObject* object, QEvent* event); + void focusInEvent(QFocusEvent* event); // QAbstractScrollArea void scrollContentsBy(int dx, int dy);