Warn before exiting Eliot when a game is started

This commit is contained in:
Olivier Teulière 2012-01-05 21:08:54 +01:00
parent c7cf102674
commit 219b99192d
2 changed files with 18 additions and 4 deletions

View file

@ -358,6 +358,18 @@ void MainWindow::showDefinition(QString iWord)
void MainWindow::closeEvent(QCloseEvent *event)
{
if (m_game)
{
QString msg = _q("A game has been started.");
if (!requestConfirmation(msg, _q("Do you really want to quit?")))
{
event->ignore();
return;
}
}
LOG_INFO("Exiting");
// Make sure auxiliary windows don't survive after the main one
if (m_bagWindow)
m_bagWindow->close();
@ -436,11 +448,14 @@ void MainWindow::changeDictionary(QString iFileName)
}
bool MainWindow::requestConfirmation(QString msg)
bool MainWindow::requestConfirmation(QString msg, QString question)
{
QMessageBox confirmationBox(QMessageBox::Question, _q("Eliot"), msg,
QMessageBox::Yes | QMessageBox::No, this);
confirmationBox.setInformativeText(_q("Do you want to continue?"));
if (question != "")
confirmationBox.setInformativeText(question);
else
confirmationBox.setInformativeText(_q("Do you want to continue?"));
confirmationBox.setDefaultButton(QMessageBox::Yes);
confirmationBox.setEscapeButton(QMessageBox::No);
int res = confirmationBox.exec();
@ -803,7 +818,6 @@ void MainWindow::onGamePrint()
void MainWindow::onGameQuit()
{
LOG_INFO("Exiting");
close();
}

View file

@ -174,7 +174,7 @@ private:
void destroyCurrentGame();
/// Ask for a confirmation
bool requestConfirmation(QString msg);
bool requestConfirmation(QString msg, QString question = "");
};