diff options
author | Arno <arno@disconnect.de> | 2018-02-18 08:28:59 +0100 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2018-02-18 08:28:59 +0100 |
commit | a80fe1e9dc3a16d9c41d40065768315237b8091f (patch) | |
tree | 5622440bb751b9333cf9cf89dee21abc7504731c /playerwidget.cpp | |
parent | 2c720f3c54b054db348b8107f14362ce1fb2d430 (diff) | |
download | BeetPlayer-a80fe1e9dc3a16d9c41d40065768315237b8091f.tar.gz BeetPlayer-a80fe1e9dc3a16d9c41d40065768315237b8091f.tar.bz2 BeetPlayer-a80fe1e9dc3a16d9c41d40065768315237b8091f.zip |
Implement "Goto album"
Raise album view and select, center and expand album if found. It's
useful for albums with various artists, I hope.
Diffstat (limited to 'playerwidget.cpp')
-rw-r--r-- | playerwidget.cpp | 29 |
1 files changed, 25 insertions, 4 deletions
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("<tr><td>License</td><td style=\"padding-left: 30px\">GPL 2 or later</td></tr></table>")); QMessageBox::about(this, title, aboutText); } + +void PlayerWidget::gotoAlbum(){ + CollectionArtistsView *artistView = mCollectionStack->findChild<CollectionArtistsView*>("artists"); + CollectionAlbumsView *albumView = mCollectionStack->findChild<CollectionAlbumsView*>("albums"); + QString album = artistView->view()->selectionModel()->currentIndex().data(AlbumRole).toString(); + if(!album.isEmpty()){ + const CollectionWidgetProxy *proxy = qobject_cast<const CollectionWidgetProxy*>(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); + } + } +} |