Geant4  10.00.p02
G4UIQt.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4UIQt.cc 79182 2014-02-20 09:06:39Z gcosmo $
28 //
29 // L. Garnier
30 
31 #ifdef G4UI_BUILD_QT_SESSION
32 
33 #include "G4Types.hh"
34 
35 #include <string.h>
36 
37 #include "G4UIQt.hh"
38 #include "G4UImanager.hh"
39 #include "G4StateManager.hh"
40 #include "G4UIcommandTree.hh"
41 #include "G4UIcommandStatus.hh"
42 
43 #include "G4Qt.hh"
44 
45 #include <qapplication.h>
46 #include <qmessagebox.h>
47 #include <qlineedit.h>
48 #include <qwidget.h>
49 #include <qmenubar.h>
50 #include <qlayout.h>
51 #include <qpushbutton.h>
52 #include <qlabel.h>
53 #include <qsplitter.h>
54 #include <qscrollbar.h>
55 #include <qdialog.h>
56 #include <qevent.h>
57 #include <qtextedit.h>
58 #include <qsignalmapper.h>
59 #include <qtabwidget.h>
60 #include <qtabbar.h>
61 #include <qstringlist.h>
62 
63 #include <qmainwindow.h>
64 #include <qmenu.h>
65 #include <qlistwidget.h>
66 #include <qtreewidget.h>
67 #include <qgroupbox.h>
68 #include <qscrollarea.h>
69 #include <qtoolbox.h>
70 #include <qradiobutton.h>
71 #include <qbuttongroup.h>
72 #include <qcombobox.h>
73 #include <qsignalmapper.h>
74 #include <qpainter.h>
75 #include <qcolordialog.h>
76 #include <qtoolbar.h>
77 #include <qfiledialog.h>
78 #include <qdesktopwidget.h>
79 #include <qmessagebox.h>
80 
81 
82 #include <stdlib.h>
83 
84 // Pourquoi Static et non variables de classe ?
85 static G4bool exitSession = true;
86 static G4bool exitPause = true;
87 
108 G4UIQt::G4UIQt (
109  int argc
110 ,char** argv
111 )
112 :fMainWindow(NULL)
113 ,fCommandLabel(NULL)
114 ,fCommandArea(NULL)
115 ,fCoutTBTextArea(NULL)
116 ,fHelpArea(NULL)
117 ,fUITabWidget(NULL)
118 ,fG4cout("")
119 ,fCoutFilter(NULL)
120 ,fHistoryTBTableList(NULL)
121 ,fHelpTreeWidget(NULL)
122 ,fHelpTBWidget(NULL)
123 ,fHistoryTBWidget(NULL)
124 ,fCoutTBWidget(NULL)
125 ,fSceneTreeComponentsTBWidget(NULL)
126 ,fHelpLine(NULL)
127 ,fViewerTabWidget(NULL)
128 ,fCoutText("Output")
129 ,fEmptyViewerTabLabel(NULL)
130 ,fMainSplitterWidget(NULL)
131 ,fRightSplitterWidget(NULL)
132 ,fLeftSplitterWidget(NULL)
133 ,fHelpVSplitter(NULL)
134 ,fViewerTabHandleWidget(NULL)
135 ,fToolbarApp(NULL)
136 ,fToolbarUser(NULL)
137 ,fStringSeparator("__$$$@%%###__")
138 ,fLastOpenPath("")
139 ,fMoveSelected(false)
140 ,fRotateSelected(true)
141 ,fPickSelected(false)
142 ,fZoomInSelected(false)
143 ,fZoomOutSelected(false)
144 {
145 
146  G4Qt* interactorManager = G4Qt::getInstance (argc,argv,(char*)"Qt");
147  if (!(QApplication*)interactorManager->GetMainInteractor()) {
148  G4UImanager* UImanager = G4UImanager::GetUIpointer();
149  G4int verbose = UImanager->GetVerboseLevel();
150 
151  if (verbose >= 2) {
152  G4cout << "G4UIQt : Unable to init Qt. Aborted" << G4endl;
153  }
154  }
155 
157  if(UI!=NULL) UI->SetSession(this);
158  if(UI!=NULL) UI->SetG4UIWindow(this);
159 
160  // Check if already define in external app QMainWindow
161  bool found = false;
162  Q_FOREACH (QWidget *widget, QApplication::allWidgets()) {
163  if ((found== false) && (widget->inherits("QMainWindow"))) {
164  found = true;
165  }
166  }
167 
168  if (found) {
169  G4UImanager* UImanager = G4UImanager::GetUIpointer();
170  G4int verbose = UImanager->GetVerboseLevel();
171 
172  if (verbose >= 2) {
173  G4cout << "G4UIQt : Found an external App with a QMainWindow already defined. Aborted" << G4endl;
174  }
175  return ;
176  }
177  fMainWindow = new QMainWindow();
178 
179  // the splitter
180  fMainSplitterWidget = new QSplitter(Qt::Horizontal);
181 
182  fMainSplitterWidget->addWidget(CreateLeftSplitterWidget());
183  fMainSplitterWidget->addWidget(CreateRightSplitterWidget());
184 
185  QSizePolicy policy = QSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
186  policy.setHorizontalStretch(2);
187  fRightSplitterWidget->setSizePolicy(policy);
188 
189  policy = QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum);
190  policy.setHorizontalStretch(1);
191  fLeftSplitterWidget->setSizePolicy(policy);
192 
193  fMainWindow->setCentralWidget(fMainSplitterWidget);
194 
195  if(UI!=NULL) UI->SetCoutDestination(this); // TO KEEP
196 
197  fMainWindow->setWindowTitle(QFileInfo( QCoreApplication::applicationFilePath() ).fileName());
198  fMainWindow->move(QPoint(50,50));
199 
200  // force the size at be correct at the beggining
201  // because the widget is not realized yet, the size of the main window is not up to date. But
202  // we need it in order to add some viewer inside
203  fMainWindow->resize(fLeftSplitterWidget->width()+fRightSplitterWidget->width()+20,
204  fLeftSplitterWidget->height()+fRightSplitterWidget->height()+20);
205 
206  // Set not visible until session start
207  #if QT_VERSION < 0x040200
208  fMainWindow->hide();
209  #else
210  fMainWindow->setVisible(false);
211  #endif
212 }
213 
214 
215 
216 G4UIQt::~G4UIQt(
217 )
218 {
219  G4UImanager* UI = G4UImanager::GetUIpointer(); // TO KEEP
220  if(UI!=NULL) { // TO KEEP
221  UI->SetSession(NULL); // TO KEEP
222  UI->SetG4UIWindow(NULL);
223  UI->SetCoutDestination(NULL); // TO KEEP
224  }
225 
226  if (fMainWindow!=NULL) {
227  delete fMainWindow;
228  }
229 }
230 
233 QWidget* G4UIQt::CreateHistoryTBWidget(
234 )
235 {
236  fHistoryTBWidget = new QWidget();
237 
238  QVBoxLayout *layoutHistoryTB = new QVBoxLayout();
239  fHistoryTBTableList = new QListWidget();
240  fHistoryTBTableList->setSelectionMode(QAbstractItemView::SingleSelection);
241  connect(fHistoryTBTableList, SIGNAL(itemSelectionChanged()), SLOT(CommandHistoryCallback()));
242  fHistoryTBTableList->installEventFilter(this);
243 
244  layoutHistoryTB->addWidget(fHistoryTBTableList);
245 
246  fHistoryTBWidget->setLayout(layoutHistoryTB);
247  return fHistoryTBWidget;
248 }
249 
250 
253 QWidget* G4UIQt::CreateHelpTBWidget(
254 )
255 {
256  fHelpTBWidget = new QWidget();
257 
258  QWidget *helpWidget = new QWidget();
259  QHBoxLayout *helpLayout = new QHBoxLayout();
260  QVBoxLayout *vLayout = new QVBoxLayout();
261  fHelpVSplitter = new QSplitter(Qt::Horizontal);
262  fHelpLine = new QLineEdit();
263  helpLayout->addWidget(new QLabel("Search :"));
264  helpLayout->addWidget(fHelpLine);
265  connect( fHelpLine, SIGNAL( editingFinished () ), this, SLOT( LookForHelpStringCallback() ) );
266 
267  // Create Help tree
268  FillHelpTree();
269 
270  fHelpArea = new QTextEdit();
271  fHelpArea->setReadOnly(true);
272 
273  // Set layouts
274 
275  if (fHelpTreeWidget) {
276  fHelpVSplitter->addWidget(fHelpTreeWidget);
277  }
278  fHelpVSplitter->addWidget(fHelpArea);
279 
280  vLayout->addWidget(helpWidget);
281  vLayout->addWidget(fHelpVSplitter,1);
282 
283  helpWidget->setLayout(helpLayout);
284  fHelpTBWidget->setLayout(vLayout);
285 
286  return fHelpTBWidget;
287 }
288 
289 
292 QWidget* G4UIQt::CreateCoutTBWidget(
293 )
294 {
295  fCoutTBWidget = new QGroupBox("Output");
296 
297  QVBoxLayout *layoutCoutTB = new QVBoxLayout();
298 
299  fCoutTBTextArea = new QTextEdit();
300 
301  // set font familly and size
302  fCoutTBTextArea->setFontFamily("Courier");
303  fCoutTBTextArea->setFontPointSize(12);
304 
305  fCoutFilter = new QLineEdit();
306  QLabel* coutFilterLabel = new QLabel("Filter : ");
307  coutFilterLabel->setToolTip("filter output by...");
308 
309  QPushButton *coutTBClearButton = new QPushButton("clear output");
310  coutTBClearButton->setToolTip("clear output");
311  connect(coutTBClearButton, SIGNAL(clicked()), SLOT(ClearButtonCallback()));
312  connect(fCoutFilter, SIGNAL(textEdited ( const QString &)), SLOT(CoutFilterCallback( const QString &)));
313 
314  fCoutTBTextArea->setReadOnly(true);
315 
316  QWidget* coutButtonWidget = new QWidget();
317  QHBoxLayout* layoutCoutTBButtons = new QHBoxLayout();
318  layoutCoutTBButtons->addWidget(coutTBClearButton);
319  layoutCoutTBButtons->addWidget(coutFilterLabel);
320  layoutCoutTBButtons->addWidget(fCoutFilter);
321  coutButtonWidget->setLayout(layoutCoutTBButtons);
322 
323  // reduce margins
324  layoutCoutTBButtons->setContentsMargins(3,3,3,0);
325 
326  layoutCoutTB->addWidget(fCoutTBTextArea);
327  layoutCoutTB->addWidget(coutButtonWidget);
328 
329  fCoutTBWidget->setLayout(layoutCoutTB);
330 
331  fCoutTBTextArea->setMinimumSize(100,100);
332 
333  return fCoutTBWidget;
334 }
335 
336 
339 QWidget* G4UIQt::CreateVisParametersTBWidget(
340 )
341 {
342  return NULL;
343 }
344 
345 
348 QWidget* G4UIQt::CreateUITabWidget(
349 )
350 {
351  fUITabWidget = new QTabWidget();
352 
353  // the right splitter
354  fUITabWidget->addTab(CreateSceneTreeComponentsTBWidget(),"Scene tree");
355  fUITabWidget->addTab(CreateHelpTBWidget(),"Help");
356  fUITabWidget->addTab(CreateHistoryTBWidget(),"History");
357  // fUITabWidget->setCurrentWidget(fSceneTreeComponentsTBWidget);
358 
359  connect(fUITabWidget, SIGNAL(currentChanged(int)), SLOT(ToolBoxActivated(int)));
360 
361  return fUITabWidget;
362 }
363 
364 
365 QWidget* G4UIQt::CreateSceneTreeComponentsTBWidget(){
366 
367  fSceneTreeComponentsTBWidget = new QTabWidget();
368 
369 #if QT_VERSION < 0x040200
370  fSceneTreeComponentsTBWidget->hide();
371 #else
372  fSceneTreeComponentsTBWidget->setVisible(false);
373 #endif
374 
375  return fSceneTreeComponentsTBWidget;
376 }
377 
378 
379 QWidget* G4UIQt::CreateLeftSplitterWidget(){
380 
381  fLeftSplitterWidget = new QWidget();
382  QVBoxLayout * layoutLeftSplitterWidget = new QVBoxLayout();
383  layoutLeftSplitterWidget->addWidget(CreateUITabWidget());
384 
385  fLeftSplitterWidget->setLayout(layoutLeftSplitterWidget);
386 
387  fLeftSplitterWidget->resize(200,200);
388 
389  return fLeftSplitterWidget;
390 }
391 
392 
393 QWidget* G4UIQt::CreateRightSplitterWidget(){
394 
395  fRightSplitterWidget = new QSplitter(Qt::Vertical);
396 
397  // Set layouts
398  QWidget* commandLineWidget = new QWidget();
399  QHBoxLayout *layoutCommandLine = new QHBoxLayout();
400 
401  // fill them
402 
403  fCommandLabel = new QLabel("");
404 
405  fCommandArea = new QLineEdit();
406  fCommandArea->installEventFilter(this);
407  fCommandArea->activateWindow();
408 
409  fCommandArea->setFocusPolicy ( Qt::StrongFocus );
410  fCommandArea->setFocus(Qt::TabFocusReason);
411  fCommandArea->setToolTip("Apply command");
412 
413 
414  layoutCommandLine->addWidget(fCommandLabel);
415  layoutCommandLine->addWidget(fCommandArea);
416 
417  commandLineWidget->setLayout(layoutCommandLine);
418 
419  fEmptyViewerTabLabel = new QLabel("If you want to have a Viewer, please use /vis/open commands.");
420 
421 
422 
423 
424  // fill right splitter
425 
426  // Create an widget to handle OGL widget and label
427  fViewerTabHandleWidget = new QWidget();
428  QVBoxLayout * viewerTabHandleLayout = new QVBoxLayout();
429  viewerTabHandleLayout->addWidget(fEmptyViewerTabLabel);
430  fViewerTabHandleWidget->setLayout(viewerTabHandleLayout);
431 
432 
433  fRightSplitterWidget->addWidget(fViewerTabHandleWidget);
434  fRightSplitterWidget->addWidget(CreateCoutTBWidget());
435  fRightSplitterWidget->addWidget(commandLineWidget);
436 
437 // set the QGLWidget size policy
438  QSizePolicy policy = QSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
439  policy.setVerticalStretch(4);
440  fViewerTabHandleWidget->setSizePolicy(policy);
441 
442  fViewerTabHandleWidget->setMinimumSize(40,40);
443 
444  commandLineWidget->setMinimumSize(50,50);
445 
446  // Connect signal
447  connect(fCommandArea, SIGNAL(returnPressed()), SLOT(CommandEnteredCallback()));
448  connect(fCommandArea, SIGNAL(textEdited(const QString &)), SLOT(CommandEditedCallback(const QString &)));
449 
450  fRightSplitterWidget->resize(200,200);
451  return fRightSplitterWidget;
452 }
453 
454 
457 QTabWidget* G4UIQt::GetSceneTreeComponentsTBWidget(
458 )
459 {
460  return fSceneTreeComponentsTBWidget;
461 }
462 
463 
467 bool G4UIQt::AddTabWidget(
468  QWidget* aWidget
469 ,QString name
470 ,int sizeX
471 ,int sizeY
472 )
473 {
474  // Special case for Qt version between 5.0 and 5.1 on Mac OSX
475  // Due to a bug in this Qt version, we can't put a OpenGL Widget inside the QTabWidget.
476  // A work around is to put it outside. Returning false will fore the wiewer to put the QGLWidget
477  // inside a new QWindow.
478 
479 #ifdef Q_OS_MAC
480  #if QT_VERSION < 0x050100
481  #if QT_VERSION >= 0x050000
482  QString message = QString(
483  "This Qt version [")+qVersion ()+"] has some issues with the OpenGL viewer.\n"+
484  "To prevent problems, you are not allowed to open a Store nor Immediate viewer.\n" +
485  "\n" +
486  "Please upgrade to Qt version >= 5.1\n";
487 
488  QMessageBox::warning(fMainWindow, tr("Warning"),
489  tr(message.toStdString().c_str()),
490  QMessageBox::Ok);
491  return false;
492  #endif
493  #endif
494 #endif
495 
496  if (fViewerTabWidget == NULL) {
497  fViewerTabWidget = new G4QTabWidget(fViewerTabHandleWidget, sizeX, sizeY);
498  #if QT_VERSION < 0x040500
499 #else
500  fViewerTabWidget->setTabsClosable (true);
501 #endif
502 
503 #if QT_VERSION < 0x040200
504 #else
505  fViewerTabWidget->setUsesScrollButtons (true);
506 #endif
507 
508 #if QT_VERSION < 0x040500
509 #else
510  connect(fViewerTabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(TabCloseCallback(int)));
511 #endif
512  connect(fViewerTabWidget, SIGNAL(currentChanged ( int ) ), SLOT(UpdateTabWidget(int)));
513  }
514 
515  if (!aWidget) {
516  return false;
517  }
518 // Has to be added before we put it into the fViewerTabHandleWidget widget
519  fViewerTabWidget->addTab(aWidget,name);
520 
521  // Remove QLabel
522 
523  // L.Garnier 26/05/2010 : not exactly the same in qt3. Could cause some
524  // troubles
525  if (fEmptyViewerTabLabel != NULL) {
526  int index = -1;
527  index = fViewerTabHandleWidget->layout()->indexOf(fEmptyViewerTabLabel);
528  if ( index != -1) {
529  fViewerTabHandleWidget->layout()->removeWidget(fEmptyViewerTabLabel);
530  delete fEmptyViewerTabLabel;
531  fEmptyViewerTabLabel = NULL;
532 
533  fViewerTabHandleWidget->layout()->addWidget(fViewerTabWidget);
534  }
535  }
536 
537 
538 
539  fViewerTabWidget->setCurrentIndex(fViewerTabWidget->count()-1);
540 
541  // Set visible
542  #if QT_VERSION < 0x040200
543  fViewerTabWidget->setLastTabCreated(fViewerTabWidget->currentIndex());
544  #else
545  fViewerTabWidget->setLastTabCreated(fViewerTabWidget->currentIndex());
546  #endif
547 
548  // Problems with resize. The widgets are not realy drawn at this step,
549  // then we have to force them on order to check the size.
550  // try to computer new size in order not to go out of the screen
551 
552  // size of current tab
553  QSize s = QSize(sizeX,sizeY);
554 
555  QRect screen = QApplication::desktop()->screenGeometry();
556 
557  if (fMainWindow->width()-fViewerTabWidget->width()+sizeX > screen.width()) {
558  s.setWidth(screen.width()-fMainWindow->width()+fViewerTabWidget->width());
559  }
560  if (fMainWindow->height()-fViewerTabWidget->height()+sizeY > screen.height()-24) { // 24 is the menuBar height on mac
561  s.setHeight(screen.height()-fMainWindow->height()+fViewerTabWidget->height()-24);
562  }
563  int winWidth = fMainWindow->width();
564  int winHeight = fMainWindow->height();
565  int oldTabWidth = fViewerTabWidget->width();
566  int oldTabHeight = fViewerTabWidget->height();
567  int newTabWidth = fViewerTabWidget->sizeHint().width();
568  int newTabHeight = fViewerTabWidget->sizeHint().height();
569 
570  fViewerTabWidget->setPreferredSize(s);
571  fMainWindow->resize(winWidth-oldTabWidth+newTabWidth,
572  winHeight-oldTabHeight+newTabHeight);
573  return true;
574 }
575 
576 
577 void G4UIQt::UpdateTabWidget(int tabNumber) {
578  if ( fViewerTabWidget == NULL) {
579  fViewerTabWidget = new G4QTabWidget;
580  }
581 
582  fViewerTabWidget->setCurrentIndex(tabNumber);
583 
584  // Send this signal to unblock graphic updates !
585  fViewerTabWidget->setTabSelected(false);
586 
587  #if QT_VERSION < 0x040200
588  fViewerTabWidget->show();
589  #else
590  fViewerTabWidget->setVisible(true);
591  #endif
592 
593  // This will send a paintEvent to OGL Viewers
594  fViewerTabWidget->setTabSelected(true);
595 }
596 
597 
600 void G4UIQt::ResizeTabWidget( QResizeEvent* e) {
601  if ( fViewerTabWidget) {
602  for (G4int a=0;a<fViewerTabWidget->count() ;a++) {
603  fViewerTabWidget->widget(a)->resize(e->size());
604  }
605  }
606 }
607 
608 
611 G4UIsession* G4UIQt::SessionStart (
612 )
613 {
614  G4Qt* interactorManager = G4Qt::getInstance ();
615  Prompt("Session :");
616  exitSession = false;
617 
618  QCoreApplication::sendPostedEvents () ;
619 
620  #if QT_VERSION < 0x040200
621  fMainWindow->show();
622  #else
623  fMainWindow->setVisible(true);
624  #endif
625  interactorManager->DisableSecondaryLoop (); // TO KEEP
626  if ((QApplication*)interactorManager->GetMainInteractor())
627  ((QApplication*)interactorManager->GetMainInteractor())->exec();
628 
629  interactorManager->EnableSecondaryLoop ();
630  return this;
631 }
632 
633 
639 void G4UIQt::Prompt (
640  G4String aPrompt
641 )
642 {
643  if (!aPrompt) return;
644 
645  fCommandLabel->setText((char*)aPrompt.data());
646 }
647 
648 
649 
650 void G4UIQt::SessionTerminate (
651 )
652 {
653  G4Qt* interactorManager = G4Qt::getInstance ();
654  fMainWindow->close();
655  ((QApplication*)interactorManager->GetMainInteractor())->exit();
656 }
657 
658 
659 
668 void G4UIQt::PauseSessionStart (
669  const G4String& aState
670 )
671 {
672  if (!aState) return;
673 
674  if(aState=="G4_pause> ") { // TO KEEP
675  SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP
676  } // TO KEEP
677 
678  if(aState=="EndOfEvent") { // TO KEEP
679  // Picking with feed back in event data Done here !!!
680  SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP
681  } // TO KEEP
682 }
683 
684 
685 
690 void G4UIQt::SecondaryLoop (
691  G4String aPrompt
692 )
693 {
694  if (!aPrompt) return;
695 
696  G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ?
697  Prompt(aPrompt); // TO KEEP
698  exitPause = false; // TO KEEP
699  while(1) {
700  ((QApplication*)interactorManager)->processEvents(QEventLoop::WaitForMoreEvents);
701  if(exitPause==true) break; // TO KEEP
702  } // TO KEEP
703  Prompt("Session :"); // TO KEEP
704 }
705 
706 
707 
713 G4int G4UIQt::ReceiveG4cout (
714  const G4String& aString
715  )
716 {
717  if (!aString) return 0;
718 
719  QStringList newStr;
720 
721  // Add to stringList
722  newStr = QStringList(QString((char*)aString.data()).trimmed());
723  fG4cout += newStr;
724 
725  QStringList result = newStr.filter(fCoutFilter->text());
726 
727  if (result.join("").isEmpty()) {
728  return 0;
729  }
730  fCoutTBTextArea->append(result.join(""));
731  fCoutTBTextArea->repaint();
732 
733  fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
734 
735  return 0;
736 }
737 
738 
744 G4int G4UIQt::ReceiveG4cerr (
745  const G4String& aString
746 )
747 {
748  if (!aString) return 0;
749 
750  QStringList newStr;
751 
752  // Add to stringList
753  newStr = QStringList(QString((char*)aString.data()).trimmed());
754  fG4cout += newStr;
755 
756  QStringList result = newStr.filter(fCoutFilter->text());
757 
758  // Suppress space, \n,\t,\r...
759  if (QString(aString.data()).trimmed() != "") {
762  // In case of Abort or Quit, the useful error message should be in the last error message !
763  QMessageBox::critical(fMainWindow, "Error",QString(fLastErrMessage.data())+"\n"+aString.data());
764  }
765  }
766  QColor previousColor = fCoutTBTextArea->textColor();
767  fCoutTBTextArea->setTextColor(Qt::red);
768  fCoutTBTextArea->append(result.join("\n"));
769  fCoutTBTextArea->setTextColor(previousColor);
770  fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
771  fCoutTBTextArea->repaint();
772 
773  if (QString(aString.data()).trimmed() != "") {
774  fLastErrMessage = aString;
775  }
776  return 0;
777 }
778 
779 
780 
786 void G4UIQt::AddMenu (
787  const char* aName
788 ,const char* aLabel
789 )
790 {
791  if (aName == NULL) return;
792  if (aLabel == NULL) return;
793 
794  QMenu *fileMenu = new QMenu(aLabel);
795  fMainWindow->menuBar()->addMenu(fileMenu);
796 
797  AddInteractor (aName,(G4Interactor)fileMenu);
798 }
799 
800 
807 void G4UIQt::AddButton (
808  const char* aMenu
809 ,const char* aLabel
810 ,const char* aCommand
811 )
812 {
813  if(aMenu==NULL) return; // TO KEEP
814  if(aLabel==NULL) return; // TO KEEP
815  if(aCommand==NULL) return; // TO KEEP
816 
817  QMenu *parentTmp = (QMenu*)GetInteractor(aMenu);
818 
819  if(parentTmp==NULL) {
820  G4UImanager* UImanager = G4UImanager::GetUIpointer();
821  G4int verbose = UImanager->GetVerboseLevel();
822 
823  if (verbose >= 2) {
824  G4cout << "Menu name " << aMenu<< " does not exist, please define it before using it."<< G4endl;
825  }
826  return;
827  }
828 
829  // Find the command in the command tree
831  if(UI==NULL) return;
832  G4UIcommandTree * treeTop = UI->GetTree();
833 
834  G4String cmd = aCommand;
835  G4int cmdEndPos = cmd.find_first_of(" \t");
836  if(cmdEndPos!=G4int(std::string::npos)) {
837  cmd.erase(cmdEndPos);
838  }
839 
840  if(treeTop->FindPath(cmd) == NULL) {
841  G4UImanager* UImanager = G4UImanager::GetUIpointer();
842  G4int verbose = UImanager->GetVerboseLevel();
843 
844  if (verbose >= 2) {
845  G4cout << "Warning: command '"<< cmd <<"' does not exist, please define it before using it."<< G4endl;
846  }
847  }
848 
849  QSignalMapper *signalMapper = new QSignalMapper(this);
850  QAction *action = parentTmp->addAction(aLabel, signalMapper, SLOT(map()));
851 
852  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&)));
853  signalMapper->setMapping(action, QString(aCommand));
854 }
855 
856 
857 
858 
862 void G4UIQt::AddIcon(const char* aLabel, const char* aIconFile, const char* aCommand, const char* aFileName){
863  if(aLabel==NULL) return; // TO KEEP
864  // special case, aCommand could be NULL if aIconFile is not user_icon
865  if (aCommand==NULL) {
866  if (std::string(aIconFile) == "user_icon") {
867  return; // TO KEEP
868  }
869  }
870  QPixmap pix;
871  bool userToolBar = false;
872 
873  if (std::string(aIconFile) == "user_icon") {
874  // try to open a file
875  pix = QPixmap(aFileName);
876  if (pix.isNull()) {
877  G4UImanager* UImanager = G4UImanager::GetUIpointer();
878  G4int verbose = UImanager->GetVerboseLevel();
879 
880  if (verbose >= 2) {
881  G4cout << "Warning: file '"<< aFileName <<"' is incorrect or does not exist, this command will not be build"<< G4endl;
882  }
883  return;
884  }
885  userToolBar = true;
886  } else if (std::string(aIconFile) == "open") {
887  const char * const xpm[]={
888  "32 32 33 1",
889  " c None",
890  "+ c #09091E",
891  "@ c #191B18",
892  "# c #5F615F",
893  "$ c #777977",
894  "% c #AEB1AF",
895  "& c #929491",
896  "* c #515250",
897  "= c #858784",
898  "- c #333533",
899  "; c #000100",
900  "> c #272926",
901  ", c #424341",
902  "' c #696C6A",
903  ") c #5F4927",
904  "! c #583D18",
905  "~ c #6E6A5B",
906  "{ c #47351D",
907  "] c #E0A554",
908  "^ c #FFD67B",
909  "/ c #EFB465",
910  "( c #FDBF6C",
911  "_ c #FFCD76",
912  ": c #806238",
913  "< c #362611",
914  "[ c #0B0D0A",
915  "} c #68471B",
916  "| c #523E22",
917  "1 c #B78A51",
918  "2 c #A17B44",
919  "3 c #D6A45E",
920  "4 c #C29354",
921  "5 c #A1A3A0",
922  " ",
923  " ",
924  " +@@@# ",
925  " $% +& * ",
926  " #= $ -; ",
927  " %>;+ ",
928  " ,;;+ ",
929  " &#$''#' >;;;+ ",
930  " =)!)!!!!~ *#$'' ",
931  " {]^/((_({- %%%%%%%%%%% ",
932  " {(^_^^^^:<{{{{{{{{{{{{{[& ",
933  " {/_/(((((/]]]]]]]]]]]/]!# ",
934  " {/^(((((_^^^^^^^^^^^^^^:# ",
935  " {/^(((_^^____________^^}$ ",
936  " {/^(((((/////////////((!# ",
937  " {/^/^_:<|||||||||||||||@@****1 ",
938  " {/^/^(<[)||||||||||||||))!!}<; ",
939  " {/^_(:|234444444444444444432)1 ",
940  " {/_^/<)34444444444444444443}, ",
941  " {/^(2{:41111111111111111142|5 ",
942  " {3^3<:31111111111111111143}- ",
943  " {/^2<:31111111111111111441|' ",
944  " {_/<:41111111111111111143}, ",
945  " {(4<:31111111111111111144!# ",
946  " )4))44111111111111111144}, ",
947  " )2<:31111111111111111144{# ",
948  " @|:14444444444444444444}* ",
949  " ;@434444444444444444434<# ",
950  " ;[))))))))))))))))))))!~ ",
951  " ++++++++++++++++++++++;% ",
952  " ",
953  " "}
954  ;
955  pix = QPixmap(xpm);
956 
957  } else if (std::string(aIconFile) == "save") {
958  const char * const xpm[]={
959  "32 32 24 1",
960  " c None",
961  "+ c #000200",
962  "@ c #141E43",
963  "# c #000C56",
964  "$ c #494A47",
965  "% c #636662",
966  "& c #312F2A",
967  "* c #191B19",
968  "= c #002992",
969  "- c #003DFF",
970  "; c #041DA5",
971  "> c #A8A9A3",
972  ", c #FDFFFC",
973  "' c #DDE0DD",
974  ") c #818783",
975  "! c #C9CBC8",
976  "~ c #0116C3",
977  "{ c #C5C8FA",
978  "] c #6596FC",
979  "^ c #A0B4F9",
980  "/ c #0B2AFD",
981  "( c #799BE3",
982  "_ c #5F4826",
983  ": c #D5D8D5",
984  " ",
985  " ",
986  " +++++++++++++++++++++++++ ",
987  " +@##+$%%%%%%%%%%%%%%%&*$%&+ ",
988  " +=-;@>,,''',,,,,,,',,)&!,)+ ",
989  " +;-~@>,,,,,,,,,,,,,,,>$!,)+ ",
990  " +=-~@>,,,,,{]]]]]^,,,>*&$&+ ",
991  " +=-~@>,,,,,'{^{^^{,,,>*#=#+ ",
992  " +=-~@>,,,,,,,,,,,,,,,>@~/=+ ",
993  " +=-~@>,,,{{{''''{',,,>@~-=+ ",
994  " +=-~@>,,'^]]]]]]({,,,>@~-=+ ",
995  " +=-~@>,,,{{{{{{{{{,,,>@~-=+ ",
996  " +=-~@>,,,,,'{^{{^{,,,>@~-=+ ",
997  " +=-~@>,,,,,]]]]]]],,,>@~-=+ ",
998  " +=-~*>,,,,,,,,,,,,,,,>@~-=+ ",
999  " +=-~@>,,,,,,,,,,,,,,,>@~-=+ ",
1000  " +=-/=$%%%%%%%%%%%%%%%$=/-=+ ",
1001  " +=---;###############;---=+ ",
1002  " +=---////////////////----=+ ",
1003  " +=----------------///----=+ ",
1004  " +=---=@##############@#--=+ ",
1005  " +=---@+++++++++++*%))_+~-=+ ",
1006  " +=---#+++++++++++&:,,>@~-=+ ",
1007  " +=---#+++++++++++$',,>@~-=+ ",
1008  " +=---#+++++++++++&!,,>@~-=+ ",
1009  " +=/--#+++++++++++&',,>@~-=+ ",
1010  " @;--#+++++++++++$',,>@~-=+ ",
1011  " @;;@+++++++++++*)!>%@=;#+ ",
1012  " @++++++++++++++*&**++@++ ",
1013  " ",
1014  " ",
1015  " "}
1016  ;
1017  pix = QPixmap(xpm);
1018  } else if (std::string(aIconFile) == "move") {
1019  const char * const xpm[]={
1020  "32 32 16 1",
1021  " c None",
1022  ". c #F1F1F1",
1023  "+ c #939393",
1024  "@ c #282828",
1025  "# c #787878",
1026  "$ c #000000",
1027  "% c #CCCCCC",
1028  "& c #1A1A1A",
1029  "* c #0D0D0D",
1030  "= c #5D5D5D",
1031  "- c #AEAEAE",
1032  "; c #BBBBBB",
1033  "> c #C9C9C9",
1034  ", c #D6D6D6",
1035  "' c #FFFFFF",
1036  ") c #999999",
1037  " ",
1038  " ",
1039  " ",
1040  " ",
1041  " .. ",
1042  " ++ ",
1043  " .@@. ",
1044  " #$$# ",
1045  " %&$$*% ",
1046  " =$$$$= ",
1047  " -**$$**- ",
1048  " %;%&*>;% ",
1049  " -% @& %- ",
1050  " ,=*; @& ;*=, ",
1051  " .#*$$> >$$*#. ",
1052  " ')&$$$$*@@ @@*$$$$&)' ",
1053  " ')&$$$$*@@ @@*$$$$&+' ",
1054  " .#*$$> >$$*#. ",
1055  " ,=*; @& ;*=, ",
1056  " -% @& %- ",
1057  " %;%&*>>% ",
1058  " -**$$**- ",
1059  " =$$$$= ",
1060  " %&$$*% ",
1061  " #$$# ",
1062  " .@@. ",
1063  " ++ ",
1064  " .. ",
1065  " ",
1066  " ",
1067  " ",
1068  " "}
1069  ;
1070  pix = QPixmap(xpm);
1071 
1072  } else if (std::string(aIconFile) == "rotate") {
1073  const char * const xpm[]={
1074  "32 32 27 1",
1075  " c None",
1076  ". c #003333",
1077  "+ c #000066",
1078  "@ c #1A1A1A",
1079  "# c #003399",
1080  "$ c #3333CC",
1081  "% c #000033",
1082  "& c #353535",
1083  "* c #434343",
1084  "= c #336699",
1085  "- c #3399FF",
1086  "; c #003366",
1087  "> c #5D5D5D",
1088  ", c #282828",
1089  "' c #3399CC",
1090  ") c #333333",
1091  "! c #3366CC",
1092  "~ c #333399",
1093  "{ c #505050",
1094  "] c #666666",
1095  "^ c #333366",
1096  "/ c #0033CC",
1097  "( c #3366FF",
1098  "_ c #336666",
1099  ": c #787878",
1100  "< c #868686",
1101  "[ c #6B6B6B",
1102  " .++@ ",
1103  " #$$%&* ",
1104  " =--; *>, ",
1105  " '-= )>& ",
1106  " !-', ,>* ",
1107  " !!=--= >* ",
1108  " =------!!~@&)@ ",
1109  " --------!*{{{*&, ",
1110  " -------=){*{{{>>{) ",
1111  " ,!-----= ){& ,&{{@",
1112  " ,*>!----= &>& )@",
1113  " ){>)~---= *]) @",
1114  " @*>, --! ,&@ ",
1115  " @{* '! ,-!=~^,@ ",
1116  " @& == {/(----!^ ",
1117  " _ ]:;(----' ",
1118  " ==_ >{+(----~ ",
1119  " !-!!======!!(((---! ",
1120  " ='--------------! ",
1121  " =!!!!'!!=; !-! ",
1122  " &<* !~ ",
1123  " @. *[* ; ",
1124  " ;+)>* ",
1125  " @@ ",
1126  " ",
1127  " ",
1128  " ",
1129  " ",
1130  " ",
1131  " ",
1132  " ",
1133  " "}
1134  ;
1135  pix = QPixmap(xpm);
1136 
1137  } else if (std::string(aIconFile) == "pick") {
1138  const char * const xpm[]={
1139  "32 32 2 1",
1140  " c None",
1141  ". c #000000",
1142  " ",
1143  " ",
1144  " ",
1145  " ",
1146  " ",
1147  " ",
1148  " ",
1149  " . ",
1150  " .. ",
1151  " ... ",
1152  " .... ",
1153  " ..... ",
1154  " ...... ",
1155  " ....... ",
1156  " ....... ",
1157  " ........ ",
1158  " ..... ",
1159  " ...... ",
1160  " .. .. ",
1161  " . .. ",
1162  " ... ",
1163  " .. ",
1164  " .. ",
1165  " ",
1166  " ",
1167  " ",
1168  " ",
1169  " ",
1170  " ",
1171  " ",
1172  " ",
1173  " "}
1174  ;
1175  pix = QPixmap(xpm);
1176  } else if (std::string(aIconFile) == "zoom_in") {
1177  const char * const xpm[]={
1178  "32 32 11 1",
1179  " c None",
1180  ". c #C9CBC8",
1181  "+ c #A8A9A3",
1182  "@ c #818783",
1183  "# c #D5D8D5",
1184  "$ c #9BCCCC",
1185  "% c #5FC7F4",
1186  "& c #FDFFFC",
1187  "* c #636662",
1188  "= c #9599CE",
1189  "- c #DDE0DD",
1190  " ",
1191  " ",
1192  " ",
1193  " ",
1194  " ",
1195  " .++@@++. ",
1196  " +++..#.+++ ",
1197  " .@+...++++#+@. ",
1198  " @$.%%+&&&@%..@ ",
1199  " ++.%%%+&&&*%%.++ ",
1200  " .+#%%%%+&&&*%%.#+ ",
1201  " ++..%%%+&&&*%%%.++ ",
1202  " +#.+++++&&&*++++.+ ",
1203  " @.+&&&&&&&&&&&&&+@ ",
1204  " @#+&&&&&&&&&&&&&+@ ",
1205  " @.+&&&&&&&&&&&&&+. ",
1206  " +++@***+&&&****@+. ",
1207  " ....++++&&&*++++.. ",
1208  " ++.===+&&&*%=.++ ",
1209  " @..==+&&&*=..@#& ",
1210  " .@+#.+&&&@-+@@*@ ",
1211  " +++.++++++ *+@* ",
1212  " .+@@@++. @**+* ",
1213  " .*@*+* ",
1214  " .*@*+* ",
1215  " +*@@* ",
1216  " .**+ ",
1217  " ",
1218  " ",
1219  " ",
1220  " ",
1221  " "}
1222  ;
1223  pix = QPixmap(xpm);
1224  } else if (std::string(aIconFile) == "zoom_out") {
1225  const char * const xpm[]={
1226  "32 32 11 1",
1227  " c None",
1228  ". c #C9CBC8",
1229  "+ c #A8A9A3",
1230  "@ c #818783",
1231  "# c #D5D8D5",
1232  "$ c #5FC7F4",
1233  "% c #9BCCCC",
1234  "& c #FDFFFC",
1235  "* c #636662",
1236  "= c #9599CE",
1237  "- c #DDE0DD",
1238  " ",
1239  " ",
1240  " ",
1241  " ",
1242  " ",
1243  " .++@@++. ",
1244  " +++..#.+++ ",
1245  " .@+..$$$$.#+@. ",
1246  " @%.$$$$$$$$..@ ",
1247  " ++.$$$$$$$$$$.++ ",
1248  " .+#$$$$$$$$$$$.#+ ",
1249  " ++..$$$$$$$$$$$.++ ",
1250  " +#.+++++++++++++.+ ",
1251  " @.+&&&&&&&&&&&&&+@ ",
1252  " @#+&&&&&&&&&&&&&+@ ",
1253  " @.+&&&&&&&&&&&&&+. ",
1254  " +++@***********@+. ",
1255  " ....++++++++++++.. ",
1256  " ++.===$$$$$$=.++ ",
1257  " @..===$$$$=..@#& ",
1258  " .@+#.$$$..-+@@*@ ",
1259  " +++#--.+++ *+@* ",
1260  " .+@@@++. @**+* ",
1261  " .*@*+* ",
1262  " .*@*+* ",
1263  " +*@@* ",
1264  " .**+ ",
1265  " ",
1266  " ",
1267  " ",
1268  " ",
1269  " "}
1270  ;
1271  pix = QPixmap(xpm);
1272  } else if (std::string(aIconFile) == "wireframe") {
1273  const char * const xpm[]={
1274  "32 32 24 1",
1275  " c None",
1276  "+ c #E4E4E4",
1277  "@ c #D5D5D5",
1278  "# c #E1E1E1",
1279  "$ c #E7E7E7",
1280  "% c #D8D8D8",
1281  "& c #A7A7A7",
1282  "* c #000000",
1283  "= c #989898",
1284  "- c #8A8A8A",
1285  "; c #B5B5B5",
1286  "> c #1B1B1B",
1287  ", c #676767",
1288  "' c #959595",
1289  ") c #4A4A4A",
1290  "! c #878787",
1291  "~ c #D3D3D3",
1292  "{ c #C4C4C4",
1293  "] c #A4A4A4",
1294  "^ c #5B5B5B",
1295  "/ c #B3B3B3",
1296  "( c #787878",
1297  "_ c #C7C7C7",
1298  ": c #585858",
1299  " ",
1300  " +@@# ",
1301  " $%@@@@@&****=+ ",
1302  " +&********&@-***; ",
1303  " +@@@&**&@@@@@@$ @*-&>&+ ",
1304  " +*****&+ %*@ ,**'# ",
1305  " @***)!~ @*{&*****+ ",
1306  " @*!]***&+ +-*^**'~!*@ ",
1307  " @*~ +@&**&@@@@@@&****&+ ~*@ ",
1308  " @*@ +&********&-*= @*@ ",
1309  " @*@ $%@-*-@$ @*@ @*@ ",
1310  " @*@ @*@ %*% @*@ ",
1311  " @*@ %*% %*% @*@ ",
1312  " @*@ %*% %*% @*@ ",
1313  " @*@ %*% %*% @*@ ",
1314  " @*@ %*% %*% @*@ ",
1315  " @*@ %*% %*% @*@ ",
1316  " @*@ @*@ %*% @*@ ",
1317  " @*@ =*-+ @*@ @*@ ",
1318  " @*@ $%@@&****&@-*-+ @*@ ",
1319  " @*@ $@&*****&@@&******&~~!*@ ",
1320  " @*{/***&@@%$ $@-*-&*****+ ",
1321  " @*)*)(-~ @*@ ~)**] ",
1322  " +*******&@@@@+ %*_+]**] ",
1323  " +@@@@@&******&@%+_*^**]# ",
1324  " $%@@@&****:**&+ ",
1325  " +%@&**& ",
1326  " ++ ",
1327  " ",
1328  " ",
1329  " ",
1330  " "}
1331  ;
1332  pix = QPixmap(xpm);
1333  } else if (std::string(aIconFile) == "solid") {
1334  const char * const xpm[]={
1335  "32 32 33 1",
1336  " c None",
1337  "+ c #C2DEDE",
1338  "@ c #B5D7DF",
1339  "# c #ACD6E6",
1340  "$ c #60C0EC",
1341  "% c #4EB7EE",
1342  "& c #53B9ED",
1343  "* c #82CEEA",
1344  "= c #CFDDDA",
1345  "- c #94C9E8",
1346  "; c #0960FF",
1347  "> c #0943FF",
1348  ", c #0949FF",
1349  "' c #3CB3F0",
1350  ") c #71C7EB",
1351  "! c #73CBE5",
1352  "~ c #D3DDDB",
1353  "{ c #C4DDDE",
1354  "] c #B7D5DF",
1355  "^ c #2DACF5",
1356  "/ c #59C1ED",
1357  "( c #5FC0ED",
1358  "_ c #85CEE9",
1359  ": c #096BFF",
1360  "< c #2AACF6",
1361  "[ c #5CBEEC",
1362  "} c #7ACAE4",
1363  "| c #73CAEB",
1364  "1 c #71C8E5",
1365  "2 c #D1DDDA",
1366  "3 c #CBDDD9",
1367  "4 c #67C1EB",
1368  "5 c #80CDEA",
1369  " ",
1370  " ",
1371  " +@@@@@@#$%&*= ",
1372  " +-;>>>>>>>>>,')!~ ",
1373  " {]@@-;>>>>>>>>>>>>^/(_= ",
1374  " {:>>>>>>>>>>>>>>>>><//[)!= ",
1375  " ]>>>>>>>>>>>>>>>>>><////[)} ",
1376  " @>>>>>>>>>>>>>>>>>><//////| ",
1377  " @>>>>>>>>>>>>>>>>>><//////| ",
1378  " @>>>>>>>>>>>>>>>>>><//////| ",
1379  " @>>>>>>>>>>>>>>>>>><//////| ",
1380  " @>>>>>>>>>>>>>>>>>><//////| ",
1381  " @>>>>>>>>>>>>>>>>>><//////| ",
1382  " @>>>>>>>>>>>>>>>>>><//////| ",
1383  " @>>>>>>>>>>>>>>>>>><//////| ",
1384  " @>>>>>>>>>>>>>>>>>><//////| ",
1385  " @>>>>>>>>>>>>>>>>>><//////| ",
1386  " @>>>>>>>>>>>>>>>>>><//////| ",
1387  " @>>>>>>>>>>>>>>>>>><//////| ",
1388  " @>>>>>>>>>>>>>>>>>><//////| ",
1389  " @>>>>>>>>>>>>>>>>>><//////| ",
1390  " @>>>>>>>>>>>>>>>>>></////[1 ",
1391  " @>>>>>>>>>>>>>>>>>><////[*2 ",
1392  " {:>>>>>>>>>>>>>>>>><//[)12 ",
1393  " +@@@@@-;>>>>>>>>>><[)13 ",
1394  " {]@@@-;>>>,'*3 ",
1395  " +@@#452 ",
1396  " ",
1397  " ",
1398  " ",
1399  " ",
1400  " "}
1401  ;
1402  pix = QPixmap(xpm);
1403  } else if (std::string(aIconFile) == "hidden_line_removal") {
1404  const char * const xpm[]={
1405  "32 32 15 1",
1406  " c None",
1407  "+ c #D5D5D5",
1408  "@ c #C7C7C7",
1409  "# c #9C9C9C",
1410  "$ c #000000",
1411  "% c #8E8E8E",
1412  "& c #808080",
1413  "* c #A9A9A9",
1414  "= c #D8D8D8",
1415  "- c #CACACA",
1416  "; c #181818",
1417  "> c #9F9F9F",
1418  ", c #ACACAC",
1419  "' c #B9B9B9",
1420  ") c #555555",
1421  " ",
1422  " +@@+ ",
1423  " +@@@@@@#$$$$%+ ",
1424  " +#$$$$$$$$#@&$$$* ",
1425  " =-@@#$$#@@@@@-= @$&#;>= ",
1426  " =$$$$$#+ -$@ *$$%+ ",
1427  " -$&@-= -$- #$$$= ",
1428  " -$@ -$- +&$- ",
1429  " @$@ @$@ @$@ ",
1430  " @$@ @$@ @$@ ",
1431  " @$@ @$@ @$@ ",
1432  " @$@ @$@ @$@ ",
1433  " @$@ @$@ @$@ ",
1434  " @$@ @$@ @$@ ",
1435  " @$@ @$@ @$@ ",
1436  " @$@ @$@ @$@ ",
1437  " @$@ @$@ @$@ ",
1438  " @$@ @$@ @$@ ",
1439  " @$@ @$@ @$@ ",
1440  " @$@ @$@ @$@ ",
1441  " @$@ @$@ @$@ ",
1442  " @$@ @$@ #$= ",
1443  " -$&@@@-= -$- =>;, ",
1444  " =$$$$$$$#@@@-= -$'+#$$, ",
1445  " =-@@@@#$$$$$$#@-+'$)$$#+ ",
1446  " =-@@@#$$$$)$$#+ ",
1447  " +@@#$$# ",
1448  " ++ ",
1449  " ",
1450  " ",
1451  " ",
1452  " "}
1453  ;
1454  pix = QPixmap(xpm);
1455  } else if (std::string(aIconFile) == "hidden_line_and_surface_removal") {
1456  const char * const xpm[]={
1457  "32 32 40 1",
1458  " c None",
1459  "+ c #FFFFFF",
1460  "@ c #89A2E9",
1461  "# c #5378E3",
1462  "$ c #A2B5ED",
1463  "% c #5379E3",
1464  "& c #5076E3",
1465  "* c #3E69E4",
1466  "= c #0C43F8",
1467  "- c #043FFE",
1468  "; c #CDD9ED",
1469  "> c #BDCDE9",
1470  ", c #FBFCFC",
1471  "' c #406AE4",
1472  ") c #0439FE",
1473  "! c #0137FF",
1474  "~ c #4F75E3",
1475  "{ c #9EB5E3",
1476  "] c #829FE0",
1477  "^ c #B6C6E7",
1478  "/ c #9DB4E3",
1479  "( c #7E9CE0",
1480  "_ c #B2C3E9",
1481  ": c #7E9AE0",
1482  "< c #86A2E1",
1483  "[ c #CAD6ED",
1484  "} c #5177E3",
1485  "| c #829CE0",
1486  "1 c #BCCCE9",
1487  "2 c #3A67E6",
1488  "3 c #0A43FA",
1489  "4 c #95ACE1",
1490  "5 c #BBCBE9",
1491  "6 c #A9BBE5",
1492  "7 c #96AFE1",
1493  "8 c #BDCBE9",
1494  "9 c #4067E4",
1495  "0 c #6485E5",
1496  "a c #E3EAF3",
1497  "b c #CAD6F3",
1498  " ",
1499  " ",
1500  " ++++ ",
1501  " ++++++++@#$+++ ",
1502  " ++@%####&*=-#+;>, ",
1503  " +++++@'=)))))))!)~+{]^++ ",
1504  " +$%&*=)!!!!!!!!!)~+/(]_+++ ",
1505  " +#-))!!!!!!!!!!!)~+/(::<[+ ",
1506  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1507  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1508  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1509  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1510  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1511  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1512  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1513  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1514  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1515  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1516  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1517  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1518  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1519  " +#)!!!!!!!!!!!!!!}+/:::|1+ ",
1520  " +$#}}~23!!!!!!!!)~+/(]45, ",
1521  " +++++++@#}}~23!!)~+678++ ",
1522  " ++++++@#~90+a++ ",
1523  " ++++b++ ",
1524  " ++ ",
1525  " ",
1526  " ",
1527  " ",
1528  " ",
1529  " "}
1530  ;
1531  pix = QPixmap(xpm);
1532  } else if (std::string(aIconFile) == "perspective") {
1533  const char * const xpm[]={
1534  "32 32 3 1",
1535  " c None",
1536  ". c #D5D8D5",
1537  "+ c #000000",
1538  " ",
1539  " ",
1540  " ",
1541  " ",
1542  " ",
1543  " ................ ",
1544  " ....+++++++++++++++. ",
1545  " ...++++..+.........+++. ",
1546  " ..++..............++..+. ",
1547  " .+++++++++++++++++.. .+. ",
1548  " .+...............+. .+. ",
1549  " .+. .+. .+. .+. ",
1550  " .+. .+. .+. .+. ",
1551  " .+. .+. .+. .+. ",
1552  " .+. .+. .+. .+. ",
1553  " .+. .+. .+. .+. ",
1554  " .+. .+. .+. .+. ",
1555  " .+. .+. .+. .+. ",
1556  " .+. .+. .+. .+. ",
1557  " .+. .+......+....+. ",
1558  " .+. ..++++++.+.++++. ",
1559  " .+. .++.......+...+.. ",
1560  " .+. .++. .+..++. ",
1561  " .+. ..+.. .+..+. ",
1562  " .+..++. .+.+. ",
1563  " .+.++. .+++. ",
1564  " .+++.............++. ",
1565  " .+++++++++++++++++. ",
1566  " ................... ",
1567  " ",
1568  " ",
1569  " "}
1570  ;
1571  pix = QPixmap(xpm);
1572  } else if (std::string(aIconFile) == "ortho") {
1573  const char * const xpm[]={
1574  "32 32 3 1",
1575  " c None",
1576  ". c #D5D8D5",
1577  "@ c #000000",
1578  " ",
1579  " ",
1580  " ",
1581  " ................... ",
1582  " ..@@@@@@@@@@@@@@@@@. ",
1583  " ..@@@.............@@@. ",
1584  " ..@@.@. ..@..@. ",
1585  " ..@@ ..@. .@@...@. ",
1586  " ..@@..............@@.. .@. ",
1587  " .@@@@@@@@@@@@@@@@@.. .@. ",
1588  " .@...............@. .@. ",
1589  " .@. .@. .@. .@. ",
1590  " .@. .@. .@. .@. ",
1591  " .@. .@. .@. .@. ",
1592  " .@. .@. .@. .@. ",
1593  " .@. .@. .@. .@. ",
1594  " .@. .@. .@. .@. ",
1595  " .@. .@. .@. .@. ",
1596  " .@. .@. .@. .@. ",
1597  " .@. .@. .@. .@. ",
1598  " .@. .@. .@. .@. ",
1599  " .@. .@........@......@. ",
1600  " .@. .@@@@@@@@@.@.@@@@@@. ",
1601  " .@. .@@+........@....@@.. ",
1602  " .@...@. .@...@... ",
1603  " .@.@@. .@.@@ . ",
1604  " .@@@.............@@@.. ",
1605  " .@@@@@@@@@@@@@@@@@... ",
1606  " ................... ",
1607  " ",
1608  " ",
1609  " "}
1610  ;
1611  pix = QPixmap(xpm);
1612  } else {
1613  G4UImanager* UImanager = G4UImanager::GetUIpointer();
1614  G4int verbose = UImanager->GetVerboseLevel();
1615 
1616  if (verbose >= 2) {
1617  G4cout << "Parameter"<< aIconFile <<" not defined"<< G4endl;
1618  }
1619  return;
1620  }
1621  QToolBar *currentToolbar = NULL;
1622  if (userToolBar) {
1623  if (fToolbarUser == NULL) {
1624  fToolbarUser = new QToolBar();
1625  fToolbarUser->setIconSize (QSize(20,20));
1626  fMainWindow->addToolBar(Qt::TopToolBarArea, fToolbarUser);
1627  }
1628  currentToolbar = fToolbarUser;
1629  } else {
1630  if (fToolbarApp == NULL) {
1631  fToolbarApp = new QToolBar();
1632  fToolbarApp->setIconSize (QSize(20,20));
1633  fMainWindow->addToolBar(Qt::TopToolBarArea, fToolbarApp);
1634  }
1635  currentToolbar = fToolbarApp;
1636  }
1637 
1638  QSignalMapper *signalMapper = new QSignalMapper(this);
1639  QAction *action = currentToolbar->addAction(pix,aLabel, signalMapper, SLOT(map()));
1640 
1641 
1642  // special cases :"open"
1643  if (std::string(aIconFile) == "open") {
1644  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(OpenIconCallback(const QString &)));
1645  QString txt = aCommand + fStringSeparator + aLabel;
1646  signalMapper->setMapping(action, QString(txt));
1647 
1648  // special cases :"save"
1649  } else if (std::string(aIconFile) == "save") {
1650  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(SaveIconCallback(const QString&)));
1651  QString txt = aCommand + fStringSeparator + aLabel;
1652  signalMapper->setMapping(action, QString(txt));
1653 
1654  // special cases : cursor style
1655  } else if ((std::string(aIconFile) == "move") ||
1656  (std::string(aIconFile) == "rotate") ||
1657  (std::string(aIconFile) == "pick") ||
1658  (std::string(aIconFile) == "zoom_out") ||
1659  (std::string(aIconFile) == "zoom_in")) {
1660  action->setCheckable(TRUE);
1661  action->setChecked(TRUE);
1662  action->setData(aIconFile);
1663 
1664  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ChangeCursorStyle(const QString&)));
1665  signalMapper->setMapping(action, QString(aIconFile));
1666 
1667  if (std::string(aIconFile) == "move") {
1668  SetIconMoveSelected();
1669  }
1670  if (std::string(aIconFile) == "rotate") {
1671  SetIconRotateSelected();
1672  }
1673  if (std::string(aIconFile) == "pick") {
1674  SetIconPickSelected();
1675  }
1676  if (std::string(aIconFile) == "zoom_in") {
1677  SetIconZoomInSelected();
1678  }
1679  if (std::string(aIconFile) == "zoom_out") {
1680  SetIconZoomOutSelected();
1681  }
1682 
1683  // special case : surface style
1684  } else if ((std::string(aIconFile) == "hidden_line_removal") ||
1685  (std::string(aIconFile) == "hidden_line_and_surface_removal") ||
1686  (std::string(aIconFile) == "solid") ||
1687  (std::string(aIconFile) == "wireframe")) {
1688  action->setCheckable(TRUE);
1689  action->setChecked(TRUE);
1690  action->setData(aIconFile);
1691  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ChangeSurfaceStyle(const QString&)));
1692  signalMapper->setMapping(action, QString(aIconFile));
1693 
1694  if (std::string(aIconFile) == "hidden_line_removal") {
1695  SetIconHLRSelected();
1696  }
1697  if (std::string(aIconFile) == "hidden_line_and_surface_removal") {
1698  SetIconHLHSRSelected();
1699  }
1700  if (std::string(aIconFile) == "solid") {
1701  SetIconSolidSelected();
1702  }
1703  if (std::string(aIconFile) == "wireframe") {
1704  SetIconWireframeSelected();
1705  }
1706 
1707  // special case : perspective/ortho
1708  } else if ((std::string(aIconFile) == "perspective") ||
1709  (std::string(aIconFile) == "ortho")) {
1710  action->setCheckable(TRUE);
1711  action->setChecked(TRUE);
1712  action->setData(aIconFile);
1713  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ChangePerspectiveOrtho(const QString&)));
1714  signalMapper->setMapping(action, QString(aIconFile));
1715 
1716  if (std::string(aIconFile) == "perspective") {
1717  SetIconPerspectiveSelected();
1718  }
1719  if (std::string(aIconFile) == "ortho") {
1720  SetIconOrthoSelected();
1721  }
1722 
1723  } else {
1724 
1725  // Find the command in the command tree
1727  if(UI==NULL) return;
1728  G4UIcommandTree * treeTop = UI->GetTree();
1729  if (aCommand != NULL) {
1730  if(treeTop->FindPath(aCommand) == NULL) {
1731  G4UImanager* UImanager = G4UImanager::GetUIpointer();
1732  G4int verbose = UImanager->GetVerboseLevel();
1733 
1734  if (verbose >= 2) {
1735  G4cout << "Warning: command '"<< aCommand <<"' does not exist, please define it before using it."<< G4endl;
1736  }
1737  }
1738  }
1739 
1740  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&)));
1741  signalMapper->setMapping(action, QString(aCommand));
1742  }
1743 }
1744 
1745 
1746 
1747 void G4UIQt::ActivateCommand(
1748  G4String newCommand
1749 )
1750 {
1751  if (!fHelpTreeWidget) {
1752  return;
1753  }
1754  // Look for the choosen command "newCommand"
1755  size_t i = newCommand.index(" ");
1756  G4String targetCom ="";
1757  if( i != std::string::npos )
1758  {
1759  G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
1760  newValue.strip(G4String::both);
1761  targetCom = ModifyToFullPathCommand( newValue );
1762  }
1763  if (targetCom != "") {
1764  OpenHelpTreeOnCommand(targetCom.data());
1765  }
1766 
1767  fUITabWidget->setCurrentWidget(fHelpTBWidget);
1768 }
1769 
1770 
1771 
1778 void G4UIQt::InitHelpTreeAndVisParametersWidget()
1779 {
1780 
1781  if (! fHelpTreeWidget ) {
1782  fHelpTreeWidget = new QTreeWidget();
1783  }
1784 
1785  // build widget
1786  fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
1787  QStringList labels;
1788  labels << QString("Command");
1789  fHelpTreeWidget->setHeaderLabels(labels);
1790 
1791 
1792  connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback()));
1793  connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback()));
1794 
1795 }
1802 void G4UIQt::FillHelpTree()
1803 {
1804  if (! fHelpTreeWidget ) {
1805  InitHelpTreeAndVisParametersWidget();
1806  }
1807 
1808  QString searchText = fHelpLine->text();
1809 
1810  if (searchText =="") {
1811  // clear old help tree
1812  // fHelpTreeWidget->clear();
1813  } else {
1814  return;
1815  }
1816 
1817  if (fHelpArea) {
1818 #if QT_VERSION < 0x040200
1819  fHelpArea->clear();
1820 #else
1821  fHelpArea->setText("");
1822 #endif
1823  }
1824 
1825  if (fHelpLine) {
1826 #if QT_VERSION < 0x040200
1827  fHelpLine->clear();
1828 #else
1829  fHelpLine->setText("");
1830 #endif
1831  }
1832 
1834  if(UI==NULL) return;
1835  G4UIcommandTree * treeTop = UI->GetTree();
1836 
1837  G4int treeSize = treeTop->GetTreeEntry();
1838  QTreeWidgetItem * newItem = NULL;
1839  QString commandText = "";
1840  for (int a=0;a<treeSize;a++) {
1841  // Creating new item
1842  newItem = NULL;
1843 
1844  commandText = QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed();
1845 
1846  // if already exist, don't create it !
1847  for (int b=0;b<fHelpTreeWidget->topLevelItemCount();b++) {
1848  if (!newItem)
1849  newItem = FindTreeItem(fHelpTreeWidget->topLevelItem(b),commandText);
1850  }
1851 
1852  if (newItem == NULL) {
1853 
1854  newItem = new QTreeWidgetItem();
1855  newItem->setText(0,GetShortCommandPath(commandText));
1856  fHelpTreeWidget->addTopLevelItem(newItem);
1857  }
1858 
1859  // look for childs
1860  CreateHelpTree(newItem,treeTop->GetTree(a+1));
1861  }
1862 
1863 }
1864 
1865 
1866 
1871 void G4UIQt::CreateHelpTree(
1872  QTreeWidgetItem *aParent
1873 ,G4UIcommandTree *aCommandTree
1874 )
1875 {
1876  if (aParent == NULL) return;
1877  if (aCommandTree == NULL) return;
1878 
1879 
1880  // Creating new item
1881  QTreeWidgetItem * newItem;
1882 
1883  QString commandText = "";
1884  // Get the Sub directories
1885  for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
1886 
1887  commandText = QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed();
1888 
1889  // if already exist, don't create it !
1890  newItem = FindTreeItem(aParent,commandText);
1891  if (newItem == NULL) {
1892  newItem = new QTreeWidgetItem();
1893  newItem->setText(0,GetShortCommandPath(commandText));
1894  aParent->addChild(newItem);
1895  }
1896  CreateHelpTree(newItem,aCommandTree->GetTree(a+1));
1897  }
1898 
1899  // Get the Commands
1900 
1901  for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
1902 
1903  QStringList stringList;
1904  commandText = QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed();
1905 
1906  // if already exist, don't create it !
1907  newItem = FindTreeItem(aParent,commandText);
1908  if (newItem == NULL) {
1909  newItem = new QTreeWidgetItem();
1910  newItem->setText(0,GetShortCommandPath(commandText));
1911  aParent->addChild(newItem);
1912 
1913 #if QT_VERSION < 0x040202
1914  fHelpTreeWidget->setItemExpanded(newItem,false);
1915 #else
1916  newItem->setExpanded(false);
1917 #endif
1918  }
1919  }
1920 }
1921 
1922 
1923 
1924 
1930 bool G4UIQt::CreateVisCommandGroupAndToolBox(
1931  G4UIcommand* aCommand
1932 ,QWidget* aParent
1933 ,int aDepthLevel
1934 ,bool isDialog
1935 )
1936 {
1937  QString commandText = QString((char*)(aCommand->GetCommandPath().data())).section("/",-aDepthLevel);
1938 
1939  if (commandText == NULL) {
1940  return false;
1941  }
1942 
1943  // Look if groupBox is create
1944  // QGroupBox* gBoxCommandWidget;
1945  QWidget* newParentWidget = NULL;
1946  bool found = false;
1947  QString commandSection = commandText.left(commandText.indexOf("/"));
1948 
1949  if (aDepthLevel == 1) {
1950  QToolBox* currentParent = dynamic_cast<QToolBox*>(aParent);
1951  if (currentParent != 0){
1952 
1953  // already exists ?
1954  for (int a=0; a<currentParent->count(); a++) {
1955  if (currentParent->itemText(a) == commandSection) {
1956  found = true;
1957  newParentWidget = currentParent->widget(a);
1958  }
1959  }
1960  }
1961  // Not found ? create it
1962  if (!found) {
1963  newParentWidget = new QGroupBox();
1964  newParentWidget->setLayout(new QVBoxLayout());
1965  if (currentParent != 0){
1966  currentParent->addItem(newParentWidget,commandSection);
1967  } else {
1968  if (!aParent->layout()) {
1969  aParent->setLayout(new QVBoxLayout());
1970  }
1971  aParent->layout()->addWidget(newParentWidget);
1972  }
1973 
1974  if (commandText.indexOf("/") == -1) {
1975 
1976  // Guidance
1977  QString guidance;
1978  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
1979  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
1980  guidance += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
1981  }
1982  newParentWidget->setToolTip(guidance);
1983  }
1984 
1985  QScrollArea* sc = dynamic_cast<QScrollArea*>(newParentWidget->parent()->parent());
1986  if (sc != 0) {
1987  sc->ensureWidgetVisible(newParentWidget);
1988 
1989  }
1990  }
1991  } else {
1992 
1993  // try to know if this level is already there
1994  QGroupBox* currentParent = dynamic_cast<QGroupBox*>(aParent);
1995  if (currentParent != 0){
1996 
1997  // if depth==2, then we add a [more parameters inside] to the toolBoxItem parent
1998  // QGroupBox > QWidget > QScrollArea > QToolBox
1999  if (aDepthLevel == 2){
2000  QToolBox* parentToolBox = dynamic_cast<QToolBox*>(currentParent->parent()->parent()->parent());
2001  if (parentToolBox != 0) {
2002  // parentToolBox->setItemText(parentToolBox->indexOf(currentParent),"[more parameters inside]");
2003  }
2004  }
2005  for (int a=0; a<aParent->layout()->count(); a++) {
2006  QGroupBox* gb = dynamic_cast<QGroupBox*>(aParent->layout()->itemAt(a)->widget());
2007  if (gb != 0) {
2008  if (gb->title() == commandSection) {
2009  found = true;
2010  newParentWidget = gb;
2011  }
2012  }
2013  }
2014  }
2015 
2016  // Not found ? create it
2017  if (!found) {
2018  newParentWidget = new QGroupBox();
2019  newParentWidget->setLayout(new QVBoxLayout());
2020  if (!aParent->layout()) {
2021  aParent->setLayout(new QVBoxLayout());
2022  }
2023  aParent->layout()->addWidget(newParentWidget);
2024 
2025  // set toolTip
2026  // Guidance
2027  QString guidance;
2028  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
2029  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
2030  guidance += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
2031  }
2032  newParentWidget->setToolTip(guidance);
2033  }
2034  }
2035 
2036  // fill command groupbox
2037  if (commandText.indexOf("/") == -1) {
2038  if (CreateCommandWidget(aCommand, newParentWidget,isDialog)) {
2039  return true;
2040  }
2041  } else {
2042  CreateVisCommandGroupAndToolBox(aCommand,newParentWidget, aDepthLevel-1,isDialog);
2043  }
2044 
2045  return true;
2046 }
2047 
2048 
2049 
2055 bool G4UIQt::CreateCommandWidget(G4UIcommand* aCommand, QWidget* aParent, bool isDialog) {
2056 
2057  if (aCommand == NULL) {
2058  return false;
2059  }
2060 
2061 
2062  // parameters
2063  G4int n_parameterEntry = aCommand->GetParameterEntries();
2064  if( n_parameterEntry > 0 ) {
2065  G4UIparameter *param;
2066 
2067  // Re-implementation of G4UIparameter.cc
2068  QWidget* paramWidget = new QWidget();
2069  QGridLayout* gridLayout = new QGridLayout();
2070  paramWidget->setLayout(gridLayout);
2071 
2072  // Special case for colour, try to display a color chooser if we found red/green/blue parameter
2073  unsigned int nbColorParameter = 0;
2074  bool isStillColorParameter = false;
2075  bool isColorDialogAdded = false;
2076  QLabel* redLabel = NULL;
2077  QLabel* greenLabel = NULL;
2078  QString redDefaultStr = "";
2079  QString greenDefaultStr = "";
2080  QString blueDefaultStr = "";
2081  QWidget* redInput = NULL;
2082  QWidget* greenInput = NULL;
2083 
2084  for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
2085  QString txt;
2086  param = aCommand->GetParameter(i_thParameter);
2087  QLabel* label = new QLabel(QString((char*)(param->GetParameterName()).data()));
2088 
2089  if ((label->text() == "red") || (label->text() == "red_or_string")){
2090  nbColorParameter ++;
2091  isStillColorParameter = true;
2092  } else if ((label->text() == "green") && isStillColorParameter) {
2093  nbColorParameter ++;
2094  } else if ((label->text() == "blue") && isStillColorParameter) {
2095  nbColorParameter ++;
2096  } else if (!isColorDialogAdded) {
2097 
2098  // not following red/green/blue parameters ?
2099  if (nbColorParameter == 1) {
2100  gridLayout->addWidget(redLabel,i_thParameter-1,0);
2101  gridLayout->addWidget(redInput,i_thParameter-1,1);
2102  } else if (nbColorParameter == 2) {
2103  gridLayout->addWidget(redLabel,i_thParameter-2,0);
2104  gridLayout->addWidget(redInput,i_thParameter-2,1);
2105  gridLayout->addWidget(greenLabel,i_thParameter-1,0);
2106  gridLayout->addWidget(greenInput,i_thParameter-1,1);
2107  }
2108  nbColorParameter = 0;
2109  }
2110  // Check parameter type, could be NULL if not found
2111  QWidget* input = NULL;
2112  if ((QString(QChar(param->GetParameterType())) == "d") || (QString(QChar(param->GetParameterType())) == "i")) {
2113  input = new QLineEdit();
2114  // set default value
2115  dynamic_cast<QLineEdit*>(input)->setText(QString((char*)(param->GetDefaultValue()).data()));
2116 
2117  if (((label->text() == "red") || (label->text() == "red_or_string")) && isStillColorParameter) {
2118  redDefaultStr = QString((char*)(param->GetDefaultValue()).data());
2119  } else if ((label->text() == "green") && isStillColorParameter) {
2120  greenDefaultStr = QString((char*)(param->GetDefaultValue()).data());
2121  } else if ((label->text() == "green") && isStillColorParameter) {
2122  blueDefaultStr = QString((char*)(param->GetDefaultValue()).data());
2123  }
2124 
2125  } else if (QString(QChar(param->GetParameterType())) == "b") {
2126  input = new QWidget();
2127  QHBoxLayout* layout = new QHBoxLayout();
2128  input->setLayout(layout);
2129 
2130  QButtonGroup* buttons = new QButtonGroup();
2131  QRadioButton* radioOff = new QRadioButton("0");
2132  QRadioButton* radioOn = new QRadioButton("1");
2133  buttons->addButton(radioOn);
2134  buttons->addButton(radioOff);
2135  layout->addWidget(radioOn);
2136  layout->addWidget(radioOff);
2137 
2138  // set default value
2139  QString defaultValue = QString((char*)(param->GetDefaultValue()).data());
2140  if (defaultValue == "0") {
2141  radioOff->setChecked(true);
2142  } else if (defaultValue == "1") {
2143  radioOn->setChecked(true);
2144  }
2145  } else if ((QString(QChar(param->GetParameterType())) == "s") && (!param->GetParameterCandidates().isNull())) {
2146  input = new QComboBox();
2147  QString candidates = QString((char*)(param->GetParameterCandidates()).data());
2148  QStringList list = candidates.split (" ");
2149 
2150  // add all candidates to widget
2151  QString defaultValue = QString((char*)(param->GetDefaultValue()).data());
2152  for (int a=0; a<list.size(); a++) {
2153  dynamic_cast<QComboBox*>(input)->addItem(list.at(a));
2154  if (list.at(a) == defaultValue) {
2155  dynamic_cast<QComboBox*>(input)->setCurrentIndex(a);
2156  }
2157  }
2158 
2159  } else if ((QString(QChar(param->GetParameterType())) == "s")) { // string
2160  input = new QLineEdit();
2161  // set default value
2162  dynamic_cast<QLineEdit*>(input)->setText(QString((char*)(param->GetDefaultValue()).data()));
2163 
2164  } else if ((QString(QChar(param->GetParameterType())) == "c")) { // on/off
2165  input = new QWidget();
2166  QHBoxLayout* layout = new QHBoxLayout();
2167  input->setLayout(layout);
2168 
2169  QButtonGroup* buttons = new QButtonGroup();
2170  QRadioButton* radioOff = new QRadioButton("off");
2171  QRadioButton* radioOn = new QRadioButton("on");
2172  buttons->addButton(radioOn);
2173  buttons->addButton(radioOff);
2174  layout->addWidget(radioOn);
2175  layout->addWidget(radioOff);
2176 
2177  // set default value
2178  QString defaultValue = QString((char*)(param->GetDefaultValue()).data());
2179  if (defaultValue == "off") {
2180  radioOff->setChecked(true);
2181  } else if (defaultValue == "on") {
2182  radioOn->setChecked(true);
2183  }
2184 
2185  } else {
2186  input = new QLineEdit();
2187  dynamic_cast<QLineEdit*>(input)->setText(QString((char*)(param->GetDefaultValue()).data()));
2188  }
2189 
2190  txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
2191  if( ! param->GetParameterGuidance().isNull() )
2192  txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
2193 
2194  txt += " Parameter type : " + QString(QChar(param->GetParameterType())) + "\n";
2195  if(param->IsOmittable()){
2196  txt += " Omittable : True\n";
2197  } else {
2198  txt += " Omittable : False\n";
2199  }
2200  if( param->GetCurrentAsDefault() ) {
2201  txt += " Default value : taken from the current value\n";
2202  } else if( ! param->GetDefaultValue().isNull() ) {
2203  txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n";
2204  }
2205  if( ! param->GetParameterRange().isNull() ) {
2206  txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
2207  }
2208  if( ! param->GetParameterCandidates().isNull() ) {
2209  txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
2210  }
2211 
2212  if (isStillColorParameter && (nbColorParameter != 0)) {
2213  if ((label->text() == "red") || (label->text() == "red_or_string")) {
2214  redLabel = label;
2215  redInput = input;
2216  } else if (label->text() == "green") {
2217  greenLabel = label;
2218  greenInput = input;
2219  } else if (label->text() == "blue") {
2220 
2221  // we have all, then add a color chooser
2222 
2223  // Create a pixmap with the default color
2224  QColor qc;
2225  if ((redDefaultStr != "") && (redDefaultStr != "") && (redDefaultStr != "")) {
2226  qc.setRgbF(redDefaultStr.toDouble(),
2227  greenDefaultStr.toDouble(),
2228  blueDefaultStr.toDouble());
2229  }
2230  QPixmap pixmap = QPixmap(QSize(16, 16));
2231  pixmap.fill (qc);
2232  QPainter painter(&pixmap);
2233  painter.setPen(Qt::black);
2234  painter.drawRect(0,0,15,15); // Draw contour
2235 
2236  input = new QPushButton("Change color");
2237  dynamic_cast<QPushButton*>(input)->setIcon(pixmap);
2238  dynamic_cast<QPushButton*>(input)->setAccessibleName(redDefaultStr+" "+greenDefaultStr+" "+blueDefaultStr);
2239  label = new QLabel("Choose color");
2240 
2241  // less 1 because we have to add one to the row number
2242  nbColorParameter--;
2243  gridLayout->addWidget(label,i_thParameter-nbColorParameter,0);
2244  input->setToolTip("Select the current color");
2245  gridLayout->addWidget(input,i_thParameter-nbColorParameter,1);
2246 
2247  // Connect pushButton to ColorDialog in callback
2248  QSignalMapper* signalMapper = new QSignalMapper(this);
2249  signalMapper->setMapping(input,input);
2250  connect(input, SIGNAL(clicked()), signalMapper, SLOT(map()));
2251  connect(signalMapper, SIGNAL(mapped(QWidget*)),this, SLOT(ChangeColorCallback(QWidget*)));
2252 
2253  isColorDialogAdded = true;
2254  isStillColorParameter = false;
2255  }
2256  } else {
2257  gridLayout->addWidget(label,i_thParameter-nbColorParameter,0);
2258  input->setToolTip(txt);
2259  gridLayout->addWidget(input,i_thParameter-nbColorParameter,1);
2260  }
2261  }
2262  // add command name in hidden value at last line position 0
2263  QLabel* name = new QLabel(QString((char*)(aCommand->GetCommandPath().data())));
2264  name->hide();
2265  gridLayout->addWidget(name,n_parameterEntry-nbColorParameter,0);
2266 
2267  QPushButton* applyButton = new QPushButton("Apply");
2268  if (!isDialog) {
2269 
2270  gridLayout->addWidget(applyButton,n_parameterEntry-nbColorParameter,1);
2271 
2272  QSignalMapper* signalMapper = new QSignalMapper(this);
2273  signalMapper->setMapping(applyButton, paramWidget);
2274  connect(applyButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
2275  connect(signalMapper, SIGNAL(mapped(QWidget*)),this, SLOT(VisParameterCallback(QWidget*)));
2276  } else {
2277  // Apply/Cancel buttons
2278 
2279  applyButton->setAutoDefault( TRUE );
2280  applyButton->setDefault( TRUE );
2281  gridLayout->addWidget(applyButton,n_parameterEntry-nbColorParameter,0);
2282 
2283  QPushButton* cancelButton = new QPushButton( tr( "&Cancel" ));
2284  cancelButton->setAutoDefault( TRUE );
2285  gridLayout->addWidget(cancelButton,n_parameterEntry-nbColorParameter,1);
2286 
2287  QSignalMapper* signalMapper = new QSignalMapper(this);
2288  signalMapper->setMapping(applyButton, paramWidget);
2289  connect(applyButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
2290  connect(signalMapper, SIGNAL(mapped(QWidget*)),this, SLOT(VisParameterCallback(QWidget*)));
2291 
2292  QWidget * parentCheck = aParent;
2293  QDialog* parentDialog = NULL;
2294  bool found = false;
2295  while ((parentCheck->parentWidget()) != NULL) {
2296  parentCheck = parentCheck->parentWidget();
2297  parentDialog = dynamic_cast<QDialog*>(parentCheck);
2298  if (parentDialog) {
2299  connect( applyButton, SIGNAL( clicked() ), parentDialog, SLOT( accept() ) );
2300  connect( cancelButton, SIGNAL( clicked() ), parentDialog, SLOT( reject() ) );
2301  found = true;
2302  }
2303  }
2304  if (!found) {
2305  return false;
2306  }
2307  }
2308 
2309  if (!aParent->layout()) {
2310  aParent->setLayout(new QVBoxLayout());
2311  }
2312  aParent->layout()->addWidget(paramWidget);
2313  }
2314 
2315  return true;
2316 }
2317 
2318 
2323 QTreeWidgetItem* G4UIQt::FindTreeItem(
2324  QTreeWidgetItem *aParent
2325 ,const QString& aCommand
2326 )
2327 {
2328  if (aParent == NULL) return NULL;
2329 
2330  // Suppress last "/"
2331  QString myCommand = aCommand;
2332 
2333  if (myCommand.lastIndexOf("/") == (myCommand.size()-1)) {
2334  myCommand = myCommand.left(myCommand.size()-1);
2335  }
2336 
2337  if (GetLongCommandPath(aParent) == myCommand)
2338  return aParent;
2339 
2340  QTreeWidgetItem * tmp = NULL;
2341  for (int a=0;a<aParent->childCount();a++) {
2342  if (!tmp)
2343  tmp = FindTreeItem(aParent->child(a),myCommand);
2344  }
2345  return tmp;
2346 }
2347 
2348 
2349 
2357 QString G4UIQt::GetCommandList (
2358  const G4UIcommand *aCommand
2359 )
2360 {
2361 
2362  QString txt ="";
2363  if (aCommand == NULL)
2364  return txt;
2365 
2366  G4String commandPath = aCommand->GetCommandPath();
2367  G4String rangeString = aCommand->GetRange();
2368  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
2369  G4int n_parameterEntry = aCommand->GetParameterEntries();
2370 
2371  if ((commandPath == "") &&
2372  (rangeString == "") &&
2373  (n_guidanceEntry == 0) &&
2374  (n_parameterEntry == 0)) {
2375  return txt;
2376  }
2377 
2378  if((commandPath.length()-1)!='/') {
2379  txt += "Command " + QString((char*)(commandPath).data()) + "\n";
2380  }
2381  txt += "Guidance :\n";
2382 
2383  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
2384  txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
2385  }
2386  if( ! rangeString.isNull() ) {
2387  txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n";
2388  }
2389  if( n_parameterEntry > 0 ) {
2390  G4UIparameter *param;
2391 
2392  // Re-implementation of G4UIparameter.cc
2393 
2394  for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
2395  param = aCommand->GetParameter(i_thParameter);
2396  txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
2397  if( ! param->GetParameterGuidance().isNull() )
2398  txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
2399  txt += " Parameter type : " + QString(QChar(param->GetParameterType())) + "\n";
2400  if(param->IsOmittable()){
2401  txt += " Omittable : True\n";
2402  } else {
2403  txt += " Omittable : False\n";
2404  }
2405  if( param->GetCurrentAsDefault() ) {
2406  txt += " Default value : taken from the current value\n";
2407  } else if( ! param->GetDefaultValue().isNull() ) {
2408  txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n";
2409  }
2410  if( ! param->GetParameterRange().isNull() ) {
2411  txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
2412  }
2413  if( ! param->GetParameterCandidates().isNull() ) {
2414  txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
2415  }
2416  }
2417  }
2418  return txt;
2419 }
2420 
2421 
2427 G4bool G4UIQt::IsGUICommand(
2428  const G4UIcommand *aCommand
2429 )
2430 {
2431  if (aCommand == NULL)
2432  return false;
2433 
2434  G4int n_parameterEntry = aCommand->GetParameterEntries();
2435 
2436  if( n_parameterEntry > 0 ) {
2437  G4UIparameter *param;
2438 
2439  // Re-implementation of G4UIparameter.cc
2440 
2441  for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
2442  param = aCommand->GetParameter(i_thParameter);
2443  if (QString(QChar(param->GetParameterType())) == "d") {
2444  return true;
2445  }
2446  if (QString(QChar(param->GetParameterType())) == "b") {
2447  return true;
2448  }
2449  if (QString(QChar(param->GetParameterType())) == "i") {
2450  return true;
2451  }
2452  if (QString(QChar(param->GetParameterType())) == "s") {
2453  return true;
2454  }
2455  }
2456  }
2457  return false;
2458 }
2459 
2460 
2463 G4bool G4UIQt::GetHelpChoice(
2464  G4int&
2465 )
2466 {
2467  return true;
2468 }
2469 
2470 
2478 bool G4UIQt::eventFilter( // Should stay with a minuscule eventFilter because of Qt
2479  QObject *aObj
2480 ,QEvent *aEvent
2481 )
2482 {
2483  bool moveCommandCursor = false;
2484  if (aObj == NULL) return false;
2485  if (aEvent == NULL) return false;
2486 
2487  if (aObj == fHistoryTBTableList) {
2488  if (aEvent->type() == QEvent::KeyPress) {
2489  fCommandArea->setFocus();
2490  }
2491  }
2492  if (aObj == fCommandArea) {
2493  if (aEvent->type() == QEvent::KeyPress) {
2494  QKeyEvent *e = static_cast<QKeyEvent*>(aEvent);
2495  if ((e->key() == (Qt::Key_Down)) ||
2496  (e->key() == (Qt::Key_PageDown)) ||
2497  (e->key() == (Qt::Key_Up)) ||
2498  (e->key() == (Qt::Key_PageUp))) {
2499  int selection = fHistoryTBTableList->currentRow();
2500  if (fHistoryTBTableList->count()) {
2501  if (selection == -1) {
2502  selection = fHistoryTBTableList->count()-1;
2503  } else {
2504  if (e->key() == (Qt::Key_Down)) {
2505  if (selection <(fHistoryTBTableList->count()-1))
2506  selection++;
2507  } else if (e->key() == (Qt::Key_PageDown)) {
2508  selection = fHistoryTBTableList->count()-1;
2509  } else if (e->key() == (Qt::Key_Up)) {
2510  if (selection >0)
2511  selection --;
2512  } else if (e->key() == (Qt::Key_PageUp)) {
2513  selection = 0;
2514  }
2515  }
2516  fHistoryTBTableList->clearSelection();
2517 #if QT_VERSION < 0x040202
2518  fHistoryTBTableList->setItemSelected(fHistoryTBTableList->item(selection),true);
2519 #else
2520  fHistoryTBTableList->item(selection)->setSelected(true);
2521 #endif
2522  fHistoryTBTableList->setCurrentItem(fHistoryTBTableList->item(selection));
2523  }
2524  moveCommandCursor = true;
2525  } else if (e->key() == (Qt::Key_Tab)) {
2526  G4String ss = Complete(fCommandArea->text().toStdString().c_str());
2527  fCommandArea->setText((char*)(ss.data()));
2528 
2529  // do not pass by parent, it will disable widget tab focus !
2530  return true;
2531  // L.Garnier : MetaModifier is CTRL for MAC, but I don't want to put a MAC
2532  // specific #ifdef
2533  } else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_A)) {
2534  fCommandArea->home(false);
2535  return true;
2536  } else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_E)) {
2537  fCommandArea->end(false);
2538  return true;
2539  }
2540  }
2541  }
2542  bool res= false;
2543  // change cursor position if needed
2544  if (moveCommandCursor == true) {
2545  fCommandArea->setCursorPosition ( fCommandArea->text().length() );
2546  fCommandArea->setCursorPosition (4);
2547  } else {
2548  // pass the event on to the parent class
2549  res = QObject::eventFilter(aObj, aEvent);
2550  }
2551  return res;
2552 }
2553 
2554 
2555 
2556 
2557 /***************************************************************************/
2558 //
2559 // SLOTS DEFINITIONS
2560 //
2561 /***************************************************************************/
2562 
2565 void G4UIQt::ShowHelpCallback (
2566 )
2567 {
2568  TerminalHelp("");
2569 }
2570 
2571 
2574 void G4UIQt::ClearButtonCallback (
2575 )
2576 {
2577  fCoutTBTextArea->clear();
2578  fG4cout.clear();
2579 }
2580 
2583 void G4UIQt::ExitSession (
2584 )
2585 {
2586  SessionTerminate();
2587 }
2588 
2589 void G4UIQt::ExitHelp(
2590 ) const
2591 {
2592 }
2593 
2597 void G4UIQt::CommandEnteredCallback (
2598 )
2599 {
2600  // split by any new line character
2601  QStringList list = fCommandArea->text().split(QRegExp("[\r\n]"),QString::SkipEmptyParts);
2602 
2603  // Apply for all commands
2604  for (int a=0; a< list.size(); a++) {
2605  QString txt (list[a].trimmed());
2606  if (txt != "") {
2607  fHistoryTBTableList->addItem(txt);
2608  fHistoryTBTableList->clearSelection();
2609  fHistoryTBTableList->setCurrentItem(NULL);
2610  fCommandArea->setText("");
2611  G4Qt* interactorManager = G4Qt::getInstance ();
2612  if (interactorManager) {
2613  interactorManager->FlushAndWaitExecution();
2614  }
2615 
2616  G4String command = txt.toStdString().c_str();
2617  if (command(0,4) != "help") {
2618  ApplyShellCommand (command,exitSession,exitPause);
2619  } else {
2620  ActivateCommand(command);
2621  }
2622  }
2623  }
2624 
2625  // Rebuild help tree
2626  FillHelpTree();
2627 
2628  if(exitSession==true)
2629  SessionTerminate();
2630 }
2631 
2632 
2637 void G4UIQt::CommandEditedCallback(const QString &)
2638 {
2639  QStringList list = fCommandArea->text().split(QRegExp("[\r\n]"),QString::SkipEmptyParts);
2640 
2641  if (list.size() > 1) { // trigger ActivateCommand
2642  for (int a=0; a<list.size()-1; a++) {
2643  // set only the first part
2644  fCommandArea->setText(list[a]);
2645  // trigger callback
2646  CommandEnteredCallback();
2647  }
2648  // reset unfinished command
2649  fCommandArea->setText(list[list.size()-1]);
2650  }
2651 }
2652 
2653 
2656 void G4UIQt::VisParameterCallback(QWidget* widget){
2657  if (widget == NULL) {
2658  return;
2659  }
2660 
2661  // Look in all the Grid layout, but only column 1 (0 is the parameter name)
2662  QGridLayout* grid = dynamic_cast<QGridLayout*>(widget->layout());
2663  if (grid == 0) {
2664  return;
2665  }
2666  QString command;
2667 #if QT_VERSION < 0x040400
2668  QWidget* name = grid->itemAt(grid->columnCount()*(grid->rowCount()-2))->widget();
2669 #else
2670  QWidget* name = grid->itemAtPosition(grid->rowCount()-1,0)->widget();
2671 #endif
2672  if (dynamic_cast<QLabel*>(name) == 0) {
2673  return;
2674  }
2675  command += (dynamic_cast<QLabel*>(name))->text()+" ";
2676 
2677  for (int a=0;a<grid->rowCount()-1; a++) {
2678 #if QT_VERSION < 0x040400
2679  QWidget* widgetTmp = grid->itemAt(a*grid->columnCount()+1)->widget();
2680 #else
2681  QWidget* widgetTmp = grid->itemAtPosition(a,1)->widget();
2682 #endif
2683 
2684  // 4 kind of widgets : QLineEdit / QComboBox / radioButtonsGroup / QPushButton (color chooser)
2685  if (widgetTmp != NULL) {
2686 
2687  if (dynamic_cast<QLineEdit*>(widgetTmp) != 0) {
2688  command += (dynamic_cast<QLineEdit*>(widgetTmp))->text()+" ";
2689 
2690  } else if (dynamic_cast<QComboBox*>(widgetTmp) != 0){
2691  command += (dynamic_cast<QComboBox*>(widgetTmp))->itemText((dynamic_cast<QComboBox*>(widgetTmp))->currentIndex())+" ";
2692 
2693  // Color chooser
2694  } else if (dynamic_cast<QPushButton*>(widgetTmp) != 0){
2695  command += widgetTmp->accessibleName()+" ";
2696 
2697  // Check for Button group
2698  } else if (dynamic_cast<QWidget*>(widgetTmp) != 0){
2699  if (widgetTmp->layout()->count() > 0){
2700  if (dynamic_cast<QRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()) != 0) {
2701  QAbstractButton * checked = (dynamic_cast<QRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()))->group()->checkedButton();
2702  if (checked != 0) {
2703  command += (dynamic_cast<QRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()))->group()->checkedButton()->text()+" ";
2704  }
2705  }
2706  }
2707 
2708  }
2709  }
2710  }
2711  if (command != "") {
2713  if(UI != NULL) {
2714  UI->ApplyCommand(command.toStdString().c_str());
2715  }
2716  }
2717 }
2718 
2719 
2725 void G4UIQt::ButtonCallback (
2726  const QString& aCommand
2727 )
2728 {
2729  G4String ss = G4String(aCommand.toStdString().c_str());
2730  ss = ss.strip(G4String::leading);
2731 
2733  if(UI==NULL) return;
2734  G4UIcommandTree * treeTop = UI->GetTree();
2735 
2736  G4UIcommand* command = treeTop->FindPath(ss);
2737 
2738  if (command) {
2739  // if is GUI, then open a dialog
2740  if (IsGUICommand(command)) {
2741  QDialog* menuParameterDialog = new QDialog();
2742 
2743  if (CreateVisCommandGroupAndToolBox(command,menuParameterDialog,1,true)) {
2744  menuParameterDialog->setWindowTitle (aCommand);
2745  menuParameterDialog->setSizePolicy (QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
2746 
2747  // exec this dialog, apply the command automaticaly, and return
2748  menuParameterDialog->exec();
2749  return;
2750  }
2751  }
2752  }
2753 
2754  ApplyShellCommand(ss,exitSession,exitPause);
2755 
2756  // Rebuild help tree
2757  FillHelpTree();
2758 
2759  if(exitSession==true)
2760  SessionTerminate();
2761 }
2762 
2763 
2764 
2767 void G4UIQt::HelpTreeClicCallback (
2768 )
2769 {
2770  QTreeWidgetItem* item = NULL;
2771  if (!fHelpTreeWidget)
2772  return ;
2773 
2774  if (!fHelpArea)
2775  return;
2776 
2777  QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
2778  if (list.isEmpty())
2779  return;
2780  item = list.first();
2781  if (!item)
2782  return;
2783 
2785  if(UI==NULL) return;
2786  G4UIcommandTree * treeTop = UI->GetTree();
2787 
2788  std::string itemText = GetLongCommandPath(item).toStdString();
2789 
2790  // check if it is a command path
2791  if (item->childCount() > 0) {
2792  itemText +="/";
2793  }
2794  G4UIcommand* command = treeTop->FindPath(itemText.c_str());
2795 
2796  if (command) {
2797  #if QT_VERSION < 0x040200
2798  fHelpArea->clear();
2799  fHelpArea->append(GetCommandList(command));
2800  #else
2801  fHelpArea->setText(GetCommandList(command));
2802  #endif
2803  } else { // this is a command
2804  G4UIcommandTree* path = treeTop->FindCommandTree(itemText.c_str());
2805  if ( path) {
2806  // this is not a command, this is a sub directory
2807  // We display the Title
2808  #if QT_VERSION < 0x040200
2809  fHelpArea->clear();
2810  fHelpArea->append(path->GetTitle().data());
2811  #else
2812  fHelpArea->setText(path->GetTitle().data());
2813  #endif
2814  }
2815  }
2816 }
2817 
2820 void G4UIQt::HelpTreeDoubleClicCallback (
2821 )
2822 {
2823  HelpTreeClicCallback();
2824 
2825  QTreeWidgetItem* item = NULL;
2826  if (!fHelpTreeWidget)
2827  return ;
2828 
2829  if (!fHelpArea)
2830  return;
2831 
2832  QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
2833  if (list.isEmpty())
2834  return;
2835  item = list.first();
2836  if (!item)
2837  return;
2838 
2839  fCommandArea->clear();
2840  fCommandArea->setText(GetLongCommandPath(item));
2841 }
2842 
2843 
2847 void G4UIQt::CommandHistoryCallback(
2848 )
2849 {
2850  QListWidgetItem* item = NULL;
2851  if (!fHistoryTBTableList)
2852  return ;
2853 
2854 
2855  QList<QListWidgetItem *> list =fHistoryTBTableList->selectedItems();
2856  if (list.isEmpty())
2857  return;
2858  item = list.first();
2859  if (!item)
2860  return;
2861  fCommandArea->setText(item->text());
2862 }
2863 
2864 
2865 void G4UIQt::CoutFilterCallback(
2866 const QString & text) {
2867 
2868  QStringList result = fG4cout.filter(text);
2869  fCoutTBTextArea->setPlainText(result.join("\n"));
2870 
2871  fCoutTBTextArea->repaint();
2872  fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
2873 
2874  }
2875 
2880 void G4UIQt::LookForHelpStringCallback(
2881 )
2882 {
2883  QString searchText = fHelpLine->text();
2884 
2885 #if QT_VERSION < 0x040200
2886  fHelpArea->clear();
2887 #else
2888  fHelpArea->setText("");
2889 #endif
2890  if (searchText =="") {
2891  // clear old help tree
2892  fHelpTreeWidget->clear();
2893 
2894  FillHelpTree();
2895 
2896  return;
2897  } else {
2898  OpenHelpTreeOnCommand(searchText);
2899  }
2900 }
2901 
2902 
2903 void G4UIQt::OpenHelpTreeOnCommand(
2904  const QString & searchText
2905 )
2906 {
2907  // the help tree
2909  if(UI==NULL) return;
2910  G4UIcommandTree * treeTop = UI->GetTree();
2911 
2912  G4int treeSize = treeTop->GetTreeEntry();
2913 
2914  // clear old help tree
2915  fHelpTreeWidget->clear();
2916 
2917  // look for new items
2918 
2919  int tmp = 0;
2920 
2921  QMap<int,QString> commandResultMap;
2922  QMap<int,QString> commandChildResultMap;
2923 
2924  for (int a=0;a<treeSize;a++) {
2925  G4UIcommand* command = treeTop->FindPath(treeTop->GetTree(a+1)->GetPathName().data());
2926  tmp = GetCommandList (command).count(searchText,Qt::CaseInsensitive);
2927  if (tmp >0) {
2928  commandResultMap.insertMulti(tmp,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()));
2929  }
2930  // look for childs
2931  commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a+1),searchText);
2932  // insert new childs
2933  if (!commandChildResultMap.empty()) {
2934  QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
2935  while (i != commandChildResultMap.constEnd()) {
2936  commandResultMap.insertMulti(i.key(),i.value());
2937  i++;
2938  }
2939  commandChildResultMap.clear();
2940  }
2941  }
2942 
2943  // build new help tree
2944  fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
2945  fHelpTreeWidget->setColumnCount(2);
2946  QStringList labels;
2947  labels << QString("Command") << QString("Match");
2948  fHelpTreeWidget->setHeaderLabels(labels);
2949 
2950  if (commandResultMap.empty()) {
2951 #if QT_VERSION < 0x040200
2952  fHelpArea->clear();
2953  fHelpArea->append("No match found");
2954 #else
2955  fHelpArea->setText("No match found");
2956 #endif
2957  return;
2958  }
2959 
2960  QMap<int,QString>::const_iterator i = commandResultMap.constEnd();
2961  i--;
2962  // 10 maximum progress values
2963  float multValue = 10.0/(float)(i.key());
2964  QString progressChar = "|";
2965  QString progressStr = "|";
2966 
2967  QTreeWidgetItem * newItem;
2968  bool end = false;
2969  while (!end) {
2970  if (i == commandResultMap.constBegin()) {
2971  end = true;
2972  }
2973  for(int a=0;a<int(i.key()*multValue);a++) {
2974  progressStr += progressChar;
2975  }
2976  newItem = new QTreeWidgetItem();
2977  QString commandStr = i.value().trimmed();
2978 
2979  if (commandStr.indexOf("/") == 0) {
2980  commandStr = commandStr.right(commandStr.size()-1);
2981  }
2982 
2983  newItem->setText(0,commandStr);
2984  newItem->setText(1,progressStr);
2985  fHelpTreeWidget->addTopLevelItem(newItem);
2986 #if QT_VERSION < 0x040200
2987 #else
2988  newItem->setForeground ( 1, QBrush(Qt::blue) );
2989 #endif
2990  progressStr = "|";
2991  i--;
2992  }
2993  fHelpTreeWidget->resizeColumnToContents (0);
2994  fHelpTreeWidget->sortItems(1,Qt::DescendingOrder);
2995  // fHelpTreeWidget->setColumnWidth(1,10);//resizeColumnToContents (1);
2996 }
2997 
2998 
2999 
3000 
3001 QMap<int,QString> G4UIQt::LookForHelpStringInChildTree(
3002  G4UIcommandTree *aCommandTree
3003 ,const QString & text
3004  )
3005 {
3006  QMap<int,QString> commandResultMap;
3007  if (aCommandTree == NULL) return commandResultMap;
3008 
3009 
3010  // Get the Sub directories
3011  int tmp = 0;
3012  QMap<int,QString> commandChildResultMap;
3013 
3014  for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
3015  const G4UIcommand* command = aCommandTree->GetGuidance();
3016  tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
3017  if (tmp >0) {
3018  commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()));
3019  }
3020  // look for childs
3021  commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text);
3022 
3023  if (!commandChildResultMap.empty()) {
3024  // insert new childs
3025  QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
3026  while (i != commandChildResultMap.constEnd()) {
3027  commandResultMap.insertMulti(i.key(),i.value());
3028  i++;
3029  }
3030  commandChildResultMap.clear();
3031  }
3032  }
3033  // Get the Commands
3034 
3035  for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
3036  const G4UIcommand* command = aCommandTree->GetCommand(a+1);
3037  tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
3038  if (tmp >0) {
3039  commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()));
3040  }
3041 
3042  }
3043  return commandResultMap;
3044 }
3045 
3046 
3047 QString G4UIQt::GetShortCommandPath(
3048 QString commandPath
3049 )
3050 {
3051  if (commandPath.indexOf("/") == 0) {
3052  commandPath = commandPath.right(commandPath.size()-1);
3053  }
3054 
3055  commandPath = commandPath.right(commandPath.size()-commandPath.lastIndexOf("/",-2)-1);
3056 
3057  if (commandPath.lastIndexOf("/") == (commandPath.size()-1)) {
3058  commandPath = commandPath.left(commandPath.size()-1);
3059  }
3060 
3061  return commandPath;
3062 }
3063 
3064 
3065 QString G4UIQt::GetLongCommandPath(
3066  QTreeWidgetItem* item
3067 )
3068 {
3069  if (item == NULL) return "";
3070 
3071  // rebuild path:
3072  QString itemText = "";
3073  itemText = item->text(0);
3074 
3075  while (item->parent() != NULL) {
3076  itemText = item->parent()->text(0)+"/"+itemText;
3077  item = item->parent();
3078  }
3079  itemText = "/"+itemText;
3080 
3081  return itemText;
3082 }
3083 
3084 
3085 void G4UIQt::ChangeColorCallback(QWidget* widget) {
3086  if (widget == NULL) {
3087  return;
3088  }
3089 
3090  QPushButton* button = dynamic_cast<QPushButton*>(widget);
3091  if (button == 0) {
3092  return;
3093  }
3094  QString value = button->accessibleName();
3095 
3096  QColor old;
3097  old.setRgbF(value.section(" ",0,1).toDouble(),
3098  value.section(" ",1,2).toDouble(),
3099  value.section(" ",2,3).toDouble());
3100 #if QT_VERSION < 0x040500
3101  bool a;
3102  QColor color = QColor(QColorDialog::getRgba (old.rgba(),&a,fUITabWidget));
3103 #else
3104  QColor color = QColorDialog::getColor(old,
3105  fUITabWidget,
3106  "Change color",
3107  QColorDialog::ShowAlphaChannel);
3108 #endif
3109 
3110 
3111  if (color.isValid()) {
3112  // rebuild the widget icon
3113  QPixmap pixmap = QPixmap(QSize(16, 16));
3114  pixmap.fill (color);
3115  QPainter painter(&pixmap);
3116  painter.setPen(Qt::black);
3117  painter.drawRect(0,0,15,15); // Draw contour
3118 
3119  button->setAccessibleName(QString::number(color.redF())+" "+
3120  QString::number(color.greenF())+" "+
3121  QString::number(color.blueF())+" "
3122  );
3123  button->setIcon(pixmap);
3124 
3125 
3126  }
3127 }
3128 
3129 
3130 void G4UIQt::ChangeCursorStyle(const QString& action) {
3131 
3132  // Theses actions should be in the app toolbar
3133 
3134  fMoveSelected = true;
3135  fPickSelected = true;
3136  fRotateSelected = true;
3137  fZoomInSelected = true;
3138  fZoomOutSelected = true;
3139 
3140  if (fToolbarApp == NULL) return;
3141  QList<QAction *> list = fToolbarApp->actions ();
3142  for (int i = 0; i < list.size(); ++i) {
3143  if (list.at(i)->data().toString () == action) {
3144  list.at(i)->setChecked(TRUE);
3145  } else if (list.at(i)->data().toString () == "move") {
3146  fMoveSelected = false;
3147  list.at(i)->setChecked(FALSE);
3148  } else if (list.at(i)->data().toString () == "pick") {
3149  fPickSelected = false;
3150  list.at(i)->setChecked(FALSE);
3151  } else if (list.at(i)->data().toString () == "rotate") {
3152  fRotateSelected = false;
3153  list.at(i)->setChecked(FALSE);
3154  } else if (list.at(i)->data().toString () == "zoom_in") {
3155  fZoomInSelected = false;
3156  list.at(i)->setChecked(FALSE);
3157  } else if (list.at(i)->data().toString () == "zoom_out") {
3158  fZoomOutSelected = false;
3159  list.at(i)->setChecked(FALSE);
3160  }
3161  }
3162  // FIXME : Should connect this to Vis
3163 }
3164 
3165 
3166 /* A little bit like "void G4OpenGLQtViewer::toggleDrawingAction(int aAction)"
3167  But for all viewers, not only Qt
3168 
3169 FIXME : Should be a feedback when changing viewer !
3170 
3171  */
3172 void G4UIQt::ChangeSurfaceStyle(const QString& action) {
3173 
3174  // Theses actions should be in the app toolbar
3175 
3176  if (fToolbarApp == NULL) return;
3177  QList<QAction *> list = fToolbarApp->actions ();
3178  for (int i = 0; i < list.size(); ++i) {
3179  if (list.at(i)->data().toString () == action) {
3180  list.at(i)->setChecked(TRUE);
3181  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
3182  list.at(i)->setChecked(FALSE);
3183  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3184  list.at(i)->setChecked(FALSE);
3185  } else if (list.at(i)->data().toString () == "solid") {
3186  list.at(i)->setChecked(FALSE);
3187  } else if (list.at(i)->data().toString () == "wireframe") {
3188  list.at(i)->setChecked(FALSE);
3189  }
3190  }
3191  // FIXME : Should connect this to Vis
3192 
3193  if (action == "hidden_line_removal") {
3194  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style w");
3195  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 1");
3196 
3197  } else if (action == "hidden_line_and_surface_removal") {
3198  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style s");
3199  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 1");
3200 
3201  } else if (action == "solid") {
3202  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style s");
3203  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 0");
3204 
3205  } else if (action == "wireframe") {
3206  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style w");
3207  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 0");
3208  }
3209 }
3210 
3211 
3212 void G4UIQt::OpenIconCallback(const QString& aParam) {
3213 
3214  QString aCommand = aParam.left(aParam.indexOf(fStringSeparator));
3215  QString aLabel = aParam.mid(aParam.indexOf(fStringSeparator)+fStringSeparator.length());
3216 
3217  QString nomFich = QFileDialog::getOpenFileName(fMainWindow, aLabel, fLastOpenPath, "Macro files (*.mac)");
3218  if (nomFich != "") {
3219  G4UImanager::GetUIpointer()->ApplyCommand((QString(aCommand)+ QString(" ")+ nomFich).toStdString().c_str());
3220  QDir dir;
3221  fLastOpenPath = dir.absoluteFilePath(nomFich);
3222  }
3223 }
3224 
3225 
3226 void G4UIQt::SaveIconCallback(const QString& aParam) {
3227 
3228  QString aCommand = aParam.left(aParam.indexOf(fStringSeparator));
3229  QString aLabel = aParam.mid(aParam.indexOf(fStringSeparator)+fStringSeparator.length());
3230 
3231  QString nomFich = QFileDialog::getSaveFileName(fMainWindow, aLabel, fLastOpenPath, "Macro files (*.mac)");
3232  if (nomFich != "") {
3233  G4UImanager::GetUIpointer()->ApplyCommand((QString(aCommand)+ QString(" ")+nomFich).toStdString().c_str());
3234  QDir dir;
3235  fLastOpenPath = dir.absoluteFilePath(nomFich);
3236  }
3237 }
3238 
3239 
3240 
3241 void G4UIQt::ChangePerspectiveOrtho(const QString& action) {
3242 
3243  // Theses actions should be in the app toolbar
3244 
3245  if (fToolbarApp == NULL) return;
3246  QList<QAction *> list = fToolbarApp->actions ();
3247  QString checked = "";
3248  for (int i = 0; i < list.size(); ++i) {
3249  if (list.at(i)->data().toString () == action) {
3250  list.at(i)->setChecked(TRUE);
3251  checked = list.at(i)->data().toString ();
3252  } else if (list.at(i)->data().toString () == "persepective") {
3253  list.at(i)->setChecked(FALSE);
3254  } else if (list.at(i)->data().toString () == "ortho") {
3255  list.at(i)->setChecked(FALSE);
3256  }
3257  }
3258 
3259  if ((action == "ortho") && (checked == "ortho")) {
3260  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/projection o");
3261  } else if ((action == "perspective") && (checked == "perspective")) {
3262  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/projection p");
3263  }
3264 }
3265 
3266 
3267 
3268 void G4UIQt::SetIconMoveSelected() {
3269  // Theses actions should be in the app toolbar
3270  fMoveSelected = true;
3271  fRotateSelected = false;
3272  fPickSelected = false;
3273  fZoomInSelected = false;
3274  fZoomOutSelected = false;
3275 
3276  if (fToolbarApp == NULL) return;
3277  QList<QAction *> list = fToolbarApp->actions ();
3278  for (int i = 0; i < list.size(); ++i) {
3279  if (list.at(i)->data().toString () == "move") {
3280  list.at(i)->setChecked(TRUE);
3281  } else if (list.at(i)->data().toString () == "rotate") {
3282  list.at(i)->setChecked(FALSE);
3283  } else if (list.at(i)->data().toString () == "pick") {
3284  list.at(i)->setChecked(FALSE);
3285  } else if (list.at(i)->data().toString () == "zoom_in") {
3286  list.at(i)->setChecked(FALSE);
3287  } else if (list.at(i)->data().toString () == "zoom_out") {
3288  list.at(i)->setChecked(FALSE);
3289  }
3290  }
3291 }
3292 
3293 
3294 void G4UIQt::SetIconRotateSelected() {
3295  // Theses actions should be in the app toolbar
3296  fRotateSelected = true;
3297  fMoveSelected = false;
3298  fPickSelected = false;
3299  fZoomInSelected = false;
3300  fZoomOutSelected = false;
3301 
3302  if (fToolbarApp == NULL) return;
3303  QList<QAction *> list = fToolbarApp->actions ();
3304  for (int i = 0; i < list.size(); ++i) {
3305  if (list.at(i)->data().toString () == "rotate") {
3306  list.at(i)->setChecked(TRUE);
3307  } else if (list.at(i)->data().toString () == "move") {
3308  list.at(i)->setChecked(FALSE);
3309  } else if (list.at(i)->data().toString () == "pick") {
3310  list.at(i)->setChecked(FALSE);
3311  } else if (list.at(i)->data().toString () == "zoom_in") {
3312  list.at(i)->setChecked(FALSE);
3313  } else if (list.at(i)->data().toString () == "zoom_out") {
3314  list.at(i)->setChecked(FALSE);
3315  }
3316  }
3317 }
3318 
3319 
3320 void G4UIQt::SetIconPickSelected() {
3321  // Theses actions should be in the app toolbar
3322  fPickSelected = true;
3323  fMoveSelected = false;
3324  fRotateSelected = false;
3325  fZoomInSelected = false;
3326  fZoomOutSelected = false;
3327 
3328  if (fToolbarApp == NULL) return;
3329  QList<QAction *> list = fToolbarApp->actions ();
3330  for (int i = 0; i < list.size(); ++i) {
3331  if (list.at(i)->data().toString () == "pick") {
3332  list.at(i)->setChecked(TRUE);
3333  } else if (list.at(i)->data().toString () == "move") {
3334  list.at(i)->setChecked(FALSE);
3335  } else if (list.at(i)->data().toString () == "rotate") {
3336  list.at(i)->setChecked(FALSE);
3337  } else if (list.at(i)->data().toString () == "zoom_in") {
3338  list.at(i)->setChecked(FALSE);
3339  } else if (list.at(i)->data().toString () == "zoom_out") {
3340  list.at(i)->setChecked(FALSE);
3341  }
3342  }
3343 }
3344 
3345 
3346 void G4UIQt::SetIconZoomInSelected() {
3347  // Theses actions should be in the app toolbar
3348  fZoomInSelected = true;
3349  fMoveSelected = false;
3350  fRotateSelected = false;
3351  fPickSelected = false;
3352  fZoomOutSelected = false;
3353 
3354  if (fToolbarApp == NULL) return;
3355  QList<QAction *> list = fToolbarApp->actions ();
3356  for (int i = 0; i < list.size(); ++i) {
3357  if (list.at(i)->data().toString () == "zoom_in") {
3358  list.at(i)->setChecked(TRUE);
3359  } else if (list.at(i)->data().toString () == "move") {
3360  list.at(i)->setChecked(FALSE);
3361  } else if (list.at(i)->data().toString () == "rotate") {
3362  list.at(i)->setChecked(FALSE);
3363  } else if (list.at(i)->data().toString () == "pick") {
3364  list.at(i)->setChecked(FALSE);
3365  } else if (list.at(i)->data().toString () == "zoom_out") {
3366  list.at(i)->setChecked(FALSE);
3367  }
3368  }
3369 }
3370 
3371 
3372 void G4UIQt::SetIconZoomOutSelected() {
3373  // Theses actions should be in the app toolbar
3374  fZoomOutSelected = true;
3375  fMoveSelected = false;
3376  fRotateSelected = false;
3377  fPickSelected = false;
3378  fZoomInSelected = false;
3379 
3380  if (fToolbarApp == NULL) return;
3381  QList<QAction *> list = fToolbarApp->actions ();
3382  for (int i = 0; i < list.size(); ++i) {
3383  if (list.at(i)->data().toString () == "zoom_out") {
3384  list.at(i)->setChecked(TRUE);
3385  } else if (list.at(i)->data().toString () == "move") {
3386  list.at(i)->setChecked(FALSE);
3387  } else if (list.at(i)->data().toString () == "rotate") {
3388  list.at(i)->setChecked(FALSE);
3389  } else if (list.at(i)->data().toString () == "pick") {
3390  list.at(i)->setChecked(FALSE);
3391  } else if (list.at(i)->data().toString () == "zoom_in") {
3392  list.at(i)->setChecked(FALSE);
3393  }
3394  }
3395 }
3396 
3397 
3398 void G4UIQt::SetIconSolidSelected() {
3399  // Theses actions should be in the app toolbar
3400 
3401  if (fToolbarApp == NULL) return;
3402  QList<QAction *> list = fToolbarApp->actions ();
3403  for (int i = 0; i < list.size(); ++i) {
3404  if (list.at(i)->data().toString () == "solid") {
3405  list.at(i)->setChecked(TRUE);
3406  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
3407  list.at(i)->setChecked(FALSE);
3408  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3409  list.at(i)->setChecked(FALSE);
3410  } else if (list.at(i)->data().toString () == "wireframe") {
3411  list.at(i)->setChecked(FALSE);
3412  }
3413  }
3414 }
3415 
3416 
3417 void G4UIQt::SetIconWireframeSelected() {
3418  // Theses actions should be in the app toolbar
3419 
3420  if (fToolbarApp == NULL) return;
3421  QList<QAction *> list = fToolbarApp->actions ();
3422  for (int i = 0; i < list.size(); ++i) {
3423  if (list.at(i)->data().toString () == "wireframe") {
3424  list.at(i)->setChecked(TRUE);
3425  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
3426  list.at(i)->setChecked(FALSE);
3427  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3428  list.at(i)->setChecked(FALSE);
3429  } else if (list.at(i)->data().toString () == "solid") {
3430  list.at(i)->setChecked(FALSE);
3431  }
3432  }
3433 }
3434 
3435 
3436 void G4UIQt::SetIconHLRSelected() {
3437  // Theses actions should be in the app toolbar
3438 
3439  if (fToolbarApp == NULL) return;
3440  QList<QAction *> list = fToolbarApp->actions ();
3441  for (int i = 0; i < list.size(); ++i) {
3442  if (list.at(i)->data().toString () == "hidden_line_removal") {
3443  list.at(i)->setChecked(TRUE);
3444  } else if (list.at(i)->data().toString () == "solid") {
3445  list.at(i)->setChecked(FALSE);
3446  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3447  list.at(i)->setChecked(FALSE);
3448  } else if (list.at(i)->data().toString () == "wireframe") {
3449  list.at(i)->setChecked(FALSE);
3450  }
3451  }
3452 }
3453 
3454 
3455 void G4UIQt::SetIconHLHSRSelected() {
3456  // Theses actions should be in the app toolbar
3457 
3458  if (fToolbarApp == NULL) return;
3459  QList<QAction *> list = fToolbarApp->actions ();
3460  for (int i = 0; i < list.size(); ++i) {
3461  if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3462  list.at(i)->setChecked(TRUE);
3463  } else if (list.at(i)->data().toString () == "solid") {
3464  list.at(i)->setChecked(FALSE);
3465  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
3466  list.at(i)->setChecked(FALSE);
3467  } else if (list.at(i)->data().toString () == "wireframe") {
3468  list.at(i)->setChecked(FALSE);
3469  }
3470  }
3471 }
3472 
3473 
3474 void G4UIQt::SetIconPerspectiveSelected() {
3475  // Theses actions should be in the app toolbar
3476 
3477  if (fToolbarApp == NULL) return;
3478  QList<QAction *> list = fToolbarApp->actions ();
3479  for (int i = 0; i < list.size(); ++i) {
3480  if (list.at(i)->data().toString () == "perspective") {
3481  list.at(i)->setChecked(TRUE);
3482  } else if (list.at(i)->data().toString () == "ortho") {
3483  list.at(i)->setChecked(FALSE);
3484  }
3485  }
3486 }
3487 
3488 
3489 
3490 void G4UIQt::SetIconOrthoSelected() {
3491  // Theses actions should be in the app toolbar
3492 
3493  if (fToolbarApp == NULL) return;
3494  QList<QAction *> list = fToolbarApp->actions ();
3495  for (int i = 0; i < list.size(); ++i) {
3496  if (list.at(i)->data().toString () == "ortho") {
3497  list.at(i)->setChecked(TRUE);
3498  } else if (list.at(i)->data().toString () == "perspective") {
3499  list.at(i)->setChecked(FALSE);
3500  }
3501  }
3502 }
3503 
3504 
3505 
3506 G4QTabWidget::G4QTabWidget(
3507 QWidget* aParent,
3508 int sizeX,
3509 int sizeY
3510 ):QTabWidget(aParent)
3511  ,fTabSelected(false)
3512  ,fLastCreated(-1)
3513 ,fPreferedSizeX(sizeX+6) // margin left+right
3514 ,fPreferedSizeY(sizeY+58) // tab label height + margin left+right
3515 {
3516  setMinimumSize(100,100);
3517  QSizePolicy policy = QSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
3518  setSizePolicy(policy);
3519 }
3520 
3521 G4QTabWidget::G4QTabWidget(
3522 ):QTabWidget()
3523  ,fTabSelected(false)
3524  ,fLastCreated(-1)
3525 ,fPreferedSizeX(0)
3526 ,fPreferedSizeY(0)
3527 {
3528 }
3529 
3530 
3531 
3532 #if QT_VERSION < 0x040500
3533 void G4UIQt::TabCloseCallback(int){
3534 #else
3535 void G4UIQt::TabCloseCallback(int a){
3536 #endif
3537 #if QT_VERSION < 0x040500
3538 #else
3539  if (fViewerTabWidget == NULL) return;
3540 
3541  // get the address of the widget
3542  QWidget* temp = fViewerTabWidget->widget(a);
3543  // remove the tab
3544  fViewerTabWidget->removeTab (a);
3545 
3546  // delete the widget
3547  delete temp;
3548 
3549  // if there is no more tab inside the tab widget
3550  if (fViewerTabWidget->count() == 0) {
3551  if (fEmptyViewerTabLabel == NULL) {
3552  fEmptyViewerTabLabel = new QLabel("If you want to have a Viewer, please use /vis/open commands.");
3553  }
3554 
3555  fViewerTabHandleWidget->layout()->removeWidget(fViewerTabWidget);
3556 
3557  fViewerTabHandleWidget->layout()->addWidget(fEmptyViewerTabLabel);
3558 
3559  fEmptyViewerTabLabel->show();
3560  }
3561 #endif
3562 }
3563 
3564 
3565 void G4UIQt::ToolBoxActivated(int a){
3566 
3567  if (fUITabWidget->widget(a) == fHelpTBWidget) {
3568  // Rebuild the help tree
3569  FillHelpTree();
3570  } else if (fUITabWidget->widget(a) == fSceneTreeComponentsTBWidget) {
3571 #if QT_VERSION < 0x040200
3572  fSceneTreeComponentsTBWidget->show();
3573 #else
3574  fSceneTreeComponentsTBWidget->setVisible(true);
3575 #endif
3576  }
3577 }
3578 
3579 
3580 void G4QTabWidget::paintEvent(
3581 QPaintEvent *
3582 )
3583 {
3584 
3585  if (currentWidget()) {
3586 
3587  if ( isTabSelected()) {
3588 
3589  // QCoreApplication::sendPostedEvents () ;
3590 
3591  QString text = tabText (currentIndex());
3592 
3593  if (fLastCreated == -1) {
3594  QString paramSelect = QString("/vis/viewer/select ")+text;
3596  if(UI != NULL) {
3597  UI->ApplyCommand(paramSelect.toStdString().c_str());
3598  }
3599  } else {
3600  fLastCreated = -1;
3601  }
3602  setTabSelected(false);
3603  }
3604  }
3605 }
3606 
3607 #endif
G4UIcommandTree * FindCommandTree(const char *commandPath)
Try to match a command or a path with the one given.
G4String GetParameterCandidates() const
const G4String & GetRange() const
Definition: G4UIcommand.hh:133
Definition: test07.cc:36
G4UIcommand * FindPath(const char *commandPath) const
G4String strip(G4int strip_Type=trailing, char c=' ')
G4int GetCommandEntry() const
G4String name
Definition: TRTMaterials.hh:40
G4String GetParameterName() const
G4UIcommand * GetCommand(G4int i)
G4int GetTreeEntry() const
G4double a
Definition: TRTMaterials.hh:39
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:227
void SetSession(G4UIsession *const value)
Definition: G4UImanager.hh:213
Definition: test07.cc:36
int G4int
Definition: G4Types.hh:78
const G4String & GetGuidanceLine(G4int i) const
Definition: G4UIcommand.hh:137
void SetG4UIWindow(G4UIsession *const value)
Definition: G4UImanager.hh:215
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4bool IsOmittable() const
static const double s
Definition: G4SIunits.hh:150
void * G4Interactor
static G4StateManager * GetStateManager()
G4GLOB_DLL std::ostream G4cout
str_size index(const char *, G4int pos=0) const
G4UIcommandTree * GetTree(G4int i)
bool G4bool
Definition: G4Types.hh:79
#define FALSE
Definition: globals.hh:52
G4UIparameter * GetParameter(G4int i) const
Definition: G4UIcommand.hh:145
#define TRUE
Definition: globals.hh:55
const G4String & GetCommandPath() const
Definition: G4UIcommand.hh:139
G4ApplicationState GetCurrentState() const
const G4String GetPathName() const
const char * data() const
const G4String GetTitle() const
G4UIcommandTree * GetTree() const
Definition: G4UImanager.hh:206
G4String GetDefaultValue() const
void SetCoutDestination(G4UIsession *const value)
Definition: G4UImanager.cc:604
const G4UIcommand * GetGuidance() const
char GetParameterType() const
#define G4endl
Definition: G4ios.hh:61
const G4String GetParameterGuidance() const
G4String GetParameterRange() const
G4int GetGuidanceEntries() const
Definition: G4UIcommand.hh:135
G4int GetParameterEntries() const
Definition: G4UIcommand.hh:143
G4bool GetCurrentAsDefault() const
G4bool isNull() const
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:432