Ignore:
Timestamp:
Nov 12, 2007, 4:42:32 PM (17 years ago)
Author:
garnier
Message:

r636@mac-90108: laurentgarnier | 2007-11-12 16:46:00 +0100
modif pour qt3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc

    r595 r599  
    2525//
    2626//
    27 // $Id: G4OpenGLQtViewer.cc,v 1.3 2007/11/08 17:00:51 lgarnier Exp $
     27// $Id: G4OpenGLQtViewer.cc,v 1.4 2007/11/09 15:03:22 lgarnier Exp $
    2828// GEANT4 tag $Name:  $
    2929//
     
    5151#include "G4UImanager.hh"
    5252#include <qapplication.h>
    53 #include <qboxLayout.h>
     53#include <qlayout.h>
    5454#include <qdialog.h>
     55
     56#if QT_VERSION >= 0x040000
    5557#include <qmenu.h>
    5658#include <qimagewriter.h>
     59#else
     60#include <qaction.h>
     61#include <qwidgetlist.h>
     62#include <qmenudata.h>
     63#include <qpopupmenu.h>
     64#include <qimage.h>
     65#endif
     66
    5767#include <qmessagebox.h>
    5868#include <qfiledialog.h>
     
    6272#include <qdialog.h>
    6373#include <qevent.h> //include <qcontextmenuevent.h>
    64 #include <qmenu.h>
    65 #include <qimage.h>
    6674
    6775
     
    100108    G4cerr << "Visualization window not defined, please choose one before" << G4endl;
    101109  } else {
     110#if QT_VERSION < 0x040000
     111    GLWindow->setActiveWindow();
     112#else
    102113    GLWindow->activateWindow();
     114#endif
    103115    printf("G4OpenGLQtViewer::ShowView -----------------------\n");
    104116  }
     
    145157    // look for the main window
    146158    bool found = false;
     159#if QT_VERSION < 0x040000
     160    QWidgetList  *list = QApplication::allWidgets();
     161    QWidgetListIt it( *list );         // iterate over the widgets
     162    QWidget * widget;
     163    while ( (widget=it.current()) != 0 ) {  // for each widget...
     164      ++it;
     165      if ((found== false) && (widget->inherits("QMainWindow"))) {
     166        printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n");
     167        GLWindow = new QDialog(widget,0,FALSE,Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WStyle_MinMax );
     168        found = true;
     169      }
     170    }
     171    delete list;                      // delete the list, not the widgets
     172#else
    147173    foreach (QWidget *widget, QApplication::allWidgets()) {
    148174      if ((found== false) && (widget->inherits("QMainWindow"))) {
     
    152178      }
    153179    }
     180#endif
     181
    154182    if (found==false) {
    155183      printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist, but not found\n");
     
    161189  }
    162190
     191#if QT_VERSION < 0x040000
     192  QHBoxLayout *mainLayout = new QHBoxLayout(GLWindow);
     193#else
    163194  QHBoxLayout *mainLayout = new QHBoxLayout;
     195#endif
    164196
    165197  mainLayout->addWidget(fWindow);
     198
     199#if QT_VERSION < 0x040000
     200  GLWindow->setCaption( tr( "QGl Viewer" ));
     201#else
    166202  GLWindow->setLayout(mainLayout);
    167   GLWindow->setWindowTitle("QGl Viewer");
     203  GLWindow->setWindowTitle(tr("QGl Viewer"));
     204#endif
    168205  GLWindow->resize(300, 300);
    169206  GLWindow->move(900,300);
     
    229266void G4OpenGLQtViewer::createPopupMenu()    {
    230267
     268#if QT_VERSION < 0x040000
     269  fContextMenu = new QPopupMenu( GLWindow,"All" );
     270#else
    231271  fContextMenu = new QMenu("All");
    232 
     272#endif
     273  Q_CHECK_PTR( fContextMenu );
     274
     275#if QT_VERSION < 0x040000
     276  // === Mouse menu ===
     277  QPopupMenu *mMouseAction = new QPopupMenu( fContextMenu );
     278  Q_CHECK_PTR( mMouseAction );
     279
     280  QAction *rotate = new QAction("&Rotate scene",CTRL+Key_N,mMouseAction);
     281  QAction *move =  new QAction("&Move scene",CTRL+Key_M,mMouseAction);
     282  rotate->addTo(mMouseAction);
     283  move->addTo(mMouseAction);
     284
     285  fContextMenu->insertItem( "&Mouse action", mMouseAction);
     286
     287#else
     288  // === Mouse menu ===
    233289  QMenu *mMouseAction = fContextMenu->addMenu("&Mouse action");
     290
    234291  QAction *rotate = mMouseAction->addAction("&Rotate scene");
    235292  QAction *move = mMouseAction->addAction("&Move scene");
     293#endif
     294
    236295  // INIT mMouse
    237296  createRadioAction(rotate,move,SLOT(toggleMouseAction(bool)),1);
    238297
    239   //Style Menu
     298#if QT_VERSION < 0x040000
     299  // === Style Menu ===
     300  QPopupMenu *mStyle = new QPopupMenu(fContextMenu);
     301
     302  QPopupMenu *mRepresentation = new QPopupMenu(fContextMenu);
     303
     304  QAction *polyhedron = new QAction("&Polyhedron",CTRL+Key_P,mRepresentation);
     305  QAction *nurbs = new QAction("&NURBS",CTRL+Key_N,mRepresentation);
     306  polyhedron->addTo(mRepresentation);
     307  nurbs->addTo(mRepresentation);
     308
     309  mStyle->insertItem("&Representation",mRepresentation);
     310  fContextMenu->insertItem("&Style",mStyle);
     311
     312#else
     313  // === Style Menu ===
    240314  QMenu *mStyle = fContextMenu->addMenu("&Style");
    241315
     
    243317  QAction *polyhedron = mRepresentation->addAction("Polyhedron");
    244318  QAction *nurbs = mRepresentation->addAction("NURBS");
     319#endif
    245320  // INIT mStyle
    246321  G4ViewParameters::RepStyle style;
     
    255330
    256331
     332#if QT_VERSION < 0x040000
     333  // === Drawing Menu ===
     334  QPopupMenu *mDrawing = new QPopupMenu(fContextMenu);
     335  fContextMenu->insertItem("&Drawing",mDrawing);
     336
     337  fDrawingWireframe = new QPopupMenu(mDrawing);
     338  mDrawing->insertItem("&Wireframe",fDrawingWireframe);
     339
     340  mDrawing->setCheckable(true);
     341  fDrawingWireframe->setCheckable(true);
     342
     343  fDrawingLineRemoval = new QPopupMenu(mDrawing);
     344  mDrawing->insertItem("&Hidden line removal",fDrawingLineRemoval);
     345  fDrawingLineRemoval->setCheckable(true);
     346
     347  fDrawingSurfaceRemoval = new QPopupMenu(mDrawing);
     348  mDrawing->insertItem("&Hidden surface removal",fDrawingSurfaceRemoval);
     349  fDrawingSurfaceRemoval->setCheckable(true);
     350
     351  fDrawingLineSurfaceRemoval = new QPopupMenu(mDrawing);
     352  mDrawing->insertItem("&Hidden line and surface removal",fDrawingLineSurfaceRemoval);
     353  fDrawingLineSurfaceRemoval->setCheckable(true);
     354
     355#else
     356  // === Drawing Menu ===
    257357  QMenu *mDrawing = mStyle->addMenu("&Drawing");
     358
    258359  fDrawingWireframe = mDrawing->addAction("Wireframe");
    259360  fDrawingWireframe->setCheckable(true);
    260   fDrawingWireframe->setChecked(true);
     361
    261362  fDrawingLineRemoval = mDrawing->addAction("Hidden line removal");
    262363  fDrawingLineRemoval->setCheckable(true);
     364
    263365  fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal");
    264366  fDrawingSurfaceRemoval->setCheckable(true);
     367
    265368  fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal");
    266369  fDrawingLineSurfaceRemoval->setCheckable(true);
     370#endif
    267371  // INIT Drawing
    268372  G4ViewParameters::DrawingStyle d_style;
    269373  d_style = fVP.GetDrawingStyle();
    270374 
    271   fDrawingWireframe->setCheckable(true);
    272   fDrawingLineRemoval->setCheckable(true);
    273   fDrawingSurfaceRemoval->setCheckable(true);
    274   fDrawingLineSurfaceRemoval->setCheckable(true);
    275 
     375#if QT_VERSION < 0x040000
     376  if (d_style == G4ViewParameters::wireframe) {
     377    fDrawingWireframe->setItemChecked(0,true);
     378  } else if (d_style == G4ViewParameters::hlr) {
     379    fDrawingLineRemoval->setItemChecked(0,true);
     380  } else if (d_style == G4ViewParameters::hsr) {
     381    fDrawingSurfaceRemoval->setItemChecked(0,true);
     382  } else if (d_style == G4ViewParameters::hlhsr) {
     383    fDrawingLineSurfaceRemoval->setItemChecked(0,true);
     384  } else {
     385    mDrawing->clear();
     386  }
     387#else
    276388  if (d_style == G4ViewParameters::wireframe) {
    277389    fDrawingWireframe->setChecked(true);
     
    285397    mDrawing->clear();
    286398  }
     399#endif
    287400
    288401  QObject ::connect(fDrawingWireframe,
     
    304417
    305418
     419#if QT_VERSION < 0x040000
     420  QPopupMenu *mBackground = new QPopupMenu(mStyle);
     421  mStyle->insertItem("&Background color",mBackground);
     422
     423  QAction *white = new QAction("&White",CTRL+Key_W,mBackground);
     424  QAction *black =  new QAction("&Black",CTRL+Key_B,mBackground);
     425  white->addTo(mBackground);
     426  black->addTo(mBackground);
     427
     428#else
    306429  QMenu *mBackground = mStyle->addMenu("&Background color");
    307430  QAction *white = mBackground->addAction("White");
    308431  QAction *black = mBackground->addAction("Black");
     432
     433#endif
    309434  if (background.GetRed() == 1. &&
    310435      background.GetGreen() == 1. &&
     
    316441
    317442
    318   // Action Menu
     443#if QT_VERSION < 0x040000
     444  // === Action Menu ===
     445  QPopupMenu *mActions = new QPopupMenu(fContextMenu);
     446  fContextMenu->insertItem("&Actions",mActions);
     447
     448  QAction *controlPanels = new QAction("&Control panels",CTRL+Key_C,mActions);
     449  QAction *exitG4 =  new QAction("&Exit to G4Vis >",CTRL+Key_E,mActions);
     450  QAction *createEPS =  new QAction("&Save as ...",CTRL+Key_S,mActions);
     451  controlPanels->addTo(mActions);
     452  exitG4->addTo(mActions);
     453  createEPS->addTo(mActions);
     454
     455#else
     456  // === Action Menu ===
    319457  QMenu *mActions = fContextMenu->addMenu("&Actions");
    320458  QAction *controlPanels = mActions->addAction("Control panels");
    321459  QAction *exitG4 = mActions->addAction("Exit to G4Vis >");
    322460  QAction *createEPS = mActions->addAction("Save as ...");
     461#endif
     462
    323463  QObject ::connect(controlPanels,
    324464                    SIGNAL(triggered()),
     
    335475
    336476
    337   // Special Menu
     477#if QT_VERSION < 0x040000
     478  // === Special Menu ===
     479  QPopupMenu *mSpecial = new QPopupMenu(fContextMenu);
     480  fContextMenu->insertItem("S&pecial",mSpecial);
     481
     482  QPopupMenu *mTransparency = new QPopupMenu(mSpecial);
     483  mSpecial->insertItem("Transparency",mTransparency);
     484
     485  QAction *transparencyOn = new QAction("&On",CTRL+Key_O,mTransparency);
     486  QAction *transparencyOff = new QAction("&Off",CTRL+Key_F,mTransparency);
     487  transparencyOn->addTo(mTransparency);
     488  transparencyOff->addTo(mTransparency);
     489
     490#else
     491  // === Special Menu ===
    338492  QMenu *mSpecial = fContextMenu->addMenu("S&pecial");
    339   QMenu *transparency = mSpecial->addMenu("Transparency");
    340   QAction *transparencyOn = transparency->addAction("On");
    341   QAction *transparencyOff = transparency->addAction("Off");
     493  QMenu *mTransparency = mSpecial->addMenu("Transparency");
     494  QAction *transparencyOn = mTransparency->addAction("On");
     495  QAction *transparencyOff = mTransparency->addAction("Off");
     496#endif
     497
    342498  if (transparency_enabled == false) {
    343499    createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),2);
     
    349505
    350506
     507#if QT_VERSION < 0x040000
     508  QPopupMenu *mAntialiasing = new QPopupMenu(mSpecial);
     509  mSpecial->insertItem("Antialiasing",mAntialiasing);
     510
     511  QAction *antialiasingOn = new QAction("&On",CTRL+Key_O,mAntialiasing);
     512  QAction *antialiasingOff = new QAction("&Off",CTRL+Key_F,mAntialiasing);
     513  antialiasingOn->addTo(mAntialiasing);
     514  antialiasingOff->addTo(mAntialiasing);
     515
     516#else
    351517  QMenu *mAntialiasing = mSpecial->addMenu("Antialiasing");
    352518  QAction *antialiasingOn = mAntialiasing->addAction("On");
    353519  QAction *antialiasingOff = mAntialiasing->addAction("Off");
     520#endif
     521
    354522  if (antialiasing_enabled == false) {
    355523    createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),2);
     
    360528  }
    361529
     530#if QT_VERSION < 0x040000
     531  QPopupMenu *mHaloing = new QPopupMenu(mSpecial);
     532  mSpecial->insertItem("Haloing",mHaloing);
     533
     534  QAction *haloingOn = new QAction("&On",CTRL+Key_O,mHaloing);
     535  QAction *haloingOff = new QAction("&Off",CTRL+Key_F,mHaloing);
     536  haloingOn->addTo(mHaloing);
     537  haloingOff->addTo(mHaloing);
     538#else
    362539  QMenu *mHaloing = mSpecial->addMenu("Haloing");
    363540  QAction *haloingOn = mHaloing->addAction("On");
    364541  QAction *haloingOff = mHaloing->addAction("Off");
     542#endif
    365543  if (haloing_enabled == false) {
    366544    createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),2);
     
    371549  }
    372550
     551#if QT_VERSION < 0x040000
     552  QPopupMenu *mAux = new QPopupMenu(mSpecial);
     553  mSpecial->insertItem("Auxiliairy edges",mAux);
     554
     555  QAction *auxOn = new QAction("&On",CTRL+Key_O,mAux);
     556  QAction *auxOff = new QAction("&Off",CTRL+Key_F,mAux);
     557  auxOn->addTo(mAux);
     558  auxOff->addTo(mAux);
     559
     560#else
    373561  QMenu *mAux = mSpecial->addMenu("Auxiliary edges");
    374562  QAction *auxOn = mAux->addAction("On");
    375563  QAction *auxOff = mAux->addAction("Off");
     564#endif
    376565  if (!fVP.IsAuxEdgeVisible()) {
    377566    createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),1);
     
    381570
    382571
     572#if QT_VERSION < 0x040000
     573  QPopupMenu *mFullScreen = new QPopupMenu(mSpecial);
     574  mSpecial->insertItem("Full screen",mFullScreen);
     575
     576  QAction *fullOn = new QAction("&On",CTRL+Key_O,mFullScreen);
     577  QAction *fullOff = new QAction("&Off",CTRL+Key_F,mFullScreen);
     578  fullOn->addTo(mFullScreen);
     579  fullOff->addTo(mFullScreen);
     580#else
    383581  QMenu *mFullScreen = mSpecial->addMenu("Full screen");
    384582  QAction *fullOn = mFullScreen->addAction("On");
    385583  QAction *fullOff = mFullScreen->addAction("Off");
     584#endif
    386585  createRadioAction(fullOn,fullOff,SLOT(toggleFullScreen(bool)),2);
    387586
     
    415614   @param nCheck: 1 : first action will be set true. 2 : second action will be set true
    416615*/
     616#if QT_VERSION < 0x040000
     617void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) {
     618
     619  if (action1->parent()->inherits("QPopupMenu")){
     620    ((QPopupMenu*)action1->parent())->setCheckable(true);
     621  }
     622  ((QPopupMenu*)action1->parent())->setItemChecked(0,true);
     623  ((QPopupMenu*)action1->parent())->setItemChecked(1,true);
     624
     625  if (nCheck ==1)
     626    ((QPopupMenu*)action1->parent())->setItemChecked(0,true);
     627  else
     628    ((QPopupMenu*)action1->parent())->setItemChecked(1,true);
     629   
     630  QObject ::connect(action1, SIGNAL(triggered(bool)),action2, SLOT(toggle()));
     631  QObject ::connect(action2, SIGNAL(triggered(bool)),action1, SLOT(toggle()));
     632
     633  QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str());
     634}
     635
     636#else
    417637void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) {
    418638
     
    431651
    432652}
     653#endif
    433654
    434655/**
     
    770991   @param mButtons mouse button active
    771992*/
     993
     994#if QT_VERSION < 0x040000
     995void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::ButtonState mButtons)
     996#else
    772997void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons)
     998#endif
    773999{
    7741000  int dx = pos_x - lastPos.x();
Note: See TracChangeset for help on using the changeset viewer.