Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
.
[graphlib.git] / DrawingArea.cpp
index f0b2316..6c3e3cc 100644 (file)
@@ -5,6 +5,7 @@ DrawingArea::DrawingArea(int width, int height)
     image = new QImage(width, height, QImage::Format_RGB32);
     image->fill(QColor(Qt::white).rgb());
     painter = new QPainter(image);
+    setDirty();
 }
 
 DrawingArea::~DrawingArea()
@@ -13,16 +14,6 @@ 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());
@@ -39,11 +30,40 @@ void DrawingArea::setColor(float red, float green, float blue)
 
 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;
 }