From a8d5afb9c4b061bc8657600312d4a5c6cab4c71f Mon Sep 17 00:00:00 2001 From: Arno Date: Fri, 11 May 2018 18:55:43 +0200 Subject: Fix logic when we start playing If nothing is selected in the song view, but it's populated, don't give up early. Select the first one and try to continue. --- playerwidget.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'playerwidget.cpp') diff --git a/playerwidget.cpp b/playerwidget.cpp index f6ad0d6..f944e64 100644 --- a/playerwidget.cpp +++ b/playerwidget.cpp @@ -478,25 +478,25 @@ void PlayerWidget::rightCurrentChanged(const QModelIndex &cur, const QModelIndex } void PlayerWidget::doPlay(){ - if(mPlayer->state() == QMediaPlayer::PausedState || mPlayer->state() == QMediaPlayer::StoppedState){ - mPlayer->play(); - mPlayA->setChecked(true); - emit playModeChanged(tr("Playing")); - emit setWinTitle(mCurWinTitle); - mTrayIcon->setIcon(QIcon(":/play.png")); - mTrayIcon->setToolTip(mCurToolTip); - return; - } int playListCount = mSongModel->rowCount(); if(playListCount == 0){ emit message(tr("Playlist is empty! Dazed and confused, but trying to continue...")); doStop(); return; } + + if(mPlayer->state() == QMediaPlayer::PausedState){ + mPlayer->play(); + mPlayA->setChecked(true); + emit playModeChanged(tr("Playing")); + return; + } QModelIndexList sel = mSongView->selectionModel()->selectedRows(); - if(sel.isEmpty()){ - mSongView->selectionModel()->select(mSongModel->index(0, 0), QItemSelectionModel::SelectCurrent); - sel = mSongView->selectionModel()->selectedRows(); + if(mPlayer->state() == QMediaPlayer::StoppedState){ + if(sel.isEmpty()){ + mSongView->selectionModel()->setCurrentIndex(mSongModel->index(0, 0), QItemSelectionModel::SelectCurrent); + sel = mSongView->selectionModel()->selectedRows(); + } } playCurrent(sel.first()); } @@ -739,6 +739,10 @@ void PlayerWidget::playCurrent(const QModelIndex &index){ mPlayer->stop(); QString fullPath = index.data(CollectionWidget::FullPathRole).toString(); play(fullPath); + mPlayer->play(); + mPlayA->setChecked(true); + emit playModeChanged(tr("Playing")); + emit setWinTitle(mCurWinTitle); mTrayIcon->setIcon(QIcon(":/play.png")); mTrayIcon->setToolTip(mCurToolTip); } -- cgit v1.2.3-70-g09d2