X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/graphlib.git/blobdiff_plain/731920852b16f59be2e9e00f11470d23003b5ea4..0e285c89f65c68d9b304a44891d95cea61a766bf:/DrawingWindow.cpp diff --git a/DrawingWindow.cpp b/DrawingWindow.cpp index 7015d6a..3234441 100644 --- a/DrawingWindow.cpp +++ b/DrawingWindow.cpp @@ -665,11 +665,11 @@ bool DrawingWindow::waitMousePress(int &x, int &y, int &button, unsigned long time) { bool pressed; - safeLock(mouseMutex); + safeLock(inputMutex); if (terminateThread) { pressed = false; } else { - pressed = mouseCondition.wait(&mouseMutex, time) && !terminateThread; + pressed = inputCondition.wait(&inputMutex, time) && !terminateThread; if (pressed) { x = mousePos.x(); y = mousePos.y(); @@ -683,7 +683,7 @@ bool DrawingWindow::waitMousePress(int &x, int &y, int &button, button = 0; } } - safeUnlock(mouseMutex); + safeUnlock(inputMutex); return pressed; } @@ -745,15 +745,18 @@ void DrawingWindow::usleep(unsigned long usecs) DrawingThread::usleep(usecs); } +//--- DrawingWindow (protected methods) -------------------------------- +//! \cond show_protected + /*! * \see QWidget */ void DrawingWindow::closeEvent(QCloseEvent *ev) { timer.stop(); - thread->terminate(); + thread->exit(); syncMutex.lock(); - mouseMutex.lock(); + inputMutex.lock(); terminateThread = true; // this flag is needed for the case // where the following wakeAll() call // occurs between the @@ -761,11 +764,14 @@ void DrawingWindow::closeEvent(QCloseEvent *ev) // mutex lock in safeLock() called // from sync() syncCondition.wakeAll(); - mouseCondition.wakeAll(); - mouseMutex.unlock(); + inputCondition.wakeAll(); + inputMutex.unlock(); syncMutex.unlock(); QWidget::closeEvent(ev); - thread->wait(); + if (!thread->wait(250)) { + thread->terminate(); + thread->wait(); + } } /*! @@ -794,12 +800,12 @@ void DrawingWindow::customEvent(QEvent *ev) */ void DrawingWindow::mousePressEvent(QMouseEvent *ev) { - mouseMutex.lock(); + inputMutex.lock(); mousePos = ev->pos(); mouseButton = ev->button(); ev->accept(); - mouseCondition.wakeAll(); - mouseMutex.unlock(); + inputCondition.wakeAll(); + inputMutex.unlock(); } /*! @@ -807,17 +813,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(); } /*! @@ -858,6 +857,8 @@ void DrawingWindow::timerEvent(QTimerEvent *ev) } } +// \endcond + //--- DrawingWindow (private methods) ---------------------------------- //! Fonction d'initialisation.