Skip to content

Commit

Permalink
rename to [Library],show_track_menu and make it read/write
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Jan 17, 2022
1 parent 8cf8e1f commit 4808a05
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/library/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ void Library::bindLibraryWidget(
&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
16 changes: 9 additions & 7 deletions src/library/librarycontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,17 +327,15 @@ 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<ControlPushButton>(
ConfigKey("[Library]", "toggle_track_menu"));
connect(m_pShowTrackMenu.get(),
&ControlPushButton::valueChanged,
this,
ConfigKey("[Library]", "show_track_menu"));
m_pShowTrackMenu->setStates(2);
m_pShowTrackMenu->connectValueChangeRequest(this,
[this](double value) {
VERIFY_OR_DEBUG_ASSERT(m_pLibraryWidget) {
return;
}
if (value > 0.0) {
emit showHideTrackMenu();
}
bool show = static_cast<bool>(value);
emit showHideTrackMenu(show);
});

// Deprecated controls
Expand Down Expand Up @@ -489,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
3 changes: 2 additions & 1 deletion src/library/librarycontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ class LibraryControl : public QObject {

signals:
void clearSearchIfClearButtonHasFocus();
void showHideTrackMenu();
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
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
19 changes: 15 additions & 4 deletions 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,15 +469,19 @@ void WTrackTableView::slotUnhide() {
}
}

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

Expand Down
3 changes: 2 additions & 1 deletion src/widget/wtracktableview.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +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();
void slotShowHideTrackMenu(bool show);

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

0 comments on commit 4808a05

Please sign in to comment.