Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Simplify method keyPressEvent.
[graphlib.git] / DrawingWindow.cpp
index 7015d6a..5c918ba 100644 (file)
@@ -751,7 +751,7 @@ void DrawingWindow::usleep(unsigned long usecs)
 void DrawingWindow::closeEvent(QCloseEvent *ev)
 {
     timer.stop();
-    thread->terminate();
+    thread->exit();
     syncMutex.lock();
     mouseMutex.lock();
     terminateThread = true;     // this flag is needed for the case
@@ -765,7 +765,10 @@ void DrawingWindow::closeEvent(QCloseEvent *ev)
     mouseMutex.unlock();
     syncMutex.unlock();
     QWidget::closeEvent(ev);
-    thread->wait();
+    if (!thread->wait(250)) {
+        thread->terminate();
+        thread->wait();
+    }
 }
 
 /*!
@@ -807,17 +810,10 @@ void DrawingWindow::mousePressEvent(QMouseEvent *ev)
  */
 void DrawingWindow::keyPressEvent(QKeyEvent *ev)
 {
-    bool accept = true;
-    switch (ev->key()) {
-    case Qt::Key_Escape:
+    if (ev->key() == Qt::Key_Escape) {
+        ev->accept();
         close();
-        break;
-    default:
-        accept = false;
-        break;
     }
-    if (accept)
-        ev->accept();
 }
 
 /*!