Skip to content

Commit

Permalink
Disable actions if undo/save stacks are empty
Browse files Browse the repository at this point in the history
  • Loading branch information
schuay committed Jul 23, 2012
1 parent ea57b30 commit 108a989
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ void MainWindow::toggleFullscreen(bool full_screen) {
}
}

void MainWindow::undoStackSizeChanged(int size)
{
m_action_undo->setEnabled(size != 0);
}

void MainWindow::saveStackSizeChanged(int size)
{
m_action_load_state->setEnabled(size != 0);
}

void MainWindow::closeEvent(QCloseEvent *event) {
saveWindowState();
KXmlGuiWindow::closeEvent(event);
Expand Down Expand Up @@ -203,9 +213,9 @@ void MainWindow::startGame() {
disconnect(&m_timer, SIGNAL(timeout()), this, SLOT(updatePlayedTime()));
}

m_action_undo->setEnabled(true);
m_action_undo->setEnabled(false);
m_action_save_state->setEnabled(true);
m_action_load_state->setEnabled(true);
m_action_load_state->setEnabled(false);
m_action_pause->setEnabled(true);
m_action_pause->setChecked(false);
#ifdef HAVE_KGDIFFICULTY
Expand All @@ -226,6 +236,8 @@ void MainWindow::startGame() {
connect(&m_timer, SIGNAL(timeout()), this, SLOT(updatePlayedTime()));
connect(m_game.data(), SIGNAL(stateChanged()), this, SLOT(updatePositions()));
connect(m_game.data(), SIGNAL(gameWon()), this, SLOT(gameWon()));
connect(m_game.data(), SIGNAL(undoStackSizeChanged(int)), this, SLOT(undoStackSizeChanged(int)));
connect(m_game.data(), SIGNAL(saveStackSizeChanged(int)), this, SLOT(saveStackSizeChanged(int)));

m_in_progress = true;
}
Expand Down
4 changes: 4 additions & 0 deletions src/gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ private slots:
void loadBoard();
void toggleFullscreen(bool full_screen);

/* Enable or disable undo/save state related actions. */
void undoStackSizeChanged(int size);
void saveStackSizeChanged(int size);

private:
enum Mode {
Random, /* board is randomly generated, highscores enabled */
Expand Down

0 comments on commit 108a989

Please sign in to comment.