Skip to content

Commit

Permalink
Library: add control to open/close the track menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Dec 23, 2021
1 parent 70bee44 commit 797aa84
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/library/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
18 changes: 17 additions & 1 deletion src/library/librarycontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,23 @@ LibraryControl::LibraryControl(Library* pLibrary)
}
});

/// Deprecated controls
// Show the track context menu for selected tracks, or hide it
// if it is the current active window
m_pShowTrackMenu = std::make_unique<ControlPushButton>(
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<ControlPushButton>(ConfigKey("[Playlist]", "SelectNextTrack"));
connect(m_pSelectNextTrack.get(),
&ControlPushButton::valueChanged,
Expand Down
4 changes: 4 additions & 0 deletions src/library/librarycontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class LibraryControl : public QObject {

signals:
void clearSearchIfClearButtonHasFocus();
void showHideTrackMenu();

public slots:
// Deprecated navigation slots
Expand Down Expand Up @@ -145,6 +146,9 @@ class LibraryControl : public QObject {
std::unique_ptr<ControlPushButton> m_pTrackColorPrev;
std::unique_ptr<ControlPushButton> m_pTrackColorNext;

// Control to show/hide the track menu
std::unique_ptr<ControlPushButton> m_pShowTrackMenu;

// Controls to navigate search history
std::unique_ptr<ControlPushButton> m_pSelectHistoryNext;
std::unique_ptr<ControlPushButton> m_pSelectHistoryPrev;
Expand Down
12 changes: 12 additions & 0 deletions src/widget/wtracktableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/widget/wtracktableview.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class WTrackTableView : public WLibraryTableView {
void slotUnhide();
void slotPurge();
void slotDeleteTracksFromDisk();
void slotShowHideTrackMenu();

void slotAddToAutoDJBottom() override;
void slotAddToAutoDJTop() override;
Expand Down

0 comments on commit 797aa84

Please sign in to comment.