Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library: add control to open/close the track menu #4465

Merged
merged 2 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/library/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,15 @@ void Library::bindLibraryWidget(

m_pLibraryControl->bindLibraryWidget(pLibraryWidget, pKeyboard);

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
22 changes: 21 additions & 1 deletion src/library/librarycontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,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
// The control is updated in slotUpdateTrackMenuControl with the actual state
// sent from WTrackMenu via WTrackTableView
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 @@ -489,6 +505,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 @@ -50,10 +50,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 @@ -151,6 +153,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
8 changes: 8 additions & 0 deletions src/widget/wtrackmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,19 @@ int WTrackMenu::getTrackCount() const {
}
}

void WTrackMenu::closeEvent(QCloseEvent* event) {
// Actually the event is accepted by default. doing it explicitly doesn't hurt.
// If it's not accepted the menu remains open and entire GUI will be blocked!
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 @@ -341,6 +341,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 @@ -461,6 +468,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 @@ -470,7 +493,7 @@ void WTrackTableView::contextMenuEvent(QContextMenuEvent* event) {
QModelIndexList indices = selectionModel()->selectedRows();
m_pTrackMenu->loadTrackModelIndices(indices);

//Create the right-click menu
// Create the right-click menu
m_pTrackMenu->popup(event->globalPos());
}

Expand Down
4 changes: 4 additions & 0 deletions src/widget/wtracktableview.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,16 @@ class WTrackTableView : public WLibraryTableView {
return m_pFocusBorderColor;
}

signals:
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