Index: trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc
===================================================================
--- trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc	(revision 652)
+++ trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc	(revision 673)
@@ -43,4 +43,5 @@
 //#include <qmouseevent.h>
 #include <qevent.h> // include <qcontextmenuevent.h>
+#include <qpainter.h>
 
 G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
@@ -53,4 +54,5 @@
  QGLWidget()                      // FIXME : gerer le pb du parent !
  {
+   zoomAction = false;
    nbPaint =0;
    hasToRepaint =false;
@@ -230,7 +232,9 @@
 ,int aHeight)
 {  
-  glViewport(0, 0, aWidth, aHeight);
-  glMatrixMode(GL_PROJECTION);
-  glMatrixMode(GL_MODELVIEW);
+  setupViewport(aWidth,aHeight);
+
+//   glViewport(0, 0, aWidth, aHeight);
+//   glMatrixMode(GL_PROJECTION);
+//   glMatrixMode(GL_MODELVIEW);
 
    if (((WinSize_x != (G4int)aWidth)) || (WinSize_y != (G4int) aHeight)) {
@@ -246,51 +250,104 @@
 
 
+/** 
+@see :
+*/
 
 void G4OpenGLStoredQtViewer::paintGL()
  {
-   if (!readyToPaint) {
-#ifdef GEANT4_QT_DEBUG
-     printf("G4OpenGLStoredQtViewer::paintGL ============  Not ready %d\n",readyToPaint);
-#endif
-     readyToPaint= true;
-     return;
-   }
-   // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
-   //    WHEN CLICK ON THE FRAME FOR EXAMPLE
-   //    EXECEPT WHEN MOUSE MOVE EVENT
-   if ( !hasToRepaint) {
-     if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) {
-#ifdef GEANT4_QT_DEBUG
-       printf("G4OpenGLStoredQtViewer::paintGL ============  Dont repaint\n");
-#endif
+   if (zoomAction) {
+     QPainter painter;
+     painter.begin(this);
+     //     painter.setRenderHint(QPainter::Antialiasing);
+     QColor bg = QColor(glBufferImage.pixel(0,0));
+     printf("%d+%d+%d+%d %d+%d+%d+%d",bg.red(),bg.green(),bg.blue(),bg.alpha(),qAlpha(glBufferImage.pixel(0,0)),qRed(glBufferImage.pixel(0,0)),qGreen(glBufferImage.pixel(0,0)),qBlue(glBufferImage.pixel(0,0)));
+     painter.setBackground(QBrush(bg));
+     //     painter.drawRect(10,10,50,80);
+//      QImage test = grabFrameBuffer().copy();
+//      painter.drawImage(0, 0,test);
+     for (int ay=0;ay<glBufferImage.height();ay++) {
+       for (int ax=0;ax<glBufferImage.width();ax++) {
+         if(QColor(glBufferImage.pixel(ax,ay)) != bg) {
+//            painter.setPen(QColor(glBufferImage.pixel(ax,ay)));
+//            painter.drawPoint(ax,glBufferImage.height()-ay);
+         } else {
+           printf("o");
+         }
+         //          printf("%d+%d+%d+%d ",QColor(glBufferImage.pixel(ax,ay)).red(),QColor(glBufferImage.pixel(ax,ay)).green(),QColor(glBufferImage.pixel(ax,ay)).blue(),QColor(glBufferImage.pixel(ax,ay)).alpha());
+//          if (glBufferImage.pixel(ax,ay) == 255) {
+//            test.setPixel(ax,ay,1);
+//          } else {
+//            test.setPixel(ax,ay,0);
+//          }
+       }
+       //       printf("\n");
+     }
+//      for (int ay=0;ay<test.height();ay++) {
+//        for (int ax=0;ax<test.width();ax++) {
+//          if (test.pixel(ax,ay) == 1) {
+//            printf(".");
+//          } else if (!test.pixel(ax,ay)) {
+//            printf("X");
+//          } else {
+//            printf("%d",test.pixel(ax,ay));
+//          }
+//        }
+//        printf("\n");
+//      }
+     
+     //     painter.drawImage(0, 0, glBufferImage);
+     //     painter.drawImage(0, 0, test,0,0,-1,-1,Qt::ColorOnly);
+     
+     printf("paint event zoom \n");
+     //     painter.drawRect(beginZoom.x(),beginZoom.y(),endZoom.x()-beginZoom.x(),endZoom.y()-beginZoom.y());
+     painter.end();
+   } else {
+     
+     if (!readyToPaint) {
+#ifdef GEANT4_QT_DEBUG
+       printf("G4OpenGLStoredQtViewer::paintGL ============  Not ready %d\n",readyToPaint);
+#endif
+       readyToPaint= true;
        return;
      }
+     // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
+     //    WHEN CLICK ON THE FRAME FOR EXAMPLE
+     //    EXECEPT WHEN MOUSE MOVE EVENT
+     if ( !hasToRepaint) {
+       if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) {
+#ifdef GEANT4_QT_DEBUG
+         printf("G4OpenGLStoredQtViewer::paintGL ============  Dont repaint\n");
+#endif
+         return;
+       }
+     }
+     nbPaint++;
+#ifdef GEANT4_QT_DEBUG
+     printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV %d ready %d\n",nbPaint,readyToPaint);
+#endif
+     WinSize_x = (G4int) width();
+     WinSize_y = (G4int) height();
+     
+     setupViewport(width(),height());
+     //     glViewport (0, 0, width(), height());
+     //   glLoadIdentity();
+     
+     
+     SetView();
+     
+     //   //  printf("before ClearView\n");
+#ifdef GEANT4_QT_DEBUG
+     printf("    ClearView\n");
+#endif
+     
+     ClearView (); //ok, put the background correct
+     DrawView();
+     
+     hasToRepaint =false;
+     
+#ifdef GEANT4_QT_DEBUG
+     printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d ready %d\n",nbPaint,readyToPaint);
+#endif
    }
-   nbPaint++;
-#ifdef GEANT4_QT_DEBUG
-   printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV %d ready %d\n",nbPaint,readyToPaint);
-#endif
-   WinSize_x = (G4int) width();
-   WinSize_y = (G4int) height();
-   
-   glViewport (0, 0, width(), height());
-   //   glLoadIdentity();
-   
-
-   SetView();
-
-//   //  printf("before ClearView\n");
-#ifdef GEANT4_QT_DEBUG
-   printf("    ClearView\n");
-#endif
-   
-   ClearView (); //ok, put the background correct
-   DrawView();
-
-   hasToRepaint =false;
-
-#ifdef GEANT4_QT_DEBUG
-   printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d ready %d\n",nbPaint,readyToPaint);
-#endif
  }
 
@@ -300,14 +357,66 @@
   printf("G4OpenGLStoredQtViewer::mousePressEvent\n");
 #endif
+  setMouseTracking(true);
   G4MousePressEvent(event->pos());
 }
 
+void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *event)
+{
+#ifdef GEANT4_QT_DEBUG
+  printf("G4OpenGLStoredQtViewer::mouseDoubleClickEvent\n");
+#endif
+  setMouseTracking(true);
+  zoomAction=true;
+  makeCurrent();
+  glBufferImage = QImage( width(), height(), QImage::Format_ARGB32_Premultiplied );
+  glReadPixels( 0, 0, width(), height(), GL_RGBA, GL_UNSIGNED_BYTE, glBufferImage.bits() );
+  //  glBufferImage = grabFrameBuffer(false).convertToFormat(QImage::Format_RGB16); //QImage::Format_ARGB32_Premultiplied
+  
+#ifdef GEANT4_QT_DEBUG
+//   for (int ay=0;ay<glBufferImage.height();ay++) {
+//     for (int ax=0;ax<glBufferImage.width();ax++) {
+//       if (glBufferImage.pixel(ax,ay) == 255) {
+//         printf(".");
+//       } else if (!glBufferImage.pixel(ax,ay)) {
+//         printf("X");
+//       } else {
+//         printf("%d",glBufferImage.pixel(ax,ay));
+//       }
+//     }
+//     printf("\n");
+//   }
+#endif
+  beginZoom.setX(event->x());
+  beginZoom.setY(event->y());
+}
+
+void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *event)
+{
+#ifdef GEANT4_QT_DEBUG
+  printf("G4OpenGLStoredQtViewer::mouseReleaseEvent\n");
+#endif
+  setMouseTracking(false);
+  zoomAction =false;
+}
+
 void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
 {
+  // special case of mouse zoom action, it should draw a rect on
+  // the openGL buffer, so it could only be done in this class
+  // and sould be reimplemented in G4OpenGLImmediateQtViewer
+  if (!zoomAction) {
 #if QT_VERSION < 0x040000
-  G4MouseMoveEvent(event->x(),event->y(),event->state());
+    G4MouseMoveEvent(event->x(),event->y(),event->state());
 #else
-  G4MouseMoveEvent(event->x(),event->y(),event->buttons());
-#endif
+    G4MouseMoveEvent(event->x(),event->y(),event->buttons());
+#endif
+  } else {
+#ifdef GEANT4_QT_DEBUG
+    printf("G4OpenGLStoredQtViewer::mouseMoveEvent zoom\n");
+#endif
+    endZoom.setX(event->x());
+    endZoom.setY(event->y());
+    updateGL();
+  }
   //  DrawView();
 }
@@ -328,3 +437,4 @@
 }
 
-#endif
+
+#endif
