From e9465b0f8af7be99a106203261c73da887fe0de9 Mon Sep 17 00:00:00 2001 From: Daniel Fichtner Date: Wed, 6 Oct 2021 15:20:15 +0200 Subject: [PATCH 1/5] nullptr for Options options = Notify --- src/dealer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dealer.cpp b/src/dealer.cpp index 58ccae76..285583d5 100644 --- a/src/dealer.cpp +++ b/src/dealer.cpp @@ -1957,7 +1957,8 @@ bool DealerScene::allowedToStartNewGame() i18n("Abandon Current Game?"), KGuiItem(i18n("Abandon Current Game")), KStandardGuiItem::cancel(), - QStringLiteral("careaboutstats") + QStringLiteral("careaboutstats"), + nullptr ) == KMessageBox::Continue; } -- GitLab From d18b47ca4f20f2a1f1c517be2783c1365d1a106f Mon Sep 17 00:00:00 2001 From: Daniel Fichtner Date: Wed, 6 Oct 2021 23:15:49 +0200 Subject: [PATCH 2/5] change nullptr to 0 --- src/dealer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dealer.cpp b/src/dealer.cpp index 285583d5..1d902481 100644 --- a/src/dealer.cpp +++ b/src/dealer.cpp @@ -1958,7 +1958,7 @@ bool DealerScene::allowedToStartNewGame() KGuiItem(i18n("Abandon Current Game")), KStandardGuiItem::cancel(), QStringLiteral("careaboutstats"), - nullptr + 0 ) == KMessageBox::Continue; } -- GitLab From ddff6f7f47c14698dfb75f98b0a4f0f5957d39c0 Mon Sep 17 00:00:00 2001 From: Daniel Fichtner Date: Wed, 6 Oct 2021 23:59:08 +0200 Subject: [PATCH 3/5] make New Game notification adhere to KPats sounds settings --- src/dealer.cpp | 48 +++++++++++++++++++++++++++++++++------------- src/dealer.h | 4 ++++ src/mainwindow.cpp | 3 +++ 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/dealer.cpp b/src/dealer.cpp index 1d902481..2ed2c2b4 100644 --- a/src/dealer.cpp +++ b/src/dealer.cpp @@ -1348,6 +1348,12 @@ void DealerScene::setSolverEnabled(bool a) } +void DealerScene::setPlayNotification(bool a) +{ + m_playNotification = a; +} + + void DealerScene::setAutoDropEnabled( bool enabled ) { m_autoDropEnabled = enabled; @@ -1947,19 +1953,35 @@ bool DealerScene::allowedToStartNewGame() { // Check if the user is already running a game, and if she is, // then ask if she wants to abort it. - return !m_dealStarted - || m_dealWasJustSaved - || m_toldAboutWonGame - || m_toldAboutLostGame - || KMessageBox::warningContinueCancel(nullptr, - i18n("A new game has been requested, but there is already a game in progress.\n\n" - "A loss will be recorded in the statistics if the current game is abandoned."), - i18n("Abandon Current Game?"), - KGuiItem(i18n("Abandon Current Game")), - KStandardGuiItem::cancel(), - QStringLiteral("careaboutstats"), - 0 - ) == KMessageBox::Continue; + if (DealerScene::m_playNotification) { + return !m_dealStarted + || m_dealWasJustSaved + || m_toldAboutWonGame + || m_toldAboutLostGame + || KMessageBox::warningContinueCancel(nullptr, + i18n("A new game has been requested, but there is already a game in progress.\n\n" + "A loss will be recorded in the statistics if the current game is abandoned."), + i18n("Abandon Current Game?"), + KGuiItem(i18n("Abandon Current Game")), + KStandardGuiItem::cancel(), + QStringLiteral("careaboutstats") + ) == KMessageBox::Continue; + } + else { + return !m_dealStarted + || m_dealWasJustSaved + || m_toldAboutWonGame + || m_toldAboutLostGame + || KMessageBox::warningContinueCancel(nullptr, + i18n("A new game has been requested, but there is already a game in progress.\n\n" + "A loss will be recorded in the statistics if the current game is abandoned."), + i18n("Abandon Current Game?"), + KGuiItem(i18n("Abandon Current Game")), + KStandardGuiItem::cancel(), + QStringLiteral("careaboutstats"), + 0 + ) == KMessageBox::Continue; + } } void DealerScene::addCardForDeal( KCardPile * pile, KCard * card, bool faceUp, QPointF startPos ) diff --git a/src/dealer.h b/src/dealer.h index d98b5e4a..ea699b5b 100644 --- a/src/dealer.h +++ b/src/dealer.h @@ -110,6 +110,8 @@ public: SolverInterface * solver() const; void startSolver(); + void setPlayNotification( bool a ); + virtual bool isGameLost() const; virtual bool isGameWon() const; @@ -253,6 +255,8 @@ private: bool m_autoDropEnabled; bool m_solverEnabled; + bool m_playNotification; + bool m_dealStarted; bool m_dealWasEverWinnable; bool m_dealHasBeenWon; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index aa1f69c3..e11f1946 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -529,6 +529,7 @@ void MainWindow::setGameType(int id) m_dealer->mapOldId( id ); m_dealer->setSolverEnabled( m_solverEnabledAction->isChecked() ); m_dealer->setAutoDropEnabled( m_autoDropEnabledAction->isChecked() ); + m_dealer->setPlayNotification( m_playSoundsAction->isChecked() ); m_view->setScene( m_dealer ); @@ -686,10 +687,12 @@ void MainWindow::updateSoundEngine() connect(m_dealer, &DealerScene::cardsPickedUp, m_soundEngine, &SoundEngine::cardsPickedUp); connect(m_dealer, &DealerScene::cardsPutDown, m_soundEngine, &SoundEngine::cardsPutDown); + m_dealer->setPlayNotification( true ); } else if ( m_soundEngine ) { disconnect( m_dealer, nullptr, m_soundEngine, nullptr ); + m_dealer->setPlayNotification( false ); } } } -- GitLab From 409c2989df275261b014603909d855531ac62076 Mon Sep 17 00:00:00 2001 From: Daniel Fichtner Date: Fri, 8 Oct 2021 23:56:53 +0200 Subject: [PATCH 4/5] refactor code to get rid of duplication --- src/dealer.cpp | 47 ++++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/src/dealer.cpp b/src/dealer.cpp index 2ed2c2b4..41cc89cd 100644 --- a/src/dealer.cpp +++ b/src/dealer.cpp @@ -1953,35 +1953,24 @@ bool DealerScene::allowedToStartNewGame() { // Check if the user is already running a game, and if she is, // then ask if she wants to abort it. - if (DealerScene::m_playNotification) { - return !m_dealStarted - || m_dealWasJustSaved - || m_toldAboutWonGame - || m_toldAboutLostGame - || KMessageBox::warningContinueCancel(nullptr, - i18n("A new game has been requested, but there is already a game in progress.\n\n" - "A loss will be recorded in the statistics if the current game is abandoned."), - i18n("Abandon Current Game?"), - KGuiItem(i18n("Abandon Current Game")), - KStandardGuiItem::cancel(), - QStringLiteral("careaboutstats") - ) == KMessageBox::Continue; - } - else { - return !m_dealStarted - || m_dealWasJustSaved - || m_toldAboutWonGame - || m_toldAboutLostGame - || KMessageBox::warningContinueCancel(nullptr, - i18n("A new game has been requested, but there is already a game in progress.\n\n" - "A loss will be recorded in the statistics if the current game is abandoned."), - i18n("Abandon Current Game?"), - KGuiItem(i18n("Abandon Current Game")), - KStandardGuiItem::cancel(), - QStringLiteral("careaboutstats"), - 0 - ) == KMessageBox::Continue; - } + KMessageBox::Options foo = 0; + if (DealerScene::m_playNotification) + { + foo |= KMessageBox::Notify; + } + return !m_dealStarted + || m_dealWasJustSaved + || m_toldAboutWonGame + || m_toldAboutLostGame + || KMessageBox::warningContinueCancel(nullptr, + i18n("A new game has been requested, but there is already a game in progress.\n\n" + "A loss will be recorded in the statistics if the current game is abandoned."), + i18n("Abandon Current Game?"), + KGuiItem(i18n("Abandon Current Game")), + KStandardGuiItem::cancel(), + QStringLiteral("careaboutstats"), + foo + ) == KMessageBox::Continue; } void DealerScene::addCardForDeal( KCardPile * pile, KCard * card, bool faceUp, QPointF startPos ) -- GitLab From cc4e96f508d1cc95622206398003c4f7eb6423a2 Mon Sep 17 00:00:00 2001 From: Frederik Schwarzer Date: Sat, 9 Oct 2021 07:21:20 +0000 Subject: [PATCH 5/5] Apply 2 suggestion(s) to 1 file(s) --- src/dealer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dealer.cpp b/src/dealer.cpp index 41cc89cd..16634142 100644 --- a/src/dealer.cpp +++ b/src/dealer.cpp @@ -1953,10 +1953,10 @@ bool DealerScene::allowedToStartNewGame() { // Check if the user is already running a game, and if she is, // then ask if she wants to abort it. - KMessageBox::Options foo = 0; + KMessageBox::Options options = 0; if (DealerScene::m_playNotification) { - foo |= KMessageBox::Notify; + options |= KMessageBox::Notify; } return !m_dealStarted || m_dealWasJustSaved @@ -1969,7 +1969,7 @@ bool DealerScene::allowedToStartNewGame() KGuiItem(i18n("Abandon Current Game")), KStandardGuiItem::cancel(), QStringLiteral("careaboutstats"), - foo + options ) == KMessageBox::Continue; } -- GitLab