From 84edc0463b5a253476d0f7bea10cbc3462f8a29d Mon Sep 17 00:00:00 2001 From: ronso0 Date: Mon, 20 Dec 2021 12:18:59 +0100 Subject: [PATCH] Library: add control to open/close the track menu --- src/library/library.cpp | 5 +++++ src/library/librarycontrol.cpp | 16 ++++++++++++++++ src/library/librarycontrol.h | 4 ++++ src/widget/wtracktableview.cpp | 12 ++++++++++++ src/widget/wtracktableview.h | 1 + 5 files changed, 38 insertions(+) diff --git a/src/library/library.cpp b/src/library/library.cpp index 78ecb99b9832..ca12dd4f257b 100644 --- a/src/library/library.cpp +++ b/src/library/library.cpp @@ -425,6 +425,11 @@ void Library::bindLibraryWidget( m_pLibraryControl, &LibraryControl::setLibraryFocus); + connect(m_pLibraryControl, + &LibraryControl::showHideTrackMenu, + pTrackTableView, + &WTrackTableView::slotShowHideTrackMenu); + for (const auto& feature : qAsConst(m_features)) { feature->bindLibraryWidget(pLibraryWidget, pKeyboard); } diff --git a/src/library/librarycontrol.cpp b/src/library/librarycontrol.cpp index 1197c0ae6932..d388024f0be9 100644 --- a/src/library/librarycontrol.cpp +++ b/src/library/librarycontrol.cpp @@ -302,6 +302,22 @@ LibraryControl::LibraryControl(Library* pLibrary) } }); + /// Show the track context menu for selected tracks, or hide it + /// if it is the current active window + m_pShowTrackMenu = std::make_unique( + ConfigKey("[Library]", "show_track_menu")); + connect(m_pShowTrackMenu.get(), + &ControlPushButton::valueChanged, + this, + [this](double value) { + VERIFY_OR_DEBUG_ASSERT(m_pLibraryWidget) { + return; + } + if (value > 0.0) { + emit showHideTrackMenu(); + } + }); + /// Deprecated controls m_pSelectNextTrack = std::make_unique(ConfigKey("[Playlist]", "SelectNextTrack")); connect(m_pSelectNextTrack.get(), diff --git a/src/library/librarycontrol.h b/src/library/librarycontrol.h index 7ab00b3983d0..bb159ed6ad5a 100644 --- a/src/library/librarycontrol.h +++ b/src/library/librarycontrol.h @@ -49,6 +49,7 @@ class LibraryControl : public QObject { signals: void clearSearchIfClearButtonHasFocus(); + void showHideTrackMenu(); public slots: // Deprecated navigation slots @@ -145,6 +146,9 @@ class LibraryControl : public QObject { std::unique_ptr m_pTrackColorPrev; std::unique_ptr m_pTrackColorNext; + // Control to show/hide the track menu + std::unique_ptr m_pShowTrackMenu; + // Controls to navigate search history std::unique_ptr m_pSelectHistoryNext; std::unique_ptr m_pSelectHistoryPrev; diff --git a/src/widget/wtracktableview.cpp b/src/widget/wtracktableview.cpp index 92ee26bed0ae..d5fe1c84ea3d 100644 --- a/src/widget/wtracktableview.cpp +++ b/src/widget/wtracktableview.cpp @@ -468,6 +468,18 @@ void WTrackTableView::slotUnhide() { } } +void WTrackTableView::slotShowHideTrackMenu() { + VERIFY_OR_DEBUG_ASSERT(m_pTrackMenu.get()) { + return; + } + if (m_pTrackMenu->isActiveWindow()) { + m_pTrackMenu->close(); + } else { + QContextMenuEvent event(QContextMenuEvent::Mouse, QCursor::pos()); + contextMenuEvent(&event); + } +} + void WTrackTableView::contextMenuEvent(QContextMenuEvent* event) { VERIFY_OR_DEBUG_ASSERT(m_pTrackMenu.get()) { initTrackMenu(); diff --git a/src/widget/wtracktableview.h b/src/widget/wtracktableview.h index 33c385efefa9..0236e235e65f 100644 --- a/src/widget/wtracktableview.h +++ b/src/widget/wtracktableview.h @@ -61,6 +61,7 @@ class WTrackTableView : public WLibraryTableView { void slotUnhide(); void slotPurge(); void slotDeleteTracksFromDisk(); + void slotShowHideTrackMenu(); void slotAddToAutoDJBottom() override; void slotAddToAutoDJTop() override;