1 #ifndef DRAWING_WINDOW_H
2 #define DRAWING_WINDOW_H
15 class DrawingWindow: public QWidget {
19 typedef void (*ThreadFunction)(DrawingWindow &);
21 static const int DEFAULT_WIDTH = 640;
22 static const int DEFAULT_HEIGHT = 480;
24 DrawingWindow(ThreadFunction fun,
25 int width = DEFAULT_WIDTH, int height = DEFAULT_HEIGHT);
26 DrawingWindow(QWidget *parent,
28 int width = DEFAULT_WIDTH, int height = DEFAULT_HEIGHT);
29 DrawingWindow(QWidget *parent, Qt::WindowFlags flags,
31 int width = DEFAULT_WIDTH, int height = DEFAULT_HEIGHT);
38 void setColor(float red, float green, float blue);
39 void setColor(const QColor &color);
41 void drawPoint(int x, int y);
42 void drawLine(int x1, int y1, int x2, int y2);
45 void closeEvent(QCloseEvent *ev);
46 void paintEvent(QPaintEvent *ev);
47 void showEvent(QShowEvent *ev);
48 void timerEvent(QTimerEvent *ev);
51 class DrawingThread: public QThread {
53 DrawingThread(DrawingWindow &w, ThreadFunction f);
56 void enableTerminate();
57 void disableTerminate();
60 DrawingWindow &drawingWindow;
61 ThreadFunction threadFunction;
65 static const int paintInterval = 33;
72 DrawingThread *thread;
80 void initialize(ThreadFunction fun, int width, int height);
86 void setDirtyRect(int x, int y);
87 void setDirtyRect(int x1, int y1, int x2, int y2);
88 void setDirtyRect(const QRect &rect);
92 int DrawingWindow::width() const
94 return image->width();
98 int DrawingWindow::height() const
100 return image->height();
104 void DrawingWindow::lock()
106 thread->disableTerminate();
111 void DrawingWindow::unlock()
114 thread->enableTerminate();
118 void DrawingWindow::setDirtyRect()
121 dirtyRect.setRect(0, 0, width(), height());
125 void DrawingWindow::setDirtyRect(int x, int y)
127 setDirtyRect(QRect(x, y, 1, 1));
131 void DrawingWindow::setDirtyRect(int x1, int y1, int x2, int y2)
134 r.setCoords(x1, y1, x2, y2);
135 setDirtyRect(r.normalized());
139 void DrawingWindow::DrawingThread::enableTerminate()
141 setTerminationEnabled(true);
145 void DrawingWindow::DrawingThread::disableTerminate()
147 setTerminationEnabled(false);
150 #endif // !DRAWING_WINDOW_H