From de62420846846a2d5bfb72961c654affdbaa8cf3 Mon Sep 17 00:00:00 2001 From: ronso0 Date: Mon, 31 Aug 2020 18:28:58 +0200 Subject: [PATCH] WLibraryTableView: on FocusIn, select the first item if there is no previous selection (focused item) --- src/widget/wlibrarytableview.cpp | 15 +++++++++++++++ src/widget/wlibrarytableview.h | 1 + 2 files changed, 16 insertions(+) diff --git a/src/widget/wlibrarytableview.cpp b/src/widget/wlibrarytableview.cpp index 297a8347d71..4daa99120c3 100644 --- a/src/widget/wlibrarytableview.cpp +++ b/src/widget/wlibrarytableview.cpp @@ -148,3 +148,18 @@ void WLibraryTableView::setSelectedClick(bool enable) { setEditTriggers(QAbstractItemView::EditKeyPressed); } } + +bool WLibraryTableView::event(QEvent* e) { + // On FocusIn, with no focused item, select the first track which can then + // instantly be loaded to a deck. + // This is especially helpful if the table has only one track, which can not + // be selected with up/down buttons, either physical or emulated via + // [Library],MoveVertical controls. See lp:1808632 + if (e->type() == QEvent::FocusIn && + model()->rowCount() > 0 && + currentIndex().row() == -1) { + selectRow(0); + } + + return QTableView::event(e); +} diff --git a/src/widget/wlibrarytableview.h b/src/widget/wlibrarytableview.h index 57601488e67..2d323eb6f85 100644 --- a/src/widget/wlibrarytableview.h +++ b/src/widget/wlibrarytableview.h @@ -58,6 +58,7 @@ class WLibraryTableView : public QTableView, public virtual LibraryView { private: void loadVScrollBarPosState(); void saveVScrollBarPosState(); + bool event(QEvent* e); const UserSettingsPointer m_pConfig; const ConfigKey m_vScrollBarPosKey;