Index: trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc
===================================================================
--- trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc	(revision 595)
+++ trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc	(revision 599)
@@ -25,5 +25,5 @@
 //
 //
-// $Id: G4OpenGLQtViewer.cc,v 1.3 2007/11/08 17:00:51 lgarnier Exp $
+// $Id: G4OpenGLQtViewer.cc,v 1.4 2007/11/09 15:03:22 lgarnier Exp $
 // GEANT4 tag $Name:  $
 //
@@ -51,8 +51,18 @@
 #include "G4UImanager.hh"
 #include <qapplication.h>
-#include <qboxLayout.h>
+#include <qlayout.h>
 #include <qdialog.h>
+
+#if QT_VERSION >= 0x040000
 #include <qmenu.h>
 #include <qimagewriter.h>
+#else
+#include <qaction.h>
+#include <qwidgetlist.h>
+#include <qmenudata.h>
+#include <qpopupmenu.h>
+#include <qimage.h>
+#endif
+
 #include <qmessagebox.h>
 #include <qfiledialog.h>
@@ -62,6 +72,4 @@
 #include <qdialog.h>
 #include <qevent.h> //include <qcontextmenuevent.h>
-#include <qmenu.h>
-#include <qimage.h>
 
 
@@ -100,5 +108,9 @@
     G4cerr << "Visualization window not defined, please choose one before" << G4endl;
   } else {
+#if QT_VERSION < 0x040000
+    GLWindow->setActiveWindow();
+#else
     GLWindow->activateWindow();
+#endif
     printf("G4OpenGLQtViewer::ShowView -----------------------\n");
   }
@@ -145,4 +157,18 @@
     // look for the main window
     bool found = false;
+#if QT_VERSION < 0x040000
+    QWidgetList  *list = QApplication::allWidgets();
+    QWidgetListIt it( *list );         // iterate over the widgets
+    QWidget * widget;
+    while ( (widget=it.current()) != 0 ) {  // for each widget...
+      ++it;
+      if ((found== false) && (widget->inherits("QMainWindow"))) {
+        printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n");
+        GLWindow = new QDialog(widget,0,FALSE,Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WStyle_MinMax );
+        found = true;
+      }
+    }
+    delete list;                      // delete the list, not the widgets
+#else
     foreach (QWidget *widget, QApplication::allWidgets()) {
       if ((found== false) && (widget->inherits("QMainWindow"))) {
@@ -152,4 +178,6 @@
       }
     }
+#endif
+
     if (found==false) {
       printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist, but not found\n");
@@ -161,9 +189,18 @@
   }
 
+#if QT_VERSION < 0x040000
+  QHBoxLayout *mainLayout = new QHBoxLayout(GLWindow);
+#else
   QHBoxLayout *mainLayout = new QHBoxLayout;
+#endif
 
   mainLayout->addWidget(fWindow);
+
+#if QT_VERSION < 0x040000
+  GLWindow->setCaption( tr( "QGl Viewer" ));
+#else
   GLWindow->setLayout(mainLayout);
-  GLWindow->setWindowTitle("QGl Viewer");
+  GLWindow->setWindowTitle(tr("QGl Viewer"));
+#endif
   GLWindow->resize(300, 300);
   GLWindow->move(900,300);
