Index: trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh
===================================================================
--- trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh	(revision 792)
+++ trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh	(revision 797)
@@ -58,4 +58,5 @@
 class QKeyEvent;
 class QProcess;
+class QTime;
 
 class G4OpenGLSceneHandler;
@@ -92,17 +93,18 @@
   void manageContextMenuEvent(QContextMenuEvent *e);
 #if QT_VERSION < 0x040000
-  void G4MousePressEvent(QPoint, Qt::ButtonState);
-#else
-  void G4MousePressEvent(QPoint, Qt::MouseButtons);
-#endif
+  void G4MousePressEvent(QPoint);
+#else
+  void G4MousePressEvent(QPoint);
+#endif
+  void G4MouseReleaseEvent();
   void G4MouseDoubleClickEvent(QPoint p);
 #if QT_VERSION < 0x040000
-  void G4MouseMoveEvent(int, int, Qt::ButtonState,bool mAutoMove = false);
-#else
-  void G4MouseMoveEvent(int, int, Qt::MouseButtons,bool mAutoMove = false);
+  void G4MouseMoveEvent(int, int, Qt::ButtonState);
+#else
+  void G4MouseMoveEvent(int, int, Qt::MouseButtons);
 #endif
   void G4keyPressEvent (QKeyEvent * event); 
-  void rotateScene(G4double, G4double,bool mAutoRotate=false);
-  void moveScene(G4double, G4double, G4double,bool,bool mAutoMove=false);
+  void rotateScene(int, int);
+  void moveScene(int, int, int,bool);
 
 
@@ -183,4 +185,6 @@
   RECORDING_STEP fRecordingStep;
   QProcess *fProcess;
+  QTime *fLastEventTime;
+  int fSpinningDelay;
 
 private slots :
Index: trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc
===================================================================
--- trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc	(revision 792)
+++ trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc	(revision 797)
@@ -36,5 +36,5 @@
 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER
 
-//#define GEANT4_QT_DEBUG
+#define GEANT4_QT_DEBUG
 
 #include "G4OpenGLQtViewer.hh"
@@ -77,5 +77,5 @@
 #include <qdialog.h>
 #include <qevent.h> //include <qcontextmenuevent.h>
-
+#include <qdatetime.h>
 
 //////////////////////////////////////////////////////////////////////////////
@@ -316,4 +316,6 @@
   initMovieParameters();
 
+  fLastEventTime = new QTime();
+
 #ifdef GEANT4_QT_DEBUG
   printf("G4OpenGLQtViewer::G4OpenGLQtViewer END\n");
@@ -1507,13 +1509,51 @@
 */
 #if QT_VERSION < 0x040000
-void G4OpenGLQtViewer::G4MousePressEvent(QPoint p,Qt::ButtonState mButtons)
-#else
-void G4OpenGLQtViewer::G4MousePressEvent(QPoint p,Qt::MouseButtons mButtons)
+void G4OpenGLQtViewer::G4MousePressEvent(QPoint p)
+#else
+void G4OpenGLQtViewer::G4MousePressEvent(QPoint p)
 #endif
 {
   fAutoMove = false; // stop automove
   fLastPos = p;
+  fLastEventTime->start();
   if (fMouseAction == STYLE2){  // pick
     Pick(p.x(),p.y());
+  }
+}
+
+/**
+*/
+void G4OpenGLQtViewer::G4MouseReleaseEvent()
+{
+  fSpinningDelay = fLastEventTime->elapsed();
+#ifdef GEANT4_QT_DEBUG
+  printf("G4OpenGLQtViewer::G4MouseReleaseEvent delay %d\n",fSpinningDelay);
+#endif
+  if ((fDeltaPosX == 0) && (fDeltaPosY == 0)) {
+    return;
+  }
+  if (fSpinningDelay < 100 ) {
+    fAutoMove = true;
+
+    QTime lastMoveTime;
+    lastMoveTime.start();
+    // try to addapt speed move/rotate looking to drawing speed
+    int cycles = 4;
+    while (fAutoMove) {
+      if ( lastMoveTime.elapsed() > (100 / (cycles/2))) {
+        if (fMouseAction == STYLE1) {  // rotate
+          rotateScene(fDeltaPosX,fDeltaPosY);
+        } else if (fMouseAction == STYLE2) {  // move
+          moveScene(-fDeltaPosX,-fDeltaPosY,0,true);
+        }
+        lastMoveTime.start();
+        cycles = 1 ;
+      }
+      ((QApplication*)G4Qt::getInstance ())->processEvents();
+      cycles ++ ;
+    }
+    fDeltaPosX = 0;
+    fDeltaPosY = 0;
+    
   }
 }
