Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc	(revision 681)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc	(revision 682)
@@ -37,5 +37,4 @@
 
 #include "G4OpenGLStoredQtViewer.hh"
-#include "G4VisManager.hh"
 
 #include "G4ios.hh"
@@ -43,17 +42,16 @@
 //#include <qmouseevent.h>
 #include <qevent.h> // include <qcontextmenuevent.h>
-#include <qpainter.h>
 
 G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
 (G4OpenGLStoredSceneHandler& sceneHandler,
  const G4String&  name):
- G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
- G4OpenGLViewer (sceneHandler),
- G4OpenGLQtViewer (sceneHandler),
- G4OpenGLStoredViewer (sceneHandler),
- QGLWidget(QGLFormat(QGL::SampleBuffers))             // FIXME : gerer le pb du parent !
- {
-   nbPaint =0;
-   hasToRepaint =false;
+  G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
+  G4OpenGLViewer (sceneHandler),
+  G4OpenGLQtViewer (sceneHandler),
+  G4OpenGLStoredViewer (sceneHandler),
+  QGLWidget(QGLFormat(QGL::SampleBuffers))             // FIXME : gerer le pb du parent !
+{
+  nbPaint =0;
+  hasToRepaint =false;
   if (fViewId < 0) return;  // In case error in base class instantiation.
 }
@@ -61,12 +59,12 @@
 G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
 #ifdef GEANT4_QT_DEBUG
-   printf("GLWidget::~GLWidget \n");
-#endif
-   makeCurrent();
-   // this is connect to the Dialog for deleting it properly
-   // when close event.
-   //   ((QDialog*)window())->reject();
-#ifdef GEANT4_QT_DEBUG
-   printf("GLWidget::~GLWidget END\n");
+  printf("GLWidget::~GLWidget \n");
+#endif
+  makeCurrent();
+  // this is connect to the Dialog for deleting it properly
+  // when close event.
+  //   ((QDialog*)window())->reject();
+#ifdef GEANT4_QT_DEBUG
+  printf("GLWidget::~GLWidget END\n");
 #endif
 }
@@ -74,10 +72,10 @@
 void G4OpenGLStoredQtViewer::Initialise() {
 #ifdef GEANT4_QT_DEBUG
-   printf("GLWidget::Initialise \n");
-#endif
-   readyToPaint = false;
-   CreateGLQtContext ();
-#ifdef GEANT4_QT_DEBUG
-   printf("G4OpenGLStoredQtViewer::Initialise () 2\n");
+  printf("GLWidget::Initialise \n");
+#endif
+  readyToPaint = false;
+  CreateGLQtContext ();
+#ifdef GEANT4_QT_DEBUG
+  printf("G4OpenGLStoredQtViewer::Initialise () 2\n");
 #endif
   CreateMainWindow (this);
@@ -85,5 +83,5 @@
   printf("G4OpenGLStoredQtViewer::Initialise () 3\n");
 #endif
-  //  CreateFontLists ();  // FIXME Does nothing!
+  CreateFontLists ();  // FIXME Does nothing!
   
 #ifdef GEANT4_QT_DEBUG
@@ -99,29 +97,26 @@
   ClearView (); //ok, put the background correct
   FinishView();
-#ifdef GEANT4_QT_DEBUG
-  printf("G4OpenGLStoredQtViewer::Initialise () 4\n");
-#endif
 }
 
 void G4OpenGLStoredQtViewer::initializeGL () {
 
-   InitializeGLView ();
-
-#ifdef GEANT4_QT_DEBUG
-   printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n");
-#endif
-
-   // clear the buffers and window.
-   ClearView ();
-   //   printf("G4OpenGLStoredQtViewer::InitialiseGL () 2\n");
-   FinishView ();
+  InitializeGLView ();
+
+#ifdef GEANT4_QT_DEBUG
+  printf("G4OpenGLStoredQtViewer::InitialiseGL () 1\n");
+#endif
+
+  // clear the buffers and window.
+  ClearView ();
+  //   printf("G4OpenGLStoredQtViewer::InitialiseGL () 2\n");
+  FinishView ();
    
-   glDepthFunc (GL_LEQUAL);
-   glDepthMask (GL_TRUE);
-
-   hasToRepaint =true;
-
-#ifdef GEANT4_QT_DEBUG
-   printf("G4OpenGLStoredQtViewer::InitialiseGL  -------------------------------------------------------------------------------------\n");
+  glDepthFunc (GL_LEQUAL);
+  glDepthMask (GL_TRUE);
+
+  hasToRepaint =true;
+
+#ifdef GEANT4_QT_DEBUG
+  printf("G4OpenGLStoredQtViewer::InitialiseGL  -------------------------------------------------------------------------------------\n");
 #endif
 }