@@ -229,13 +266,50 @@
 void G4OpenGLQtViewer::createPopupMenu()    {
 
+#if QT_VERSION < 0x040000
+  fContextMenu = new QPopupMenu( GLWindow,"All" );
+#else
   fContextMenu = new QMenu("All");
-
+#endif
+  Q_CHECK_PTR( fContextMenu );
+
+#if QT_VERSION < 0x040000
+  // === Mouse menu ===
+  QPopupMenu *mMouseAction = new QPopupMenu( fContextMenu );
+  Q_CHECK_PTR( mMouseAction );
+
+  QAction *rotate = new QAction("&Rotate scene",CTRL+Key_N,mMouseAction);
+  QAction *move =  new QAction("&Move scene",CTRL+Key_M,mMouseAction);
+  rotate->addTo(mMouseAction);
+  move->addTo(mMouseAction);
+
+  fContextMenu->insertItem( "&Mouse action", mMouseAction);
+
+#else
+  // === Mouse menu ===
   QMenu *mMouseAction = fContextMenu->addMenu("&Mouse action");
+
   QAction *rotate = mMouseAction->addAction("&Rotate scene");
   QAction *move = mMouseAction->addAction("&Move scene");
+#endif
+
   // INIT mMouse
   createRadioAction(rotate,move,SLOT(toggleMouseAction(bool)),1);
 
-  //Style Menu
+#if QT_VERSION < 0x040000
+  // === Style Menu ===
+  QPopupMenu *mStyle = new QPopupMenu(fContextMenu);
+
+  QPopupMenu *mRepresentation = new QPopupMenu(fContextMenu);
+
+  QAction *polyhedron = new QAction("&Polyhedron",CTRL+Key_P,mRepresentation);
+  QAction *nurbs = new QAction("&NURBS",CTRL+Key_N,mRepresentation);
+  polyhedron->addTo(mRepresentation);
+  nurbs->addTo(mRepresentation);
+
+  mStyle->insertItem("&Representation",mRepresentation);
+  fContextMenu->insertItem("&Style",mStyle);
+
+#else
+  // === Style Menu ===
   QMenu *mStyle = fContextMenu->addMenu("&Style");
 
@@ -243,4 +317,5 @@
   QAction *polyhedron = mRepresentation->addAction("Polyhedron");
   QAction *nurbs = mRepresentation->addAction("NURBS");
+#endif
   // INIT mStyle
   G4ViewParameters::RepStyle style;
@@ -255,23 +330,60 @@
 
 
+#if QT_VERSION < 0x040000
+  // === Drawing Menu ===
+  QPopupMenu *mDrawing = new QPopupMenu(fContextMenu);
+  fContextMenu->insertItem("&Drawing",mDrawing);
+
+  fDrawingWireframe = new QPopupMenu(mDrawing);
+  mDrawing->insertItem("&Wireframe",fDrawingWireframe);
+
+  mDrawing->setCheckable(true);
+  fDrawingWireframe->setCheckable(true);
+
+  fDrawingLineRemoval = new QPopupMenu(mDrawing);
+  mDrawing->insertItem("&Hidden line removal",fDrawingLineRemoval);
+  fDrawingLineRemoval->setCheckable(true);
+
+  fDrawingSurfaceRemoval = new QPopupMenu(mDrawing);
+  mDrawing->insertItem("&Hidden surface removal",fDrawingSurfaceRemoval);
+  fDrawingSurfaceRemoval->setCheckable(true);
+
+  fDrawingLineSurfaceRemoval = new QPopupMenu(mDrawing);
+  mDrawing->insertItem("&Hidden line and surface removal",fDrawingLineSurfaceRemoval);
+  fDrawingLineSurfaceRemoval->setCheckable(true);
+
+#else
+  // === Drawing Menu ===
   QMenu *mDrawing = mStyle->addMenu("&Drawing");
+
   fDrawingWireframe = mDrawing->addAction("Wireframe");
   fDrawingWireframe->setCheckable(true);
-  fDrawingWireframe->setChecked(true);
+
   fDrawingLineRemoval = mDrawing->addAction("Hidden line removal");
   fDrawingLineRemoval->setCheckable(true);
+
   fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal");
   fDrawingSurfaceRemoval->setCheckable(true);
+
   fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal");
   fDrawingLineSurfaceRemoval->setCheckable(true);
+#endif
   // INIT Drawing
   G4ViewParameters::DrawingStyle d_style;
   d_style = fVP.GetDrawingStyle();
   
-  fDrawingWireframe->setCheckable(true);
-  fDrawingLineRemoval->setCheckable(true);
-  fDrawingSurfaceRemoval->setCheckable(true);
-  fDrawingLineSurfaceRemoval->setCheckable(true);
-
+#if QT_VERSION < 0x040000
+  if (d_style == G4ViewParameters::wireframe) {
+    fDrawingWireframe->setItemChecked(0,true);
+  } else if (d_style == G4ViewParameters::hlr) {
+    fDrawingLineRemoval->setItemChecked(0,true);
+  } else if (d_style == G4ViewParameters::hsr) {
+    fDrawingSurfaceRemoval->setItemChecked(0,true);
+  } else if (d_style == G4ViewParameters::hlhsr) {
+    fDrawingLineSurfaceRemoval->setItemChecked(0,true);
+  } else {
+    mDrawing->clear();
+  }
+#else
   if (d_style == G4ViewParameters::wireframe) {
     fDrawingWireframe->setChecked(true);
@@ -285,4 +397,5 @@
     mDrawing->clear();
   }
+#endif
 
   QObject ::connect(fDrawingWireframe, 
@@ -304,7 +417,19 @@
 
 
+#if QT_VERSION < 0x040000
+  QPopupMenu *mBackground = new QPopupMenu(mStyle);
+  mStyle->insertItem("&Background color",mBackground);
+
+  QAction *white = new QAction("&White",CTRL+Key_W,mBackground);
+  QAction *black =  new QAction("&Black",CTRL+Key_B,mBackground);
+  white->addTo(mBackground);
+  black->addTo(mBackground);
+
+#else
   QMenu *mBackground = mStyle->addMenu("&Background color");
   QAction *white = mBackground->addAction("White");
   QAction *black = mBackground->addAction("Black");
+
+#endif
   if (background.GetRed() == 1. &&
       background.GetGreen() == 1. &&
@@ -316,9 +441,24 @@
 
 
-  // Action Menu
+#if QT_VERSION < 0x040000
+  // === Action Menu ===
+  QPopupMenu *mActions = new QPopupMenu(fContextMenu);
+  fContextMenu->insertItem("&Actions",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);
+  controlPanels->addTo(mActions);
+  exitG4->addTo(mActions);
+  createEPS->addTo(mActions);
+
+#else
+  // === Action Menu ===
   QMenu *mActions = fContextMenu->addMenu("&Actions");
   QAction *controlPanels = mActions->addAction("Control panels");
   QAction *exitG4 = mActions->addAction("Exit to G4Vis >");
   QAction *createEPS = mActions->addAction("Save as ...");
+#endif
+
   QObject ::connect(controlPanels, 
                     SIGNAL(triggered()),
@@ -335,9 +475,25 @@
 
 
-  // Special Menu
+#if QT_VERSION < 0x040000
+  // === Special Menu ===
+  QPopupMenu *mSpecial = new QPopupMenu(fContextMenu);
+  fContextMenu->insertItem("S&pecial",mSpecial);
+
+  QPopupMenu *mTransparency = new QPopupMenu(mSpecial);
+  mSpecial->insertItem("Transparency",mTransparency);
+
+  QAction *transparencyOn = new QAction("&On",CTRL+Key_O,mTransparency);
+  QAction *transparencyOff = new QAction("&Off",CTRL+Key_F,mTransparency);
+  transparencyOn->addTo(mTransparency);
+  transparencyOff->addTo(mTransparency);
+
+#else
+  // === Special Menu ===
   QMenu *mSpecial = fContextMenu->addMenu("S&pecial");
-  QMenu *transparency = mSpecial->addMenu("Transparency");
-  QAction *transparencyOn = transparency->addAction("On");
-  QAction *transparencyOff = transparency->addAction("Off");
+  QMenu *mTransparency = mSpecial->addMenu("Transparency");
+  QAction *transparencyOn = mTransparency->addAction("On");
+  QAction *transparencyOff = mTransparency->addAction("Off");
+#endif
+
   if (transparency_enabled == false) {
     createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),2);
@@ -349,7 +505,19 @@
 
 
+#if QT_VERSION < 0x040000
+  QPopupMenu *mAntialiasing = new QPopupMenu(mSpecial);
+  mSpecial->insertItem("Antialiasing",mAntialiasing);
+
+  QAction *antialiasingOn = new QAction("&On",CTRL+Key_O,mAntialiasing);
+  QAction *antialiasingOff = new QAction("&Off",CTRL+Key_F,mAntialiasing);
+  antialiasingOn->addTo(mAntialiasing);
+  antialiasingOff->addTo(mAntialiasing);
+
+#else
   QMenu *mAntialiasing = mSpecial->addMenu("Antialiasing");
   QAction *antialiasingOn = mAntialiasing->addAction("On");
   QAction *antialiasingOff = mAntialiasing->addAction("Off");
+#endif
+
   if (antialiasing_enabled == false) {
     createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),2);
@@ -360,7 +528,17 @@
   }
 
+#if QT_VERSION < 0x040000
+  QPopupMenu *mHaloing = new QPopupMenu(mSpecial);
+  mSpecial->insertItem("Haloing",mHaloing);
+
+  QAction *haloingOn = new QAction("&On",CTRL+Key_O,mHaloing);
+  QAction *haloingOff = new QAction("&Off",CTRL+Key_F,mHaloing);
+  haloingOn->addTo(mHaloing);
+  haloingOff->addTo(mHaloing);
+#else
   QMenu *mHaloing = mSpecial->addMenu("Haloing");
   QAction *haloingOn = mHaloing->addAction("On");
   QAction *haloingOff = mHaloing->addAction("Off");
+#endif
   if (haloing_enabled == false) {
     createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),2);
@@ -371,7 +549,18 @@
   }
 
+#if QT_VERSION < 0x040000
+  QPopupMenu *mAux = new QPopupMenu(mSpecial);
+  mSpecial->insertItem("Auxiliairy edges",mAux);
+
+  QAction *auxOn = new QAction("&On",CTRL+Key_O,mAux);
+  QAction *auxOff = new QAction("&Off",CTRL+Key_F,mAux);
+  auxOn->addTo(mAux);
+  auxOff->addTo(mAux);
+
+#else
   QMenu *mAux = mSpecial->addMenu("Auxiliary edges");
   QAction *auxOn = mAux->addAction("On");
   QAction *auxOff = mAux->addAction("Off");
+#endif
   if (!fVP.IsAuxEdgeVisible()) {
     createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),1);
@@ -381,7 +570,17 @@
 
 
+#if QT_VERSION < 0x040000
+  QPopupMenu *mFullScreen = new QPopupMenu(mSpecial);
+  mSpecial->insertItem("Full screen",mFullScreen);
+
+  QAction *fullOn = new QAction("&On",CTRL+Key_O,mFullScreen);
+  QAction *fullOff = new QAction("&Off",CTRL+Key_F,mFullScreen);
+  fullOn->addTo(mFullScreen);
+  fullOff->addTo(mFullScreen);
+#else
   QMenu *mFullScreen = mSpecial->addMenu("Full screen");
   QAction *fullOn = mFullScreen->addAction("On");
   QAction *fullOff = mFullScreen->addAction("Off");
