Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
.
authorgiersch <giersch>
Mon, 1 Oct 2007 16:02:56 +0000 (16:02 +0000)
committergiersch <giersch>
Mon, 1 Oct 2007 16:02:56 +0000 (16:02 +0000)
DrawingArea.cpp [new file with mode: 0644]
DrawingArea.h [new file with mode: 0644]
DrawingAreaInterface.h [new file with mode: 0644]
DrawingThreadCore.cpp [new file with mode: 0644]
DrawingThreadCore.h [new file with mode: 0644]
MainDrawingThread.cpp [new file with mode: 0644]
MainDrawingThread.h [new file with mode: 0644]
test/hello.cpp
test/hello.pro

diff --git a/DrawingArea.cpp b/DrawingArea.cpp
new file mode 100644 (file)
index 0000000..f0b2316
--- /dev/null
@@ -0,0 +1,49 @@
+#include <DrawingArea.h>
+
+DrawingArea::DrawingArea(int width, int height)
+{
+    image = new QImage(width, height, QImage::Format_RGB32);
+    image->fill(QColor(Qt::white).rgb());
+    painter = new QPainter(image);
+}
+
+DrawingArea::~DrawingArea()
+{
+    delete painter;
+    delete image;
+}
+
+int DrawingArea::width() const
+{
+    return image->width();
+}
+
+int DrawingArea::height() const
+{
+    return image->height();
+}
+
+void DrawingArea::setColor(const QColor &color)
+{
+    QPen pen(painter->pen());
+    pen.setColor(color);
+    painter->setPen(pen);
+}
+
+void DrawingArea::setColor(float red, float green, float blue)
+{
+    QColor color;
+    color.setRgbF(red, green, blue);
+    this->setColor(color);
+}
+
+void DrawingArea::drawPoint(int x, int y)
+{
+    painter->drawPoint(x, y);
+}
+
+void DrawingArea::drawLine(int x1, int y1, int x2, int y2)
+{
+    painter->drawLine(x1, y1, x2, y2);
+}
+
diff --git a/DrawingArea.h b/DrawingArea.h
new file mode 100644 (file)
index 0000000..76d03ef
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef DRAWING_AREA_H
+#define DRAWING_AREA_H
+
+#include <DrawingAreaInterface.h>
+
+#include <QColor>
+#include <QImage>
+#include <QPainter>
+
+class DrawingArea: public DrawingAreaInterface {
+private:
+    QImage *image;
+    QPainter *painter;
+
+public:
+    DrawingArea(int width = DEFAULT_WIDTH, int height = DEFAULT_HEIGHT);
+    ~DrawingArea();
+
+    int width() const;
+    int height() const;
+
+    void setColor(const QColor &color);
+    void setColor(float red, float green, float blue);
+
+    void drawPoint(int x, int y);
+    void drawLine(int x1, int y1, int x2, int y2);
+
+};
+
+#endif // !DRAWING_AREA_H
+
+
+
diff --git a/DrawingAreaInterface.h b/DrawingAreaInterface.h
new file mode 100644 (file)
index 0000000..98190e7
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef DRAWING_AREA_INTERFACE_H
+#define DRAWING_AREA_INTERFACE_H
+
+class DrawingAreaInterface {
+public:
+    static const int DEFAULT_WIDTH = 640;
+    static const int DEFAULT_HEIGHT = 480;
+
+    virtual ~DrawingAreaInterface() { }
+
+    virtual void setColor(float red, float green, float blue) = 0;
+    virtual void drawPoint(int x, int y) = 0;
+    virtual void drawLine(int x1, int y1, int x2, int y2) = 0;
+    
+    virtual void wait() = 0;
+    virtual void waitAll() = 0;
+};
+
+#endif // !DRAWING_AREA_INTERFACE_H
diff --git a/DrawingThreadCore.cpp b/DrawingThreadCore.cpp
new file mode 100644 (file)
index 0000000..b1628a6
--- /dev/null
@@ -0,0 +1,24 @@
+#include <DrawingThreadCore.h>
+
+DrawingThreadCore::DrawingThreadCore(int argc_, char **argv_)
+    : QThread()
+    , argc(argc_)
+    , argv(argv_)
+{
+}
+
+void DrawingThreadCore::run()
+{
+    exit(this->runForReal(argc, argv));
+}
+
+int DrawingThreadCore::runForReal()
+{
+    throw MissingImplementationException();
+}
+
+int DrawingThreadCore::runForReal(int /* argc */, char ** /* argv_ */)
+{
+    return this->runForReal();
+}
+
diff --git a/DrawingThreadCore.h b/DrawingThreadCore.h
new file mode 100644 (file)
index 0000000..e0658e9
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef DRAWING_THREAD_CORE_H
+#define DRAWING_THREAD_CORE_H
+
+#include <QThread>
+
+class DrawingThreadCore: public QThread {
+private:
+    int argc;
+    char **argv;
+
+public:
+    class MissingImplementationException { };
+
+protected:
+    virtual int runForReal();
+    virtual int runForReal(int argc, char **argv);
+
+public:
+    DrawingThreadCore(int argc, char **argv);
+
+    void run();
+
+};
+
+#endif // !DRAWING_THREAD_CORE_H
diff --git a/MainDrawingThread.cpp b/MainDrawingThread.cpp
new file mode 100644 (file)
index 0000000..2c4339a
--- /dev/null
@@ -0,0 +1,18 @@
+#include <MainDrawingThread.h>
+
+#include <QApplication>
+
+MainDrawingThread::MainDrawingThread(int argc, char **argv)
+    : DrawingThreadCore(argc, argv)
+{
+}
+
+int main(int argc, char *argv[])
+{
+    QApplication application(argc, argv);
+    MainDrawingThread mainDrawingThread(argc, argv);
+
+    mainDrawingThread.start();
+
+    return application.exec();
+}
diff --git a/MainDrawingThread.h b/MainDrawingThread.h
new file mode 100644 (file)
index 0000000..08091b8
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef MAIN_DRAWING_THREAD_H
+#define MAIN_DRAWING_THREAD_H
+
+#include <DrawingThreadCore.h>
+
+class MainDrawingThread: public DrawingThreadCore {
+public:
+    MainDrawingThread(int argc, char **argv);
+
+    int runForReal();
+    int runForReal(int argc, char **argv);
+};
+
+#define main_thread MainDrawingThread::runForReal
+
+#endif // !MAIN_DRAWING_THREAD_H
index 29b81f8..a388e00 100644 (file)
  */
 
 
