From 58868f34882be4712e0eb1439993cd8929c1a947 Mon Sep 17 00:00:00 2001 From: giersch Date: Tue, 6 Nov 2007 06:51:52 +0000 Subject: [PATCH] . --- DrawingWindow.cpp | 22 ++++++++++------------ DrawingWindow.h | 6 ++---- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/DrawingWindow.cpp b/DrawingWindow.cpp index 16405b5..1f5bb6b 100644 --- a/DrawingWindow.cpp +++ b/DrawingWindow.cpp @@ -5,6 +5,12 @@ #include +/* + TODO : + class DrawingWindowPrivate { ... } + externalize class DrawingThread +*/ + DrawingWindow::DrawingWindow(ThreadFunction fun, int width, int height) : QWidget() { @@ -83,26 +89,18 @@ void DrawingWindow::drawLine(int x1, int y1, int x2, int y2) 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); QRect rect = ev->rect(); - lock(); + mutex.lock(); QImage imageCopy(*image); - unlock(); + mutex.unlock(); widgetPainter.drawImage(rect, imageCopy, rect); } @@ -118,12 +116,12 @@ void DrawingWindow::showEvent(QShowEvent *ev) void DrawingWindow::timerEvent(QTimerEvent *ev) { if (ev->timerId() == timer.timerId()) { - lock(); + mutex.lock(); if (dirtyFlag) { update(dirtyRect); dirtyFlag = false; } - unlock(); + mutex.unlock(); timer.start(paintInterval, this); } else { QWidget::timerEvent(ev); diff --git a/DrawingWindow.h b/DrawingWindow.h index 0a0863f..10f0aa8 100644 --- a/DrawingWindow.h +++ b/DrawingWindow.h @@ -138,15 +138,13 @@ void DrawingWindow::setDirtyRect(int x1, int y1, int x2, int y2) inline void DrawingWindow::DrawingThread::enableTerminate() { - if (currentThread() == this) - setTerminationEnabled(true); + setTerminationEnabled(true); } inline void DrawingWindow::DrawingThread::disableTerminate() { - if (currentThread() == this) - setTerminationEnabled(false); + setTerminationEnabled(false); } #endif // !DRAWING_WINDOW_H -- 2.20.1