Commit a09bf4f4 authored by Dmitry Suzdalev's avatar Dmitry Suzdalev

Disable undo action when it's nothing to undo

svn path=/branches/work/kreversi_rewrite/; revision=574325
parent d3f452a6
......@@ -87,6 +87,10 @@ public:
* Undoes the last player-computer move pair
*/
void undo();
/**
* @return if undo is possible
*/
bool canUndo() const { return !m_undoStack.isEmpty(); }
/**
* Returns a hint to current player
*/
......
......@@ -32,7 +32,8 @@ void KReversiMainWindow::setupActions()
{
KAction *newGameAct = KStdAction::openNew(this, SLOT(slotNewGame()), actionCollection(), "new_game");
KAction *quitAct = KStdAction::quit(this, SLOT(close()), actionCollection(), "quit");
KAction *undoAct = KStdAction::undo( this, SLOT(slotUndo()), actionCollection(), "undo" );
m_undoAct = KStdAction::undo( this, SLOT(slotUndo()), actionCollection(), "undo" );
m_undoAct->setEnabled( false ); // nothing to undo at the start of the game
KAction *hintAct = new KAction( KIcon("wizard"), i18n("Hint"), actionCollection(), "hint" );
hintAct->setShortcut( Qt::Key_H );
connect( hintAct, SIGNAL(triggered(bool)), m_scene, SLOT(slotHint()) );
......@@ -59,7 +60,7 @@ void KReversiMainWindow::setupActions()
addAction(newGameAct);
addAction(quitAct);
addAction(undoAct);
addAction(m_undoAct);
addAction(hintAct);
}
......@@ -82,6 +83,7 @@ void KReversiMainWindow::slotNewGame()
{
delete m_game;
m_game = new KReversiGame;
connect( m_game, SIGNAL(moveFinished()), SLOT(slotMoveFinished()) );
if(m_scene == 0) // if called first time
{
......@@ -94,11 +96,19 @@ void KReversiMainWindow::slotNewGame()
}
}
void KReversiMainWindow::slotMoveFinished()
{
m_undoAct->setEnabled( m_game->canUndo() );
}
void KReversiMainWindow::slotUndo()
{
if( !m_scene->isBusy() )
{
// scene will automatically notice that it needs to update
m_game->undo();
m_undoAct->setEnabled( m_game->canUndo() );
}
}
#include "mainwindow.moc"
......@@ -17,11 +17,14 @@ public slots:
void slotNewGame();
void slotBackgroundChanged(const QString& text);
void slotUndo();
void slotMoveFinished();
private:
void setupActions();
KReversiScene *m_scene;
KReversiView *m_view;
KReversiGame *m_game;
KAction* m_undoAct;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment