Index: trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh
===================================================================
--- trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh	(revision 670)
+++ trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh	(revision 673)
@@ -68,4 +68,5 @@
   void ShowView ();
   virtual void updateQWidget()=0;
+  void setupViewport(int, int);
 
 protected:
@@ -74,4 +75,6 @@
   void manageContextMenuEvent(QContextMenuEvent *e);
   void G4MousePressEvent(QPoint);
+  void G4MouseReleaseEvent(QPoint p);
+  void G4MouseDoubleClickEvent(QPoint p);
 #if QT_VERSION < 0x040000
   void G4MouseMoveEvent(int, int, Qt::ButtonState);
@@ -119,6 +122,6 @@
   void actionDrawingSurfaceRemoval();
   void actionDrawingLineSurfaceRemoval();
-  void actionControlPanels();
-  void actionExitG4();
+//   void actionControlPanels();
+//   void actionExitG4();
   void actionCreateEPS();
 
Index: trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredQtViewer.hh
===================================================================
--- trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredQtViewer.hh	(revision 670)
+++ trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredQtViewer.hh	(revision 673)
@@ -66,4 +66,6 @@
   void mousePressEvent(QMouseEvent *event);
   void mouseMoveEvent(QMouseEvent *event);
+  void mouseDoubleClickEvent(QMouseEvent *event);
+  void mouseReleaseEvent(QMouseEvent *event);
   void contextMenuEvent(QContextMenuEvent *e);
 
@@ -71,5 +73,9 @@
   bool hasToRepaint;
   bool readyToPaint;
+  bool zoomAction;
   int nbPaint;
+  QPoint beginZoom;
+  QPoint endZoom;
+  QImage glBufferImage;
 };
 
Index: trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateQtViewer.cc
===================================================================
--- trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateQtViewer.cc	(revision 670)
+++ trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateQtViewer.cc	(revision 673)
@@ -139,5 +139,5 @@
    //Make sure current viewer is attached and clean...
    //Qt version needed
