Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
.
authorgiersch <giersch>
Mon, 5 Nov 2007 16:17:27 +0000 (16:17 +0000)
committergiersch <giersch>
Mon, 5 Nov 2007 16:17:27 +0000 (16:17 +0000)
DrawingWindow.cpp
DrawingWindow.h
test/hello.cpp

index 9a8d501..eb14102 100644 (file)
@@ -49,12 +49,6 @@ void DrawingWindow::initialize(ThreadFunction fun, int width, int height)
 
     painter = new QPainter(image);
 
 
     painter = new QPainter(image);
 
-#ifdef USE_PIXMAP_CACHE
-    pixmap = new QPixmap(image->size());
-    QPainter pixmapPainter(pixmap);
-    pixmapPainter.drawImage(0, 0, *image);
-#endif
-
     dirtyFlag = false;
 
     setFocusPolicy(Qt::StrongFocus);
     dirtyFlag = false;
 
     setFocusPolicy(Qt::StrongFocus);
@@ -70,9 +64,6 @@ void DrawingWindow::initialize(ThreadFunction fun, int width, int height)
 DrawingWindow::~DrawingWindow()
 {
     delete thread;
 DrawingWindow::~DrawingWindow()
 {
     delete thread;
-#ifdef USE_PIXMAP_CACHE
-    delete pixmap;
-#endif
     delete painter;
     delete image;
 }
     delete painter;
     delete image;
 }
@@ -111,13 +102,10 @@ void DrawingWindow::paintEvent(QPaintEvent *ev)
 {
     QPainter widgetPainter(this);
     QRect rect = ev->rect();
 {
     QPainter widgetPainter(this);
     QRect rect = ev->rect();
-#ifdef USE_PIXMAP_CACHE
-    widgetPainter.drawPixmap(rect, *pixmap, rect);
-#else
     lock();
     lock();
-    widgetPainter.drawImage(rect, *image, rect);
+    QImage imageCopy(*image);
     unlock();
     unlock();
-#endif
+    widgetPainter.drawImage(rect, imageCopy, rect);
 }
 
 void DrawingWindow::showEvent(QShowEvent *ev)
 }
 
 void DrawingWindow::showEvent(QShowEvent *ev)
@@ -134,37 +122,16 @@ void DrawingWindow::timerEvent(QTimerEvent *ev)
     if (ev->timerId() == timer.timerId()) {
         lock();
         if (dirtyFlag) {
     if (ev->timerId() == timer.timerId()) {
         lock();
         if (dirtyFlag) {
-#ifdef USE_PIXMAP_CACHE
-            QPainter pixmapPainter(pixmap);
-            pixmapPainter.drawImage(dirtyRect, *image, dirtyRect);
-#endif
-            dirtyFlag = false;
             update(dirtyRect);
             update(dirtyRect);
-            timer.start(paintInterval, this);
+            dirtyFlag = false;
         }
         unlock();
         }
         unlock();
+        timer.start(paintInterval, this);
     } else {
         QWidget::timerEvent(ev);
     }
 }
 
     } else {
         QWidget::timerEvent(ev);
     }
 }
 
-void DrawingWindow::setDirtyRect()
-{
-    setDirtyRect(QRect(0, 0, width(), height()));
-}
-
-void DrawingWindow::setDirtyRect(int x, int y)
-{
-    setDirtyRect(QRect(x, y, 1, 1));
-}
-
-void DrawingWindow::setDirtyRect(int x1, int y1, int x2, int y2)
-{
-    QRect r;
-    r.setCoords(x1, y1, x2, y2);
-    setDirtyRect(r.normalized());
-}
-
 void DrawingWindow::setDirtyRect(const QRect &rect)
 {
     if (dirtyFlag) {
 void DrawingWindow::setDirtyRect(const QRect &rect)
 {
     if (dirtyFlag) {
index d2ee6de..7291e96 100644 (file)
@@ -1,16 +1,11 @@
 #ifndef DRAWING_WINDOW_H
 #define DRAWING_WINDOW_H
 
 #ifndef DRAWING_WINDOW_H
 #define DRAWING_WINDOW_H
 
-#define USE_PIXMAP_CACHE
-
 #include <QBasicTimer>
 #include <QColor>
 #include <QImage>
 #include <QMutex>
 #include <QPainter>
 #include <QBasicTimer>
 #include <QColor>
 #include <QImage>
 #include <QMutex>
 #include <QPainter>
-#ifdef USE_PIXMAP_CACHE
-#  include <QPixmap>
-#endif
 #include <QRect>
 #include <QWidget>
 #include <Qt>
 #include <QRect>
 #include <QWidget>
 #include <Qt>
@@ -58,9 +53,6 @@ private:
 
     QImage *image;
     QPainter *painter;
 
     QImage *image;
     QPainter *painter;
-#ifdef USE_PIXMAP_CACHE
-    QPixmap *pixmap;
-#endif
 
     DrawingThread *thread;
     bool thread_started;
 
     DrawingThread *thread;
     bool thread_started;
@@ -105,4 +97,25 @@ void DrawingWindow::unlock()
     mutex.unlock();
 }
 
     mutex.unlock();
 }
 
+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());
+}
+
 #endif // !DRAWING_WINDOW_H
 #endif // !DRAWING_WINDOW_H
index 4143590..cf598aa 100644 (file)
@@ -119,13 +119,37 @@ int mandel(DrawingWindow &w)
     return 0;
 }
 
     return 0;
 }
 
+int lines(DrawingWindow &w)
+{
+    int n = 100000;
+    int xmax = w.width();
+    int ymax = w.height();
+    while (n-- > 0) {
+        double r = rand() / (float )RAND_MAX;
+        double g = rand() / (float )RAND_MAX;
+        double b = rand() / (float )RAND_MAX;
+        int x1 = rand() % xmax;
+        int y1 = rand() % ymax;
+        int x2 = rand() % xmax;
+        int y2 = rand() % ymax;
+        w.setColor(r, g, b);
+        w.drawLine(x1, y1, x2, y2);
+    }
+    return 0;
+}
+
 int main(int argc, char *argv[])
 {
 int main(int argc, char *argv[])
 {
-    const int nf = 1;
-    const int nm = 1;
     const int w = 1000;
     const int h = 700;
     QApplication application(argc, argv);
     const int w = 1000;
     const int h = 700;
     QApplication application(argc, argv);
+
+    DrawingWindow dd(lines, w, h);
+    dd.show();
+    return application.exec();
+
+    const int nf = 1;
+    const int nm = 1;
     DrawingWindow *dw[nf + nm];
 
     for (int i = 0; i < nf; ++i)
     DrawingWindow *dw[nf + nm];
 
     for (int i = 0; i < nf; ++i)