From a7346f12e37f808491a76b2465de8ae8cd951d51 Mon Sep 17 00:00:00 2001 From: giersch Date: Wed, 21 Nov 2007 08:09:04 +0000 Subject: [PATCH] . --- DrawingWindow.cpp | 55 ++++++++++++++++++++----------------------- chateaux/chateaux.cpp | 6 +++-- 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/DrawingWindow.cpp b/DrawingWindow.cpp index 9af145f..c68b7b8 100644 --- a/DrawingWindow.cpp +++ b/DrawingWindow.cpp @@ -165,7 +165,7 @@ bool DrawingWindow::sync(unsigned long time) void DrawingWindow::closeGraph() { - qApp->postEvent(this, new QCloseEvent()); + qApp->postEvent(this, new QEvent(QEvent::Type(QEvent::User + 1))); } void DrawingWindow::sleep(unsigned long secs) @@ -185,48 +185,43 @@ void DrawingWindow::usleep(unsigned long usecs) void DrawingWindow::closeEvent(QCloseEvent *ev) { - qDebug(">>>CLOSING<<<\n"); - char x = 'A'; - qDebug(">>> %c <<<\n", x++); timer.stop(); - qDebug(">>> %c <<<\n", x++); thread->terminate(); - qDebug(">>> %c <<<\n", x++); syncMutex.lock(); - qDebug(">>> %c <<<\n", x++); terminateThread = true; // this flag is needed for the case // where the following wakeAll() call // occurs between the // setTerminationEnable(false) and the // mutex lock in safeLock() called // from sync() - qDebug(">>> %c <<<\n", x++); syncCondition.wakeAll(); - qDebug(">>> %c <<<\n", x++); syncMutex.unlock(); - qDebug(">>> %c <<<\n", x++); QWidget::closeEvent(ev); - qDebug(">>> %c <<<\n", x++); thread->wait(); - qDebug(">>> %c <<<\n", x++); - qDebug(">>>CLOSED<<<\n"); -} - -void DrawingWindow::customEvent(QEvent *) -{ - mayUpdate(); - qApp->sendPostedEvents(this, QEvent::UpdateLater); - qApp->sendPostedEvents(this, QEvent::UpdateRequest); - qApp->sendPostedEvents(this, QEvent::Paint); - qApp->processEvents(QEventLoop::ExcludeUserInputEvents | - QEventLoop::ExcludeSocketNotifiers | - QEventLoop::DeferredDeletion | - QEventLoop::X11ExcludeTimers); - qApp->flush(); - qApp->syncX(); - syncMutex.lock(); - syncCondition.wakeAll(); - syncMutex.unlock(); +} + +void DrawingWindow::customEvent(QEvent *ev) +{ + switch ((int )ev->type()) { + case QEvent::User: + mayUpdate(); + qApp->sendPostedEvents(this, QEvent::UpdateLater); + qApp->sendPostedEvents(this, QEvent::UpdateRequest); + qApp->sendPostedEvents(this, QEvent::Paint); + qApp->processEvents(QEventLoop::ExcludeUserInputEvents | + QEventLoop::ExcludeSocketNotifiers | + QEventLoop::DeferredDeletion | + QEventLoop::X11ExcludeTimers); + qApp->flush(); + qApp->syncX(); + syncMutex.lock(); + syncCondition.wakeAll(); + syncMutex.unlock(); + break; + case QEvent::User + 1: + close(); + break; + } } void DrawingWindow::keyPressEvent(QKeyEvent *ev) diff --git a/chateaux/chateaux.cpp b/chateaux/chateaux.cpp index 7f4d093..44e22d4 100644 --- a/chateaux/chateaux.cpp +++ b/chateaux/chateaux.cpp @@ -321,8 +321,10 @@ void jeu(DrawingWindow& w) w.sleep(2); else { char r; - std::cout << "Recommencer (o/n) ? "; - std::cin >> r; + do { + std::cout << "Recommencer (o/n) ? "; + std::cin >> r; + } while (std::cin.good() && r != 'o' && r != 'n'); rejouer = r == 'o'; } } while (rejouer); -- 2.20.1