source: trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc @ 711

Last change on this file since 711 was 711, checked in by garnier, 16 years ago

debut de recherche du decalage de deplacement

  • Property svn:mime-type set to text/cpp
File size: 57.4 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26//
27// $Id: G4OpenGLQtViewer.cc,v 1.10 2008/01/30 10:54:13 lgarnier Exp $
28// GEANT4 tag $Name:  $
29//
30//
31// G4OpenGLQtViewer : Class to provide Qt specific
32//                     functionality for OpenGL in GEANT4
33//
34// 27/06/2003 : G.Barrand : implementation (at last !).
35
36#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
37
38#define GEANT4_QT_DEBUG
39
40#include "G4OpenGLQtViewer.hh"
41
42#include "G4ios.hh"
43#include "G4VisExtent.hh"
44#include "G4LogicalVolume.hh"
45#include "G4VSolid.hh"
46#include "G4Point3D.hh"
47#include "G4Normal3D.hh"
48#include "G4Scene.hh"
49#include "G4OpenGLQtExportDialog.hh"
50#include "G4UnitsTable.hh"
51#include "G4Qt.hh"
52#include "G4UImanager.hh"
53#include "G4UIcommandTree.hh"
54#include <qapplication.h>
55#include <qlayout.h>
56#include <qdialog.h>
57
58#if QT_VERSION >= 0x040000
59#include <qmenu.h>
60#include <qimagewriter.h>
61#else
62#include <qaction.h>
63#include <qwidgetlist.h>
64#include <qpopupmenu.h>
65#include <qimage.h>
66#endif
67
68#include <qmessagebox.h>
69#include <qfiledialog.h>
70#include <qprinter.h>
71#include <qpainter.h>
72#include <qgl.h> // include <qglwidget.h>
73#include <qdialog.h>
74#include <qevent.h> //include <qcontextmenuevent.h>
75
76
77//////////////////////////////////////////////////////////////////////////////
78/**
79   Implementation of virtual method of G4VViewer
80*/
81void G4OpenGLQtViewer::SetView (
82)
83//////////////////////////////////////////////////////////////////////////////
84//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
85{
86#ifdef GEANT4_QT_DEBUG
87  printf("G4OpenGLQtViewer::SetView ++++++++++++++++++++\n");
88#endif
89  //   if(!fHDC) return;
90  //   if(!fHGLRC) return;
91  //   ::wglMakeCurrent(fHDC,fHGLRC);
92  //  fWindow->makeCurrent();
93  G4OpenGLViewer::SetView ();
94#ifdef GEANT4_QT_DEBUG
95  printf("G4OpenGLQtViewer::SetView --------------------\n");
96#endif
97}
98
99/**
100 * Set the viewport of the scene
101 */
102void G4OpenGLQtViewer::setupViewport(int aWidth, int aHeight)
103{
104  int side = aWidth;
105  if (aHeight < aWidth) side = aHeight;
106  glViewport((aWidth - side) / 2, (aHeight - side) / 2, side, side);
107 
108  glMatrixMode(GL_PROJECTION);
109  glLoadIdentity();
110  glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
111  glMatrixMode(GL_MODELVIEW);
112}
113
114
115//////////////////////////////////////////////////////////////////////////////
116/**
117   Implementation of virtual method of G4VViewer
118*/
119void G4OpenGLQtViewer::ShowView (
120)
121//////////////////////////////////////////////////////////////////////////////
122//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
123{
124#ifdef GEANT4_QT_DEBUG
125  printf("G4OpenGLQtViewer::ShowView  +++++++++++++++++++++\n");
126#endif
127  if (!GLWindow) {
128    G4cerr << "Visualization window not defined, please choose one before\n" << G4endl;
129  } else {
130#if QT_VERSION < 0x040000
131    GLWindow->setActiveWindow();
132#else
133    GLWindow->activateWindow();
134#endif
135#ifdef GEANT4_QT_DEBUG
136    printf("G4OpenGLQtViewer::ShowView -----------------------\n");
137#endif
138  }
139  glFlush ();
140  //   // Empty the Windows message queue :
141  //   MSG event;
142  //   while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
143  //     ::TranslateMessage(&event);
144  //     ::DispatchMessage (&event);
145  //   }
146}
147
148
149
150//////////////////////////////////////////////////////////////////////////////
151void G4OpenGLQtViewer::CreateGLQtContext (
152)
153//////////////////////////////////////////////////////////////////////////////
154//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
155{
156#ifdef GEANT4_QT_DEBUG
157  printf("G4OpenGLQtViewer::CreateGLQtContext \n");
158#endif
159}
160
161
162//////////////////////////////////////////////////////////////////////////////
163void G4OpenGLQtViewer::CreateMainWindow (
164 QGLWidget* glWidget
165)
166//////////////////////////////////////////////////////////////////////////////
167//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
168{
169
170  if(fWindow) return; //Done.
171#ifdef GEANT4_QT_DEBUG
172  printf("G4OpenGLQtViewer::CreateMainWindow glWidget\n");
173#endif
174
175  // launch Qt if not
176  G4Qt* interactorManager = G4Qt::getInstance ();
177  //  G4UImanager* UI = G4UImanager::GetUIpointer();
178
179  fWindow = glWidget ;
180  //  fWindow->makeCurrent();
181
182  // create window
183  if (((QApplication*)interactorManager->GetMainInteractor())) {
184    // look for the main window
185    bool found = false;
186#if QT_VERSION < 0x040000
187    // theses lines does nothing exept this one "GLWindow = new QDialog(0..."
188    // but if I comment them, it doesn't work...
189    QWidgetList  *list = QApplication::allWidgets();
190    QWidgetListIt it( *list );         // iterate over the widgets
191    QWidget * widget;
192    while ( (widget=it.current()) != 0 ) {  // for each widget...
193      ++it;
194      if ((found== false) && (widget->inherits("QMainWindow"))) {
195        GLWindow = new QDialog(0,0,FALSE,Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WStyle_MinMax );
196        found = true;
197      }
198    }
199    delete list;                      // delete the list, not the widgets
200#else
201    foreach (QWidget *widget, QApplication::allWidgets()) {
202      if ((found== false) && (widget->inherits("QMainWindow"))) {
203        GLWindow = new QDialog(0,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
204        found = true;
205      }
206    }
207#endif
208
209#if QT_VERSION < 0x040000
210    glWidget->reparent(GLWindow,0,QPoint(0,0)); 
211#else
212    glWidget->setParent(GLWindow); 
213#endif
214
215    if (found==false) {
216#ifdef GEANT4_QT_DEBUG
217      printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist, but not found\n");
218#endif
219      GLWindow = new QDialog();
220    }
221  } else {
222#ifdef GEANT4_QT_DEBUG
223    printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n");
224#endif
225    GLWindow = new QDialog();
226  }
227
228  QHBoxLayout *mainLayout = new QHBoxLayout(GLWindow);
229
230  mainLayout->addWidget(fWindow);
231
232#if QT_VERSION < 0x040000
233  GLWindow->setCaption( tr( "QGl Viewer" ));
234#else
235  GLWindow->setLayout(mainLayout);
236  GLWindow->setWindowTitle(tr("QGl Viewer"));
237#endif
238  GLWindow->resize(300, 300);
239  GLWindow->move(900,300);
240  GLWindow->show();
241 
242  // delete the pointer if close this
243  //  GLWindow->setAttribute(Qt::WA_DeleteOnClose);
244
245#if QT_VERSION >= 0x040000
246//   QObject ::connect(GLWindow,
247//                     SIGNAL(rejected()),
248//                     this,
249//                     SLOT(dialogClosed()));
250#endif
251
252  WinSize_x = 400;
253  WinSize_y = 400;
254  if (WinSize_x < fVP.GetWindowSizeHintX ())
255    WinSize_x = fVP.GetWindowSizeHintX ();
256  if (WinSize_y < fVP.GetWindowSizeHintY ())
257    WinSize_y = fVP.GetWindowSizeHintY ();
258
259  if(!fWindow) return;
260#ifdef GEANT4_QT_DEBUG
261  printf("G4OpenGLQtViewer::CreateMainWindow glWidget END\n");
262#endif
263
264  if (!fContextMenu)
265    createPopupMenu();
266
267}
268
269#if QT_VERSION >= 0x040000
270/**  Close the dialog and set the pointer to NULL
271 */
272// void G4OpenGLQtViewer::dialogClosed() {
273// #ifdef GEANT4_QT_DEBUG
274//   printf("G4OpenGLQtViewer::dialogClosed END\n");
275// #endif
276//   //  GLWindow = NULL;
277// }
278#endif
279
280//////////////////////////////////////////////////////////////////////////////
281G4OpenGLQtViewer::G4OpenGLQtViewer (
282                                    G4OpenGLSceneHandler& scene
283                                    )
284  :G4VViewer (scene, -1)
285  ,G4OpenGLViewer (scene)
286  ,fWindow(0)
287  ,fContextMenu(0)
288  ,fMouseAction(STYLE1)
289  ,fDeltaSceneTranslation(1/100)
290  ,fDeltaZoom(1.1)
291  ,holdKeyEvent(false)
292{
293#ifdef GEANT4_QT_DEBUG
294  printf("G4OpenGLQtViewer::G4OpenGLQtViewer \n");
295#endif
296}
297
298//////////////////////////////////////////////////////////////////////////////
299G4OpenGLQtViewer::~G4OpenGLQtViewer (
300)
301//////////////////////////////////////////////////////////////////////////////
302//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
303{
304#ifdef GEANT4_QT_DEBUG
305  printf("G4OpenGLQtViewer::~G4OpenGLQtViewer \n");
306#endif
307}
308
309
310/**
311   Create a popup menu for the widget. This menu is activated by right-mouse click
312*/
313void G4OpenGLQtViewer::createPopupMenu()    {
314
315#if QT_VERSION < 0x040000
316  fContextMenu = new QPopupMenu( GLWindow,"All" );
317#else
318  fContextMenu = new QMenu("All");
319#endif
320
321#if QT_VERSION < 0x040000
322  QPopupMenu *mMouseAction = new QPopupMenu( fContextMenu );
323  fContextMenu->insertItem("&Mouse actions");
324#else
325  QMenu *mMouseAction = fContextMenu->addMenu("&Mouse actions");
326#endif
327
328#if QT_VERSION < 0x040000
329  // === Mouse menu ===
330
331  fMouseRotate = new QPopupMenu(mMouseAction);
332  mMouseAction->insertItem("&Rotate",fMouseRotate);
333
334  mMouseAction->setCheckable(true);
335  fMouseRotate->setCheckable(true);
336
337  fMousePick = new QPopupMenu(mMouseAction);
338  mMouseAction->insertItem("&Pick",fMousePick);
339  fMousePick->setCheckable(true);
340
341  fMouseShortcuts = new QPopupMenu(mMouseAction);
342  mMouseAction->insertItem("&Show Shortcuts",fMouseShortcuts);
343  fMouseShortcuts->setCheckable(true);
344
345#else
346  // === Mouse menu ===
347
348  fMouseRotate = mMouseAction->addAction("Rotate");
349  fMouseRotate->setCheckable(true);
350
351  fMousePick = mMouseAction->addAction("Pick");
352  fMousePick->setCheckable(true);
353
354  fMouseShortcuts = mMouseAction->addAction("Show Shortcuts");
355  fMouseShortcuts->setCheckable(true);
356#endif
357
358  // INIT mMouse
359#if QT_VERSION < 0x040000
360  fMouseRotate->setItemChecked(0,true);
361
362  QObject ::connect(fMouseRotate,
363                    SIGNAL(activated(int)),
364                    this,
365                    SLOT(actionMouseRotate()));
366
367  QObject ::connect(fMousePick,
368                    SIGNAL(activated(int)),
369                    this,
370                    SLOT(actionMousePick()));
371
372  QObject ::connect(fMouseShortcuts,
373                    SIGNAL(activated(int)),
374                    this,
375                    SLOT(actionMouseShortcuts()));
376
377#else
378  fMouseRotate->setChecked(true);
379
380  QObject ::connect(fMouseRotate,
381                    SIGNAL(triggered(bool)),
382                    this,
383                    SLOT(actionMouseRotate()));
384
385  QObject ::connect(fMousePick,
386                    SIGNAL(triggered(bool)),
387                    this,
388                    SLOT(actionMousePick()));
389
390  QObject ::connect(fMouseShortcuts,
391                    SIGNAL(triggered(bool)),
392                    this,
393                    SLOT(actionMouseShortcuts()));
394#endif
395
396#if QT_VERSION < 0x040000
397  // === Style Menu ===
398  QPopupMenu *mStyle = new QPopupMenu(fContextMenu);
399
400  QPopupMenu *mRepresentation = new QPopupMenu(fContextMenu);
401
402  QPopupMenu *mProjection = new QPopupMenu(fContextMenu);
403
404#if QT_VERSION < 0x030200
405  QAction *polyhedron = new QAction("&Polyhedron","&Polyhedron",CTRL+Key_P,mRepresentation);
406  QAction *nurbs = new QAction("&NURBS","&NURBS",CTRL+Key_N,mRepresentation);
407
408  QAction *ortho = new QAction("&Orthographic","&Orthographic",CTRL+Key_O,mProjection);
409  QAction *perspective = new QAction("&Perspective","&Perspective",CTRL+Key_P,mProjection);
410#else
411  QAction *polyhedron = new QAction("&Polyhedron",CTRL+Key_P,mRepresentation);
412  QAction *nurbs = new QAction("&NURBS",CTRL+Key_N,mRepresentation);
413
414  QAction *ortho = new QAction("&Orthographic",CTRL+Key_O,mProjection);
415  QAction *perspective = new QAction("&Perspective",CTRL+Key_P,mProjection);
416#endif
417  polyhedron->addTo(mRepresentation);
418  nurbs->addTo(mRepresentation);
419
420  ortho->addTo(mProjection);
421  perspective->addTo(mProjection);
422
423  mStyle->insertItem("&Representation",mRepresentation);
424  mStyle->insertItem("&Projection",mProjection);
425  fContextMenu->insertItem("&Style",mStyle);
426
427
428#else
429  // === Style Menu ===
430  QMenu *mStyle = fContextMenu->addMenu("&Style");
431
432  QMenu *mRepresentation = mStyle->addMenu("&Representation");
433  QMenu *mProjection = mStyle->addMenu("&Projection");
434  QAction *polyhedron = mRepresentation->addAction("Polyhedron");
435  QAction *nurbs = mRepresentation->addAction("NURBS");
436
437  QAction *ortho = mProjection->addAction("Orthographic");
438  QAction *perspective = mProjection->addAction("Persepective");
439#endif
440
441  // INIT mRepresentation
442  G4ViewParameters::RepStyle style;
443  style = fVP.GetRepStyle();
444  if (style == G4ViewParameters::polyhedron) {
445    createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),1);
446  } else if (style == G4ViewParameters::nurbs) {
447    createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),2);
448  } else {
449    mRepresentation->clear();
450  }
451
452  // INIT mProjection
453  if (fVP.GetFieldHalfAngle() == 0) {
454    createRadioAction(ortho, perspective,SLOT(toggleProjection(bool)),1);
455  } else {
456    createRadioAction(ortho, perspective,SLOT(toggleProjection(bool)),2);
457  }
458
459#if QT_VERSION < 0x040000
460  // === Drawing Menu ===
461  QPopupMenu *mDrawing = new QPopupMenu(fContextMenu);
462  fContextMenu->insertItem("&Drawing",mDrawing);
463
464  fDrawingWireframe = new QPopupMenu(mDrawing);
465  mDrawing->insertItem("&Wireframe",fDrawingWireframe);
466
467  mDrawing->setCheckable(true);
468  fDrawingWireframe->setCheckable(true);
469
470  fDrawingLineRemoval = new QPopupMenu(mDrawing);
471  mDrawing->insertItem("&Hidden line removal",fDrawingLineRemoval);
472  fDrawingLineRemoval->setCheckable(true);
473
474  fDrawingSurfaceRemoval = new QPopupMenu(mDrawing);
475  mDrawing->insertItem("&Hidden surface removal",fDrawingSurfaceRemoval);
476  fDrawingSurfaceRemoval->setCheckable(true);
477
478  fDrawingLineSurfaceRemoval = new QPopupMenu(mDrawing);
479  mDrawing->insertItem("&Hidden line and surface removal",fDrawingLineSurfaceRemoval);
480  fDrawingLineSurfaceRemoval->setCheckable(true);
481
482#else
483  // === Drawing Menu ===
484  QMenu *mDrawing = mStyle->addMenu("&Drawing");
485
486  fDrawingWireframe = mDrawing->addAction("Wireframe");
487  fDrawingWireframe->setCheckable(true);
488
489  fDrawingLineRemoval = mDrawing->addAction("Hidden line removal");
490  fDrawingLineRemoval->setCheckable(true);
491
492  fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal");
493  fDrawingSurfaceRemoval->setCheckable(true);
494
495  fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal");
496  fDrawingLineSurfaceRemoval->setCheckable(true);
497#endif
498  // INIT Drawing
499  G4ViewParameters::DrawingStyle d_style;
500  d_style = fVP.GetDrawingStyle();
501 
502#if QT_VERSION < 0x040000
503  if (d_style == G4ViewParameters::wireframe) {
504    fDrawingWireframe->setItemChecked(0,true);
505  } else if (d_style == G4ViewParameters::hlr) {
506    fDrawingLineRemoval->setItemChecked(0,true);
507  } else if (d_style == G4ViewParameters::hsr) {
508    fDrawingSurfaceRemoval->setItemChecked(0,true);
509  } else if (d_style == G4ViewParameters::hlhsr) {
510    fDrawingLineSurfaceRemoval->setItemChecked(0,true);
511  } else {
512    mDrawing->clear();
513  }
514#ifdef GEANT4_QT_DEBUG
515  printf("G4OpenGLQtViewer:: fDrawingWireframe 1\n");
516#endif
517  QObject ::connect(fDrawingWireframe,
518                    SIGNAL(activated(int)),
519                    this,
520                    SLOT(actionDrawingWireframe()));
521#ifdef GEANT4_QT_DEBUG
522  printf("G4OpenGLQtViewer:: fDrawingWireframe 2\n");
523#endif
524  QObject ::connect(fDrawingLineRemoval,
525                    SIGNAL(activated(int)),
526                    this,
527                    SLOT(actionDrawingLineRemoval()));
528  QObject ::connect(fDrawingSurfaceRemoval,
529                    SIGNAL(activated(int)),
530                    this,
531                    SLOT(actionDrawingSurfaceRemoval()));
532  QObject ::connect(fDrawingLineSurfaceRemoval,
533                    SIGNAL(activated(int)),
534                    this,
535                    SLOT(actionDrawingLineSurfaceRemoval()));
536#else
537  if (d_style == G4ViewParameters::wireframe) {
538    fDrawingWireframe->setChecked(true);
539  } else if (d_style == G4ViewParameters::hlr) {
540    fDrawingLineRemoval->setChecked(true);
541  } else if (d_style == G4ViewParameters::hsr) {
542    fDrawingSurfaceRemoval->setChecked(true);
543  } else if (d_style == G4ViewParameters::hlhsr) {
544    fDrawingLineSurfaceRemoval->setChecked(true);
545  } else {
546    mDrawing->clear();
547  }
548  QObject ::connect(fDrawingWireframe,
549                    SIGNAL(triggered(bool)),
550                    this,
551                    SLOT(actionDrawingWireframe()));
552  QObject ::connect(fDrawingLineRemoval,
553                    SIGNAL(triggered(bool)),
554                    this,
555                    SLOT(actionDrawingLineRemoval()));
556  QObject ::connect(fDrawingSurfaceRemoval,
557                    SIGNAL(triggered(bool)),
558                    this,
559                    SLOT(actionDrawingSurfaceRemoval()));
560  QObject ::connect(fDrawingLineSurfaceRemoval,
561                    SIGNAL(triggered(bool)),
562                    this,
563                    SLOT(actionDrawingLineSurfaceRemoval()));
564#endif
565
566
567
568#if QT_VERSION < 0x040000
569  QPopupMenu *mBackground = new QPopupMenu(mStyle);
570  mStyle->insertItem("&Background color",mBackground);
571
572#if QT_VERSION < 0x030200
573  QAction *white = new QAction("&White","&White",CTRL+Key_W,mBackground);
574  QAction *black =  new QAction("&Black","&Black",CTRL+Key_B,mBackground);
575#else
576  QAction *white = new QAction("&White",CTRL+Key_W,mBackground);
577  QAction *black =  new QAction("&Black",CTRL+Key_B,mBackground);
578#endif
579  white->addTo(mBackground);
580  black->addTo(mBackground);
581
582#else
583  QMenu *mBackground = mStyle->addMenu("&Background color");
584  QAction *white = mBackground->addAction("White");
585  QAction *black = mBackground->addAction("Black");
586
587#endif
588  if (background.GetRed() == 1. &&
589      background.GetGreen() == 1. &&
590      background.GetBlue() == 1.) {
591    createRadioAction(white,black,SLOT(toggleBackground(bool)),1);
592  } else {
593    createRadioAction(white,black,SLOT(toggleBackground(bool)),2);
594  }
595
596
597#if QT_VERSION < 0x040000
598  // === Action Menu ===
599  QPopupMenu *mActions = new QPopupMenu(fContextMenu);
600  fContextMenu->insertItem("&Actions",mActions);
601
602#if QT_VERSION < 0x030200
603  QAction *createEPS =  new QAction("&Save as ...","&Save as ...",CTRL+Key_S,mActions);
604#else
605  QAction *createEPS =  new QAction("&Save as ...",CTRL+Key_S,mActions);
606#endif
607  createEPS->addTo(mActions);
608  QObject ::connect(createEPS,
609                    SIGNAL(activated()),
610                    this,
611                    SLOT(actionCreateEPS()));
612
613#else
614  // === Action Menu ===
615  QMenu *mActions = fContextMenu->addMenu("&Actions");
616  QAction *createEPS = mActions->addAction("Save as ...");
617  QObject ::connect(createEPS,
618                    SIGNAL(triggered()),
619                    this,
620                    SLOT(actionCreateEPS()));
621#endif
622
623
624
625#if QT_VERSION < 0x040000
626  // === Special Menu ===
627  QPopupMenu *mSpecial = new QPopupMenu(fContextMenu);
628  fContextMenu->insertItem("S&pecial",mSpecial);
629
630  QPopupMenu *mTransparency = new QPopupMenu(mSpecial);
631  mSpecial->insertItem("Transparency",mTransparency);
632
633#if QT_VERSION < 0x030200
634  QAction *transparencyOn = new QAction("&On","&On",CTRL+Key_O,mTransparency);
635  QAction *transparencyOff = new QAction("&Off","&Off",CTRL+Key_F,mTransparency);
636#else
637  QAction *transparencyOn = new QAction("&On",CTRL+Key_O,mTransparency);
638  QAction *transparencyOff = new QAction("&Off",CTRL+Key_F,mTransparency);
639#endif
640  transparencyOn->addTo(mTransparency);
641  transparencyOff->addTo(mTransparency);
642
643#else
644  // === Special Menu ===
645  QMenu *mSpecial = fContextMenu->addMenu("S&pecial");
646  QMenu *mTransparency = mSpecial->addMenu("Transparency");
647  QAction *transparencyOn = mTransparency->addAction("On");
648  QAction *transparencyOff = mTransparency->addAction("Off");
649#endif
650
651  if (transparency_enabled == false) {
652    createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),2);
653  } else if (transparency_enabled == true) {
654    createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),1);
655  } else {
656    mSpecial->clear();
657  }
658
659
660#if QT_VERSION < 0x040000
661  QPopupMenu *mAntialiasing = new QPopupMenu(mSpecial);
662  mSpecial->insertItem("Antialiasing",mAntialiasing);
663
664#if QT_VERSION < 0x030200
665  QAction *antialiasingOn = new QAction("&On","&On",CTRL+Key_O,mAntialiasing);
666  QAction *antialiasingOff = new QAction("&Off","&Off",CTRL+Key_F,mAntialiasing);
667#else
668  QAction *antialiasingOn = new QAction("&On",CTRL+Key_O,mAntialiasing);
669  QAction *antialiasingOff = new QAction("&Off",CTRL+Key_F,mAntialiasing);
670#endif
671  antialiasingOn->addTo(mAntialiasing);
672  antialiasingOff->addTo(mAntialiasing);
673
674#else
675  QMenu *mAntialiasing = mSpecial->addMenu("Antialiasing");
676  QAction *antialiasingOn = mAntialiasing->addAction("On");
677  QAction *antialiasingOff = mAntialiasing->addAction("Off");
678#endif
679
680  if (antialiasing_enabled == false) {
681    createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),2);
682  } else if (antialiasing_enabled == true) {
683    createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),1);
684  } else {
685    mAntialiasing->clear();
686  }
687
688#if QT_VERSION < 0x040000
689  QPopupMenu *mHaloing = new QPopupMenu(mSpecial);
690  mSpecial->insertItem("Haloing",mHaloing);
691
692#if QT_VERSION < 0x030200
693  QAction *haloingOn = new QAction("&On","&On",CTRL+Key_O,mHaloing);
694  QAction *haloingOff = new QAction("&Off","&Off",CTRL+Key_F,mHaloing);
695#else
696  QAction *haloingOn = new QAction("&On",CTRL+Key_O,mHaloing);
697  QAction *haloingOff = new QAction("&Off",CTRL+Key_F,mHaloing);
698#endif
699  haloingOn->addTo(mHaloing);
700  haloingOff->addTo(mHaloing);
701#else
702  QMenu *mHaloing = mSpecial->addMenu("Haloing");
703  QAction *haloingOn = mHaloing->addAction("On");
704  QAction *haloingOff = mHaloing->addAction("Off");
705#endif
706  if (haloing_enabled == false) {
707    createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),2);
708  } else if (haloing_enabled == true) {
709    createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),1);
710  } else {
711    mHaloing->clear();
712  }
713
714#if QT_VERSION < 0x040000
715  QPopupMenu *mAux = new QPopupMenu(mSpecial);
716  mSpecial->insertItem("Auxiliairy edges",mAux);
717
718#if QT_VERSION < 0x030200
719  QAction *auxOn = new QAction("&On","&On",CTRL+Key_O,mAux);
720  QAction *auxOff = new QAction("&Off","&Off",CTRL+Key_F,mAux);
721#else
722  QAction *auxOn = new QAction("&On",CTRL+Key_O,mAux);
723  QAction *auxOff = new QAction("&Off",CTRL+Key_F,mAux);
724#endif
725  auxOn->addTo(mAux);
726  auxOff->addTo(mAux);
727
728#else
729  QMenu *mAux = mSpecial->addMenu("Auxiliary edges");
730  QAction *auxOn = mAux->addAction("On");
731  QAction *auxOff = mAux->addAction("Off");
732#endif
733  if (!fVP.IsAuxEdgeVisible()) {
734    createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),1);
735  } else {
736    createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),2);
737  }
738
739
740#if QT_VERSION >= 0x030200
741#if QT_VERSION < 0x040000
742  QPopupMenu *mFullScreen = new QPopupMenu(mSpecial);
743  mSpecial->insertItem("Full screen",mFullScreen);
744
745  QAction *fullOn = new QAction("&On",CTRL+Key_O,mFullScreen);
746  QAction *fullOff = new QAction("&Off",CTRL+Key_F,mFullScreen);
747  fullOn->addTo(mFullScreen);
748  fullOff->addTo(mFullScreen);
749#else
750  QMenu *mFullScreen = mSpecial->addMenu("Full screen");
751  QAction *fullOn = mFullScreen->addAction("On");
752  QAction *fullOff = mFullScreen->addAction("Off");
753#endif
754  createRadioAction(fullOn,fullOff,SLOT(toggleFullScreen()),2);
755#endif
756
757}
758
759void G4OpenGLQtViewer::manageContextMenuEvent(QContextMenuEvent *e)
760{
761  if (!GLWindow) {
762    G4cerr << "Visualization window not defined, please choose one before\n" << G4endl;
763  } else {
764 
765    if (!fContextMenu)
766      createPopupMenu();
767   
768    // launch menu
769    if ( fContextMenu ) {
770      fContextMenu->exec( e->globalPos() );
771      //    delete fContextMenu;
772    }
773  }
774  e->accept();
775}
776
777
778/**
779   Create a radio button menu. The two menu will be connected. When click on one,
780   eatch state will be invert and callback method will be called.
781   @param action1 first action to connect
782   @param action2 second action to connect
783   @param method callback method
784   @param nCheck: 1 : first action will be set true. 2 : second action will be set true
785*/
786#if QT_VERSION < 0x040000
787void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) {
788
789  if (action1->parent()->inherits("QPopupMenu")){
790    ((QPopupMenu*)action1->parent())->setCheckable(true);
791  }
792  ((QPopupMenu*)action1->parent())->setItemChecked(0,true);
793  ((QPopupMenu*)action1->parent())->setItemChecked(1,true);
794
795  if (nCheck ==1)
796    ((QPopupMenu*)action1->parent())->setItemChecked(0,true);
797  else
798    ((QPopupMenu*)action1->parent())->setItemChecked(1,true);
799   
800  //FIXME : Should not work on Qt3
801  QObject ::connect(action1, SIGNAL(activated()),action2, SLOT(toggle()));
802  QObject ::connect(action2, SIGNAL(activated()),action1, SLOT(toggle()));
803
804  QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str());
805}
806
807#else
808void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) {
809
810  action1->setCheckable(true);
811  action2->setCheckable(true);
812
813  if (nCheck ==1)
814    action1->setChecked (true);
815  else
816    action2->setChecked (true);
817   
818  QObject ::connect(action1, SIGNAL(triggered(bool)),action2, SLOT(toggle()));
819  QObject ::connect(action2, SIGNAL(triggered(bool)),action1, SLOT(toggle()));
820
821  QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str());
822
823}
824#endif
825
826/**
827   Slot activate when mouseAction->rotate menu is set
828 */
829void G4OpenGLQtViewer::actionMouseRotate() {
830  emit toggleMouseAction(STYLE1);
831}
832
833
834/**
835   Slot activate when mouseAction->zoom menu is set
836 */
837void G4OpenGLQtViewer::actionMousePick() {
838#ifdef GEANT4_QT_DEBUG
839  printf("G4OpenGLQtViewer::actionMousePick \n");
840#endif
841  emit toggleMouseAction(STYLE3);
842}
843
844/**
845   Slot activate when mouseAction->zoom menu is set
846 */
847void G4OpenGLQtViewer::actionMouseShortcuts() {
848#ifdef GEANT4_QT_DEBUG
849  printf("G4OpenGLQtViewer::actionMouseShortcuts \n");
850#endif
851  emit toggleMouseAction(STYLE3);
852}
853
854/**
855   Slot activate when drawing->wireframe menu is set
856 */
857void G4OpenGLQtViewer::actionDrawingWireframe() {
858  emit toggleDrawingAction(1);
859}
860
861/**
862   Slot activate when drawing->line removal menu is set
863 */
864void G4OpenGLQtViewer::actionDrawingLineRemoval() {
865  emit toggleDrawingAction(2);
866}
867
868/**
869   Slot activate when drawing->surface removal menu is set
870 */
871void G4OpenGLQtViewer::actionDrawingSurfaceRemoval() {
872  emit toggleDrawingAction(3);
873}
874
875/**
876   Slot activate when drawing->wireframe menu is set
877 */
878void G4OpenGLQtViewer::actionDrawingLineSurfaceRemoval() {
879  emit toggleDrawingAction(4);
880}
881
882
883/**
884   Slot activated when mouse action is toggle
885   @param aAction : STYLE1, STYLE2, STYLE3
886 */
887void G4OpenGLQtViewer::toggleMouseAction(mouseActions aAction) {
888 
889  if (aAction == STYLE1) {  // rotate
890    G4cout << "Click and move mouse to rotate volume \n" << G4endl;
891    G4cout << "Press left/right arrows to move volume left/right\n" << G4endl;
892    G4cout << "Press up/down arrows to move volume up/down\n" << G4endl;
893    G4cout << "Press CONTROL+up/down arrows to move volume toward/forward\n" << G4endl;
894    G4cout << "Press SHIFT+left/right arrows to rotate volume left/right\n" << G4endl;
895    G4cout << "Press SHIFT+up/down arrows to rotate volume up/down\n" << G4endl;
896    G4cout << "Press +/- to zoom into volume\n" << G4endl;
897#if QT_VERSION < 0x040000
898    fMouseRotate->setItemChecked (0,true);
899    fMousePick->setItemChecked (0,false);
900    fMouseShortcuts->setItemChecked (0,false);
901#else
902    fMouseRotate->setChecked (true);
903    fMousePick->setChecked (false);
904    fMouseShortcuts->setChecked (false);
905#endif
906    fMouseAction = STYLE1;
907    fVP.SetPicking(false);
908  } else  if (aAction == STYLE2) { //pick
909    G4cout << "Click and pick \n" << G4endl;
910#if QT_VERSION < 0x040000
911    fMouseRotate->setItemChecked (0,false);
912    fMousePick->setItemChecked (0,true);
913#else
914    fMouseRotate->setChecked (false);
915    fMousePick->setChecked (true);
916#endif
917    fVP.SetPicking(true);
918    fMouseAction = STYLE2;
919  } else  if (aAction == STYLE3) {  // display shortcuts
920#if QT_VERSION < 0x040000
921    fMouseRotate->setItemChecked (0,false);
922    fMousePick->setItemChecked (0,false);
923    fMouseShortcuts->setItemChecked (0,true);
924#else
925    fMouseRotate->setChecked (false);
926    fMousePick->setChecked (false);
927    fMouseShortcuts->setChecked (true);
928#endif
929    fMouseAction = STYLE3;
930    fVP.SetPicking(false);
931
932    G4cout << "Click and move mouse to rotate volume \n" << G4endl;
933    G4cout << "Press left/right arrows to move volume left/right\n" << G4endl;
934    G4cout << "Press up/down arrows to move volume up/down\n" << G4endl;
935    G4cout << "Press CONTROL+up/down arrows to move volume toward/forward\n" << G4endl;
936    G4cout << "Press SHIFT+left/right arrows to rotate volume left/right\n" << G4endl;
937    G4cout << "Press SHIFT+up/down arrows to rotate volume up/down\n" << G4endl;
938    G4cout << "Press +/- to zoom into volume\n" << G4endl;
939  }
940
941}
942/**
943   Slot activated when drawing menu is toggle
944   Warning : When G4OpenGLStoredQtViewer::DrawView() method call,
945   KernelVisitDecision () will be call and will set the fNeedKernelVisit
946   to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations.
947   It will cause a redraw of the view
948   @param aAction : 1 wireframe, 2 line removal, 3 surface removal, 4 line & surface removal
949   @see G4OpenGLStoredQtViewer::DrawView
950   @see G4XXXStoredViewer::CompareForKernelVisit
951 */
952void G4OpenGLQtViewer::toggleDrawingAction(int aAction) {
953
954  G4ViewParameters::DrawingStyle d_style;
955 
956
957  if (aAction ==1) {
958#if QT_VERSION < 0x040000
959    fDrawingWireframe->setItemChecked (0,true);
960    fDrawingLineRemoval->setItemChecked (0,false);
961    fDrawingSurfaceRemoval->setItemChecked (0,false);
962    fDrawingLineSurfaceRemoval->setItemChecked (0,false);
963#else
964    fDrawingWireframe->setChecked (true);
965    fDrawingLineRemoval->setChecked (false);
966    fDrawingSurfaceRemoval->setChecked (false);
967    fDrawingLineSurfaceRemoval->setChecked (false);
968#endif
969
970    d_style = G4ViewParameters::wireframe;
971
972  } else  if (aAction ==2) {
973#if QT_VERSION < 0x040000
974    fDrawingWireframe->setItemChecked (0,false);
975    fDrawingLineRemoval->setItemChecked (0,true);
976    fDrawingSurfaceRemoval->setItemChecked (0,false);
977    fDrawingLineSurfaceRemoval->setItemChecked (0,false);
978#else
979    fDrawingWireframe->setChecked (false);
980    fDrawingLineRemoval->setChecked (true);
981    fDrawingSurfaceRemoval->setChecked (false);
982    fDrawingLineSurfaceRemoval->setChecked (false);
983#endif
984
985    d_style = G4ViewParameters::hlr;
986
987  } else  if (aAction ==3) {
988#if QT_VERSION < 0x040000
989    fDrawingWireframe->setItemChecked (0,false);
990    fDrawingLineRemoval->setItemChecked (0,false);
991    fDrawingSurfaceRemoval->setItemChecked (0,true);
992    fDrawingLineSurfaceRemoval->setItemChecked (0,false);
993#else
994    fDrawingWireframe->setChecked (false);
995    fDrawingLineRemoval->setChecked (false);
996    fDrawingSurfaceRemoval->setChecked (true);
997    fDrawingLineSurfaceRemoval->setChecked (false);
998#endif
999
1000    d_style = G4ViewParameters::hsr;
1001
1002  } else  if (aAction ==4) {
1003#if QT_VERSION < 0x040000
1004    fDrawingWireframe->setItemChecked (0,false);
1005    fDrawingLineRemoval->setItemChecked (0,false);
1006    fDrawingSurfaceRemoval->setItemChecked (0,false);
1007    fDrawingLineSurfaceRemoval->setItemChecked (0,true);
1008#else
1009    fDrawingWireframe->setChecked (false);
1010    fDrawingLineRemoval->setChecked (false);
1011    fDrawingSurfaceRemoval->setChecked (false);
1012    fDrawingLineSurfaceRemoval->setChecked (true);
1013#endif
1014    d_style = G4ViewParameters::hlhsr;
1015  }
1016  fVP.SetDrawingStyle(d_style);
1017
1018  updateQWidget();
1019#ifdef GEANT4_QT_DEBUG
1020  printf("G4OpenGLQtViewer::toggleDrawingAction\n");
1021#endif
1022}
1023
1024
1025/**
1026   SLOT Activate by a click on the representation menu
1027   Warning : When G4OpenGLStoredQtViewer::DrawView() method call,
1028   KernelVisitDecision () will be call and will set the fNeedKernelVisit
1029   to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations.
1030   It will cause a redraw of the view
1031   @param check : 1 polyhedron, 0 nurbs
1032   @see G4OpenGLStoredQtViewer::DrawView
1033   @see G4XXXStoredViewer::CompareForKernelVisit
1034*/
1035void G4OpenGLQtViewer::toggleRepresentation(bool check) {
1036
1037  G4ViewParameters::RepStyle style;
1038  if (check == 1) {
1039    style = G4ViewParameters::polyhedron;
1040  } else {
1041    style = G4ViewParameters::nurbs;
1042  }
1043  fVP.SetRepStyle (style);
1044
1045  updateQWidget();
1046}
1047
1048/**
1049   SLOT Activate by a click on the projection menu
1050   Warning : When G4OpenGLStoredQtViewer::DrawView() method call,
1051   KernelVisitDecision () will be call and will set the fNeedKernelVisit
1052   to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations.
1053   It will cause a redraw of the view
1054   @param check : 1 orthographic, 2 perspective
1055   @see G4OpenGLStoredQtViewer::DrawView
1056   @see G4XXXStoredViewer::CompareForKernelVisit
1057*/
1058void G4OpenGLQtViewer::toggleProjection(bool check) {
1059
1060  if (check == 1) {
1061    fVP.SetFieldHalfAngle (0);
1062  } else {
1063
1064    // look for the default parameter hidden in G4UIcommand parameters
1065    G4UImanager* UI = G4UImanager::GetUIpointer();
1066    if(UI==NULL)
1067      return;
1068    G4UIcommandTree * treeTop = UI->GetTree();
1069
1070    // find command
1071    G4UIcommand* command = treeTop->FindPath("/vis/viewer/set/projection");
1072    if (!command)
1073      return;
1074
1075    // find param
1076    G4UIparameter * angleParam = NULL;
1077    for(G4int i=0;  i<command->GetParameterEntries(); i++)
1078    {
1079      if( command->GetParameter(i)->GetParameterName() == "field-half-angle" ) {
1080        angleParam = command->GetParameter(i);
1081      }
1082    }
1083    if (!angleParam)
1084      return;
1085
1086    // find unit
1087    G4UIparameter * unitParam = NULL;
1088    for(G4int i=0;  i<command->GetParameterEntries(); i++)
1089    {
1090      if( command->GetParameter(i)->GetParameterName() == "unit" ) {
1091        unitParam = command->GetParameter(i);
1092      }
1093    }
1094    if (!unitParam)
1095      return;
1096
1097    G4double defaultValue = command->ConvertToDouble(angleParam->GetDefaultValue())
1098                            * G4UnitDefinition::GetValueOf(unitParam->GetDefaultValue());
1099    if (defaultValue > 89.5 || defaultValue <= 0.0) {
1100      G4cerr << "Field half angle should be 0 < angle <= 89.5 degrees. Check your default Field half angle parameter\n";
1101    } else {
1102      G4cout << "Perspective view has been set to default value. Field half angle="<<angleParam->GetDefaultValue() <<" \n" << G4endl;
1103      fVP.SetFieldHalfAngle (defaultValue);
1104      SetView ();
1105    }
1106  } 
1107  updateQWidget();
1108}
1109
1110
1111/**
1112   SLOT Activate by a click on the background menu
1113@param check : 1 white, 0 black
1114*/
1115void G4OpenGLQtViewer::toggleBackground(bool check) {
1116
1117  //   //I need to revisit the kernel if the background colour changes and
1118  //   //hidden line removal is enabled, because hlr drawing utilises the
1119  //   //background colour in its drawing...
1120  //   // (Note added by JA 13/9/2005) Background now handled in view
1121  //   // parameters.  A kernel visit is triggered on change of background.
1122  if (check == 1) {
1123    ((G4ViewParameters&)this->GetViewParameters()).
1124      SetBackgroundColour(G4Colour(1.,1.,1.));  // White
1125  } else {
1126    ((G4ViewParameters&)this->GetViewParameters()).
1127      SetBackgroundColour(G4Colour(0.,0.,0.));  // Black
1128  }
1129  updateQWidget();
1130}
1131
1132/**
1133   SLOT Activate by a click on the transparency menu
1134@param check : 1 , 0
1135*/
1136void G4OpenGLQtViewer::toggleTransparency(bool check) {
1137 
1138  if (check) {
1139    transparency_enabled = false;
1140  } else {
1141    transparency_enabled = true;
1142  }
1143  SetNeedKernelVisit (true);
1144  updateQWidget();
1145}
1146
1147/**
1148   SLOT Activate by a click on the antialiasing menu
1149@param check : 1 , 0
1150*/
1151void G4OpenGLQtViewer::toggleAntialiasing(bool check) {
1152
1153  if (!check) {
1154    antialiasing_enabled = false;
1155    glDisable (GL_LINE_SMOOTH);
1156    glDisable (GL_POLYGON_SMOOTH);
1157  } else {
1158    antialiasing_enabled = true;
1159    glEnable (GL_LINE_SMOOTH);
1160    glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
1161    glEnable (GL_POLYGON_SMOOTH);
1162    glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
1163  }
1164
1165  updateQWidget();
1166}
1167
1168/**
1169   SLOT Activate by a click on the haloing menu
1170@param check : 1 , 0
1171*/
1172//FIXME : I SEE NOTHING...
1173void G4OpenGLQtViewer::toggleHaloing(bool check) {
1174  if (check) {
1175    haloing_enabled = false;
1176  } else {
1177    haloing_enabled = true;
1178  }
1179
1180  updateQWidget();
1181
1182}
1183
1184/**
1185   SLOT Activate by a click on the auxiliaire edges menu
1186@param check : 1 , 0
1187*/
1188void G4OpenGLQtViewer::toggleAux(bool check) {
1189  if (check) {
1190    fVP.SetAuxEdgeVisible(false);
1191  } else {
1192    fVP.SetAuxEdgeVisible(true);
1193  }
1194  SetNeedKernelVisit (true);
1195  updateQWidget();
1196
1197}
1198
1199/**
1200   SLOT Activate by a click on the full screen menu
1201*/
1202void G4OpenGLQtViewer::toggleFullScreen() {
1203#if QT_VERSION >= 0x030200
1204  GLWindow->setWindowState(GLWindow->windowState() ^ Qt::WindowFullScreen);
1205#else
1206  G4cerr << "This version of G4UI Could not generate the selected format\n" << G4endl;
1207#endif
1208}
1209
1210void G4OpenGLQtViewer::actionCreateEPS() {
1211  QString filters;
1212#if QT_VERSION < 0x040000
1213  QStrList listFormat=QImageIO::outputFormats();
1214  char *tmp=listFormat.first();
1215  while (tmp!=0) {
1216    filters += QString(tmp) + ";;";
1217    tmp=listFormat.next();
1218  }
1219#else
1220  QList<QByteArray> formats =  QImageWriter::supportedImageFormats ();
1221  for (int i = 0; i < formats.size(); ++i) {
1222    filters +=formats.at(i) + ";;";
1223  }
1224#endif
1225  filters += "eps;;";
1226  filters += "ps;;";
1227  filters += "pdf";
1228  QString* selectedFormat = new QString();
1229#if QT_VERSION < 0x040000
1230  QString nomFich =  QFileDialog::getSaveFileName ( ".",
1231                                                    filters,
1232                                                    GLWindow,
1233                                                    "Save file dialog",
1234                                                    tr("Save as ..."),
1235                                                    selectedFormat );
1236#else
1237  QString nomFich =  QFileDialog::getSaveFileName ( GLWindow,
1238                                                    tr("Save as ..."),
1239                                                    ".",
1240                                                    filters,
1241                                                    selectedFormat );
1242#endif
1243  // bmp jpg jpeg png ppm xbm xpm
1244  if (nomFich == "") {
1245    return;
1246  }
1247#if QT_VERSION < 0x040000
1248  nomFich += "."+QString(selectedFormat->ascii());
1249  QString format = selectedFormat->lower();
1250#else
1251  nomFich += "."+QString(selectedFormat->toStdString().c_str());
1252  QString format = selectedFormat->toLower();
1253#endif
1254  G4OpenGLQtExportDialog* exportDialog= new G4OpenGLQtExportDialog(GLWindow,format,fWindow->height(),fWindow->width());
1255  if(  exportDialog->exec()) {
1256
1257    QImage image;
1258    bool res = false;
1259    if ((exportDialog->getWidth() !=fWindow->width()) ||
1260        (exportDialog->getHeight() !=fWindow->height())) {
1261      if (format != QString("eps")) {
1262      G4cerr << "Export->Change Size : This function is not implemented, to export in another size, please resize your frame to what you need\n" << G4endl;
1263     
1264      //    rescaleImage(exportDialog->getWidth(),exportDialog->getHeight());// re-scale image
1265      //      QGLWidget* glResized = fWindow;
1266
1267      // FIXME :
1268      // L.Garnier : I've try to implement change size function, but the problem is
1269      // the renderPixmap function call the QGLWidget to resize and it doesn't draw
1270      // the content of this widget... It only draw the background.
1271
1272      //      fWindow->renderPixmap (exportDialog->getWidth()*2,exportDialog->getHeight()*2,true );
1273
1274      //      QPixmap pixmap = fWindow->renderPixmap ();
1275     
1276      //      image = pixmap->toImage();
1277      //      glResized->resize(exportDialog->getWidth()*2,exportDialog->getHeight()*2);
1278      //      image = glResized->grabFrameBuffer();
1279      }     
1280    } else {
1281      image = fWindow->grabFrameBuffer();
1282    }   
1283    if (format == QString("eps")) {
1284      if (exportDialog->getVectorEPS()) {
1285        res = generateVectorEPS(nomFich,exportDialog->getWidth(),exportDialog->getHeight(),image);
1286      } else {
1287        res = generateEPS(nomFich,exportDialog->getNbColor(),image);
1288      }
1289    } else if ((format == "ps") || (format == "pdf")) {
1290      res = generatePS_PDF(nomFich,exportDialog->getNbColor(),image);
1291    } else if ((format == "tif") ||
1292               (format == "tiff") ||
1293               (format == "jpg") ||
1294               (format == "jpeg") ||
1295               (format == "png") ||
1296               (format == "pbm") ||
1297               (format == "pgm") ||
1298               (format == "ppm") ||
1299               (format == "bmp") ||
1300               (format == "xbm") ||
1301               (format == "xpm")) {
1302#if QT_VERSION < 0x040000
1303      res = image.save(nomFich,selectedFormat->ascii(),exportDialog->getSliderValue());
1304#else
1305      res = image.save(nomFich,0,exportDialog->getSliderValue());
1306#endif
1307    } else {
1308      G4cerr << "This version of G4UI Could not generate the selected format\n" << G4endl;
1309    }
1310    if (res == false) {
1311#if QT_VERSION < 0x040000
1312      G4cerr << "Error while saving file... "<<nomFich.ascii()<<"\n" << G4endl;
1313#else
1314      G4cerr << "Error while saving file... "<<nomFich.toStdString().c_str()<<"\n" << G4endl;
1315#endif
1316    } else {
1317#if QT_VERSION < 0x040000
1318      G4cout << "File "<<nomFich.ascii()<<" has been saved \n" << G4endl;
1319#else
1320      G4cout << "File "<<nomFich.toStdString().c_str()<<" has been saved \n" << G4endl;
1321#endif
1322    }
1323   
1324  } else { // cancel selected
1325    return;
1326  }
1327 
1328#ifdef GEANT4_QT_DEBUG
1329  printf("G4OpenGLQtViewer::actionCreateEPS() \n");
1330#endif
1331}
1332
1333/*
1334// http://www.google.com/codesearch?hl=en&q=+jpg+Qt+quality+QDialog+show:FZkUoth8oiw:TONpW2mR-_c:tyTfrKMO-xI&sa=N&cd=2&ct=rc&cs_p=http://soft.proindependent.com/src/qtiplot-0.8.9.zip&cs_f=qtiplot-0.8.9/qtiplot/src/application.cpp#a0
1335
1336void Graph::exportToSVG(const QString& fname)
1337{
1338  // enable workaround for Qt3 misalignments
1339  QwtPainter::setSVGMode(true);
1340  QPicture picture;
1341  QPainter p(&picture);
1342  d_plot->print(&p, d_plot->rect());
1343  p.end();
1344
1345  picture.save(fname, "svg");
1346}
1347*/
1348
1349
1350
1351
1352/**
1353   Save the current mouse press point
1354   @param p mouse click point
1355*/
1356void G4OpenGLQtViewer::G4MousePressEvent(QPoint p)
1357{
1358  fLastPos = p;
1359  if (fMouseAction == STYLE2){  // pick
1360    Pick(p.x(),p.y());
1361  }
1362}
1363
1364
1365/**
1366   @param pos_x mouse x position
1367   @param pos_y mouse y position
1368   @param mButtons mouse button active
1369*/
1370
1371#if QT_VERSION < 0x040000
1372void G4OpenGLQtViewer::G4MouseEvent(int pos_x, int pos_y,Qt::ButtonState mButtons)
1373#else
1374void G4OpenGLQtViewer::G4MouseEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons)
1375#endif
1376{
1377  int dx = fLastPos.x() - pos_x;
1378  int dy = fLastPos.y() - pos_y;
1379  if (fMouseAction == STYLE1) {  // rotate
1380    if (mButtons & Qt::LeftButton) {
1381      G4MouseRotateEvent(dx,dy);
1382    }
1383  }
1384  fLastPos = QPoint(pos_x, pos_y);
1385}
1386
1387/**
1388   Move the scene of dx, dy, dz values.
1389   Values are in
1390   100 moves of 1 => move of 10cm of the scene
1391   @param dx delta mouse x position
1392   @param dy delta mouse y position
1393*/
1394
1395void G4OpenGLQtViewer::G4MouseMoveEvent(int dx, int dy, int dz)
1396{
1397//               2
1398//         ------------       0              0              tx
1399//         right - left
1400//                            2
1401//             0         ------------        0              ty
1402//                       top - bottom
1403//                                           -2
1404//             0              0         ------------        tz
1405//                                       zFar-zNear
1406//             0              0              0              1
1407//        where
1408//                        tx = - (right + left) / (right - left)
1409//                        ty = - (top + bottom) / (top - bottom)
1410//                        tz = - (zFar + zNear) / (zFar - zNear)
1411 double              projection_view[16];
1412 glGetDoublev (GL_PROJECTION_MATRIX, projection_view);
1413 printf("%f\t%f\t%f\t%f\n",projection_view[0],projection_view[1],projection_view[2],projection_view[3]);
1414 printf("%f\t%f\t%f\t%f\n",projection_view[4],projection_view[5],projection_view[6],projection_view[7]);
1415 printf("%f\t%f\t%f\t%f\n",projection_view[8],projection_view[9],projection_view[10],projection_view[11]);
1416 printf("%f\t%f\t%f\t%f\n",projection_view[12],projection_view[13],projection_view[14],projection_view[15]);
1417//   int deltaX =
1418// GLenum clip = glGet(GL_CLIP_PLANE);
1419//   int deltaY = ;
1420
1421
1422  G4Point3D stp = GetSceneHandler()->GetScene()->GetStandardTargetPoint();
1423 
1424  G4Point3D tp = stp + fVP.GetCurrentTargetPoint ();
1425 
1426  const G4Vector3D& upVector = fVP.GetUpVector ();
1427  const G4Vector3D& vpVector = fVP.GetViewpointDirection ();
1428 
1429  G4Vector3D unitRight = (upVector.cross (vpVector)).unit();
1430  G4Vector3D unitUp    = (vpVector.cross (unitRight)).unit();
1431 
1432#ifdef GEANT4_QT_DEBUG
1433  G4cout << fVP<<G4endl;
1434  printf("Mouse event Target Point : %f %f %f\n",tp.x(),tp.y(),tp.z());
1435  printf("Mouse event upVector : %f %f %f\n",upVector.x(),upVector.y(),upVector.z());
1436  printf("Mouse event vpVector Point : %f %f %f\n",vpVector.x(),vpVector.y(),vpVector.z());
1437  printf("Mouse event unitRight Point : %f %f %f\n",unitRight.x(),unitRight.y(),unitRight.z());
1438  printf("Mouse event unitUp Point : %f %f %f\n",unitUp.x(),unitUp.y(),unitUp.z());
1439#endif
1440  tp += -dx * unitRight + dy * unitUp + dz * vpVector;
1441  fVP.SetCurrentTargetPoint (tp - stp);
1442 
1443  updateQWidget();
1444}
1445
1446
1447/**
1448   @param dx delta mouse x position
1449   @param dy delta mouse y position
1450*/
1451
1452void G4OpenGLQtViewer::G4MouseRotateEvent(int dx, int dy)
1453{
1454  //phi spin stuff here
1455 
1456  G4Vector3D vp = fVP.GetViewpointDirection ().unit ();
1457  G4Vector3D up = fVP.GetUpVector ().unit ();
1458 
1459  G4Vector3D yprime = (up.cross(vp)).unit();
1460  G4Vector3D zprime = (vp.cross(yprime)).unit();
1461 
1462  G4double delta_alpha;
1463  G4double delta_theta;
1464 
1465  if (fVP.GetLightsMoveWithCamera()) {
1466    delta_alpha = dy;
1467    delta_theta = -dx;
1468  } else {
1469    delta_alpha = -dy;
1470    delta_theta = dx;
1471  }   
1472 
1473  delta_alpha *= deg;
1474  delta_theta *= deg;
1475 
1476  G4Vector3D new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime;
1477 
1478  G4Vector3D new_up;
1479  if (fVP.GetLightsMoveWithCamera()) {
1480    new_up = (new_vp.cross(yprime)).unit();
1481    fVP.SetUpVector(new_up);
1482  } else {
1483    new_up = up;
1484  }
1485  ////////////////
1486  // Rotates by fixed azimuthal angle delta_theta.
1487 
1488  G4double cosalpha = new_up.dot (new_vp.unit());
1489  G4double sinalpha = std::sqrt (1. - std::pow (cosalpha, 2));
1490  yprime = (new_up.cross (new_vp.unit())).unit ();
1491  G4Vector3D xprime = yprime.cross (new_up);
1492  // Projection of vp on plane perpendicular to up...
1493  G4Vector3D a1 = sinalpha * xprime;
1494  // Required new projection...
1495  G4Vector3D a2 =
1496    sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime);
1497  // Required Increment vector...
1498  G4Vector3D delta = a2 - a1;
1499  // So new viewpoint is...
1500  G4Vector3D viewPoint = new_vp.unit() + delta;
1501 
1502  fVP.SetViewAndLights (viewPoint);
1503  updateQWidget();
1504 
1505}
1506
1507/** This is the benning of a rescale function. It does nothing for the moment
1508    @param aWidth : new width
1509    @param aHeight : new height
1510*/
1511void G4OpenGLQtViewer::rescaleImage(
1512 int aWidth
1513,int aHeight
1514){
1515#ifdef GEANT4_QT_DEBUG
1516  printf("should rescale \n");
1517#endif
1518  GLfloat* feedback_buffer;
1519  GLint returned;
1520  FILE* file;
1521 
1522//   feedback_buffer = new GLfloat[size];
1523//   glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer);
1524//   glRenderMode (GL_FEEDBACK);
1525 
1526//   glViewport (0, 0, aWidth, aHeight);
1527//   DrawView();
1528//   returned = glRenderMode (GL_RENDER);
1529
1530}
1531
1532/**
1533   Generate Vectorial Encapsulated Postscript form image
1534   @param aFilename : name of file
1535   @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha
1536   @param aImage : Image to print
1537*/
1538bool G4OpenGLQtViewer::generateVectorEPS (
1539 QString aFilename
1540,int aWidth
1541,int aHeight
1542,QImage aImage
1543)
1544{
1545  // Print vectored PostScript
1546 
1547  G4int size = 5000000;
1548
1549  GLfloat* feedback_buffer;
1550  GLint returned;
1551  FILE* file;
1552 
1553  feedback_buffer = new GLfloat[size];
1554  glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer);
1555  glRenderMode (GL_FEEDBACK);
1556 
1557  int side = aWidth;
1558  if (aHeight < aWidth) side = aHeight;
1559  glViewport((aWidth - side) / 2, (aHeight - side) / 2, side, side);
1560  DrawView();
1561
1562  returned = glRenderMode (GL_RENDER);
1563 
1564 
1565#if QT_VERSION < 0x040000
1566  file = fopen (aFilename.ascii(), "w");
1567#else
1568  file = fopen (aFilename.toStdString().c_str(), "w");
1569#endif
1570  if (file) {
1571    spewWireframeEPS (file, returned, feedback_buffer, "rendereps");
1572  } else {
1573#if QT_VERSION < 0x040000
1574    G4cerr << "Could not open "<< aFilename.ascii()<<"\n" << G4endl;
1575#else
1576    G4cerr << "Could not open "<< aFilename.toStdString().c_str()<<"\n" << G4endl;
1577#endif
1578  }
1579 
1580  delete[] feedback_buffer;
1581
1582  return true;
1583}
1584
1585/**
1586   Generate Encapsulated Postscript form image
1587   @param aFilename : name of file
1588   @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha
1589   @param aImage : Image to print
1590*/
1591bool G4OpenGLQtViewer::generateEPS (
1592 QString aFilename
1593,int aInColor
1594,QImage aImage
1595)
1596{
1597  // FIXME
1598#ifdef GEANT4_QT_DEBUG
1599  printf("saving EPS\n");
1600#endif
1601
1602  FILE* fp;
1603
1604  if (aImage.bits () == NULL)
1605    return false;
1606 
1607#if QT_VERSION < 0x040000
1608  fp = fopen (aFilename.ascii(), "w");
1609#else
1610  fp = fopen (aFilename.toStdString().c_str(), "w");
1611#endif
1612  if (fp == NULL) {
1613    return false;
1614  }
1615 
1616  fprintf (fp, "%%!PS-Adobe-2.0 EPSF-1.2\n");
1617#if QT_VERSION < 0x040000
1618  fprintf (fp, "%%%%Title: %s\n", aFilename.ascii());
1619#else
1620  fprintf (fp, "%%%%Title: %s\n", aFilename.toStdString().c_str());
1621#endif
1622  fprintf (fp, "%%%%Creator: OpenGL pixmap render output\n");
1623  fprintf (fp, "%%%%BoundingBox: 0 0 %d %d\n", aImage.width(), aImage.height());
1624  fprintf (fp, "%%%%EndComments\n");
1625  fprintf (fp, "gsave\n");
1626  fprintf (fp, "/bwproc {\n");
1627  fprintf (fp, "    rgbproc\n");
1628  fprintf (fp, "    dup length 3 idiv string 0 3 0 \n");
1629  fprintf (fp, "    5 -1 roll {\n");
1630  fprintf (fp, "    add 2 1 roll 1 sub dup 0 eq\n");
1631  fprintf (fp, "    { pop 3 idiv 3 -1 roll dup 4 -1 roll dup\n");
1632  fprintf (fp, "       3 1 roll 5 -1 roll } put 1 add 3 0 \n");
1633  fprintf (fp, "    { 2 1 roll } ifelse\n");
1634  fprintf (fp, "    }forall\n");
1635  fprintf (fp, "    pop pop pop\n");
1636  fprintf (fp, "} def\n");
1637  fprintf (fp, "systemdict /colorimage known not {\n");
1638  fprintf (fp, "   /colorimage {\n");
1639  fprintf (fp, "       pop\n");
1640  fprintf (fp, "       pop\n");
1641  fprintf (fp, "       /rgbproc exch def\n");
1642  fprintf (fp, "       { bwproc } image\n");
1643  fprintf (fp, "   }  def\n");
1644  fprintf (fp, "} if\n");
1645  fprintf (fp, "/picstr %d string def\n", aImage.width() * aInColor);
1646  fprintf (fp, "%d %d scale\n", aImage.width(), aImage.height());
1647  fprintf (fp, "%d %d %d\n", aImage.width(), aImage.height(), 8);
1648  fprintf (fp, "[%d 0 0 %d 0 0]\n", aImage.width(), aImage.height());
1649  fprintf (fp, "{currentfile picstr readhexstring pop}\n");
1650  fprintf (fp, "false %d\n", aInColor);
1651  fprintf (fp, "colorimage\n");
1652 
1653
1654  int width = aImage.width();
1655  int height = aImage.height();
1656  int depth = aImage.depth();
1657  int size = width*height;
1658 
1659  if (depth == 1)
1660    size = (width+7)/8*height;
1661  else if (aInColor == 1)
1662    size = size*3;
1663 
1664  int i = 0;
1665  //  if ( aInColor ==1 ) {
1666  // FIXME : L. Garnier. For the moment 10 dec 2007, I could not find a way
1667  // to save correctly grayscale Image. I mean that color or grayscale image
1668  // have the same file save size !
1669 
1670  /* } else*/ if (depth == 8) {
1671    for(int y=height-1; y >=0 ; y--) {
1672      const uchar * s = aImage.scanLine(y);
1673      for(int x=0; x <width; x++) {
1674        QRgb rgb = aImage.color(s[x]);
1675        if (aInColor == 1) {
1676          fprintf (fp, " %02hx ",(unsigned char)qGray(rgb));
1677          i++;
1678        } else {
1679          fprintf (fp, " %02hx %02hx %02hx",
1680                   (unsigned char) qRed(rgb),
1681                   (unsigned char) qGreen(rgb),
1682                   (unsigned char) qBlue(rgb));
1683          i += 3;
1684        }
1685      }
1686      fprintf (fp, "\n");
1687    }
1688  } else {
1689#if QT_VERSION < 0x040000
1690    bool alpha = aImage.hasAlphaBuffer();
1691#else
1692    bool alpha = aImage.hasAlphaChannel();
1693    for(int y=height-1; y >=0 ; y--) {
1694      QRgb * s = (QRgb*)(aImage.scanLine(y));
1695      for(int x=0; x <width; x++) {
1696        QRgb rgb = (*s++);
1697        if (alpha && qAlpha(rgb) < 0x40) // 25% alpha, convert to white -
1698          rgb = qRgb(0xff, 0xff, 0xff);
1699        if (aInColor == 1) {
1700          fprintf (fp, " %02hx ",(unsigned char)qGray(rgb));
1701          i++;
1702        } else {
1703          fprintf (fp, " %02hx %02hx %02hx",
1704                   (unsigned char) qRed(rgb),
1705                   (unsigned char) qGreen(rgb),
1706                   (unsigned char) qBlue(rgb));
1707          i += 3;
1708        }
1709      }
1710      fprintf (fp, "\n");
1711    }
1712#endif
1713
1714  }
1715
1716  fprintf (fp, "grestore\n");
1717  fprintf (fp, "showpage\n");
1718  fclose (fp);
1719
1720  return true;
1721}
1722/**
1723   Generate Postscript or PDF form image
1724   @param aFilename : name of file
1725   @param aInColor : numbers of colors : 1->BW 2->RGB
1726   @param aImage : Image to print
1727*/
1728bool G4OpenGLQtViewer::generatePS_PDF (
1729 QString aFilename
1730,int aInColor
1731,QImage aImage
1732)
1733{
1734
1735#if QT_VERSION < 0x040000
1736#ifdef Q_WS_MAC || Q_WS_X11
1737  QPrinter printer;
1738  //  printer.setPageSize(pageSize);
1739  if (aInColor == 1) {
1740    printer.setColorMode(QPrinter::GrayScale);
1741  } else {
1742    printer.setColorMode(QPrinter::Color);
1743  }
1744
1745  /* FIXME : I don't know which format it will save...
1746     if (aFilename.endsWith(".ps")) {
1747     printer.setOutputFormat(QPrinter::PostScriptFormat);
1748     } else {
1749     printer.setOutputFormat(QPrinter::PdfFormat);
1750     }
1751  */
1752  printer.setOutputFileName(aFilename);
1753  //  printer.setFullPage ( true);
1754  QPainter paint(&printer);
1755  paint.drawImage (0,0,aImage );
1756  paint.end();
1757#else
1758  G4cerr << "This fonction is only supported on Mac OsX or X11 with Qt3. Full platform supported with Qt4\n" << G4endl;
1759#endif
1760#else
1761  QPrinter printer;
1762  //  printer.setPageSize(pageSize);
1763
1764  // FIXME : L. Garnier 4/12/07
1765  // This is not working, it does nothing. Image is staying in color mode
1766  // So I have desactivate the B/W button in GUI
1767  if ((!aImage.isGrayscale ()) &&(aInColor ==1 )) {
1768#if QT_VERSION < 0x040000
1769    aImage = aImage.convertDepth(1,Qt::MonoOnly);
1770#else
1771    aImage = aImage.convertToFormat ( aImage.format(), Qt::MonoOnly);
1772#endif
1773  }
1774
1775
1776  if (aFilename.endsWith(".ps")) {
1777#if QT_VERSION > 0x040200
1778    printer.setOutputFormat(QPrinter::PostScriptFormat);
1779#endif
1780  } else {
1781#if QT_VERSION > 0x040100
1782    printer.setOutputFormat(QPrinter::PdfFormat);
1783#endif
1784  }
1785#if QT_VERSION > 0x040100
1786  printer.setOutputFileName(aFilename);
1787#endif
1788  //  printer.setFullPage ( true);
1789  QPainter paint(&printer);
1790  paint.drawImage (0,0,aImage);
1791  paint.end();
1792#endif
1793  return true;
1794}
1795
1796
1797void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * event)
1798{
1799  if (holdKeyEvent)
1800    return;
1801
1802  holdKeyEvent = true;
1803
1804#if QT_VERSION < 0x040000
1805  if ((event->key() == Qt::Key_Down) && (event->state() & Qt::AltButton )) { // go backward
1806#else
1807  if ((event->key() == Qt::Key_Down) && (event->modifiers() & Qt::AltModifier )) { // go backward
1808#endif
1809    G4MouseMoveEvent(0,0,1);
1810  }
1811#if QT_VERSION < 0x040000
1812  else if ((event->key() == Qt::Key_Up) && (event->state() & Qt::AltButton)) { // go forward
1813#else
1814  else if ((event->key() == Qt::Key_Up) && (event->modifiers() & Qt::AltModifier)) { // go forward
1815#endif
1816    G4MouseMoveEvent(0,0,-1);
1817  }
1818#if QT_VERSION < 0x040000
1819  if ((event->key() == Qt::Key_Down) && (event->state() & Qt::ShiftButton)) { // rotate phi
1820#else
1821  if ((event->key() == Qt::Key_Down) && (event->modifiers() & Qt::ShiftModifier)) { // rotate phi
1822#endif
1823    G4MouseRotateEvent(0,-1);
1824  }
1825#if QT_VERSION < 0x040000
1826  else if ((event->key() == Qt::Key_Up) && (event->state() & Qt::ShiftButton)) { // rotate phi
1827#else
1828  else if ((event->key() == Qt::Key_Up) && (event->modifiers() & Qt::ShiftModifier)) { // rotate phi
1829#endif
1830    G4MouseRotateEvent(0,1);
1831  }
1832#if QT_VERSION < 0x040000
1833  if ((event->key() == Qt::Key_Left) && (event->state() & Qt::ShiftButton)) { // rotate theta
1834#else
1835  if ((event->key() == Qt::Key_Left) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta
1836#endif
1837    G4MouseRotateEvent(1,0);
1838  }
1839#if QT_VERSION < 0x040000
1840  else if ((event->key() == Qt::Key_Right) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta
1841#else
1842  else if ((event->key() == Qt::Key_Right) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta
1843#endif
1844    G4MouseRotateEvent(-1,0);
1845  }
1846  if (event->key() == Qt::Key_Escape) { // escaped from full screen
1847    toggleFullScreen();
1848  }
1849  if (event->key() == Qt::Key_Plus) { // zoom in
1850    fVP.SetZoomFactor(fVP.GetZoomFactor()*fDeltaZoom);
1851    updateQWidget();
1852  }
1853  else if (event->key() == Qt::Key_Minus) { // zoom out
1854    fVP.SetZoomFactor(fVP.GetZoomFactor()/fDeltaZoom);
1855    updateQWidget();
1856  }
1857  // with no modifiers
1858  if (!event->modifiers()) {
1859    if (event->key() == Qt::Key_Down) { // go down
1860      G4MouseMoveEvent(0,1,0);
1861    }
1862    else if (event->key() == Qt::Key_Up) {  // go up
1863      G4MouseMoveEvent(0,-1,0);
1864    }
1865    if (event->key() == Qt::Key_Left) { // go left
1866      G4MouseMoveEvent(-1,0,0);
1867    }
1868    else if (event->key() == Qt::Key_Right) { // go right
1869      G4MouseMoveEvent(1,0,0);
1870    }
1871  }
1872  holdKeyEvent = false;
1873}
1874
1875/*
1876 
1877void MultiLayer::exportToSVG(const QString& fname)
1878{
1879  QPicture picture;
1880  QPainter p(&picture);
1881  for (int i=0;i<(int)graphsList->count();i++)
1882    {
1883      Graph *gr=(Graph *)graphsList->at(i);
1884      Plot *myPlot= (Plot *)gr->plotWidget();
1885     
1886      QPoint pos=gr->pos();
1887     
1888      int width=int(myPlot->frameGeometry().width());
1889      int height=int(myPlot->frameGeometry().height());
1890     
1891      myPlot->print(&p, QRect(pos,QSize(width,height)));
1892    }
1893 
1894  p.end();
1895  picture.save(fname, "svg");
1896}
1897*/
1898#endif
Note: See TracBrowser for help on using the repository browser.