+ initialize(fun, width, height);
+}
+
+void DrawingWindow::initialize(ThreadFunction fun, int width, int height)
+{
+ image = new QImage(width, height, QImage::Format_RGB32);
+ image->fill(QColor(Qt::white).rgb());
+
+ painter = new QPainter(image);
+
+#ifdef USE_PIXMAP_CACHE
+ pixmap = new QPixmap(image->size());
+ QPainter pixmapPainter(pixmap);
+ pixmapPainter.drawImage(0, 0, *image);
+#endif
+
+ dirtyFlag = false;
+
+ setFocusPolicy(Qt::StrongFocus);
+ setFixedSize(image->size());
+ setAttribute(Qt::WA_OpaquePaintEvent);
+ setFocus();
+ timer.start(paintInterval, this);
+
+ thread = new DrawingThread(*this, fun);
+ thread_started = false;
+}
+
+DrawingWindow::~DrawingWindow()
+{
+ delete thread;
+#ifdef USE_PIXMAP_CACHE
+ delete pixmap;
+#endif
+ delete painter;
+ delete image;
+}
+
+void DrawingWindow::setColor(const QColor &color)
+{
+ QPen pen(painter->pen());
+ pen.setColor(color);
+ painter->setPen(pen);
+}
+
+void DrawingWindow::setColor(float red, float green, float blue)
+{
+ QColor color;
+ color.setRgbF(red, green, blue);
+ this->setColor(color);
+}
+
+void DrawingWindow::drawPoint(int x, int y)
+{
+ lock();
+ painter->drawPoint(x, y);
+ setDirtyRect(x, y);
+ unlock();
+}
+
+void DrawingWindow::drawLine(int x1, int y1, int x2, int y2)
+{
+ lock();
+ painter->drawLine(x1, y1, x2, y2);
+ setDirtyRect(x1, y1, x2, y2);
+ unlock();