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 Jan 17, 2022
1 parent f37a59f commit 2e286e5
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/library/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,15 @@ void Library::bindLibraryWidget(
m_pLibraryControl,
&LibraryControl::setLibraryFocus);

connect(m_pLibraryControl,
&LibraryControl::showHideTrackMenu,
pTrackTableView,
&WTrackTableView::slotShowHideTrackMenu);
connect(pTrackTableView,
&WTrackTableView::trackMenuVisible,
m_pLibraryControl,
&LibraryControl::slotUpdateTrackMenuControl);

for (const auto& feature : qAsConst(m_features)) {
feature->bindLibraryWidget(pLibraryWidget, pKeyboard);
}
Expand Down
20 changes: 19 additions & 1 deletion src/library/librarycontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,21 @@ 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"));
m_pShowTrackMenu->setStates(2);
m_pShowTrackMenu->connectValueChangeRequest(this,
[this](double value) {
VERIFY_OR_DEBUG_ASSERT(m_pLibraryWidget) {
return;
}
bool show = static_cast<bool>(value);
emit showHideTrackMenu(show);
});

// Deprecated controls
m_pSelectNextTrack = std::make_unique<ControlPushButton>(ConfigKey("[Playlist]", "SelectNextTrack"));
connect(m_pSelectNextTrack.get(),
&ControlPushButton::valueChanged,
Expand Down Expand Up @@ -473,6 +487,10 @@ void LibraryControl::searchboxWidgetDeleted() {
m_pSearchbox = nullptr;
}

void LibraryControl::slotUpdateTrackMenuControl(bool visible) {
m_pShowTrackMenu->setAndConfirm(visible ? 1.0 : 0.0);
}

void LibraryControl::slotLoadSelectedTrackToGroup(const QString& group, bool play) {
if (!m_pLibraryWidget) {
return;
Expand Down
5 changes: 5 additions & 0 deletions src/library/librarycontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ class LibraryControl : public QObject {

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

public slots:
// Deprecated navigation slots
void slotLoadSelectedTrackToGroup(const QString& group, bool play);
void slotUpdateTrackMenuControl(bool visible);

private slots:
void libraryWidgetDeleted();
Expand Down Expand Up @@ -145,6 +147,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
6 changes: 6 additions & 0 deletions src/widget/wtrackmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,17 @@ int WTrackMenu::getTrackCount() const {
}
}

void WTrackMenu::closeEvent(QCloseEvent* event) {
event->accept();
emit trackMenuVisible(false);
}

void WTrackMenu::popup(const QPoint& pos, QAction* at) {
if (isEmpty()) {
return;
}
QMenu::popup(pos, at);
emit trackMenuVisible(true);
}

void WTrackMenu::createMenus() {
Expand Down
2 changes: 2 additions & 0 deletions src/widget/wtrackmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class WTrackMenu : public QMenu {

signals:
void loadTrackToPlayer(TrackPointer pTrack, const QString& group, bool play = false);
void trackMenuVisible(bool visible);

private slots:
// File
Expand Down Expand Up @@ -138,6 +139,7 @@ class WTrackMenu : public QMenu {
void slotPurge();

private:
void closeEvent(QCloseEvent* event) override;
// This getter verifies that m_pTrackModel is set when
// invoked.
const QModelIndexList& getTrackIndices() const;
Expand Down
25 changes: 24 additions & 1 deletion src/widget/wtracktableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,13 @@ void WTrackTableView::initTrackMenu() {
&WTrackMenu::loadTrackToPlayer,
this,
&WTrackTableView::loadTrackToPlayer);

connect(m_pTrackMenu,
&WTrackMenu::trackMenuVisible,
this,
[this](bool visible) {
emit trackMenuVisible(visible);
});
}

// slot
Expand Down Expand Up @@ -462,6 +469,22 @@ void WTrackTableView::slotUnhide() {
}
}

void WTrackTableView::slotShowHideTrackMenu(bool show) {
VERIFY_OR_DEBUG_ASSERT(m_pTrackMenu.get()) {
return;
}
if (show == m_pTrackMenu->isVisible()) {
emit trackMenuVisible(show);
return;
}
if (show) {
QContextMenuEvent event(QContextMenuEvent::Mouse, QCursor::pos());
contextMenuEvent(&event);
} else {
m_pTrackMenu->close();
}
}

void WTrackTableView::contextMenuEvent(QContextMenuEvent* event) {
VERIFY_OR_DEBUG_ASSERT(m_pTrackMenu.get()) {
initTrackMenu();
Expand All @@ -471,7 +494,7 @@ void WTrackTableView::contextMenuEvent(QContextMenuEvent* event) {
QModelIndexList indices = selectionModel()->selectedRows();
m_pTrackMenu->loadTrackModelIndices(indices);

//Create the right-click menu
// Create the right-click menu
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
m_pTrackMenu->popup(event->globalPosition().toPoint());
#else
Expand Down
2 changes: 2 additions & 0 deletions src/widget/wtracktableview.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ class WTrackTableView : public WLibraryTableView {

signals:
void trackTableFocusChange(FocusWidget newFocusWidget);
void trackMenuVisible(bool visible);

public slots:
void loadTrackModel(QAbstractItemModel* model, bool restoreState = false);
void slotMouseDoubleClicked(const QModelIndex &);
void slotUnhide();
void slotPurge();
void slotDeleteTracksFromDisk();
void slotShowHideTrackMenu(bool show);

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

0 comments on commit 2e286e5

Please sign in to comment.