From 7de8b0574b37d32e91939461c7bab93b818af620 Mon Sep 17 00:00:00 2001 From: Arno Date: Mon, 19 Feb 2018 02:46:37 +0100 Subject: Implement QAction to fill playlist with favorites --- playerwidget.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'playerwidget.cpp') diff --git a/playerwidget.cpp b/playerwidget.cpp index e9349f3..be4eb62 100644 --- a/playerwidget.cpp +++ b/playerwidget.cpp @@ -208,6 +208,11 @@ void PlayerWidget::setupGui(QSplashScreen *splash){ QAction *searchMBA = new QAction(QIcon(":/bizarre_amputee.png"), tr("Search Musicbrainz"), this); connect(searchMBA, &QAction::triggered, [this, curW] { searchMusicbrainz(curW->view()->selectionModel()->currentIndex()); }); curW->view()->addAction(searchMBA); + if(name == "favorites"){ + QAction *addAllFavsA = new QAction((QIcon(":/shuffle.png")), tr("Clear and Add all"), this); + connect(addAllFavsA, &QAction::triggered, this, &PlayerWidget::clearAndAddAllFavorites); + curW->customActions()->addAction(addAllFavsA); + } curW->view()->addActions(curW->customActions()->actions()); } } @@ -1067,3 +1072,16 @@ void PlayerWidget::addToFavorites(const QModelIndexList &idxs){ fav->populate(); } } + +void PlayerWidget::clearAndAddAllFavorites(){ + mSongModel->clear(); + mSongModel->setHorizontalHeaderLabels(QStringList() << "Song"); + CollectionWidget *favWidget = qobject_cast(mCollectionStack->currentWidget()); + QStandardItemModel *m = favWidget->model(); + QStandardItem *root = m->invisibleRootItem(); + for(int i = 0; i < root->rowCount(); ++i){ + QModelIndex curIdx = m->indexFromItem(root->child(i, 0)); + addSong(curIdx); + } + shufflePlayList(); +} -- cgit v1.2.3-70-g09d2