image = new QImage(width, height, QImage::Format_RGB32);
image->fill(QColor(Qt::white).rgb());
painter = new QPainter(image);
+ setDirty();
}
DrawingArea::~DrawingArea()
delete image;
}
-int DrawingArea::width() const
-{
- return image->width();
-}
-
-int DrawingArea::height() const
-{
- return image->height();
-}
-
void DrawingArea::setColor(const QColor &color)
{
QPen pen(painter->pen());
void DrawingArea::drawPoint(int x, int y)
{
+ lock();
painter->drawPoint(x, y);
+ setDirty(QRect(x, y, 1, 1));
+ unlock();
}
void DrawingArea::drawLine(int x1, int y1, int x2, int y2)
{
+ lock();
painter->drawLine(x1, y1, x2, y2);
+ if (x1 > x2)
+ std::swap(x1, x2);
+ if (y1 > y2)
+ std::swap(y1, y2);
+ setDirty(QRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1));
+ unlock();
+}
+
+void DrawingArea::setDirty()
+{
+ setDirty(QRect(0, 0, width(), height()));
+}
+
+void DrawingArea::setDirty(const QRect &rect)
+{
+ if (dirtyFlag)
+ dirtyRect |= rect;
+ else
+ dirtyRect = rect;
+ dirtyFlag = true;
+}
+
+void DrawingArea::setClean()
+{
+ dirtyFlag = false;
}