+#endif
   createRadioAction(fullOn,fullOff,SLOT(toggleFullScreen(bool)),2);
 
@@ -415,4 +614,25 @@
    @param nCheck: 1 : first action will be set true. 2 : second action will be set true
 */
+#if QT_VERSION < 0x040000
+void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) {
+
+  if (action1->parent()->inherits("QPopupMenu")){
+    ((QPopupMenu*)action1->parent())->setCheckable(true);
+  }
+  ((QPopupMenu*)action1->parent())->setItemChecked(0,true);
+  ((QPopupMenu*)action1->parent())->setItemChecked(1,true);
+
+  if (nCheck ==1)
+    ((QPopupMenu*)action1->parent())->setItemChecked(0,true);
+  else
+    ((QPopupMenu*)action1->parent())->setItemChecked(1,true);
+   
+  QObject ::connect(action1, SIGNAL(triggered(bool)),action2, SLOT(toggle()));
+  QObject ::connect(action2, SIGNAL(triggered(bool)),action1, SLOT(toggle()));
+
+  QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str());
+}
+
+#else
 void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) {
 
@@ -431,4 +651,5 @@
 
 }
+#endif
 
 /**
@@ -770,5 +991,10 @@
    @param mButtons mouse button active
 */
+
+#if QT_VERSION < 0x040000
+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
 {
   int dx = pos_x - lastPos.x();
