summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2017-02-27 10:53:18 +0100
committerArno <arno@disconnect.de>2017-02-27 10:53:18 +0100
commit52384c4685a9d25ceb97b8acc36fe5844ec112b4 (patch)
treed49d3b6631f5e576a3641f6e7740c8c15521a649
parent1829b80114d5cfe2e097491b658eb39f4fbe71c0 (diff)
downloadBeetPlayer-52384c4685a9d25ceb97b8acc36fe5844ec112b4.tar.gz
BeetPlayer-52384c4685a9d25ceb97b8acc36fe5844ec112b4.tar.bz2
BeetPlayer-52384c4685a9d25ceb97b8acc36fe5844ec112b4.zip
Implement previous and next
-rw-r--r--beetplayer.qrc2
-rw-r--r--next.pngbin0 -> 966 bytes
-rw-r--r--playerwidget.cpp50
-rw-r--r--playerwidget.h4
-rw-r--r--previous.pngbin0 -> 956 bytes
5 files changed, 50 insertions, 6 deletions
diff --git a/beetplayer.qrc b/beetplayer.qrc
index c115556..c3b4f0d 100644
--- a/beetplayer.qrc
+++ b/beetplayer.qrc
@@ -12,5 +12,7 @@
<file>dice.png</file>
<file>shuffle.png</file>
<file>mute.png</file>
+ <file>previous.png</file>
+ <file>next.png</file>
</qresource>
</RCC>
diff --git a/next.png b/next.png
new file mode 100644
index 0000000..13142fa
--- /dev/null
+++ b/next.png
Binary files differ
diff --git a/playerwidget.cpp b/playerwidget.cpp
index 13cd2f5..bfe3815 100644
--- a/playerwidget.cpp
+++ b/playerwidget.cpp
@@ -154,11 +154,15 @@ void PlayerWidget::createActions(){
pauseA->setCheckable(true);
playAG->addAction(pauseA);
connect(pauseA, SIGNAL(triggered()), mPlayer, SLOT(pause()));
- QAction *stopA = new QAction(QIcon(":/stop.png"), tr("Stop"), this);
- stopA->setCheckable(true);
- playAG->addAction(stopA);
- stopA->trigger();
- connect(stopA, SIGNAL(triggered()), mPlayer, SLOT(stop()));
+ mStopA = new QAction(QIcon(":/stop.png"), tr("Stop"), this);
+ mStopA->setCheckable(true);
+ playAG->addAction(mStopA);
+ mStopA->trigger();
+ connect(mStopA, SIGNAL(triggered()), mPlayer, SLOT(stop()));
+ QAction *previousA = new QAction(QIcon(":/previous.png"), tr("Previous"), this);
+ connect(previousA, SIGNAL(triggered()), this, SLOT(previous()));
+ QAction *nextA = new QAction(QIcon(":/next.png"), tr("Next"), this);
+ connect(nextA, SIGNAL(triggered()), this, SLOT(next()));
QAction *addToPlayListA = new QAction(QIcon(":/belly_right.png"), tr("Add to playlist"), this);
connect(addToPlayListA, SIGNAL(triggered()), this, SLOT(addToPlayList()));
QAction *removeFromPlayListA = new QAction(QIcon(":/belly_left.png"), tr("Remove from playlist"), this);
@@ -185,7 +189,10 @@ void PlayerWidget::createActions(){
mToolBar->addWidget(spacer1);
mToolBar->addAction(mPlayA);
mToolBar->addAction(pauseA);
- mToolBar->addAction(stopA);
+ mToolBar->addAction(mStopA);
+ mToolBar->addSeparator();
+ mToolBar->addAction(previousA);
+ mToolBar->addAction(nextA);
mToolBar->addSeparator();
mToolBar->addAction(addToPlayListA);
mToolBar->addAction(removeFromPlayListA);
@@ -466,3 +473,34 @@ void PlayerWidget::volumeChanged(int volume){
void PlayerWidget::mute(bool triggered){
mPlayer->setMuted(triggered);
}
+
+void PlayerWidget::next(){
+ advance(1);
+}
+
+void PlayerWidget::previous(){
+ advance(-1);
+}
+
+void PlayerWidget::advance(int numSongs){
+ QModelIndexList sel = mPlayListView->selectionModel()->selectedRows();
+ if(sel.isEmpty()){
+ QStandardItem *root = mPlayListModel->invisibleRootItem();
+ if(root->rowCount() > 0){
+ QModelIndex first = mPlayListModel->index(0, 0);
+ mPlayListView->selectionModel()->setCurrentIndex(first, QItemSelectionModel::ClearAndSelect);
+ QString fp = first.data(FullPathRole).toString();
+ play(fp);
+ return;
+ }
+ return;
+ }
+ QModelIndex cur = sel.first();
+ QModelIndex nextIdx = mPlayListModel->index(cur.row() + numSongs, 0);
+ if(nextIdx.isValid()){
+ mPlayListView->selectionModel()->setCurrentIndex(nextIdx, QItemSelectionModel::ClearAndSelect);
+ cur = nextIdx;
+ QString fp = cur.data(FullPathRole).toString();
+ play(fp);
+ }
+}
diff --git a/playerwidget.h b/playerwidget.h
index a4d183a..e828748 100644
--- a/playerwidget.h
+++ b/playerwidget.h
@@ -35,6 +35,8 @@ class PlayerWidget : public QWidget {
void playCurrent(const QModelIndex &index);
void mute(bool triggered);
void volumeChanged(int volume);
+ void next();
+ void previous();
private:
void setupGui();
@@ -45,6 +47,7 @@ class PlayerWidget : public QWidget {
void recurse(const QModelIndex &parent);
void addSong(const QModelIndex &idx);
void play(const QString &fullPath);
+ void advance(int numSongs);
QLineEdit *mFilter;
QMediaPlayer *mPlayer;
BeetView *mView;
@@ -61,6 +64,7 @@ class PlayerWidget : public QWidget {
QStandardItemModel *mPlayListModel;
QToolBar *mToolBar;
QAction *mPlayA;
+ QAction *mStopA;
};
#endif // PLAYERWIDGET_H
diff --git a/previous.png b/previous.png
new file mode 100644
index 0000000..d84ffca
--- /dev/null
+++ b/previous.png
Binary files differ