[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/work/kreversi_rewrite
From: Dmitry Suzdalev <dimsuz () gmail ! com>
Date: 2006-08-18 17:54:48
Message-ID: 1155923688.264786.20131.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 574325 by dimsuz:
Disable undo action when it's nothing to undo
M +4 -0 kreversigame.h
M +12 -2 mainwindow.cpp
M +3 -0 mainwindow.h
--- branches/work/kreversi_rewrite/kreversigame.h #574324:574325
@@ -88,6 +88,10 @@
*/
void undo();
/**
+ * @return if undo is possible
+ */
+ bool canUndo() const { return !m_undoStack.isEmpty(); }
+ /**
* Returns a hint to current player
*/
KReversiMove getHint() const;
--- branches/work/kreversi_rewrite/mainwindow.cpp #574324:574325
@@ -32,7 +32,8 @@
{
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 @@
addAction(newGameAct);
addAction(quitAct);
- addAction(undoAct);
+ addAction(m_undoAct);
addAction(hintAct);
}
@@ -82,6 +83,7 @@
{
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::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"
--- branches/work/kreversi_rewrite/mainwindow.h #574324:574325
@@ -17,11 +17,14 @@
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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic