X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/graphlib.git/blobdiff_plain/7e44377ed59d10dcf9f04ff898691b99d5f8a1c8..58868f34882be4712e0eb1439993cd8929c1a947:/DrawingWindow.h diff --git a/DrawingWindow.h b/DrawingWindow.h index 9e86889..10f0aa8 100644 --- a/DrawingWindow.h +++ b/DrawingWindow.h @@ -10,6 +10,8 @@ #include #include +#include + class DrawingWindow: public QWidget { /* Q_OBJECT */ @@ -40,12 +42,25 @@ public: void drawLine(int x1, int y1, int x2, int y2); protected: + void closeEvent(QCloseEvent *ev); void paintEvent(QPaintEvent *ev); void showEvent(QShowEvent *ev); void timerEvent(QTimerEvent *ev); private: - class DrawingThread; + class DrawingThread: public QThread { + public: + DrawingThread(DrawingWindow &w, ThreadFunction f); + void run(); + + void enableTerminate(); + void disableTerminate(); + + private: + DrawingWindow &drawingWindow; + ThreadFunction threadFunction; + + }; static const int paintInterval = 33; @@ -60,7 +75,6 @@ private: bool dirtyFlag; QRect dirtyRect; - bool mutex_enabled; QMutex mutex; void initialize(ThreadFunction fun, int width, int height); @@ -89,16 +103,15 @@ int DrawingWindow::height() const inline void DrawingWindow::lock() { - if (mutex_enabled) - mutex.lock(); - if (!mutex_enabled) - mutex.unlock(); + thread->disableTerminate(); + mutex.lock(); } inline void DrawingWindow::unlock() { mutex.unlock(); + thread->enableTerminate(); } inline @@ -122,4 +135,16 @@ void DrawingWindow::setDirtyRect(int x1, int y1, int x2, int y2) setDirtyRect(r.normalized()); } +inline +void DrawingWindow::DrawingThread::enableTerminate() +{ + setTerminationEnabled(true); +} + +inline +void DrawingWindow::DrawingThread::disableTerminate() +{ + setTerminationEnabled(false); +} + #endif // !DRAWING_WINDOW_H