From 15ed75b116367c9f5ded61bc21e4425725630ec3 Mon Sep 17 00:00:00 2001 From: ronso0 Date: Wed, 28 Feb 2024 13:08:52 +0100 Subject: [PATCH 1/3] View menu: add 'Show Auto DJ' action --- src/library/autodj/autodjfeature.cpp | 11 +++-------- src/library/autodj/autodjfeature.h | 1 + src/library/library.cpp | 14 ++++++++++++-- src/library/library.h | 6 +++++- src/mixxxmainwindow.cpp | 5 +++++ src/widget/wlibrary.cpp | 9 ++++----- src/widget/wmainmenubar.cpp | 14 ++++++++++++++ src/widget/wmainmenubar.h | 1 + 8 files changed, 45 insertions(+), 16 deletions(-) diff --git a/src/library/autodj/autodjfeature.cpp b/src/library/autodj/autodjfeature.cpp index a004dfa7f44c..03d745ef5490 100644 --- a/src/library/autodj/autodjfeature.cpp +++ b/src/library/autodj/autodjfeature.cpp @@ -22,12 +22,6 @@ #include "widget/wlibrary.h" #include "widget/wlibrarysidebar.h" -namespace { - -const QString kViewName = QStringLiteral("Auto DJ"); - -} // namespace - namespace { constexpr int kMaxRetrieveAttempts = 3; @@ -55,6 +49,7 @@ AutoDJFeature::AutoDJFeature(Library* pLibrary, m_pAutoDJProcessor(nullptr), m_pSidebarModel(make_parented(this)), m_pAutoDJView(nullptr), + m_viewName(Library::kAutoDJViewName), m_autoDjCratesDao(m_iAutoDJPlaylistId, pLibrary->trackCollectionManager(), m_pConfig) { qRegisterMetaType("AutoDJState"); m_pAutoDJProcessor = new AutoDJProcessor(this, @@ -152,7 +147,7 @@ void AutoDJFeature::bindLibraryWidget( m_pLibrary, m_pAutoDJProcessor, keyboard); - libraryWidget->registerView(kViewName, m_pAutoDJView); + libraryWidget->registerView(m_viewName, m_pAutoDJView); connect(m_pAutoDJView, &DlgAutoDJ::loadTrack, this, @@ -196,7 +191,7 @@ TreeItemModel* AutoDJFeature::sidebarModel() const { void AutoDJFeature::activate() { //qDebug() << "AutoDJFeature::activate()"; - emit switchToView(kViewName); + emit switchToView(m_viewName); emit disableSearch(); emit enableCoverArtDisplay(true); } diff --git a/src/library/autodj/autodjfeature.h b/src/library/autodj/autodjfeature.h index f17f44785039..53edd691426b 100644 --- a/src/library/autodj/autodjfeature.h +++ b/src/library/autodj/autodjfeature.h @@ -65,6 +65,7 @@ class AutoDJFeature : public LibraryFeature { AutoDJProcessor* m_pAutoDJProcessor; parented_ptr m_pSidebarModel; DlgAutoDJ* m_pAutoDJView; + const QString m_viewName; // Initialize the list of crates loaded into the auto-DJ queue. void constructCrateChildModel(); diff --git a/src/library/library.cpp b/src/library/library.cpp index 21f543399406..782f71a19608 100644 --- a/src/library/library.cpp +++ b/src/library/library.cpp @@ -51,7 +51,9 @@ using namespace mixxx::library::prefs; // This is the name which we use to register the WTrackTableView with the // WLibrary -const QString Library::m_sTrackViewName = QString("WTrackTableView"); +const QString Library::m_sTrackViewName = QStringLiteral("WTrackTableView"); + +const QString Library::kAutoDJViewName = QStringLiteral("Auto DJ"); // The default row height of the library. const int Library::kDefaultRowHeightPx = 20; @@ -71,6 +73,7 @@ Library::Library( m_pLibraryControl(make_parented(this)), m_pLibraryWidget(nullptr), m_pMixxxLibraryFeature(nullptr), + m_pAutoDJFeature(nullptr), m_pPlaylistFeature(nullptr), m_pCrateFeature(nullptr), m_pAnalysisFeature(nullptr) { @@ -98,7 +101,8 @@ Library::Library( Qt::DirectConnection /* signal-to-signal */); #endif - addFeature(new AutoDJFeature(this, m_pConfig, pPlayerManager)); + m_pAutoDJFeature = new AutoDJFeature(this, m_pConfig, pPlayerManager); + addFeature(m_pAutoDJFeature); m_pPlaylistFeature = new PlaylistFeature(this, UserSettingsPointer(m_pConfig)); addFeature(m_pPlaylistFeature); @@ -756,6 +760,12 @@ void Library::searchTracksInCollection(const QString& query) { m_pMixxxLibraryFeature->searchAndActivate(query); } +void Library::showAutoDJ() { + m_pAutoDJFeature->activate(); + emit switchToView(kAutoDJViewName); + m_pSidebarModel->slotFeatureSelect(m_pAutoDJFeature); +} + #ifdef __ENGINEPRIME__ std::unique_ptr Library::makeLibraryExporter( QWidget* parent) { diff --git a/src/library/library.h b/src/library/library.h index e4240aaf4686..8968a305f773 100644 --- a/src/library/library.h +++ b/src/library/library.h @@ -16,6 +16,7 @@ #include "util/parented_ptr.h" class AnalysisFeature; +class AutoDJFeature; class BrowseFeature; class ControlObject; class CrateFeature; @@ -105,6 +106,9 @@ class Library: public QObject { /// Triggers a new search in the internal track collection /// and shows the results by switching the view. void searchTracksInCollection(const QString& query); + void showAutoDJ(); + + static const QString kAutoDJViewName; bool requestAddDir(const QString& directory); bool requestRemoveDir(const QString& directory, LibraryRemovalType removalType); @@ -189,9 +193,9 @@ class Library: public QObject { QList m_features; const static QString m_sTrackViewName; - const static QString m_sAutoDJViewName; WLibrary* m_pLibraryWidget; MixxxLibraryFeature* m_pMixxxLibraryFeature; + AutoDJFeature* m_pAutoDJFeature; PlaylistFeature* m_pPlaylistFeature; CrateFeature* m_pCrateFeature; AnalysisFeature* m_pAnalysisFeature; diff --git a/src/mixxxmainwindow.cpp b/src/mixxxmainwindow.cpp index 4cda0aa7a57d..69d183e7554b 100644 --- a/src/mixxxmainwindow.cpp +++ b/src/mixxxmainwindow.cpp @@ -976,6 +976,11 @@ void MixxxMainWindow::connectMenuBar() { m_pCoreServices->getLibrary().get(), &Library::slotCreatePlaylist, Qt::UniqueConnection); + connect(m_pMenuBar, + &WMainMenuBar::showAutoDJ, + m_pCoreServices->getLibrary().get(), + &Library::showAutoDJ, + Qt::UniqueConnection); } #ifdef __ENGINEPRIME__ diff --git a/src/widget/wlibrary.cpp b/src/widget/wlibrary.cpp index dcc0390dde33..5520c0b3ce4f 100644 --- a/src/widget/wlibrary.cpp +++ b/src/widget/wlibrary.cpp @@ -55,9 +55,6 @@ void WLibrary::switchToView(const QString& name) { const auto lock = lockMutex(&m_mutex); //qDebug() << "WLibrary::switchToView" << name; - LibraryView* pOldLibrartView = dynamic_cast( - currentWidget()); - QWidget* pWidget = m_viewMap.value(name, nullptr); if (pWidget != nullptr) { LibraryView* pLibraryView = dynamic_cast(pWidget); @@ -68,8 +65,10 @@ void WLibrary::switchToView(const QString& name) { return; } if (currentWidget() != pWidget) { - if (pOldLibrartView) { - pOldLibrartView->saveCurrentViewState(); + LibraryView* pOldLibraryView = dynamic_cast( + currentWidget()); + if (pOldLibraryView) { + pOldLibraryView->saveCurrentViewState(); } //qDebug() << "WLibrary::setCurrentWidget" << name; setCurrentWidget(pWidget); diff --git a/src/widget/wmainmenubar.cpp b/src/widget/wmainmenubar.cpp index b22196815dfa..cac1b2f5b044 100644 --- a/src/widget/wmainmenubar.cpp +++ b/src/widget/wmainmenubar.cpp @@ -377,6 +377,20 @@ void WMainMenuBar::initialize() { pViewMenu->addSeparator(); + QString autoDJTitle = tr("Show Auto DJ"); + QString autoDJText = tr("Switch to the Auto DJ view."); + auto* pViewAutoDJ = new QAction(autoDJTitle, this); + // pViewAutoDJ->setShortcut(QKeySequence(m_pKbdConfig->getValue( + // ConfigKey("[KeyboardShortcuts]", "ViewMenu_ShowAutoDJ"), + // tr("Ctrl+9", "Menubar|View|Show Auto DJ")))); + pViewAutoDJ->setStatusTip(autoDJText); + pViewAutoDJ->setWhatsThis(buildWhatsThis(autoDJTitle, autoDJText)); + pViewAutoDJ->setCheckable(false); + connect(pViewAutoDJ, &QAction::triggered, this, &WMainMenuBar::showAutoDJ); + pViewMenu->addAction(pViewAutoDJ); + + pViewMenu->addSeparator(); + QString fullScreenTitle = tr("&Full Screen"); QString fullScreenText = tr("Display Mixxx using the full screen"); auto* pViewFullScreen = new QAction(fullScreenTitle, this); diff --git a/src/widget/wmainmenubar.h b/src/widget/wmainmenubar.h index dd9fafadbcee..385c9412c369 100644 --- a/src/widget/wmainmenubar.h +++ b/src/widget/wmainmenubar.h @@ -69,6 +69,7 @@ class WMainMenuBar : public QMenuBar { #endif void searchInCurrentView(); void searchInAllTracks(); + void showAutoDJ(); void showAbout(); void showKeywheel(bool visible); void showPreferences(); From cb3dd4aa1563e56e17094df7ac89f3a417e9fee9 Mon Sep 17 00:00:00 2001 From: ronso0 Date: Mon, 29 Jul 2024 13:19:15 +0200 Subject: [PATCH 2/3] Library: don't scroll when programmatically selecting AutoDJ --- src/library/library.cpp | 3 ++- src/library/libraryfeature.h | 2 +- src/library/sidebarmodel.cpp | 8 +++++--- src/library/sidebarmodel.h | 6 ++++-- src/widget/wlibrarysidebar.cpp | 16 +++++++++++++--- src/widget/wlibrarysidebar.h | 2 +- 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/library/library.cpp b/src/library/library.cpp index 782f71a19608..ab26cadbd36b 100644 --- a/src/library/library.cpp +++ b/src/library/library.cpp @@ -763,7 +763,8 @@ void Library::searchTracksInCollection(const QString& query) { void Library::showAutoDJ() { m_pAutoDJFeature->activate(); emit switchToView(kAutoDJViewName); - m_pSidebarModel->slotFeatureSelect(m_pAutoDJFeature); + // Select it but don't scroll there + m_pSidebarModel->slotFeatureSelect(m_pAutoDJFeature, QModelIndex(), false); } #ifdef __ENGINEPRIME__ diff --git a/src/library/libraryfeature.h b/src/library/libraryfeature.h index 3c0a204cc436..cfef22ea0569 100644 --- a/src/library/libraryfeature.h +++ b/src/library/libraryfeature.h @@ -165,7 +165,7 @@ class LibraryFeature : public QObject { // emit this signal if the foreign music collection has been imported/parsed. void featureLoadingFinished(LibraryFeature*s); // emit this signal to select pFeature - void featureSelect(LibraryFeature* pFeature, const QModelIndex& index); + void featureSelect(LibraryFeature* pFeature, const QModelIndex& index, bool scrollTo = true); // emit this signal to enable/disable the cover art widget void enableCoverArtDisplay(bool); void trackSelected(TrackPointer pTrack); diff --git a/src/library/sidebarmodel.cpp b/src/library/sidebarmodel.cpp index 2a43430a6913..d12e4b6d5d71 100644 --- a/src/library/sidebarmodel.cpp +++ b/src/library/sidebarmodel.cpp @@ -96,7 +96,7 @@ void SidebarModel::setDefaultSelection(unsigned int index) { void SidebarModel::activateDefaultSelection() { if (m_iDefaultSelectedIndex < static_cast(m_sFeatures.size())) { - emit selectIndex(getDefaultSelection()); + emit selectIndex(getDefaultSelection(), true /* scrollTo */); // Selecting an index does not activate it. m_sFeatures[m_iDefaultSelectedIndex]->activate(); } @@ -593,7 +593,9 @@ void SidebarModel::featureRenamed(LibraryFeature* pFeature) { } } -void SidebarModel::slotFeatureSelect(LibraryFeature* pFeature, const QModelIndex& featureIndex) { +void SidebarModel::slotFeatureSelect(LibraryFeature* pFeature, + const QModelIndex& featureIndex, + bool scrollTo) { QModelIndex ind; if (featureIndex.isValid()) { TreeItem* pTreeItem = static_cast(featureIndex.internalPointer()); @@ -606,5 +608,5 @@ void SidebarModel::slotFeatureSelect(LibraryFeature* pFeature, const QModelIndex } } } - emit selectIndex(ind); + emit selectIndex(ind, scrollTo); } diff --git a/src/library/sidebarmodel.h b/src/library/sidebarmodel.h index 60bd28c3029c..742bb0c28417 100644 --- a/src/library/sidebarmodel.h +++ b/src/library/sidebarmodel.h @@ -56,7 +56,9 @@ class SidebarModel : public QAbstractItemModel { void rightClicked(const QPoint& globalPos, const QModelIndex& index); void renameItem(const QModelIndex& index); void deleteItem(const QModelIndex& index); - void slotFeatureSelect(LibraryFeature* pFeature, const QModelIndex& index = QModelIndex()); + void slotFeatureSelect(LibraryFeature* pFeature, + const QModelIndex& index = QModelIndex(), + bool scrollTo = true); // Slots for every single QAbstractItemModel signal // void slotColumnsAboutToBeInserted(const QModelIndex& parent, int start, int end); @@ -79,7 +81,7 @@ class SidebarModel : public QAbstractItemModel { void slotFeatureLoadingFinished(LibraryFeature*); signals: - void selectIndex(const QModelIndex& index); + void selectIndex(const QModelIndex& index, bool scrollTo); private slots: void slotPressedUntilClickedTimeout(); diff --git a/src/widget/wlibrarysidebar.cpp b/src/widget/wlibrarysidebar.cpp index babe0714ac3d..fd0e9edcffa3 100644 --- a/src/widget/wlibrarysidebar.cpp +++ b/src/widget/wlibrarysidebar.cpp @@ -351,8 +351,8 @@ void WLibrarySidebar::focusInEvent(QFocusEvent* event) { QTreeView::focusInEvent(event); } -void WLibrarySidebar::selectIndex(const QModelIndex& index) { - //qDebug() << "WLibrarySidebar::selectIndex" << index; +void WLibrarySidebar::selectIndex(const QModelIndex& index, bool scrollToIndex) { + // qDebug() << "WLibrarySidebar::selectIndex" << index << scrollToIndex; if (!index.isValid()) { return; } @@ -365,8 +365,18 @@ void WLibrarySidebar::selectIndex(const QModelIndex& index) { expand(index.parent()); } setSelectionModel(pModel); + if (!scrollToIndex) { + // With auto-scroll enabled, setCurrentIndex() would scroll there. + // Disable (and re-enable if we don't want to scroll, e.g. when selecting + // AutoDJ from the menubar or during startup + setAutoScroll(false); + } setCurrentIndex(index); - scrollTo(index); + if (scrollToIndex) { + scrollTo(index); + } else { + setAutoScroll(true); + } } /// Selects a child index from a feature and ensures visibility diff --git a/src/widget/wlibrarysidebar.h b/src/widget/wlibrarysidebar.h index 2e092751ae66..a521df6e4d96 100644 --- a/src/widget/wlibrarysidebar.h +++ b/src/widget/wlibrarysidebar.h @@ -30,7 +30,7 @@ class WLibrarySidebar : public QTreeView, public WBaseWidget { bool isFeatureRootIndexSelected(LibraryFeature* pFeature); public slots: - void selectIndex(const QModelIndex&); + void selectIndex(const QModelIndex& index, bool scrollToIndex = true); void selectChildIndex(const QModelIndex&, bool selectItem = true); void slotSetFont(const QFont& font); From 3c508f35a38820f4ece6a2edb4f2abdf86ae2b6c Mon Sep 17 00:00:00 2001 From: ronso0 Date: Mon, 29 Jul 2024 15:04:44 +0200 Subject: [PATCH 3/3] startup: show AutoDJ if it's run via command line arg --- src/mixxxmainwindow.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/mixxxmainwindow.cpp b/src/mixxxmainwindow.cpp index 69d183e7554b..60d5906d91d7 100644 --- a/src/mixxxmainwindow.cpp +++ b/src/mixxxmainwindow.cpp @@ -450,6 +450,12 @@ void MixxxMainWindow::initialize() { if (CmdlineArgs::Instance().getStartAutoDJ()) { qDebug("Enabling Auto DJ from CLI flag."); ControlObject::set(ConfigKey("[AutoDJ]", "enabled"), 1.0); + // Switch to Auto DJ feature + auto* pLibrary = m_pCoreServices->getLibrary().get(); + // Note: auto-scroll is disabled but that doesn't really matter here + // because the sidebar is still in its initial state (top feature visible, + // AutoDj is second from the top by default, all features collapsed). + pLibrary->showAutoDJ(); } }