Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Games
KReversi
Commits
a09bf4f4
Commit
a09bf4f4
authored
Aug 18, 2006
by
Dmitry Suzdalev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disable undo action when it's nothing to undo
svn path=/branches/work/kreversi_rewrite/; revision=574325
parent
d3f452a6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
2 deletions
+19
-2
kreversigame.h
kreversigame.h
+4
-0
mainwindow.cpp
mainwindow.cpp
+12
-2
mainwindow.h
mainwindow.h
+3
-0
No files found.
kreversigame.h
View file @
a09bf4f4
...
...
@@ -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
*/
...
...
mainwindow.cpp
View file @
a09bf4f4
...
...
@@ -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"
mainwindow.h
View file @
a09bf4f4
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment