diff options
author | RJ Ryan <rryan@mixxx.org> | 2014-03-25 13:28:13 -0400 |
---|---|---|
committer | RJ Ryan <rryan@mixxx.org> | 2014-03-25 13:28:13 -0400 |
commit | 38684dacf1987afc61f81263ca358d57c0a580f2 (patch) | |
tree | b06264cd57e7f8d29df39047dc37c9c8b3cfcc42 /src/widget/wlibrarysidebar.cpp | |
parent | d1f54023b9b4b714b4afe4332d6df68a1a630bf2 (diff) |
Do not fake a Return key press to expand/collapse a library sidebar item. Fixes Bug #582503.
Diffstat (limited to 'src/widget/wlibrarysidebar.cpp')
-rw-r--r-- | src/widget/wlibrarysidebar.cpp | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/src/widget/wlibrarysidebar.cpp b/src/widget/wlibrarysidebar.cpp index 4d1a0625d6..4ff6dcb025 100644 --- a/src/widget/wlibrarysidebar.cpp +++ b/src/widget/wlibrarysidebar.cpp @@ -141,32 +141,41 @@ void WLibrarySidebar::dropEvent(QDropEvent * event) { } } -void WLibrarySidebar::keyPressEvent(QKeyEvent* event) { - if (event->key() == Qt::Key_Return) - { - QModelIndexList selectedIndices = this->selectionModel()->selectedRows(); - if (selectedIndices.size() > 0) { - QModelIndex index = selectedIndices.at(0); - emit(pressed(index)); - //Expand or collapse the item as necessary. - setExpanded(index, !isExpanded(index)); - } + +void WLibrarySidebar::toggleSelectedItem() { + QModelIndexList selectedIndices = this->selectionModel()->selectedRows(); + if (selectedIndices.size() > 0) { + QModelIndex index = selectedIndices.at(0); + // Activate the item so its content shows in the main library. + emit(pressed(index)); + // Expand or collapse the item as necessary. + setExpanded(index, !isExpanded(index)); } - else if (event->key() == Qt::Key_Down || event->key() == Qt::Key_Up) - { - //Let the tree view move up and down for us... +} + +void WLibrarySidebar::keyPressEvent(QKeyEvent* event) { + if (event->key() == Qt::Key_Return) { + toggleSelectedItem(); + return; + } else if (event->key() == Qt::Key_Down || event->key() == Qt::Key_Up) { + // Let the tree view move up and down for us. QTreeView::keyPressEvent(event); - //But force the index to be activated/clicked after the selection - //changes. (Saves you from having to push "enter" after changing the selection.) + + // But force the index to be activated/clicked after the selection + // changes. (Saves you from having to push "enter" after changing the + // selection.) QModelIndexList selectedIndices = this->selectionModel()->selectedRows(); + //Note: have to get the selected indices _after_ QTreeView::keyPressEvent() if (selectedIndices.size() > 0) { QModelIndex index = selectedIndices.at(0); emit(pressed(index)); } + return; } - else - QTreeView::keyPressEvent(event); + + // Fall through to deafult handler. + QTreeView::keyPressEvent(event); } void WLibrarySidebar::selectIndex(const QModelIndex& index) { |