+ painter->setBrush(getColor());
+ drawCircle(x, y, r);
+ painter->setBrush(Qt::NoBrush);
+}
+
+void DrawingWindow::drawText(int x, int y, const char *text, int flags)
+{
+ QRect r(image->rect());
+ switch (flags & Qt::AlignHorizontal_Mask) {
+ case Qt::AlignRight:
+ r.setRight(x);
+ break;
+ case Qt::AlignHCenter:
+ if (x < width / 2)
+ r.setLeft(2 * x - width + 1);
+ else
+ r.setRight(2 * x);
+ break;
+ default:
+ r.setLeft(x);
+ }
+ switch (flags & Qt::AlignVertical_Mask) {
+ case Qt::AlignBottom:
+ r.setBottom(y);
+ break;
+ case Qt::AlignVCenter:
+ if (y < height / 2)
+ r.setTop(2 * y - height + 1);
+ else
+ r.setBottom(2 * y);
+ break;
+ default:
+ r.setTop(y);
+ }
+ safeLock(imageMutex);
+ painter->drawText(r, flags, text, &r);
+ dirty(r);
+ safeUnlock(imageMutex);
+}
+
+void DrawingWindow::drawTextBg(int x, int y, const char *text, int flags)
+{
+ painter->setBackgroundMode(Qt::OpaqueMode);
+ drawText(x, y, text, flags);
+ painter->setBackgroundMode(Qt::TransparentMode);
+}
+
+unsigned int DrawingWindow::getPointColor(int x, int y)
+{
+ return image->pixel(x, y);
+}
+
+bool DrawingWindow::sync(unsigned long time)
+{
+ bool synced;
+ safeLock(syncMutex);
+ if (terminateThread) {
+ synced = false;
+ } else {
+ qApp->postEvent(this, new QEvent(QEvent::User));
+ synced = syncCondition.wait(&syncMutex, time);
+ }
+ safeUnlock(syncMutex);
+ return synced;
+}
+
+void DrawingWindow::closeGraph()
+{
+ qApp->postEvent(this, new QEvent(QEvent::Type(QEvent::User + 1)));
+}
+
+void DrawingWindow::sleep(unsigned long secs)
+{
+ DrawingThread::sleep(secs);
+}
+
+void DrawingWindow::msleep(unsigned long msecs)
+{
+ DrawingThread::msleep(msecs);
+}
+
+void DrawingWindow::usleep(unsigned long usecs)
+{
+ DrawingThread::usleep(usecs);
+}
+
+void DrawingWindow::closeEvent(QCloseEvent *ev)
+{
+ timer.stop();
+ thread->terminate();
+ syncMutex.lock();
+ terminateThread = true; // this flag is needed for the case
+ // where the following wakeAll() call
+ // occurs between the
+ // setTerminationEnable(false) and the
+ // mutex lock in safeLock() called
+ // from sync()
+ syncCondition.wakeAll();
+ syncMutex.unlock();
+ QWidget::closeEvent(ev);
+ thread->wait();
+}
+
+void DrawingWindow::customEvent(QEvent *ev)
+{
+ switch ((int )ev->type()) {
+ case QEvent::User:
+ mayUpdate();
+ qApp->sendPostedEvents(this, QEvent::UpdateLater);
+ qApp->sendPostedEvents(this, QEvent::UpdateRequest);
+ qApp->sendPostedEvents(this, QEvent::Paint);
+ qApp->processEvents(QEventLoop::ExcludeUserInputEvents |
+ QEventLoop::ExcludeSocketNotifiers |
+ QEventLoop::DeferredDeletion |
+ QEventLoop::X11ExcludeTimers);
+ qApp->flush();
+ qApp->syncX();
+ syncMutex.lock();
+ syncCondition.wakeAll();
+ syncMutex.unlock();
+ break;
+ case QEvent::User + 1:
+ close();
+ break;
+ }
+}
+
+void DrawingWindow::keyPressEvent(QKeyEvent *ev)
+{
+ bool accept = true;
+ switch (ev->key()) {
+ case Qt::Key_Escape:
+ close();
+ break;
+ default:
+ accept = false;
+ break;
+ }
+ if (accept)
+ ev->accept();