Skip to content

Commit

Permalink
Merge pull request #4740 from ronso0/select-in-library_fixup
Browse files Browse the repository at this point in the history
WTrackMenu: Add ability to select loaded track in library -- fixup/tweak
  • Loading branch information
daschuer authored May 16, 2022
2 parents d5da303 + 7d5aa8b commit 9148cb2
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 22 deletions.
28 changes: 22 additions & 6 deletions src/library/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Library::Library(
m_pTrackCollectionManager(pTrackCollectionManager),
m_pSidebarModel(make_parented<SidebarModel>(this)),
m_pLibraryControl(make_parented<LibraryControl>(this)),
m_pLibraryWidget(nullptr),
m_pMixxxLibraryFeature(nullptr),
m_pPlaylistFeature(nullptr),
m_pCrateFeature(nullptr),
Expand Down Expand Up @@ -103,6 +104,7 @@ Library::Library(
#endif

addFeature(new AutoDJFeature(this, m_pConfig, pPlayerManager));

m_pPlaylistFeature = new PlaylistFeature(this, UserSettingsPointer(m_pConfig));
addFeature(m_pPlaylistFeature);

Expand Down Expand Up @@ -138,6 +140,7 @@ Library::Library(
addFeature(browseFeature);

addFeature(new RecordingFeature(this, m_pConfig, pRecordingManager));

addFeature(new SetlogFeature(this, UserSettingsPointer(m_pConfig)));

m_pAnalysisFeature = new AnalysisFeature(this, m_pConfig);
Expand Down Expand Up @@ -368,10 +371,11 @@ void Library::bindSidebarWidget(WLibrarySidebar* pSidebarWidget) {

void Library::bindLibraryWidget(
WLibrary* pLibraryWidget, KeyboardEventFilter* pKeyboard) {
WTrackTableView* pTrackTableView = new WTrackTableView(pLibraryWidget,
m_pLibraryWidget = pLibraryWidget;
WTrackTableView* pTrackTableView = new WTrackTableView(m_pLibraryWidget,
m_pConfig,
this,
pLibraryWidget->getTrackTableBackgroundColorOpacity(),
m_pLibraryWidget->getTrackTableBackgroundColorOpacity(),
true);
pTrackTableView->installEventFilter(pKeyboard);
connect(this,
Expand All @@ -386,11 +390,11 @@ void Library::bindLibraryWidget(
&WTrackTableView::loadTrackToPlayer,
this,
&Library::slotLoadTrackToPlayer);
pLibraryWidget->registerView(m_sTrackViewName, pTrackTableView);
m_pLibraryWidget->registerView(m_sTrackViewName, pTrackTableView);

connect(this,
&Library::switchToView,
pLibraryWidget,
m_pLibraryWidget,
&WLibrary::switchToView);
connect(this,
&Library::saveModelState,
Expand All @@ -400,6 +404,10 @@ void Library::bindLibraryWidget(
&Library::restoreModelState,
pTrackTableView,
&WTrackTableView::slotRestoreCurrentViewState);
connect(this,
&Library::selectTrack,
m_pLibraryWidget,
&WLibrary::slotSelectTrackInActiveTrackView);
connect(pTrackTableView,
&WTrackTableView::trackSelected,
this,
Expand All @@ -418,7 +426,7 @@ void Library::bindLibraryWidget(
pTrackTableView,
&WTrackTableView::setSelectedClick);

m_pLibraryControl->bindLibraryWidget(pLibraryWidget, pKeyboard);
m_pLibraryControl->bindLibraryWidget(m_pLibraryWidget, pKeyboard);

connect(m_pLibraryControl,
&LibraryControl::showHideTrackMenu,
Expand All @@ -430,7 +438,7 @@ void Library::bindLibraryWidget(
&LibraryControl::slotUpdateTrackMenuControl);

for (const auto& feature : qAsConst(m_features)) {
feature->bindLibraryWidget(pLibraryWidget, pKeyboard);
feature->bindLibraryWidget(m_pLibraryWidget, pKeyboard);
}

// Set the current font and row height on all the WTrackTableViews that were
Expand Down Expand Up @@ -668,6 +676,14 @@ std::unique_ptr<mixxx::LibraryExporter> Library::makeLibraryExporter(
}
#endif

bool Library::isTrackIdInCurrentLibraryView(const TrackId& trackId) {
if (m_pLibraryWidget) {
return m_pLibraryWidget->isTrackInCurrentView(trackId);
} else {
return false;
}
}

LibraryTableModel* Library::trackTableModel() const {
VERIFY_OR_DEBUG_ASSERT(m_pMixxxLibraryFeature) {
return nullptr;
Expand Down
4 changes: 4 additions & 0 deletions src/library/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class Library: public QObject {
/// Needed for exposing models to QML
LibraryTableModel* trackTableModel() const;

bool isTrackIdInCurrentLibraryView(const TrackId& trackId);

int getTrackTableRowHeight() const {
return m_iTrackTableRowHeight;
}
Expand Down Expand Up @@ -127,6 +129,7 @@ class Library: public QObject {
void disableSearch();
// emit this signal to enable/disable the cover art widget
void enableCoverArtDisplay(bool);
void selectTrack(const TrackId&);
void trackSelected(TrackPointer pTrack);
#ifdef __ENGINEPRIME__
void exportLibrary();
Expand Down Expand Up @@ -157,6 +160,7 @@ class Library: public QObject {
QList<LibraryFeature*> m_features;
const static QString m_sTrackViewName;
const static QString m_sAutoDJViewName;
WLibrary* m_pLibraryWidget;
MixxxLibraryFeature* m_pMixxxLibraryFeature;
PlaylistFeature* m_pPlaylistFeature;
CrateFeature* m_pCrateFeature;
Expand Down
1 change: 0 additions & 1 deletion src/library/recording/dlgrecording.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "recording/recordingmanager.h"
#include "track/track_decl.h"

class PlaylistTableModel;
class WLibrary;
class WTrackTableView;

Expand Down
49 changes: 43 additions & 6 deletions src/widget/wlibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ void WLibrary::setup(const QDomNode& node, const SkinContext& context) {
}

bool WLibrary::registerView(const QString& name, QWidget* view) {
//qDebug() << "WLibrary::registerView" << name;
const auto lock = lockMutex(&m_mutex);
if (m_viewMap.contains(name)) {
return false;
}
if (dynamic_cast<LibraryView*>(view) == nullptr) {
qDebug() << "WARNING: Attempted to register a view with WLibrary "
<< "that does not implement the LibraryView interface. "
qDebug() << "WARNING: Attempted to register view" << name << "with WLibrary "
<< "which does not implement the LibraryView interface. "
<< "Ignoring.";
return false;
}
Expand All @@ -58,8 +59,8 @@ void WLibrary::switchToView(const QString& name) {
if (widget != nullptr) {
LibraryView * lview = dynamic_cast<LibraryView*>(widget);
if (lview == nullptr) {
qDebug() << "WARNING: Attempted to register a view with WLibrary "
<< "that does not implement the LibraryView interface. "
qDebug() << "WARNING: Attempted to switch to view" << name << "with WLibrary "
<< "which does not implement the LibraryView interface. "
<< "Ignoring.";
return;
}
Expand All @@ -80,8 +81,8 @@ void WLibrary::search(const QString& name) {
QWidget* current = currentWidget();
LibraryView* view = dynamic_cast<LibraryView*>(current);
if (view == nullptr) {
qDebug() << "WARNING: Attempted to register a view with WLibrary "
<< "that does not implement the LibraryView interface. Ignoring.";
qDebug() << "WARNING: Attempted to search in view" << name << "with WLibrary "
<< "which does not implement the LibraryView interface. Ignoring.";
return;
}
lock.unlock();
Expand All @@ -92,6 +93,42 @@ LibraryView* WLibrary::getActiveView() const {
return dynamic_cast<LibraryView*>(currentWidget());
}

bool WLibrary::isTrackInCurrentView(const TrackId& trackId) {
//qDebug() << "WLibrary::isTrackInCurrentView" << trackId;
QWidget* current = currentWidget();
WTrackTableView* tracksView = qobject_cast<WTrackTableView*>(current);
if (!tracksView) {
// This view is no tracks view, but maybe a special tracks view with a
// controls row (AutoDJ, Recording)?
//qDebug() << " view is no tracks view. look for tracks view child";
tracksView = current->findChild<WTrackTableView*>();
}
if (tracksView) {
//qDebug() << " tracks view found";
return tracksView->isTrackInCurrentView(trackId);
} else {
// No tracks view, this is probably a root view WLibraryTextBrowser
//qDebug() << " no tracks view found";
return false;
}
}

void WLibrary::slotSelectTrackInActiveTrackView(const TrackId& trackId) {
//qDebug() << "WLibrary::slotSelectTrackInActiveTrackView" << trackId;
QWidget* current = currentWidget();
WTrackTableView* tracksView = qobject_cast<WTrackTableView*>(current);
if (!tracksView) {
//qDebug() << " view is no tracks view. look for tracks view child";
tracksView = current->findChild<WTrackTableView*>();
}
if (tracksView) {
//qDebug() << " tracks view found";
tracksView->slotSelectTrack(trackId);
} else {
//qDebug() << " no tracks view found";
}
}

bool WLibrary::event(QEvent* pEvent) {
if (pEvent->type() == QEvent::ToolTip) {
updateTooltip();
Expand Down
7 changes: 7 additions & 0 deletions src/widget/wlibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ class WLibrary : public QStackedWidget, public WBaseWidget {

LibraryView* getActiveView() const;

// This returns true if the current view is or has a WTracksTableView and
// contains trackId, otherwise false.
// This is primarily used to disable the "Select track in library" track menu action
// to avoid unintended behaviour if the current view has no tracks table.
bool isTrackInCurrentView(const TrackId& trackId);

// Alpha value for row color background
static constexpr double kDefaultTrackTableBackgroundColorOpacity = 0.125; // 12.5% opacity
static constexpr double kMinTrackTableBackgroundColorOpacity = 0.0; // 0% opacity
Expand All @@ -47,6 +53,7 @@ class WLibrary : public QStackedWidget, public WBaseWidget {
// view is the specified view, or if the name does not specify any
// registered view.
void switchToView(const QString& name);
void slotSelectTrackInActiveTrackView(const TrackId& trackId);

void search(const QString&);

Expand Down
29 changes: 29 additions & 0 deletions src/widget/wtrackmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ void WTrackMenu::createActions() {
connect(m_pFileBrowserAct, &QAction::triggered, this, &WTrackMenu::slotOpenInFileBrowser);
}

if (featureIsEnabled(Feature::SelectInLibrary)) {
m_pSelectInLibraryAct = new QAction(tr("Select in Library"), this);
connect(m_pSelectInLibraryAct, &QAction::triggered, this, &WTrackMenu::slotSelectInLibrary);
}

if (featureIsEnabled(Feature::Metadata)) {
m_pImportMetadataFromFileAct =
new QAction(tr("Import From File Tags"), m_pMetadataMenu);
Expand Down Expand Up @@ -415,6 +420,14 @@ void WTrackMenu::createActions() {
void WTrackMenu::setupActions() {
if (featureIsEnabled(Feature::SearchRelated)) {
addMenu(m_pSearchRelatedMenu);
}

if (featureIsEnabled(Feature::SelectInLibrary)) {
addAction(m_pSelectInLibraryAct);
}

if (featureIsEnabled(Feature::SearchRelated) ||
featureIsEnabled(Feature::SelectInLibrary)) {
addSeparator();
}

Expand Down Expand Up @@ -818,6 +831,14 @@ void WTrackMenu::updateMenus() {
}
}

if (featureIsEnabled(Feature::SelectInLibrary)) {
bool enabled = false;
if (m_pTrack) {
enabled = m_pLibrary->isTrackIdInCurrentLibraryView(m_pTrack->getId());
}
m_pSelectInLibraryAct->setEnabled(enabled);
}

if (featureIsEnabled(Feature::Properties)) {
m_pPropertiesAct->setEnabled(singleTrackSelected);
}
Expand Down Expand Up @@ -970,6 +991,12 @@ void WTrackMenu::slotOpenInFileBrowser() {
mixxx::DesktopHelper::openInFileBrowser(locations);
}

void WTrackMenu::slotSelectInLibrary() {
if (m_pTrack) {
emit m_pLibrary->selectTrack(m_pTrack->getId());
}
}

namespace {

class ImportMetadataFromFileTagsTrackPointerOperation : public mixxx::TrackPointerOperation {
Expand Down Expand Up @@ -2134,6 +2161,8 @@ bool WTrackMenu::featureIsEnabled(Feature flag) const {
return m_pTrackModel->hasCapabilities(TrackModel::Capability::EditMetadata);
case Feature::SearchRelated:
return m_pLibrary != nullptr;
case Feature::SelectInLibrary:
return m_pTrack != nullptr;
default:
DEBUG_ASSERT(!"unreachable");
return false;
Expand Down
7 changes: 6 additions & 1 deletion src/widget/wtrackmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ class WTrackMenu : public QMenu {
Properties = 1 << 12,
SearchRelated = 1 << 13,
UpdateReplayGainFromPregain = 1 << 14,
SelectInLibrary = 1 << 15,
TrackModelFeatures = Remove | HideUnhidePurge,
All = AutoDJ | LoadTo | Playlist | Crate | Remove | Metadata | Reset |
BPM | Color | HideUnhidePurge | RemoveFromDisk | FileBrowser |
Properties | SearchRelated | UpdateReplayGainFromPregain
Properties | SearchRelated | UpdateReplayGainFromPregain | SelectInLibrary
};
Q_DECLARE_FLAGS(Features, Feature)

Expand Down Expand Up @@ -88,6 +89,7 @@ class WTrackMenu : public QMenu {
private slots:
// File
void slotOpenInFileBrowser();
void slotSelectInLibrary();

// Row color
void slotColorPicked(const mixxx::RgbColor::optional_t& color);
Expand Down Expand Up @@ -253,6 +255,9 @@ class WTrackMenu : public QMenu {
// Open file in default file browser
QAction* m_pFileBrowserAct{};

// Select track in library
QAction* m_pSelectInLibraryAct{};

// BPM feature
QAction* m_pBpmLockAction{};
QAction* m_pBpmUnlockAction{};
Expand Down
3 changes: 2 additions & 1 deletion src/widget/wtrackproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ constexpr WTrackMenu::Features kTrackMenuFeatures =
WTrackMenu::Feature::RemoveFromDisk |
WTrackMenu::Feature::FileBrowser |
WTrackMenu::Feature::Properties |
WTrackMenu::Feature::UpdateReplayGainFromPregain;
WTrackMenu::Feature::UpdateReplayGainFromPregain |
WTrackMenu::Feature::SelectInLibrary;
} // namespace

WTrackProperty::WTrackProperty(
Expand Down
Loading

0 comments on commit 9148cb2

Please sign in to comment.