Index: /trunk/geant4/visualization/OpenGL/GNUmakefile
===================================================================
--- /trunk/geant4/visualization/OpenGL/GNUmakefile	(revision 538)
+++ /trunk/geant4/visualization/OpenGL/GNUmakefile	(revision 539)
@@ -28,4 +28,5 @@
 CPPFLAGS += -I$(G4BASE)/intercoms/include
 CPPFLAGS += -I$(G4BASE)/interfaces/common/include
+CPPFLAGS += -I$(G4BASE)/interfaces/basic/include
 CPPFLAGS += -I$(G4BASE)/tracking/include
 CPPFLAGS += -I$(G4BASE)/digits_hits/hits/include
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateQtViewer.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateQtViewer.hh	(revision 538)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateQtViewer.hh	(revision 539)
@@ -40,4 +40,5 @@
 #include "G4OpenGLImmediateViewer.hh"
 #include "G4OpenGLQtViewer.hh"
+#include <QGLWidget>
 
 #include "globals.hh"
@@ -46,5 +47,5 @@
 
 class G4OpenGLImmediateQtViewer:
-public G4OpenGLQtViewer, public G4OpenGLImmediateViewer{
+  public G4OpenGLQtViewer, public G4OpenGLImmediateViewer, public QGLWidget {
   
 public:
@@ -54,4 +55,6 @@
   void DrawView ();
   void FinishView ();
+  void resizeGL(int width,int height);
+  void paintGL();
 };
 
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh	(revision 538)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh	(revision 539)
@@ -59,4 +59,5 @@
   void CreateGLQtContext ();
   virtual void CreateMainWindow ();
+  void CreateMainWindow (QGLWidget*);
 protected:
   G4int WinSize_x;
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateQt.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateQt.cc	(revision 538)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateQt.cc	(revision 539)
@@ -28,5 +28,5 @@
 // GEANT4 tag $Name: geant4-08-02-patch-01 $
 //
-//
+// 
 // OpenGLImmediateQt graphics system factory.
 
@@ -42,36 +42,38 @@
 
 G4OpenGLImmediateQt::G4OpenGLImmediateQt ():
-        G4VGraphicsSystem ("OpenGLImmediateQt",
-                           "OGLIQT",
-                           G4VisFeaturesOfOpenGLIQt (),
-                   G4VGraphicsSystem::threeD) {
-    G4OpenGLViewerMessenger::GetInstance();
+  G4VGraphicsSystem ("OpenGLImmediateQt",
+		     "OGLIQT",
+		     G4VisFeaturesOfOpenGLIQt (),
+		     G4VGraphicsSystem::threeD)
+{
+  G4OpenGLViewerMessenger::GetInstance();
 }
 
 G4VSceneHandler* G4OpenGLImmediateQt::CreateSceneHandler
 (const G4String& name) {
-    G4VSceneHandler* pScene = new G4OpenGLImmediateSceneHandler (*this, name);
-    return    pScene;
+  G4VSceneHandler* pScene = new G4OpenGLImmediateSceneHandler (*this, name);
+  return    pScene;
 }
 
 G4VViewer* G4OpenGLImmediateQt::CreateViewer
 (G4VSceneHandler& scene, const G4String& name) {
-    G4VViewer* pView =
-        new G4OpenGLImmediateQtViewer
-        ((G4OpenGLImmediateSceneHandler&) scene, name);
-    if (pView) {
-        if (pView -> GetViewId () < 0) {
-            G4cerr << "G4OpenGLImmediateQt::CreateViewer: error flagged by negative"
-            " view id in G4OpenGLImmediateQtViewer creation."
-            "\n Destroying view and returning null pointer."
-            << G4endl;
-            delete pView;
-            pView = 0;
-        }
-    } else {
-        G4cerr << "G4OpenGLImmediateQt::CreateViewer: null pointer on"
-        " new G4OpenGLImmediateQtViewer." << G4endl;
+  G4VViewer* pView =
+    new G4OpenGLImmediateQtViewer
+    ((G4OpenGLImmediateSceneHandler&) scene, name);
+  if (pView) {
+    if (pView -> GetViewId () < 0) {
+      G4cerr << "G4OpenGLImmediateQt::CreateViewer: error flagged by negative"
+	" view id in G4OpenGLImmediateQtViewer creation."
+	"\n Destroying view and returning null pointer."
+	   << G4endl;
+      delete pView;
+      pView = 0;
     }
-    return pView;
+  }
+  else {
+    G4cerr << "G4OpenGLImmediateQt::CreateViewer: null pointer on"
+      " new G4OpenGLImmediateQtViewer." << G4endl;
+  }
+   return pView;
 }
 
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateQtViewer.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateQtViewer.cc	(revision 538)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateQtViewer.cc	(revision 539)
@@ -28,5 +28,5 @@
 // GEANT4 tag $Name: geant4-08-02-patch-01 $
 //
-// 
+//
 // Class G4OpenGLImmediateQtViewer : a class derived from G4OpenGLQtViewer and
 //                                G4OpenGLImmediateViewer.
@@ -53,6 +53,7 @@
 // ensure a suitable window was found
 
+  printf("G4OpenGLImmediateQtViewer::Initialise () 1\n");
   CreateGLQtContext ();
-  CreateMainWindow ();
+  CreateMainWindow (this);
   CreateFontLists ();
 
@@ -71,4 +72,5 @@
 void G4OpenGLImmediateQtViewer::DrawView () {
 
+  printf("G4OpenGLImmediateQtViewer::DrawView %d %d\n",WinSize_x, WinSize_y);
   // If a double buffer context has been forced upon us, ignore the
   // back buffer for this OpenGLImmediate view.
@@ -100,4 +102,5 @@
 }
 
+
 //////////////////////////////////////////////////////////////////////////////
 void G4OpenGLImmediateQtViewer::FinishView (
@@ -106,4 +109,5 @@
 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
 {
+  printf("G4OpenGLImmediateQtViewer::FinishView \n");
   //    if(!fHDC) return;
 
@@ -118,3 +122,26 @@
 }
 
+
+void G4OpenGLImmediateQtViewer::resizeGL(
+ int width
+,int height)
+{
+  printf("G4OpenGLImmediateQtViewer::resizeGL \n");
+  int side = qMin(width, 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);
+}
+
+void G4OpenGLImmediateQtViewer::paintGL()
+ {
+  printf("G4OpenGLImmediateQtViewer::paintGL \n");
+  // FIXME
+  //  DrawView();
+  //  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+  //  glLoadIdentity();
+  //  glTranslated(0.0, 0.0, -10.0);
+ }
 #endif
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc	(revision 538)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc	(revision 539)
@@ -45,4 +45,9 @@
 #include "G4Normal3D.hh"
 
+#include "G4Qt.hh"
+#include "G4UIManager.hh"
+#include <QtGui/qboxlayout.h>
+#include <QtGui/qdialog.h>
+#include <QtGui/qpushbutton.h>
 
 //////////////////////////////////////////////////////////////////////////////
@@ -131,10 +136,35 @@
 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
 {
-  printf("G4OpenGLQtViewer::CreateMainWindow \n");
 
   if(fWindow) return; //Done.
+  printf("G4OpenGLQtViewer::CreateMainWindow 2\n");
+
+  // launch Qt if not
+  G4Qt* interactorManager = G4Qt::getInstance ();
+  //  G4UImanager* UI = G4UImanager::GetUIpointer();
+  printf("G4OpenGLQtViewer::CreateMainWindow 3\n");
+
+  QPushButton hello("Hello world!");
+  hello.resize(100, 30);
+  hello.show();
 
   fWindow = new QGLWidget() ;
   fWindow->makeCurrent();
+
+  // create window
+  QDialog* GLWindow ;
+  if (qApp) {
+    GLWindow = new QDialog();//qApp->mainWidget());
+  } else {
+    GLWindow = new QDialog();
+  }
+
+  QHBoxLayout *mainLayout = new QHBoxLayout;
+  mainLayout->addWidget(fWindow);
+  GLWindow->setLayout(mainLayout);
+  GLWindow->setWindowTitle("QGl Viewer");
+  GLWindow->resize(100, 30);
+  GLWindow->show();
+
 
 //   // Bill Gates stuff...
@@ -157,10 +187,10 @@
 //   }  
   
-//   WinSize_x = 400;
-//   WinSize_y = 400;
-//   if (WinSize_x < fVP.GetWindowSizeHintX ())
-//     WinSize_x = fVP.GetWindowSizeHintX ();
-//   if (WinSize_y < fVP.GetWindowSizeHintY ())
-//     WinSize_y = fVP.GetWindowSizeHintY ();
+   WinSize_x = 400;
+   WinSize_y = 400;
+   if (WinSize_x < fVP.GetWindowSizeHintX ())
+     WinSize_x = fVP.GetWindowSizeHintX ();
+   if (WinSize_y < fVP.GetWindowSizeHintY ())
+     WinSize_y = fVP.GetWindowSizeHintY ();
 
 //   fWindow = ::CreateWindow(className,fName.c_str(), 
@@ -193,4 +223,93 @@
 
 //////////////////////////////////////////////////////////////////////////////
+void G4OpenGLQtViewer::CreateMainWindow (
+QGLWidget* glWidget
+) 
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+
+  if(fWindow) return; //Done.
+  printf("G4OpenGLQtViewer::CreateMainWindow glWidget\n");
+
+  // launch Qt if not
+  G4Qt* interactorManager = G4Qt::getInstance ();
+  //  G4UImanager* UI = G4UImanager::GetUIpointer();
+  printf("G4OpenGLQtViewer::CreateMainWindow 3\n");
+
+  fWindow = glWidget ;
+  fWindow->makeCurrent();
+
+  // create window
+  QDialog* GLWindow ;
+  if (qApp) {
+    GLWindow = new QDialog();//qApp->mainWidget());
+  } else {
+    GLWindow = new QDialog();
+  }
+
+  QHBoxLayout *mainLayout = new QHBoxLayout;
+  mainLayout->addWidget(fWindow);
+  GLWindow->setLayout(mainLayout);
+  GLWindow->setWindowTitle("QGl Viewer");
+  GLWindow->resize(300, 300);
+  GLWindow->show();
+
+
+//   // Bill Gates stuff...
+//   static const char className[] = "G4OpenGLQt";
+//   static bool done = false;
+//   if(done==false) {
+//     WNDCLASS wc;
+//     wc.style = CS_HREDRAW | CS_VREDRAW;
+//     wc.lpfnWndProc = (WNDPROC)WindowProc;
+//     wc.cbClsExtra = 0;
+//     wc.cbWndExtra = 0;
+//     wc.hInstance = ::GetModuleHandle(NULL);
+//     wc.hIcon = LoadIcon  (NULL, IDI_APPLICATION);
+//     wc.hCursor = LoadCursor(NULL,IDC_CROSS);
+//     wc.hbrBackground = NULL;
+//     wc.lpszMenuName = className;
+//     wc.lpszClassName = className;
+//     ::RegisterClass(&wc);
+//     done = true;
+//   }  
+  
+   WinSize_x = 400;
+   WinSize_y = 400;
+   if (WinSize_x < fVP.GetWindowSizeHintX ())
+     WinSize_x = fVP.GetWindowSizeHintX ();
+   if (WinSize_y < fVP.GetWindowSizeHintY ())
+     WinSize_y = fVP.GetWindowSizeHintY ();
+
+//   fWindow = ::CreateWindow(className,fName.c_str(), 
+// 			   WS_OVERLAPPEDWINDOW,
+// 			   //WS_CHILD | WS_VISIBLE,
+// 			   0,0,
+// 			   WinSize_x,WinSize_y,
+// 			   NULL, NULL, 
+// 			   ::GetModuleHandle(NULL),
+// 			   NULL);
+//   if(!fWindow) return;
+
+//   ::SetWindowLong(fWindow,GWL_USERDATA,LONG(this));
+
+//   // initialize OpenGL rendering :
+//   fHDC = ::GetDC(fWindow);
+//   if( fHDC && (SetWindowPixelFormat(fHDC)==TRUE) ) {
+//     fHGLRC = ::wglCreateContext(fHDC);
+//   }
+  
+//   if(fHDC && fHGLRC) {
+//     ::wglMakeCurrent(fHDC,fHGLRC);
+//   }
+
+//   ::SetForegroundWindow(fWindow);
+//   ::ShowWindow(fWindow,SW_SHOWDEFAULT);
+//   ::UpdateWindow(fWindow);
+//   ::DrawMenuBar(fWindow);
+}
+
+//////////////////////////////////////////////////////////////////////////////
 G4OpenGLQtViewer::G4OpenGLQtViewer (
  G4OpenGLSceneHandler& scene
@@ -198,5 +317,5 @@
 :G4VViewer (scene, -1)
 ,G4OpenGLViewer (scene)
-                                   //,fWindow(0)
+,fWindow(0)
                                    //,fHDC(0)
                                    //,fHGLRC(0)