@@ -129,78 +124,79 @@
 
 void G4OpenGLStoredQtViewer::DrawView () {
+
 #ifdef GEANT4_QT_DEBUG
   printf("G4OpenGLStoredQtViewer::DrawView %d %d   VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",WinSize_x, WinSize_y);
 #endif
-   G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
-
-   //Make sure current viewer is attached and clean...
-   //Qt version needed
-   //   glViewport (0, 0, WinSize_x, WinSize_y);
-
-   //See if things have changed from last time and remake if necessary...
-   // The fNeedKernelVisit flag might have been set by the user in
-   // /vis/viewer/rebuild, but if not, make decision and set flag only
-   // if necessary...
-   if (!fNeedKernelVisit) 
-
-   if (!fNeedKernelVisit) KernelVisitDecision ();
+  G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
+
+  //Make sure current viewer is attached and clean...
+  //Qt version needed
+  //   glViewport (0, 0, WinSize_x, WinSize_y);
+
+  //See if things have changed from last time and remake if necessary...
+  // The fNeedKernelVisit flag might have been set by the user in
+  // /vis/viewer/rebuild, but if not, make decision and set flag only
+  // if necessary...
+  if (!fNeedKernelVisit) 
+
+    if (!fNeedKernelVisit) KernelVisitDecision ();
    
-   G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
-   ProcessView ();
+  G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
+  ProcessView ();
    
 
-   if(style!=G4ViewParameters::hlr &&
-      haloing_enabled) {
-#ifdef GEANT4_QT_DEBUG
-     printf("G4OpenGLStoredQtViewer::DrawView DANS LE IF\n");
-#endif
-
-     HaloingFirstPass ();
-     DrawDisplayLists ();
-     glFlush ();
-
-     HaloingSecondPass ();
-
-     DrawDisplayLists ();
-     FinishView ();
-
-   } else {
-#ifdef GEANT4_QT_DEBUG
-     printf("***************************  CASE 1 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
-#endif
-     
-     // If kernel visit was needed, drawing and FinishView will already
-     // have been done, so...
-     if (!kernelVisitWasNeeded) {
-#ifdef GEANT4_QT_DEBUG
-       printf("***************************  CASE 2 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
-#endif
-       DrawDisplayLists ();
-       FinishView ();
-     } else {
-#ifdef GEANT4_QT_DEBUG
-       printf("***************************  CASE 3 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
-#endif
-       // However, union cutaways are implemented in DrawDisplayLists, so make
-       // an extra pass...
-       if (fVP.IsCutaway() &&
-           fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
-         ClearView();
-         DrawDisplayLists ();
-         FinishView ();
-#ifdef GEANT4_QT_DEBUG
-         printf("***************************  CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
-#endif
-       } else { // ADD TO AVOID KernelVisit=1 and nothing to display
-         DrawDisplayLists ();
-         FinishView ();
-       }
-     }
-   }
-
-#ifdef GEANT4_QT_DEBUG
-   printf("G4OpenGLStoredQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y);
-#endif
-   hasToRepaint =true;
+  if(style!=G4ViewParameters::hlr &&
+     haloing_enabled) {
+#ifdef GEANT4_QT_DEBUG
+    printf("G4OpenGLStoredQtViewer::DrawView DANS LE IF\n");
+#endif
+
+    HaloingFirstPass ();
+    DrawDisplayLists ();
+    glFlush ();
+
+    HaloingSecondPass ();
+
+    DrawDisplayLists ();
+    FinishView ();
+
+  } else {
+#ifdef GEANT4_QT_DEBUG
+    printf("***************************  CASE 1 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
+#endif
+     
+    // If kernel visit was needed, drawing and FinishView will already
+    // have been done, so...
+    if (!kernelVisitWasNeeded) {
+#ifdef GEANT4_QT_DEBUG
+      printf("***************************  CASE 2 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
+#endif
+      DrawDisplayLists ();
+      FinishView ();
+    } else {
+#ifdef GEANT4_QT_DEBUG
+      printf("***************************  CASE 3 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
+#endif
+      // However, union cutaways are implemented in DrawDisplayLists, so make
+      // an extra pass...
+      if (fVP.IsCutaway() &&
+          fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
+        ClearView();
+        DrawDisplayLists ();
+        FinishView ();
+#ifdef GEANT4_QT_DEBUG
+        printf("***************************  CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
+#endif
+      } else { // ADD TO AVOID KernelVisit=1 and nothing to display
+        DrawDisplayLists ();
+        FinishView ();
+      }
+    }
+  }
+
+#ifdef GEANT4_QT_DEBUG
+  printf("G4OpenGLStoredQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y);
+#endif
+  hasToRepaint =true;
 }
 
@@ -226,22 +222,18 @@
 
 /**
- - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
- */
+   - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
+*/
 void G4OpenGLStoredQtViewer::resizeGL(
- int aWidth
-,int aHeight)
+                                      int aWidth
+                                      ,int aHeight)
 {  
   setupViewport(aWidth,aHeight);
 
-//   glViewport(0, 0, aWidth, aHeight);
-//   glMatrixMode(GL_PROJECTION);
-//   glMatrixMode(GL_MODELVIEW);
-
-   if (((WinSize_x != (G4int)aWidth)) || (WinSize_y != (G4int) aHeight)) {
-     hasToRepaint =true;
-   }
-   WinSize_x = (G4int) aWidth;
-   WinSize_y = (G4int) aHeight;
-
+  if (((WinSize_x != (G4int)aWidth)) || (WinSize_y != (G4int) aHeight)) {
+    hasToRepaint =true;
+  }
+  WinSize_x = (G4int) aWidth;
+  WinSize_y = (G4int) aHeight;
+  
 #ifdef GEANT4_QT_DEBUG
   printf("G4OpenGLStoredQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d %d=%d %d=%d\n",hasToRepaint,width(),aWidth,height(),aHeight);
@@ -251,64 +243,66 @@
 
 /** 
-@see :
+    @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
-         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
- }
+{
+     
+  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
+}
 
 void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
 {
-#ifdef GEANT4_QT_DEBUG
-  printf("G4OpenGLStoredQtViewer::mousePressEvent\n");
-#endif
-  setMouseTracking(true);
-  G4MousePressEvent(event->pos());
+  if ((event->buttons() & Qt::LeftButton) && (event->modifiers() & Qt::NoModifier)) {
+#ifdef GEANT4_QT_DEBUG
+    printf("G4OpenGLStoredQtViewer::mousePressEvent\n");
+#endif
+    setMouseTracking(true);
+    G4MousePressEvent(event->pos());
+  }
 }
 
@@ -322,6 +316,6 @@
   printf("G4OpenGLStoredQtViewer::mouseDoubleClickEvent\n");
 #endif
-//   setMouseTracking(true);
-//   glBufferImage = grabFrameBuffer().convertToFormat(QImage::Format_ARGB32);//_Premultiplied);  
+  //   setMouseTracking(true);
+  //   glBufferImage = grabFrameBuffer().convertToFormat(QImage::Format_ARGB32);//_Premultiplied);  
 }
 
@@ -331,5 +325,5 @@
   printf("G4OpenGLStoredQtViewer::mouseReleaseEvent\n");
 #endif
-//   setMouseTracking(false);
+  //   setMouseTracking(false);
 }
 
@@ -338,7 +332,7 @@
 
 #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());
+  G4MouseMoveEvent(event->x(),event->y(),event->buttons());
 #endif
 }
