diff --git a/src/gui/ksudoku.cpp b/src/gui/ksudoku.cpp --- a/src/gui/ksudoku.cpp +++ b/src/gui/ksudoku.cpp @@ -102,6 +102,8 @@ else msg = i18nc("The two parameters are strings like '2 minutes' or '1 second'.", "Congratulations! You made it in %1 and %2.", i18np("1 minute", "%1 minutes", mins), i18np("1 second", "%1 seconds", secs)); + onModified(true); // make sure buttons have the correct enabled state + KMessageBox::information(this, msg); } @@ -546,6 +548,11 @@ m_gameSave->setEnabled(game.isValid()); m_gameSaveAs->setEnabled(game.isValid()); if(game.isValid()) { + bool isEnterPuzzleMode = !game.puzzle()->hasSolution(); + action("move_hint")->setVisible(!isEnterPuzzleMode); + action("move_solve")->setVisible(!isEnterPuzzleMode); + action("move_dub_puzzle")->setVisible(isEnterPuzzleMode); + action("move_undo")->setEnabled(game.canUndo()); action("move_redo")->setEnabled(game.canRedo()); @@ -556,17 +563,19 @@ action("move_undo")->setEnabled(false); action("move_redo")->setEnabled(false); - action("move_hint")->setEnabled(false); - action("move_solve")->setEnabled(false); - action("move_dub_puzzle")->setEnabled(false); + action("move_hint")->setVisible(false); + action("move_solve")->setVisible(false); + action("move_dub_puzzle")->setVisible(false); } } void KSudoku::onModified(bool /*isModified*/) { Game game = currentGame(); if(game.isValid()) { action("move_undo")->setEnabled(game.canUndo()); action("move_redo")->setEnabled(game.canRedo()); + action("move_hint")->setEnabled(!game.allValuesSetAndUsable()); + action("move_solve")->setEnabled(!game.wasFinished()); } } diff --git a/src/gui/ksudokugame.h b/src/gui/ksudokugame.h --- a/src/gui/ksudokugame.h +++ b/src/gui/ksudokugame.h @@ -213,7 +213,7 @@ bool userHadHelp() const; /** - * Returns whether the game was allready solved. + * Returns whether the game was already solved. */ bool wasFinished() const; @@ -250,6 +250,12 @@ void setMessageParent (QWidget * messageParent); QWidget * messageParent(); + /* + * Returns true if all values are filled in (not empty) + * and in usable areas (as in Samurai); false otherwise + */ + bool allValuesSetAndUsable() const; + private: /** * When the game was finished this function emits a @c completed() diff --git a/src/gui/ksudokugame.cpp b/src/gui/ksudokugame.cpp --- a/src/gui/ksudokugame.cpp +++ b/src/gui/ksudokugame.cpp @@ -566,14 +566,23 @@ } } +bool Game::allValuesSetAndUsable() const { + for (int i = 0; i < size(); i++) { + if (value(i) == 0) { + return false; + } + } + + return true; +} + void Game::checkCompleted() { if(!m_private || !m_private->puzzle->hasSolution()) return; - // Find cells that are empty and not in unusable areas (as in Samurai). - for(int i = 0; i < size(); i++) - if((value(i) == 0) && (solution(i) > 0)) - return; - + if (!allValuesSetAndUsable()) { + return; + } + for(int i = 0; i < size(); i++) { if(value(i) != solution(i)) { m_private->emitCompleted(false, time(), m_private->hadHelp);