Geant4  10.01.p01
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 88937 2015-03-16 15:55:38Z 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 #include "G4MTcoutDestination.hh"
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 <qheaderview.h>
68 #include <qgroupbox.h>
69 #include <qscrollarea.h>
70 #include <qtoolbox.h>
71 #include <qradiobutton.h>
72 #include <qbuttongroup.h>
73 #include <qcombobox.h>
74 #include <qsignalmapper.h>
75 #include <qpainter.h>
76 #include <qcolordialog.h>
77 #include <qtoolbar.h>
78 #include <qfiledialog.h>
79 #include <qdesktopwidget.h>
80 #include <qtablewidget.h>
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 ,fUITabWidget(NULL)
117 ,fCoutFilter(NULL)
118 ,fHistoryTBTableList(NULL)
119 ,fHelpTreeWidget(NULL)
120 ,fHelpTBWidget(NULL)
121 ,fHistoryTBWidget(NULL)
122 ,fCoutDockWidget(NULL)
123 ,fUIDockWidget(NULL)
124 ,fSceneTreeComponentsTBWidget(NULL)
125 ,fHelpLine(NULL)
126 ,fViewerTabWidget(NULL)
127 ,fCoutText("Output")
128 ,fStartPage(NULL)
129 ,fHelpVSplitter(NULL)
130 ,fParameterHelpLabel(NULL)
131 ,fParameterHelpTable(NULL)
132 ,fToolbarApp(NULL)
133 ,fToolbarUser(NULL)
134 ,fStringSeparator("__$$$@%%###__")
135 ,fLastOpenPath("")
136 ,fSearchIcon(NULL)
137 ,fClearIcon(NULL)
138 #ifdef G4MULTITHREADED
139 ,fThreadsFilterComboBox(NULL)
140 #endif
141 ,fDefaultViewerFirstPageHTMLText("")
142 ,fMoveSelected(false)
143 ,fRotateSelected(true)
144 ,fPickSelected(false)
145 ,fZoomInSelected(false)
146 ,fZoomOutSelected(false)
147 {
148 
149  G4Qt* interactorManager = G4Qt::getInstance (argc,argv,(char*)"Qt");
150  if (!(QApplication*)interactorManager->GetMainInteractor()) {
151  G4UImanager* UImanager = G4UImanager::GetUIpointer();
152  G4int verbose = UImanager->GetVerboseLevel();
153 
154  if (verbose >= 2) {
155  G4cout << "G4UIQt : Unable to init Qt. Aborted" << G4endl;
156  }
157  }
158 
160  if(UI!=NULL) UI->SetSession(this);
161  if(UI!=NULL) UI->SetG4UIWindow(this);
162 
163  // Check if already define in external app QMainWindow
164  bool found = false;
165  Q_FOREACH (QWidget *widget, QApplication::allWidgets()) {
166  if ((found== false) && (widget->inherits("QMainWindow"))) {
167  found = true;
168  }
169  }
170 
171  if (found) {
172  G4UImanager* UImanager = G4UImanager::GetUIpointer();
173  G4int verbose = UImanager->GetVerboseLevel();
174 
175  if (verbose >= 2) {
176  G4cout << "G4UIQt : Found an external App with a QMainWindow already defined. Aborted" << G4endl;
177  }
178  return ;
179  }
180  fMainWindow = new QMainWindow();
181 
182  fMainWindow->setCorner( Qt::TopLeftCorner, Qt::LeftDockWidgetArea );
183  fMainWindow->setCorner( Qt::TopRightCorner, Qt::RightDockWidgetArea );
184  fMainWindow->setCorner( Qt::BottomLeftCorner, Qt::LeftDockWidgetArea );
185  fMainWindow->setCorner( Qt::BottomRightCorner, Qt::RightDockWidgetArea );
186 
187  fMainWindow->setCentralWidget(CreateViewerWidget());
188  fMainWindow->addDockWidget(Qt::LeftDockWidgetArea, CreateUITabWidget());
189  fMainWindow->addDockWidget(Qt::BottomDockWidgetArea, CreateCoutTBWidget());
190 
191 
192 
193  if(UI!=NULL) UI->SetCoutDestination(this); // TO KEEP
194 
195  // explicitly request that cout/cerr messages from threads are ALSO propagated to the master.
196  masterG4coutDestination = this;
197 
198  fMainWindow->setWindowTitle(QFileInfo( QCoreApplication::applicationFilePath() ).fileName());
199  fMainWindow->move(QPoint(50,50));
200 
201  // force the size at be correct at the beggining
202  // because the widget is not realized yet, the size of the main window is not up to date. But
203  // we need it in order to add some viewer inside
204  fMainWindow->resize(fUIDockWidget->width()+fCoutDockWidget->width()+20,
205  fUIDockWidget->height()+fCoutDockWidget->height()+20);
206 
207  // set last focus on command line
208  fCommandArea->setFocus(Qt::TabFocusReason);
209 
210  // Allow QTextCursor to be called by another thread :
211  // http://qt-project.org/doc/qt-4.8/qmetatype.html#qRegisterMetaType
212  qRegisterMetaType<QTextCursor>("QTextCursor");
213 
214  // add some tips
215  AddTabWidget(fStartPage,"Useful tips");
216 
217  // Set not visible until session start
218  #if QT_VERSION < 0x040200
219  fMainWindow->hide();
220  #else
221  fMainWindow->setVisible(false);
222  #endif
223 }
224 
225 
226 
227 G4UIQt::~G4UIQt(
228 )
229 {
230  G4UImanager* UI = G4UImanager::GetUIpointer(); // TO KEEP
231  if(UI!=NULL) { // TO KEEP
232  UI->SetSession(NULL); // TO KEEP
233  UI->SetG4UIWindow(NULL);
234  UI->SetCoutDestination(0); // TO KEEP
235  masterG4coutDestination = 0; // set to cout when UI is deleted
236  }
237 
238  if (fMainWindow!=NULL) {
239  delete fMainWindow;
240  }
241 }
242 
245 QWidget* G4UIQt::CreateHistoryTBWidget(
246 )
247 {
248  fHistoryTBWidget = new QWidget();
249 
250  QVBoxLayout *layoutHistoryTB = new QVBoxLayout();
251  fHistoryTBTableList = new QListWidget();
252  fHistoryTBTableList->setSelectionMode(QAbstractItemView::SingleSelection);
253  connect(fHistoryTBTableList, SIGNAL(itemSelectionChanged()), SLOT(CommandHistoryCallback()));
254  fHistoryTBTableList->installEventFilter(this);
255 
256  layoutHistoryTB->addWidget(fHistoryTBTableList);
257 
258  fHistoryTBWidget->setLayout(layoutHistoryTB);
259  return fHistoryTBWidget;
260 }
261 
262 
265 QWidget* G4UIQt::CreateHelpTBWidget(
266 )
267 {
268  fHelpTBWidget = new QWidget();
269 
270  QWidget *helpWidget = new QWidget();
271  QHBoxLayout *helpLayout = new QHBoxLayout();
272  QVBoxLayout *vLayout = new QVBoxLayout();
273  fHelpVSplitter = new QSplitter(Qt::Vertical);
274  fHelpLine = new QLineEdit();
275  helpLayout->addWidget(new QLabel("Search :"));
276  helpLayout->addWidget(fHelpLine);
277  connect( fHelpLine, SIGNAL( editingFinished () ), this, SLOT( LookForHelpStringCallback() ) );
278 
279  // Create Help tree
280  FillHelpTree();
281 
282  fParameterHelpLabel = new QTextEdit();
283  fParameterHelpLabel->setReadOnly(true);
284  fParameterHelpTable = new QTableWidget();
285 
286  // Set layouts
287 
288  if (fHelpTreeWidget) {
289  fHelpVSplitter->addWidget(fHelpTreeWidget);
290  }
291  fHelpVSplitter->addWidget(fParameterHelpLabel);
292  fHelpVSplitter->addWidget(fParameterHelpTable);
293 
294  fParameterHelpLabel->setVisible(false);
295  fParameterHelpTable->setVisible(false);
296  QSizePolicy policy = QSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum);
297  policy.setVerticalStretch(4);
298  if (fHelpTreeWidget) {
299  fHelpTreeWidget->setSizePolicy(policy);
300  }
301  policy = QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Preferred);
302  policy.setVerticalStretch(1);
303  fParameterHelpLabel->setSizePolicy(policy);
304  fParameterHelpTable->setSizePolicy(policy);
305 
306  vLayout->addWidget(helpWidget);
307  vLayout->addWidget(fHelpVSplitter,1);
308  vLayout->setContentsMargins(5,5,5,5);
309 
310  helpWidget->setLayout(helpLayout);
311  fHelpTBWidget->setLayout(vLayout);
312 
313  return fHelpTBWidget;
314 }
315 
316 
319 G4UIDockWidget* G4UIQt::CreateCoutTBWidget(
320 )
321 {
322  const char * const search[] = {
323  /* columns rows colors chars-per-pixel */
324  "19 19 8 1",
325  " c #5C5C5C",
326  ". c #7D7D7D",
327  "X c #9B9B9B",
328  "o c #C3C3C3",
329  "O c None",
330  "+ c #000000",
331  "@ c #000000",
332  "# c None",
333  /* pixels */
334  "OOOOOOOOOOOOOOOOOOO",
335  "OOOOOOOOOOOOOOOOOOO",
336  "OOOOOOOo. .oOOOOOO",
337  "OOOOOOX XOOOOO",
338  "OOOOOo XOOX oOOOO",
339  "OOOOO. XOOOOX .OOOO",
340  "OOOOO OOOOOO OOOO",
341  "OOOOO OOOOOO OOOO",
342  "OOOOO. XOOOOo .OOOO",
343  "OOOOOo oOOo oOOOO",
344  "OOOOOOX XOOOO",
345  "OOOOOOOo. . XOOO",
346  "OOOOOOOOOOOOO. XOO",
347  "OOOOOOOOOOOOOO. XOO",
348  "OOOOOOOOOOOOOOOoOOO",
349  "OOOOOOOOOOOOOOOOOOO",
350  "OOOOOOOOOOOOOOOOOOO",
351  "OOOOOOOOOOOOOOOOOOO",
352  "OOOOOOOOOOOOOOOOOOO"
353  };
354 
355  const char * const clear[] = {
356  /* columns rows colors chars-per-pixel */
357  "20 20 8 1",
358  " c #020202",
359  ". c #202020",
360  "X c #2C2C2C",
361  "o c #797979",
362  "O c None",
363  "+ c #797979",
364  "@ c #797979",
365  "# c #797979",
366  /* pixels */
367  "OOOOOOOOOOOOOOOOOOOO",
368  "OOOOOOOo oOOOOOOO",
369  "OOOOOXX XXOOOOO",
370  "OOOOOOOOOOOOOOOOOOOO",
371  "OOOOOOOOOOOOOOOOOOOO",
372  "OOOO XXXXXXXXXX OOOO",
373  "OOO XOOOOOOOOOO OOO",
374  "OOOOXOooOooOooO OOOO",
375  "OOOOXOooOooOooO OOOO",
376  "OOOOXOooOooOooO OOOO",
377  "OOOOXOooOooOooO OOOO",
378  "OOOOXOooOooOooO OOOO",
379  "OOOOXOooOooOooO OOOO",
380  "OOOOXOooOooOooO OOOO",
381  "OOOOXOooOooOooO OOOO",
382  "OOOOXOooOooOooO OOOO",
383  "OOOOXOooOooOooO OOOO",
384  "OOOOXOOOOOOOOOO OOOO",
385  "OOOOOooooooooooOOOOO",
386  "OOOOOO........OOOOOO"
387  };
388 
389  fSearchIcon = new QPixmap(search);
390  fClearIcon = new QPixmap(clear);
391 
392  QWidget* coutTBWidget = new QWidget();
393 
394  QVBoxLayout *layoutCoutTB = new QVBoxLayout();
395 
396  fCoutTBTextArea = new QTextEdit();
397 
398  // set font familly and size
399  fCoutTBTextArea->setFontFamily("Courier");
400  fCoutTBTextArea->setFontPointSize(12);
401 
402  fCoutFilter = new QLineEdit();
403  fCoutFilter->setToolTip("Filter output by...");
404 
405 #if QT_VERSION > 0x050100
406  fCoutFilter->addAction(*fSearchIcon,QLineEdit::TrailingPosition);
407  fCoutFilter->setStyleSheet ("border-radius:7px;");
408 #else
409  QPushButton *coutTBFilterButton = new QPushButton();
410  coutTBFilterButton->setIcon(*fSearchIcon);
411  coutTBFilterButton->setStyleSheet ("padding-left: 0px; border:0px;");
412  fCoutFilter->setStyleSheet ("padding-right: 0px;");
413 #endif
414 
415  QPushButton *coutTBClearButton = new QPushButton();
416  coutTBClearButton->setIcon(*fClearIcon);
417  coutTBClearButton->setToolTip("Clear console output");
418  coutTBClearButton->setStyleSheet ("border-radius:7px;");
419  connect(coutTBClearButton, SIGNAL(clicked()), SLOT(ClearButtonCallback()));
420  connect(fCoutFilter, SIGNAL(textEdited ( const QString &)), SLOT(CoutFilterCallback( const QString &)));
421 
422  fCoutTBTextArea->setReadOnly(true);
423 
424  QWidget* coutButtonWidget = new QWidget();
425  QHBoxLayout* layoutCoutTBButtons = new QHBoxLayout();
426 
427 #ifdef G4MULTITHREADED
428  // add all candidates to widget
429  fThreadsFilterComboBox = new QComboBox();
430  fThreadsFilterComboBox->setInsertPolicy(QComboBox::InsertAlphabetically);
431  connect(fThreadsFilterComboBox, SIGNAL(activated(int)), this, SLOT(ThreadComboBoxCallback(int)));
432 
433  UpdateCoutThreadFilter();
434 
435  fThreadsFilterComboBox->setToolTip("Thread selection in output");
436  layoutCoutTBButtons->addWidget(new QLabel(" Threads:"));
437  layoutCoutTBButtons->addWidget(fThreadsFilterComboBox);
438 #endif
439 
440  layoutCoutTBButtons->addWidget(fCoutFilter);
441 #if QT_VERSION <= 0x050100
442  layoutCoutTBButtons->addWidget(coutTBFilterButton);
443 #endif
444  layoutCoutTBButtons->addWidget(coutTBClearButton);
445  coutButtonWidget->setLayout(layoutCoutTBButtons);
446 
447  // reduce margins
448  layoutCoutTBButtons->setContentsMargins(3,3,3,0);
449 
450  layoutCoutTB->addWidget(coutButtonWidget);
451  layoutCoutTB->addWidget(fCoutTBTextArea);
452 
453  coutTBWidget->setLayout(layoutCoutTB);
454 
455  fCoutTBTextArea->setMinimumSize(100,100);
456 
457  // Command line :
458  QWidget* commandLineWidget = new QWidget();
459  QHBoxLayout *layoutCommandLine = new QHBoxLayout();
460 
461  // fill them
462 
463  fCommandLabel = new QLabel("");
464 
465  fCommandArea = new QLineEdit();
466  fCommandArea->installEventFilter(this);
467  fCommandArea->activateWindow();
468 
469  fCommandArea->setFocusPolicy ( Qt::StrongFocus );
470  fCommandArea->setFocus(Qt::TabFocusReason);
471  fCommandArea->setToolTip("Apply command");
472 
473 
474  layoutCommandLine->addWidget(fCommandLabel);
475  layoutCommandLine->addWidget(fCommandArea);
476 
477  // Connect signal
478  connect(fCommandArea, SIGNAL(returnPressed()), SLOT(CommandEnteredCallback()));
479  connect(fCommandArea, SIGNAL(textEdited(const QString &)), SLOT(CommandEditedCallback(const QString &)));
480 
481 
482  commandLineWidget->setLayout(layoutCommandLine);
483  commandLineWidget->setMinimumSize(50,50);
484 
485  layoutCoutTB->addWidget(commandLineWidget);
486 
487  fCoutDockWidget = new G4UIDockWidget ("Output");
488  fCoutDockWidget->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
489 
490  fCoutDockWidget->setWidget(coutTBWidget);
491  return fCoutDockWidget;
492 }
493 
494 
497 QWidget* G4UIQt::CreateVisParametersTBWidget(
498 )
499 {
500  return NULL;
501 }
502 
503 
506 G4UIDockWidget* G4UIQt::CreateUITabWidget(
507 )
508 {
509  fUITabWidget = new QTabWidget();
510 
511  // the left dock
512  fUITabWidget->addTab(CreateSceneTreeComponentsTBWidget(),"Scene tree");
513  fUITabWidget->addTab(CreateHelpTBWidget(),"Help");
514  fUITabWidget->addTab(CreateHistoryTBWidget(),"History");
515  fUITabWidget->setCurrentWidget(fHelpTBWidget);
516 
517  fUITabWidget->setTabToolTip (0,"Scene component tree. Only available in Stored mode");
518  fUITabWidget->setTabToolTip (1,"Help widget");
519  fUITabWidget->setTabToolTip (2,"All commands history");
520  connect(fUITabWidget, SIGNAL(currentChanged(int)), SLOT(ToolBoxActivated(int)));
521 
522  fUIDockWidget = new G4UIDockWidget ("Scene tree, Help, History");
523  fUIDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
524 
525  fUIDockWidget->setWidget(fUITabWidget);
526 
527  return fUIDockWidget;
528 }
529 
530 
531 QWidget* G4UIQt::CreateSceneTreeComponentsTBWidget(){
532 
533  fSceneTreeComponentsTBWidget = new QTabWidget();
534 
535 #if QT_VERSION < 0x040200
536  fSceneTreeComponentsTBWidget->hide();
537 #else
538  fSceneTreeComponentsTBWidget->setVisible(false);
539 #endif
540 
541  return fSceneTreeComponentsTBWidget;
542 }
543 
544 
545 QWidget* G4UIQt::CreateViewerWidget(){
546 
547  // Set layouts
548 
549  SetStartPage(std::string("<table width='100%'><tr><td width='30%'></td><td><div ")+
550  "style='color: rgb(140, 31, 31); font-size: xx-large; font-family: Garamond, serif; padding-bottom: 0px; font-weight: normal'>Geant4: "+
551  QApplication::applicationName ().toStdString()+
552  "</div></td><td width='40%'>&nbsp;<br/><i>http://geant4.web.cern.ch/geant4/</i></td></tr></table>"+
553  "<p>&nbsp;</p>"+
554  "<div style='background:#EEEEEE;'><b>Tooltips :</b><ul>"+
555  "<li><b>Start a new viewer :</b><br />"+
556  "<i>'/vis/open/...'<br />"+
557  "For example '/vis/open OGL'</i></li>"+
558  "<li><b>Execute a macro file :</b><br />"+
559  "<i>'/control/execute my_macro_file'</i></li>"+
560  "</ul></div>"+
561 
562  "<div style='background:#EEEEEE;'><b>Documentation :</b><ul>"+
563  "<li><b>Visualization tutorial :</b><br />"+
564  "<i><a href='http://geant4.in2p3.fr/spip.php?article60&lang=en'>Geant4 Qt User Interface tutorial </a>: http://geant4.in2p3.fr/spip.php?article60&lang=en</i></li>"+
565  "<li><b>Visualisation publication :</b><br />"+
566  "<i><a href='http://www.worldscientific.com/doi/abs/10.1142/S1793962313400011'>The Geant4 Visualization System - A Multi-Driver Graphics System</b><br />, Allison, J. et al., International Journal of Modeling, Simulation, and Scientific Computing, Vol. 4, Suppl. 1 (2013) 1340001</a>:<br/> http://www.worldscientific.com/doi/abs/10.1142/S1793962313400011</i></li>"+
567  "</ul></div>"+
568 
569  "<div style='background:#EEEEEE;'><b>Getting Help :</b><ul>"+
570  "<li><b>If problems arise, try <a href='http://geant4-hn.slac.stanford.edu:5090/Geant4-HyperNews/index'>browsing the user forum</a> to see whether or not your problem has already been encountered.<br /> If it hasn't, you can post it and Geant4 developers will do their best to find a solution. This is also a good place to<br /> discuss Geant4 topics in general.</b> http://geant4-hn.slac.stanford.edu:5090/Geant4-HyperNews/index"+
571  "<li><b>Get a look at <a href='http://geant4.kek.jp/geant4/support/index.shtml'>Geant4 User support pages</a>: <i>http://geant4.kek.jp/geant4/support/index.shtml</i></b></li>"+
572  "</ul></div>"
573  );
574 
575 
576  // fill right splitter
577  if (fViewerTabWidget == NULL) {
578  fViewerTabWidget = new G4QTabWidget();
579 #if QT_VERSION < 0x040500
580 #else
581  fViewerTabWidget->setTabsClosable (true);
582 #endif
583 
584 #if QT_VERSION < 0x040200
585 #else
586  fViewerTabWidget->setUsesScrollButtons (true);
587 #endif
588 
589 #if QT_VERSION < 0x040500
590 #else
591  connect(fViewerTabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(TabCloseCallback(int)));
592 #endif
593  connect(fViewerTabWidget, SIGNAL(currentChanged ( int ) ), SLOT(UpdateTabWidget(int)));
594  }
595 
596 // set the QGLWidget size policy
597  QSizePolicy policy = QSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
598  policy.setVerticalStretch(4);
599  fViewerTabWidget->setSizePolicy(policy);
600 
601  fViewerTabWidget->setMinimumSize(40,40);
602 
603  return fViewerTabWidget;
604 }
605 
606 
609 QTabWidget* G4UIQt::GetSceneTreeComponentsTBWidget(
610 )
611 {
612  return fSceneTreeComponentsTBWidget;
613 }
614 
615 
616 
617 
620 bool G4UIQt::AddViewerTab(
621  QWidget* aWidget
622  ,std::string title
623  )
624 {
625  if (fViewerTabWidget == NULL) {
626  return false;
627  }
628  fViewerTabWidget->addTab(aWidget,title.c_str());
629 
630  return true;
631 }
632 
633 
636 bool G4UIQt::AddViewerTabFromFile(
637  std::string fileName
638  ,std::string title
639  )
640 {
641  if (fViewerTabWidget == NULL) {
642  return false;
643  }
644 
646  if(UI==NULL) return 0;
647  std::ifstream file(UI->FindMacroPath(fileName.c_str()).data());
648  if (file) {
649 
650  std::string content( (std::istreambuf_iterator<char>(file) ),
651  (std::istreambuf_iterator<char>() ) );
652 
653  QTextEdit* text = new QTextEdit();
654  text->setAcceptRichText (true);
655  text->setContentsMargins(5,5,5,5);
656  text->setText(QString("<pre>")+content.c_str()+"</pre>");
657  text->setReadOnly(true);
658  fViewerTabWidget->addTab(text,title.c_str());
659  } else {
660  return false;
661  }
662  return true;
663 }
664 
665 
669 bool G4UIQt::AddTabWidget(
670  QWidget* aWidget
671 ,QString name
672 )
673 {
674  // Special case for Qt version between 5.0 and 5.1 on Mac OSX
675  // Due to a bug in this Qt version, we can't put a OpenGL Widget inside the QTabWidget.
676  // A work around is to put it outside. Returning false will fore the wiewer to put the QGLWidget
677  // inside a new QWindow.
678 
679 #ifdef Q_OS_MAC
680  #if QT_VERSION < 0x050100
681  #if QT_VERSION >= 0x050000
682  QString message = QString(
683  "This Qt version [")+qVersion ()+"] has some issues with the OpenGL viewer.\n"+
684  "To prevent problems, you are not allowed to open a Store nor Immediate viewer.\n" +
685  "\n" +
686  "Please upgrade to Qt version >= 5.1\n";
687 
688  QMessageBox::warning(fMainWindow, tr("Warning"),
689  tr(message.toStdString().c_str()),
690  QMessageBox::Ok);
691  return false;
692  #endif
693  #endif
694 #endif
695 
696  if (fViewerTabWidget == NULL) {
697  fViewerTabWidget = new G4QTabWidget();
698 #if QT_VERSION < 0x040500
699 #else
700  fViewerTabWidget->setTabsClosable (true);
701 #endif
702 
703 #if QT_VERSION < 0x040200
704 #else
705  fViewerTabWidget->setUsesScrollButtons (true);
706 #endif
707 
708 #if QT_VERSION < 0x040500
709 #else
710  connect(fViewerTabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(TabCloseCallback(int)));
711 #endif
712  connect(fViewerTabWidget, SIGNAL(currentChanged ( int ) ), SLOT(UpdateTabWidget(int)));
713  }
714 
715  if (!aWidget) {
716  return false;
717  }
718 // Has to be added before we put it into the fViewerTabWidget widget
719  aWidget->setParent(fViewerTabWidget); // Will create in some cases widget outside
720  // of UI for a really short moment
721 
722  fViewerTabWidget->addTab(aWidget,name);
723 
724  fViewerTabWidget->setCurrentIndex(fViewerTabWidget->count()-1);
725 
726  // Set visible
727  #if QT_VERSION < 0x040200
728  fViewerTabWidget->setLastTabCreated(fViewerTabWidget->currentIndex());
729  #else
730  fViewerTabWidget->setLastTabCreated(fViewerTabWidget->currentIndex());
731  #endif
732 
733  // Not the good solution, but ensure that the help tree is correctly build when launching a viewer
734  // It should be done by a notification when adding a command, but that's nit done yet (Geant4.10.1)
735  FillHelpTree();
736 
737  return true;
738 }
739 
740 
741 void G4UIQt::SetStartPage(
742 const std::string& text)
743 {
744  if (text != "") {
745  fDefaultViewerFirstPageHTMLText = text;
746  }
747  if (!fStartPage) {
748  fStartPage = new QTextEdit();
749  fStartPage->setAcceptRichText (true);
750  fStartPage->setContentsMargins(5,5,5,5);
751  fStartPage->setReadOnly(true);
752  }
753  fStartPage->setText(fDefaultViewerFirstPageHTMLText.c_str());
754 }
755 
756 
757 void G4UIQt::UpdateTabWidget(int tabNumber) {
758  if ( fViewerTabWidget == NULL) {
759  fViewerTabWidget = new G4QTabWidget;
760  }
761 
762  fViewerTabWidget->setCurrentIndex(tabNumber);
763 
764  // Send this signal to unblock graphic updates !
765  fViewerTabWidget->setTabSelected(false);
766 
767  #if QT_VERSION < 0x040200
768  fViewerTabWidget->show();
769  #else
770  fViewerTabWidget->setVisible(true);
771  #endif
772 
773  // This will send a paintEvent to OGL Viewers
774  fViewerTabWidget->setTabSelected(true);
775 }
776 
777 
780 void G4UIQt::ResizeTabWidget( QResizeEvent* e) {
781  if ( fViewerTabWidget) {
782  for (G4int a=0;a<fViewerTabWidget->count() ;a++) {
783  fViewerTabWidget->widget(a)->resize(e->size());
784  }
785  }
786 }
787 
788 
791 G4UIsession* G4UIQt::SessionStart (
792 )
793 {
794  G4Qt* interactorManager = G4Qt::getInstance ();
795  Prompt("Session :");
796  exitSession = false;
797 
798  QCoreApplication::sendPostedEvents () ;
799 
800  #if QT_VERSION < 0x040200
801  fMainWindow->show();
802  #else
803  fMainWindow->setVisible(true);
804  #endif
805 
806  // Focus on command line
807  fCommandArea->setFocus();
808 
809  interactorManager->DisableSecondaryLoop (); // TO KEEP
810  if ((QApplication*)interactorManager->GetMainInteractor())
811  ((QApplication*)interactorManager->GetMainInteractor())->exec();
812 
813  interactorManager->EnableSecondaryLoop ();
814  return this;
815 }
816 
817 
823 void G4UIQt::Prompt (
824  G4String aPrompt
825 )
826 {
827  if (!aPrompt) return;
828 
829  fCommandLabel->setText((char*)aPrompt.data());
830 }
831 
832 
833 
834 void G4UIQt::SessionTerminate (
835 )
836 {
837  G4Qt* interactorManager = G4Qt::getInstance ();
838  fMainWindow->close();
839  ((QApplication*)interactorManager->GetMainInteractor())->exit();
840 }
841 
842 
843 
852 void G4UIQt::PauseSessionStart (
853  const G4String& aState
854 )
855 {
856  if (!aState) return;
857 
858  if(aState=="G4_pause> ") { // TO KEEP
859  SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP
860  } // TO KEEP
861 
862  if(aState=="EndOfEvent") { // TO KEEP
863  // Picking with feed back in event data Done here !!!
864  SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP
865  } // TO KEEP
866 }
867 
868 
869 
874 void G4UIQt::SecondaryLoop (
875  G4String aPrompt
876 )
877 {
878  if (!aPrompt) return;
879 
880  G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ?
881  Prompt(aPrompt); // TO KEEP
882  exitPause = false; // TO KEEP
883  while(1) {
884  ((QApplication*)interactorManager)->processEvents(QEventLoop::WaitForMoreEvents);
885  if(exitPause==true) break; // TO KEEP
886  } // TO KEEP
887  Prompt("Session :"); // TO KEEP
888 }
889 
890 #ifdef G4MULTITHREADED
891 #include "G4Threading.hh"
892 #include "G4AutoLock.hh"
893 namespace {
894  G4Mutex ReceiveG4coutMutex = G4MUTEX_INITIALIZER;
895  G4Mutex ReceiveG4cerrMutex = G4MUTEX_INITIALIZER;
896 }
897 #endif
898 
904 G4int G4UIQt::ReceiveG4cout (
905  const G4String& aString
906  )
907 {
908  if (!aString) return 0;
909 
910 #ifdef G4MULTITHREADED
911  G4AutoLock al(&ReceiveG4coutMutex);
912 #endif
913 
914  // Try to be smart :
915  // "*** This is just a warning message. ***"
916  if (aString.contains("*** This is just a warning message. ***")) {
917  return ReceiveG4cerr(aString);
918  }
919 
920  QStringList newStr;
921 
922  // Add to string
923  G4UIOutputString txt = G4UIOutputString(QString((char*)aString.data()).trimmed(),GetThreadPrefix());
924  fG4OutputString.push_back(txt);
925 
926 #ifdef G4MULTITHREADED
927  QString result = FilterOutput(txt,fThreadsFilterComboBox->currentText(),fCoutFilter->text());
928 #else
929  QString result = FilterOutput(txt,"",fCoutFilter->text());
930 #endif
931 
932  if (result.isEmpty()) {
933  return 0;
934  }
935  QColor previousColor = fCoutTBTextArea->textColor();
936  fCoutTBTextArea->setTextColor(Qt::black);
937  fCoutTBTextArea->append(result);
938  fCoutTBTextArea->setTextColor(previousColor);
939  fCoutTBTextArea->ensureCursorVisible ();
940 
941 #ifdef G4MULTITHREADED
942  UpdateCoutThreadFilter();
943 #endif
944  return 0;
945 }
946 
947 
953 G4int G4UIQt::ReceiveG4cerr (
954  const G4String& aString
955 )
956 {
957  if (!aString) return 0;
958 
959 #ifdef G4MULTITHREADED
960  G4AutoLock al(&ReceiveG4cerrMutex);
961 #endif
962  QStringList newStr;
963 
964  // Add to string
965 
966  G4UIOutputString txt = G4UIOutputString(QString((char*)aString.data()).trimmed(),
967  GetThreadPrefix(),
968  "error");
969  fG4OutputString.push_back(txt);
970 
971 #ifdef G4MULTITHREADED
972  QString result = FilterOutput(txt,fThreadsFilterComboBox->currentText(),fCoutFilter->text());
973 #else
974  QString result = FilterOutput(txt,"",fCoutFilter->text());
975 #endif
976  if (result.isEmpty()) {
977  return 0;
978  }
979 
980  // Suppress space, \n,\t,\r...
981  if (QString(aString.data()).trimmed() != "") {
984  // In case of Abort or Quit, the useful error message should be in the last error message !
985  QMessageBox::critical(fMainWindow, "Error",QString(fLastErrMessage.data())+"\n"+aString.data());
986  }
987  }
988  QColor previousColor = fCoutTBTextArea->textColor();
989  fCoutTBTextArea->setTextColor(Qt::red);
990  fCoutTBTextArea->append(result);
991  fCoutTBTextArea->setTextColor(previousColor);
992  fCoutTBTextArea->ensureCursorVisible ();
993 
994  if (QString(aString.data()).trimmed() != "") {
995  fLastErrMessage = aString;
996  }
997 #ifdef G4MULTITHREADED
998  UpdateCoutThreadFilter();
999 #endif
1000  return 0;
1001 }
1002 
1003 
1004 G4String G4UIQt::GetThreadPrefix() {
1005  G4String threadPrefix = "";
1006 #ifdef G4MULTITHREADED
1008  if(UI==NULL) return "";
1009  if (UI->GetThreadCout() != NULL) {
1010  threadPrefix = UI->GetThreadCout()->GetFullPrefixString().data();
1011  if (UI->GetThreadCout()->GetPrefixString() == G4String("G4VIS")) {
1012  return "G4VIS";
1013  }
1014  }
1015 #endif
1016  return threadPrefix;
1017 }
1018 
1019 
1020 #ifdef G4MULTITHREADED
1021 void G4UIQt::UpdateCoutThreadFilter() {
1023  if(UI==NULL) return;
1024 
1025  // add "All" and "Master"
1026  if (fThreadsFilterComboBox->count() < 2) {
1027  if ( fThreadsFilterComboBox->findText("All", Qt::MatchExactly) == -1) {
1028  fThreadsFilterComboBox->addItem("All");
1029  }
1030  }
1031  if (fThreadsFilterComboBox->count() < 2) {
1032  if ( fThreadsFilterComboBox->findText("Master", Qt::MatchExactly) == -1) {
1033  fThreadsFilterComboBox->addItem("Master");
1034  }
1035  }
1036  // Add current Cout
1037  G4String prefix = GetThreadPrefix();
1038  if (prefix != "") {
1039  if ( fThreadsFilterComboBox->findText(prefix.data(), Qt::MatchExactly) == -1) {
1040  fThreadsFilterComboBox->addItem(prefix.data());
1041  }
1042  }
1043 }
1044 #endif
1045 
1046 
1052 void G4UIQt::AddMenu (
1053  const char* aName
1054 ,const char* aLabel
1055 )
1056 {
1057  if (aName == NULL) return;
1058  if (aLabel == NULL) return;
1059 
1060  QMenu *fileMenu = new QMenu(aLabel);
1061  fMainWindow->menuBar()->addMenu(fileMenu);
1062 
1063  AddInteractor (aName,(G4Interactor)fileMenu);
1064 }
1065 
1066 
1073 void G4UIQt::AddButton (
1074  const char* aMenu
1075 ,const char* aLabel
1076 ,const char* aCommand
1077 )
1078 {
1079  if(aMenu==NULL) return; // TO KEEP
1080  if(aLabel==NULL) return; // TO KEEP
1081  if(aCommand==NULL) return; // TO KEEP
1082 
1083  QMenu *parentTmp = (QMenu*)GetInteractor(aMenu);
1084 
1085  if(parentTmp==NULL) {
1086  G4UImanager* UImanager = G4UImanager::GetUIpointer();
1087  G4int verbose = UImanager->GetVerboseLevel();
1088 
1089  if (verbose >= 2) {
1090  G4cout << "Menu name " << aMenu<< " does not exist, please define it before using it."<< G4endl;
1091  }
1092  return;
1093  }
1094 
1095  // Find the command in the command tree
1097  if(UI==NULL) return;
1098  G4UIcommandTree * treeTop = UI->GetTree();
1099 
1100  G4String cmd = aCommand;
1101  G4int cmdEndPos = cmd.find_first_of(" \t");
1102  if(cmdEndPos!=G4int(std::string::npos)) {
1103  cmd.erase(cmdEndPos);
1104  }
1105 
1106  if(treeTop->FindPath(cmd) == NULL) {
1107  G4UImanager* UImanager = G4UImanager::GetUIpointer();
1108  G4int verbose = UImanager->GetVerboseLevel();
1109 
1110  if (verbose >= 2) {
1111  G4cout << "Warning: command '"<< cmd <<"' does not exist, please define it before using it."<< G4endl;
1112  }
1113  }
1114 
1115  QSignalMapper *signalMapper = new QSignalMapper(this);
1116  QAction *action = parentTmp->addAction(aLabel, signalMapper, SLOT(map()));
1117 
1118  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&)));
1119  signalMapper->setMapping(action, QString(aCommand));
1120 }
1121 
1122 
1123 
1124 
1128 void G4UIQt::AddIcon(const char* aLabel, const char* aIconFile, const char* aCommand, const char* aFileName){
1129  if(aLabel==NULL) return; // TO KEEP
1130  // special case, aCommand could be NULL if aIconFile is not user_icon
1131  if (aCommand==NULL) {
1132  if (std::string(aIconFile) == "user_icon") {
1133  return; // TO KEEP
1134  }
1135  }
1136  QPixmap pix;
1137  bool userToolBar = false;
1138 
1139  if (std::string(aIconFile) == "user_icon") {
1140  // try to open a file
1141  G4UImanager* UImanager = G4UImanager::GetUIpointer();
1142  pix = QPixmap(UImanager->FindMacroPath(aFileName).data());
1143  if (pix.isNull()) {
1144  G4int verbose = UImanager->GetVerboseLevel();
1145 
1146  if (verbose >= 2) {
1147  G4cout << "Warning: file '"<< aFileName <<"' is incorrect or does not exist, this command will not be build"<< G4endl;
1148  }
1149  return;
1150  }
1151  userToolBar = true;
1152  } else if (std::string(aIconFile) == "open") {
1153  const char * const xpm[]={
1154  "32 32 33 1",
1155  " c None",
1156  "+ c #09091E",
1157  "@ c #191B18",
1158  "# c #5F615F",
1159  "$ c #777977",
1160  "% c #AEB1AF",
1161  "& c #929491",
1162  "* c #515250",
1163  "= c #858784",
1164  "- c #333533",
1165  "; c #000100",
1166  "> c #272926",
1167  ", c #424341",
1168  "' c #696C6A",
1169  ") c #5F4927",
1170  "! c #583D18",
1171  "~ c #6E6A5B",
1172  "{ c #47351D",
1173  "] c #E0A554",
1174  "^ c #FFD67B",
1175  "/ c #EFB465",
1176  "( c #FDBF6C",
1177  "_ c #FFCD76",
1178  ": c #806238",
1179  "< c #362611",
1180  "[ c #0B0D0A",
1181  "} c #68471B",
1182  "| c #523E22",
1183  "1 c #B78A51",
1184  "2 c #A17B44",
1185  "3 c #D6A45E",
1186  "4 c #C29354",
1187  "5 c #A1A3A0",
1188  " ",
1189  " ",
1190  " +@@@# ",
1191  " $% +& * ",
1192  " #= $ -; ",
1193  " %>;+ ",
1194  " ,;;+ ",
1195  " &#$''#' >;;;+ ",
1196  " =)!)!!!!~ *#$'' ",
1197  " {]^/((_({- %%%%%%%%%%% ",
1198  " {(^_^^^^:<{{{{{{{{{{{{{[& ",
1199  " {/_/(((((/]]]]]]]]]]]/]!# ",
1200  " {/^(((((_^^^^^^^^^^^^^^:# ",
1201  " {/^(((_^^____________^^}$ ",
1202  " {/^(((((/////////////((!# ",
1203  " {/^/^_:<|||||||||||||||@@****1 ",
1204  " {/^/^(<[)||||||||||||||))!!}<; ",
1205  " {/^_(:|234444444444444444432)1 ",
1206  " {/_^/<)34444444444444444443}, ",
1207  " {/^(2{:41111111111111111142|5 ",
1208  " {3^3<:31111111111111111143}- ",
1209  " {/^2<:31111111111111111441|' ",
1210  " {_/<:41111111111111111143}, ",
1211  " {(4<:31111111111111111144!# ",
1212  " )4))44111111111111111144}, ",
1213  " )2<:31111111111111111144{# ",
1214  " @|:14444444444444444444}* ",
1215  " ;@434444444444444444434<# ",
1216  " ;[))))))))))))))))))))!~ ",
1217  " ++++++++++++++++++++++;% ",
1218  " ",
1219  " "}
1220  ;
1221  pix = QPixmap(xpm);
1222 
1223  } else if (std::string(aIconFile) == "save") {
1224  const char * const xpm[]={
1225  "32 32 24 1",
1226  " c None",
1227  "+ c #000200",
1228  "@ c #141E43",
1229  "# c #000C56",
1230  "$ c #494A47",
1231  "% c #636662",
1232  "& c #312F2A",
1233  "* c #191B19",
1234  "= c #002992",
1235  "- c #003DFF",
1236  "; c #041DA5",
1237  "> c #A8A9A3",
1238  ", c #FDFFFC",
1239  "' c #DDE0DD",
1240  ") c #818783",
1241  "! c #C9CBC8",
1242  "~ c #0116C3",
1243  "{ c #C5C8FA",
1244  "] c #6596FC",
1245  "^ c #A0B4F9",
1246  "/ c #0B2AFD",
1247  "( c #799BE3",
1248  "_ c #5F4826",
1249  ": c #D5D8D5",
1250  " ",
1251  " ",
1252  " +++++++++++++++++++++++++ ",
1253  " +@##+$%%%%%%%%%%%%%%%&*$%&+ ",
1254  " +=-;@>,,''',,,,,,,',,)&!,)+ ",
1255  " +;-~@>,,,,,,,,,,,,,,,>$!,)+ ",
1256  " +=-~@>,,,,,{]]]]]^,,,>*&$&+ ",
1257  " +=-~@>,,,,,'{^{^^{,,,>*#=#+ ",
1258  " +=-~@>,,,,,,,,,,,,,,,>@~/=+ ",
1259  " +=-~@>,,,{{{''''{',,,>@~-=+ ",
1260  " +=-~@>,,'^]]]]]]({,,,>@~-=+ ",
1261  " +=-~@>,,,{{{{{{{{{,,,>@~-=+ ",
1262  " +=-~@>,,,,,'{^{{^{,,,>@~-=+ ",
1263  " +=-~@>,,,,,]]]]]]],,,>@~-=+ ",
1264  " +=-~*>,,,,,,,,,,,,,,,>@~-=+ ",
1265  " +=-~@>,,,,,,,,,,,,,,,>@~-=+ ",
1266  " +=-/=$%%%%%%%%%%%%%%%$=/-=+ ",
1267  " +=---;###############;---=+ ",
1268  " +=---////////////////----=+ ",
1269  " +=----------------///----=+ ",
1270  " +=---=@##############@#--=+ ",
1271  " +=---@+++++++++++*%))_+~-=+ ",
1272  " +=---#+++++++++++&:,,>@~-=+ ",
1273  " +=---#+++++++++++$',,>@~-=+ ",
1274  " +=---#+++++++++++&!,,>@~-=+ ",
1275  " +=/--#+++++++++++&',,>@~-=+ ",
1276  " @;--#+++++++++++$',,>@~-=+ ",
1277  " @;;@+++++++++++*)!>%@=;#+ ",
1278  " @++++++++++++++*&**++@++ ",
1279  " ",
1280  " ",
1281  " "}
1282  ;
1283  pix = QPixmap(xpm);
1284  } else if (std::string(aIconFile) == "move") {
1285  const char * const xpm[]={
1286  "32 32 16 1",
1287  " c None",
1288  ". c #F1F1F1",
1289  "+ c #939393",
1290  "@ c #282828",
1291  "# c #787878",
1292  "$ c #000000",
1293  "% c #CCCCCC",
1294  "& c #1A1A1A",
1295  "* c #0D0D0D",
1296  "= c #5D5D5D",
1297  "- c #AEAEAE",
1298  "; c #BBBBBB",
1299  "> c #C9C9C9",
1300  ", c #D6D6D6",
1301  "' c #FFFFFF",
1302  ") c #999999",
1303  " ",
1304  " ",
1305  " ",
1306  " ",
1307  " .. ",
1308  " ++ ",
1309  " .@@. ",
1310  " #$$# ",
1311  " %&$$*% ",
1312  " =$$$$= ",
1313  " -**$$**- ",
1314  " %;%&*>;% ",
1315  " -% @& %- ",
1316  " ,=*; @& ;*=, ",
1317  " .#*$$> >$$*#. ",
1318  " ')&$$$$*@@ @@*$$$$&)' ",
1319  " ')&$$$$*@@ @@*$$$$&+' ",
1320  " .#*$$> >$$*#. ",
1321  " ,=*; @& ;*=, ",
1322  " -% @& %- ",
1323  " %;%&*>>% ",
1324  " -**$$**- ",
1325  " =$$$$= ",
1326  " %&$$*% ",
1327  " #$$# ",
1328  " .@@. ",
1329  " ++ ",
1330  " .. ",
1331  " ",
1332  " ",
1333  " ",
1334  " "}
1335  ;
1336  pix = QPixmap(xpm);
1337 
1338  } else if (std::string(aIconFile) == "rotate") {
1339  const char * const xpm[]={
1340  "32 32 27 1",
1341  " c None",
1342  ". c #003333",
1343  "+ c #000066",
1344  "@ c #1A1A1A",
1345  "# c #003399",
1346  "$ c #3333CC",
1347  "% c #000033",
1348  "& c #353535",
1349  "* c #434343",
1350  "= c #336699",
1351  "- c #3399FF",
1352  "; c #003366",
1353  "> c #5D5D5D",
1354  ", c #282828",
1355  "' c #3399CC",
1356  ") c #333333",
1357  "! c #3366CC",
1358  "~ c #333399",
1359  "{ c #505050",
1360  "] c #666666",
1361  "^ c #333366",
1362  "/ c #0033CC",
1363  "( c #3366FF",
1364  "_ c #336666",
1365  ": c #787878",
1366  "< c #868686",
1367  "[ c #6B6B6B",
1368  " .++@ ",
1369  " #$$%&* ",
1370  " =--; *>, ",
1371  " '-= )>& ",
1372  " !-', ,>* ",
1373  " !!=--= >* ",
1374  " =------!!~@&)@ ",
1375  " --------!*{{{*&, ",
1376  " -------=){*{{{>>{) ",
1377  " ,!-----= ){& ,&{{@",
1378  " ,*>!----= &>& )@",
1379  " ){>)~---= *]) @",
1380  " @*>, --! ,&@ ",
1381  " @{* '! ,-!=~^,@ ",
1382  " @& == {/(----!^ ",
1383  " _ ]:;(----' ",
1384  " ==_ >{+(----~ ",
1385  " !-!!======!!(((---! ",
1386  " ='--------------! ",
1387  " =!!!!'!!=; !-! ",
1388  " &<* !~ ",
1389  " @. *[* ; ",
1390  " ;+)>* ",
1391  " @@ ",
1392  " ",
1393  " ",
1394  " ",
1395  " ",
1396  " ",
1397  " ",
1398  " ",
1399  " "}
1400  ;
1401  pix = QPixmap(xpm);
1402 
1403  } else if (std::string(aIconFile) == "pick") {
1404  const char * const xpm[]={
1405  "32 32 2 1",
1406  " c None",
1407  ". c #000000",
1408  " ",
1409  " ",
1410  " ",
1411  " ",
1412  " ",
1413  " ",
1414  " ",
1415  " . ",
1416  " .. ",
1417  " ... ",
1418  " .... ",
1419  " ..... ",
1420  " ...... ",
1421  " ....... ",
1422  " ....... ",
1423  " ........ ",
1424  " ..... ",
1425  " ...... ",
1426  " .. .. ",
1427  " . .. ",
1428  " ... ",
1429  " .. ",
1430  " .. ",
1431  " ",
1432  " ",
1433  " ",
1434  " ",
1435  " ",
1436  " ",
1437  " ",
1438  " ",
1439  " "}
1440  ;
1441  pix = QPixmap(xpm);
1442  } else if (std::string(aIconFile) == "zoom_in") {
1443  const char * const xpm[]={
1444  "32 32 11 1",
1445  " c None",
1446  ". c #C9CBC8",
1447  "+ c #A8A9A3",
1448  "@ c #818783",
1449  "# c #D5D8D5",
1450  "$ c #9BCCCC",
1451  "% c #5FC7F4",
1452  "& c #FDFFFC",
1453  "* c #636662",
1454  "= c #9599CE",
1455  "- c #DDE0DD",
1456  " ",
1457  " ",
1458  " ",
1459  " ",
1460  " ",
1461  " .++@@++. ",
1462  " +++..#.+++ ",
1463  " .@+...++++#+@. ",
1464  " @$.%%+&&&@%..@ ",
1465  " ++.%%%+&&&*%%.++ ",
1466  " .+#%%%%+&&&*%%.#+ ",
1467  " ++..%%%+&&&*%%%.++ ",
1468  " +#.+++++&&&*++++.+ ",
1469  " @.+&&&&&&&&&&&&&+@ ",
1470  " @#+&&&&&&&&&&&&&+@ ",
1471  " @.+&&&&&&&&&&&&&+. ",
1472  " +++@***+&&&****@+. ",
1473  " ....++++&&&*++++.. ",
1474  " ++.===+&&&*%=.++ ",
1475  " @..==+&&&*=..@#& ",
1476  " .@+#.+&&&@-+@@*@ ",
1477  " +++.++++++ *+@* ",
1478  " .+@@@++. @**+* ",
1479  " .*@*+* ",
1480  " .*@*+* ",
1481  " +*@@* ",
1482  " .**+ ",
1483  " ",
1484  " ",
1485  " ",
1486  " ",
1487  " "}
1488  ;
1489  pix = QPixmap(xpm);
1490  } else if (std::string(aIconFile) == "zoom_out") {
1491  const char * const xpm[]={
1492  "32 32 11 1",
1493  " c None",
1494  ". c #C9CBC8",
1495  "+ c #A8A9A3",
1496  "@ c #818783",
1497  "# c #D5D8D5",
1498  "$ c #5FC7F4",
1499  "% c #9BCCCC",
1500  "& c #FDFFFC",
1501  "* c #636662",
1502  "= c #9599CE",
1503  "- c #DDE0DD",
1504  " ",
1505  " ",
1506  " ",
1507  " ",
1508  " ",
1509  " .++@@++. ",
1510  " +++..#.+++ ",
1511  " .@+..$$$$.#+@. ",
1512  " @%.$$$$$$$$..@ ",
1513  " ++.$$$$$$$$$$.++ ",
1514  " .+#$$$$$$$$$$$.#+ ",
1515  " ++..$$$$$$$$$$$.++ ",
1516  " +#.+++++++++++++.+ ",
1517  " @.+&&&&&&&&&&&&&+@ ",
1518  " @#+&&&&&&&&&&&&&+@ ",
1519  " @.+&&&&&&&&&&&&&+. ",
1520  " +++@***********@+. ",
1521  " ....++++++++++++.. ",
1522  " ++.===$$$$$$=.++ ",
1523  " @..===$$$$=..@#& ",
1524  " .@+#.$$$..-+@@*@ ",
1525  " +++#--.+++ *+@* ",
1526  " .+@@@++. @**+* ",
1527  " .*@*+* ",
1528  " .*@*+* ",
1529  " +*@@* ",
1530  " .**+ ",
1531  " ",
1532  " ",
1533  " ",
1534  " ",
1535  " "}
1536  ;
1537  pix = QPixmap(xpm);
1538  } else if (std::string(aIconFile) == "wireframe") {
1539  const char * const xpm[]={
1540  "32 32 24 1",
1541  " c None",
1542  "+ c #E4E4E4",
1543  "@ c #D5D5D5",
1544  "# c #E1E1E1",
1545  "$ c #E7E7E7",
1546  "% c #D8D8D8",
1547  "& c #A7A7A7",
1548  "* c #000000",
1549  "= c #989898",
1550  "- c #8A8A8A",
1551  "; c #B5B5B5",
1552  "> c #1B1B1B",
1553  ", c #676767",
1554  "' c #959595",
1555  ") c #4A4A4A",
1556  "! c #878787",
1557  "~ c #D3D3D3",
1558  "{ c #C4C4C4",
1559  "] c #A4A4A4",
1560  "^ c #5B5B5B",
1561  "/ c #B3B3B3",
1562  "( c #787878",
1563  "_ c #C7C7C7",
1564  ": c #585858",
1565  " ",
1566  " +@@# ",
1567  " $%@@@@@&****=+ ",
1568  " +&********&@-***; ",
1569  " +@@@&**&@@@@@@$ @*-&>&+ ",
1570  " +*****&+ %*@ ,**'# ",
1571  " @***)!~ @*{&*****+ ",
1572  " @*!]***&+ +-*^**'~!*@ ",
1573  " @*~ +@&**&@@@@@@&****&+ ~*@ ",
1574  " @*@ +&********&-*= @*@ ",
1575  " @*@ $%@-*-@$ @*@ @*@ ",
1576  " @*@ @*@ %*% @*@ ",
1577  " @*@ %*% %*% @*@ ",
1578  " @*@ %*% %*% @*@ ",
1579  " @*@ %*% %*% @*@ ",
1580  " @*@ %*% %*% @*@ ",
1581  " @*@ %*% %*% @*@ ",
1582  " @*@ @*@ %*% @*@ ",
1583  " @*@ =*-+ @*@ @*@ ",
1584  " @*@ $%@@&****&@-*-+ @*@ ",
1585  " @*@ $@&*****&@@&******&~~!*@ ",
1586  " @*{/***&@@%$ $@-*-&*****+ ",
1587  " @*)*)(-~ @*@ ~)**] ",
1588  " +*******&@@@@+ %*_+]**] ",
1589  " +@@@@@&******&@%+_*^**]# ",
1590  " $%@@@&****:**&+ ",
1591  " +%@&**& ",
1592  " ++ ",
1593  " ",
1594  " ",
1595  " ",
1596  " "}
1597  ;
1598  pix = QPixmap(xpm);
1599  } else if (std::string(aIconFile) == "solid") {
1600  const char * const xpm[]={
1601  "32 32 33 1",
1602  " c None",
1603  "+ c #C2DEDE",
1604  "@ c #B5D7DF",
1605  "# c #ACD6E6",
1606  "$ c #60C0EC",
1607  "% c #4EB7EE",
1608  "& c #53B9ED",
1609  "* c #82CEEA",
1610  "= c #CFDDDA",
1611  "- c #94C9E8",
1612  "; c #0960FF",
1613  "> c #0943FF",
1614  ", c #0949FF",
1615  "' c #3CB3F0",
1616  ") c #71C7EB",
1617  "! c #73CBE5",
1618  "~ c #D3DDDB",
1619  "{ c #C4DDDE",
1620  "] c #B7D5DF",
1621  "^ c #2DACF5",
1622  "/ c #59C1ED",
1623  "( c #5FC0ED",
1624  "_ c #85CEE9",
1625  ": c #096BFF",
1626  "< c #2AACF6",
1627  "[ c #5CBEEC",
1628  "} c #7ACAE4",
1629  "| c #73CAEB",
1630  "1 c #71C8E5",
1631  "2 c #D1DDDA",
1632  "3 c #CBDDD9",
1633  "4 c #67C1EB",
1634  "5 c #80CDEA",
1635  " ",
1636  " ",
1637  " +@@@@@@#$%&*= ",
1638  " +-;>>>>>>>>>,')!~ ",
1639  " {]@@-;>>>>>>>>>>>>^/(_= ",
1640  " {:>>>>>>>>>>>>>>>>><//[)!= ",
1641  " ]>>>>>>>>>>>>>>>>>><////[)} ",
1642  " @>>>>>>>>>>>>>>>>>><//////| ",
1643  " @>>>>>>>>>>>>>>>>>><//////| ",
1644  " @>>>>>>>>>>>>>>>>>><//////| ",
1645  " @>>>>>>>>>>>>>>>>>><//////| ",
1646  " @>>>>>>>>>>>>>>>>>><//////| ",
1647  " @>>>>>>>>>>>>>>>>>><//////| ",
1648  " @>>>>>>>>>>>>>>>>>><//////| ",
1649  " @>>>>>>>>>>>>>>>>>><//////| ",
1650  " @>>>>>>>>>>>>>>>>>><//////| ",
1651  " @>>>>>>>>>>>>>>>>>><//////| ",
1652  " @>>>>>>>>>>>>>>>>>><//////| ",
1653  " @>>>>>>>>>>>>>>>>>><//////| ",
1654  " @>>>>>>>>>>>>>>>>>><//////| ",
1655  " @>>>>>>>>>>>>>>>>>><//////| ",
1656  " @>>>>>>>>>>>>>>>>>></////[1 ",
1657  " @>>>>>>>>>>>>>>>>>><////[*2 ",
1658  " {:>>>>>>>>>>>>>>>>><//[)12 ",
1659  " +@@@@@-;>>>>>>>>>><[)13 ",
1660  " {]@@@-;>>>,'*3 ",
1661  " +@@#452 ",
1662  " ",
1663  " ",
1664  " ",
1665  " ",
1666  " "}
1667  ;
1668  pix = QPixmap(xpm);
1669  } else if (std::string(aIconFile) == "hidden_line_removal") {
1670  const char * const xpm[]={
1671  "32 32 15 1",
1672  " c None",
1673  "+ c #D5D5D5",
1674  "@ c #C7C7C7",
1675  "# c #9C9C9C",
1676  "$ c #000000",
1677  "% c #8E8E8E",
1678  "& c #808080",
1679  "* c #A9A9A9",
1680  "= c #D8D8D8",
1681  "- c #CACACA",
1682  "; c #181818",
1683  "> c #9F9F9F",
1684  ", c #ACACAC",
1685  "' c #B9B9B9",
1686  ") c #555555",
1687  " ",
1688  " +@@+ ",
1689  " +@@@@@@#$$$$%+ ",
1690  " +#$$$$$$$$#@&$$$* ",
1691  " =-@@#$$#@@@@@-= @$&#;>= ",
1692  " =$$$$$#+ -$@ *$$%+ ",
1693  " -$&@-= -$- #$$$= ",
1694  " -$@ -$- +&$- ",
1695  " @$@ @$@ @$@ ",
1696  " @$@ @$@ @$@ ",
1697  " @$@ @$@ @$@ ",
1698  " @$@ @$@ @$@ ",
1699  " @$@ @$@ @$@ ",
1700  " @$@ @$@ @$@ ",
1701  " @$@ @$@ @$@ ",
1702  " @$@ @$@ @$@ ",
1703  " @$@ @$@ @$@ ",
1704  " @$@ @$@ @$@ ",
1705  " @$@ @$@ @$@ ",
1706  " @$@ @$@ @$@ ",
1707  " @$@ @$@ @$@ ",
1708  " @$@ @$@ #$= ",
1709  " -$&@@@-= -$- =>;, ",
1710  " =$$$$$$$#@@@-= -$'+#$$, ",
1711  " =-@@@@#$$$$$$#@-+'$)$$#+ ",
1712  " =-@@@#$$$$)$$#+ ",
1713  " +@@#$$# ",
1714  " ++ ",
1715  " ",
1716  " ",
1717  " ",
1718  " "}
1719  ;
1720  pix = QPixmap(xpm);
1721  } else if (std::string(aIconFile) == "hidden_line_and_surface_removal") {
1722  const char * const xpm[]={
1723  "32 32 40 1",
1724  " c None",
1725  "+ c #FFFFFF",
1726  "@ c #89A2E9",
1727  "# c #5378E3",
1728  "$ c #A2B5ED",
1729  "% c #5379E3",
1730  "& c #5076E3",
1731  "* c #3E69E4",
1732  "= c #0C43F8",
1733  "- c #043FFE",
1734  "; c #CDD9ED",
1735  "> c #BDCDE9",
1736  ", c #FBFCFC",
1737  "' c #406AE4",
1738  ") c #0439FE",
1739  "! c #0137FF",
1740  "~ c #4F75E3",
1741  "{ c #9EB5E3",
1742  "] c #829FE0",
1743  "^ c #B6C6E7",
1744  "/ c #9DB4E3",
1745  "( c #7E9CE0",
1746  "_ c #B2C3E9",
1747  ": c #7E9AE0",
1748  "< c #86A2E1",
1749  "[ c #CAD6ED",
1750  "} c #5177E3",
1751  "| c #829CE0",
1752  "1 c #BCCCE9",
1753  "2 c #3A67E6",
1754  "3 c #0A43FA",
1755  "4 c #95ACE1",
1756  "5 c #BBCBE9",
1757  "6 c #A9BBE5",
1758  "7 c #96AFE1",
1759  "8 c #BDCBE9",
1760  "9 c #4067E4",
1761  "0 c #6485E5",
1762  "a c #E3EAF3",
1763  "b c #CAD6F3",
1764  " ",
1765  " ",
1766  " ++++ ",
1767  " ++++++++@#$+++ ",
1768  " ++@%####&*=-#+;>, ",
1769  " +++++@'=)))))))!)~+{]^++ ",
1770  " +$%&*=)!!!!!!!!!)~+/(]_+++ ",
1771  " +#-))!!!!!!!!!!!)~+/(::<[+ ",
1772  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1773  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1774  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1775  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1776  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1777  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1778  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1779  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1780  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1781  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1782  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1783  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1784  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1785  " +#)!!!!!!!!!!!!!!}+/:::|1+ ",
1786  " +$#}}~23!!!!!!!!)~+/(]45, ",
1787  " +++++++@#}}~23!!)~+678++ ",
1788  " ++++++@#~90+a++ ",
1789  " ++++b++ ",
1790  " ++ ",
1791  " ",
1792  " ",
1793  " ",
1794  " ",
1795  " "}
1796  ;
1797  pix = QPixmap(xpm);
1798  } else if (std::string(aIconFile) == "perspective") {
1799  const char * const xpm[]={
1800  "32 32 3 1",
1801  " c None",
1802  ". c #D5D8D5",
1803  "+ c #000000",
1804  " ",
1805  " ",
1806  " ",
1807  " ",
1808  " ",
1809  " ................ ",
1810  " ....+++++++++++++++. ",
1811  " ...++++..+.........+++. ",
1812  " ..++..............++..+. ",
1813  " .+++++++++++++++++.. .+. ",
1814  " .+...............+. .+. ",
1815  " .+. .+. .+. .+. ",
1816  " .+. .+. .+. .+. ",
1817  " .+. .+. .+. .+. ",
1818  " .+. .+. .+. .+. ",
1819  " .+. .+. .+. .+. ",
1820  " .+. .+. .+. .+. ",
1821  " .+. .+. .+. .+. ",
1822  " .+. .+. .+. .+. ",
1823  " .+. .+......+....+. ",
1824  " .+. ..++++++.+.++++. ",
1825  " .+. .++.......+...+.. ",
1826  " .+. .++. .+..++. ",
1827  " .+. ..+.. .+..+. ",
1828  " .+..++. .+.+. ",
1829  " .+.++. .+++. ",
1830  " .+++.............++. ",
1831  " .+++++++++++++++++. ",
1832  " ................... ",
1833  " ",
1834  " ",
1835  " "}
1836  ;
1837  pix = QPixmap(xpm);
1838  } else if (std::string(aIconFile) == "ortho") {
1839  const char * const xpm[]={
1840  "32 32 3 1",
1841  " c None",
1842  ". c #D5D8D5",
1843  "@ c #000000",
1844  " ",
1845  " ",
1846  " ",
1847  " ................... ",
1848  " ..@@@@@@@@@@@@@@@@@. ",
1849  " ..@@@.............@@@. ",
1850  " ..@@.@. ..@..@. ",
1851  " ..@@ ..@. .@@...@. ",
1852  " ..@@..............@@.. .@. ",
1853  " .@@@@@@@@@@@@@@@@@.. .@. ",
1854  " .@...............@. .@. ",
1855  " .@. .@. .@. .@. ",
1856  " .@. .@. .@. .@. ",
1857  " .@. .@. .@. .@. ",
1858  " .@. .@. .@. .@. ",
1859  " .@. .@. .@. .@. ",
1860  " .@. .@. .@. .@. ",
1861  " .@. .@. .@. .@. ",
1862  " .@. .@. .@. .@. ",
1863  " .@. .@. .@. .@. ",
1864  " .@. .@. .@. .@. ",
1865  " .@. .@........@......@. ",
1866  " .@. .@@@@@@@@@.@.@@@@@@. ",
1867  " .@. .@@+........@....@@.. ",
1868  " .@...@. .@...@... ",
1869  " .@.@@. .@.@@ . ",
1870  " .@@@.............@@@.. ",
1871  " .@@@@@@@@@@@@@@@@@... ",
1872  " ................... ",
1873  " ",
1874  " ",
1875  " "}
1876  ;
1877  pix = QPixmap(xpm);
1878  } else {
1879  G4UImanager* UImanager = G4UImanager::GetUIpointer();
1880  G4int verbose = UImanager->GetVerboseLevel();
1881 
1882  if (verbose >= 2) {
1883  G4cout << "Parameter"<< aIconFile <<" not defined"<< G4endl;
1884  }
1885  return;
1886  }
1887  QToolBar *currentToolbar = NULL;
1888  if (userToolBar) {
1889  if (fToolbarUser == NULL) {
1890  fToolbarUser = new QToolBar();
1891  fToolbarUser->setIconSize (QSize(20,20));
1892  fMainWindow->addToolBar(Qt::TopToolBarArea, fToolbarUser);
1893  }
1894  currentToolbar = fToolbarUser;
1895  } else {
1896  if (fToolbarApp == NULL) {
1897  fToolbarApp = new QToolBar();
1898  fToolbarApp->setIconSize (QSize(20,20));
1899  fMainWindow->addToolBar(Qt::TopToolBarArea, fToolbarApp);
1900  }
1901  currentToolbar = fToolbarApp;
1902  }
1903 
1904  QSignalMapper *signalMapper = new QSignalMapper(this);
1905  QAction *action = currentToolbar->addAction(pix,aLabel, signalMapper, SLOT(map()));
1906 
1907 
1908  // special cases :"open"
1909  if (std::string(aIconFile) == "open") {
1910  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(OpenIconCallback(const QString &)));
1911  QString txt = aCommand + fStringSeparator + aLabel;
1912  signalMapper->setMapping(action, QString(txt));
1913 
1914  // special cases :"save"
1915  } else if (std::string(aIconFile) == "save") {
1916  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(SaveIconCallback(const QString&)));
1917  QString txt = aCommand + fStringSeparator + aLabel;
1918  signalMapper->setMapping(action, QString(txt));
1919 
1920  // special cases : cursor style
1921  } else if ((std::string(aIconFile) == "move") ||
1922  (std::string(aIconFile) == "rotate") ||
1923  (std::string(aIconFile) == "pick") ||
1924  (std::string(aIconFile) == "zoom_out") ||
1925  (std::string(aIconFile) == "zoom_in")) {
1926  action->setCheckable(TRUE);
1927  action->setChecked(TRUE);
1928  action->setData(aIconFile);
1929 
1930  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ChangeCursorStyle(const QString&)));
1931  signalMapper->setMapping(action, QString(aIconFile));
1932 
1933  if (std::string(aIconFile) == "move") {
1934  SetIconMoveSelected();
1935  }
1936  if (std::string(aIconFile) == "rotate") {
1937  SetIconRotateSelected();
1938  }
1939  if (std::string(aIconFile) == "pick") {
1940  SetIconPickSelected();
1941  }
1942  if (std::string(aIconFile) == "zoom_in") {
1943  SetIconZoomInSelected();
1944  }
1945  if (std::string(aIconFile) == "zoom_out") {
1946  SetIconZoomOutSelected();
1947  }
1948 
1949  // special case : surface style
1950  } else if ((std::string(aIconFile) == "hidden_line_removal") ||
1951  (std::string(aIconFile) == "hidden_line_and_surface_removal") ||
1952  (std::string(aIconFile) == "solid") ||
1953  (std::string(aIconFile) == "wireframe")) {
1954  action->setCheckable(TRUE);
1955  action->setChecked(TRUE);
1956  action->setData(aIconFile);
1957  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ChangeSurfaceStyle(const QString&)));
1958  signalMapper->setMapping(action, QString(aIconFile));
1959 
1960  if (std::string(aIconFile) == "hidden_line_removal") {
1961  SetIconHLRSelected();
1962  }
1963  if (std::string(aIconFile) == "hidden_line_and_surface_removal") {
1964  SetIconHLHSRSelected();
1965  }
1966  if (std::string(aIconFile) == "solid") {
1967  SetIconSolidSelected();
1968  }
1969  if (std::string(aIconFile) == "wireframe") {
1970  SetIconWireframeSelected();
1971  }
1972 
1973  // special case : perspective/ortho
1974  } else if ((std::string(aIconFile) == "perspective") ||
1975  (std::string(aIconFile) == "ortho")) {
1976  action->setCheckable(TRUE);
1977  action->setChecked(TRUE);
1978  action->setData(aIconFile);
1979  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ChangePerspectiveOrtho(const QString&)));
1980  signalMapper->setMapping(action, QString(aIconFile));
1981 
1982  if (std::string(aIconFile) == "perspective") {
1983  SetIconPerspectiveSelected();
1984  }
1985  if (std::string(aIconFile) == "ortho") {
1986  SetIconOrthoSelected();
1987  }
1988 
1989  } else {
1990 
1991  // Find the command in the command tree
1993  if(UI==NULL) return;
1994  G4UIcommandTree * treeTop = UI->GetTree();
1995  if (aCommand != NULL) {
1996  if(treeTop->FindPath(aCommand) == NULL) {
1997  G4UImanager* UImanager = G4UImanager::GetUIpointer();
1998  G4int verbose = UImanager->GetVerboseLevel();
1999 
2000  if (verbose >= 2) {
2001  G4cout << "Warning: command '"<< aCommand <<"' does not exist, please define it before using it."<< G4endl;
2002  }
2003  }
2004  }
2005 
2006  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&)));
2007  signalMapper->setMapping(action, QString(aCommand));
2008  }
2009 }
2010 
2011 
2012 
2013 void G4UIQt::ActivateCommand(
2014  G4String newCommand
2015 )
2016 {
2017  if (!fHelpTreeWidget) {
2018  return;
2019  }
2020  // Look for the choosen command "newCommand"
2021  size_t i = newCommand.index(" ");
2022  G4String targetCom ="";
2023  if( i != std::string::npos )
2024  {
2025  G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
2026  newValue.strip(G4String::both);
2027  targetCom = ModifyToFullPathCommand( newValue );
2028  }
2029  if (targetCom != "") {
2030  OpenHelpTreeOnCommand(targetCom.data());
2031  }
2032 
2033  fUITabWidget->setCurrentWidget(fHelpTBWidget);
2034 }
2035 
2036 
2037 
2044 void G4UIQt::InitHelpTreeAndVisParametersWidget()
2045 {
2046 
2047  if (! fHelpTreeWidget ) {
2048  fHelpTreeWidget = new QTreeWidget();
2049  }
2050 
2051  // build widget
2052  fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
2053  QStringList labels;
2054  labels << QString("Command");
2055  fHelpTreeWidget->setHeaderLabels(labels);
2056 
2057 
2058  connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback()));
2059  connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback()));
2060 
2061 }
2068 void G4UIQt::FillHelpTree()
2069 {
2070  if (! fHelpTreeWidget ) {
2071  InitHelpTreeAndVisParametersWidget();
2072  }
2073 
2074  QString searchText = fHelpLine->text();
2075 
2076  if (searchText =="") {
2077  // clear old help tree
2078  // fHelpTreeWidget->clear();
2079  } else {
2080  return;
2081  }
2082 
2083  if (fParameterHelpLabel) {
2084  fParameterHelpLabel->setText("Choose a command in the command tree");
2085  fParameterHelpTable->setVisible(false);
2086  }
2087 
2088  if (fHelpLine) {
2089 #if QT_VERSION < 0x040200
2090  fHelpLine->clear();
2091 #else
2092  fHelpLine->setText("");
2093 #endif
2094  }
2095 
2097  if(UI==NULL) return;
2098  G4UIcommandTree * treeTop = UI->GetTree();
2099 
2100  G4int treeSize = treeTop->GetTreeEntry();
2101  QTreeWidgetItem * newItem = NULL;
2102  QString commandText = "";
2103  for (int a=0;a<treeSize;a++) {
2104  // Creating new item
2105  newItem = NULL;
2106 
2107  commandText = QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed();
2108 
2109  // if already exist, don't create it !
2110  for (int b=0;b<fHelpTreeWidget->topLevelItemCount();b++) {
2111  if (!newItem)
2112  newItem = FindTreeItem(fHelpTreeWidget->topLevelItem(b),commandText);
2113  }
2114 
2115  if (newItem == NULL) {
2116 
2117  newItem = new QTreeWidgetItem();
2118  newItem->setText(0,GetShortCommandPath(commandText));
2119  fHelpTreeWidget->addTopLevelItem(newItem);
2120  }
2121 
2122  // look for childs
2123  CreateHelpTree(newItem,treeTop->GetTree(a+1));
2124  }
2125 
2126 }
2127 
2128 
2129 
2134 void G4UIQt::CreateHelpTree(
2135  QTreeWidgetItem *aParent
2136 ,G4UIcommandTree *aCommandTree
2137 )
2138 {
2139  if (aParent == NULL) return;
2140  if (aCommandTree == NULL) return;
2141 
2142 
2143  // Creating new item
2144  QTreeWidgetItem * newItem;
2145 
2146  QString commandText = "";
2147  // Get the Sub directories
2148  for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
2149 
2150  commandText = QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed();
2151 
2152  // if already exist, don't create it !
2153  newItem = FindTreeItem(aParent,commandText);
2154  if (newItem == NULL) {
2155  newItem = new QTreeWidgetItem();
2156  newItem->setText(0,GetShortCommandPath(commandText));
2157  aParent->addChild(newItem);
2158  }
2159  CreateHelpTree(newItem,aCommandTree->GetTree(a+1));
2160  }
2161 
2162  // Get the Commands
2163 
2164  for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
2165 
2166  QStringList stringList;
2167  commandText = QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed();
2168 
2169  // if already exist, don't create it !
2170  newItem = FindTreeItem(aParent,commandText);
2171  if (newItem == NULL) {
2172  newItem = new QTreeWidgetItem();
2173  newItem->setText(0,GetShortCommandPath(commandText));
2174  aParent->addChild(newItem);
2175 
2176 #if QT_VERSION < 0x040202
2177  fHelpTreeWidget->setItemExpanded(newItem,false);
2178 #else
2179  newItem->setExpanded(false);
2180 #endif
2181  }
2182  }
2183 }
2184 
2185 
2186 
2187 
2193 bool G4UIQt::CreateVisCommandGroupAndToolBox(
2194  G4UIcommand* aCommand
2195 ,QWidget* aParent
2196 ,int aDepthLevel
2197 ,bool isDialog
2198 )
2199 {
2200  QString commandText = QString((char*)(aCommand->GetCommandPath().data())).section("/",-aDepthLevel);
2201 
2202  if (commandText == NULL) {
2203  return false;
2204  }
2205 
2206  // Look if groupBox is create
2207  // QGroupBox* gBoxCommandWidget;
2208  QWidget* newParentWidget = NULL;
2209  bool found = false;
2210  QString commandSection = commandText.left(commandText.indexOf("/"));
2211 
2212  if (aDepthLevel == 1) {
2213  QToolBox* currentParent = dynamic_cast<QToolBox*>(aParent);
2214  if (currentParent != 0){
2215 
2216  // already exists ?
2217  for (int a=0; a<currentParent->count(); a++) {
2218  if (currentParent->itemText(a) == commandSection) {
2219  found = true;
2220  newParentWidget = currentParent->widget(a);
2221  }
2222  }
2223  }
2224  // Not found ? create it
2225  if (!found) {
2226  newParentWidget = new QGroupBox();
2227  newParentWidget->setLayout(new QVBoxLayout());
2228  if (currentParent != 0){
2229  currentParent->addItem(newParentWidget,commandSection);
2230  } else {
2231  if (!aParent->layout()) {
2232  aParent->setLayout(new QVBoxLayout());
2233  }
2234  aParent->layout()->addWidget(newParentWidget);
2235  }
2236 
2237  if (commandText.indexOf("/") == -1) {
2238 
2239  // Guidance
2240  QString guidance;
2241  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
2242  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
2243  guidance += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
2244  }
2245  newParentWidget->setToolTip(guidance);
2246  }
2247 
2248  QScrollArea* sc = dynamic_cast<QScrollArea*>(newParentWidget->parent()->parent());
2249  if (sc != 0) {
2250  sc->ensureWidgetVisible(newParentWidget);
2251 
2252  }
2253  }
2254  } else {
2255 
2256  // try to know if this level is already there
2257  QGroupBox* currentParent = dynamic_cast<QGroupBox*>(aParent);
2258  if (currentParent != 0){
2259 
2260  // if depth==2, then we add a [more parameters inside] to the toolBoxItem parent
2261  // QGroupBox > QWidget > QScrollArea > QToolBox
2262  if (aDepthLevel == 2){
2263  QToolBox* parentToolBox = dynamic_cast<QToolBox*>(currentParent->parent()->parent()->parent());
2264  if (parentToolBox != 0) {
2265  // parentToolBox->setItemText(parentToolBox->indexOf(currentParent),"[more parameters inside]");
2266  }
2267  }
2268  for (int a=0; a<aParent->layout()->count(); a++) {
2269  QGroupBox* gb = dynamic_cast<QGroupBox*>(aParent->layout()->itemAt(a)->widget());
2270  if (gb != 0) {
2271  if (gb->title() == commandSection) {
2272  found = true;
2273  newParentWidget = gb;
2274  }
2275  }
2276  }
2277  }
2278 
2279  // Not found ? create it
2280  if (!found) {
2281  newParentWidget = new QGroupBox();
2282  newParentWidget->setLayout(new QVBoxLayout());
2283  if (!aParent->layout()) {
2284  aParent->setLayout(new QVBoxLayout());
2285  }
2286  aParent->layout()->addWidget(newParentWidget);
2287 
2288  // set toolTip
2289  // Guidance
2290  QString guidance;
2291  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
2292  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
2293  guidance += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
2294  }
2295  newParentWidget->setToolTip(guidance);
2296  }
2297  }
2298 
2299  // fill command groupbox
2300  if (commandText.indexOf("/") == -1) {
2301  if (CreateCommandWidget(aCommand, newParentWidget,isDialog)) {
2302  return true;
2303  }
2304  } else {
2305  CreateVisCommandGroupAndToolBox(aCommand,newParentWidget, aDepthLevel-1,isDialog);
2306  }
2307 
2308  return true;
2309 }
2310 
2311 
2312 
2318 bool G4UIQt::CreateCommandWidget(G4UIcommand* aCommand, QWidget* aParent, bool isDialog) {
2319 
2320  if (aCommand == NULL) {
2321  return false;
2322  }
2323 
2324 
2325  // parameters
2326  G4int n_parameterEntry = aCommand->GetParameterEntries();
2327  if( n_parameterEntry > 0 ) {
2328  G4UIparameter *param;
2329 
2330  // Re-implementation of G4UIparameter.cc
2331  QWidget* paramWidget = new QWidget();
2332  QGridLayout* gridLayout = new QGridLayout();
2333  paramWidget->setLayout(gridLayout);
2334 
2335  // Special case for colour, try to display a color chooser if we found red/green/blue parameter
2336  unsigned int nbColorParameter = 0;
2337  bool isStillColorParameter = false;
2338  bool isColorDialogAdded = false;
2339  QLabel* redLabel = NULL;
2340  QLabel* greenLabel = NULL;
2341  QString redDefaultStr = "";
2342  QString greenDefaultStr = "";
2343  QString blueDefaultStr = "";
2344  QWidget* redInput = NULL;
2345  QWidget* greenInput = NULL;
2346 
2347  for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
2348  QString txt;
2349  param = aCommand->GetParameter(i_thParameter);
2350  QLabel* label = new QLabel(QString((char*)(param->GetParameterName()).data()));
2351 
2352  if ((label->text() == "red") || (label->text() == "red_or_string")){
2353  nbColorParameter ++;
2354  isStillColorParameter = true;
2355  } else if ((label->text() == "green") && isStillColorParameter) {
2356  nbColorParameter ++;
2357  } else if ((label->text() == "blue") && isStillColorParameter) {
2358  nbColorParameter ++;
2359  } else if (!isColorDialogAdded) {
2360 
2361  // not following red/green/blue parameters ?
2362  if (nbColorParameter == 1) {
2363  gridLayout->addWidget(redLabel,i_thParameter-1,0);
2364  gridLayout->addWidget(redInput,i_thParameter-1,1);
2365  } else if (nbColorParameter == 2) {
2366  gridLayout->addWidget(redLabel,i_thParameter-2,0);
2367  gridLayout->addWidget(redInput,i_thParameter-2,1);
2368  gridLayout->addWidget(greenLabel,i_thParameter-1,0);
2369  gridLayout->addWidget(greenInput,i_thParameter-1,1);
2370  }
2371  nbColorParameter = 0;
2372  }
2373  // Check parameter type, could be NULL if not found
2374  QWidget* input = NULL;
2375  if ((QString(QChar(param->GetParameterType())) == "d") || (QString(QChar(param->GetParameterType())) == "i")) {
2376  input = new QLineEdit();
2377  // set default value
2378  dynamic_cast<QLineEdit*>(input)->setText(QString((char*)(param->GetDefaultValue()).data()));
2379 
2380  if (((label->text() == "red") || (label->text() == "red_or_string")) && isStillColorParameter) {
2381  redDefaultStr = QString((char*)(param->GetDefaultValue()).data());
2382  } else if ((label->text() == "green") && isStillColorParameter) {
2383  greenDefaultStr = QString((char*)(param->GetDefaultValue()).data());
2384  } else if ((label->text() == "green") && isStillColorParameter) {
2385  blueDefaultStr = QString((char*)(param->GetDefaultValue()).data());
2386  }
2387 
2388  } else if (QString(QChar(param->GetParameterType())) == "b") {
2389  input = new QWidget();
2390  QHBoxLayout* layout = new QHBoxLayout();
2391  input->setLayout(layout);
2392 
2393  QButtonGroup* buttons = new QButtonGroup();
2394  QRadioButton* radioOff = new QRadioButton("0");
2395  QRadioButton* radioOn = new QRadioButton("1");
2396  buttons->addButton(radioOn);
2397  buttons->addButton(radioOff);
2398  layout->addWidget(radioOn);
2399  layout->addWidget(radioOff);
2400 
2401  // set default value
2402  QString defaultValue = QString((char*)(param->GetDefaultValue()).data());
2403  if (defaultValue == "0") {
2404  radioOff->setChecked(true);
2405  } else if (defaultValue == "1") {
2406  radioOn->setChecked(true);
2407  }
2408  } else if ((QString(QChar(param->GetParameterType())) == "s") && (!param->GetParameterCandidates().isNull())) {
2409  input = new QComboBox();
2410  QString candidates = QString((char*)(param->GetParameterCandidates()).data());
2411  QStringList list = candidates.split (" ");
2412 
2413  // add all candidates to widget
2414  QString defaultValue = QString((char*)(param->GetDefaultValue()).data());
2415  for (int a=0; a<list.size(); a++) {
2416  dynamic_cast<QComboBox*>(input)->addItem(list.at(a));
2417  if (list.at(a) == defaultValue) {
2418  dynamic_cast<QComboBox*>(input)->setCurrentIndex(a);
2419  }
2420  }
2421 
2422  } else if ((QString(QChar(param->GetParameterType())) == "s")) { // string
2423  input = new QLineEdit();
2424  // set default value
2425  dynamic_cast<QLineEdit*>(input)->setText(QString((char*)(param->GetDefaultValue()).data()));
2426 
2427  } else if ((QString(QChar(param->GetParameterType())) == "c")) { // on/off
2428  input = new QWidget();
2429  QHBoxLayout* layout = new QHBoxLayout();
2430  input->setLayout(layout);
2431 
2432  QButtonGroup* buttons = new QButtonGroup();
2433  QRadioButton* radioOff = new QRadioButton("off");
2434  QRadioButton* radioOn = new QRadioButton("on");
2435  buttons->addButton(radioOn);
2436  buttons->addButton(radioOff);
2437  layout->addWidget(radioOn);
2438  layout->addWidget(radioOff);
2439 
2440  // set default value
2441  QString defaultValue = QString((char*)(param->GetDefaultValue()).data());
2442  if (defaultValue == "off") {
2443  radioOff->setChecked(true);
2444  } else if (defaultValue == "on") {
2445  radioOn->setChecked(true);
2446  }
2447 
2448  } else {
2449  input = new QLineEdit();
2450  dynamic_cast<QLineEdit*>(input)->setText(QString((char*)(param->GetDefaultValue()).data()));
2451  }
2452 
2453  txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
2454  if( ! param->GetParameterGuidance().isNull() )
2455  txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
2456 
2457  txt += " Parameter type : " + QString(QChar(param->GetParameterType())) + "\n";
2458  if(param->IsOmittable()){
2459  txt += " Omittable : True\n";
2460  } else {
2461  txt += " Omittable : False\n";
2462  }
2463  if( param->GetCurrentAsDefault() ) {
2464  txt += " Default value : taken from the current value\n";
2465  } else if( ! param->GetDefaultValue().isNull() ) {
2466  txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n";
2467  }
2468  if( ! param->GetParameterRange().isNull() ) {
2469  txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
2470  }
2471  if( ! param->GetParameterCandidates().isNull() ) {
2472  txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
2473  }
2474 
2475  if (isStillColorParameter && (nbColorParameter != 0)) {
2476  if ((label->text() == "red") || (label->text() == "red_or_string")) {
2477  redLabel = label;
2478  redInput = input;
2479  } else if (label->text() == "green") {
2480  greenLabel = label;
2481  greenInput = input;
2482  } else if (label->text() == "blue") {
2483 
2484  // we have all, then add a color chooser
2485 
2486  // Create a pixmap with the default color
2487  QColor qc;
2488  if ((redDefaultStr != "") && (redDefaultStr != "") && (redDefaultStr != "")) {
2489  qc.setRgbF(redDefaultStr.toDouble(),
2490  greenDefaultStr.toDouble(),
2491  blueDefaultStr.toDouble());
2492  }
2493  QPixmap pixmap = QPixmap(QSize(16, 16));
2494  pixmap.fill (qc);
2495  QPainter painter(&pixmap);
2496  painter.setPen(Qt::black);
2497  painter.drawRect(0,0,15,15); // Draw contour
2498 
2499  input = new QPushButton("Change color");
2500  dynamic_cast<QPushButton*>(input)->setIcon(pixmap);
2501  dynamic_cast<QPushButton*>(input)->setAccessibleName(redDefaultStr+" "+greenDefaultStr+" "+blueDefaultStr);
2502  label = new QLabel("Choose color");
2503 
2504  // less 1 because we have to add one to the row number
2505  nbColorParameter--;
2506  gridLayout->addWidget(label,i_thParameter-nbColorParameter,0);
2507  input->setToolTip("Select the current color");
2508  gridLayout->addWidget(input,i_thParameter-nbColorParameter,1);
2509 
2510  // Connect pushButton to ColorDialog in callback
2511  QSignalMapper* signalMapper = new QSignalMapper(this);
2512  signalMapper->setMapping(input,input);
2513  connect(input, SIGNAL(clicked()), signalMapper, SLOT(map()));
2514  connect(signalMapper, SIGNAL(mapped(QWidget*)),this, SLOT(ChangeColorCallback(QWidget*)));
2515 
2516  isColorDialogAdded = true;
2517  isStillColorParameter = false;
2518  }
2519  } else {
2520  gridLayout->addWidget(label,i_thParameter-nbColorParameter,0);
2521  input->setToolTip(txt);
2522  gridLayout->addWidget(input,i_thParameter-nbColorParameter,1);
2523  }
2524  }
2525  // add command name in hidden value at last line position 0
2526  QLabel* name = new QLabel(QString((char*)(aCommand->GetCommandPath().data())));
2527  name->hide();
2528  gridLayout->addWidget(name,n_parameterEntry-nbColorParameter,0);
2529 
2530  QPushButton* applyButton = new QPushButton("Apply");
2531  if (!isDialog) {
2532 
2533  gridLayout->addWidget(applyButton,n_parameterEntry-nbColorParameter,1);
2534 
2535  QSignalMapper* signalMapper = new QSignalMapper(this);
2536  signalMapper->setMapping(applyButton, paramWidget);
2537  connect(applyButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
2538  connect(signalMapper, SIGNAL(mapped(QWidget*)),this, SLOT(VisParameterCallback(QWidget*)));
2539  } else {
2540  // Apply/Cancel buttons
2541 
2542  applyButton->setAutoDefault( TRUE );
2543  applyButton->setDefault( TRUE );
2544  gridLayout->addWidget(applyButton,n_parameterEntry-nbColorParameter,0);
2545 
2546  QPushButton* cancelButton = new QPushButton( tr( "&Cancel" ));
2547  cancelButton->setAutoDefault( TRUE );
2548  gridLayout->addWidget(cancelButton,n_parameterEntry-nbColorParameter,1);
2549 
2550  QSignalMapper* signalMapper = new QSignalMapper(this);
2551  signalMapper->setMapping(applyButton, paramWidget);
2552  connect(applyButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
2553  connect(signalMapper, SIGNAL(mapped(QWidget*)),this, SLOT(VisParameterCallback(QWidget*)));
2554 
2555  QWidget * parentCheck = aParent;
2556  QDialog* parentDialog = NULL;
2557  bool found = false;
2558  while ((parentCheck->parentWidget()) != NULL) {
2559  parentCheck = parentCheck->parentWidget();
2560  parentDialog = dynamic_cast<QDialog*>(parentCheck);
2561  if (parentDialog) {
2562  connect( applyButton, SIGNAL( clicked() ), parentDialog, SLOT( accept() ) );
2563  connect( cancelButton, SIGNAL( clicked() ), parentDialog, SLOT( reject() ) );
2564  found = true;
2565  }
2566  }
2567  if (!found) {
2568  return false;
2569  }
2570  }
2571 
2572  if (!aParent->layout()) {
2573  aParent->setLayout(new QVBoxLayout());
2574  }
2575  aParent->layout()->addWidget(paramWidget);
2576  }
2577 
2578  return true;
2579 }
2580 
2581 
2586 QTreeWidgetItem* G4UIQt::FindTreeItem(
2587  QTreeWidgetItem *aParent
2588 ,const QString& aCommand
2589 )
2590 {
2591  if (aParent == NULL) return NULL;
2592 
2593  // Suppress last "/"
2594  QString myCommand = aCommand;
2595 
2596  if (myCommand.lastIndexOf("/") == (myCommand.size()-1)) {
2597  myCommand = myCommand.left(myCommand.size()-1);
2598  }
2599 
2600  if (GetLongCommandPath(aParent) == myCommand)
2601  return aParent;
2602 
2603  QTreeWidgetItem * tmp = NULL;
2604  for (int a=0;a<aParent->childCount();a++) {
2605  if (!tmp)
2606  tmp = FindTreeItem(aParent->child(a),myCommand);
2607  }
2608  return tmp;
2609 }
2610 
2611 
2612 
2620 QString G4UIQt::GetCommandList (
2621  const G4UIcommand *aCommand
2622  )
2623 {
2624 
2625  QString txt ="";
2626  if (aCommand == NULL)
2627  return txt;
2628 
2629  G4String commandPath = aCommand->GetCommandPath();
2630  G4String rangeString = aCommand->GetRange();
2631  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
2632  G4int n_parameterEntry = aCommand->GetParameterEntries();
2633 
2634  if ((commandPath == "") &&
2635  (rangeString == "") &&
2636  (n_guidanceEntry == 0) &&
2637  (n_parameterEntry == 0)) {
2638  return txt;
2639  }
2640 
2641  if((commandPath.length()-1)!='/') {
2642  txt += "Command " + QString((char*)(commandPath).data()) + "\n";
2643  }
2644  txt += "Guidance :\n";
2645 
2646  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
2647  txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
2648  }
2649  if( ! rangeString.isNull() ) {
2650  txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n";
2651  }
2652  if( n_parameterEntry > 0 ) {
2653  G4UIparameter *param;
2654 
2655  // Re-implementation of G4UIparameter.cc
2656 
2657  for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
2658  param = aCommand->GetParameter(i_thParameter);
2659  txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
2660  if( ! param->GetParameterGuidance().isNull() )
2661  txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
2662  txt += " Parameter type : " + QString(QChar(param->GetParameterType())) + "\n";
2663  if(param->IsOmittable()){
2664  txt += " Omittable : True\n";
2665  } else {
2666  txt += " Omittable : False\n";
2667  }
2668  if( param->GetCurrentAsDefault() ) {
2669  txt += " Default value : taken from the current value\n";
2670  } else if( ! param->GetDefaultValue().isNull() ) {
2671  txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n";
2672  }
2673  if( ! param->GetParameterRange().isNull() ) {
2674  txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
2675  }
2676  if( ! param->GetParameterCandidates().isNull() ) {
2677  txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
2678  }
2679  }
2680  }
2681  return txt;
2682 }
2683 
2684 
2692 void G4UIQt::updateHelpArea (
2693  const G4UIcommand *aCommand
2694 )
2695 {
2696  if (!fParameterHelpLabel)
2697  return;
2698  if (!fParameterHelpTable)
2699  return;
2700 
2701  fParameterHelpLabel->setTextInteractionFlags(Qt::NoTextInteraction);
2702  QString txt;
2703  if (aCommand == NULL)
2704  return;
2705 
2706  G4String commandPath = aCommand->GetCommandPath();
2707  G4String rangeString = aCommand->GetRange();
2708  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
2709  G4int n_parameterEntry = aCommand->GetParameterEntries();
2710 
2711  if ((commandPath == "") &&
2712  (rangeString == "") &&
2713  (n_guidanceEntry == 0) &&
2714  (n_parameterEntry == 0)) {
2715  return;
2716  }
2717 
2718  if((commandPath.length()-1)!='/') {
2719  txt += "<b>Command </b> " + QString((char*)(commandPath).data()) + "<br />";
2720  }
2721  txt += "<b>Guidance :</b> ";
2722 
2723  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
2724  txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "<br />";
2725  }
2726  if( ! rangeString.isNull() ) {
2727  txt += "<b>Range of parameters : </b> " + QString((char*)(rangeString).data()) + "<br />";
2728  } else {
2729  txt += "<br />";
2730  }
2731  fParameterHelpLabel->setHtml(txt);
2732 
2733  if( n_parameterEntry > 0 ) {
2734  G4UIparameter *param;
2735 
2736  // Re-implementation of G4UIparameter.cc
2737 
2738  fParameterHelpTable->clear();
2739  fParameterHelpTable->setRowCount(n_parameterEntry);
2740  fParameterHelpTable->setColumnCount(8);
2741  fParameterHelpTable->setHorizontalHeaderLabels(QStringList() <<
2742  tr("") <<
2743  tr("Parameter") <<
2744  tr("Guidance") <<
2745  tr("Type") <<
2746  tr("Ommitable") <<
2747  tr("Default") <<
2748  tr("Range") <<
2749  tr("Candidate"));
2750  fParameterHelpTable->setColumnWidth(2,60);
2751 
2752  fParameterHelpTable->verticalHeader()->setVisible(false);
2753  fParameterHelpTable->setAlternatingRowColors (true);
2754 #if QT_VERSION < 0x050000
2755  fParameterHelpTable->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
2756  fParameterHelpTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
2757 #else
2758  fParameterHelpTable->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
2759  fParameterHelpTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
2760 #endif
2761  fParameterHelpTable->setWordWrap(true);
2762 
2763  QTableWidgetItem* t = fParameterHelpTable->horizontalHeaderItem(1);
2764  QFont fnt = t->font();
2765  int size = fnt.pointSize();
2766  fnt.setPointSize(size-2);
2767 
2768  for( G4int a=0; a<n_parameterEntry; a++ ) {
2769  param = aCommand->GetParameter(a);
2770  fParameterHelpTable->setItem(a, 0, new QTableWidgetItem(QString::number(a+1)));
2771 
2772  fParameterHelpTable->setItem(a, 1, new QTableWidgetItem(QString((char*)(param->GetParameterName()).data())));
2773  if( ! param->GetParameterGuidance().isNull() ) {
2774  fParameterHelpTable->setItem(a, 2, new QTableWidgetItem(QString((char*)(param->GetParameterGuidance()).data())));
2775  }
2776  fParameterHelpTable->setItem(a, 3, new QTableWidgetItem(QString(QChar(param->GetParameterType()))));
2777 
2778  if(param->IsOmittable()){
2779  fParameterHelpTable->setItem(a, 4, new QTableWidgetItem(QString("True")));
2780  } else {
2781  fParameterHelpTable->setItem(a, 4, new QTableWidgetItem(QString("False")));
2782  }
2783  if( param->GetCurrentAsDefault() ) {
2784  fParameterHelpTable->setItem(a, 5, new QTableWidgetItem(QString("taken from the current value")));
2785  } else if( ! param->GetDefaultValue().isNull() ) {
2786  fParameterHelpTable->setItem(a, 5, new QTableWidgetItem(QString((char*)(param->GetDefaultValue()).data())));
2787  }
2788  if( ! param->GetParameterRange().isNull() ) {
2789  fParameterHelpTable->setItem(a, 6, new QTableWidgetItem(QString((char*)(param->GetParameterRange()).data())));
2790  }
2791  if( ! param->GetParameterCandidates().isNull() ) {
2792  fParameterHelpTable->setItem(a, 7, new QTableWidgetItem(QString((char*)(param->GetParameterCandidates()).data())));
2793  }
2794  // tooltips
2795  for (int b=0; b<8; b++) {
2796  QTableWidgetItem* tmp = fParameterHelpTable->item(a,b);
2797  if (tmp) {
2798  tmp->setToolTip(tmp->text());
2799  tmp->setFlags(Qt::NoItemFlags);
2800  tmp->setForeground(QBrush());
2801  tmp->setFont(fnt);
2802  }
2803  }
2804  fParameterHelpTable->resizeRowToContents(a);
2805  }
2806  for (int c=0; c<8; c++) {
2807  if (c !=2) {
2808  fParameterHelpTable->resizeColumnToContents(c);
2809  }
2810  }
2811  fParameterHelpLabel->setVisible(true);
2812  fParameterHelpTable->setVisible(true);
2813 
2814  }
2815 }
2816 
2817 
2823 G4bool G4UIQt::IsGUICommand(
2824  const G4UIcommand *aCommand
2825 )
2826 {
2827  if (aCommand == NULL)
2828  return false;
2829 
2830  G4int n_parameterEntry = aCommand->GetParameterEntries();
2831 
2832  if( n_parameterEntry > 0 ) {
2833  G4UIparameter *param;
2834 
2835  // Re-implementation of G4UIparameter.cc
2836 
2837  for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
2838  param = aCommand->GetParameter(i_thParameter);
2839  if (QString(QChar(param->GetParameterType())) == "d") {
2840  return true;
2841  }
2842  if (QString(QChar(param->GetParameterType())) == "b") {
2843  return true;
2844  }
2845  if (QString(QChar(param->GetParameterType())) == "i") {
2846  return true;
2847  }
2848  if (QString(QChar(param->GetParameterType())) == "s") {
2849  return true;
2850  }
2851  }
2852  }
2853  return false;
2854 }
2855 
2856 
2859 G4bool G4UIQt::GetHelpChoice(
2860  G4int&
2861 )
2862 {
2863  return true;
2864 }
2865 
2866 
2874 bool G4UIQt::eventFilter( // Should stay with a minuscule eventFilter because of Qt
2875  QObject *aObj
2876 ,QEvent *aEvent
2877 )
2878 {
2879  bool moveCommandCursor = false;
2880  if (aObj == NULL) return false;
2881  if (aEvent == NULL) return false;
2882 
2883  if (aObj == fHistoryTBTableList) {
2884  if (aEvent->type() == QEvent::KeyPress) {
2885  fCommandArea->setFocus();
2886  }
2887  }
2888  if (aObj == fCommandArea) {
2889  if (aEvent->type() == QEvent::KeyPress) {
2890  QKeyEvent *e = static_cast<QKeyEvent*>(aEvent);
2891  if ((e->key() == (Qt::Key_Down)) ||
2892  (e->key() == (Qt::Key_PageDown)) ||
2893  (e->key() == (Qt::Key_Up)) ||
2894  (e->key() == (Qt::Key_PageUp))) {
2895  int selection = fHistoryTBTableList->currentRow();
2896  if (fHistoryTBTableList->count()) {
2897  if (selection == -1) {
2898  selection = fHistoryTBTableList->count()-1;
2899  } else {
2900  if (e->key() == (Qt::Key_Down)) {
2901  if (selection <(fHistoryTBTableList->count()-1))
2902  selection++;
2903  } else if (e->key() == (Qt::Key_PageDown)) {
2904  selection = fHistoryTBTableList->count()-1;
2905  } else if (e->key() == (Qt::Key_Up)) {
2906  if (selection >0)
2907  selection --;
2908  } else if (e->key() == (Qt::Key_PageUp)) {
2909  selection = 0;
2910  }
2911  }
2912  fHistoryTBTableList->clearSelection();
2913 #if QT_VERSION < 0x040202
2914  fHistoryTBTableList->setItemSelected(fHistoryTBTableList->item(selection),true);
2915 #else
2916  fHistoryTBTableList->item(selection)->setSelected(true);
2917 #endif
2918  fHistoryTBTableList->setCurrentItem(fHistoryTBTableList->item(selection));
2919  }
2920  moveCommandCursor = true;
2921  } else if (e->key() == (Qt::Key_Tab)) {
2922  G4String ss = Complete(fCommandArea->text().toStdString().c_str());
2923  fCommandArea->setText((char*)(ss.data()));
2924 
2925  // do not pass by parent, it will disable widget tab focus !
2926  return true;
2927  // L.Garnier : MetaModifier is CTRL for MAC, but I don't want to put a MAC
2928  // specific #ifdef
2929  } else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_A)) {
2930  fCommandArea->home(false);
2931  return true;
2932  } else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_E)) {
2933  fCommandArea->end(false);
2934  return true;
2935  }
2936  }
2937  }
2938  bool res= false;
2939  // change cursor position if needed
2940  if (moveCommandCursor == true) {
2941  fCommandArea->setCursorPosition ( fCommandArea->text().length() );
2942  fCommandArea->setCursorPosition (4);
2943  } else {
2944  // pass the event on to the parent class
2945  res = QObject::eventFilter(aObj, aEvent);
2946  }
2947  return res;
2948 }
2949 
2950 
2951 
2952 
2953 /***************************************************************************/
2954 //
2955 // SLOTS DEFINITIONS
2956 //
2957 /***************************************************************************/
2958 
2961 void G4UIQt::ShowHelpCallback (
2962 )
2963 {
2964  TerminalHelp("");
2965 }
2966 
2967 
2970 void G4UIQt::ClearButtonCallback (
2971 )
2972 {
2973  fCoutTBTextArea->clear();
2974  fG4OutputString.clear();
2975 }
2976 
2979 void G4UIQt::ExitSession (
2980 )
2981 {
2982  SessionTerminate();
2983 }
2984 
2985 void G4UIQt::ExitHelp(
2986 ) const
2987 {
2988 }
2989 
2993 void G4UIQt::CommandEnteredCallback (
2994 )
2995 {
2996  // split by any new line character
2997  QStringList list = fCommandArea->text().split(QRegExp("[\r\n]"),QString::SkipEmptyParts);
2998 
2999  // Apply for all commands
3000  for (int a=0; a< list.size(); a++) {
3001  QString txt (list[a].trimmed());
3002  if (txt != "") {
3003  fHistoryTBTableList->addItem(txt);
3004  fHistoryTBTableList->clearSelection();
3005  fHistoryTBTableList->setCurrentItem(NULL);
3006  fCommandArea->setText("");
3007  G4Qt* interactorManager = G4Qt::getInstance ();
3008  if (interactorManager) {
3009  interactorManager->FlushAndWaitExecution();
3010  }
3011 
3012  G4String command = txt.toStdString().c_str();
3013  if (command(0,4) != "help") {
3014  ApplyShellCommand (command,exitSession,exitPause);
3015  } else {
3016  ActivateCommand(command);
3017  }
3018  }
3019  }
3020  // set the focus to the command line
3021  fCommandArea->setFocus();
3022 
3023  // Rebuild help tree
3024  FillHelpTree();
3025 
3026  if(exitSession==true)
3027  SessionTerminate();
3028 }
3029 
3030 
3035 void G4UIQt::CommandEditedCallback(const QString &)
3036 {
3037  QStringList list = fCommandArea->text().split(QRegExp("[\r\n]"),QString::SkipEmptyParts);
3038 
3039  if (list.size() > 1) { // trigger ActivateCommand
3040  for (int a=0; a<list.size()-1; a++) {
3041  // set only the first part
3042  fCommandArea->setText(list[a]);
3043  // trigger callback
3044  CommandEnteredCallback();
3045  }
3046  // reset unfinished command
3047  fCommandArea->setText(list[list.size()-1]);
3048  }
3049 }
3050 
3051 
3054 void G4UIQt::VisParameterCallback(QWidget* widget){
3055  if (widget == NULL) {
3056  return;
3057  }
3058 
3059  // Look in all the Grid layout, but only column 1 (0 is the parameter name)
3060  QGridLayout* grid = dynamic_cast<QGridLayout*>(widget->layout());
3061  if (grid == 0) {
3062  return;
3063  }
3064  QString command;
3065 #if QT_VERSION < 0x040400
3066  QWidget* name = grid->itemAt(grid->columnCount()*(grid->rowCount()-2))->widget();
3067 #else
3068  QWidget* name = grid->itemAtPosition(grid->rowCount()-1,0)->widget();
3069 #endif
3070  if (dynamic_cast<QLabel*>(name) == 0) {
3071  return;
3072  }
3073  command += (dynamic_cast<QLabel*>(name))->text()+" ";
3074 
3075  for (int a=0;a<grid->rowCount()-1; a++) {
3076 #if QT_VERSION < 0x040400
3077  QWidget* widgetTmp = grid->itemAt(a*grid->columnCount()+1)->widget();
3078 #else
3079  QWidget* widgetTmp = grid->itemAtPosition(a,1)->widget();
3080 #endif
3081 
3082  // 4 kind of widgets : QLineEdit / QComboBox / radioButtonsGroup / QPushButton (color chooser)
3083  if (widgetTmp != NULL) {
3084 
3085  if (dynamic_cast<QLineEdit*>(widgetTmp) != 0) {
3086  command += (dynamic_cast<QLineEdit*>(widgetTmp))->text()+" ";
3087 
3088  } else if (dynamic_cast<QComboBox*>(widgetTmp) != 0){
3089  command += (dynamic_cast<QComboBox*>(widgetTmp))->itemText((dynamic_cast<QComboBox*>(widgetTmp))->currentIndex())+" ";
3090 
3091  // Color chooser
3092  } else if (dynamic_cast<QPushButton*>(widgetTmp) != 0){
3093  command += widgetTmp->accessibleName()+" ";
3094 
3095  // Check for Button group
3096  } else if (dynamic_cast<QWidget*>(widgetTmp) != 0){
3097  if (widgetTmp->layout()->count() > 0){
3098  if (dynamic_cast<QRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()) != 0) {
3099  QAbstractButton * checked = (dynamic_cast<QRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()))->group()->checkedButton();
3100  if (checked != 0) {
3101  command += (dynamic_cast<QRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()))->group()->checkedButton()->text()+" ";
3102  }
3103  }
3104  }
3105 
3106  }
3107  }
3108  }
3109  if (command != "") {
3111  if(UI != NULL) {
3112  UI->ApplyCommand(command.toStdString().c_str());
3113  }
3114  }
3115 }
3116 
3117 
3123 void G4UIQt::ButtonCallback (
3124  const QString& aCommand
3125 )
3126 {
3127  G4String ss = G4String(aCommand.toStdString().c_str());
3128  ss = ss.strip(G4String::leading);
3129 
3131  if(UI==NULL) return;
3132  G4UIcommandTree * treeTop = UI->GetTree();
3133 
3134  G4UIcommand* command = treeTop->FindPath(ss);
3135 
3136  if (command) {
3137  // if is GUI, then open a dialog
3138  if (IsGUICommand(command)) {
3139  QDialog* menuParameterDialog = new QDialog();
3140 
3141  if (CreateVisCommandGroupAndToolBox(command,menuParameterDialog,1,true)) {
3142  menuParameterDialog->setWindowTitle (aCommand);
3143  menuParameterDialog->setSizePolicy (QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
3144 
3145  // exec this dialog, apply the command automaticaly, and return
3146  menuParameterDialog->exec();
3147  return;
3148  }
3149  }
3150  }
3151 
3152  ApplyShellCommand(ss,exitSession,exitPause);
3153 
3154  // Rebuild help tree
3155  FillHelpTree();
3156 
3157  if(exitSession==true)
3158  SessionTerminate();
3159 }
3160 
3161 
3162 
3165 void G4UIQt::HelpTreeClicCallback (
3166 )
3167 {
3168  QTreeWidgetItem* item = NULL;
3169  if (!fHelpTreeWidget)
3170  return ;
3171 
3172  QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
3173  if (list.isEmpty())
3174  return;
3175  item = list.first();
3176  if (!item)
3177  return;
3178 
3180  if(UI==NULL) return;
3181  G4UIcommandTree * treeTop = UI->GetTree();
3182 
3183  std::string itemText = GetLongCommandPath(item).toStdString();
3184 
3185  // check if it is a command path
3186  if (item->childCount() > 0) {
3187  itemText +="/";
3188  }
3189  G4UIcommand* command = treeTop->FindPath(itemText.c_str());
3190 
3191  if (command) {
3192  updateHelpArea(command);
3193  } else { // this is a command
3194  G4UIcommandTree* path = treeTop->FindCommandTree(itemText.c_str());
3195  if ( path) {
3196  // this is not a command, this is a sub directory
3197  // We display the Title
3198  fParameterHelpLabel->setVisible(true);
3199  fParameterHelpLabel->setText(path->GetTitle().data());
3200  fParameterHelpTable->setVisible(false);
3201  }
3202  }
3203 }
3204 
3207 void G4UIQt::HelpTreeDoubleClicCallback (
3208 )
3209 {
3210  HelpTreeClicCallback();
3211 
3212  QTreeWidgetItem* item = NULL;
3213  if (!fHelpTreeWidget)
3214  return ;
3215 
3216  QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
3217  if (list.isEmpty())
3218  return;
3219  item = list.first();
3220  if (!item)
3221  return;
3222 
3223  fCommandArea->clear();
3224  fCommandArea->setText(GetLongCommandPath(item));
3225 }
3226 
3227 
3231 void G4UIQt::CommandHistoryCallback(
3232 )
3233 {
3234  QListWidgetItem* item = NULL;
3235  if (!fHistoryTBTableList)
3236  return ;
3237 
3238 
3239  QList<QListWidgetItem *> list =fHistoryTBTableList->selectedItems();
3240  if (list.isEmpty())
3241  return;
3242  item = list.first();
3243  if (!item)
3244  return;
3245  fCommandArea->setText(item->text());
3246 }
3247 
3248 
3249 void G4UIQt::ThreadComboBoxCallback(int) {
3250  CoutFilterCallback("");
3251 }
3252 
3253 
3254 void G4UIQt::CoutFilterCallback(
3255 const QString &) {
3256 
3257  FilterAllOutputTextArea();
3258 
3259  fCoutTBTextArea->repaint();
3260  fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
3261 
3262  }
3263 
3264 
3265 QString G4UIQt::FilterOutput(
3266  const G4UIOutputString& output
3267 ,const QString& currentThread
3268 ,const QString& filter
3269 ) {
3270 
3271 #ifdef G4MULTITHREADED
3272  if ((currentThread == "All") ||
3273  (currentThread == output.fThread)) {
3274 #else
3275  if (currentThread == "") {
3276 #endif
3277  if (output.fText.contains(QRegExp(filter))) {
3278  return output.fText;
3279  }
3280  }
3281  return "";
3282 }
3283 
3284 
3285 void G4UIQt::FilterAllOutputTextArea() {
3286 
3287  QString currentThread = "";
3288 #ifdef G4MULTITHREADED
3289  currentThread = fThreadsFilterComboBox->currentText();
3290  if (currentThread == "Master") {
3291  currentThread = "";
3292  }
3293 #endif
3294  QString filter = fCoutFilter->text();
3295  G4String previousOutputStream = "";
3296 
3297  fCoutTBTextArea->clear();
3298  fCoutTBTextArea->setTextColor(QColor(Qt::black));
3299 
3300  for (unsigned int a=0; a<fG4OutputString.size(); a++) {
3301  G4UIOutputString out = fG4OutputString[a];
3302  if (FilterOutput(out,currentThread,filter) != "") {
3303 
3304  // changing color ?
3305  if (out.fOutputStream != previousOutputStream) {
3306  previousOutputStream = out.fOutputStream;
3307  if (out.fOutputStream == "info") {
3308  fCoutTBTextArea->setTextColor(QColor(Qt::black));
3309  } else {
3310  fCoutTBTextArea->setTextColor(QColor(Qt::red));
3311  }
3312  }
3313  fCoutTBTextArea->append(out.fText);
3314  }
3315  }
3316  fCoutTBTextArea->setTextColor(QColor(Qt::black));
3317 }
3318 
3319 
3324 void G4UIQt::LookForHelpStringCallback(
3325 )
3326 {
3327  QString searchText = fHelpLine->text();
3328 
3329  fParameterHelpLabel->setText("");
3330  fParameterHelpTable->setVisible(false);
3331  if (searchText =="") {
3332  // clear old help tree
3333  fHelpTreeWidget->clear();
3334 
3335  FillHelpTree();
3336 
3337  return;
3338  } else {
3339  OpenHelpTreeOnCommand(searchText);
3340  }
3341 }
3342 
3343 
3344 void G4UIQt::OpenHelpTreeOnCommand(
3345  const QString & searchText
3346 )
3347 {
3348  // the help tree
3350  if(UI==NULL) return;
3351  G4UIcommandTree * treeTop = UI->GetTree();
3352 
3353  G4int treeSize = treeTop->GetTreeEntry();
3354 
3355  // clear old help tree
3356  fHelpTreeWidget->clear();
3357 
3358  // look for new items
3359 
3360  int tmp = 0;
3361 
3362  QMap<int,QString> commandResultMap;
3363  QMap<int,QString> commandChildResultMap;
3364 
3365  for (int a=0;a<treeSize;a++) {
3366  G4UIcommand* command = treeTop->FindPath(treeTop->GetTree(a+1)->GetPathName().data());
3367  tmp = GetCommandList (command).count(searchText,Qt::CaseInsensitive);
3368  if (tmp >0) {
3369  commandResultMap.insertMulti(tmp,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()));
3370  }
3371  // look for childs
3372  commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a+1),searchText);
3373  // insert new childs
3374  if (!commandChildResultMap.empty()) {
3375  QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
3376  while (i != commandChildResultMap.constEnd()) {
3377  commandResultMap.insertMulti(i.key(),i.value());
3378  i++;
3379  }
3380  commandChildResultMap.clear();
3381  }
3382  }
3383 
3384  // build new help tree
3385  fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
3386  fHelpTreeWidget->setColumnCount(2);
3387  QStringList labels;
3388  labels << QString("Command") << QString("Match");
3389  fHelpTreeWidget->setHeaderLabels(labels);
3390 
3391  if (commandResultMap.empty()) {
3392  fParameterHelpLabel->setText("No match found");
3393  fParameterHelpTable->setVisible(false);
3394  return;
3395  }
3396 
3397  QMap<int,QString>::const_iterator i = commandResultMap.constEnd();
3398  i--;
3399  // 10 maximum progress values
3400  float multValue = 10.0/(float)(i.key());
3401  QString progressChar = "|";
3402  QString progressStr = "|";
3403 
3404  QTreeWidgetItem * newItem;
3405  bool end = false;
3406  while (!end) {
3407  if (i == commandResultMap.constBegin()) {
3408  end = true;
3409  }
3410  for(int a=0;a<int(i.key()*multValue);a++) {
3411  progressStr += progressChar;
3412  }
3413  newItem = new QTreeWidgetItem();
3414  QString commandStr = i.value().trimmed();
3415 
3416  if (commandStr.indexOf("/") == 0) {
3417  commandStr = commandStr.right(commandStr.size()-1);
3418  }
3419 
3420  newItem->setText(0,commandStr);
3421  newItem->setText(1,progressStr);
3422  fHelpTreeWidget->addTopLevelItem(newItem);
3423 #if QT_VERSION < 0x040200
3424 #else
3425  newItem->setForeground ( 1, QBrush(Qt::blue) );
3426 #endif
3427  progressStr = "|";
3428  i--;
3429  }
3430  fHelpTreeWidget->resizeColumnToContents (0);
3431  fHelpTreeWidget->sortItems(1,Qt::DescendingOrder);
3432  // fHelpTreeWidget->setColumnWidth(1,10);//resizeColumnToContents (1);
3433 }
3434 
3435 
3436 
3437 
3438 QMap<int,QString> G4UIQt::LookForHelpStringInChildTree(
3439  G4UIcommandTree *aCommandTree
3440 ,const QString & text
3441  )
3442 {
3443  QMap<int,QString> commandResultMap;
3444  if (aCommandTree == NULL) return commandResultMap;
3445 
3446 
3447  // Get the Sub directories
3448  int tmp = 0;
3449  QMap<int,QString> commandChildResultMap;
3450 
3451  for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
3452  const G4UIcommand* command = aCommandTree->GetGuidance();
3453  tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
3454  if (tmp >0) {
3455  commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()));
3456  }
3457  // look for childs
3458  commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text);
3459 
3460  if (!commandChildResultMap.empty()) {
3461  // insert new childs
3462  QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
3463  while (i != commandChildResultMap.constEnd()) {
3464  commandResultMap.insertMulti(i.key(),i.value());
3465  i++;
3466  }
3467  commandChildResultMap.clear();
3468  }
3469  }
3470  // Get the Commands
3471 
3472  for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
3473  const G4UIcommand* command = aCommandTree->GetCommand(a+1);
3474  tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
3475  if (tmp >0) {
3476  commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()));
3477  }
3478 
3479  }
3480  return commandResultMap;
3481 }
3482 
3483 
3484 QString G4UIQt::GetShortCommandPath(
3485 QString commandPath
3486 )
3487 {
3488  if (commandPath.indexOf("/") == 0) {
3489  commandPath = commandPath.right(commandPath.size()-1);
3490  }
3491 
3492  commandPath = commandPath.right(commandPath.size()-commandPath.lastIndexOf("/",-2)-1);
3493 
3494  if (commandPath.lastIndexOf("/") == (commandPath.size()-1)) {
3495  commandPath = commandPath.left(commandPath.size()-1);
3496  }
3497 
3498  return commandPath;
3499 }
3500 
3501 
3502 QString G4UIQt::GetLongCommandPath(
3503  QTreeWidgetItem* item
3504 )
3505 {
3506  if (item == NULL) return "";
3507 
3508  // rebuild path:
3509  QString itemText = "";
3510  itemText = item->text(0);
3511 
3512  while (item->parent() != NULL) {
3513  itemText = item->parent()->text(0)+"/"+itemText;
3514  item = item->parent();
3515  }
3516  itemText = "/"+itemText;
3517 
3518  return itemText;
3519 }
3520 
3521 
3522 void G4UIQt::ChangeColorCallback(QWidget* widget) {
3523  if (widget == NULL) {
3524  return;
3525  }
3526 
3527  QPushButton* button = dynamic_cast<QPushButton*>(widget);
3528  if (button == 0) {
3529  return;
3530  }
3531  QString value = button->accessibleName();
3532 
3533  QColor old;
3534  old.setRgbF(value.section(" ",0,1).toDouble(),
3535  value.section(" ",1,2).toDouble(),
3536  value.section(" ",2,3).toDouble());
3537 #if QT_VERSION < 0x040500
3538  bool a;
3539  QColor color = QColor(QColorDialog::getRgba (old.rgba(),&a,fUITabWidget));
3540 #else
3541  QColor color = QColorDialog::getColor(old,
3542  fUITabWidget,
3543  "Change color",
3544  QColorDialog::ShowAlphaChannel);
3545 #endif
3546 
3547 
3548  if (color.isValid()) {
3549  // rebuild the widget icon
3550  QPixmap pixmap = QPixmap(QSize(16, 16));
3551  pixmap.fill (color);
3552  QPainter painter(&pixmap);
3553  painter.setPen(Qt::black);
3554  painter.drawRect(0,0,15,15); // Draw contour
3555 
3556  button->setAccessibleName(QString::number(color.redF())+" "+
3557  QString::number(color.greenF())+" "+
3558  QString::number(color.blueF())+" "
3559  );
3560  button->setIcon(pixmap);
3561 
3562 
3563  }
3564 }
3565 
3566 
3567 void G4UIQt::ChangeCursorStyle(const QString& action) {
3568 
3569  // Theses actions should be in the app toolbar
3570 
3571  fMoveSelected = true;
3572  fPickSelected = true;
3573  fRotateSelected = true;
3574  fZoomInSelected = true;
3575  fZoomOutSelected = true;
3576 
3577  if (fToolbarApp == NULL) return;
3578  QList<QAction *> list = fToolbarApp->actions ();
3579  for (int i = 0; i < list.size(); ++i) {
3580  if (list.at(i)->data().toString () == action) {
3581  list.at(i)->setChecked(TRUE);
3582  if (list.at(i)->data().toString () == "pick") {
3583  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/picking true");
3584  }
3585  } else if (list.at(i)->data().toString () == "move") {
3586  fMoveSelected = false;
3587  list.at(i)->setChecked(FALSE);
3588  } else if (list.at(i)->data().toString () == "pick") {
3589  fPickSelected = false;
3590  list.at(i)->setChecked(FALSE);
3591  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/picking false");
3592  } else if (list.at(i)->data().toString () == "rotate") {
3593  fRotateSelected = false;
3594  list.at(i)->setChecked(FALSE);
3595  } else if (list.at(i)->data().toString () == "zoom_in") {
3596  fZoomInSelected = false;
3597  list.at(i)->setChecked(FALSE);
3598  } else if (list.at(i)->data().toString () == "zoom_out") {
3599  fZoomOutSelected = false;
3600  list.at(i)->setChecked(FALSE);
3601  }
3602  }
3603  // FIXME : Should connect this to Vis
3604 }
3605 
3606 
3607 /* A little bit like "void G4OpenGLQtViewer::toggleDrawingAction(int aAction)"
3608  But for all viewers, not only Qt
3609 
3610 FIXME : Should be a feedback when changing viewer !
3611 
3612  */
3613 void G4UIQt::ChangeSurfaceStyle(const QString& action) {
3614 
3615  // Theses actions should be in the app toolbar
3616 
3617  if (fToolbarApp == NULL) return;
3618  QList<QAction *> list = fToolbarApp->actions ();
3619  for (int i = 0; i < list.size(); ++i) {
3620  if (list.at(i)->data().toString () == action) {
3621  list.at(i)->setChecked(TRUE);
3622  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
3623  list.at(i)->setChecked(FALSE);
3624  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3625  list.at(i)->setChecked(FALSE);
3626  } else if (list.at(i)->data().toString () == "solid") {
3627  list.at(i)->setChecked(FALSE);
3628  } else if (list.at(i)->data().toString () == "wireframe") {
3629  list.at(i)->setChecked(FALSE);
3630  }
3631  }
3632  // FIXME : Should connect this to Vis
3633 
3634  if (action == "hidden_line_removal") {
3635  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style w");
3636  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 1");
3637 
3638  } else if (action == "hidden_line_and_surface_removal") {
3639  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style s");
3640  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 1");
3641 
3642  } else if (action == "solid") {
3643  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style s");
3644  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 0");
3645 
3646  } else if (action == "wireframe") {
3647  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style w");
3648  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 0");
3649  }
3650 }
3651 
3652 
3653 void G4UIQt::OpenIconCallback(const QString& aParam) {
3654 
3655  QString aCommand = aParam.left(aParam.indexOf(fStringSeparator));
3656  QString aLabel = aParam.mid(aParam.indexOf(fStringSeparator)+fStringSeparator.length());
3657 
3658  QString nomFich = QFileDialog::getOpenFileName(fMainWindow, aLabel, fLastOpenPath, "Macro files (*.mac)");
3659  if (nomFich != "") {
3660  G4UImanager::GetUIpointer()->ApplyCommand((QString(aCommand)+ QString(" ")+ nomFich).toStdString().c_str());
3661  QDir dir;
3662  fLastOpenPath = dir.absoluteFilePath(nomFich);
3663  }
3664 }
3665 
3666 
3667 void G4UIQt::SaveIconCallback(const QString& aParam) {
3668 
3669  QString aCommand = aParam.left(aParam.indexOf(fStringSeparator));
3670  QString aLabel = aParam.mid(aParam.indexOf(fStringSeparator)+fStringSeparator.length());
3671 
3672  QString nomFich = QFileDialog::getSaveFileName(fMainWindow, aLabel, fLastOpenPath, "Macro files (*.mac)");
3673  if (nomFich != "") {
3674  G4UImanager::GetUIpointer()->ApplyCommand((QString(aCommand)+ QString(" ")+nomFich).toStdString().c_str());
3675  QDir dir;
3676  fLastOpenPath = dir.absoluteFilePath(nomFich);
3677  }
3678 }
3679 
3680 
3681 
3682 void G4UIQt::ChangePerspectiveOrtho(const QString& action) {
3683 
3684  // Theses actions should be in the app toolbar
3685 
3686  if (fToolbarApp == NULL) return;
3687  QList<QAction *> list = fToolbarApp->actions ();
3688  QString checked = "";
3689  for (int i = 0; i < list.size(); ++i) {
3690  if (list.at(i)->data().toString () == action) {
3691  list.at(i)->setChecked(TRUE);
3692  checked = list.at(i)->data().toString ();
3693  } else if (list.at(i)->data().toString () == "persepective") {
3694  list.at(i)->setChecked(FALSE);
3695  } else if (list.at(i)->data().toString () == "ortho") {
3696  list.at(i)->setChecked(FALSE);
3697  }
3698  }
3699 
3700  if ((action == "ortho") && (checked == "ortho")) {
3701  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/projection o");
3702  } else if ((action == "perspective") && (checked == "perspective")) {
3703  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/projection p");
3704  }
3705 }
3706 
3707 
3708 
3709 void G4UIQt::SetIconMoveSelected() {
3710  // Theses actions should be in the app toolbar
3711  fMoveSelected = true;
3712  fRotateSelected = false;
3713  fPickSelected = false;
3714  fZoomInSelected = false;
3715  fZoomOutSelected = false;
3716 
3717  if (fToolbarApp == NULL) return;
3718  QList<QAction *> list = fToolbarApp->actions ();
3719  for (int i = 0; i < list.size(); ++i) {
3720  if (list.at(i)->data().toString () == "move") {
3721  list.at(i)->setChecked(TRUE);
3722  } else if (list.at(i)->data().toString () == "rotate") {
3723  list.at(i)->setChecked(FALSE);
3724  } else if (list.at(i)->data().toString () == "pick") {
3725  list.at(i)->setChecked(FALSE);
3726  } else if (list.at(i)->data().toString () == "zoom_in") {
3727  list.at(i)->setChecked(FALSE);
3728  } else if (list.at(i)->data().toString () == "zoom_out") {
3729  list.at(i)->setChecked(FALSE);
3730  }
3731  }
3732 }
3733 
3734 
3735 void G4UIQt::SetIconRotateSelected() {
3736  // Theses actions should be in the app toolbar
3737  fRotateSelected = true;
3738  fMoveSelected = false;
3739  fPickSelected = false;
3740  fZoomInSelected = false;
3741  fZoomOutSelected = false;
3742 
3743  if (fToolbarApp == NULL) return;
3744  QList<QAction *> list = fToolbarApp->actions ();
3745  for (int i = 0; i < list.size(); ++i) {
3746  if (list.at(i)->data().toString () == "rotate") {
3747  list.at(i)->setChecked(TRUE);
3748  } else if (list.at(i)->data().toString () == "move") {
3749  list.at(i)->setChecked(FALSE);
3750  } else if (list.at(i)->data().toString () == "pick") {
3751  list.at(i)->setChecked(FALSE);
3752  } else if (list.at(i)->data().toString () == "zoom_in") {
3753  list.at(i)->setChecked(FALSE);
3754  } else if (list.at(i)->data().toString () == "zoom_out") {
3755  list.at(i)->setChecked(FALSE);
3756  }
3757  }
3758 }
3759 
3760 
3761 void G4UIQt::SetIconPickSelected() {
3762  // Theses actions should be in the app toolbar
3763  fPickSelected = true;
3764  fMoveSelected = false;
3765  fRotateSelected = false;
3766  fZoomInSelected = false;
3767  fZoomOutSelected = false;
3768 
3769  if (fToolbarApp == NULL) return;
3770  QList<QAction *> list = fToolbarApp->actions ();
3771  for (int i = 0; i < list.size(); ++i) {
3772  if (list.at(i)->data().toString () == "pick") {
3773  list.at(i)->setChecked(TRUE);
3774  } else if (list.at(i)->data().toString () == "move") {
3775  list.at(i)->setChecked(FALSE);
3776  } else if (list.at(i)->data().toString () == "rotate") {
3777  list.at(i)->setChecked(FALSE);
3778  } else if (list.at(i)->data().toString () == "zoom_in") {
3779  list.at(i)->setChecked(FALSE);
3780  } else if (list.at(i)->data().toString () == "zoom_out") {
3781  list.at(i)->setChecked(FALSE);
3782  }
3783  }
3784 }
3785 
3786 
3787 void G4UIQt::SetIconZoomInSelected() {
3788  // Theses actions should be in the app toolbar
3789  fZoomInSelected = true;
3790  fMoveSelected = false;
3791  fRotateSelected = false;
3792  fPickSelected = false;
3793  fZoomOutSelected = false;
3794 
3795  if (fToolbarApp == NULL) return;
3796  QList<QAction *> list = fToolbarApp->actions ();
3797  for (int i = 0; i < list.size(); ++i) {
3798  if (list.at(i)->data().toString () == "zoom_in") {
3799  list.at(i)->setChecked(TRUE);
3800  } else if (list.at(i)->data().toString () == "move") {
3801  list.at(i)->setChecked(FALSE);
3802  } else if (list.at(i)->data().toString () == "rotate") {
3803  list.at(i)->setChecked(FALSE);
3804  } else if (list.at(i)->data().toString () == "pick") {
3805  list.at(i)->setChecked(FALSE);
3806  } else if (list.at(i)->data().toString () == "zoom_out") {
3807  list.at(i)->setChecked(FALSE);
3808  }
3809  }
3810 }
3811 
3812 
3813 void G4UIQt::SetIconZoomOutSelected() {
3814  // Theses actions should be in the app toolbar
3815  fZoomOutSelected = true;
3816  fMoveSelected = false;
3817  fRotateSelected = false;
3818  fPickSelected = false;
3819  fZoomInSelected = false;
3820 
3821  if (fToolbarApp == NULL) return;
3822  QList<QAction *> list = fToolbarApp->actions ();
3823  for (int i = 0; i < list.size(); ++i) {
3824  if (list.at(i)->data().toString () == "zoom_out") {
3825  list.at(i)->setChecked(TRUE);
3826  } else if (list.at(i)->data().toString () == "move") {
3827  list.at(i)->setChecked(FALSE);
3828  } else if (list.at(i)->data().toString () == "rotate") {
3829  list.at(i)->setChecked(FALSE);
3830  } else if (list.at(i)->data().toString () == "pick") {
3831  list.at(i)->setChecked(FALSE);
3832  } else if (list.at(i)->data().toString () == "zoom_in") {
3833  list.at(i)->setChecked(FALSE);
3834  }
3835  }
3836 }
3837 
3838 
3839 void G4UIQt::SetIconSolidSelected() {
3840  // Theses actions should be in the app toolbar
3841 
3842  if (fToolbarApp == NULL) return;
3843  QList<QAction *> list = fToolbarApp->actions ();
3844  for (int i = 0; i < list.size(); ++i) {
3845  if (list.at(i)->data().toString () == "solid") {
3846  list.at(i)->setChecked(TRUE);
3847  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
3848  list.at(i)->setChecked(FALSE);
3849  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3850  list.at(i)->setChecked(FALSE);
3851  } else if (list.at(i)->data().toString () == "wireframe") {
3852  list.at(i)->setChecked(FALSE);
3853  }
3854  }
3855 }
3856 
3857 
3858 void G4UIQt::SetIconWireframeSelected() {
3859  // Theses actions should be in the app toolbar
3860 
3861  if (fToolbarApp == NULL) return;
3862  QList<QAction *> list = fToolbarApp->actions ();
3863  for (int i = 0; i < list.size(); ++i) {
3864  if (list.at(i)->data().toString () == "wireframe") {
3865  list.at(i)->setChecked(TRUE);
3866  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
3867  list.at(i)->setChecked(FALSE);
3868  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3869  list.at(i)->setChecked(FALSE);
3870  } else if (list.at(i)->data().toString () == "solid") {
3871  list.at(i)->setChecked(FALSE);
3872  }
3873  }
3874 }
3875 
3876 
3877 void G4UIQt::SetIconHLRSelected() {
3878  // Theses actions should be in the app toolbar
3879 
3880  if (fToolbarApp == NULL) return;
3881  QList<QAction *> list = fToolbarApp->actions ();
3882  for (int i = 0; i < list.size(); ++i) {
3883  if (list.at(i)->data().toString () == "hidden_line_removal") {
3884  list.at(i)->setChecked(TRUE);
3885  } else if (list.at(i)->data().toString () == "solid") {
3886  list.at(i)->setChecked(FALSE);
3887  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3888  list.at(i)->setChecked(FALSE);
3889  } else if (list.at(i)->data().toString () == "wireframe") {
3890  list.at(i)->setChecked(FALSE);
3891  }
3892  }
3893 }
3894 
3895 
3896 void G4UIQt::SetIconHLHSRSelected() {
3897  // Theses actions should be in the app toolbar
3898 
3899  if (fToolbarApp == NULL) return;
3900  QList<QAction *> list = fToolbarApp->actions ();
3901  for (int i = 0; i < list.size(); ++i) {
3902  if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3903  list.at(i)->setChecked(TRUE);
3904  } else if (list.at(i)->data().toString () == "solid") {
3905  list.at(i)->setChecked(FALSE);
3906  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
3907  list.at(i)->setChecked(FALSE);
3908  } else if (list.at(i)->data().toString () == "wireframe") {
3909  list.at(i)->setChecked(FALSE);
3910  }
3911  }
3912 }
3913 
3914 
3915 void G4UIQt::SetIconPerspectiveSelected() {
3916  // Theses actions should be in the app toolbar
3917 
3918  if (fToolbarApp == NULL) return;
3919  QList<QAction *> list = fToolbarApp->actions ();
3920  for (int i = 0; i < list.size(); ++i) {
3921  if (list.at(i)->data().toString () == "perspective") {
3922  list.at(i)->setChecked(TRUE);
3923  } else if (list.at(i)->data().toString () == "ortho") {
3924  list.at(i)->setChecked(FALSE);
3925  }
3926  }
3927 }
3928 
3929 
3930 
3931 void G4UIQt::SetIconOrthoSelected() {
3932  // Theses actions should be in the app toolbar
3933 
3934  if (fToolbarApp == NULL) return;
3935  QList<QAction *> list = fToolbarApp->actions ();
3936  for (int i = 0; i < list.size(); ++i) {
3937  if (list.at(i)->data().toString () == "ortho") {
3938  list.at(i)->setChecked(TRUE);
3939  } else if (list.at(i)->data().toString () == "perspective") {
3940  list.at(i)->setChecked(FALSE);
3941  }
3942  }
3943 }
3944 
3945 
3946 
3947 G4QTabWidget::G4QTabWidget(
3948 QWidget* aParent,
3949 int sizeX,
3950 int sizeY
3951 ):QTabWidget(aParent)
3952  ,fTabSelected(false)
3953  ,fLastCreated(-1)
3954 ,fPreferedSizeX(sizeX+6) // margin left+right
3955 ,fPreferedSizeY(sizeY+58) // tab label height + margin left+right
3956 {
3957  setMinimumSize(100,100);
3958  QSizePolicy policy = QSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
3959  setSizePolicy(policy);
3960 }
3961 
3962 G4QTabWidget::G4QTabWidget(
3963 ):QTabWidget()
3964  ,fTabSelected(false)
3965  ,fLastCreated(-1)
3966 ,fPreferedSizeX(0)
3967 ,fPreferedSizeY(0)
3968 {
3969 }
3970 
3971 
3972 G4UIOutputString::G4UIOutputString(
3973 QString text,
3974 G4String origine,
3975 G4String outputStream
3976 ):
3977  fText(text)
3978 ,fThread(origine)
3979 {
3980  if (!GetOutputList().contains(QString(" ")+outputStream+" ")) {
3981  fOutputStream = "info";
3982  } else {
3983  fOutputStream = outputStream;
3984  }
3985 }
3986 
3987 
3988 #if QT_VERSION < 0x040500
3989 void G4UIQt::TabCloseCallback(int){
3990 #else
3991 void G4UIQt::TabCloseCallback(int a){
3992 #endif
3993 #if QT_VERSION < 0x040500
3994 #else
3995  if (fViewerTabWidget == NULL) return;
3996 
3997  // get the address of the widget
3998  QWidget* temp = fViewerTabWidget->widget(a);
3999  // remove the tab
4000  fViewerTabWidget->removeTab (a);
4001 
4002  // delete the widget
4003  delete temp;
4004 #endif
4005 }
4006 
4007 
4008 void G4UIQt::ToolBoxActivated(int a){
4009 
4010  if (fUITabWidget->widget(a) == fHelpTBWidget) {
4011  // Rebuild the help tree
4012  FillHelpTree();
4013  } else if (fUITabWidget->widget(a) == fSceneTreeComponentsTBWidget) {
4014 #if QT_VERSION < 0x040200
4015  fSceneTreeComponentsTBWidget->show();
4016 #else
4017  fSceneTreeComponentsTBWidget->setVisible(true);
4018 #endif
4019  }
4020 }
4021 
4022 
4023 void G4QTabWidget::paintEvent(
4024 QPaintEvent *
4025 )
4026 {
4027 
4028  if (currentWidget()) {
4029 
4030  if ( isTabSelected()) {
4031 
4032  // QCoreApplication::sendPostedEvents () ;
4033 
4034  QString text = tabText (currentIndex());
4035 
4036  if (fLastCreated == -1) {
4037  QTextEdit* edit = dynamic_cast<QTextEdit*>(currentWidget());
4038  if (!edit){
4039  QString paramSelect = QString("/vis/viewer/select ")+text;
4041  if(UI != NULL) {
4042  UI->ApplyCommand(paramSelect.toStdString().c_str());
4043  }
4044  }
4045  } else {
4046  fLastCreated = -1;
4047  }
4048  setTabSelected(false);
4049  }
4050  }
4051 }
4052 
4053 
4054 G4UIDockWidget::G4UIDockWidget(QString txt):
4055  QDockWidget(txt)
4056 {}
4057 
4058 
4059 void G4UIDockWidget::closeEvent(QCloseEvent *aEvent) {
4060  setFloating (false);
4061 
4062  //prevent from closing
4063  aEvent->ignore();
4064  // hide them instead
4065  hide();
4066 }
4067 
4068 #endif
G4UIcommandTree * FindCommandTree(const char *commandPath)
Try to match a command or a path with the one given.
G4MTcoutDestination * GetThreadCout()
Definition: G4UImanager.hh:294
G4String GetParameterCandidates() const
const G4String & GetRange() const
Definition: G4UIcommand.hh:133
Definition: test07.cc:36
G4UIcommand * FindPath(const char *commandPath) const
G4String strip(G4int strip_Type=trailing, char c=' ')
G4int GetCommandEntry() const
G4String name
Definition: TRTMaterials.hh:40
G4String GetParameterName() const
G4UIcommand * GetCommand(G4int i)
G4String GetFullPrefixString() const
G4int GetTreeEntry() const
G4double a
Definition: TRTMaterials.hh:39
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:227
void SetSession(G4UIsession *const value)
Definition: G4UImanager.hh:213
Definition: test07.cc:36
int G4int
Definition: G4Types.hh:78
const G4String & GetGuidanceLine(G4int i) const
Definition: G4UIcommand.hh:137
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:171
void SetG4UIWindow(G4UIsession *const value)
Definition: G4UImanager.hh:215
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4bool IsOmittable() const
void * G4Interactor
G4String GetPrefixString() const
static G4StateManager * GetStateManager()
G4GLOB_DLL std::ostream G4cout
str_size index(const char *, G4int pos=0) const
G4UIcommandTree * GetTree(G4int i)
bool G4bool
Definition: G4Types.hh:79
#define FALSE
Definition: globals.hh:52
G4UIparameter * GetParameter(G4int i) const
Definition: G4UIcommand.hh:145
#define TRUE
Definition: globals.hh:55
const G4String & GetCommandPath() const
Definition: G4UIcommand.hh:139
G4ApplicationState GetCurrentState() const
const G4String GetPathName() const
G4bool contains(const std::string &) const
const char * data() const
const G4String GetTitle() const
G4int G4Mutex
Definition: G4Threading.hh:169
G4UIcommandTree * GetTree() const
Definition: G4UImanager.hh:206
G4String & append(const G4String &)
G4String GetDefaultValue() const
void SetCoutDestination(G4UIsession *const value)
Definition: G4UImanager.cc:604
const G4UIcommand * GetGuidance() const
char GetParameterType() const
#define G4endl
Definition: G4ios.hh:61
const G4String GetParameterGuidance() const
G4String GetParameterRange() const
G4int GetGuidanceEntries() const
Definition: G4UIcommand.hh:135
G4int GetParameterEntries() const
Definition: G4UIcommand.hh:143
G4String FindMacroPath(const G4String &fname) const
Definition: G4UImanager.cc:680
G4bool GetCurrentAsDefault() const
G4bool isNull() const
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:432