Geant4_10
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 78056 2013-12-03 08:29:59Z 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  fViewerTabHandleWidget->setMinimumSize(40,40);
438 
439  commandLineWidget->setMinimumSize(50,50);
440 
441  // Connect signal
442  connect(fCommandArea, SIGNAL(returnPressed()), SLOT(CommandEnteredCallback()));
443  connect(fCommandArea, SIGNAL(textEdited(const QString &)), SLOT(CommandEditedCallback(const QString &)));
444 
445  fRightSplitterWidget->resize(200,200);
446  return fRightSplitterWidget;
447 }
448 
449 
452 QTabWidget* G4UIQt::GetSceneTreeComponentsTBWidget(
453 )
454 {
455  return fSceneTreeComponentsTBWidget;
456 }
457 
458 
462 bool G4UIQt::AddTabWidget(
463  QWidget* aWidget
464 ,QString name
465 ,int sizeX
466 ,int sizeY
467 )
468 {
469  // Special case for Qt version between 5.0 and 5.1 on Mac OSX
470  // Due to a bug in this Qt version, we can't put a OpenGL Widget inside the QTabWidget.
471  // A work around is to put it outside. Returning false will fore the wiewer to put the QGLWidget
472  // inside a new QWindow.
473 
474 #ifdef Q_OS_MAC
475  #if QT_VERSION < 0x050100
476  #if QT_VERSION >= 0x050000
477  QString message = QString(
478  "This Qt version [")+qVersion ()+"] has some issues with the OpenGL viewer.\n"+
479  "To prevent problems, you are not allowed to open a Store nor Immediate viewer.\n" +
480  "\n" +
481  "Please upgrade to Qt version >= 5.1\n";
482 
483  QMessageBox::warning(fMainWindow, tr("Warning"),
484  tr(message.toStdString().c_str()),
485  QMessageBox::Ok);
486  return false;
487  #endif
488  #endif
489 #endif
490 
491  if (fViewerTabWidget == NULL) {
492  fViewerTabWidget = new G4QTabWidget(fViewerTabHandleWidget, sizeX, sizeY);
493  #if QT_VERSION < 0x040500
494 #else
495  fViewerTabWidget->setTabsClosable (true);
496 #endif
497 
498 #if QT_VERSION < 0x040200
499 #else
500  fViewerTabWidget->setUsesScrollButtons (true);
501 #endif
502 
503 #if QT_VERSION < 0x040500
504 #else
505  connect(fViewerTabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(TabCloseCallback(int)));
506 #endif
507  connect(fViewerTabWidget, SIGNAL(currentChanged ( int ) ), SLOT(UpdateTabWidget(int)));
508  }
509 
510  if (!aWidget) {
511  return false;
512  }
513 // Has to be added before we put it into the fViewerTabHandleWidget widget
514  fViewerTabWidget->addTab(aWidget,name);
515 
516  // Remove QLabel
517 
518  // L.Garnier 26/05/2010 : not exactly the same in qt3. Could cause some
519  // troubles
520  if (fEmptyViewerTabLabel != NULL) {
521  int index = -1;
522  index = fViewerTabHandleWidget->layout()->indexOf(fEmptyViewerTabLabel);
523  if ( index != -1) {
524  fViewerTabHandleWidget->layout()->removeWidget(fEmptyViewerTabLabel);
525  delete fEmptyViewerTabLabel;
526  fEmptyViewerTabLabel = NULL;
527  printf("fViewerTabHandleWidget :%d %d\n",fViewerTabHandleWidget->width(), fViewerTabHandleWidget->height());
528 
529  fViewerTabHandleWidget->layout()->addWidget(fViewerTabWidget);
530  printf("fViewerTabHandleWidget :%d %d\n",fViewerTabHandleWidget->width(), fViewerTabHandleWidget->height());
531  }
532  }
533 
534 
535 
536  fViewerTabWidget->setCurrentIndex(fViewerTabWidget->count()-1);
537 
538  // Set visible
539  #if QT_VERSION < 0x040200
540  fViewerTabWidget->setLastTabCreated(fViewerTabWidget->currentIndex());
541  #else
542  fViewerTabWidget->setLastTabCreated(fViewerTabWidget->currentIndex());
543  #endif
544 
545  // Problems with resize. The widgets are not realy drawn at this step,
546  // then we have to force them on order to check the size.
547  // try to computer new size in order not to go out of the screen
548 
549  // size of current tab
550  QSize s = QSize(sizeX,sizeY);
551 
552  QRect screen = QApplication::desktop()->screenGeometry();
553 
554  if (fMainWindow->width()-fViewerTabWidget->width()+sizeX > screen.width()) {
555  s.setWidth(screen.width()-fMainWindow->width()+fViewerTabWidget->width());
556  }
557  if (fMainWindow->height()-fViewerTabWidget->height()+sizeY > screen.height()-24) { // 24 is the menuBar height on mac
558  s.setHeight(screen.height()-fMainWindow->height()+fViewerTabWidget->height()-24);
559  }
560  int winWidth = fMainWindow->width();
561  int winHeight = fMainWindow->height();
562  int oldTabWidth = fViewerTabWidget->width();
563  int oldTabHeight = fViewerTabWidget->height();
564  int newTabWidth = fViewerTabWidget->sizeHint().width();
565  int newTabHeight = fViewerTabWidget->sizeHint().height();
566 
567  fViewerTabWidget->setPreferredSize(s);
568  fMainWindow->resize(winWidth-oldTabWidth+newTabWidth,
569  winHeight-oldTabHeight+newTabHeight);
570  return true;
571 }
572 
573 
574 void G4UIQt::UpdateTabWidget(int tabNumber) {
575  if ( fViewerTabWidget == NULL) {
576  fViewerTabWidget = new G4QTabWidget;
577  }
578 
579  fViewerTabWidget->setCurrentIndex(tabNumber);
580 
581  // Send this signal to unblock graphic updates !
582  fViewerTabWidget->setTabSelected(false);
583 
584  #if QT_VERSION < 0x040200
585  fViewerTabWidget->show();
586  #else
587  fViewerTabWidget->setVisible(true);
588  #endif
589 
590  // This will send a paintEvent to OGL Viewers
591  fViewerTabWidget->setTabSelected(true);
592 }
593 
594 
597 void G4UIQt::ResizeTabWidget( QResizeEvent* e) {
598  if ( fViewerTabWidget) {
599  for (G4int a=0;a<fViewerTabWidget->count() ;a++) {
600  fViewerTabWidget->widget(a)->resize(e->size());
601  }
602  }
603 }
604 
605 
608 G4UIsession* G4UIQt::SessionStart (
609 )
610 {
611  G4Qt* interactorManager = G4Qt::getInstance ();
612  Prompt("Session :");
613  exitSession = false;
614 
615  QCoreApplication::sendPostedEvents () ;
616 
617  #if QT_VERSION < 0x040200
618  fMainWindow->show();
619  #else
620  fMainWindow->setVisible(true);
621  #endif
622  interactorManager->DisableSecondaryLoop (); // TO KEEP
623  if ((QApplication*)interactorManager->GetMainInteractor())
624  ((QApplication*)interactorManager->GetMainInteractor())->exec();
625 
626  interactorManager->EnableSecondaryLoop ();
627  return this;
628 }
629 
630 
636 void G4UIQt::Prompt (
637  G4String aPrompt
638 )
639 {
640  if (!aPrompt) return;
641 
642  fCommandLabel->setText((char*)aPrompt.data());
643 }
644 
645 
646 
647 void G4UIQt::SessionTerminate (
648 )
649 {
650  G4Qt* interactorManager = G4Qt::getInstance ();
651  fMainWindow->close();
652  ((QApplication*)interactorManager->GetMainInteractor())->exit();
653 }
654 
655 
656 
665 void G4UIQt::PauseSessionStart (
666  const G4String& aState
667 )
668 {
669  if (!aState) return;
670 
671  if(aState=="G4_pause> ") { // TO KEEP
672  SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP
673  } // TO KEEP
674 
675  if(aState=="EndOfEvent") { // TO KEEP
676  // Picking with feed back in event data Done here !!!
677  SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP
678  } // TO KEEP
679 }
680 
681 
682 
687 void G4UIQt::SecondaryLoop (
688  G4String aPrompt
689 )
690 {
691  if (!aPrompt) return;
692 
693  G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ?
694  Prompt(aPrompt); // TO KEEP
695  exitPause = false; // TO KEEP
696  while(1) {
697  ((QApplication*)interactorManager)->processEvents(QEventLoop::WaitForMoreEvents);
698  if(exitPause==true) break; // TO KEEP
699  } // TO KEEP
700  Prompt("Session :"); // TO KEEP
701 }
702 
703 
704 
710 G4int G4UIQt::ReceiveG4cout (
711  const G4String& aString
712  )
713 {
714  if (!aString) return 0;
715 
716  QStringList newStr;
717 
718  // Add to stringList
719  newStr = QStringList(QString((char*)aString.data()).trimmed());
720  fG4cout += newStr;
721 
722  QStringList result = newStr.filter(fCoutFilter->text());
723 
724  if (result.join("").isEmpty()) {
725  return 0;
726  }
727  fCoutTBTextArea->append(result.join(""));
728  fCoutTBTextArea->repaint();
729 
730  fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
731 
732  return 0;
733 }
734 
735 
741 G4int G4UIQt::ReceiveG4cerr (
742  const G4String& aString
743 )
744 {
745  if (!aString) return 0;
746 
747  QStringList newStr;
748 
749  // Add to stringList
750  newStr = QStringList(QString((char*)aString.data()).trimmed());
751  fG4cout += newStr;
752 
753  QStringList result = newStr.filter(fCoutFilter->text());
754 
755  // Suppress space, \n,\t,\r...
756  if (QString(aString.data()).trimmed() != "") {
759  // In case of Abort or Quit, the useful error message should be in the last error message !
760  QMessageBox::critical(fMainWindow, "Error",QString(fLastErrMessage.data())+"\n"+aString.data());
761  }
762  }
763  QColor previousColor = fCoutTBTextArea->textColor();
764  fCoutTBTextArea->setTextColor(Qt::red);
765  fCoutTBTextArea->append(result.join("\n"));
766  fCoutTBTextArea->setTextColor(previousColor);
767  fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
768  fCoutTBTextArea->repaint();
769 
770  if (QString(aString.data()).trimmed() != "") {
771  fLastErrMessage = aString;
772  }
773  return 0;
774 }
775 
776 
777 
783 void G4UIQt::AddMenu (
784  const char* aName
785 ,const char* aLabel
786 )
787 {
788  if (aName == NULL) return;
789  if (aLabel == NULL) return;
790 
791  QMenu *fileMenu = new QMenu(aLabel);
792  fMainWindow->menuBar()->addMenu(fileMenu);
793 
794  AddInteractor (aName,(G4Interactor)fileMenu);
795 }
796 
797 
804 void G4UIQt::AddButton (
805  const char* aMenu
806 ,const char* aLabel
807 ,const char* aCommand
808 )
809 {
810  if(aMenu==NULL) return; // TO KEEP
811  if(aLabel==NULL) return; // TO KEEP
812  if(aCommand==NULL) return; // TO KEEP
813 
814  QMenu *parentTmp = (QMenu*)GetInteractor(aMenu);
815 
816  if(parentTmp==NULL) {
817  G4UImanager* UImanager = G4UImanager::GetUIpointer();
818  G4int verbose = UImanager->GetVerboseLevel();
819 
820  if (verbose >= 2) {
821  G4cout << "Menu name " << aMenu<< " does not exist, please define it before using it."<< G4endl;
822  }
823  return;
824  }
825 
826  // Find the command in the command tree
828  if(UI==NULL) return;
829  G4UIcommandTree * treeTop = UI->GetTree();
830 
831  G4String cmd = aCommand;
832  G4int cmdEndPos = cmd.find_first_of(" \t");
833  if(cmdEndPos!=G4int(std::string::npos)) {
834  cmd.erase(cmdEndPos);
835  }
836 
837  if(treeTop->FindPath(cmd) == NULL) {
838  G4UImanager* UImanager = G4UImanager::GetUIpointer();
839  G4int verbose = UImanager->GetVerboseLevel();
840 
841  if (verbose >= 2) {
842  G4cout << "Warning: command '"<< cmd <<"' does not exist, please define it before using it."<< G4endl;
843  }
844  }
845 
846  QSignalMapper *signalMapper = new QSignalMapper(this);
847  QAction *action = parentTmp->addAction(aLabel, signalMapper, SLOT(map()));
848 
849  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&)));
850  signalMapper->setMapping(action, QString(aCommand));
851 }
852 
853 
854 
855 
859 void G4UIQt::AddIcon(const char* aLabel, const char* aIconFile, const char* aCommand, const char* aFileName){
860  if(aLabel==NULL) return; // TO KEEP
861  // special case, aCommand could be NULL if aIconFile is not user_icon
862  if (aCommand==NULL) {
863  if (std::string(aIconFile) == "user_icon") {
864  return; // TO KEEP
865  }
866  }
867  QPixmap pix;
868  bool userToolBar = false;
869 
870  if (std::string(aIconFile) == "user_icon") {
871  // try to open a file
872  pix = QPixmap(aFileName);
873  if (pix.isNull()) {
874  G4UImanager* UImanager = G4UImanager::GetUIpointer();
875  G4int verbose = UImanager->GetVerboseLevel();
876 
877  if (verbose >= 2) {
878  G4cout << "Warning: file '"<< aFileName <<"' is incorrect or does not exist, this command will not be build"<< G4endl;
879  }
880  return;
881  }
882  userToolBar = true;
883  } else if (std::string(aIconFile) == "open") {
884  const char * const xpm[]={
885  "32 32 33 1",
886  " c None",
887  "+ c #09091E",
888  "@ c #191B18",
889  "# c #5F615F",
890  "$ c #777977",
891  "% c #AEB1AF",
892  "& c #929491",
893  "* c #515250",
894  "= c #858784",
895  "- c #333533",
896  "; c #000100",
897  "> c #272926",
898  ", c #424341",
899  "' c #696C6A",
900  ") c #5F4927",
901  "! c #583D18",
902  "~ c #6E6A5B",
903  "{ c #47351D",
904  "] c #E0A554",
905  "^ c #FFD67B",
906  "/ c #EFB465",
907  "( c #FDBF6C",
908  "_ c #FFCD76",
909  ": c #806238",
910  "< c #362611",
911  "[ c #0B0D0A",
912  "} c #68471B",
913  "| c #523E22",
914  "1 c #B78A51",
915  "2 c #A17B44",
916  "3 c #D6A45E",
917  "4 c #C29354",
918  "5 c #A1A3A0",
919  " ",
920  " ",
921  " +@@@# ",
922  " $% +& * ",
923  " #= $ -; ",
924  " %>;+ ",
925  " ,;;+ ",
926  " &#$''#' >;;;+ ",
927  " =)!)!!!!~ *#$'' ",
928  " {]^/((_({- %%%%%%%%%%% ",
929  " {(^_^^^^:<{{{{{{{{{{{{{[& ",
930  " {/_/(((((/]]]]]]]]]]]/]!# ",
931  " {/^(((((_^^^^^^^^^^^^^^:# ",
932  " {/^(((_^^____________^^}$ ",
933  " {/^(((((/////////////((!# ",
934  " {/^/^_:<|||||||||||||||@@****1 ",
935  " {/^/^(<[)||||||||||||||))!!}<; ",
936  " {/^_(:|234444444444444444432)1 ",
937  " {/_^/<)34444444444444444443}, ",
938  " {/^(2{:41111111111111111142|5 ",
939  " {3^3<:31111111111111111143}- ",
940  " {/^2<:31111111111111111441|' ",
941  " {_/<:41111111111111111143}, ",
942  " {(4<:31111111111111111144!# ",
943  " )4))44111111111111111144}, ",
944  " )2<:31111111111111111144{# ",
945  " @|:14444444444444444444}* ",
946  " ;@434444444444444444434<# ",
947  " ;[))))))))))))))))))))!~ ",
948  " ++++++++++++++++++++++;% ",
949  " ",
950  " "}
951  ;
952  pix = QPixmap(xpm);
953 
954  } else if (std::string(aIconFile) == "save") {
955  const char * const xpm[]={
956  "32 32 24 1",
957  " c None",
958  "+ c #000200",
959  "@ c #141E43",
960  "# c #000C56",
961  "$ c #494A47",
962  "% c #636662",
963  "& c #312F2A",
964  "* c #191B19",
965  "= c #002992",
966  "- c #003DFF",
967  "; c #041DA5",
968  "> c #A8A9A3",
969  ", c #FDFFFC",
970  "' c #DDE0DD",
971  ") c #818783",
972  "! c #C9CBC8",
973  "~ c #0116C3",
974  "{ c #C5C8FA",
975  "] c #6596FC",
976  "^ c #A0B4F9",
977  "/ c #0B2AFD",
978  "( c #799BE3",
979  "_ c #5F4826",
980  ": c #D5D8D5",
981  " ",
982  " ",
983  " +++++++++++++++++++++++++ ",
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  pix = QPixmap(xpm);
1015  } else if (std::string(aIconFile) == "move") {
1016  const char * const xpm[]={
1017  "32 32 16 1",
1018  " c None",
1019  ". c #F1F1F1",
1020  "+ c #939393",
1021  "@ c #282828",
1022  "# c #787878",
1023  "$ c #000000",
1024  "% c #CCCCCC",
1025  "& c #1A1A1A",
1026  "* c #0D0D0D",
1027  "= c #5D5D5D",
1028  "- c #AEAEAE",
1029  "; c #BBBBBB",
1030  "> c #C9C9C9",
1031  ", c #D6D6D6",
1032  "' c #FFFFFF",
1033  ") c #999999",
1034  " ",
1035  " ",
1036  " ",
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  pix = QPixmap(xpm);
1068 
1069  } else if (std::string(aIconFile) == "rotate") {
1070  const char * const xpm[]={
1071  "32 32 27 1",
1072  " c None",
1073  ". c #003333",
1074  "+ c #000066",
1075  "@ c #1A1A1A",
1076  "# c #003399",
1077  "$ c #3333CC",
1078  "% c #000033",
1079  "& c #353535",
1080  "* c #434343",
1081  "= c #336699",
1082  "- c #3399FF",
1083  "; c #003366",
1084  "> c #5D5D5D",
1085  ", c #282828",
1086  "' c #3399CC",
1087  ") c #333333",
1088  "! c #3366CC",
1089  "~ c #333399",
1090  "{ c #505050",
1091  "] c #666666",
1092  "^ c #333366",
1093  "/ c #0033CC",
1094  "( c #3366FF",
1095  "_ c #336666",
1096  ": c #787878",
1097  "< c #868686",
1098  "[ c #6B6B6B",
1099  " .++@ ",
1100  " #$$%&* ",
1101  " =--; *>, ",
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  pix = QPixmap(xpm);
1133 
1134  } else if (std::string(aIconFile) == "pick") {
1135  const char * const xpm[]={
1136  "32 32 2 1",
1137  " c None",
1138  ". c #000000",
1139  " ",
1140  " ",
1141  " ",
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  pix = QPixmap(xpm);
1173  } else if (std::string(aIconFile) == "zoom_in") {
1174  const char * const xpm[]={
1175  "32 32 11 1",
1176  " c None",
1177  ". c #C9CBC8",
1178  "+ c #A8A9A3",
1179  "@ c #818783",
1180  "# c #D5D8D5",
1181  "$ c #9BCCCC",
1182  "% c #5FC7F4",
1183  "& c #FDFFFC",
1184  "* c #636662",
1185  "= c #9599CE",
1186  "- c #DDE0DD",
1187  " ",
1188  " ",
1189  " ",
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  pix = QPixmap(xpm);
1221  } else if (std::string(aIconFile) == "zoom_out") {
1222  const char * const xpm[]={
1223  "32 32 11 1",
1224  " c None",
1225  ". c #C9CBC8",
1226  "+ c #A8A9A3",
1227  "@ c #818783",
1228  "# c #D5D8D5",
1229  "$ c #5FC7F4",
1230  "% c #9BCCCC",
1231  "& c #FDFFFC",
1232  "* c #636662",
1233  "= c #9599CE",
1234  "- c #DDE0DD",
1235  " ",
1236  " ",
1237  " ",
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  pix = QPixmap(xpm);
1269  } else if (std::string(aIconFile) == "wireframe") {
1270  const char * const xpm[]={
1271  "32 32 24 1",
1272  " c None",
1273  "+ c #E4E4E4",
1274  "@ c #D5D5D5",
1275  "# c #E1E1E1",
1276  "$ c #E7E7E7",
1277  "% c #D8D8D8",
1278  "& c #A7A7A7",
1279  "* c #000000",
1280  "= c #989898",
1281  "- c #8A8A8A",
1282  "; c #B5B5B5",
1283  "> c #1B1B1B",
1284  ", c #676767",
1285  "' c #959595",
1286  ") c #4A4A4A",
1287  "! c #878787",
1288  "~ c #D3D3D3",
1289  "{ c #C4C4C4",
1290  "] c #A4A4A4",
1291  "^ c #5B5B5B",
1292  "/ c #B3B3B3",
1293  "( c #787878",
1294  "_ c #C7C7C7",
1295  ": c #585858",
1296  " ",
1297  " +@@# ",
1298  " $%@@@@@&****=+ ",
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  pix = QPixmap(xpm);
1330  } else if (std::string(aIconFile) == "solid") {
1331  const char * const xpm[]={
1332  "32 32 33 1",
1333  " c None",
1334  "+ c #C2DEDE",
1335  "@ c #B5D7DF",
1336  "# c #ACD6E6",
1337  "$ c #60C0EC",
1338  "% c #4EB7EE",
1339  "& c #53B9ED",
1340  "* c #82CEEA",
1341  "= c #CFDDDA",
1342  "- c #94C9E8",
1343  "; c #0960FF",
1344  "> c #0943FF",
1345  ", c #0949FF",
1346  "' c #3CB3F0",
1347  ") c #71C7EB",
1348  "! c #73CBE5",
1349  "~ c #D3DDDB",
1350  "{ c #C4DDDE",
1351  "] c #B7D5DF",
1352  "^ c #2DACF5",
1353  "/ c #59C1ED",
1354  "( c #5FC0ED",
1355  "_ c #85CEE9",
1356  ": c #096BFF",
1357  "< c #2AACF6",
1358  "[ c #5CBEEC",
1359  "} c #7ACAE4",
1360  "| c #73CAEB",
1361  "1 c #71C8E5",
1362  "2 c #D1DDDA",
1363  "3 c #CBDDD9",
1364  "4 c #67C1EB",
1365  "5 c #80CDEA",
1366  " ",
1367  " ",
1368  " +@@@@@@#$%&*= ",
1369  " +-;>>>>>>>>>,')!~ ",
1370  " {]@@-;>>>>>>>>>>>>^/(_= ",
1371  " {:>>>>>>>>>>>>>>>>><//[)!= ",
1372  " ]>>>>>>>>>>>>>>>>>><////[)} ",
1373  " @>>>>>>>>>>>>>>>>>><//////| ",
1374  " @>>>>>>>>>>>>>>>>>><//////| ",
1375  " @>>>>>>>>>>>>>>>>>><//////| ",
1376  " @>>>>>>>>>>>>>>>>>><//////| ",
1377  " @>>>>>>>>>>>>>>>>>><//////| ",
1378  " @>>>>>>>>>>>>>>>>>><//////| ",
1379  " @>>>>>>>>>>>>>>>>>><//////| ",
1380  " @>>>>>>>>>>>>>>>>>><//////| ",
1381  " @>>>>>>>>>>>>>>>>>><//////| ",
1382  " @>>>>>>>>>>>>>>>>>><//////| ",
1383  " @>>>>>>>>>>>>>>>>>><//////| ",
1384  " @>>>>>>>>>>>>>>>>>><//////| ",
1385  " @>>>>>>>>>>>>>>>>>><//////| ",
1386  " @>>>>>>>>>>>>>>>>>><//////| ",
1387  " @>>>>>>>>>>>>>>>>>></////[1 ",
1388  " @>>>>>>>>>>>>>>>>>><////[*2 ",
1389  " {:>>>>>>>>>>>>>>>>><//[)12 ",
1390  " +@@@@@-;>>>>>>>>>><[)13 ",
1391  " {]@@@-;>>>,'*3 ",
1392  " +@@#452 ",
1393  " ",
1394  " ",
1395  " ",
1396  " ",
1397  " "}
1398  ;
1399  pix = QPixmap(xpm);
1400  } else if (std::string(aIconFile) == "hidden_line_removal") {
1401  const char * const xpm[]={
1402  "32 32 15 1",
1403  " c None",
1404  "+ c #D5D5D5",
1405  "@ c #C7C7C7",
1406  "# c #9C9C9C",
1407  "$ c #000000",
1408  "% c #8E8E8E",
1409  "& c #808080",
1410  "* c #A9A9A9",
1411  "= c #D8D8D8",
1412  "- c #CACACA",
1413  "; c #181818",
1414  "> c #9F9F9F",
1415  ", c #ACACAC",
1416  "' c #B9B9B9",
1417  ") c #555555",
1418  " ",
1419  " +@@+ ",
1420  " +@@@@@@#$$$$%+ ",
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  pix = QPixmap(xpm);
1452  } else if (std::string(aIconFile) == "hidden_line_and_surface_removal") {
1453  const char * const xpm[]={
1454  "32 32 40 1",
1455  " c None",
1456  "+ c #FFFFFF",
1457  "@ c #89A2E9",
1458  "# c #5378E3",
1459  "$ c #A2B5ED",
1460  "% c #5379E3",
1461  "& c #5076E3",
1462  "* c #3E69E4",
1463  "= c #0C43F8",
1464  "- c #043FFE",
1465  "; c #CDD9ED",
1466  "> c #BDCDE9",
1467  ", c #FBFCFC",
1468  "' c #406AE4",
1469  ") c #0439FE",
1470  "! c #0137FF",
1471  "~ c #4F75E3",
1472  "{ c #9EB5E3",
1473  "] c #829FE0",
1474  "^ c #B6C6E7",
1475  "/ c #9DB4E3",
1476  "( c #7E9CE0",
1477  "_ c #B2C3E9",
1478  ": c #7E9AE0",
1479  "< c #86A2E1",
1480  "[ c #CAD6ED",
1481  "} c #5177E3",
1482  "| c #829CE0",
1483  "1 c #BCCCE9",
1484  "2 c #3A67E6",
1485  "3 c #0A43FA",
1486  "4 c #95ACE1",
1487  "5 c #BBCBE9",
1488  "6 c #A9BBE5",
1489  "7 c #96AFE1",
1490  "8 c #BDCBE9",
1491  "9 c #4067E4",
1492  "0 c #6485E5",
1493  "a c #E3EAF3",
1494  "b c #CAD6F3",
1495  " ",
1496  " ",
1497  " ++++ ",
1498  " ++++++++@#$+++ ",
1499  " ++@%####&*=-#+;>, ",
1500  " +++++@'=)))))))!)~+{]^++ ",
1501  " +$%&*=)!!!!!!!!!)~+/(]_+++ ",
1502  " +#-))!!!!!!!!!!!)~+/(::<[+ ",
1503  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1504  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1505  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1506  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1507  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1508  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1509  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1510  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1511  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1512  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1513  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1514  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1515  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1516  " +#)!!!!!!!!!!!!!!}+/:::|1+ ",
1517  " +$#}}~23!!!!!!!!)~+/(]45, ",
1518  " +++++++@#}}~23!!)~+678++ ",
1519  " ++++++@#~90+a++ ",
1520  " ++++b++ ",
1521  " ++ ",
1522  " ",
1523  " ",
1524  " ",
1525  " ",
1526  " "}
1527  ;
1528  pix = QPixmap(xpm);
1529  } else if (std::string(aIconFile) == "perspective") {
1530  const char * const xpm[]={
1531  "32 32 3 1",
1532  " c None",
1533  ". c #D5D8D5",
1534  "+ c #000000",
1535  " ",
1536  " ",
1537  " ",
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  pix = QPixmap(xpm);
1569  } else if (std::string(aIconFile) == "ortho") {
1570  const char * const xpm[]={
1571  "32 32 3 1",
1572  " c None",
1573  ". c #D5D8D5",
1574  "@ c #000000",
1575  " ",
1576  " ",
1577  " ",
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  pix = QPixmap(xpm);
1609  } else {
1610  G4UImanager* UImanager = G4UImanager::GetUIpointer();
1611  G4int verbose = UImanager->GetVerboseLevel();
1612 
1613  if (verbose >= 2) {
1614  G4cout << "Parameter"<< aIconFile <<" not defined"<< G4endl;
1615  }
1616  return;
1617  }
1618  QToolBar *currentToolbar = NULL;
1619  if (userToolBar) {
1620  if (fToolbarUser == NULL) {
1621  fToolbarUser = new QToolBar();
1622  fToolbarUser->setIconSize (QSize(20,20));
1623  fMainWindow->addToolBar(Qt::TopToolBarArea, fToolbarUser);
1624  }
1625  currentToolbar = fToolbarUser;
1626  } else {
1627  if (fToolbarApp == NULL) {
1628  fToolbarApp = new QToolBar();
1629  fToolbarApp->setIconSize (QSize(20,20));
1630  fMainWindow->addToolBar(Qt::TopToolBarArea, fToolbarApp);
1631  }
1632  currentToolbar = fToolbarApp;
1633  }
1634 
1635  QSignalMapper *signalMapper = new QSignalMapper(this);
1636  QAction *action = currentToolbar->addAction(pix,aLabel, signalMapper, SLOT(map()));
1637 
1638 
1639  // special cases :"open"
1640  if (std::string(aIconFile) == "open") {
1641  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(OpenIconCallback(const QString &)));
1642  QString txt = aCommand + fStringSeparator + aLabel;
1643  signalMapper->setMapping(action, QString(txt));
1644 
1645  // special cases :"save"
1646  } else if (std::string(aIconFile) == "save") {
1647  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(SaveIconCallback(const QString&)));
1648  QString txt = aCommand + fStringSeparator + aLabel;
1649  signalMapper->setMapping(action, QString(txt));
1650 
1651  // special cases : cursor style
1652  } else if ((std::string(aIconFile) == "move") ||
1653  (std::string(aIconFile) == "rotate") ||
1654  (std::string(aIconFile) == "pick") ||
1655  (std::string(aIconFile) == "zoom_out") ||
1656  (std::string(aIconFile) == "zoom_in")) {
1657  action->setCheckable(TRUE);
1658  action->setChecked(TRUE);
1659  action->setData(aIconFile);
1660 
1661  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ChangeCursorStyle(const QString&)));
1662  signalMapper->setMapping(action, QString(aIconFile));
1663 
1664  if (std::string(aIconFile) == "move") {
1665  SetIconMoveSelected();
1666  }
1667  if (std::string(aIconFile) == "rotate") {
1668  SetIconRotateSelected();
1669  }
1670  if (std::string(aIconFile) == "pick") {
1671  SetIconPickSelected();
1672  }
1673  if (std::string(aIconFile) == "zoom_in") {
1674  SetIconZoomInSelected();
1675  }
1676  if (std::string(aIconFile) == "zoom_out") {
1677  SetIconZoomOutSelected();
1678  }
1679 
1680  // special case : surface style
1681  } else if ((std::string(aIconFile) == "hidden_line_removal") ||
1682  (std::string(aIconFile) == "hidden_line_and_surface_removal") ||
1683  (std::string(aIconFile) == "solid") ||
1684  (std::string(aIconFile) == "wireframe")) {
1685  action->setCheckable(TRUE);
1686  action->setChecked(TRUE);
1687  action->setData(aIconFile);
1688  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ChangeSurfaceStyle(const QString&)));
1689  signalMapper->setMapping(action, QString(aIconFile));
1690 
1691  if (std::string(aIconFile) == "hidden_line_removal") {
1692  SetIconHLRSelected();
1693  }
1694  if (std::string(aIconFile) == "hidden_line_and_surface_removal") {
1695  SetIconHLHSRSelected();
1696  }
1697  if (std::string(aIconFile) == "solid") {
1698  SetIconSolidSelected();
1699  }
1700  if (std::string(aIconFile) == "wireframe") {
1701  SetIconWireframeSelected();
1702  }
1703 
1704  // special case : perspective/ortho
1705  } else if ((std::string(aIconFile) == "perspective") ||
1706  (std::string(aIconFile) == "ortho")) {
1707  action->setCheckable(TRUE);
1708  action->setChecked(TRUE);
1709  action->setData(aIconFile);
1710  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ChangePerspectiveOrtho(const QString&)));
1711  signalMapper->setMapping(action, QString(aIconFile));
1712 
1713  if (std::string(aIconFile) == "perspective") {
1714  SetIconPerspectiveSelected();
1715  }
1716  if (std::string(aIconFile) == "ortho") {
1717  SetIconOrthoSelected();
1718  }
1719 
1720  } else {
1721 
1722  // Find the command in the command tree
1724  if(UI==NULL) return;
1725  G4UIcommandTree * treeTop = UI->GetTree();
1726  if (aCommand != NULL) {
1727  if(treeTop->FindPath(aCommand) == NULL) {
1728  G4UImanager* UImanager = G4UImanager::GetUIpointer();
1729  G4int verbose = UImanager->GetVerboseLevel();
1730 
1731  if (verbose >= 2) {
1732  G4cout << "Warning: command '"<< aCommand <<"' does not exist, please define it before using it."<< G4endl;
1733  }
1734  }
1735  }
1736 
1737  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&)));
1738  signalMapper->setMapping(action, QString(aCommand));
1739  }
1740 }
1741 
1742 
1743 
1744 void G4UIQt::ActivateCommand(
1745  G4String newCommand
1746 )
1747 {
1748  if (!fHelpTreeWidget) {
1749  return;
1750  }
1751  // Look for the choosen command "newCommand"
1752  size_t i = newCommand.index(" ");
1753  G4String targetCom ="";
1754  if( i != std::string::npos )
1755  {
1756  G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
1757  newValue.strip(G4String::both);
1758  targetCom = ModifyToFullPathCommand( newValue );
1759  }
1760  if (targetCom != "") {
1761  OpenHelpTreeOnCommand(targetCom.data());
1762  }
1763 
1764  fUITabWidget->setCurrentWidget(fHelpTBWidget);
1765 }
1766 
1767 
1768 
1775 void G4UIQt::InitHelpTreeAndVisParametersWidget()
1776 {
1777 
1778  if (! fHelpTreeWidget ) {
1779  fHelpTreeWidget = new QTreeWidget();
1780  }
1781 
1782  // build widget
1783  fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
1784  QStringList labels;
1785  labels << QString("Command");
1786  fHelpTreeWidget->setHeaderLabels(labels);
1787 
1788 
1789  connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback()));
1790  connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback()));
1791 
1792 }
1799 void G4UIQt::FillHelpTree()
1800 {
1801  if (! fHelpTreeWidget ) {
1802  InitHelpTreeAndVisParametersWidget();
1803  }
1804 
1805  QString searchText = fHelpLine->text();
1806 
1807  if (searchText =="") {
1808  // clear old help tree
1809  // fHelpTreeWidget->clear();
1810  } else {
1811  return;
1812  }
1813 
1814  if (fHelpArea) {
1815 #if QT_VERSION < 0x040200
1816  fHelpArea->clear();
1817 #else
1818  fHelpArea->setText("");
1819 #endif
1820  }
1821 
1822  if (fHelpLine) {
1823 #if QT_VERSION < 0x040200
1824  fHelpLine->clear();
1825 #else
1826  fHelpLine->setText("");
1827 #endif
1828  }
1829 
1831  if(UI==NULL) return;
1832  G4UIcommandTree * treeTop = UI->GetTree();
1833 
1834  G4int treeSize = treeTop->GetTreeEntry();
1835  QTreeWidgetItem * newItem = NULL;
1836  QString commandText = "";
1837  for (int a=0;a<treeSize;a++) {
1838  // Creating new item
1839  newItem = NULL;
1840 
1841  commandText = QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed();
1842 
1843  // if already exist, don't create it !
1844  for (int b=0;b<fHelpTreeWidget->topLevelItemCount();b++) {
1845  if (!newItem)
1846  newItem = FindTreeItem(fHelpTreeWidget->topLevelItem(b),commandText);
1847  }
1848 
1849  if (newItem == NULL) {
1850 
1851  newItem = new QTreeWidgetItem();
1852  newItem->setText(0,GetShortCommandPath(commandText));
1853  fHelpTreeWidget->addTopLevelItem(newItem);
1854  }
1855 
1856  // look for childs
1857  CreateHelpTree(newItem,treeTop->GetTree(a+1));
1858  }
1859 
1860 }
1861 
1862 
1863 
1868 void G4UIQt::CreateHelpTree(
1869  QTreeWidgetItem *aParent
1870 ,G4UIcommandTree *aCommandTree
1871 )
1872 {
1873  if (aParent == NULL) return;
1874  if (aCommandTree == NULL) return;
1875 
1876 
1877  // Creating new item
1878  QTreeWidgetItem * newItem;
1879 
1880  QString commandText = "";
1881  // Get the Sub directories
1882  for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
1883 
1884  commandText = QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed();
1885 
1886  // if already exist, don't create it !
1887  newItem = FindTreeItem(aParent,commandText);
1888  if (newItem == NULL) {
1889  newItem = new QTreeWidgetItem();
1890  newItem->setText(0,GetShortCommandPath(commandText));
1891  aParent->addChild(newItem);
1892  }
1893  CreateHelpTree(newItem,aCommandTree->GetTree(a+1));
1894  }
1895 
1896  // Get the Commands
1897 
1898  for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
1899 
1900  QStringList stringList;
1901  commandText = QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed();
1902 
1903  // if already exist, don't create it !
1904  newItem = FindTreeItem(aParent,commandText);
1905  if (newItem == NULL) {
1906  newItem = new QTreeWidgetItem();
1907  newItem->setText(0,GetShortCommandPath(commandText));
1908  aParent->addChild(newItem);
1909 
1910 #if QT_VERSION < 0x040202
1911  fHelpTreeWidget->setItemExpanded(newItem,false);
1912 #else
1913  newItem->setExpanded(false);
1914 #endif
1915  }
1916  }
1917 }
1918 
1919 
1920 
1921 
1927 bool G4UIQt::CreateVisCommandGroupAndToolBox(
1928  G4UIcommand* aCommand
1929 ,QWidget* aParent
1930 ,int aDepthLevel
1931 ,bool isDialog
1932 )
1933 {
1934  QString commandText = QString((char*)(aCommand->GetCommandPath().data())).section("/",-aDepthLevel);
1935 
1936  if (commandText == NULL) {
1937  return false;
1938  }
1939 
1940  // Look if groupBox is create
1941  // QGroupBox* gBoxCommandWidget;
1942  QWidget* newParentWidget = NULL;
1943  bool found = false;
1944  QString commandSection = commandText.left(commandText.indexOf("/"));
1945 
1946  if (aDepthLevel == 1) {
1947  QToolBox* currentParent = dynamic_cast<QToolBox*>(aParent);
1948  if (currentParent != 0){
1949 
1950  // already exists ?
1951  for (int a=0; a<currentParent->count(); a++) {
1952  if (currentParent->itemText(a) == commandSection) {
1953  found = true;
1954  newParentWidget = currentParent->widget(a);
1955  }
1956  }
1957  }
1958  // Not found ? create it
1959  if (!found) {
1960  newParentWidget = new QGroupBox();
1961  newParentWidget->setLayout(new QVBoxLayout());
1962  if (currentParent != 0){
1963  currentParent->addItem(newParentWidget,commandSection);
1964  } else {
1965  if (!aParent->layout()) {
1966  aParent->setLayout(new QVBoxLayout());
1967  }
1968  aParent->layout()->addWidget(newParentWidget);
1969  }
1970 
1971  if (commandText.indexOf("/") == -1) {
1972 
1973  // Guidance
1974  QString guidance;
1975  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
1976  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
1977  guidance += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
1978  }
1979  newParentWidget->setToolTip(guidance);
1980  }
1981 
1982  QScrollArea* sc = dynamic_cast<QScrollArea*>(newParentWidget->parent()->parent());
1983  if (sc != 0) {
1984  sc->ensureWidgetVisible(newParentWidget);
1985 
1986  }
1987  }
1988  } else {
1989 
1990  // try to know if this level is already there
1991  QGroupBox* currentParent = dynamic_cast<QGroupBox*>(aParent);
1992  if (currentParent != 0){
1993 
1994  // if depth==2, then we add a [more parameters inside] to the toolBoxItem parent
1995  // QGroupBox > QWidget > QScrollArea > QToolBox
1996  if (aDepthLevel == 2){
1997  QToolBox* parentToolBox = dynamic_cast<QToolBox*>(currentParent->parent()->parent()->parent());
1998  if (parentToolBox != 0) {
1999  // parentToolBox->setItemText(parentToolBox->indexOf(currentParent),"[more parameters inside]");
2000  }
2001  }
2002  for (int a=0; a<aParent->layout()->count(); a++) {
2003  QGroupBox* gb = dynamic_cast<QGroupBox*>(aParent->layout()->itemAt(a)->widget());
2004  if (gb != 0) {
2005  if (gb->title() == commandSection) {
2006  found = true;
2007  newParentWidget = gb;
2008  }
2009  }
2010  }
2011  }
2012 
2013  // Not found ? create it
2014  if (!found) {
2015  newParentWidget = new QGroupBox();
2016  newParentWidget->setLayout(new QVBoxLayout());
2017  if (!aParent->layout()) {
2018  aParent->setLayout(new QVBoxLayout());
2019  }
2020  aParent->layout()->addWidget(newParentWidget);
2021 
2022  // set toolTip
2023  // Guidance
2024  QString guidance;
2025  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
2026  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
2027  guidance += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
2028  }
2029  newParentWidget->setToolTip(guidance);
2030  }
2031  }
2032 
2033  // fill command groupbox
2034  if (commandText.indexOf("/") == -1) {
2035  if (CreateCommandWidget(aCommand, newParentWidget,isDialog)) {
2036  return true;
2037  }
2038  } else {
2039  CreateVisCommandGroupAndToolBox(aCommand,newParentWidget, aDepthLevel-1,isDialog);
2040  }
2041 
2042  return true;
2043 }
2044 
2045 
2046 
2052 bool G4UIQt::CreateCommandWidget(G4UIcommand* aCommand, QWidget* aParent, bool isDialog) {
2053 
2054  if (aCommand == NULL) {
2055  return false;
2056  }
2057 
2058 
2059  // parameters
2060  G4int n_parameterEntry = aCommand->GetParameterEntries();
2061  if( n_parameterEntry > 0 ) {
2062  G4UIparameter *param;
2063 
2064  // Re-implementation of G4UIparameter.cc
2065  QWidget* paramWidget = new QWidget();
2066  QGridLayout* gridLayout = new QGridLayout();
2067  paramWidget->setLayout(gridLayout);
2068 
2069  // Special case for colour, try to display a color chooser if we found red/green/blue parameter
2070  unsigned int nbColorParameter = 0;
2071  bool isStillColorParameter = false;
2072  bool isColorDialogAdded = false;
2073  QLabel* redLabel = NULL;
2074  QLabel* greenLabel = NULL;
2075  QString redDefaultStr = "";
2076  QString greenDefaultStr = "";
2077  QString blueDefaultStr = "";
2078  QWidget* redInput = NULL;
2079  QWidget* greenInput = NULL;
2080 
2081  for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
2082  QString txt;
2083  param = aCommand->GetParameter(i_thParameter);
2084  QLabel* label = new QLabel(QString((char*)(param->GetParameterName()).data()));
2085 
2086  if ((label->text() == "red") || (label->text() == "red_or_string")){
2087  nbColorParameter ++;
2088  isStillColorParameter = true;
2089  } else if ((label->text() == "green") && isStillColorParameter) {
2090  nbColorParameter ++;
2091  } else if ((label->text() == "blue") && isStillColorParameter) {
2092  nbColorParameter ++;
2093  } else if (!isColorDialogAdded) {
2094 
2095  // not following red/green/blue parameters ?
2096  if (nbColorParameter == 1) {
2097  gridLayout->addWidget(redLabel,i_thParameter-1,0);
2098  gridLayout->addWidget(redInput,i_thParameter-1,1);
2099  } else if (nbColorParameter == 2) {
2100  gridLayout->addWidget(redLabel,i_thParameter-2,0);
2101  gridLayout->addWidget(redInput,i_thParameter-2,1);
2102  gridLayout->addWidget(greenLabel,i_thParameter-1,0);
2103  gridLayout->addWidget(greenInput,i_thParameter-1,1);
2104  }
2105  nbColorParameter = 0;
2106  }
2107  // Check parameter type, could be NULL if not found
2108  QWidget* input = NULL;
2109  if ((QString(QChar(param->GetParameterType())) == "d") || (QString(QChar(param->GetParameterType())) == "i")) {
2110  input = new QLineEdit();
2111  // set default value
2112  dynamic_cast<QLineEdit*>(input)->setText(QString((char*)(param->GetDefaultValue()).data()));
2113 
2114  if (((label->text() == "red") || (label->text() == "red_or_string")) && isStillColorParameter) {
2115  redDefaultStr = QString((char*)(param->GetDefaultValue()).data());
2116  } else if ((label->text() == "green") && isStillColorParameter) {
2117  greenDefaultStr = QString((char*)(param->GetDefaultValue()).data());
2118  } else if ((label->text() == "green") && isStillColorParameter) {
2119  blueDefaultStr = QString((char*)(param->GetDefaultValue()).data());
2120  }
2121 
2122  } else if (QString(QChar(param->GetParameterType())) == "b") {
2123  input = new QWidget();
2124  QHBoxLayout* layout = new QHBoxLayout();
2125  input->setLayout(layout);
2126 
2127  QButtonGroup* buttons = new QButtonGroup();
2128  QRadioButton* radioOff = new QRadioButton("0");
2129  QRadioButton* radioOn = new QRadioButton("1");
2130  buttons->addButton(radioOn);
2131  buttons->addButton(radioOff);
2132  layout->addWidget(radioOn);
2133  layout->addWidget(radioOff);
2134 
2135  // set default value
2136  QString defaultValue = QString((char*)(param->GetDefaultValue()).data());
2137  if (defaultValue == "0") {
2138  radioOff->setChecked(true);
2139  } else if (defaultValue == "1") {
2140  radioOn->setChecked(true);
2141  }
2142  } else if ((QString(QChar(param->GetParameterType())) == "s") && (!param->GetParameterCandidates().isNull())) {
2143  input = new QComboBox();
2144  QString candidates = QString((char*)(param->GetParameterCandidates()).data());
2145  QStringList list = candidates.split (" ");
2146 
2147  // add all candidates to widget
2148  QString defaultValue = QString((char*)(param->GetDefaultValue()).data());
2149  for (int a=0; a<list.size(); a++) {
2150  dynamic_cast<QComboBox*>(input)->addItem(list.at(a));
2151  if (list.at(a) == defaultValue) {
2152  dynamic_cast<QComboBox*>(input)->setCurrentIndex(a);
2153  }
2154  }
2155 
2156  } else if ((QString(QChar(param->GetParameterType())) == "s")) { // string
2157  input = new QLineEdit();
2158  // set default value
2159  dynamic_cast<QLineEdit*>(input)->setText(QString((char*)(param->GetDefaultValue()).data()));
2160 
2161  } else if ((QString(QChar(param->GetParameterType())) == "c")) { // on/off
2162  input = new QWidget();
2163  QHBoxLayout* layout = new QHBoxLayout();
2164  input->setLayout(layout);
2165 
2166  QButtonGroup* buttons = new QButtonGroup();
2167  QRadioButton* radioOff = new QRadioButton("off");
2168  QRadioButton* radioOn = new QRadioButton("on");
2169  buttons->addButton(radioOn);
2170  buttons->addButton(radioOff);
2171  layout->addWidget(radioOn);
2172  layout->addWidget(radioOff);
2173 
2174  // set default value
2175  QString defaultValue = QString((char*)(param->GetDefaultValue()).data());
2176  if (defaultValue == "off") {
2177  radioOff->setChecked(true);
2178  } else if (defaultValue == "on") {
2179  radioOn->setChecked(true);
2180  }
2181 
2182  } else {
2183  input = new QLineEdit();
2184  dynamic_cast<QLineEdit*>(input)->setText(QString((char*)(param->GetDefaultValue()).data()));
2185  }
2186 
2187  txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
2188  if( ! param->GetParameterGuidance().isNull() )
2189  txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
2190 
2191  txt += " Parameter type : " + QString(QChar(param->GetParameterType())) + "\n";
2192  if(param->IsOmittable()){
2193  txt += " Omittable : True\n";
2194  } else {
2195  txt += " Omittable : False\n";
2196  }
2197  if( param->GetCurrentAsDefault() ) {
2198  txt += " Default value : taken from the current value\n";
2199  } else if( ! param->GetDefaultValue().isNull() ) {
2200  txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n";
2201  }
2202  if( ! param->GetParameterRange().isNull() ) {
2203  txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
2204  }
2205  if( ! param->GetParameterCandidates().isNull() ) {
2206  txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
2207  }
2208 
2209  if (isStillColorParameter && (nbColorParameter != 0)) {
2210  if ((label->text() == "red") || (label->text() == "red_or_string")) {
2211  redLabel = label;
2212  redInput = input;
2213  } else if (label->text() == "green") {
2214  greenLabel = label;
2215  greenInput = input;
2216  } else if (label->text() == "blue") {
2217 
2218  // we have all, then add a color chooser
2219 
2220  // Create a pixmap with the default color
2221  QColor qc;
2222  if ((redDefaultStr != "") && (redDefaultStr != "") && (redDefaultStr != "")) {
2223  qc.setRgbF(redDefaultStr.toDouble(),
2224  greenDefaultStr.toDouble(),
2225  blueDefaultStr.toDouble());
2226  }
2227  QPixmap pixmap = QPixmap(QSize(16, 16));
2228  pixmap.fill (qc);
2229  QPainter painter(&pixmap);
2230  painter.setPen(Qt::black);
2231  painter.drawRect(0,0,15,15); // Draw contour
2232 
2233  input = new QPushButton("Change color");
2234  dynamic_cast<QPushButton*>(input)->setIcon(pixmap);
2235  dynamic_cast<QPushButton*>(input)->setAccessibleName(redDefaultStr+" "+greenDefaultStr+" "+blueDefaultStr);
2236  label = new QLabel("Choose color");
2237 
2238  // less 1 because we have to add one to the row number
2239  nbColorParameter--;
2240  gridLayout->addWidget(label,i_thParameter-nbColorParameter,0);
2241  input->setToolTip("Select the current color");
2242  gridLayout->addWidget(input,i_thParameter-nbColorParameter,1);
2243 
2244  // Connect pushButton to ColorDialog in callback
2245  QSignalMapper* signalMapper = new QSignalMapper(this);
2246  signalMapper->setMapping(input,input);
2247  connect(input, SIGNAL(clicked()), signalMapper, SLOT(map()));
2248  connect(signalMapper, SIGNAL(mapped(QWidget*)),this, SLOT(ChangeColorCallback(QWidget*)));
2249 
2250  isColorDialogAdded = true;
2251  isStillColorParameter = false;
2252  }
2253  } else {
2254  gridLayout->addWidget(label,i_thParameter-nbColorParameter,0);
2255  input->setToolTip(txt);
2256  gridLayout->addWidget(input,i_thParameter-nbColorParameter,1);
2257  }
2258  }
2259  // add command name in hidden value at last line position 0
2260  QLabel* name = new QLabel(QString((char*)(aCommand->GetCommandPath().data())));
2261  name->hide();
2262  gridLayout->addWidget(name,n_parameterEntry-nbColorParameter,0);
2263 
2264  QPushButton* applyButton = new QPushButton("Apply");
2265  if (!isDialog) {
2266 
2267  gridLayout->addWidget(applyButton,n_parameterEntry-nbColorParameter,1);
2268 
2269  QSignalMapper* signalMapper = new QSignalMapper(this);
2270  signalMapper->setMapping(applyButton, paramWidget);
2271  connect(applyButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
2272  connect(signalMapper, SIGNAL(mapped(QWidget*)),this, SLOT(VisParameterCallback(QWidget*)));
2273  } else {
2274  // Apply/Cancel buttons
2275 
2276  applyButton->setAutoDefault( TRUE );
2277  applyButton->setDefault( TRUE );
2278  gridLayout->addWidget(applyButton,n_parameterEntry-nbColorParameter,0);
2279 
2280  QPushButton* cancelButton = new QPushButton( tr( "&Cancel" ));
2281  cancelButton->setAutoDefault( TRUE );
2282  gridLayout->addWidget(cancelButton,n_parameterEntry-nbColorParameter,1);
2283 
2284  QSignalMapper* signalMapper = new QSignalMapper(this);
2285  signalMapper->setMapping(applyButton, paramWidget);
2286  connect(applyButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
2287  connect(signalMapper, SIGNAL(mapped(QWidget*)),this, SLOT(VisParameterCallback(QWidget*)));
2288 
2289  QWidget * parentCheck = aParent;
2290  QDialog* parentDialog = NULL;
2291  bool found = false;
2292  while ((parentCheck->parentWidget()) != NULL) {
2293  parentCheck = parentCheck->parentWidget();
2294  parentDialog = dynamic_cast<QDialog*>(parentCheck);
2295  if (parentDialog) {
2296  connect( applyButton, SIGNAL( clicked() ), parentDialog, SLOT( accept() ) );
2297  connect( cancelButton, SIGNAL( clicked() ), parentDialog, SLOT( reject() ) );
2298  found = true;
2299  }
2300  }
2301  if (!found) {
2302  return false;
2303  }
2304  }
2305 
2306  if (!aParent->layout()) {
2307  aParent->setLayout(new QVBoxLayout());
2308  }
2309  aParent->layout()->addWidget(paramWidget);
2310  }
2311 
2312  return true;
2313 }
2314 
2315 
2320 QTreeWidgetItem* G4UIQt::FindTreeItem(
2321  QTreeWidgetItem *aParent
2322 ,const QString& aCommand
2323 )
2324 {
2325  if (aParent == NULL) return NULL;
2326 
2327  // Suppress last "/"
2328  QString myCommand = aCommand;
2329 
2330  if (myCommand.lastIndexOf("/") == (myCommand.size()-1)) {
2331  myCommand = myCommand.left(myCommand.size()-1);
2332  }
2333 
2334  if (GetLongCommandPath(aParent) == myCommand)
2335  return aParent;
2336 
2337  QTreeWidgetItem * tmp = NULL;
2338  for (int a=0;a<aParent->childCount();a++) {
2339  if (!tmp)
2340  tmp = FindTreeItem(aParent->child(a),myCommand);
2341  }
2342  return tmp;
2343 }
2344 
2345 
2346 
2354 QString G4UIQt::GetCommandList (
2355  const G4UIcommand *aCommand
2356 )
2357 {
2358 
2359  QString txt ="";
2360  if (aCommand == NULL)
2361  return txt;
2362 
2363  G4String commandPath = aCommand->GetCommandPath();
2364  G4String rangeString = aCommand->GetRange();
2365  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
2366  G4int n_parameterEntry = aCommand->GetParameterEntries();
2367 
2368  if ((commandPath == "") &&
2369  (rangeString == "") &&
2370  (n_guidanceEntry == 0) &&
2371  (n_parameterEntry == 0)) {
2372  return txt;
2373  }
2374 
2375  if((commandPath.length()-1)!='/') {
2376  txt += "Command " + QString((char*)(commandPath).data()) + "\n";
2377  }
2378  txt += "Guidance :\n";
2379 
2380  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
2381  txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
2382  }
2383  if( ! rangeString.isNull() ) {
2384  txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n";
2385  }
2386  if( n_parameterEntry > 0 ) {
2387  G4UIparameter *param;
2388 
2389  // Re-implementation of G4UIparameter.cc
2390 
2391  for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
2392  param = aCommand->GetParameter(i_thParameter);
2393  txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
2394  if( ! param->GetParameterGuidance().isNull() )
2395  txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
2396  txt += " Parameter type : " + QString(QChar(param->GetParameterType())) + "\n";
2397  if(param->IsOmittable()){
2398  txt += " Omittable : True\n";
2399  } else {
2400  txt += " Omittable : False\n";
2401  }
2402  if( param->GetCurrentAsDefault() ) {
2403  txt += " Default value : taken from the current value\n";
2404  } else if( ! param->GetDefaultValue().isNull() ) {
2405  txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n";
2406  }
2407  if( ! param->GetParameterRange().isNull() ) {
2408  txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
2409  }
2410  if( ! param->GetParameterCandidates().isNull() ) {
2411  txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
2412  }
2413  }
2414  }
2415  return txt;
2416 }
2417 
2418 
2424 G4bool G4UIQt::IsGUICommand(
2425  const G4UIcommand *aCommand
2426 )
2427 {
2428  if (aCommand == NULL)
2429  return false;
2430 
2431  G4int n_parameterEntry = aCommand->GetParameterEntries();
2432 
2433  if( n_parameterEntry > 0 ) {
2434  G4UIparameter *param;
2435 
2436  // Re-implementation of G4UIparameter.cc
2437 
2438  for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
2439  param = aCommand->GetParameter(i_thParameter);
2440  if (QString(QChar(param->GetParameterType())) == "d") {
2441  return true;
2442  }
2443  if (QString(QChar(param->GetParameterType())) == "b") {
2444  return true;
2445  }
2446  if (QString(QChar(param->GetParameterType())) == "i") {
2447  return true;
2448  }
2449  if (QString(QChar(param->GetParameterType())) == "s") {
2450  return true;
2451  }
2452  }
2453  }
2454  return false;
2455 }
2456 
2457 
2460 G4bool G4UIQt::GetHelpChoice(
2461  G4int&
2462 )
2463 {
2464  return true;
2465 }
2466 
2467 
2475 bool G4UIQt::eventFilter( // Should stay with a minuscule eventFilter because of Qt
2476  QObject *aObj
2477 ,QEvent *aEvent
2478 )
2479 {
2480  bool moveCommandCursor = false;
2481  if (aObj == NULL) return false;
2482  if (aEvent == NULL) return false;
2483 
2484  if (aObj == fHistoryTBTableList) {
2485  if (aEvent->type() == QEvent::KeyPress) {
2486  fCommandArea->setFocus();
2487  }
2488  }
2489  if (aObj == fCommandArea) {
2490  if (aEvent->type() == QEvent::KeyPress) {
2491  QKeyEvent *e = static_cast<QKeyEvent*>(aEvent);
2492  if ((e->key() == (Qt::Key_Down)) ||
2493  (e->key() == (Qt::Key_PageDown)) ||
2494  (e->key() == (Qt::Key_Up)) ||
2495  (e->key() == (Qt::Key_PageUp))) {
2496  int selection = fHistoryTBTableList->currentRow();
2497  if (fHistoryTBTableList->count()) {
2498  if (selection == -1) {
2499  selection = fHistoryTBTableList->count()-1;
2500  } else {
2501  if (e->key() == (Qt::Key_Down)) {
2502  if (selection <(fHistoryTBTableList->count()-1))
2503  selection++;
2504  } else if (e->key() == (Qt::Key_PageDown)) {
2505  selection = fHistoryTBTableList->count()-1;
2506  } else if (e->key() == (Qt::Key_Up)) {
2507  if (selection >0)
2508  selection --;
2509  } else if (e->key() == (Qt::Key_PageUp)) {
2510  selection = 0;
2511  }
2512  }
2513  fHistoryTBTableList->clearSelection();
2514 #if QT_VERSION < 0x040202
2515  fHistoryTBTableList->setItemSelected(fHistoryTBTableList->item(selection),true);
2516 #else
2517  fHistoryTBTableList->item(selection)->setSelected(true);
2518 #endif
2519  fHistoryTBTableList->setCurrentItem(fHistoryTBTableList->item(selection));
2520  }
2521  moveCommandCursor = true;
2522  } else if (e->key() == (Qt::Key_Tab)) {
2523  G4String ss = Complete(fCommandArea->text().toStdString().c_str());
2524  fCommandArea->setText((char*)(ss.data()));
2525 
2526  // do not pass by parent, it will disable widget tab focus !
2527  return true;
2528  // L.Garnier : MetaModifier is CTRL for MAC, but I don't want to put a MAC
2529  // specific #ifdef
2530  } else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_A)) {
2531  fCommandArea->home(false);
2532  return true;
2533  } else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_E)) {
2534  fCommandArea->end(false);
2535  return true;
2536  }
2537  }
2538  }
2539  bool res= false;
2540  // change cursor position if needed
2541  if (moveCommandCursor == true) {
2542  fCommandArea->setCursorPosition ( fCommandArea->text().length() );
2543  fCommandArea->setCursorPosition (4);
2544  } else {
2545  // pass the event on to the parent class
2546  res = QObject::eventFilter(aObj, aEvent);
2547  }
2548  return res;
2549 }
2550 
2551 
2552 
2553 
2554 /***************************************************************************/
2555 //
2556 // SLOTS DEFINITIONS
2557 //
2558 /***************************************************************************/
2559 
2562 void G4UIQt::ShowHelpCallback (
2563 )
2564 {
2565  TerminalHelp("");
2566 }
2567 
2568 
2571 void G4UIQt::ClearButtonCallback (
2572 )
2573 {
2574  fCoutTBTextArea->clear();
2575  fG4cout.clear();
2576 }
2577 
2580 void G4UIQt::ExitSession (
2581 )
2582 {
2583  SessionTerminate();
2584 }
2585 
2586 void G4UIQt::ExitHelp(
2587 ) const
2588 {
2589 }
2590 
2594 void G4UIQt::CommandEnteredCallback (
2595 )
2596 {
2597  // split by any new line character
2598  QStringList list = fCommandArea->text().split(QRegExp("[\r\n]"),QString::SkipEmptyParts);
2599 
2600  // Apply for all commands
2601  for (int a=0; a< list.size(); a++) {
2602  QString txt (list[a].trimmed());
2603  if (txt != "") {
2604  fHistoryTBTableList->addItem(txt);
2605  fHistoryTBTableList->clearSelection();
2606  fHistoryTBTableList->setCurrentItem(NULL);
2607  fCommandArea->setText("");
2608  G4Qt* interactorManager = G4Qt::getInstance ();
2609  if (interactorManager) {
2610  interactorManager->FlushAndWaitExecution();
2611  }
2612 
2613  G4String command = txt.toStdString().c_str();
2614  if (command(0,4) != "help") {
2615  ApplyShellCommand (command,exitSession,exitPause);
2616  } else {
2617  ActivateCommand(command);
2618  }
2619  }
2620  }
2621 
2622  // Rebuild help tree
2623  FillHelpTree();
2624 
2625  if(exitSession==true)
2626  SessionTerminate();
2627 }
2628 
2629 
2634 void G4UIQt::CommandEditedCallback(const QString &)
2635 {
2636  QStringList list = fCommandArea->text().split(QRegExp("[\r\n]"),QString::SkipEmptyParts);
2637 
2638  if (list.size() > 1) { // trigger ActivateCommand
2639  for (int a=0; a<list.size()-1; a++) {
2640  // set only the first part
2641  fCommandArea->setText(list[a]);
2642  // trigger callback
2643  CommandEnteredCallback();
2644  }
2645  // reset unfinished command
2646  fCommandArea->setText(list[list.size()-1]);
2647  }
2648 }
2649 
2650 
2653 void G4UIQt::VisParameterCallback(QWidget* widget){
2654  if (widget == NULL) {
2655  return;
2656  }
2657 
2658  // Look in all the Grid layout, but only column 1 (0 is the parameter name)
2659  QGridLayout* grid = dynamic_cast<QGridLayout*>(widget->layout());
2660  if (grid == 0) {
2661  return;
2662  }
2663  QString command;
2664 #if QT_VERSION < 0x040400
2665  QWidget* name = grid->itemAt(grid->columnCount()*(grid->rowCount()-2))->widget();
2666 #else
2667  QWidget* name = grid->itemAtPosition(grid->rowCount()-1,0)->widget();
2668 #endif
2669  if (dynamic_cast<QLabel*>(name) == 0) {
2670  return;
2671  }
2672  command += (dynamic_cast<QLabel*>(name))->text()+" ";
2673 
2674  for (int a=0;a<grid->rowCount()-1; a++) {
2675 #if QT_VERSION < 0x040400
2676  QWidget* widgetTmp = grid->itemAt(a*grid->columnCount()+1)->widget();
2677 #else
2678  QWidget* widgetTmp = grid->itemAtPosition(a,1)->widget();
2679 #endif
2680 
2681  // 4 kind of widgets : QLineEdit / QComboBox / radioButtonsGroup / QPushButton (color chooser)
2682  if (widgetTmp != NULL) {
2683 
2684  if (dynamic_cast<QLineEdit*>(widgetTmp) != 0) {
2685  command += (dynamic_cast<QLineEdit*>(widgetTmp))->text()+" ";
2686 
2687  } else if (dynamic_cast<QComboBox*>(widgetTmp) != 0){
2688  command += (dynamic_cast<QComboBox*>(widgetTmp))->itemText((dynamic_cast<QComboBox*>(widgetTmp))->currentIndex())+" ";
2689 
2690  // Color chooser
2691  } else if (dynamic_cast<QPushButton*>(widgetTmp) != 0){
2692  command += widgetTmp->accessibleName()+" ";
2693 
2694  // Check for Button group
2695  } else if (dynamic_cast<QWidget*>(widgetTmp) != 0){
2696  if (widgetTmp->layout()->count() > 0){
2697  if (dynamic_cast<QRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()) != 0) {
2698  QAbstractButton * checked = (dynamic_cast<QRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()))->group()->checkedButton();
2699  if (checked != 0) {
2700  command += (dynamic_cast<QRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()))->group()->checkedButton()->text()+" ";
2701  }
2702  }
2703  }
2704 
2705  }
2706  }
2707  }
2708  if (command != "") {
2710  if(UI != NULL) {
2711  UI->ApplyCommand(command.toStdString().c_str());
2712  }
2713  }
2714 }
2715 
2716 
2722 void G4UIQt::ButtonCallback (
2723  const QString& aCommand
2724 )
2725 {
2726  G4String ss = G4String(aCommand.toStdString().c_str());
2727  ss = ss.strip(G4String::leading);
2728 
2730  if(UI==NULL) return;
2731  G4UIcommandTree * treeTop = UI->GetTree();
2732 
2733  G4UIcommand* command = treeTop->FindPath(ss);
2734 
2735  if (command) {
2736  // if is GUI, then open a dialog
2737  if (IsGUICommand(command)) {
2738  QDialog* menuParameterDialog = new QDialog();
2739 
2740  if (CreateVisCommandGroupAndToolBox(command,menuParameterDialog,1,true)) {
2741  menuParameterDialog->setWindowTitle (aCommand);
2742  menuParameterDialog->setSizePolicy (QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
2743 
2744  // exec this dialog, apply the command automaticaly, and return
2745  menuParameterDialog->exec();
2746  return;
2747  }
2748  }
2749  }
2750 
2751  ApplyShellCommand(ss,exitSession,exitPause);
2752 
2753  // Rebuild help tree
2754  FillHelpTree();
2755 
2756  if(exitSession==true)
2757  SessionTerminate();
2758 }
2759 
2760 
2761 
2764 void G4UIQt::HelpTreeClicCallback (
2765 )
2766 {
2767  QTreeWidgetItem* item = NULL;
2768  if (!fHelpTreeWidget)
2769  return ;
2770 
2771  if (!fHelpArea)
2772  return;
2773 
2774  QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
2775  if (list.isEmpty())
2776  return;
2777  item = list.first();
2778  if (!item)
2779  return;
2780 
2782  if(UI==NULL) return;
2783  G4UIcommandTree * treeTop = UI->GetTree();
2784 
2785  std::string itemText = GetLongCommandPath(item).toStdString();
2786 
2787  // check if it is a command path
2788  if (item->childCount() > 0) {
2789  itemText +="/";
2790  }
2791  G4UIcommand* command = treeTop->FindPath(itemText.c_str());
2792 
2793  if (command) {
2794  #if QT_VERSION < 0x040200
2795  fHelpArea->clear();
2796  fHelpArea->append(GetCommandList(command));
2797  #else
2798  fHelpArea->setText(GetCommandList(command));
2799  #endif
2800  } else { // this is a command
2801  G4UIcommandTree* path = treeTop->FindCommandTree(itemText.c_str());
2802  if ( path) {
2803  // this is not a command, this is a sub directory
2804  // We display the Title
2805  #if QT_VERSION < 0x040200
2806  fHelpArea->clear();
2807  fHelpArea->append(path->GetTitle().data());
2808  #else
2809  fHelpArea->setText(path->GetTitle().data());
2810  #endif
2811  }
2812  }
2813 }
2814 
2817 void G4UIQt::HelpTreeDoubleClicCallback (
2818 )
2819 {
2820  HelpTreeClicCallback();
2821 
2822  QTreeWidgetItem* item = NULL;
2823  if (!fHelpTreeWidget)
2824  return ;
2825 
2826  if (!fHelpArea)
2827  return;
2828 
2829  QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
2830  if (list.isEmpty())
2831  return;
2832  item = list.first();
2833  if (!item)
2834  return;
2835 
2836  fCommandArea->clear();
2837  fCommandArea->setText(GetLongCommandPath(item));
2838 }
2839 
2840 
2844 void G4UIQt::CommandHistoryCallback(
2845 )
2846 {
2847  QListWidgetItem* item = NULL;
2848  if (!fHistoryTBTableList)
2849  return ;
2850 
2851 
2852  QList<QListWidgetItem *> list =fHistoryTBTableList->selectedItems();
2853  if (list.isEmpty())
2854  return;
2855  item = list.first();
2856  if (!item)
2857  return;
2858  fCommandArea->setText(item->text());
2859 }
2860 
2861 
2862 void G4UIQt::CoutFilterCallback(
2863 const QString & text) {
2864 
2865  QStringList result = fG4cout.filter(text);
2866  fCoutTBTextArea->setPlainText(result.join("\n"));
2867 
2868  fCoutTBTextArea->repaint();
2869  fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
2870 
2871  }
2872 
2877 void G4UIQt::LookForHelpStringCallback(
2878 )
2879 {
2880  QString searchText = fHelpLine->text();
2881 
2882 #if QT_VERSION < 0x040200
2883  fHelpArea->clear();
2884 #else
2885  fHelpArea->setText("");
2886 #endif
2887  if (searchText =="") {
2888  // clear old help tree
2889  fHelpTreeWidget->clear();
2890 
2891  FillHelpTree();
2892 
2893  return;
2894  } else {
2895  OpenHelpTreeOnCommand(searchText);
2896  }
2897 }
2898 
2899 
2900 void G4UIQt::OpenHelpTreeOnCommand(
2901  const QString & searchText
2902 )
2903 {
2904  // the help tree
2906  if(UI==NULL) return;
2907  G4UIcommandTree * treeTop = UI->GetTree();
2908 
2909  G4int treeSize = treeTop->GetTreeEntry();
2910 
2911  // clear old help tree
2912  fHelpTreeWidget->clear();
2913 
2914  // look for new items
2915 
2916  int tmp = 0;
2917 
2918  QMap<int,QString> commandResultMap;
2919  QMap<int,QString> commandChildResultMap;
2920 
2921  for (int a=0;a<treeSize;a++) {
2922  G4UIcommand* command = treeTop->FindPath(treeTop->GetTree(a+1)->GetPathName().data());
2923  tmp = GetCommandList (command).count(searchText,Qt::CaseInsensitive);
2924  if (tmp >0) {
2925  commandResultMap.insertMulti(tmp,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()));
2926  }
2927  // look for childs
2928  commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a+1),searchText);
2929  // insert new childs
2930  if (!commandChildResultMap.empty()) {
2931  QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
2932  while (i != commandChildResultMap.constEnd()) {
2933  commandResultMap.insertMulti(i.key(),i.value());
2934  i++;
2935  }
2936  commandChildResultMap.clear();
2937  }
2938  }
2939 
2940  // build new help tree
2941  fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
2942  fHelpTreeWidget->setColumnCount(2);
2943  QStringList labels;
2944  labels << QString("Command") << QString("Match");
2945  fHelpTreeWidget->setHeaderLabels(labels);
2946 
2947  if (commandResultMap.empty()) {
2948 #if QT_VERSION < 0x040200
2949  fHelpArea->clear();
2950  fHelpArea->append("No match found");
2951 #else
2952  fHelpArea->setText("No match found");
2953 #endif
2954  return;
2955  }
2956 
2957  QMap<int,QString>::const_iterator i = commandResultMap.constEnd();
2958  i--;
2959  // 10 maximum progress values
2960  float multValue = 10.0/(float)(i.key());
2961  QString progressChar = "|";
2962  QString progressStr = "|";
2963 
2964  QTreeWidgetItem * newItem;
2965  bool end = false;
2966  while (!end) {
2967  if (i == commandResultMap.constBegin()) {
2968  end = true;
2969  }
2970  for(int a=0;a<int(i.key()*multValue);a++) {
2971  progressStr += progressChar;
2972  }
2973  newItem = new QTreeWidgetItem();
2974  QString commandStr = i.value().trimmed();
2975 
2976  if (commandStr.indexOf("/") == 0) {
2977  commandStr = commandStr.right(commandStr.size()-1);
2978  }
2979 
2980  newItem->setText(0,commandStr);
2981  newItem->setText(1,progressStr);
2982  fHelpTreeWidget->addTopLevelItem(newItem);
2983 #if QT_VERSION < 0x040200
2984 #else
2985  newItem->setForeground ( 1, QBrush(Qt::blue) );
2986 #endif
2987  progressStr = "|";
2988  i--;
2989  }
2990  fHelpTreeWidget->resizeColumnToContents (0);
2991  fHelpTreeWidget->sortItems(1,Qt::DescendingOrder);
2992  // fHelpTreeWidget->setColumnWidth(1,10);//resizeColumnToContents (1);
2993 }
2994 
2995 
2996 
2997 
2998 QMap<int,QString> G4UIQt::LookForHelpStringInChildTree(
2999  G4UIcommandTree *aCommandTree
3000 ,const QString & text
3001  )
3002 {
3003  QMap<int,QString> commandResultMap;
3004  if (aCommandTree == NULL) return commandResultMap;
3005 
3006 
3007  // Get the Sub directories
3008  int tmp = 0;
3009  QMap<int,QString> commandChildResultMap;
3010 
3011  for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
3012  const G4UIcommand* command = aCommandTree->GetGuidance();
3013  tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
3014  if (tmp >0) {
3015  commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()));
3016  }
3017  // look for childs
3018  commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text);
3019 
3020  if (!commandChildResultMap.empty()) {
3021  // insert new childs
3022  QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
3023  while (i != commandChildResultMap.constEnd()) {
3024  commandResultMap.insertMulti(i.key(),i.value());
3025  i++;
3026  }
3027  commandChildResultMap.clear();
3028  }
3029  }
3030  // Get the Commands
3031 
3032  for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
3033  const G4UIcommand* command = aCommandTree->GetCommand(a+1);
3034  tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
3035  if (tmp >0) {
3036  commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()));
3037  }
3038 
3039  }
3040  return commandResultMap;
3041 }
3042 
3043 
3044 QString G4UIQt::GetShortCommandPath(
3045 QString commandPath
3046 )
3047 {
3048  if (commandPath.indexOf("/") == 0) {
3049  commandPath = commandPath.right(commandPath.size()-1);
3050  }
3051 
3052  commandPath = commandPath.right(commandPath.size()-commandPath.lastIndexOf("/",-2)-1);
3053 
3054  if (commandPath.lastIndexOf("/") == (commandPath.size()-1)) {
3055  commandPath = commandPath.left(commandPath.size()-1);
3056  }
3057 
3058  return commandPath;
3059 }
3060 
3061 
3062 QString G4UIQt::GetLongCommandPath(
3063  QTreeWidgetItem* item
3064 )
3065 {
3066  if (item == NULL) return "";
3067 
3068  // rebuild path:
3069  QString itemText = "";
3070  itemText = item->text(0);
3071 
3072  while (item->parent() != NULL) {
3073  itemText = item->parent()->text(0)+"/"+itemText;
3074  item = item->parent();
3075  }
3076  itemText = "/"+itemText;
3077 
3078  return itemText;
3079 }
3080 
3081 
3082 void G4UIQt::ChangeColorCallback(QWidget* widget) {
3083  if (widget == NULL) {
3084  return;
3085  }
3086 
3087  QPushButton* button = dynamic_cast<QPushButton*>(widget);
3088  if (button == 0) {
3089  return;
3090  }
3091  QString value = button->accessibleName();
3092 
3093  QColor old;
3094  old.setRgbF(value.section(" ",0,1).toDouble(),
3095  value.section(" ",1,2).toDouble(),
3096  value.section(" ",2,3).toDouble());
3097 #if QT_VERSION < 0x040500
3098  bool a;
3099  QColor color = QColor(QColorDialog::getRgba (old.rgba(),&a,fUITabWidget));
3100 #else
3101  QColor color = QColorDialog::getColor(old,
3102  fUITabWidget,
3103  "Change color",
3104  QColorDialog::ShowAlphaChannel);
3105 #endif
3106 
3107 
3108  if (color.isValid()) {
3109  // rebuild the widget icon
3110  QPixmap pixmap = QPixmap(QSize(16, 16));
3111  pixmap.fill (color);
3112  QPainter painter(&pixmap);
3113  painter.setPen(Qt::black);
3114  painter.drawRect(0,0,15,15); // Draw contour
3115 
3116  button->setAccessibleName(QString::number(color.redF())+" "+
3117  QString::number(color.greenF())+" "+
3118  QString::number(color.blueF())+" "
3119  );
3120  button->setIcon(pixmap);
3121 
3122 
3123  }
3124 }
3125 
3126 
3127 void G4UIQt::ChangeCursorStyle(const QString& action) {
3128 
3129  // Theses actions should be in the app toolbar
3130 
3131  fMoveSelected = true;
3132  fPickSelected = true;
3133  fRotateSelected = true;
3134  fZoomInSelected = true;
3135  fZoomOutSelected = true;
3136 
3137  if (fToolbarApp == NULL) return;
3138  QList<QAction *> list = fToolbarApp->actions ();
3139  for (int i = 0; i < list.size(); ++i) {
3140  if (list.at(i)->data().toString () == action) {
3141  list.at(i)->setChecked(TRUE);
3142  } else if (list.at(i)->data().toString () == "move") {
3143  fMoveSelected = false;
3144  list.at(i)->setChecked(FALSE);
3145  } else if (list.at(i)->data().toString () == "pick") {
3146  fPickSelected = false;
3147  list.at(i)->setChecked(FALSE);
3148  } else if (list.at(i)->data().toString () == "rotate") {
3149  fRotateSelected = false;
3150  list.at(i)->setChecked(FALSE);
3151  } else if (list.at(i)->data().toString () == "zoom_in") {
3152  fZoomInSelected = false;
3153  list.at(i)->setChecked(FALSE);
3154  } else if (list.at(i)->data().toString () == "zoom_out") {
3155  fZoomOutSelected = false;
3156  list.at(i)->setChecked(FALSE);
3157  }
3158  }
3159  // FIXME : Should connect this to Vis
3160 }
3161 
3162 
3163 /* A little bit like "void G4OpenGLQtViewer::toggleDrawingAction(int aAction)"
3164  But for all viewers, not only Qt
3165 
3166 FIXME : Should be a feedback when changing viewer !
3167 
3168  */
3169 void G4UIQt::ChangeSurfaceStyle(const QString& action) {
3170 
3171  // Theses actions should be in the app toolbar
3172 
3173  if (fToolbarApp == NULL) return;
3174  QList<QAction *> list = fToolbarApp->actions ();
3175  for (int i = 0; i < list.size(); ++i) {
3176  if (list.at(i)->data().toString () == action) {
3177  list.at(i)->setChecked(TRUE);
3178  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
3179  list.at(i)->setChecked(FALSE);
3180  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3181  list.at(i)->setChecked(FALSE);
3182  } else if (list.at(i)->data().toString () == "solid") {
3183  list.at(i)->setChecked(FALSE);
3184  } else if (list.at(i)->data().toString () == "wireframe") {
3185  list.at(i)->setChecked(FALSE);
3186  }
3187  }
3188  // FIXME : Should connect this to Vis
3189 
3190  if (action == "hidden_line_removal") {
3191  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style w");
3192  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 1");
3193 
3194  } else if (action == "hidden_line_and_surface_removal") {
3195  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style s");
3196  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 1");
3197 
3198  } else if (action == "solid") {
3199  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style s");
3200  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 0");
3201 
3202  } else if (action == "wireframe") {
3203  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style w");
3204  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 0");
3205  }
3206 }
3207 
3208 
3209 void G4UIQt::OpenIconCallback(const QString& aParam) {
3210 
3211  QString aCommand = aParam.left(aParam.indexOf(fStringSeparator));
3212  QString aLabel = aParam.mid(aParam.indexOf(fStringSeparator)+fStringSeparator.length());
3213 
3214  QString nomFich = QFileDialog::getOpenFileName(fMainWindow, aLabel, fLastOpenPath, "Macro files (*.mac)");
3215  if (nomFich != "") {
3216  G4UImanager::GetUIpointer()->ApplyCommand((QString(aCommand)+ QString(" ")+ nomFich).toStdString().c_str());
3217  QDir dir;
3218  fLastOpenPath = dir.absoluteFilePath(nomFich);
3219  }
3220 }
3221 
3222 
3223 void G4UIQt::SaveIconCallback(const QString& aParam) {
3224 
3225  QString aCommand = aParam.left(aParam.indexOf(fStringSeparator));
3226  QString aLabel = aParam.mid(aParam.indexOf(fStringSeparator)+fStringSeparator.length());
3227 
3228  QString nomFich = QFileDialog::getSaveFileName(fMainWindow, aLabel, fLastOpenPath, "Macro files (*.mac)");
3229  if (nomFich != "") {
3230  G4UImanager::GetUIpointer()->ApplyCommand((QString(aCommand)+ QString(" ")+nomFich).toStdString().c_str());
3231  QDir dir;
3232  fLastOpenPath = dir.absoluteFilePath(nomFich);
3233  }
3234 }
3235 
3236 
3237 
3238 void G4UIQt::ChangePerspectiveOrtho(const QString& action) {
3239 
3240  // Theses actions should be in the app toolbar
3241 
3242  if (fToolbarApp == NULL) return;
3243  QList<QAction *> list = fToolbarApp->actions ();
3244  QString checked = "";
3245  for (int i = 0; i < list.size(); ++i) {
3246  if (list.at(i)->data().toString () == action) {
3247  list.at(i)->setChecked(TRUE);
3248  checked = list.at(i)->data().toString ();
3249  } else if (list.at(i)->data().toString () == "persepective") {
3250  list.at(i)->setChecked(FALSE);
3251  } else if (list.at(i)->data().toString () == "ortho") {
3252  list.at(i)->setChecked(FALSE);
3253  }
3254  }
3255 
3256  if ((action == "ortho") && (checked == "ortho")) {
3257  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/projection o");
3258  } else if ((action == "perspective") && (checked == "perspective")) {
3259  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/projection p");
3260  }
3261 }
3262 
3263 
3264 
3265 void G4UIQt::SetIconMoveSelected() {
3266  // Theses actions should be in the app toolbar
3267  fMoveSelected = true;
3268  fRotateSelected = false;
3269  fPickSelected = false;
3270  fZoomInSelected = false;
3271  fZoomOutSelected = false;
3272 
3273  if (fToolbarApp == NULL) return;
3274  QList<QAction *> list = fToolbarApp->actions ();
3275  for (int i = 0; i < list.size(); ++i) {
3276  if (list.at(i)->data().toString () == "move") {
3277  list.at(i)->setChecked(TRUE);
3278  } else if (list.at(i)->data().toString () == "rotate") {
3279  list.at(i)->setChecked(FALSE);
3280  } else if (list.at(i)->data().toString () == "pick") {
3281  list.at(i)->setChecked(FALSE);
3282  } else if (list.at(i)->data().toString () == "zoom_in") {
3283  list.at(i)->setChecked(FALSE);
3284  } else if (list.at(i)->data().toString () == "zoom_out") {
3285  list.at(i)->setChecked(FALSE);
3286  }
3287  }
3288 }
3289 
3290 
3291 void G4UIQt::SetIconRotateSelected() {
3292  // Theses actions should be in the app toolbar
3293  fRotateSelected = true;
3294  fMoveSelected = false;
3295  fPickSelected = false;
3296  fZoomInSelected = false;
3297  fZoomOutSelected = false;
3298 
3299  if (fToolbarApp == NULL) return;
3300  QList<QAction *> list = fToolbarApp->actions ();
3301  for (int i = 0; i < list.size(); ++i) {
3302  if (list.at(i)->data().toString () == "rotate") {
3303  list.at(i)->setChecked(TRUE);
3304  } else if (list.at(i)->data().toString () == "move") {
3305  list.at(i)->setChecked(FALSE);
3306  } else if (list.at(i)->data().toString () == "pick") {
3307  list.at(i)->setChecked(FALSE);
3308  } else if (list.at(i)->data().toString () == "zoom_in") {
3309  list.at(i)->setChecked(FALSE);
3310  } else if (list.at(i)->data().toString () == "zoom_out") {
3311  list.at(i)->setChecked(FALSE);
3312  }
3313  }
3314 }
3315 
3316 
3317 void G4UIQt::SetIconPickSelected() {
3318  // Theses actions should be in the app toolbar
3319  fPickSelected = true;
3320  fMoveSelected = false;
3321  fRotateSelected = false;
3322  fZoomInSelected = false;
3323  fZoomOutSelected = false;
3324 
3325  if (fToolbarApp == NULL) return;
3326  QList<QAction *> list = fToolbarApp->actions ();
3327  for (int i = 0; i < list.size(); ++i) {
3328  if (list.at(i)->data().toString () == "pick") {
3329  list.at(i)->setChecked(TRUE);
3330  } else if (list.at(i)->data().toString () == "move") {
3331  list.at(i)->setChecked(FALSE);
3332  } else if (list.at(i)->data().toString () == "rotate") {
3333  list.at(i)->setChecked(FALSE);
3334  } else if (list.at(i)->data().toString () == "zoom_in") {
3335  list.at(i)->setChecked(FALSE);
3336  } else if (list.at(i)->data().toString () == "zoom_out") {
3337  list.at(i)->setChecked(FALSE);
3338  }
3339  }
3340 }
3341 
3342 
3343 void G4UIQt::SetIconZoomInSelected() {
3344  // Theses actions should be in the app toolbar
3345  fZoomInSelected = true;
3346  fMoveSelected = false;
3347  fRotateSelected = false;
3348  fPickSelected = false;
3349  fZoomOutSelected = false;
3350 
3351  if (fToolbarApp == NULL) return;
3352  QList<QAction *> list = fToolbarApp->actions ();
3353  for (int i = 0; i < list.size(); ++i) {
3354  if (list.at(i)->data().toString () == "zoom_in") {
3355  list.at(i)->setChecked(TRUE);
3356  } else if (list.at(i)->data().toString () == "move") {
3357  list.at(i)->setChecked(FALSE);
3358  } else if (list.at(i)->data().toString () == "rotate") {
3359  list.at(i)->setChecked(FALSE);
3360  } else if (list.at(i)->data().toString () == "pick") {
3361  list.at(i)->setChecked(FALSE);
3362  } else if (list.at(i)->data().toString () == "zoom_out") {
3363  list.at(i)->setChecked(FALSE);
3364  }
3365  }
3366 }
3367 
3368 
3369 void G4UIQt::SetIconZoomOutSelected() {
3370  // Theses actions should be in the app toolbar
3371  fZoomOutSelected = true;
3372  fMoveSelected = false;
3373  fRotateSelected = false;
3374  fPickSelected = false;
3375  fZoomInSelected = false;
3376 
3377  if (fToolbarApp == NULL) return;
3378  QList<QAction *> list = fToolbarApp->actions ();
3379  for (int i = 0; i < list.size(); ++i) {
3380  if (list.at(i)->data().toString () == "zoom_out") {
3381  list.at(i)->setChecked(TRUE);
3382  } else if (list.at(i)->data().toString () == "move") {
3383  list.at(i)->setChecked(FALSE);
3384  } else if (list.at(i)->data().toString () == "rotate") {
3385  list.at(i)->setChecked(FALSE);
3386  } else if (list.at(i)->data().toString () == "pick") {
3387  list.at(i)->setChecked(FALSE);
3388  } else if (list.at(i)->data().toString () == "zoom_in") {
3389  list.at(i)->setChecked(FALSE);
3390  }
3391  }
3392 }
3393 
3394 
3395 void G4UIQt::SetIconSolidSelected() {
3396  // Theses actions should be in the app toolbar
3397 
3398  if (fToolbarApp == NULL) return;
3399  QList<QAction *> list = fToolbarApp->actions ();
3400  for (int i = 0; i < list.size(); ++i) {
3401  if (list.at(i)->data().toString () == "solid") {
3402  list.at(i)->setChecked(TRUE);
3403  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
3404  list.at(i)->setChecked(FALSE);
3405  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3406  list.at(i)->setChecked(FALSE);
3407  } else if (list.at(i)->data().toString () == "wireframe") {
3408  list.at(i)->setChecked(FALSE);
3409  }
3410  }
3411 }
3412 
3413 
3414 void G4UIQt::SetIconWireframeSelected() {
3415  // Theses actions should be in the app toolbar
3416 
3417  if (fToolbarApp == NULL) return;
3418  QList<QAction *> list = fToolbarApp->actions ();
3419  for (int i = 0; i < list.size(); ++i) {
3420  if (list.at(i)->data().toString () == "wireframe") {
3421  list.at(i)->setChecked(TRUE);
3422  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
3423  list.at(i)->setChecked(FALSE);
3424  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3425  list.at(i)->setChecked(FALSE);
3426  } else if (list.at(i)->data().toString () == "solid") {
3427  list.at(i)->setChecked(FALSE);
3428  }
3429  }
3430 }
3431 
3432 
3433 void G4UIQt::SetIconHLRSelected() {
3434  // Theses actions should be in the app toolbar
3435 
3436  if (fToolbarApp == NULL) return;
3437  QList<QAction *> list = fToolbarApp->actions ();
3438  for (int i = 0; i < list.size(); ++i) {
3439  if (list.at(i)->data().toString () == "hidden_line_removal") {
3440  list.at(i)->setChecked(TRUE);
3441  } else if (list.at(i)->data().toString () == "solid") {
3442  list.at(i)->setChecked(FALSE);
3443  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3444  list.at(i)->setChecked(FALSE);
3445  } else if (list.at(i)->data().toString () == "wireframe") {
3446  list.at(i)->setChecked(FALSE);
3447  }
3448  }
3449 }
3450 
3451 
3452 void G4UIQt::SetIconHLHSRSelected() {
3453  // Theses actions should be in the app toolbar
3454 
3455  if (fToolbarApp == NULL) return;
3456  QList<QAction *> list = fToolbarApp->actions ();
3457  for (int i = 0; i < list.size(); ++i) {
3458  if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3459  list.at(i)->setChecked(TRUE);
3460  } else if (list.at(i)->data().toString () == "solid") {
3461  list.at(i)->setChecked(FALSE);
3462  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
3463  list.at(i)->setChecked(FALSE);
3464  } else if (list.at(i)->data().toString () == "wireframe") {
3465  list.at(i)->setChecked(FALSE);
3466  }
3467  }
3468 }
3469 
3470 
3471 void G4UIQt::SetIconPerspectiveSelected() {
3472  // Theses actions should be in the app toolbar
3473 
3474  if (fToolbarApp == NULL) return;
3475  QList<QAction *> list = fToolbarApp->actions ();
3476  for (int i = 0; i < list.size(); ++i) {
3477  if (list.at(i)->data().toString () == "perspective") {
3478  list.at(i)->setChecked(TRUE);
3479  } else if (list.at(i)->data().toString () == "ortho") {
3480  list.at(i)->setChecked(FALSE);
3481  }
3482  }
3483 }
3484 
3485 
3486 
3487 void G4UIQt::SetIconOrthoSelected() {
3488  // Theses actions should be in the app toolbar
3489 
3490  if (fToolbarApp == NULL) return;
3491  QList<QAction *> list = fToolbarApp->actions ();
3492  for (int i = 0; i < list.size(); ++i) {
3493  if (list.at(i)->data().toString () == "ortho") {
3494  list.at(i)->setChecked(TRUE);
3495  } else if (list.at(i)->data().toString () == "perspective") {
3496  list.at(i)->setChecked(FALSE);
3497  }
3498  }
3499 }
3500 
3501 
3502 
3503 G4QTabWidget::G4QTabWidget(
3504 QWidget* aParent,
3505 int sizeX,
3506 int sizeY
3507 ):QTabWidget(aParent)
3508  ,fTabSelected(false)
3509  ,fLastCreated(-1)
3510 ,fPreferedSizeX(sizeX+6) // margin left+right
3511 ,fPreferedSizeY(sizeY+58) // tab label height + margin left+right
3512 {
3513  setMinimumSize(100,100);
3514  QSizePolicy policy = QSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
3515  setSizePolicy(policy);
3516 }
3517 
3518 G4QTabWidget::G4QTabWidget(
3519 ):QTabWidget()
3520  ,fTabSelected(false)
3521  ,fLastCreated(-1)
3522 ,fPreferedSizeX(0)
3523 ,fPreferedSizeY(0)
3524 {
3525 }
3526 
3527 
3528 
3529 #if QT_VERSION < 0x040500
3530 void G4UIQt::TabCloseCallback(int){
3531 #else
3532 void G4UIQt::TabCloseCallback(int a){
3533 #endif
3534 #if QT_VERSION < 0x040500
3535 #else
3536  if (fViewerTabWidget == NULL) return;
3537 
3538  // get the address of the widget
3539  QWidget* temp = fViewerTabWidget->widget(a);
3540  // remove the tab
3541  fViewerTabWidget->removeTab (a);
3542 
3543  // delete the widget
3544  delete temp;
3545 
3546  // if there is no more tab inside the tab widget
3547  if (fViewerTabWidget->count() == 0) {
3548  if (fEmptyViewerTabLabel == NULL) {
3549  fEmptyViewerTabLabel = new QLabel("If you want to have a Viewer, please use /vis/open commands.");
3550  }
3551 
3552  fViewerTabHandleWidget->layout()->removeWidget(fViewerTabWidget);
3553 
3554  fViewerTabHandleWidget->layout()->addWidget(fEmptyViewerTabLabel);
3555 
3556  fEmptyViewerTabLabel->show();
3557  }
3558 #endif
3559 }
3560 
3561 
3562 void G4UIQt::ToolBoxActivated(int a){
3563 
3564  if (fUITabWidget->widget(a) == fHelpTBWidget) {
3565  // Rebuild the help tree
3566  FillHelpTree();
3567  } else if (fUITabWidget->widget(a) == fSceneTreeComponentsTBWidget) {
3568 #if QT_VERSION < 0x040200
3569  fSceneTreeComponentsTBWidget->show();
3570 #else
3571  fSceneTreeComponentsTBWidget->setVisible(true);
3572 #endif
3573  }
3574 }
3575 
3576 
3577 void G4QTabWidget::paintEvent(
3578 QPaintEvent *
3579 )
3580 {
3581 
3582  if (currentWidget()) {
3583 
3584  if ( isTabSelected()) {
3585 
3586  // QCoreApplication::sendPostedEvents () ;
3587 
3588  QString text = tabText (currentIndex());
3589 
3590  if (fLastCreated == -1) {
3591  QString paramSelect = QString("/vis/viewer/select ")+text;
3593  if(UI != NULL) {
3594  UI->ApplyCommand(paramSelect.toStdString().c_str());
3595  }
3596  } else {
3597  fLastCreated = -1;
3598  }
3599  setTabSelected(false);
3600  }
3601  }
3602 }
3603 
3604 #endif
G4UIcommandTree * FindCommandTree(const char *commandPath)
Float_t tmp
Definition: plot.C:37
G4String GetParameterCandidates() const
char cmd[1024]
Definition: tracer.cxx:25
const G4String & GetRange() const
Definition: G4UIcommand.hh:133
Definition: test07.cc:36
tuple a
Definition: test.py:11
Int_t index
Definition: macro.C:9
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
G4UIcommand * FindPath(const char *commandPath) const
const XML_Char * s
Definition: expat.h:262
G4String strip(G4int strip_Type=trailing, char c=' ')
G4int GetCommandEntry() const
G4String GetParameterName() const
G4UIcommand * GetCommand(G4int i)
G4int GetTreeEntry() const
G4double G4NeutronHPJENDLHEData::G4double result
const XML_Char * name
Definition: expat.h:151
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
void * G4Interactor
static G4StateManager * GetStateManager()
tuple b
Definition: test.py:12
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:591
const G4UIcommand * GetGuidance() const
char GetParameterType() const
const XML_Char int const XML_Char * value
Definition: expat.h:331
#define G4endl
Definition: G4ios.hh:61
printf("%d Experimental points found\n", nlines)
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
const XML_Char const XML_Char * data
Definition: expat.h:268
TDirectory * dir
Definition: macro.C:5
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:419