Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
6c3e3cce33bd7f6b3292f935e5ef1a132ebc7392
[graphlib.git] / DrawingArea.cpp
1 #include <DrawingArea.h>
2
3 DrawingArea::DrawingArea(int width, int height)
4 {
5     image = new QImage(width, height, QImage::Format_RGB32);
6     image->fill(QColor(Qt::white).rgb());
7     painter = new QPainter(image);
8     setDirty();
9 }
10
11 DrawingArea::~DrawingArea()
12 {
13     delete painter;
14     delete image;
15 }
16
17 void DrawingArea::setColor(const QColor &color)
18 {
19     QPen pen(painter->pen());
20     pen.setColor(color);
21     painter->setPen(pen);
22 }
23
24 void DrawingArea::setColor(float red, float green, float blue)
25 {
26     QColor color;
27     color.setRgbF(red, green, blue);
28     this->setColor(color);
29 }
30
31 void DrawingArea::drawPoint(int x, int y)
32 {
33     lock();
34     painter->drawPoint(x, y);
35     setDirty(QRect(x, y, 1, 1));
36     unlock();
37 }
38
39 void DrawingArea::drawLine(int x1, int y1, int x2, int y2)
40 {
41     lock();
42     painter->drawLine(x1, y1, x2, y2);
43     if (x1 > x2)
44         std::swap(x1, x2);
45     if (y1 > y2)
46         std::swap(y1, y2);
47     setDirty(QRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1));
48     unlock();
49 }
50
51 void DrawingArea::setDirty()
52 {
53     setDirty(QRect(0, 0, width(), height()));
54 }
55
56 void DrawingArea::setDirty(const QRect &rect)
57 {
58     if (dirtyFlag)
59         dirtyRect |= rect;
60     else
61         dirtyRect = rect;
62     dirtyFlag = true;
63 }
64
65 void DrawingArea::setClean()
66 {
67     dirtyFlag = false;
68 }
69