@@ -1528,37 +1568,28 @@
 
 #if QT_VERSION < 0x040000
-void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::ButtonState mButtons,bool mAutoMove)
-#else
-  void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons,bool mAutoMove)
+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)
 #endif
 {
-  fAutoMove = mAutoMove;
-
-  if (!fAutoMove) {  // keep old delta if automove
-    fDeltaPosX = fLastPos.x() - pos_x;
-    fDeltaPosY = fLastPos.y() - pos_y;
-  }
-
-  if ((fDeltaPosX == 0) && (fDeltaPosY == 0)) {
-    fAutoMove = false;
-  }
-
+
+  if (fAutoMove) {
+    return;
+  }
+
+  fDeltaPosX = fLastPos.x() - pos_x;
+  fDeltaPosY = fLastPos.y() - pos_y;
+  
   if (fMouseAction == STYLE1) {  // rotate
     if (mButtons & Qt::LeftButton) {
-      rotateScene(fDeltaPosX,fDeltaPosY,fAutoMove);
+      rotateScene(fDeltaPosX,fDeltaPosY);
     }
   } else if (fMouseAction == STYLE2) {  // move
     if (mButtons & Qt::LeftButton) {
-      if (fAutoMove) {
-        while (fAutoMove) {
-          moveScene(-fDeltaPosX,-fDeltaPosY,0,true,true);
-          ((QApplication*)G4Qt::getInstance ())->processEvents();
-        }
-      } else {
-        moveScene(-fDeltaPosX,-fDeltaPosY,0,true,false);
-      }
+      moveScene(-fDeltaPosX,-fDeltaPosY,0,true);
     }
   }
   fLastPos = QPoint(pos_x, pos_y);
+  fLastEventTime->start();
 }
 
@@ -1571,5 +1602,5 @@
 */
 
-void G4OpenGLQtViewer::moveScene(G4double dx,G4double dy, G4double dz,bool mouseMove,bool mAutoMove)
+void G4OpenGLQtViewer::moveScene(int dx,int dy, int dz,bool mouseMove)
 {
   if (fHoldMoveEvent)
@@ -1577,29 +1608,21 @@
   fHoldMoveEvent = true;
 
-  if( mAutoMove == false) {
-    fAutoMove = true;
-  }
   G4double coefTrans = 0;
   GLdouble coefDepth = 0;
-  while (fAutoMove) {
-    if( mAutoMove == false) {
-      fAutoMove = false;
-    }
-    if(mouseMove) {
-      coefTrans = ((G4double)getSceneNearWidth())/((G4double)WinSize_x);
-      if (WinSize_y <WinSize_x) {
-        coefTrans = ((G4double)getSceneNearWidth())/((G4double)WinSize_y);
-      }
-    } else {
-      coefTrans = getSceneNearWidth()*fDeltaSceneTranslation;
-      coefDepth = getSceneDepth()*fDeltaDepth;
-    }
-    fVP.IncrementPan(-dx*coefTrans,dy*coefTrans,dz*coefDepth);
-    
-    updateQWidget();
-    if (fAutoMove)
-      ((QApplication*)G4Qt::getInstance ())->processEvents();
-  }
-
+  if(mouseMove) {
+    coefTrans = ((G4double)getSceneNearWidth())/((G4double)WinSize_x);
+    if (WinSize_y <WinSize_x) {
+      coefTrans = ((G4double)getSceneNearWidth())/((G4double)WinSize_y);
+    }
+  } else {
+    coefTrans = getSceneNearWidth()*fDeltaSceneTranslation;
+    coefDepth = getSceneDepth()*fDeltaDepth;
+  }
+  fVP.IncrementPan(-dx*coefTrans,dy*coefTrans,dz*coefDepth);
+  
+  updateQWidget();
+  if (fAutoMove)
+    ((QApplication*)G4Qt::getInstance ())->processEvents();
+  
   fHoldMoveEvent = false;
 }
@@ -1611,13 +1634,14 @@
 */
 
