diff options
-rw-r--r-- | beetplayer.qrc | 2 | ||||
-rw-r--r-- | next.png | bin | 0 -> 966 bytes | |||
-rw-r--r-- | playerwidget.cpp | 50 | ||||
-rw-r--r-- | playerwidget.h | 4 | ||||
-rw-r--r-- | previous.png | bin | 0 -> 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 Binary files differnew file mode 100644 index 0000000..13142fa --- /dev/null +++ b/next.png 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 Binary files differnew file mode 100644 index 0000000..d84ffca --- /dev/null +++ b/previous.png |