Changeset 599 for trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc
- Timestamp:
- Nov 12, 2007, 4:42:32 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc
r595 r599 25 25 // 26 26 // 27 // $Id: G4OpenGLQtViewer.cc,v 1. 3 2007/11/08 17:00:51lgarnier Exp $27 // $Id: G4OpenGLQtViewer.cc,v 1.4 2007/11/09 15:03:22 lgarnier Exp $ 28 28 // GEANT4 tag $Name: $ 29 29 // … … 51 51 #include "G4UImanager.hh" 52 52 #include <qapplication.h> 53 #include <q boxLayout.h>53 #include <qlayout.h> 54 54 #include <qdialog.h> 55 56 #if QT_VERSION >= 0x040000 55 57 #include <qmenu.h> 56 58 #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 57 67 #include <qmessagebox.h> 58 68 #include <qfiledialog.h> … … 62 72 #include <qdialog.h> 63 73 #include <qevent.h> //include <qcontextmenuevent.h> 64 #include <qmenu.h>65 #include <qimage.h>66 74 67 75 … … 100 108 G4cerr << "Visualization window not defined, please choose one before" << G4endl; 101 109 } else { 110 #if QT_VERSION < 0x040000 111 GLWindow->setActiveWindow(); 112 #else 102 113 GLWindow->activateWindow(); 114 #endif 103 115 printf("G4OpenGLQtViewer::ShowView -----------------------\n"); 104 116 } … … 145 157 // look for the main window 146 158 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 147 173 foreach (QWidget *widget, QApplication::allWidgets()) { 148 174 if ((found== false) && (widget->inherits("QMainWindow"))) { … … 152 178 } 153 179 } 180 #endif 181 154 182 if (found==false) { 155 183 printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist, but not found\n"); … … 161 189 } 162 190 191 #if QT_VERSION < 0x040000 192 QHBoxLayout *mainLayout = new QHBoxLayout(GLWindow); 193 #else 163 194 QHBoxLayout *mainLayout = new QHBoxLayout; 195 #endif 164 196 165 197 mainLayout->addWidget(fWindow); 198 199 #if QT_VERSION < 0x040000 200 GLWindow->setCaption( tr( "QGl Viewer" )); 201 #else 166 202 GLWindow->setLayout(mainLayout); 167 GLWindow->setWindowTitle("QGl Viewer"); 203 GLWindow->setWindowTitle(tr("QGl Viewer")); 204 #endif 168 205 GLWindow->resize(300, 300); 169 206 GLWindow->move(900,300); … … 229 266 void G4OpenGLQtViewer::createPopupMenu() { 230 267 268 #if QT_VERSION < 0x040000 269 fContextMenu = new QPopupMenu( GLWindow,"All" ); 270 #else 231 271 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 === 233 289 QMenu *mMouseAction = fContextMenu->addMenu("&Mouse action"); 290 234 291 QAction *rotate = mMouseAction->addAction("&Rotate scene"); 235 292 QAction *move = mMouseAction->addAction("&Move scene"); 293 #endif 294 236 295 // INIT mMouse 237 296 createRadioAction(rotate,move,SLOT(toggleMouseAction(bool)),1); 238 297 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 === 240 314 QMenu *mStyle = fContextMenu->addMenu("&Style"); 241 315 … … 243 317 QAction *polyhedron = mRepresentation->addAction("Polyhedron"); 244 318 QAction *nurbs = mRepresentation->addAction("NURBS"); 319 #endif 245 320 // INIT mStyle 246 321 G4ViewParameters::RepStyle style; … … 255 330 256 331 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 === 257 357 QMenu *mDrawing = mStyle->addMenu("&Drawing"); 358 258 359 fDrawingWireframe = mDrawing->addAction("Wireframe"); 259 360 fDrawingWireframe->setCheckable(true); 260 fDrawingWireframe->setChecked(true); 361 261 362 fDrawingLineRemoval = mDrawing->addAction("Hidden line removal"); 262 363 fDrawingLineRemoval->setCheckable(true); 364 263 365 fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal"); 264 366 fDrawingSurfaceRemoval->setCheckable(true); 367 265 368 fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal"); 266 369 fDrawingLineSurfaceRemoval->setCheckable(true); 370 #endif 267 371 // INIT Drawing 268 372 G4ViewParameters::DrawingStyle d_style; 269 373 d_style = fVP.GetDrawingStyle(); 270 374 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 276 388 if (d_style == G4ViewParameters::wireframe) { 277 389 fDrawingWireframe->setChecked(true); … … 285 397 mDrawing->clear(); 286 398 } 399 #endif 287 400 288 401 QObject ::connect(fDrawingWireframe, … … 304 417 305 418 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 306 429 QMenu *mBackground = mStyle->addMenu("&Background color"); 307 430 QAction *white = mBackground->addAction("White"); 308 431 QAction *black = mBackground->addAction("Black"); 432 433 #endif 309 434 if (background.GetRed() == 1. && 310 435 background.GetGreen() == 1. && … … 316 441 317 442 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 === 319 457 QMenu *mActions = fContextMenu->addMenu("&Actions"); 320 458 QAction *controlPanels = mActions->addAction("Control panels"); 321 459 QAction *exitG4 = mActions->addAction("Exit to G4Vis >"); 322 460 QAction *createEPS = mActions->addAction("Save as ..."); 461 #endif 462 323 463 QObject ::connect(controlPanels, 324 464 SIGNAL(triggered()), … … 335 475 336 476 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 === 338 492 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 342 498 if (transparency_enabled == false) { 343 499 createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),2); … … 349 505 350 506 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 351 517 QMenu *mAntialiasing = mSpecial->addMenu("Antialiasing"); 352 518 QAction *antialiasingOn = mAntialiasing->addAction("On"); 353 519 QAction *antialiasingOff = mAntialiasing->addAction("Off"); 520 #endif 521 354 522 if (antialiasing_enabled == false) { 355 523 createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),2); … … 360 528 } 361 529 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 362 539 QMenu *mHaloing = mSpecial->addMenu("Haloing"); 363 540 QAction *haloingOn = mHaloing->addAction("On"); 364 541 QAction *haloingOff = mHaloing->addAction("Off"); 542 #endif 365 543 if (haloing_enabled == false) { 366 544 createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),2); … … 371 549 } 372 550 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 373 561 QMenu *mAux = mSpecial->addMenu("Auxiliary edges"); 374 562 QAction *auxOn = mAux->addAction("On"); 375 563 QAction *auxOff = mAux->addAction("Off"); 564 #endif 376 565 if (!fVP.IsAuxEdgeVisible()) { 377 566 createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),1); … … 381 570 382 571 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 383 581 QMenu *mFullScreen = mSpecial->addMenu("Full screen"); 384 582 QAction *fullOn = mFullScreen->addAction("On"); 385 583 QAction *fullOff = mFullScreen->addAction("Off"); 584 #endif 386 585 createRadioAction(fullOn,fullOff,SLOT(toggleFullScreen(bool)),2); 387 586 … … 415 614 @param nCheck: 1 : first action will be set true. 2 : second action will be set true 416 615 */ 616 #if QT_VERSION < 0x040000 617 void 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 417 637 void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) { 418 638 … … 431 651 432 652 } 653 #endif 433 654 434 655 /** … … 770 991 @param mButtons mouse button active 771 992 */ 993 994 #if QT_VERSION < 0x040000 995 void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::ButtonState mButtons) 996 #else 772 997 void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons) 998 #endif 773 999 { 774 1000 int dx = pos_x - lastPos.x();
Note: See TracChangeset
for help on using the changeset viewer.