-void G4OpenGLQtViewer::rotateScene(G4double dx, G4double dy,bool mAutoRotate)
+void G4OpenGLQtViewer::rotateScene(int dx, int dy)
 {
+#ifdef GEANT4_QT_DEBUG
+  printf("G4OpenGLQtViewer::rotateScene %d %d\n",dx,dy);
+#endif
+
   if (fHoldRotateEvent)
     return;
   fHoldRotateEvent = true;
 
-  if( mAutoRotate == false) {
-    fAutoMove = true;
-  }
   G4Vector3D vp;
   G4Vector3D up;
@@ -1641,75 +1665,70 @@
   G4Vector3D viewPoint;
 
-  while (fAutoMove) {
-    if( mAutoRotate == false) {
-      fAutoMove = false;
-    }
     
-    //phi spin stuff here
-  
-    vp = fVP.GetViewpointDirection ().unit ();
-    up = fVP.GetUpVector ().unit ();
-  
-    yprime = (up.cross(vp)).unit();
-    zprime = (vp.cross(yprime)).unit();
-  
-    if (fVP.GetLightsMoveWithCamera()) {
-      delta_alpha = dy * fDeltaRotation;
-      delta_theta = -dx * fDeltaRotation;
-    } else {
-      delta_alpha = -dy * fDeltaRotation;
-      delta_theta = dx * fDeltaRotation;
-    }    
-  
-    delta_alpha *= deg;
-    delta_theta *= deg;
-  
-    new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime;
-
-    // to avoid z rotation flipping
-    // to allow more than 360° rotation
-    if (fVP.GetLightsMoveWithCamera()) {
-      new_up = (new_vp.cross(yprime)).unit();
-      if (new_vp.z()*vp.z() <0) {
-        new_up.set(new_up.x(),-new_up.y(),new_up.z());
-      }
-    } else {
-      new_up = up;
-      if (new_vp.z()*vp.z() <0) {
-        new_up.set(new_up.x(),-new_up.y(),new_up.z());
-      }
-    }
-    fVP.SetUpVector(new_up);
-    ////////////////
-    // Rotates by fixed azimuthal angle delta_theta.
-    
-    cosalpha = new_up.dot (new_vp.unit());
-    sinalpha = std::sqrt (1. - std::pow (cosalpha, 2));
-    yprime = (new_up.cross (new_vp.unit())).unit ();
-    xprime = yprime.cross (new_up);
-    // Projection of vp on plane perpendicular to up...
-    a1 = sinalpha * xprime;
-    // Required new projection...
-    a2 = sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime);
-    // Required Increment vector...
-    delta = a2 - a1;
-    // So new viewpoint is...
-    viewPoint = new_vp.unit() + delta;
-    
+  //phi spin stuff here
+  
+  vp = fVP.GetViewpointDirection ().unit ();
+  up = fVP.GetUpVector ().unit ();
+  
+  yprime = (up.cross(vp)).unit();
+  zprime = (vp.cross(yprime)).unit();
+  
+  if (fVP.GetLightsMoveWithCamera()) {
+    delta_alpha = dy * fDeltaRotation;
+    delta_theta = -dx * fDeltaRotation;
+  } else {
+    delta_alpha = -dy * fDeltaRotation;
+    delta_theta = dx * fDeltaRotation;
+  }    
+  
+  delta_alpha *= deg;
+  delta_theta *= deg;
+  
+  new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime;
+  
+  // to avoid z rotation flipping
+  // to allow more than 360° rotation
+  if (fVP.GetLightsMoveWithCamera()) {
+    new_up = (new_vp.cross(yprime)).unit();
+    if (new_vp.z()*vp.z() <0) {
+      new_up.set(new_up.x(),-new_up.y(),new_up.z());
+    }
+  } else {
+    new_up = up;
+    if (new_vp.z()*vp.z() <0) {
+      new_up.set(new_up.x(),-new_up.y(),new_up.z());
+    }
+  }
+  fVP.SetUpVector(new_up);
+  ////////////////
+  // Rotates by fixed azimuthal angle delta_theta.
+  
+  cosalpha = new_up.dot (new_vp.unit());
+  sinalpha = std::sqrt (1. - std::pow (cosalpha, 2));
+  yprime = (new_up.cross (new_vp.unit())).unit ();
+  xprime = yprime.cross (new_up);
+  // Projection of vp on plane perpendicular to up...
+  a1 = sinalpha * xprime;
+  // Required new projection...
+  a2 = sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime);
+  // Required Increment vector...
+  delta = a2 - a1;
+  // So new viewpoint is...
+  viewPoint = new_vp.unit() + delta;
+  
 #ifdef GEANT4_QT_DEBUG
