diff options
author | Arno <arno@disconnect.de> | 2017-02-27 01:41:36 +0100 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2017-02-27 01:41:36 +0100 |
commit | 14992a657c57fa712a58a9b0ef117bb4c75fce97 (patch) | |
tree | bdb24803b9beac36dd277070edc1e2da97d30e6c /playerwidget.cpp | |
parent | cba00af5348162259eb7909078083edf510853f5 (diff) | |
download | BeetPlayer-14992a657c57fa712a58a9b0ef117bb4c75fce97.tar.gz BeetPlayer-14992a657c57fa712a58a9b0ef117bb4c75fce97.tar.bz2 BeetPlayer-14992a657c57fa712a58a9b0ef117bb4c75fce97.zip |
Implement shuffle playlist
And add some artwork for icons...
Diffstat (limited to 'playerwidget.cpp')
-rw-r--r-- | playerwidget.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/playerwidget.cpp b/playerwidget.cpp index 976da48..a00ded3 100644 --- a/playerwidget.cpp +++ b/playerwidget.cpp @@ -15,6 +15,8 @@ #include <QAction> #include <QToolBar> +#include <algorithm> + #include "playerwidget.h" #include "beetview.h" #include "indexerdialog.h" @@ -124,9 +126,12 @@ void PlayerWidget::createActions(){ connect(clearPlayListA, SIGNAL(triggered()), this, SLOT(clearPlayList())); QAction *refreshA = new QAction(QIcon(":/refresh.png"), tr("Refresh..."), this); connect(refreshA, SIGNAL(triggered()), this, SLOT(reindex())); + QAction *shufflePlayistA = new QAction(QIcon(":/shuffle.png"), tr("Shuffle playlist"), this); + connect(shufflePlayistA, SIGNAL(triggered()), this, SLOT(shufflePlayList())); QAction *configA = Globals::instance()->action(Globals::ConfigAction); mView->addAction(addToPlayListA); mPlayListView->addAction(removeFromPlayListA); + mPlayListView->addAction(shufflePlayistA); mPlayListView->addAction(clearPlayListA); QWidget* spacer1 = new QWidget(); spacer1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -138,6 +143,7 @@ void PlayerWidget::createActions(){ mToolBar->addAction(addToPlayListA); mToolBar->addAction(removeFromPlayListA); mToolBar->addAction(clearPlayListA); + mToolBar->addAction(shufflePlayistA); mToolBar->addSeparator(); mToolBar->addAction(refreshA); mToolBar->addSeparator(); @@ -357,3 +363,18 @@ void PlayerWidget::clearPlayList(){ mPlayListModel->clear(); mPlayListModel->setHorizontalHeaderLabels(QStringList() << "Title"); } + +void PlayerWidget::shufflePlayList(){ + QVector<QStandardItem*> items; + for(int i = 0; i < mPlayListModel->rowCount(); ++i){ + QStandardItem *cur = mPlayListModel->item(i, 0)->clone(); + items << cur; + } + std::random_shuffle(items.begin(), items.end()); + mPlayListModel->clear(); + mPlayListModel->setHorizontalHeaderLabels(QStringList() << "Title"); + QStandardItem *root = mPlayListModel->invisibleRootItem(); + foreach(QStandardItem *i, items){ + root->appendRow(i); + } +} |