X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/graphlib.git/blobdiff_plain/dc22c2e9dfe646c4517e056f87459e34ab78ce2e..a7346f12e37f808491a76b2465de8ae8cd951d51:/DrawingWindow.cpp diff --git a/DrawingWindow.cpp b/DrawingWindow.cpp index cf111e9..c68b7b8 100644 --- a/DrawingWindow.cpp +++ b/DrawingWindow.cpp @@ -139,6 +139,16 @@ void DrawingWindow::fillCircle(int x, int y, int r) painter->setBrush(Qt::NoBrush); } +void DrawingWindow::drawText(int x, int y, const char *text) +{ + QRect r(image->rect()); + r.moveTo(x, y); + safeLock(imageMutex); + painter->drawText(r, 0, text, &r); + dirty(r); + safeUnlock(imageMutex); +} + bool DrawingWindow::sync(unsigned long time) { bool synced; @@ -153,6 +163,11 @@ bool DrawingWindow::sync(unsigned long time) return synced; } +void DrawingWindow::closeGraph() +{ + qApp->postEvent(this, new QEvent(QEvent::Type(QEvent::User + 1))); +} + void DrawingWindow::sleep(unsigned long secs) { DrawingThread::sleep(secs); @@ -185,21 +200,28 @@ void DrawingWindow::closeEvent(QCloseEvent *ev) thread->wait(); } -void DrawingWindow::customEvent(QEvent *) +void DrawingWindow::customEvent(QEvent *ev) { - 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(); + 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)