From a80fe1e9dc3a16d9c41d40065768315237b8091f Mon Sep 17 00:00:00 2001 From: Arno Date: Sun, 18 Feb 2018 08:28:59 +0100 Subject: Implement "Goto album" Raise album view and select, center and expand album if found. It's useful for albums with various artists, I hope. --- playerwidget.cpp | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'playerwidget.cpp') diff --git a/playerwidget.cpp b/playerwidget.cpp index f589f4d..cc6af7c 100644 --- a/playerwidget.cpp +++ b/playerwidget.cpp @@ -48,6 +48,7 @@ #include "collectionfavoritesview.h" #include "collectionfoldersview.h" #include "collectionwebradioview.h" +#include "collectionwidgetproxy.h" PlayerWidget::PlayerWidget(QSplashScreen *splash, QWidget *parent) : QWidget(parent), mDurSecs(0), mPlayListLength(0), mIsStream(false), mModelType(DoNotCare){ mStarting = true; @@ -101,10 +102,10 @@ void PlayerWidget::setupGui(QSplashScreen *splash){ qApp->processEvents(); albumsView->populate(); cIdx = mCollectionStack->addWidget(albumsView); - QAction *viewByAlbumsA = new QAction(QIcon(":/album.png"), tr("View by album"), this); - viewByAlbumsA->setCheckable(true); - connect(viewByAlbumsA, &QAction::triggered, [this, cIdx] { mCollectionStack->setCurrentIndex(cIdx); }); - bottomTBG->addAction(viewByAlbumsA); + mViewByAlbumsA = new QAction(QIcon(":/album.png"), tr("View by album"), this); + mViewByAlbumsA->setCheckable(true); + connect(mViewByAlbumsA, &QAction::triggered, [this, cIdx] { mCollectionStack->setCurrentIndex(cIdx); }); + bottomTBG->addAction(mViewByAlbumsA); //dates view CollectionDatesView *datesView = new CollectionDatesView;; datesView->setHeaders(QStringList() << tr("Date added")); @@ -180,6 +181,9 @@ void PlayerWidget::setupGui(QSplashScreen *splash){ connect(searchMBA, &QAction::triggered, [this, curW] { searchMusicbrainz(curW->view()->selectionModel()->currentIndex()); }); curW->view()->addAction(searchMBA); } + QAction *gotoAlbumA = new QAction(QIcon(":/next.png"), tr("Goto album"), this); + connect(gotoAlbumA, &QAction::triggered, this, &PlayerWidget::gotoAlbum); + artistsView->view()->addAction(gotoAlbumA); //left widget QWidget *leftWidget = new QWidget; @@ -985,3 +989,20 @@ void PlayerWidget::aboutDlg(){ aboutText.append(tr("LicenseGPL 2 or later")); QMessageBox::about(this, title, aboutText); } + +void PlayerWidget::gotoAlbum(){ + CollectionArtistsView *artistView = mCollectionStack->findChild("artists"); + CollectionAlbumsView *albumView = mCollectionStack->findChild("albums"); + QString album = artistView->view()->selectionModel()->currentIndex().data(AlbumRole).toString(); + if(!album.isEmpty()){ + const CollectionWidgetProxy *proxy = qobject_cast(albumView->view()->model()); + QModelIndexList albumIdxs = proxy->match(proxy->index(0, 0, QModelIndex()), AlbumRole, album); + if(!albumIdxs.isEmpty()){ + mViewByAlbumsA->trigger(); + QModelIndex albumIdx = albumIdxs.first(); + albumView->view()->selectionModel()->select(albumIdx, QItemSelectionModel::ClearAndSelect); + albumView->view()->scrollTo(albumIdx, QAbstractItemView::PositionAtCenter); + albumView->view()->expand(albumIdx); + } + } +} -- cgit v1.2.3-70-g09d2