[qcross] some gui bugfixes

This commit is contained in:
Oliver Groß 2012-04-11 15:07:13 +02:00
parent 608a114a05
commit 5cb6dd6880

View File

@ -44,11 +44,13 @@ namespace qcross {
CGameWindow::CGameWindow(QWidget * parent) : QMainWindow(parent) { CGameWindow::CGameWindow(QWidget * parent) : QMainWindow(parent) {
m_Highscore = NULL; m_Highscore = NULL;
m_PictureIndex = -1; m_PictureIndex = -1;
m_Picture = new CNonogram(QSize(10, 10)); m_Picture = NULL;
m_Picture->updateNumbers();
m_Field = new CCrossFieldWidget(m_Picture, this); // CNonogram * dummyPic = new CNonogram(QSize(10, 10));
m_Field->setTime(42 * 60 + 23); // dummyPic->updateNumbers();
m_Field = new CCrossFieldWidget(NULL, this);
// m_Field->setTime(42 * 60 + 23);
setCentralWidget(m_Field); setCentralWidget(m_Field);
m_Field->showMessage(tr("Welcome to QCross!")); m_Field->showMessage(tr("Welcome to QCross!"));
@ -86,7 +88,6 @@ namespace qcross {
m_PauseGameAction = currentMenu->addAction(tr("&Pause")); m_PauseGameAction = currentMenu->addAction(tr("&Pause"));
m_PauseGameAction->setEnabled(false); m_PauseGameAction->setEnabled(false);
m_PauseGameAction->setCheckable(true); m_PauseGameAction->setCheckable(true);
m_PauseGameAction->setChecked(true);
m_PauseGameAction->setShortcut(Qt::CTRL + Qt::Key_P); m_PauseGameAction->setShortcut(Qt::CTRL + Qt::Key_P);
connect(m_PauseGameAction, SIGNAL(toggled(bool)), this, SLOT(pauseGame(bool))); connect(m_PauseGameAction, SIGNAL(toggled(bool)), this, SLOT(pauseGame(bool)));
currentMenu->addSeparator(); currentMenu->addSeparator();
@ -176,7 +177,7 @@ namespace qcross {
void CGameWindow::newGame() { void CGameWindow::newGame() {
bool notPaused = !m_Field->isPaused(); bool notPaused = !m_Field->isPaused();
if (notPaused) if (notPaused)
pauseGame(true); m_Field->pause();
CNewGameDialog dialog; CNewGameDialog dialog;
if (dialog.exec() == QDialog::Accepted) { if (dialog.exec() == QDialog::Accepted) {
@ -190,6 +191,7 @@ namespace qcross {
CNonogram * newPicture = dialog.takeNonogram(); CNonogram * newPicture = dialog.takeNonogram();
newPicture->updateNumbers(); newPicture->updateNumbers();
m_SaveGameAction->setEnabled(true);
m_PauseGameAction->setEnabled(true); m_PauseGameAction->setEnabled(true);
m_RestartGameAction->setEnabled(true); m_RestartGameAction->setEnabled(true);
@ -203,8 +205,9 @@ namespace qcross {
m_Field->resume(); m_Field->resume();
m_Field->showMessage(tr("Game started!"), 1000); m_Field->showMessage(tr("Game started!"), 1000);
} }
else
pauseGame(false); if (m_Picture && !m_PauseGameAction->isChecked())
m_Field->resume();
} }
@ -213,7 +216,7 @@ namespace qcross {
return; return;
if (!m_Field->isPaused()) if (!m_Field->isPaused())
m_PauseGameAction->setChecked(true); m_Field->pause();
QString fileName = QFileDialog::getSaveFileName(this, tr("Save current game"), QString fileName = QFileDialog::getSaveFileName(this, tr("Save current game"),
QDir::homePath(), tr("QCross Saved games (*.csg)")); QDir::homePath(), tr("QCross Saved games (*.csg)"));
@ -231,12 +234,13 @@ namespace qcross {
else else
writeSaveGame(out); writeSaveGame(out);
m_PauseGameAction->setChecked(false); if(!m_PauseGameAction->isChecked())
m_Field->resume();
} }
void CGameWindow::loadGame() { void CGameWindow::loadGame() {
if (!m_Field->isPaused()) if (!m_Field->isPaused())
m_PauseGameAction->setChecked(true); m_Field->pause();
QString fileName = QFileDialog::getOpenFileName(this, tr("Open saved game"), QString fileName = QFileDialog::getOpenFileName(this, tr("Open saved game"),
QDir::homePath(), tr("QCross Saved games (*.csg)")); QDir::homePath(), tr("QCross Saved games (*.csg)"));
@ -260,6 +264,8 @@ namespace qcross {
if (readSaveGame(in)) { if (readSaveGame(in)) {
m_PauseGameAction->setEnabled(true); m_PauseGameAction->setEnabled(true);
m_PauseGameAction->setChecked(m_Field->isPaused());
m_SaveGameAction->setEnabled(true);
} }
else { else {
m_Field->setPicture(NULL); m_Field->setPicture(NULL);
@ -276,7 +282,8 @@ namespace qcross {
} }
} }
m_PauseGameAction->setChecked(false); if (m_Picture && !m_PauseGameAction->isChecked())
m_Field->resume();
} }
void CGameWindow::restartGame() { void CGameWindow::restartGame() {
@ -289,6 +296,9 @@ namespace qcross {
} }
void CGameWindow::pauseGame(bool value) { void CGameWindow::pauseGame(bool value) {
if (value == m_Field->isPaused())
return;
if (value) { if (value) {
m_Field->pause(); m_Field->pause();
m_Field->showMessage(tr("Game paused.")); m_Field->showMessage(tr("Game paused."));