Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
.
[graphlib.git] / DrawingWindow.h
1 #ifndef DRAWING_WINDOW_H
2 #define DRAWING_WINDOW_H
3
4 #include <QWidget>
5 #include <Qt>
6
7 class DrawingWindowPrivate;
8
9 class DrawingWindow: public QWidget {
10 public:
11     typedef void (*ThreadFunction)(DrawingWindow &);
12
13     static const int DEFAULT_WIDTH = 640;
14     static const int DEFAULT_HEIGHT = 480;
15
16     DrawingWindow(ThreadFunction fun,
17                   int width = DEFAULT_WIDTH, int height = DEFAULT_HEIGHT);
18     DrawingWindow(QWidget *parent,
19                   ThreadFunction fun,
20                   int width = DEFAULT_WIDTH, int height = DEFAULT_HEIGHT);
21     DrawingWindow(QWidget *parent, Qt::WindowFlags flags,
22                   ThreadFunction fun,
23                   int width = DEFAULT_WIDTH, int height = DEFAULT_HEIGHT);
24
25     ~DrawingWindow();
26
27     const int width;
28     const int height;
29
30     // http://www.w3.org/TR/SVG/types.html#ColorKeywords
31     void setColor(float red, float green, float blue);
32     void setColor(const char *name);
33     void setBgColor(float red, float green, float blue);
34     void setBgColor(const char *name);
35
36     void clearGraph();
37
38     void drawPoint(int x, int y);
39     void drawLine(int x1, int y1, int x2, int y2);
40     void drawRect(int x1, int y1, int x2, int y2);
41     void fillRect(int x1, int y1, int x2, int y2);
42     void drawCircle(int x, int y, int r);
43     void fillCircle(int x, int y, int r);
44
45     bool sync(unsigned long time = ULONG_MAX);
46
47     void sleep(unsigned long secs);
48     void msleep(unsigned long msecs);
49     void usleep(unsigned long usecs);
50
51 protected:
52     void closeEvent(QCloseEvent *ev);
53     void customEvent(QEvent *ev);
54     void keyPressEvent(QKeyEvent *ev);
55     void paintEvent(QPaintEvent *ev);
56     void showEvent(QShowEvent *ev);
57     void timerEvent(QTimerEvent *ev);
58
59 private:
60     DrawingWindowPrivate * const d;
61
62     friend class DrawingWindowPrivate;
63 };
64
65 #endif // !DRAWING_WINDOW_H