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

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

last commit :suppresion du move button dans le menu contextuel, on garde juste le zoom et pick. Improvments for Qt3

  • Property svn:mime-type set to text/cpp
File size: 56.1 KB
RevLine 
[530]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//
[704]27// $Id: G4OpenGLQtViewer.cc,v 1.10 2008/01/30 10:54:13 lgarnier Exp $
[593]28// GEANT4 tag $Name:  $
[530]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
[707]38#define GEANT4_QT_DEBUG
[610]39
[530]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"
[564]48#include "G4Scene.hh"
[581]49#include "G4OpenGLQtExportDialog.hh"
[703]50#include "G4UnitsTable.hh"
[539]51#include "G4Qt.hh"
[569]52#include "G4UImanager.hh"
[702]53#include "G4UIcommandTree.hh"
[595]54#include <qapplication.h>
[599]55#include <qlayout.h>
[595]56#include <qdialog.h>
[599]57
58#if QT_VERSION >= 0x040000
[595]59#include <qmenu.h>
60#include <qimagewriter.h>
[599]61#else
62#include <qaction.h>
63#include <qwidgetlist.h>
64#include <qpopupmenu.h>
65#include <qimage.h>
66#endif
67
[595]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>
[530]75
[593]76
[530]77//////////////////////////////////////////////////////////////////////////////
78/**
[564]79   Implementation of virtual method of G4VViewer
80*/
[530]81void G4OpenGLQtViewer::SetView (
82)
83//////////////////////////////////////////////////////////////////////////////
84//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
85{
[608]86#ifdef GEANT4_QT_DEBUG
[542]87  printf("G4OpenGLQtViewer::SetView ++++++++++++++++++++\n");
[608]88#endif
[564]89  //   if(!fHDC) return;
90  //   if(!fHGLRC) return;
91  //   ::wglMakeCurrent(fHDC,fHGLRC);
92  //  fWindow->makeCurrent();
[579]93  G4OpenGLViewer::SetView ();
[608]94#ifdef GEANT4_QT_DEBUG
[542]95  printf("G4OpenGLQtViewer::SetView --------------------\n");
[608]96#endif
[530]97}
98
[673]99/**
100 * Set the viewport of the scene
101 */
102void G4OpenGLQtViewer::setupViewport(int aWidth, int aHeight)
103{
[709]104  int side = aWidth;
105  if (aHeight < aWidth) side = aHeight;
[673]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}
[530]113
114
115//////////////////////////////////////////////////////////////////////////////
116/**
[564]117   Implementation of virtual method of G4VViewer
118*/
[530]119void G4OpenGLQtViewer::ShowView (
120)
121//////////////////////////////////////////////////////////////////////////////
122//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
123{
[608]124#ifdef GEANT4_QT_DEBUG
[542]125  printf("G4OpenGLQtViewer::ShowView  +++++++++++++++++++++\n");
[608]126#endif
[579]127  if (!GLWindow) {
[638]128    G4cerr << "Visualization window not defined, please choose one before\n" << G4endl;
[579]129  } else {
[599]130#if QT_VERSION < 0x040000
131    GLWindow->setActiveWindow();
132#else
[579]133    GLWindow->activateWindow();
[599]134#endif
[608]135#ifdef GEANT4_QT_DEBUG
[579]136    printf("G4OpenGLQtViewer::ShowView -----------------------\n");
[608]137#endif
[579]138  }
[678]139  glFlush ();
[564]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  //   }
[530]146}
147
148
149
150//////////////////////////////////////////////////////////////////////////////
151void G4OpenGLQtViewer::CreateGLQtContext (
152)
153//////////////////////////////////////////////////////////////////////////////
154//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
155{
[608]156#ifdef GEANT4_QT_DEBUG
[530]157  printf("G4OpenGLQtViewer::CreateGLQtContext \n");
[608]158#endif
[530]159}
160
[564]161
[530]162//////////////////////////////////////////////////////////////////////////////
163void G4OpenGLQtViewer::CreateMainWindow (
[585]164 QGLWidget* glWidget
165)
[530]166//////////////////////////////////////////////////////////////////////////////
167//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
168{
169
[538]170  if(fWindow) return; //Done.
[608]171#ifdef GEANT4_QT_DEBUG
[564]172  printf("G4OpenGLQtViewer::CreateMainWindow glWidget\n");
[608]173#endif
[538]174
[539]175  // launch Qt if not
176  G4Qt* interactorManager = G4Qt::getInstance ();
177  //  G4UImanager* UI = G4UImanager::GetUIpointer();
178
[564]179  fWindow = glWidget ;
[543]180  //  fWindow->makeCurrent();
[538]181
[539]182  // create window
[569]183  if (((QApplication*)interactorManager->GetMainInteractor())) {
184    // look for the main window
185    bool found = false;
[599]186#if QT_VERSION < 0x040000
[631]187    // theses lines does nothing exept this one "GLWindow = new QDialog(0..."
[626]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
[599]200#else
[626]201    foreach (QWidget *widget, QApplication::allWidgets()) {
202      if ((found== false) && (widget->inherits("QMainWindow"))) {
[650]203        GLWindow = new QDialog(0,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
[626]204        found = true;
205      }
206    }
[608]207#endif
[612]208
209#if QT_VERSION < 0x040000
[610]210    glWidget->reparent(GLWindow,0,QPoint(0,0)); 
[612]211#else
212    glWidget->setParent(GLWindow); 
213#endif
[599]214
[569]215    if (found==false) {
[608]216#ifdef GEANT4_QT_DEBUG
[579]217      printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist, but not found\n");
[608]218#endif
[569]219      GLWindow = new QDialog();
220    }
[539]221  } else {
[608]222#ifdef GEANT4_QT_DEBUG
[579]223    printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n");
[608]224#endif
[539]225    GLWindow = new QDialog();
226  }
227
[599]228  QHBoxLayout *mainLayout = new QHBoxLayout(GLWindow);
[564]229
[539]230  mainLayout->addWidget(fWindow);
[599]231
232#if QT_VERSION < 0x040000
233  GLWindow->setCaption( tr( "QGl Viewer" ));
234#else
[539]235  GLWindow->setLayout(mainLayout);
[599]236  GLWindow->setWindowTitle(tr("QGl Viewer"));
237#endif
[564]238  GLWindow->resize(300, 300);
[570]239  GLWindow->move(900,300);
[539]240  GLWindow->show();
[530]241 
[579]242  // delete the pointer if close this
243  //  GLWindow->setAttribute(Qt::WA_DeleteOnClose);
244
[610]245#if QT_VERSION >= 0x040000
[579]246  QObject ::connect(GLWindow,
247                    SIGNAL(rejected()),
248                    this,
249                    SLOT(dialogClosed()));
[610]250#endif
[579]251
[564]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 ();
[530]258
[564]259  if(!fWindow) return;
[608]260#ifdef GEANT4_QT_DEBUG
[564]261  printf("G4OpenGLQtViewer::CreateMainWindow glWidget END\n");
[608]262#endif
[530]263
[564]264  if (!fContextMenu)
265    createPopupMenu();
[530]266
[564]267}
[530]268
[610]269#if QT_VERSION >= 0x040000
[579]270/**  Close the dialog and set the pointer to NULL
271 */
272void G4OpenGLQtViewer::dialogClosed() {
[610]273#ifdef GEANT4_QT_DEBUG
274  printf("G4OpenGLQtViewer::dialogClosed END\n");
275#endif
276  //  GLWindow = NULL;
[579]277}
[610]278#endif
[579]279
[564]280//////////////////////////////////////////////////////////////////////////////
281G4OpenGLQtViewer::G4OpenGLQtViewer (
282                                    G4OpenGLSceneHandler& scene
283                                    )
284  :G4VViewer (scene, -1)
285  ,G4OpenGLViewer (scene)
286  ,fWindow(0)
287  ,fContextMenu(0)
[696]288  ,fMouseAction(STYLE1)
289  ,fDeltaSceneTranslation(1/100)
[707]290  ,fDeltaZoom(1.1)
[702]291  ,holdKeyEvent(false)
[564]292{
[608]293#ifdef GEANT4_QT_DEBUG
[564]294  printf("G4OpenGLQtViewer::G4OpenGLQtViewer \n");
[608]295#endif
[530]296}
297
298//////////////////////////////////////////////////////////////////////////////
[564]299G4OpenGLQtViewer::~G4OpenGLQtViewer (
[539]300)
301//////////////////////////////////////////////////////////////////////////////
302//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
303{
[608]304#ifdef GEANT4_QT_DEBUG
[564]305  printf("G4OpenGLQtViewer::~G4OpenGLQtViewer \n");
[608]306#endif
[564]307}
[539]308
309
[564]310/**
311   Create a popup menu for the widget. This menu is activated by right-mouse click
312*/
313void G4OpenGLQtViewer::createPopupMenu()    {
[539]314
[599]315#if QT_VERSION < 0x040000
316  fContextMenu = new QPopupMenu( GLWindow,"All" );
317#else
[564]318  fContextMenu = new QMenu("All");
[599]319#endif
[539]320
[599]321#if QT_VERSION < 0x040000
322  QPopupMenu *mMouseAction = new QPopupMenu( fContextMenu );
[678]323  fContextMenu->insertItem("&Mouse actions");
[617]324#else
[678]325  QMenu *mMouseAction = fContextMenu->addMenu("&Mouse actions");
[617]326#endif
[599]327
[678]328#if QT_VERSION < 0x040000
329  // === Mouse menu ===
[599]330
[678]331  fMouseRotate = new QPopupMenu(mMouseAction);
332  mMouseAction->insertItem("&Rotate",fMouseRotate);
333
334  mMouseAction->setCheckable(true);
335  fMouseRotate->setCheckable(true);
336
[681]337  fMousePick = new QPopupMenu(mMouseAction);
338  mMouseAction->insertItem("&Pick",fMousePick);
339  fMousePick->setCheckable(true);
340
[707]341  fMouseShortcuts = new QPopupMenu(mMouseAction);
342  mMouseAction->insertItem("&Show Shortcuts",fMouseShortcuts);
343  fMouseShortcuts->setCheckable(true);
344
[599]345#else
346  // === Mouse menu ===
347
[678]348  fMouseRotate = mMouseAction->addAction("Rotate");
349  fMouseRotate->setCheckable(true);
350
[681]351  fMousePick = mMouseAction->addAction("Pick");
352  fMousePick->setCheckable(true);
[707]353
354  fMouseShortcuts = mMouseAction->addAction("Show Shortcuts");
355  fMouseShortcuts->setCheckable(true);
[599]356#endif
357
[564]358  // INIT mMouse
[678]359#if QT_VERSION < 0x040000
[709]360  fMouseRotate->setItemChecked(0,true);
[564]361
[678]362  QObject ::connect(fMouseRotate,
363                    SIGNAL(activated(int)),
364                    this,
365                    SLOT(actionMouseRotate()));
366
[707]367  QObject ::connect(fMousePick,
[678]368                    SIGNAL(activated(int)),
369                    this,
[707]370                    SLOT(actionMousePick()));
[678]371
[707]372  QObject ::connect(fMouseShortcuts,
[678]373                    SIGNAL(activated(int)),
374                    this,
[707]375                    SLOT(actionMouseShortcuts()));
[678]376
377#else
378  fMouseRotate->setChecked(true);
379
380  QObject ::connect(fMouseRotate,
381                    SIGNAL(triggered(bool)),
382                    this,
383                    SLOT(actionMouseRotate()));
384
[707]385  QObject ::connect(fMousePick,
[678]386                    SIGNAL(triggered(bool)),
387                    this,
[707]388                    SLOT(actionMousePick()));
[678]389
[707]390  QObject ::connect(fMouseShortcuts,
[678]391                    SIGNAL(triggered(bool)),
392                    this,
[707]393                    SLOT(actionMouseShortcuts()));
[678]394#endif
395
[599]396#if QT_VERSION < 0x040000
397  // === Style Menu ===
398  QPopupMenu *mStyle = new QPopupMenu(fContextMenu);
399
400  QPopupMenu *mRepresentation = new QPopupMenu(fContextMenu);
401
[703]402  QPopupMenu *mProjection = new QPopupMenu(fContextMenu);
[702]403
[617]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);
[702]407
408  QAction *ortho = new QAction("&Orthographic","&Orthographic",CTRL+Key_O,mProjection);
409  QAction *perspective = new QAction("&Perspective","&Perspective",CTRL+Key_P,mProjection);
[617]410#else
[599]411  QAction *polyhedron = new QAction("&Polyhedron",CTRL+Key_P,mRepresentation);
412  QAction *nurbs = new QAction("&NURBS",CTRL+Key_N,mRepresentation);
[702]413
414  QAction *ortho = new QAction("&Orthographic",CTRL+Key_O,mProjection);
415  QAction *perspective = new QAction("&Perspective",CTRL+Key_P,mProjection);
[617]416#endif
[599]417  polyhedron->addTo(mRepresentation);
418  nurbs->addTo(mRepresentation);
419
[702]420  ortho->addTo(mProjection);
421  perspective->addTo(mProjection);
422
[599]423  mStyle->insertItem("&Representation",mRepresentation);
[702]424  mStyle->insertItem("&Projection",mProjection);
[599]425  fContextMenu->insertItem("&Style",mStyle);
426
[702]427
[599]428#else
429  // === Style Menu ===
[564]430  QMenu *mStyle = fContextMenu->addMenu("&Style");
431
432  QMenu *mRepresentation = mStyle->addMenu("&Representation");
[703]433  QMenu *mProjection = mStyle->addMenu("&Projection");
[632]434  QAction *polyhedron = mRepresentation->addAction("Polyhedron");
[564]435  QAction *nurbs = mRepresentation->addAction("NURBS");
[702]436
[703]437  QAction *ortho = mProjection->addAction("Orthographic");
438  QAction *perspective = mProjection->addAction("Persepective");
[599]439#endif
[702]440
441  // INIT mRepresentation
[564]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);
[539]448  } else {
[564]449    mRepresentation->clear();
[539]450  }
451
[702]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  }
[539]458
[599]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 ===
[564]484  QMenu *mDrawing = mStyle->addMenu("&Drawing");
[599]485
[564]486  fDrawingWireframe = mDrawing->addAction("Wireframe");
487  fDrawingWireframe->setCheckable(true);
[599]488
[564]489  fDrawingLineRemoval = mDrawing->addAction("Hidden line removal");
490  fDrawingLineRemoval->setCheckable(true);
[599]491
[564]492  fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal");
493  fDrawingSurfaceRemoval->setCheckable(true);
[599]494
[564]495  fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal");
496  fDrawingLineSurfaceRemoval->setCheckable(true);
[599]497#endif
[564]498  // INIT Drawing
499  G4ViewParameters::DrawingStyle d_style;
500  d_style = fVP.GetDrawingStyle();
501 
[599]502#if QT_VERSION < 0x040000
[564]503  if (d_style == G4ViewParameters::wireframe) {
[599]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  }
[610]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()));
[599]536#else
537  if (d_style == G4ViewParameters::wireframe) {
[564]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  }
[565]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()));
[610]564#endif
[564]565
566
[610]567
[599]568#if QT_VERSION < 0x040000
569  QPopupMenu *mBackground = new QPopupMenu(mStyle);
570  mStyle->insertItem("&Background color",mBackground);
571
[617]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
[599]576  QAction *white = new QAction("&White",CTRL+Key_W,mBackground);
577  QAction *black =  new QAction("&Black",CTRL+Key_B,mBackground);
[617]578#endif
[599]579  white->addTo(mBackground);
580  black->addTo(mBackground);
581
582#else
[564]583  QMenu *mBackground = mStyle->addMenu("&Background color");
584  QAction *white = mBackground->addAction("White");
585  QAction *black = mBackground->addAction("Black");
[599]586
587#endif
[564]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
[599]597#if QT_VERSION < 0x040000
598  // === Action Menu ===
599  QPopupMenu *mActions = new QPopupMenu(fContextMenu);
600  fContextMenu->insertItem("&Actions",mActions);
601
[617]602#if QT_VERSION < 0x030200
603  QAction *createEPS =  new QAction("&Save as ...","&Save as ...",CTRL+Key_S,mActions);
604#else
[599]605  QAction *createEPS =  new QAction("&Save as ...",CTRL+Key_S,mActions);
[617]606#endif
[599]607  createEPS->addTo(mActions);
[610]608  QObject ::connect(createEPS,
609                    SIGNAL(activated()),
610                    this,
611                    SLOT(actionCreateEPS()));
[599]612
613#else
614  // === Action Menu ===
[564]615  QMenu *mActions = fContextMenu->addMenu("&Actions");
[568]616  QAction *createEPS = mActions->addAction("Save as ...");
[565]617  QObject ::connect(createEPS,
[566]618                    SIGNAL(triggered()),
[565]619                    this,
620                    SLOT(actionCreateEPS()));
[610]621#endif
[564]622
623
[610]624
[599]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
[617]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
[599]637  QAction *transparencyOn = new QAction("&On",CTRL+Key_O,mTransparency);
638  QAction *transparencyOff = new QAction("&Off",CTRL+Key_F,mTransparency);
[617]639#endif
[599]640  transparencyOn->addTo(mTransparency);
641  transparencyOff->addTo(mTransparency);
642
643#else
644  // === Special Menu ===
[564]645  QMenu *mSpecial = fContextMenu->addMenu("S&pecial");
[599]646  QMenu *mTransparency = mSpecial->addMenu("Transparency");
647  QAction *transparencyOn = mTransparency->addAction("On");
648  QAction *transparencyOff = mTransparency->addAction("Off");
649#endif
650
[564]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
[599]660#if QT_VERSION < 0x040000
661  QPopupMenu *mAntialiasing = new QPopupMenu(mSpecial);
662  mSpecial->insertItem("Antialiasing",mAntialiasing);
663
[617]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
[599]668  QAction *antialiasingOn = new QAction("&On",CTRL+Key_O,mAntialiasing);
669  QAction *antialiasingOff = new QAction("&Off",CTRL+Key_F,mAntialiasing);
[617]670#endif
[599]671  antialiasingOn->addTo(mAntialiasing);
672  antialiasingOff->addTo(mAntialiasing);
673
674#else
[564]675  QMenu *mAntialiasing = mSpecial->addMenu("Antialiasing");
676  QAction *antialiasingOn = mAntialiasing->addAction("On");
677  QAction *antialiasingOff = mAntialiasing->addAction("Off");
[599]678#endif
679
[564]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
[599]688#if QT_VERSION < 0x040000
689  QPopupMenu *mHaloing = new QPopupMenu(mSpecial);
690  mSpecial->insertItem("Haloing",mHaloing);
691
[617]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
[599]696  QAction *haloingOn = new QAction("&On",CTRL+Key_O,mHaloing);
697  QAction *haloingOff = new QAction("&Off",CTRL+Key_F,mHaloing);
[617]698#endif
[599]699  haloingOn->addTo(mHaloing);
700  haloingOff->addTo(mHaloing);
701#else
[564]702  QMenu *mHaloing = mSpecial->addMenu("Haloing");
703  QAction *haloingOn = mHaloing->addAction("On");
704  QAction *haloingOff = mHaloing->addAction("Off");
[599]705#endif
[564]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
[599]714#if QT_VERSION < 0x040000
715  QPopupMenu *mAux = new QPopupMenu(mSpecial);
716  mSpecial->insertItem("Auxiliairy edges",mAux);
717
[617]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
[599]722  QAction *auxOn = new QAction("&On",CTRL+Key_O,mAux);
723  QAction *auxOff = new QAction("&Off",CTRL+Key_F,mAux);
[617]724#endif
[599]725  auxOn->addTo(mAux);
726  auxOff->addTo(mAux);
727
728#else
[564]729  QMenu *mAux = mSpecial->addMenu("Auxiliary edges");
730  QAction *auxOn = mAux->addAction("On");
731  QAction *auxOff = mAux->addAction("Off");
[599]732#endif
[564]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
[617]740#if QT_VERSION >= 0x030200
[599]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
[564]750  QMenu *mFullScreen = mSpecial->addMenu("Full screen");
751  QAction *fullOn = mFullScreen->addAction("On");
752  QAction *fullOff = mFullScreen->addAction("Off");
[599]753#endif
[704]754  createRadioAction(fullOn,fullOff,SLOT(toggleFullScreen()),2);
[617]755#endif
[564]756
757}
758
759void G4OpenGLQtViewer::manageContextMenuEvent(QContextMenuEvent *e)
760{
[579]761  if (!GLWindow) {
[638]762    G4cerr << "Visualization window not defined, please choose one before\n" << G4endl;
[579]763  } else {
[539]764 
[579]765    if (!fContextMenu)
766      createPopupMenu();
767   
768    // launch menu
769    if ( fContextMenu ) {
770      fContextMenu->exec( e->globalPos() );
771      //    delete fContextMenu;
772    }
[564]773  }
774  e->accept();
775}
[539]776
777
[564]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*/
[599]786#if QT_VERSION < 0x040000
[564]787void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) {
788
[599]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   
[610]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()));
[599]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
[564]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}
[599]824#endif
[564]825
826/**
[678]827   Slot activate when mouseAction->rotate menu is set
828 */
829void G4OpenGLQtViewer::actionMouseRotate() {
[696]830  emit toggleMouseAction(STYLE1);
[678]831}
832
833
834/**
[707]835   Slot activate when mouseAction->zoom menu is set
[678]836 */
[707]837void G4OpenGLQtViewer::actionMousePick() {
[678]838#ifdef GEANT4_QT_DEBUG
[707]839  printf("G4OpenGLQtViewer::actionMousePick \n");
[678]840#endif
[696]841  emit toggleMouseAction(STYLE3);
[678]842}
843
844/**
[681]845   Slot activate when mouseAction->zoom menu is set
846 */
[707]847void G4OpenGLQtViewer::actionMouseShortcuts() {
[681]848#ifdef GEANT4_QT_DEBUG
[707]849  printf("G4OpenGLQtViewer::actionMouseShortcuts \n");
[681]850#endif
[707]851  emit toggleMouseAction(STYLE3);
[681]852}
853
854/**
[564]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/**
[678]884   Slot activated when mouse action is toggle
[696]885   @param aAction : STYLE1, STYLE2, STYLE3
[678]886 */
887void G4OpenGLQtViewer::toggleMouseAction(mouseActions aAction) {
888 
[707]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;
[696]896    G4cout << "Press +/- to zoom into volume\n" << G4endl;
[678]897#if QT_VERSION < 0x040000
898    fMouseRotate->setItemChecked (0,true);
[681]899    fMousePick->setItemChecked (0,false);
[707]900    fMouseShortcuts->setItemChecked (0,false);
[678]901#else
902    fMouseRotate->setChecked (true);
[681]903    fMousePick->setChecked (false);
[707]904    fMouseShortcuts->setChecked (false);
[678]905#endif
[696]906    fMouseAction = STYLE1;
[681]907    fVP.SetPicking(false);
[707]908  } else  if (aAction == STYLE2) { //pick
909    G4cout << "Click and pick \n" << G4endl;
[678]910#if QT_VERSION < 0x040000
911    fMouseRotate->setItemChecked (0,false);
[707]912    fMousePick->setItemChecked (0,true);
[678]913#else
914    fMouseRotate->setChecked (false);
[707]915    fMousePick->setChecked (true);
[678]916#endif
[707]917    fVP.SetPicking(true);
[696]918    fMouseAction = STYLE2;
[707]919  } else  if (aAction == STYLE3) {  // display shortcuts
[678]920#if QT_VERSION < 0x040000
921    fMouseRotate->setItemChecked (0,false);
[681]922    fMousePick->setItemChecked (0,false);
[707]923    fMouseShortcuts->setItemChecked (0,true);
[678]924#else
925    fMouseRotate->setChecked (false);
[681]926    fMousePick->setChecked (false);
[707]927    fMouseShortcuts->setChecked (true);
[678]928#endif
[696]929    fMouseAction = STYLE3;
[681]930    fVP.SetPicking(false);
[707]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;
[678]939  }
940
941}
942/**
[565]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
[564]951 */
952void G4OpenGLQtViewer::toggleDrawingAction(int aAction) {
953
954  G4ViewParameters::DrawingStyle d_style;
[539]955 
956
[564]957  if (aAction ==1) {
[600]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
[564]964    fDrawingWireframe->setChecked (true);
965    fDrawingLineRemoval->setChecked (false);
966    fDrawingSurfaceRemoval->setChecked (false);
967    fDrawingLineSurfaceRemoval->setChecked (false);
[600]968#endif
[564]969
970    d_style = G4ViewParameters::wireframe;
971
972  } else  if (aAction ==2) {
[600]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
[564]979    fDrawingWireframe->setChecked (false);
980    fDrawingLineRemoval->setChecked (true);
981    fDrawingSurfaceRemoval->setChecked (false);
982    fDrawingLineSurfaceRemoval->setChecked (false);
[600]983#endif
[564]984
985    d_style = G4ViewParameters::hlr;
986
987  } else  if (aAction ==3) {
[600]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
[564]994    fDrawingWireframe->setChecked (false);
995    fDrawingLineRemoval->setChecked (false);
996    fDrawingSurfaceRemoval->setChecked (true);
997    fDrawingLineSurfaceRemoval->setChecked (false);
[600]998#endif
[564]999
1000    d_style = G4ViewParameters::hsr;
1001
1002  } else  if (aAction ==4) {
[600]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
[564]1009    fDrawingWireframe->setChecked (false);
1010    fDrawingLineRemoval->setChecked (false);
1011    fDrawingSurfaceRemoval->setChecked (false);
1012    fDrawingLineSurfaceRemoval->setChecked (true);
[600]1013#endif
[564]1014    d_style = G4ViewParameters::hlhsr;
1015  }
1016  fVP.SetDrawingStyle(d_style);
1017
1018  updateQWidget();
[608]1019#ifdef GEANT4_QT_DEBUG
[564]1020  printf("G4OpenGLQtViewer::toggleDrawingAction\n");
[608]1021#endif
[539]1022}
1023
[564]1024
1025/**
1026   SLOT Activate by a click on the representation menu
[565]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
[564]1031   @param check : 1 polyhedron, 0 nurbs
[565]1032   @see G4OpenGLStoredQtViewer::DrawView
1033   @see G4XXXStoredViewer::CompareForKernelVisit
[564]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();
[530]1046}
1047
[564]1048/**
[702]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 {
[703]1063
[702]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
[703]1076    G4UIparameter * angleParam = NULL;
[702]1077    for(G4int i=0;  i<command->GetParameterEntries(); i++)
1078    {
1079      if( command->GetParameter(i)->GetParameterName() == "field-half-angle" ) {
[703]1080        angleParam = command->GetParameter(i);
[702]1081      }
1082    }
[703]1083    if (!angleParam)
[702]1084      return;
[703]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  } 
[702]1107  updateQWidget();
1108}
1109
1110
1111/**
[564]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();
[530]1130}
1131
[564]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}
[530]1146
[564]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);
[530]1163  }
[564]1164
1165  updateQWidget();
1166}
1167
1168/**
1169   SLOT Activate by a click on the haloing menu
1170@param check : 1 , 0
[530]1171*/
[564]1172//FIXME : I SEE NOTHING...
1173void G4OpenGLQtViewer::toggleHaloing(bool check) {
1174  if (check) {
1175    haloing_enabled = false;
1176  } else {
1177    haloing_enabled = true;
1178  }
[530]1179
[564]1180  updateQWidget();
[530]1181
[564]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*/
[704]1202void G4OpenGLQtViewer::toggleFullScreen() {
[617]1203#if QT_VERSION >= 0x030200
[564]1204  GLWindow->setWindowState(GLWindow->windowState() ^ Qt::WindowFullScreen);
[617]1205#else
[638]1206  G4cerr << "This version of G4UI Could not generate the selected format\n" << G4endl;
[617]1207#endif
[564]1208}
1209
[565]1210void G4OpenGLQtViewer::actionCreateEPS() {
[580]1211  QString filters;
[600]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
[580]1220  QList<QByteArray> formats =  QImageWriter::supportedImageFormats ();
1221  for (int i = 0; i < formats.size(); ++i) {
[600]1222    filters +=formats.at(i) + ";;";
[580]1223  }
[600]1224#endif
[588]1225  filters += "eps;;";
1226  filters += "ps;;";
1227  filters += "pdf";
[639]1228  QString* selectedFormat = new QString();
[600]1229#if QT_VERSION < 0x040000
1230  QString nomFich =  QFileDialog::getSaveFileName ( ".",
1231                                                    filters,
1232                                                    GLWindow,
1233                                                    "Save file dialog",
1234                                                    tr("Save as ..."),
[639]1235                                                    selectedFormat );
[600]1236#else
[580]1237  QString nomFich =  QFileDialog::getSaveFileName ( GLWindow,
1238                                                    tr("Save as ..."),
1239                                                    ".",
[582]1240                                                    filters,
[639]1241                                                    selectedFormat );
[600]1242#endif
[580]1243  // bmp jpg jpeg png ppm xbm xpm
[582]1244  if (nomFich == "") {
1245    return;
1246  }
[600]1247#if QT_VERSION < 0x040000
[639]1248  nomFich += "."+QString(selectedFormat->ascii());
1249  QString format = selectedFormat->lower();
[600]1250#else
[639]1251  nomFich += "."+QString(selectedFormat->toStdString().c_str());
1252  QString format = selectedFormat->toLower();
[600]1253#endif
[656]1254  G4OpenGLQtExportDialog* exportDialog= new G4OpenGLQtExportDialog(GLWindow,format,fWindow->height(),fWindow->width());
[585]1255  if(  exportDialog->exec()) {
[593]1256
1257    QImage image;
[655]1258    bool res = false;
[635]1259    if ((exportDialog->getWidth() !=fWindow->width()) ||
1260        (exportDialog->getHeight() !=fWindow->height())) {
[655]1261      if (format != QString("eps")) {
[638]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;
[585]1263     
[635]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();
[593]1277      //      glResized->resize(exportDialog->getWidth()*2,exportDialog->getHeight()*2);
1278      //      image = glResized->grabFrameBuffer();
[655]1279      }     
[635]1280    } else {
1281      image = fWindow->grabFrameBuffer();
1282    }   
[639]1283    if (format == QString("eps")) {
[652]1284      if (exportDialog->getVectorEPS()) {
[655]1285        res = generateVectorEPS(nomFich,exportDialog->getWidth(),exportDialog->getHeight(),image);
[652]1286      } else {
[655]1287        res = generateEPS(nomFich,exportDialog->getNbColor(),image);
[652]1288      }
[639]1289    } else if ((format == "ps") || (format == "pdf")) {
[655]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")) {
[639]1302#if QT_VERSION < 0x040000
[655]1303      res = image.save(nomFich,selectedFormat->ascii(),exportDialog->getSliderValue());
[639]1304#else
[655]1305      res = image.save(nomFich,0,exportDialog->getSliderValue());
[639]1306#endif
[585]1307    } else {
[638]1308      G4cerr << "This version of G4UI Could not generate the selected format\n" << G4endl;
[585]1309    }
[655]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
[656]1318      G4cout << "File "<<nomFich.ascii()<<" has been saved \n" << G4endl;
[655]1319#else
[656]1320      G4cout << "File "<<nomFich.toStdString().c_str()<<" has been saved \n" << G4endl;
[655]1321#endif
1322    }
[585]1323   
1324  } else { // cancel selected
1325    return;
[568]1326  }
[580]1327 
[608]1328#ifdef GEANT4_QT_DEBUG
[565]1329  printf("G4OpenGLQtViewer::actionCreateEPS() \n");
[608]1330#endif
[565]1331}
1332
[580]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
[565]1335
[580]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();
[565]1344
[580]1345  picture.save(fname, "svg");
1346}
1347*/
1348
1349
1350
1351
[564]1352/**
1353   Save the current mouse press point
1354   @param p mouse click point
1355*/
1356void G4OpenGLQtViewer::G4MousePressEvent(QPoint p)
1357{
[696]1358  fLastPos = p;
[707]1359  if (fMouseAction == STYLE2){  // pick
[681]1360    Pick(p.x(),p.y());
1361  }
[564]1362}
1363
[696]1364
[564]1365/**
1366   @param pos_x mouse x position
1367   @param pos_y mouse y position
1368   @param mButtons mouse button active
1369*/
[599]1370
1371#if QT_VERSION < 0x040000
[696]1372void G4OpenGLQtViewer::G4MouseEvent(int pos_x, int pos_y,Qt::ButtonState mButtons)
[599]1373#else
[696]1374void G4OpenGLQtViewer::G4MouseEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons)
[599]1375#endif
[564]1376{
[703]1377  int dx = fLastPos.x() - pos_x;
1378  int dy = fLastPos.y() - pos_y;
[696]1379  if (fMouseAction == STYLE1) {  // rotate
[564]1380    if (mButtons & Qt::LeftButton) {
[696]1381      G4MouseRotateEvent(dx,dy);
[564]1382    }
1383  }
[696]1384  fLastPos = QPoint(pos_x, pos_y);
[564]1385}
1386
[696]1387/**
1388   @param dx delta mouse x position
1389   @param dy delta mouse y position
1390*/
1391
1392void G4OpenGLQtViewer::G4MouseMoveEvent(int dx, int dy, int dz)
1393{
[707]1394  int deltaX =
1395GLenum clip = glGet(GL_CLIP_PLANE);
1396  int deltaY = ;
1397
1398
[696]1399  G4Point3D stp
1400    = GetSceneHandler()->GetScene()->GetStandardTargetPoint();
1401 
1402  G4Point3D tp = stp + fVP.GetCurrentTargetPoint ();
1403 
1404  const G4Vector3D& upVector = fVP.GetUpVector ();
1405  const G4Vector3D& vpVector = fVP.GetViewpointDirection ();
1406 
1407  G4Vector3D unitRight = (upVector.cross (vpVector)).unit();
1408  G4Vector3D unitUp    = (vpVector.cross (unitRight)).unit();
1409 
1410#ifdef GEANT4_QT_DEBUG
1411  G4cout << fVP<<G4endl;
1412  printf("Mouse event Target Point : %f %f %f\n",tp.x(),tp.y(),tp.z());
1413  printf("Mouse event upVector : %f %f %f\n",upVector.x(),upVector.y(),upVector.z());
1414  printf("Mouse event vpVector Point : %f %f %f\n",vpVector.x(),vpVector.y(),vpVector.z());
1415  printf("Mouse event unitRight Point : %f %f %f\n",unitRight.x(),unitRight.y(),unitRight.z());
1416  printf("Mouse event unitUp Point : %f %f %f\n",unitUp.x(),unitUp.y(),unitUp.z());
1417#endif
1418  tp += -dx * unitRight + dy * unitUp + dz * vpVector;
1419  fVP.SetCurrentTargetPoint (tp - stp);
1420 
1421  updateQWidget();
1422}
1423
1424
1425/**
1426   @param dx delta mouse x position
1427   @param dy delta mouse y position
1428*/
1429
1430void G4OpenGLQtViewer::G4MouseRotateEvent(int dx, int dy)
1431{
1432  //phi spin stuff here
1433 
1434  G4Vector3D vp = fVP.GetViewpointDirection ().unit ();
1435  G4Vector3D up = fVP.GetUpVector ().unit ();
1436 
1437  G4Vector3D yprime = (up.cross(vp)).unit();
1438  G4Vector3D zprime = (vp.cross(yprime)).unit();
1439 
1440  G4double delta_alpha;
1441  G4double delta_theta;
1442 
1443  if (fVP.GetLightsMoveWithCamera()) {
1444    delta_alpha = dy;
1445    delta_theta = -dx;
1446  } else {
1447    delta_alpha = -dy;
1448    delta_theta = dx;
1449  }   
1450 
1451  delta_alpha *= deg;
1452  delta_theta *= deg;
1453 
1454  G4Vector3D new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime;
1455 
1456  G4Vector3D new_up;
1457  if (fVP.GetLightsMoveWithCamera()) {
1458    new_up = (new_vp.cross(yprime)).unit();
1459    fVP.SetUpVector(new_up);
1460  } else {
1461    new_up = up;
1462  }
1463  ////////////////
1464  // Rotates by fixed azimuthal angle delta_theta.
1465 
1466  G4double cosalpha = new_up.dot (new_vp.unit());
1467  G4double sinalpha = std::sqrt (1. - std::pow (cosalpha, 2));
1468  yprime = (new_up.cross (new_vp.unit())).unit ();
1469  G4Vector3D xprime = yprime.cross (new_up);
1470  // Projection of vp on plane perpendicular to up...
1471  G4Vector3D a1 = sinalpha * xprime;
1472  // Required new projection...
1473  G4Vector3D a2 =
1474    sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime);
1475  // Required Increment vector...
1476  G4Vector3D delta = a2 - a1;
1477  // So new viewpoint is...
1478  G4Vector3D viewPoint = new_vp.unit() + delta;
1479 
1480  fVP.SetViewAndLights (viewPoint);
1481  updateQWidget();
1482 
1483}
1484
[660]1485/** This is the benning of a rescale function. It does nothing for the moment
1486    @param aWidth : new width
1487    @param aHeight : new height
1488*/
[585]1489void G4OpenGLQtViewer::rescaleImage(
1490 int aWidth
1491,int aHeight
1492){
[608]1493#ifdef GEANT4_QT_DEBUG
[586]1494  printf("should rescale \n");
[608]1495#endif
[660]1496  GLfloat* feedback_buffer;
1497  GLint returned;
1498  FILE* file;
1499 
[673]1500//   feedback_buffer = new GLfloat[size];
1501//   glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer);
1502//   glRenderMode (GL_FEEDBACK);
[660]1503 
[673]1504//   glViewport (0, 0, aWidth, aHeight);
1505//   DrawView();
1506//   returned = glRenderMode (GL_RENDER);
[660]1507
[585]1508}
[586]1509
1510/**
[652]1511   Generate Vectorial Encapsulated Postscript form image
[586]1512   @param aFilename : name of file
1513   @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha
1514   @param aImage : Image to print
1515*/
[652]1516bool G4OpenGLQtViewer::generateVectorEPS (
1517 QString aFilename
1518,int aWidth
1519,int aHeight
1520,QImage aImage
1521)
1522{
1523  // Print vectored PostScript
1524 
1525  G4int size = 5000000;
1526
1527  GLfloat* feedback_buffer;
1528  GLint returned;
1529  FILE* file;
1530 
1531  feedback_buffer = new GLfloat[size];
1532  glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer);
1533  glRenderMode (GL_FEEDBACK);
1534 
[709]1535  int side = aWidth;
1536  if (aHeight < aWidth) side = aHeight;
[675]1537  glViewport((aWidth - side) / 2, (aHeight - side) / 2, side, side);
[652]1538  DrawView();
1539
1540  returned = glRenderMode (GL_RENDER);
1541 
1542 
1543#if QT_VERSION < 0x040000
1544  file = fopen (aFilename.ascii(), "w");
1545#else
1546  file = fopen (aFilename.toStdString().c_str(), "w");
1547#endif
1548  if (file) {
1549    spewWireframeEPS (file, returned, feedback_buffer, "rendereps");
1550  } else {
[658]1551#if QT_VERSION < 0x040000
[673]1552    G4cerr << "Could not open "<< aFilename.ascii()<<"\n" << G4endl;
[658]1553#else
[673]1554    G4cerr << "Could not open "<< aFilename.toStdString().c_str()<<"\n" << G4endl;
[658]1555#endif
[652]1556  }
1557 
1558  delete[] feedback_buffer;
1559
1560  return true;
1561}
1562
1563/**
1564   Generate Encapsulated Postscript form image
1565   @param aFilename : name of file
1566   @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha
1567   @param aImage : Image to print
1568*/
[588]1569bool G4OpenGLQtViewer::generateEPS (
[586]1570 QString aFilename
1571,int aInColor
1572,QImage aImage
1573)
1574{
[587]1575  // FIXME
[608]1576#ifdef GEANT4_QT_DEBUG
[586]1577  printf("saving EPS\n");
[608]1578#endif
[586]1579
1580  FILE* fp;
[587]1581
[649]1582  if (aImage.bits () == NULL)
[588]1583    return false;
[586]1584 
[600]1585#if QT_VERSION < 0x040000
1586  fp = fopen (aFilename.ascii(), "w");
1587#else
[602]1588  fp = fopen (aFilename.toStdString().c_str(), "w");
[600]1589#endif
[586]1590  if (fp == NULL) {
[588]1591    return false;
[586]1592  }
1593 
1594  fprintf (fp, "%%!PS-Adobe-2.0 EPSF-1.2\n");
[600]1595#if QT_VERSION < 0x040000
1596  fprintf (fp, "%%%%Title: %s\n", aFilename.ascii());
1597#else
[602]1598  fprintf (fp, "%%%%Title: %s\n", aFilename.toStdString().c_str());
[600]1599#endif
[586]1600  fprintf (fp, "%%%%Creator: OpenGL pixmap render output\n");
[587]1601  fprintf (fp, "%%%%BoundingBox: 0 0 %d %d\n", aImage.width(), aImage.height());
[586]1602  fprintf (fp, "%%%%EndComments\n");
1603  fprintf (fp, "gsave\n");
1604  fprintf (fp, "/bwproc {\n");
1605  fprintf (fp, "    rgbproc\n");
1606  fprintf (fp, "    dup length 3 idiv string 0 3 0 \n");
1607  fprintf (fp, "    5 -1 roll {\n");
1608  fprintf (fp, "    add 2 1 roll 1 sub dup 0 eq\n");
1609  fprintf (fp, "    { pop 3 idiv 3 -1 roll dup 4 -1 roll dup\n");
1610  fprintf (fp, "       3 1 roll 5 -1 roll } put 1 add 3 0 \n");
1611  fprintf (fp, "    { 2 1 roll } ifelse\n");
1612  fprintf (fp, "    }forall\n");
1613  fprintf (fp, "    pop pop pop\n");
1614  fprintf (fp, "} def\n");
1615  fprintf (fp, "systemdict /colorimage known not {\n");
1616  fprintf (fp, "   /colorimage {\n");
1617  fprintf (fp, "       pop\n");
1618  fprintf (fp, "       pop\n");
1619  fprintf (fp, "       /rgbproc exch def\n");
1620  fprintf (fp, "       { bwproc } image\n");
1621  fprintf (fp, "   }  def\n");
1622  fprintf (fp, "} if\n");
[587]1623  fprintf (fp, "/picstr %d string def\n", aImage.width() * aInColor);
1624  fprintf (fp, "%d %d scale\n", aImage.width(), aImage.height());
1625  fprintf (fp, "%d %d %d\n", aImage.width(), aImage.height(), 8);
1626  fprintf (fp, "[%d 0 0 %d 0 0]\n", aImage.width(), aImage.height());
[586]1627  fprintf (fp, "{currentfile picstr readhexstring pop}\n");
1628  fprintf (fp, "false %d\n", aInColor);
1629  fprintf (fp, "colorimage\n");
1630 
1631
[588]1632  int width = aImage.width();
1633  int height = aImage.height();
1634  int depth = aImage.depth();
1635  int size = width*height;
1636 
1637  if (depth == 1)
1638    size = (width+7)/8*height;
1639  else if (aInColor == 1)
1640    size = size*3;
1641 
1642  int i = 0;
[649]1643  //  if ( aInColor ==1 ) {
1644  // FIXME : L. Garnier. For the moment 10 dec 2007, I could not find a way
1645  // to save correctly grayscale Image. I mean that color or grayscale image
1646  // have the same file save size !
1647 
1648  /* } else*/ if (depth == 8) {
[588]1649    for(int y=height-1; y >=0 ; y--) {
1650      const uchar * s = aImage.scanLine(y);
1651      for(int x=0; x <width; x++) {
1652        QRgb rgb = aImage.color(s[x]);
1653        if (aInColor == 1) {
1654          fprintf (fp, " %02hx ",(unsigned char)qGray(rgb));
1655          i++;
1656        } else {
1657          fprintf (fp, " %02hx %02hx %02hx",
1658                   (unsigned char) qRed(rgb),
1659                   (unsigned char) qGreen(rgb),
1660                   (unsigned char) qBlue(rgb));
1661          i += 3;
1662        }
1663      }
[586]1664      fprintf (fp, "\n");
[588]1665    }
1666  } else {
[601]1667#if QT_VERSION < 0x040000
[649]1668    bool alpha = aImage.hasAlphaBuffer();
[601]1669#else
[588]1670    bool alpha = aImage.hasAlphaChannel();
1671    for(int y=height-1; y >=0 ; y--) {
1672      QRgb * s = (QRgb*)(aImage.scanLine(y));
1673      for(int x=0; x <width; x++) {
1674        QRgb rgb = (*s++);
1675        if (alpha && qAlpha(rgb) < 0x40) // 25% alpha, convert to white -
1676          rgb = qRgb(0xff, 0xff, 0xff);
1677        if (aInColor == 1) {
1678          fprintf (fp, " %02hx ",(unsigned char)qGray(rgb));
1679          i++;
1680        } else {
1681          fprintf (fp, " %02hx %02hx %02hx",
1682                   (unsigned char) qRed(rgb),
1683                   (unsigned char) qGreen(rgb),
1684                   (unsigned char) qBlue(rgb));
1685          i += 3;
1686        }
[587]1687      }
1688      fprintf (fp, "\n");
[588]1689    }
[601]1690#endif
1691
[586]1692  }
[588]1693
[586]1694  fprintf (fp, "grestore\n");
1695  fprintf (fp, "showpage\n");
1696  fclose (fp);
[588]1697
1698  return true;
[586]1699}
[588]1700/**
1701   Generate Postscript or PDF form image
1702   @param aFilename : name of file
1703   @param aInColor : numbers of colors : 1->BW 2->RGB
1704   @param aImage : Image to print
1705*/
1706bool G4OpenGLQtViewer::generatePS_PDF (
1707 QString aFilename
1708,int aInColor
1709,QImage aImage
1710)
1711{
[638]1712
[600]1713#if QT_VERSION < 0x040000
1714#ifdef Q_WS_MAC || Q_WS_X11
[588]1715  QPrinter printer;
1716  //  printer.setPageSize(pageSize);
1717  if (aInColor == 1) {
1718    printer.setColorMode(QPrinter::GrayScale);
1719  } else {
1720    printer.setColorMode(QPrinter::Color);
1721  }
1722
[600]1723  /* FIXME : I don't know which format it will save...
1724     if (aFilename.endsWith(".ps")) {
1725     printer.setOutputFormat(QPrinter::PostScriptFormat);
1726     } else {
1727     printer.setOutputFormat(QPrinter::PdfFormat);
1728     }
1729  */
1730  printer.setOutputFileName(aFilename);
1731  //  printer.setFullPage ( true);
1732  QPainter paint(&printer);
1733  paint.drawImage (0,0,aImage );
1734  paint.end();
1735#else
[638]1736  G4cerr << "This fonction is only supported on Mac OsX or X11 with Qt3. Full platform supported with Qt4\n" << G4endl;
[600]1737#endif
1738#else
1739  QPrinter printer;
1740  //  printer.setPageSize(pageSize);
[637]1741
1742  // FIXME : L. Garnier 4/12/07
1743  // This is not working, it does nothing. Image is staying in color mode
1744  // So I have desactivate the B/W button in GUI
1745  if ((!aImage.isGrayscale ()) &&(aInColor ==1 )) {
1746#if QT_VERSION < 0x040000
1747    aImage = aImage.convertDepth(1,Qt::MonoOnly);
1748#else
1749    aImage = aImage.convertToFormat ( aImage.format(), Qt::MonoOnly);
1750#endif
[600]1751  }
1752
[637]1753
[588]1754  if (aFilename.endsWith(".ps")) {
[606]1755#if QT_VERSION > 0x040200
[588]1756    printer.setOutputFormat(QPrinter::PostScriptFormat);
[606]1757#endif
[588]1758  } else {
[606]1759#if QT_VERSION > 0x040100
[588]1760    printer.setOutputFormat(QPrinter::PdfFormat);
[606]1761#endif
[588]1762  }
[606]1763#if QT_VERSION > 0x040100
[588]1764  printer.setOutputFileName(aFilename);
[606]1765#endif
[588]1766  //  printer.setFullPage ( true);
1767  QPainter paint(&printer);
[637]1768  paint.drawImage (0,0,aImage);
[588]1769  paint.end();
[600]1770#endif
[588]1771  return true;
1772}
1773
1774
[696]1775void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * event)
1776{
[702]1777  if (holdKeyEvent)
1778    return;
1779
1780  holdKeyEvent = true;
1781
[709]1782#if QT_VERSION < 0x040000
1783  if ((event->key() == Qt::Key_Down) && (event->state() & Qt::AltButton )) { // go backward
1784#else
[707]1785  if ((event->key() == Qt::Key_Down) && (event->modifiers() & Qt::AltModifier )) { // go backward
[709]1786#endif
[707]1787    G4MouseMoveEvent(0,0,1);
1788  }
[709]1789#if QT_VERSION < 0x040000
1790  else if ((event->key() == Qt::Key_Up) && (event->state() & Qt::AltButton)) { // go forward
1791#else
[707]1792  else if ((event->key() == Qt::Key_Up) && (event->modifiers() & Qt::AltModifier)) { // go forward
[709]1793#endif
[707]1794    G4MouseMoveEvent(0,0,-1);
1795  }
[709]1796#if QT_VERSION < 0x040000
1797  if ((event->key() == Qt::Key_Down) && (event->state() & Qt::ShiftButton)) { // rotate phi
1798#else
[707]1799  if ((event->key() == Qt::Key_Down) && (event->modifiers() & Qt::ShiftModifier)) { // rotate phi
[709]1800#endif
[707]1801    G4MouseRotateEvent(0,-1);
1802  }
[709]1803#if QT_VERSION < 0x040000
1804  else if ((event->key() == Qt::Key_Up) && (event->state() & Qt::ShiftButton)) { // rotate phi
1805#else
[707]1806  else if ((event->key() == Qt::Key_Up) && (event->modifiers() & Qt::ShiftModifier)) { // rotate phi
[709]1807#endif
[707]1808    G4MouseRotateEvent(0,1);
1809  }
[709]1810#if QT_VERSION < 0x040000
1811  if ((event->key() == Qt::Key_Left) && (event->state() & Qt::ShiftButton)) { // rotate theta
1812#else
[707]1813  if ((event->key() == Qt::Key_Left) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta
[709]1814#endif
[707]1815    G4MouseRotateEvent(1,0);
1816  }
[709]1817#if QT_VERSION < 0x040000
[707]1818  else if ((event->key() == Qt::Key_Right) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta
[709]1819#else
1820  else if ((event->key() == Qt::Key_Right) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta
1821#endif
[707]1822    G4MouseRotateEvent(-1,0);
1823  }
[704]1824  if (event->key() == Qt::Key_Escape) { // escaped from full screen
1825    toggleFullScreen();
[707]1826  }
1827  if (event->key() == Qt::Key_Plus) { // zoom in
1828    fVP.SetZoomFactor(fVP.GetZoomFactor()*fDeltaZoom);
1829    updateQWidget();
1830  }
1831  else if (event->key() == Qt::Key_Minus) { // zoom out
1832    fVP.SetZoomFactor(fVP.GetZoomFactor()/fDeltaZoom);
1833    updateQWidget();
1834  }
1835  // with no modifiers
1836  if (!event->modifiers()) {
1837    if (event->key() == Qt::Key_Down) { // go down
[702]1838      G4MouseMoveEvent(0,1,0);
[696]1839    }
[707]1840    else if (event->key() == Qt::Key_Up) {  // go up
[702]1841      G4MouseMoveEvent(0,-1,0);
[696]1842    }
[707]1843    if (event->key() == Qt::Key_Left) { // go left
[696]1844      G4MouseMoveEvent(-1,0,0);
1845    }
[707]1846    else if (event->key() == Qt::Key_Right) { // go right
[696]1847      G4MouseMoveEvent(1,0,0);
1848    }
[707]1849  }
[702]1850  holdKeyEvent = false;
[696]1851}
1852
[588]1853/*
[696]1854 
[588]1855void MultiLayer::exportToSVG(const QString& fname)
1856{
1857  QPicture picture;
1858  QPainter p(&picture);
1859  for (int i=0;i<(int)graphsList->count();i++)
1860    {
1861      Graph *gr=(Graph *)graphsList->at(i);
1862      Plot *myPlot= (Plot *)gr->plotWidget();
1863     
1864      QPoint pos=gr->pos();
1865     
1866      int width=int(myPlot->frameGeometry().width());
1867      int height=int(myPlot->frameGeometry().height());
1868     
1869      myPlot->print(&p, QRect(pos,QSize(width,height)));
1870    }
1871 
1872  p.end();
1873  picture.save(fname, "svg");
1874}
1875*/
[707]1876#endif
Note: See TracBrowser for help on using the repository browser.