-#include <QApplication>
-#include <QImage>
-#include <QLabel>
-#include <QPaintEvent>
-#include <QPainter>
-#include <QPixmap>
-#include <QThread>
-#include <Qt>
-
-#include <cmath>
-#include <iostream>
-#include <string>
+#include <DrawingArea.h>
+#include <MainDrawingThread.h>
 
-//============================================================
-// DrawingAreaInterface
-
-class DrawingAreaInterface {
-public:
-    static const int DEFAULT_WIDTH = 640;
-    static const int DEFAULT_HEIGHT = 480;
+int main_thread(int, char **)
+{
+    // >>> insert main drawing code here <<<
+    return 0;
+}
 
-    virtual ~DrawingAreaInterface() { }
+//============================================================
 
-    virtual void setColor(float red, float green, float blue) = 0;
-    virtual void drawPoint(int x, int y) = 0;
-    virtual void drawLine(int x1, int y1, int x2, int y2) = 0;
-    
-    virtual void wait() = 0;
-    virtual void waitAll() = 0;
-};
+//**********************************************************************
+//**********************************************************************
+//**********************************************************************
+//**********************************************************************
+//**********************************************************************
+#if 0
 
 //============================================================
 // WindowCore
@@ -240,100 +227,6 @@ void QtDrawingArea::init(int width, int height, const char *title)
 
 
 //============================================================
-class DrawingArea: public DrawingAreaInterface {
-private:
-    QImage *image;
-    QPainter *painter;
-
-public:
-    DrawingArea(int width = DEFAULT_WIDTH, int height = DEFAULT_HEIGHT);
-    ~DrawingArea();
-
-    int width() const
-    {
-        return image->width();
-    }
-
-    int height() const
-    {
-        return image->height();
-    }
-
-    void setColor(const QColor &color)
-    {
-        QPen pen(painter->pen());
-        pen.setColor(color);
-        painter->setPen(pen);
-    }
-
-    void setColor(float red, float green, float blue)
-    {
-        QColor color;
-        color.setRgbF(red, green, blue);
-        this->setColor(color);
-    }
-
-    void drawPoint(int x, int y)
-    {
-        painter->drawPoint(x, y);
-    }
-
-    void drawLine(int x1, int y1, int x2, int y2)
-    {
-        painter->drawLine(x1, y1, x2, y2);
-    }
-
-};
-
-DrawingArea::DrawingArea(int width, int height)
-{
-    image = new QImage(width, height, QImage::Format_RGB32);
-    image->fill(QColor(Qt::white).rgb());
-    painter = new QPainter(image);
-}
-
-DrawingArea::~DrawingArea()
-{
-    delete painter;
-    delete image;
-}
-
-//============================================================
-class DrawingThreadCore: public QThread {
-public:
-    void run();
-    virtual void runForReal() = 0;
-};
-
-void DrawingThreadCore::run()
-{
-    this->runForReal();
-}
-
-//============================================================
-class MainDrawingThread: public DrawingThreadCore {
-public:
-    void runForReal();
-};
-
-void MainDrawingThread::runForReal()
-{
-    // >>> insert main drawing code here <<<
-}
-
-//============================================================
-int main(int argc, char *argv[])
-{
-    QApplication application(argc, argv);
-    MainDrawingThread mainDrawingThread;
-
-    mainDrawingThread.start();
-
-    return application.exec();
-}
-
-//============================================================
-#if 0
 
 /* paramètres par défaut */
 int larg = 600;
index c8d04a1..f788dca 100644 (file)
@@ -1,3 +1,6 @@
 TARGET = hello
 CONFIG += qt debug
-SOURCES += hello.cc
+SOURCES += hello.cc \
+        DrawingArea.cpp \
+        DrawingThreadCore.cpp  \
+        MainDrawingThread.cpp