From 0e830a97d132fdc9ac3256dce3a7323e91545f8a Mon Sep 17 00:00:00 2001 From: giersch Date: Tue, 6 Nov 2007 11:17:24 +0000 Subject: [PATCH] . --- DrawingWindow.h | 122 ++++++------------------------------------------ 1 file changed, 14 insertions(+), 108 deletions(-) diff --git a/DrawingWindow.h b/DrawingWindow.h index 10f0aa8..7685d7d 100644 --- a/DrawingWindow.h +++ b/DrawingWindow.h @@ -1,20 +1,13 @@ #ifndef DRAWING_WINDOW_H #define DRAWING_WINDOW_H -#include -#include -#include -#include -#include -#include +#include #include #include -#include +class DrawingWindowPrivate; class DrawingWindow: public QWidget { -/* Q_OBJECT */ - public: typedef void (*ThreadFunction)(DrawingWindow &); @@ -32,14 +25,21 @@ public: ~DrawingWindow(); - int width() const; - int height() const; + const int width; + const int height; void setColor(float red, float green, float blue); - void setColor(const QColor &color); + void setBgColor(float red, float green, float blue); + + void clearGraph(); void drawPoint(int x, int y); void drawLine(int x1, int y1, int x2, int y2); + void drawRect(int x1, int y1, int x2, int y2); + + void sleep(unsigned long secs); + void msleep(unsigned long msecs); + void usleep(unsigned long usecs); protected: void closeEvent(QCloseEvent *ev); @@ -48,103 +48,9 @@ protected: void timerEvent(QTimerEvent *ev); private: - class DrawingThread: public QThread { - public: - DrawingThread(DrawingWindow &w, ThreadFunction f); - void run(); - - void enableTerminate(); - void disableTerminate(); - - private: - DrawingWindow &drawingWindow; - ThreadFunction threadFunction; - - }; - - static const int paintInterval = 33; - - QBasicTimer timer; - - QImage *image; - QPainter *painter; - - DrawingThread *thread; - bool thread_started; - - bool dirtyFlag; - QRect dirtyRect; + DrawingWindowPrivate * const d; - QMutex mutex; - - void initialize(ThreadFunction fun, int width, int height); - - void lock(); - void unlock(); - - void setDirtyRect(); - void setDirtyRect(int x, int y); - void setDirtyRect(int x1, int y1, int x2, int y2); - void setDirtyRect(const QRect &rect); + friend class DrawingWindowPrivate; }; -inline -int DrawingWindow::width() const -{ - return image->width(); -} - -inline -int DrawingWindow::height() const -{ - return image->height(); -} - -inline -void DrawingWindow::lock() -{ - thread->disableTerminate(); - mutex.lock(); -} - -inline -void DrawingWindow::unlock() -{ - mutex.unlock(); - thread->enableTerminate(); -} - -inline -void DrawingWindow::setDirtyRect() -{ - dirtyFlag = true; - dirtyRect.setRect(0, 0, width(), height()); -} - -inline -void DrawingWindow::setDirtyRect(int x, int y) -{ - setDirtyRect(QRect(x, y, 1, 1)); -} - -inline -void DrawingWindow::setDirtyRect(int x1, int y1, int x2, int y2) -{ - QRect r; - r.setCoords(x1, y1, x2, y2); - setDirtyRect(r.normalized()); -} - -inline -void DrawingWindow::DrawingThread::enableTerminate() -{ - setTerminationEnabled(true); -} - -inline -void DrawingWindow::DrawingThread::disableTerminate() -{ - setTerminationEnabled(false); -} - #endif // !DRAWING_WINDOW_H -- 2.20.1