-//      printf("vp Vector : %f %f %f delta_alpha:%f delta_theta:%f cosalpha:%f sinalpha:%f\n",viewPoint.x(),viewPoint.y(),viewPoint.z(),delta_alpha,delta_theta,cosalpha,sinalpha);
-//      printf("up : %f %f %f\n",up.x(),up.y(),up.z());
-//      printf("new up : %f %f %f\n",new_up.x(),new_up.y(),new_up.z());
-//      printf("vp : %f %f %f\n",vp.x(),vp.y(),vp.z());
-//      printf("new_vp : %f %f %f\n",new_vp.x(),new_vp.y(),new_vp.z());
-#endif
-    fVP.SetViewAndLights (viewPoint);
-    updateQWidget();
-    
-    if (fAutoMove)
-      ((QApplication*)G4Qt::getInstance ())->processEvents();
-  }
+  //      printf("vp Vector : %f %f %f delta_alpha:%f delta_theta:%f cosalpha:%f sinalpha:%f\n",viewPoint.x(),viewPoint.y(),viewPoint.z(),delta_alpha,delta_theta,cosalpha,sinalpha);
+  //      printf("up : %f %f %f\n",up.x(),up.y(),up.z());
+  //      printf("new up : %f %f %f\n",new_up.x(),new_up.y(),new_up.z());
+  //      printf("vp : %f %f %f\n",vp.x(),vp.y(),vp.z());
+  //      printf("new_vp : %f %f %f\n",new_vp.x(),new_vp.y(),new_vp.z());
+#endif
+  fVP.SetViewAndLights (viewPoint);
+  updateQWidget();
   
   fHoldRotateEvent = false;
+#ifdef GEANT4_QT_DEBUG
+  printf("G4OpenGLQtViewer::Rotate END\n");
+#endif
 }
 
Index: trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc
===================================================================
--- trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc	(revision 792)
+++ trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc	(revision 797)
@@ -34,5 +34,5 @@
 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER
 
-//#define GEANT4_QT_DEBUG
+#define GEANT4_QT_DEBUG
 
 #include "G4OpenGLStoredQtViewer.hh"
@@ -158,7 +158,4 @@
 
   } else {
-#ifdef GEANT4_QT_DEBUG
-    printf("***************************  CASE 1 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
-#endif
      
     // If kernel visit was needed, drawing and FinishView will already
@@ -166,5 +163,5 @@
     if (!kernelVisitWasNeeded) {
 #ifdef GEANT4_QT_DEBUG
-      printf("***************************  CASE 2 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
+      printf("**************************  G4OpenGLStoredQtViewer::DrawView Don't need kernel Visit \n");
 #endif
       DrawDisplayLists ();
@@ -172,5 +169,5 @@
     } else {
 #ifdef GEANT4_QT_DEBUG
-      printf("***************************  CASE 3 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
+      printf("**************************  G4OpenGLStoredQtViewer::DrawView need kernel Visit \n");
 #endif
       // However, union cutaways are implemented in DrawDisplayLists, so make
@@ -208,14 +205,6 @@
 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
 {
-#ifdef GEANT4_QT_DEBUG
-  printf("G4OpenGLStoredQtViewer::FinishView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
-#endif
-
   glFlush ();
   swapBuffers ();
-#ifdef GEANT4_QT_DEBUG
-  printf("G4OpenGLStoredQtViewer::FinishView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
-#endif
-
 }
 
@@ -314,5 +303,5 @@
 #endif
     setMouseTracking(true);
-    G4MousePressEvent(event->pos(),Qt::LeftButton);
+    G4MousePressEvent(event->pos());
   }
 }
@@ -338,6 +327,7 @@
 void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *event)
 {
-#ifdef GEANT4_QT_DEBUG
-  printf("G4OpenGLStoredQtViewer::mouseReleaseEvent\n");
+  G4MouseReleaseEvent();
+#ifdef GEANT4_QT_DEBUG
+  printf("G4OpenGLStoredQtViewer::mouseReleaseEvent ================\n");
 #endif
   setMouseTracking(false);
@@ -352,10 +342,4 @@
   G4MouseMoveEvent(event->x(),event->y(),event->buttons());
 #endif
-  if (hasPendingEvents ())
-#if QT_VERSION < 0x040000
-    G4MouseMoveEvent(event->x(),event->y(),event->state());
-#else
-    G4MouseMoveEvent(event->x(),event->y(),event->buttons());
-#endif
 }
 
