Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
.
[graphlib.git] / DrawingWindow.cpp
index eb14102..16405b5 100644 (file)
@@ -3,24 +3,7 @@
 #include <QThread>
 #include <QTimerEvent>
 
-class DrawingWindow::DrawingThread: public QThread {
-public:
-    DrawingThread(DrawingWindow &w, ThreadFunction f)
-        : drawingWindow(w)
-        , threadFunction(f)
-    {
-    }
-
-    void run()
-    {
-        exit(threadFunction(drawingWindow));
-    }
-
-private:
-    DrawingWindow &drawingWindow;
-    ThreadFunction threadFunction;
-
-};
+#include <iostream>
 
 DrawingWindow::DrawingWindow(ThreadFunction fun, int width, int height)
     : QWidget()
@@ -98,6 +81,21 @@ void DrawingWindow::drawLine(int x1, int y1, int x2, int y2)
     unlock();
 }
 
+void DrawingWindow::closeEvent(QCloseEvent *ev)
+{
+    std::cerr << "A\n";
+    lock();
+    std::cerr << "B\n";
+    thread->terminate();
+    std::cerr << "C\n";
+    QWidget::closeEvent(ev);
+    std::cerr << "D\n";
+    thread->wait();
+    std::cerr << "E\n";
+    unlock();
+    std::cerr << "F\n";
+}
+
 void DrawingWindow::paintEvent(QPaintEvent *ev)
 {
     QPainter widgetPainter(this);
@@ -141,3 +139,15 @@ void DrawingWindow::setDirtyRect(const QRect &rect)
         dirtyRect = rect;
     }
 }
+
+DrawingWindow::DrawingThread::DrawingThread(DrawingWindow &w,
+                                            ThreadFunction f)
+    : drawingWindow(w)
+    , threadFunction(f)
+{
+}
+
+void DrawingWindow::DrawingThread::run()
+{
+    threadFunction(drawingWindow);
+}