Skip to content

Commit

Permalink
Merge pull request #4253 from ronso0/sidebar-left
Browse files Browse the repository at this point in the history
sidebar: Left key jumps to parent and activates it
  • Loading branch information
uklotzde authored Sep 14, 2021
2 parents af50f69 + 5f7300e commit 5b8a7a5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/widget/wlibrarysidebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,26 @@ void WLibrarySidebar::keyPressEvent(QKeyEvent* event) {
// // encoder click via "GoToItem"
// qDebug() << "GoToItem";
// TODO(xxx) decide what todo here instead of in librarycontrol
} else if (event->key() == Qt::Key_Left) {
auto selModel = selectionModel();
QModelIndexList selectedRows = selModel->selectedRows();
if (selectedRows.isEmpty()) {
return;
}
// If an expanded item is selected let QTreeView collapse it
QModelIndex selIndex = selectedRows.first();
DEBUG_ASSERT(selIndex.isValid());
if (isExpanded(selIndex)) {
QTreeView::keyPressEvent(event);
return;
}
// Else jump to its parent and activate it
QModelIndex parentIndex = selIndex.parent();
if (parentIndex.isValid()) {
selectIndex(parentIndex);
emit pressed(parentIndex);
}
return;
}

// Fall through to default handler.
Expand Down

0 comments on commit 5b8a7a5

Please sign in to comment.