diff options
author | Arno <arno@disconnect.de> | 2017-03-05 17:51:48 +0100 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2017-03-05 17:51:48 +0100 |
commit | ee0b460145fd1edd0f76bbbf3680b9ebea927940 (patch) | |
tree | 3de9268a6faf02d2f7cf0538af9233781c24d423 | |
parent | 2ff72f033af3f24ffb816bc19a34fc794f585775 (diff) | |
download | BeetPlayer-ee0b460145fd1edd0f76bbbf3680b9ebea927940.tar.gz BeetPlayer-ee0b460145fd1edd0f76bbbf3680b9ebea927940.tar.bz2 BeetPlayer-ee0b460145fd1edd0f76bbbf3680b9ebea927940.zip |
Fix play Button
Print a statusbar message when the playlist is empty. If it isn't empty,
but nothing is selected, select the first entry and play it.
-rw-r--r-- | beetplayer.cpp | 6 | ||||
-rw-r--r-- | beetplayer.h | 1 | ||||
-rw-r--r-- | playerwidget.cpp | 20 | ||||
-rw-r--r-- | playerwidget.h | 1 |
4 files changed, 26 insertions, 2 deletions
diff --git a/beetplayer.cpp b/beetplayer.cpp index 1fd0aa7..fd0d174 100644 --- a/beetplayer.cpp +++ b/beetplayer.cpp @@ -25,6 +25,7 @@ BeetPlayer::BeetPlayer(QWidget *parent, Qt::WindowFlags f) : QMainWindow(parent, connect(mPlayerWidget->player(), SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(setPlayMode(QMediaPlayer::State))); connect(mPlayerWidget, SIGNAL(numFilesChanged(int)), this, SLOT(setNumFiles(int))); connect(mPlayerWidget, SIGNAL(playListLengthChanged(quint64)), this, SLOT(setPlayListLength(quint64))); + connect(mPlayerWidget, SIGNAL(message(QString)), this, SLOT(setMessage(QString))); createStatusbar(); setCentralWidget(mPlayerWidget); } @@ -102,6 +103,10 @@ void BeetPlayer::setPlayListLength(quint64 seconds){ mPlaylistDurL->setText(r); } +void BeetPlayer::setMessage(const QString &msg){ + mGeneralL->setText(msg); +} + void BeetPlayer::createStatusbar(){ QLabel *l1 = new QLabel(tr("View:")); mModeL = new QLabel; @@ -112,6 +117,7 @@ void BeetPlayer::createStatusbar(){ statusBar()->addPermanentWidget(mModeL); mGeneralL = new QLabel; mGeneralL->setFrameStyle(QFrame::Panel | QFrame::Sunken); + mGeneralL->setFont(QFont("courier")); statusBar()->addPermanentWidget(mGeneralL, 20); //20 is an arbitray value, stretch to max QLabel *l2 = new QLabel(tr("Status:")); mActionL = new QLabel; diff --git a/beetplayer.h b/beetplayer.h index 9e7a8ce..d6e9a7b 100644 --- a/beetplayer.h +++ b/beetplayer.h @@ -19,6 +19,7 @@ class BeetPlayer : public QMainWindow { void setPlayMode(QMediaPlayer::State state); void setNumFiles(int numFiles); void setPlayListLength(quint64 seconds); + void setMessage(const QString &msg); private: void openDatabase(); diff --git a/playerwidget.cpp b/playerwidget.cpp index ebbbc16..77afffc 100644 --- a/playerwidget.cpp +++ b/playerwidget.cpp @@ -196,7 +196,7 @@ void PlayerWidget::createActions(){ mPlayA = new QAction(QIcon(":/play.png"), tr("Play"), this); mPlayA->setCheckable(true); playAG->addAction(mPlayA); - connect(mPlayA, SIGNAL(triggered()), mPlayer, SLOT(play())); + connect(mPlayA, SIGNAL(triggered()), this, SLOT(doPlay())); QAction *pauseA = new QAction(QIcon(":/pause.png"), tr("Pause"), this); pauseA->setCheckable(true); playAG->addAction(pauseA); @@ -531,6 +531,21 @@ void PlayerWidget::viewDoubleClicked(const QModelIndex &idx){ } } +void PlayerWidget::doPlay(){ + int playListCount = mPlayListModel->rowCount(); + if(playListCount == 0){ + emit message(tr("Playlist is empty! Dazed and confused, but trying to continue...")); + mStopA->trigger(); + return; + } + QModelIndexList sel = mPlayListView->selectionModel()->selectedRows(); + if(sel.isEmpty()){ + mPlayListView->selectionModel()->select(mPlayListModel->index(0, 0), QItemSelectionModel::SelectCurrent); + sel = mPlayListView->selectionModel()->selectedRows(); + } + playCurrent(sel.first()); +} + void PlayerWidget::recurse(const QModelIndex &parent){ for(int i = 0; i < mCurrentModel->rowCount(parent); ++i){ QModelIndex cur = mCurrentModel->index(i, 0, parent); @@ -761,7 +776,8 @@ void PlayerWidget::play(const QString &fullPath){ mCurrentTE->append(QString("%1 %2").arg(tr("Genre:"), -20).arg(genre)); mCurrentTE->append(QString("%1 %2").arg(tr("Track:"), -20).arg(track, 3, 10, QChar('0'))); mCurrentTE->append(QString("%1 %2").arg(tr("Year:"), -20).arg(year, 4, 10)); - mPlayA->trigger(); + mPlayer->play(); + mPlayA->setChecked(true); } void PlayerWidget::volumeChanged(int volume){ diff --git a/playerwidget.h b/playerwidget.h index bbe8333..14df101 100644 --- a/playerwidget.h +++ b/playerwidget.h @@ -32,6 +32,7 @@ class PlayerWidget : public QWidget { void doPopulateBySong(); void doPopulateByFolder(QString dir = QString()); void viewDoubleClicked(const QModelIndex &idx); + void doPlay(); void doFilter(); void clearFilter(); void reindex(); |