summaryrefslogtreecommitdiffstats
path: root/playerwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'playerwidget.cpp')
-rw-r--r--playerwidget.cpp21
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);
+ }
+}