-   glViewport (0, 0, WinSize_x, WinSize_y);
+   //   glViewport (0, 0, WinSize_x, WinSize_y);
 
    if(style!=G4ViewParameters::hlr &&
@@ -191,13 +191,5 @@
 ,int height)
 {  
-  int side = width;
-  if (width > height) {
-    side = height;
-  }
-  glViewport((width - side) / 2, (height - side) / 2, side, side);
-  glMatrixMode(GL_PROJECTION);
-  glLoadIdentity();
-  glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
-  glMatrixMode(GL_MODELVIEW);
+  setupViewport(width,height);
 #ifdef GEANT4_QT_DEBUG
   printf("G4OpenGLImmediateQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
@@ -223,5 +215,5 @@
    WinSize_y = (G4int) height();
 
-   glViewport (0, 0, width(), height());
+   setupViewport(width(),height());
 
    SetView();
Index: trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc
===================================================================
--- trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc	(revision 670)
+++ trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc	(revision 673)
@@ -97,4 +97,17 @@
 }
 
+/**
+ * Set the viewport of the scene
+ */
+void G4OpenGLQtViewer::setupViewport(int aWidth, int aHeight)
+{
+  int side = qMin(aWidth, aHeight);
+  glViewport((aWidth - side) / 2, (aHeight - side) / 2, side, side);
+  
+  glMatrixMode(GL_PROJECTION);
+  glLoadIdentity();
+  glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
+  glMatrixMode(GL_MODELVIEW);
+}
 
 
@@ -514,23 +527,23 @@
 
 #if QT_VERSION < 0x030200
-  QAction *controlPanels = new QAction("&Control panels","&Control panels",CTRL+Key_C,mActions);
-  QAction *exitG4 =  new QAction("&Exit to G4Vis >","&Exit to G4Vis >",CTRL+Key_E,mActions);
+//   QAction *controlPanels = new QAction("&Control panels","&Control panels",CTRL+Key_C,mActions);
+//   QAction *exitG4 =  new QAction("&Exit to G4Vis >","&Exit to G4Vis >",CTRL+Key_E,mActions);
   QAction *createEPS =  new QAction("&Save as ...","&Save as ...",CTRL+Key_S,mActions);
 #else
-  QAction *controlPanels = new QAction("&Control panels",CTRL+Key_C,mActions);
-  QAction *exitG4 =  new QAction("&Exit to G4Vis >",CTRL+Key_E,mActions);
+//   QAction *controlPanels = new QAction("&Control panels",CTRL+Key_C,mActions);
+//   QAction *exitG4 =  new QAction("&Exit to G4Vis >",CTRL+Key_E,mActions);
   QAction *createEPS =  new QAction("&Save as ...",CTRL+Key_S,mActions);
 #endif
-  controlPanels->addTo(mActions);
-  exitG4->addTo(mActions);
+//   controlPanels->addTo(mActions);
+//   exitG4->addTo(mActions);
   createEPS->addTo(mActions);
-  QObject ::connect(controlPanels, 
-                    SIGNAL(activated()),
-                    this, 
-                    SLOT(actionControlPanels()));
-  QObject ::connect(exitG4, 
-                    SIGNAL(activated()),
-                    this, 
-                    SLOT(actionExitG4()));
+//   QObject ::connect(controlPanels, 
+//                     SIGNAL(activated()),
+//                     this, 
+//                     SLOT(actionControlPanels()));
+//   QObject ::connect(exitG4, 
+//                     SIGNAL(activated()),
+//                     this, 
+//                     SLOT(actionExitG4()));
   QObject ::connect(createEPS, 
                     SIGNAL(activated()),
@@ -541,15 +554,15 @@
   // === Action Menu ===
   QMenu *mActions = fContextMenu->addMenu("&Actions");
-  QAction *controlPanels = mActions->addAction("Control panels");
-  QAction *exitG4 = mActions->addAction("Exit to G4Vis >");
+//   QAction *controlPanels = mActions->addAction("Control panels");
+//   QAction *exitG4 = mActions->addAction("Exit to G4Vis >");
   QAction *createEPS = mActions->addAction("Save as ...");
-  QObject ::connect(controlPanels, 
-                    SIGNAL(triggered()),
-                    this, 
-                    SLOT(actionControlPanels()));
-  QObject ::connect(exitG4, 
-                    SIGNAL(triggered()),
-                    this, 
-                    SLOT(actionExitG4()));
+//   QObject ::connect(controlPanels, 
+//                     SIGNAL(triggered()),
+//                     this, 
+//                     SLOT(actionControlPanels()));
+//   QObject ::connect(exitG4, 
+//                     SIGNAL(triggered()),
+//                     this, 
+//                     SLOT(actionExitG4()));
   QObject ::connect(createEPS, 
                     SIGNAL(triggered()),
@@ -1031,15 +1044,15 @@
 
 
-void G4OpenGLQtViewer::actionControlPanels() {
-#ifdef GEANT4_QT_DEBUG
-  printf("G4OpenGLQtViewer::actionControlPanels \n");
-#endif
-}
-
-void G4OpenGLQtViewer::actionExitG4() {
-#ifdef GEANT4_QT_DEBUG
-  printf("G4OpenGLQtViewer::actionExitG4() \n");
-#endif
-}
+// void G4OpenGLQtViewer::actionControlPanels() {
+// #ifdef GEANT4_QT_DEBUG
+//   printf("G4OpenGLQtViewer::actionControlPanels \n");
+// #endif
+// }
+
+// void G4OpenGLQtViewer::actionExitG4() {
+// #ifdef GEANT4_QT_DEBUG
+//   printf("G4OpenGLQtViewer::actionExitG4() \n");
+// #endif
+// }
 
 void G4OpenGLQtViewer::actionCreateEPS() {
@@ -1194,4 +1207,5 @@
 }
 
+
 /**
    @param pos_x mouse x position
@@ -1203,10 +1217,9 @@
 void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::ButtonState mButtons)
 #else
-void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons)
+  void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons)
 #endif
 {
   int dx = pos_x - lastPos.x();
   int dy = pos_y - lastPos.y();
-  
   if (fMouseAction) {  // rotate
     if (mButtons & Qt::LeftButton) {
@@ -1292,5 +1305,4 @@
 }
 
-
 /** This is the benning of a rescale function. It does nothing for the moment
     @param aWidth : new width
@@ -1308,11 +1320,11 @@
   FILE* file;
   
-  feedback_buffer = new GLfloat[size];
-  glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer);
-  glRenderMode (GL_FEEDBACK);
-  
-  glViewport (0, 0, aWidth, aHeight);
-  DrawView();
-  returned = glRenderMode (GL_RENDER);
+//   feedback_buffer = new GLfloat[size];
+//   glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer);
+//   glRenderMode (GL_FEEDBACK);
+  
+//   glViewport (0, 0, aWidth, aHeight);
+//   DrawView();
+//   returned = glRenderMode (GL_RENDER);
 
 }
@@ -1358,7 +1370,7 @@
   } else {
 #if QT_VERSION < 0x040000
-    G4cerr << "Could not open "<< file.ascii()<<"\n" << G4endl;
-#else
-    G4cerr << "Could not open "<< file.toStdString().c_str()<<"\n" << G4endl;
+    G4cerr << "Could not open "<< aFilename.ascii()<<"\n" << G4endl;
+#else
+    G4cerr << "Could not open "<< aFilename.toStdString().c_str()<<"\n" << G4endl;
 #endif
   }
Index: trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc
===================================================================
--- trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc	(revision 670)
+++ 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
