Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
51ff5a8600d45d19bc25404e672933b45d277687
[graphlib.git] / DrawingArea.h
1 #ifndef DRAWING_AREA_H
2 #define DRAWING_AREA_H
3
4 #include <QColor>
5 #include <QImage>
6 #include <QObject>
7 #include <QPainter>
8 #include <QRect>
9 #include <QSize>
10 #include <QMutex>
11
12 class DrawingArea: public QObject {
13 /*     Q_OBJECT */
14
15 public:
16     static const int DEFAULT_WIDTH = 640;
17     static const int DEFAULT_HEIGHT = 480;
18
19     DrawingArea(int width = DEFAULT_WIDTH, int height = DEFAULT_HEIGHT);
20     ~DrawingArea();
21
22     int width() const;
23     int height() const;
24     const QSize size() const;
25
26     void setColor(const QColor &color);
27     void setColor(float red, float green, float blue);
28
29     void drawPoint(int x, int y);
30     void drawLine(int x1, int y1, int x2, int y2);
31
32     QImage &getImage();
33
34     bool isDirty() const;
35     void setDirty();
36     void setDirty(const QRect &rect);
37     void setClean();
38
39     QRect getDirtyRect() const;
40
41     void lock();
42     void unlock();
43
44 private:
45     QImage *image;
46     QPainter *painter;
47     bool dirtyFlag;
48     QRect dirtyRect;
49     QMutex mutex;
50 };
51
52 inline
53 int DrawingArea::width() const
54 {
55     return image->width();
56 }
57
58 inline
59 int DrawingArea::height() const
60 {
61     return image->height();
62 }
63
64 inline
65 const QSize DrawingArea::size() const
66 {
67     return image->size();
68 }
69
70 inline
71 QImage &DrawingArea::getImage()
72 {
73     return *image;
74 }
75
76 inline
77 bool DrawingArea::isDirty() const
78 {
79     return dirtyFlag;
80 }
81
82 inline
83 QRect DrawingArea::getDirtyRect() const
84 {
85     return dirtyRect;
86 }
87
88 inline
89 void DrawingArea::lock()
90 {
91     mutex.lock();
92 }
93
94 inline
95 void DrawingArea::unlock()
96 {
97     mutex.unlock();
98 }
99
100 #endif // !DRAWING_AREA_H