Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
.
[graphlib.git] / DrawingWindow.cpp
index 4cbccc3..c68b7b8 100644 (file)
@@ -163,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);
@@ -195,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)