Geant4  10.02.p02
G4UIQt.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4UIQt.cc 97681 2016-06-07 08:59:17Z 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  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 void 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  fMainWindow->setCentralWidget(fViewerTabWidget);
580 #if QT_VERSION < 0x040500
581 #else
582  fViewerTabWidget->setTabsClosable (true);
583 #endif
584 
585 #if QT_VERSION < 0x040200
586 #else
587  fViewerTabWidget->setUsesScrollButtons (true);
588 #endif
589 
590 #if QT_VERSION < 0x040500
591 #else
592  connect(fViewerTabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(TabCloseCallback(int)));
593 #endif
594  connect(fViewerTabWidget, SIGNAL(currentChanged ( int ) ), SLOT(UpdateTabWidget(int)));
595  }
596 
597 // set the QGLWidget size policy
598  QSizePolicy policy = QSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
599  policy.setVerticalStretch(4);
600  fViewerTabWidget->setSizePolicy(policy);
601 
602  fViewerTabWidget->setMinimumSize(40,40);
603 }
604 
605 
608 QTabWidget* G4UIQt::GetSceneTreeComponentsTBWidget(
609 )
610 {
611  return fSceneTreeComponentsTBWidget;
612 }
613 
614 
615 
616 
619 bool G4UIQt::AddViewerTab(
620  QWidget* aWidget
621  ,std::string title
622  )
623 {
624  if (fViewerTabWidget == NULL) {
625  return false;
626  }
627  fViewerTabWidget->addTab(aWidget,title.c_str());
628 
629  return true;
630 }
631 
632 
635 bool G4UIQt::AddViewerTabFromFile(
636  std::string fileName
637  ,std::string title
638  )
639 {
640  if (fViewerTabWidget == NULL) {
641  return false;
642  }
643 
645  if(UI==NULL) return 0;
646  std::ifstream file(UI->FindMacroPath(fileName.c_str()).data());
647  if (file) {
648 
649  std::string content( (std::istreambuf_iterator<char>(file) ),
650  (std::istreambuf_iterator<char>() ) );
651 
652  QTextEdit* text = new QTextEdit();
653  text->setAcceptRichText (true);
654  text->setContentsMargins(5,5,5,5);
655  text->setText(QString("<pre>")+content.c_str()+"</pre>");
656  text->setReadOnly(true);
657  fViewerTabWidget->addTab(text,title.c_str());
658  } else {
659  return false;
660  }
661  return true;
662 }
663 
664 
668 bool G4UIQt::AddTabWidget(
669  QWidget* aWidget
670 ,QString name
671 )
672 {
673  // Special case for Qt version between 5.0 and 5.1 on Mac OSX
674  // Due to a bug in this Qt version, we can't put a OpenGL Widget inside the QTabWidget.
675  // A work around is to put it outside. Returning false will fore the wiewer to put the QGLWidget
676  // inside a new QWindow.
677 
678 #ifdef Q_OS_MAC
679  #if QT_VERSION < 0x050100
680  #if QT_VERSION >= 0x050000
681  QString message = QString(
682  "This Qt version [")+qVersion ()+"] has some issues with the OpenGL viewer.\n"+
683  "To prevent problems, you are not allowed to open a Stored nor Immediate viewer.\n" +
684  "\n" +
685  "Please upgrade to Qt version >= 5.1\n";
686 
687  QMessageBox::warning(fMainWindow, tr("Warning"),
688  tr(message.toStdString().c_str()),
689  QMessageBox::Ok);
690  return false;
691  #endif
692  #endif
693 #endif
694 
695  if (fViewerTabWidget == NULL) {
696  CreateViewerWidget();
697  }
698 
699  if (!aWidget) {
700  return false;
701  }
702 // Has to be added before we put it into the fViewerTabWidget widget
703  aWidget->setParent(fViewerTabWidget); // Will create in some cases widget outside
704  // of UI for a really short moment
705 
706  fViewerTabWidget->addTab(aWidget,name);
707 
708  fViewerTabWidget->setCurrentIndex(fViewerTabWidget->count()-1);
709 
710  // Set visible
711  #if QT_VERSION < 0x040200
712  fViewerTabWidget->setLastTabCreated(fViewerTabWidget->currentIndex());
713  #else
714  fViewerTabWidget->setLastTabCreated(fViewerTabWidget->currentIndex());
715  #endif
716 
717  // Not the good solution, but ensure that the help tree is correctly build when launching a viewer
718  // It should be done by a notification when adding a command, but that's nit done yet (Geant4.10.1)
719  FillHelpTree();
720 
721  return true;
722 }
723 
724 
725 void G4UIQt::SetStartPage(
726 const std::string& text)
727 {
728  if (text != "") {
729  fDefaultViewerFirstPageHTMLText = text;
730  }
731  if (!fStartPage) {
732  fStartPage = new QTextEdit();
733  fStartPage->setAcceptRichText (true);
734  fStartPage->setContentsMargins(5,5,5,5);
735  fStartPage->setReadOnly(true);
736  }
737  fStartPage->setText(fDefaultViewerFirstPageHTMLText.c_str());
738 }
739 
740 
741 void G4UIQt::UpdateTabWidget(int tabNumber) {
742  if ( fViewerTabWidget == NULL) {
743  fViewerTabWidget = new G4QTabWidget;
744  }
745 
746  fViewerTabWidget->setCurrentIndex(tabNumber);
747 
748  // Send this signal to unblock graphic updates !
749  fViewerTabWidget->setTabSelected(false);
750 
751  #if QT_VERSION < 0x040200
752  fViewerTabWidget->show();
753  #else
754  fViewerTabWidget->setVisible(true);
755  #endif
756 
757  // This will send a paintEvent to OGL Viewers
758  fViewerTabWidget->setTabSelected(true);
759 }
760 
761 
764 void G4UIQt::ResizeTabWidget( QResizeEvent* e) {
765  if ( fViewerTabWidget) {
766  for (G4int a=0;a<fViewerTabWidget->count() ;a++) {
767  fViewerTabWidget->widget(a)->resize(e->size());
768  }
769  }
770 }
771 
772 
775 G4UIsession* G4UIQt::SessionStart (
776 )
777 {
778  G4Qt* interactorManager = G4Qt::getInstance ();
779  Prompt("Session :");
780  exitSession = false;
781 
782  QCoreApplication::sendPostedEvents () ;
783 
784  #if QT_VERSION < 0x040200
785  fMainWindow->show();
786  #else
787  fMainWindow->setVisible(true);
788  #endif
789 
790  // Focus on command line
791  fCommandArea->setFocus();
792 
793  interactorManager->DisableSecondaryLoop (); // TO KEEP
794  if ((QApplication*)interactorManager->GetMainInteractor())
795  ((QApplication*)interactorManager->GetMainInteractor())->exec();
796 
797  interactorManager->EnableSecondaryLoop ();
798  return this;
799 }
800 
801 
807 void G4UIQt::Prompt (
808  G4String aPrompt
809 )
810 {
811  if (!aPrompt) return;
812 
813  fCommandLabel->setText((char*)aPrompt.data());
814 }
815 
816 
817 
818 void G4UIQt::SessionTerminate (
819 )
820 {
821  G4Qt* interactorManager = G4Qt::getInstance ();
822  fMainWindow->close();
823  ((QApplication*)interactorManager->GetMainInteractor())->exit();
824 }
825 
826 
827 
836 void G4UIQt::PauseSessionStart (
837  const G4String& aState
838 )
839 {
840  if (!aState) return;
841 
842  if(aState=="G4_pause> ") { // TO KEEP
843  SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP
844  } // TO KEEP
845 
846  if(aState=="EndOfEvent") { // TO KEEP
847  // Picking with feed back in event data Done here !!!
848  SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP
849  } // TO KEEP
850 }
851 
852 
853 
858 void G4UIQt::SecondaryLoop (
859  G4String aPrompt
860 )
861 {
862  if (!aPrompt) return;
863 
864  G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ?
865  Prompt(aPrompt); // TO KEEP
866  exitPause = false; // TO KEEP
867  while(1) {
868  ((QApplication*)interactorManager)->processEvents(QEventLoop::WaitForMoreEvents);
869  if(exitPause==true) break; // TO KEEP
870  } // TO KEEP
871  Prompt("Session :"); // TO KEEP
872 }
873 
874 #ifdef G4MULTITHREADED
875 #include "G4Threading.hh"
876 #include "G4AutoLock.hh"
877 namespace {
878  G4Mutex ReceiveG4coutMutex = G4MUTEX_INITIALIZER;
879  G4Mutex ReceiveG4cerrMutex = G4MUTEX_INITIALIZER;
880 }
881 #endif
882 
888 G4int G4UIQt::ReceiveG4cout (
889  const G4String& aString
890  )
891 {
892  if (!aString) return 0;
893 
894 #ifdef G4MULTITHREADED
895  G4AutoLock al(&ReceiveG4coutMutex);
896 #endif
897 
898  // Try to be smart :
899  // "*** This is just a warning message. ***"
900  if (aString.contains("*** This is just a warning message. ***")) {
901  return ReceiveG4cerr(aString);
902  }
903 
904  QStringList newStr;
905 
906  // Add to string
907  G4UIOutputString txt = G4UIOutputString(QString((char*)aString.data()).trimmed(),GetThreadPrefix());
908  fG4OutputString.push_back(txt);
909 
910 #ifdef G4MULTITHREADED
911  QString result = FilterOutput(txt,fThreadsFilterComboBox->currentText(),fCoutFilter->text());
912 #else
913  QString result = FilterOutput(txt,"",fCoutFilter->text());
914 #endif
915 
916  if (result.isEmpty()) {
917  return 0;
918  }
919  QColor previousColor = fCoutTBTextArea->textColor();
920  fCoutTBTextArea->setTextColor(Qt::black);
921  fCoutTBTextArea->append(result);
922  fCoutTBTextArea->setTextColor(previousColor);
923  fCoutTBTextArea->ensureCursorVisible ();
924 
925 #ifdef G4MULTITHREADED
926  UpdateCoutThreadFilter();
927 #endif
928  return 0;
929 }
930 
931 
937 G4int G4UIQt::ReceiveG4cerr (
938  const G4String& aString
939 )
940 {
941  if (!aString) return 0;
942 
943 #ifdef G4MULTITHREADED
944  G4AutoLock al(&ReceiveG4cerrMutex);
945 #endif
946  QStringList newStr;
947 
948  // Add to string
949 
950  G4UIOutputString txt = G4UIOutputString(QString((char*)aString.data()).trimmed(),
951  GetThreadPrefix(),
952  "error");
953  fG4OutputString.push_back(txt);
954 
955 #ifdef G4MULTITHREADED
956  QString result = FilterOutput(txt,fThreadsFilterComboBox->currentText(),fCoutFilter->text());
957 #else
958  QString result = FilterOutput(txt,"",fCoutFilter->text());
959 #endif
960  if (result.isEmpty()) {
961  return 0;
962  }
963 
964  // Suppress space, \n,\t,\r...
965  if (QString(aString.data()).trimmed() != "") {
968  // In case of Abort or Quit, the useful error message should be in the last error message !
969  QMessageBox::critical(fMainWindow, "Error",QString(fLastErrMessage.data())+"\n"+aString.data());
970  }
971  }
972  QColor previousColor = fCoutTBTextArea->textColor();
973  fCoutTBTextArea->setTextColor(Qt::red);
974  fCoutTBTextArea->append(result);
975  fCoutTBTextArea->setTextColor(previousColor);
976  fCoutTBTextArea->ensureCursorVisible ();
977 
978  if (QString(aString.data()).trimmed() != "") {
979  fLastErrMessage = aString;
980  }
981 #ifdef G4MULTITHREADED
982  UpdateCoutThreadFilter();
983 #endif
984  return 0;
985 }
986 
987 
988 G4String G4UIQt::GetThreadPrefix() {
989  G4String threadPrefix = "";
990 #ifdef G4MULTITHREADED
992  if(UI==NULL) return "";
993  if (UI->GetThreadCout() != NULL) {
994  threadPrefix = UI->GetThreadCout()->GetFullPrefixString().data();
995  if (UI->GetThreadCout()->GetPrefixString() == G4String("G4VIS")) {
996  return "G4VIS";
997  }
998  }
999 #endif
1000  return threadPrefix;
1001 }
1002 
1003 
1004 #ifdef G4MULTITHREADED
1005 void G4UIQt::UpdateCoutThreadFilter() {
1007  if(UI==NULL) return;
1008 
1009  // add "All" and "Master"
1010  if (fThreadsFilterComboBox->count() < 2) {
1011  if ( fThreadsFilterComboBox->findText("All", Qt::MatchExactly) == -1) {
1012  fThreadsFilterComboBox->addItem("All");
1013  }
1014  }
1015  if (fThreadsFilterComboBox->count() < 2) {
1016  if ( fThreadsFilterComboBox->findText("Master", Qt::MatchExactly) == -1) {
1017  fThreadsFilterComboBox->addItem("Master");
1018  }
1019  }
1020  // Add current Cout
1021  G4String prefix = GetThreadPrefix();
1022  if (prefix != "") {
1023  if ( fThreadsFilterComboBox->findText(prefix.data(), Qt::MatchExactly) == -1) {
1024  fThreadsFilterComboBox->addItem(prefix.data());
1025  }
1026  }
1027 }
1028 #endif
1029 
1030 
1036 void G4UIQt::AddMenu (
1037  const char* aName
1038 ,const char* aLabel
1039 )
1040 {
1041  if (aName == NULL) return;
1042  if (aLabel == NULL) return;
1043 
1044  QMenu *fileMenu = new QMenu(aLabel);
1045  fMainWindow->menuBar()->addMenu(fileMenu);
1046 
1047  AddInteractor (aName,(G4Interactor)fileMenu);
1048 }
1049 
1050 
1057 void G4UIQt::AddButton (
1058  const char* aMenu
1059 ,const char* aLabel
1060 ,const char* aCommand
1061 )
1062 {
1063  if(aMenu==NULL) return; // TO KEEP
1064  if(aLabel==NULL) return; // TO KEEP
1065  if(aCommand==NULL) return; // TO KEEP
1066 
1067  QMenu *parentTmp = (QMenu*)GetInteractor(aMenu);
1068 
1069  if(parentTmp==NULL) {
1070  G4UImanager* UImanager = G4UImanager::GetUIpointer();
1071  G4int verbose = UImanager->GetVerboseLevel();
1072 
1073  if (verbose >= 2) {
1074  G4cout << "Menu name " << aMenu<< " does not exist, please define it before using it."<< G4endl;
1075  }
1076  return;
1077  }
1078 
1079  // Find the command in the command tree
1081  if(UI==NULL) return;
1082  G4UIcommandTree * treeTop = UI->GetTree();
1083 
1084  G4String cmd = aCommand;
1085  G4int cmdEndPos = cmd.find_first_of(" \t");
1086  if(cmdEndPos!=G4int(std::string::npos)) {
1087  cmd.erase(cmdEndPos);
1088  }
1089 
1090  if(treeTop->FindPath(cmd) == NULL) {
1091  G4UImanager* UImanager = G4UImanager::GetUIpointer();
1092  G4int verbose = UImanager->GetVerboseLevel();
1093 
1094  if (verbose >= 2) {
1095  G4cout << "Warning: command '"<< cmd <<"' does not exist, please define it before using it."<< G4endl;
1096  }
1097  }
1098 
1099  QSignalMapper *signalMapper = new QSignalMapper(this);
1100  QAction *action = parentTmp->addAction(aLabel, signalMapper, SLOT(map()));
1101 
1102  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&)));
1103  signalMapper->setMapping(action, QString(aCommand));
1104 }
1105 
1106 
1107 
1108 
1112 void G4UIQt::AddIcon(const char* aLabel, const char* aIconFile, const char* aCommand, const char* aFileName){
1113  if(aLabel==NULL) return; // TO KEEP
1114  // special case, aCommand could be NULL if aIconFile is not user_icon
1115  if (aCommand==NULL) {
1116  if (std::string(aIconFile) == "user_icon") {
1117  return; // TO KEEP
1118  }
1119  }
1120  QPixmap pix;
1121  bool userToolBar = false;
1122 
1123  if (std::string(aIconFile) == "user_icon") {
1124  // try to open a file
1125  G4UImanager* UImanager = G4UImanager::GetUIpointer();
1126  pix = QPixmap(UImanager->FindMacroPath(aFileName).data());
1127  if (pix.isNull()) {
1128  G4int verbose = UImanager->GetVerboseLevel();
1129 
1130  if (verbose >= 2) {
1131  G4cout << "Warning: file '"<< aFileName <<"' is incorrect or does not exist, this command will not be build"<< G4endl;
1132  }
1133  return;
1134  }
1135  userToolBar = true;
1136  } else if (std::string(aIconFile) == "open") {
1137  const char * const xpm[]={
1138  "32 32 33 1",
1139  " c None",
1140  "+ c #09091E",
1141  "@ c #191B18",
1142  "# c #5F615F",
1143  "$ c #777977",
1144  "% c #AEB1AF",
1145  "& c #929491",
1146  "* c #515250",
1147  "= c #858784",
1148  "- c #333533",
1149  "; c #000100",
1150  "> c #272926",
1151  ", c #424341",
1152  "' c #696C6A",
1153  ") c #5F4927",
1154  "! c #583D18",
1155  "~ c #6E6A5B",
1156  "{ c #47351D",
1157  "] c #E0A554",
1158  "^ c #FFD67B",
1159  "/ c #EFB465",
1160  "( c #FDBF6C",
1161  "_ c #FFCD76",
1162  ": c #806238",
1163  "< c #362611",
1164  "[ c #0B0D0A",
1165  "} c #68471B",
1166  "| c #523E22",
1167  "1 c #B78A51",
1168  "2 c #A17B44",
1169  "3 c #D6A45E",
1170  "4 c #C29354",
1171  "5 c #A1A3A0",
1172  " ",
1173  " ",
1174  " +@@@# ",
1175  " $% +& * ",
1176  " #= $ -; ",
1177  " %>;+ ",
1178  " ,;;+ ",
1179  " &#$''#' >;;;+ ",
1180  " =)!)!!!!~ *#$'' ",
1181  " {]^/((_({- %%%%%%%%%%% ",
1182  " {(^_^^^^:<{{{{{{{{{{{{{[& ",
1183  " {/_/(((((/]]]]]]]]]]]/]!# ",
1184  " {/^(((((_^^^^^^^^^^^^^^:# ",
1185  " {/^(((_^^____________^^}$ ",
1186  " {/^(((((/////////////((!# ",
1187  " {/^/^_:<|||||||||||||||@@****1 ",
1188  " {/^/^(<[)||||||||||||||))!!}<; ",
1189  " {/^_(:|234444444444444444432)1 ",
1190  " {/_^/<)34444444444444444443}, ",
1191  " {/^(2{:41111111111111111142|5 ",
1192  " {3^3<:31111111111111111143}- ",
1193  " {/^2<:31111111111111111441|' ",
1194  " {_/<:41111111111111111143}, ",
1195  " {(4<:31111111111111111144!# ",
1196  " )4))44111111111111111144}, ",
1197  " )2<:31111111111111111144{# ",
1198  " @|:14444444444444444444}* ",
1199  " ;@434444444444444444434<# ",
1200  " ;[))))))))))))))))))))!~ ",
1201  " ++++++++++++++++++++++;% ",
1202  " ",
1203  " "}
1204  ;
1205  pix = QPixmap(xpm);
1206 
1207  } else if (std::string(aIconFile) == "save") {
1208  const char * const xpm[]={
1209  "32 32 24 1",
1210  " c None",
1211  "+ c #000200",
1212  "@ c #141E43",
1213  "# c #000C56",
1214  "$ c #494A47",
1215  "% c #636662",
1216  "& c #312F2A",
1217  "* c #191B19",
1218  "= c #002992",
1219  "- c #003DFF",
1220  "; c #041DA5",
1221  "> c #A8A9A3",
1222  ", c #FDFFFC",
1223  "' c #DDE0DD",
1224  ") c #818783",
1225  "! c #C9CBC8",
1226  "~ c #0116C3",
1227  "{ c #C5C8FA",
1228  "] c #6596FC",
1229  "^ c #A0B4F9",
1230  "/ c #0B2AFD",
1231  "( c #799BE3",
1232  "_ c #5F4826",
1233  ": c #D5D8D5",
1234  " ",
1235  " ",
1236  " +++++++++++++++++++++++++ ",
1237  " +@##+$%%%%%%%%%%%%%%%&*$%&+ ",
1238  " +=-;@>,,''',,,,,,,',,)&!,)+ ",
1239  " +;-~@>,,,,,,,,,,,,,,,>$!,)+ ",
1240  " +=-~@>,,,,,{]]]]]^,,,>*&$&+ ",
1241  " +=-~@>,,,,,'{^{^^{,,,>*#=#+ ",
1242  " +=-~@>,,,,,,,,,,,,,,,>@~/=+ ",
1243  " +=-~@>,,,{{{''''{',,,>@~-=+ ",
1244  " +=-~@>,,'^]]]]]]({,,,>@~-=+ ",
1245  " +=-~@>,,,{{{{{{{{{,,,>@~-=+ ",
1246  " +=-~@>,,,,,'{^{{^{,,,>@~-=+ ",
1247  " +=-~@>,,,,,]]]]]]],,,>@~-=+ ",
1248  " +=-~*>,,,,,,,,,,,,,,,>@~-=+ ",
1249  " +=-~@>,,,,,,,,,,,,,,,>@~-=+ ",
1250  " +=-/=$%%%%%%%%%%%%%%%$=/-=+ ",
1251  " +=---;###############;---=+ ",
1252  " +=---////////////////----=+ ",
1253  " +=----------------///----=+ ",
1254  " +=---=@##############@#--=+ ",
1255  " +=---@+++++++++++*%))_+~-=+ ",
1256  " +=---#+++++++++++&:,,>@~-=+ ",
1257  " +=---#+++++++++++$',,>@~-=+ ",
1258  " +=---#+++++++++++&!,,>@~-=+ ",
1259  " +=/--#+++++++++++&',,>@~-=+ ",
1260  " @;--#+++++++++++$',,>@~-=+ ",
1261  " @;;@+++++++++++*)!>%@=;#+ ",
1262  " @++++++++++++++*&**++@++ ",
1263  " ",
1264  " ",
1265  " "}
1266  ;
1267  pix = QPixmap(xpm);
1268  } else if (std::string(aIconFile) == "move") {
1269  const char * const xpm[]={
1270  "32 32 16 1",
1271  " c None",
1272  ". c #F1F1F1",
1273  "+ c #939393",
1274  "@ c #282828",
1275  "# c #787878",
1276  "$ c #000000",
1277  "% c #CCCCCC",
1278  "& c #1A1A1A",
1279  "* c #0D0D0D",
1280  "= c #5D5D5D",
1281  "- c #AEAEAE",
1282  "; c #BBBBBB",
1283  "> c #C9C9C9",
1284  ", c #D6D6D6",
1285  "' c #FFFFFF",
1286  ") c #999999",
1287  " ",
1288  " ",
1289  " ",
1290  " ",
1291  " .. ",
1292  " ++ ",
1293  " .@@. ",
1294  " #$$# ",
1295  " %&$$*% ",
1296  " =$$$$= ",
1297  " -**$$**- ",
1298  " %;%&*>;% ",
1299  " -% @& %- ",
1300  " ,=*; @& ;*=, ",
1301  " .#*$$> >$$*#. ",
1302  " ')&$$$$*@@ @@*$$$$&)' ",
1303  " ')&$$$$*@@ @@*$$$$&+' ",
1304  " .#*$$> >$$*#. ",
1305  " ,=*; @& ;*=, ",
1306  " -% @& %- ",
1307  " %;%&*>>% ",
1308  " -**$$**- ",
1309  " =$$$$= ",
1310  " %&$$*% ",
1311  " #$$# ",
1312  " .@@. ",
1313  " ++ ",
1314  " .. ",
1315  " ",
1316  " ",
1317  " ",
1318  " "}
1319  ;
1320  pix = QPixmap(xpm);
1321 
1322  } else if (std::string(aIconFile) == "rotate") {
1323  const char * const xpm[]={
1324  "32 32 27 1",
1325  " c None",
1326  ". c #003333",
1327  "+ c #000066",
1328  "@ c #1A1A1A",
1329  "# c #003399",
1330  "$ c #3333CC",
1331  "% c #000033",
1332  "& c #353535",
1333  "* c #434343",
1334  "= c #336699",
1335  "- c #3399FF",
1336  "; c #003366",
1337  "> c #5D5D5D",
1338  ", c #282828",
1339  "' c #3399CC",
1340  ") c #333333",
1341  "! c #3366CC",
1342  "~ c #333399",
1343  "{ c #505050",
1344  "] c #666666",
1345  "^ c #333366",
1346  "/ c #0033CC",
1347  "( c #3366FF",
1348  "_ c #336666",
1349  ": c #787878",
1350  "< c #868686",
1351  "[ c #6B6B6B",
1352  " .++@ ",
1353  " #$$%&* ",
1354  " =--; *>, ",
1355  " '-= )>& ",
1356  " !-', ,>* ",
1357  " !!=--= >* ",
1358  " =------!!~@&)@ ",
1359  " --------!*{{{*&, ",
1360  " -------=){*{{{>>{) ",
1361  " ,!-----= ){& ,&{{@",
1362  " ,*>!----= &>& )@",
1363  " ){>)~---= *]) @",
1364  " @*>, --! ,&@ ",
1365  " @{* '! ,-!=~^,@ ",
1366  " @& == {/(----!^ ",
1367  " _ ]:;(----' ",
1368  " ==_ >{+(----~ ",
1369  " !-!!======!!(((---! ",
1370  " ='--------------! ",
1371  " =!!!!'!!=; !-! ",
1372  " &<* !~ ",
1373  " @. *[* ; ",
1374  " ;+)>* ",
1375  " @@ ",
1376  " ",
1377  " ",
1378  " ",
1379  " ",
1380  " ",
1381  " ",
1382  " ",
1383  " "}
1384  ;
1385  pix = QPixmap(xpm);
1386 
1387  } else if (std::string(aIconFile) == "pick") {
1388  const char * const xpm[]={
1389  "32 32 2 1",
1390  " c None",
1391  ". c #000000",
1392  " ",
1393  " ",
1394  " ",
1395  " ",
1396  " ",
1397  " ",
1398  " ",
1399  " . ",
1400  " .. ",
1401  " ... ",
1402  " .... ",
1403  " ..... ",
1404  " ...... ",
1405  " ....... ",
1406  " ....... ",
1407  " ........ ",
1408  " ..... ",
1409  " ...... ",
1410  " .. .. ",
1411  " . .. ",
1412  " ... ",
1413  " .. ",
1414  " .. ",
1415  " ",
1416  " ",
1417  " ",
1418  " ",
1419  " ",
1420  " ",
1421  " ",
1422  " ",
1423  " "}
1424  ;
1425  pix = QPixmap(xpm);
1426  } else if (std::string(aIconFile) == "zoom_in") {
1427  const char * const xpm[]={
1428  "32 32 11 1",
1429  " c None",
1430  ". c #C9CBC8",
1431  "+ c #A8A9A3",
1432  "@ c #818783",
1433  "# c #D5D8D5",
1434  "$ c #9BCCCC",
1435  "% c #5FC7F4",
1436  "& c #FDFFFC",
1437  "* c #636662",
1438  "= c #9599CE",
1439  "- c #DDE0DD",
1440  " ",
1441  " ",
1442  " ",
1443  " ",
1444  " ",
1445  " .++@@++. ",
1446  " +++..#.+++ ",
1447  " .@+...++++#+@. ",
1448  " @$.%%+&&&@%..@ ",
1449  " ++.%%%+&&&*%%.++ ",
1450  " .+#%%%%+&&&*%%.#+ ",
1451  " ++..%%%+&&&*%%%.++ ",
1452  " +#.+++++&&&*++++.+ ",
1453  " @.+&&&&&&&&&&&&&+@ ",
1454  " @#+&&&&&&&&&&&&&+@ ",
1455  " @.+&&&&&&&&&&&&&+. ",
1456  " +++@***+&&&****@+. ",
1457  " ....++++&&&*++++.. ",
1458  " ++.===+&&&*%=.++ ",
1459  " @..==+&&&*=..@#& ",
1460  " .@+#.+&&&@-+@@*@ ",
1461  " +++.++++++ *+@* ",
1462  " .+@@@++. @**+* ",
1463  " .*@*+* ",
1464  " .*@*+* ",
1465  " +*@@* ",
1466  " .**+ ",
1467  " ",
1468  " ",
1469  " ",
1470  " ",
1471  " "}
1472  ;
1473  pix = QPixmap(xpm);
1474  } else if (std::string(aIconFile) == "zoom_out") {
1475  const char * const xpm[]={
1476  "32 32 11 1",
1477  " c None",
1478  ". c #C9CBC8",
1479  "+ c #A8A9A3",
1480  "@ c #818783",
1481  "# c #D5D8D5",
1482  "$ c #5FC7F4",
1483  "% c #9BCCCC",
1484  "& c #FDFFFC",
1485  "* c #636662",
1486  "= c #9599CE",
1487  "- c #DDE0DD",
1488  " ",
1489  " ",
1490  " ",
1491  " ",
1492  " ",
1493  " .++@@++. ",
1494  " +++..#.+++ ",
1495  " .@+..$$$$.#+@. ",
1496  " @%.$$$$$$$$..@ ",
1497  " ++.$$$$$$$$$$.++ ",
1498  " .+#$$$$$$$$$$$.#+ ",
1499  " ++..$$$$$$$$$$$.++ ",
1500  " +#.+++++++++++++.+ ",
1501  " @.+&&&&&&&&&&&&&+@ ",
1502  " @#+&&&&&&&&&&&&&+@ ",
1503  " @.+&&&&&&&&&&&&&+. ",
1504  " +++@***********@+. ",
1505  " ....++++++++++++.. ",
1506  " ++.===$$$$$$=.++ ",
1507  " @..===$$$$=..@#& ",
1508  " .@+#.$$$..-+@@*@ ",
1509  " +++#--.+++ *+@* ",
1510  " .+@@@++. @**+* ",
1511  " .*@*+* ",
1512  " .*@*+* ",
1513  " +*@@* ",
1514  " .**+ ",
1515  " ",
1516  " ",
1517  " ",
1518  " ",
1519  " "}
1520  ;
1521  pix = QPixmap(xpm);
1522  } else if (std::string(aIconFile) == "wireframe") {
1523  const char * const xpm[]={
1524  "32 32 24 1",
1525  " c None",
1526  "+ c #E4E4E4",
1527  "@ c #D5D5D5",
1528  "# c #E1E1E1",
1529  "$ c #E7E7E7",
1530  "% c #D8D8D8",
1531  "& c #A7A7A7",
1532  "* c #000000",
1533  "= c #989898",
1534  "- c #8A8A8A",
1535  "; c #B5B5B5",
1536  "> c #1B1B1B",
1537  ", c #676767",
1538  "' c #959595",
1539  ") c #4A4A4A",
1540  "! c #878787",
1541  "~ c #D3D3D3",
1542  "{ c #C4C4C4",
1543  "] c #A4A4A4",
1544  "^ c #5B5B5B",
1545  "/ c #B3B3B3",
1546  "( c #787878",
1547  "_ c #C7C7C7",
1548  ": c #585858",
1549  " ",
1550  " +@@# ",
1551  " $%@@@@@&****=+ ",
1552  " +&********&@-***; ",
1553  " +@@@&**&@@@@@@$ @*-&>&+ ",
1554  " +*****&+ %*@ ,**'# ",
1555  " @***)!~ @*{&*****+ ",
1556  " @*!]***&+ +-*^**'~!*@ ",
1557  " @*~ +@&**&@@@@@@&****&+ ~*@ ",
1558  " @*@ +&********&-*= @*@ ",
1559  " @*@ $%@-*-@$ @*@ @*@ ",
1560  " @*@ @*@ %*% @*@ ",
1561  " @*@ %*% %*% @*@ ",
1562  " @*@ %*% %*% @*@ ",
1563  " @*@ %*% %*% @*@ ",
1564  " @*@ %*% %*% @*@ ",
1565  " @*@ %*% %*% @*@ ",
1566  " @*@ @*@ %*% @*@ ",
1567  " @*@ =*-+ @*@ @*@ ",
1568  " @*@ $%@@&****&@-*-+ @*@ ",
1569  " @*@ $@&*****&@@&******&~~!*@ ",
1570  " @*{/***&@@%$ $@-*-&*****+ ",
1571  " @*)*)(-~ @*@ ~)**] ",
1572  " +*******&@@@@+ %*_+]**] ",
1573  " +@@@@@&******&@%+_*^**]# ",
1574  " $%@@@&****:**&+ ",
1575  " +%@&**& ",
1576  " ++ ",
1577  " ",
1578  " ",
1579  " ",
1580  " "}
1581  ;
1582  pix = QPixmap(xpm);
1583  } else if (std::string(aIconFile) == "solid") {
1584  const char * const xpm[]={
1585  "32 32 33 1",
1586  " c None",
1587  "+ c #C2DEDE",
1588  "@ c #B5D7DF",
1589  "# c #ACD6E6",
1590  "$ c #60C0EC",
1591  "% c #4EB7EE",
1592  "& c #53B9ED",
1593  "* c #82CEEA",
1594  "= c #CFDDDA",
1595  "- c #94C9E8",
1596  "; c #0960FF",
1597  "> c #0943FF",
1598  ", c #0949FF",
1599  "' c #3CB3F0",
1600  ") c #71C7EB",
1601  "! c #73CBE5",
1602  "~ c #D3DDDB",
1603  "{ c #C4DDDE",
1604  "] c #B7D5DF",
1605  "^ c #2DACF5",
1606  "/ c #59C1ED",
1607  "( c #5FC0ED",
1608  "_ c #85CEE9",
1609  ": c #096BFF",
1610  "< c #2AACF6",
1611  "[ c #5CBEEC",
1612  "} c #7ACAE4",
1613  "| c #73CAEB",
1614  "1 c #71C8E5",
1615  "2 c #D1DDDA",
1616  "3 c #CBDDD9",
1617  "4 c #67C1EB",
1618  "5 c #80CDEA",
1619  " ",
1620  " ",
1621  " +@@@@@@#$%&*= ",
1622  " +-;>>>>>>>>>,')!~ ",
1623  " {]@@-;>>>>>>>>>>>>^/(_= ",
1624  " {:>>>>>>>>>>>>>>>>><//[)!= ",
1625  " ]>>>>>>>>>>>>>>>>>><////[)} ",
1626  " @>>>>>>>>>>>>>>>>>><//////| ",
1627  " @>>>>>>>>>>>>>>>>>><//////| ",
1628  " @>>>>>>>>>>>>>>>>>><//////| ",
1629  " @>>>>>>>>>>>>>>>>>><//////| ",
1630  " @>>>>>>>>>>>>>>>>>><//////| ",
1631  " @>>>>>>>>>>>>>>>>>><//////| ",
1632  " @>>>>>>>>>>>>>>>>>><//////| ",
1633  " @>>>>>>>>>>>>>>>>>><//////| ",
1634  " @>>>>>>>>>>>>>>>>>><//////| ",
1635  " @>>>>>>>>>>>>>>>>>><//////| ",
1636  " @>>>>>>>>>>>>>>>>>><//////| ",
1637  " @>>>>>>>>>>>>>>>>>><//////| ",
1638  " @>>>>>>>>>>>>>>>>>><//////| ",
1639  " @>>>>>>>>>>>>>>>>>><//////| ",
1640  " @>>>>>>>>>>>>>>>>>></////[1 ",
1641  " @>>>>>>>>>>>>>>>>>><////[*2 ",
1642  " {:>>>>>>>>>>>>>>>>><//[)12 ",
1643  " +@@@@@-;>>>>>>>>>><[)13 ",
1644  " {]@@@-;>>>,'*3 ",
1645  " +@@#452 ",
1646  " ",
1647  " ",
1648  " ",
1649  " ",
1650  " "}
1651  ;
1652  pix = QPixmap(xpm);
1653  } else if (std::string(aIconFile) == "hidden_line_removal") {
1654  const char * const xpm[]={
1655  "32 32 15 1",
1656  " c None",
1657  "+ c #D5D5D5",
1658  "@ c #C7C7C7",
1659  "# c #9C9C9C",
1660  "$ c #000000",
1661  "% c #8E8E8E",
1662  "& c #808080",
1663  "* c #A9A9A9",
1664  "= c #D8D8D8",
1665  "- c #CACACA",
1666  "; c #181818",
1667  "> c #9F9F9F",
1668  ", c #ACACAC",
1669  "' c #B9B9B9",
1670  ") c #555555",
1671  " ",
1672  " +@@+ ",
1673  " +@@@@@@#$$$$%+ ",
1674  " +#$$$$$$$$#@&$$$* ",
1675  " =-@@#$$#@@@@@-= @$&#;>= ",
1676  " =$$$$$#+ -$@ *$$%+ ",
1677  " -$&@-= -$- #$$$= ",
1678  " -$@ -$- +&$- ",
1679  " @$@ @$@ @$@ ",
1680  " @$@ @$@ @$@ ",
1681  " @$@ @$@ @$@ ",
1682  " @$@ @$@ @$@ ",
1683  " @$@ @$@ @$@ ",
1684  " @$@ @$@ @$@ ",
1685  " @$@ @$@ @$@ ",
1686  " @$@ @$@ @$@ ",
1687  " @$@ @$@ @$@ ",
1688  " @$@ @$@ @$@ ",
1689  " @$@ @$@ @$@ ",
1690  " @$@ @$@ @$@ ",
1691  " @$@ @$@ @$@ ",
1692  " @$@ @$@ #$= ",
1693  " -$&@@@-= -$- =>;, ",
1694  " =$$$$$$$#@@@-= -$'+#$$, ",
1695  " =-@@@@#$$$$$$#@-+'$)$$#+ ",
1696  " =-@@@#$$$$)$$#+ ",
1697  " +@@#$$# ",
1698  " ++ ",
1699  " ",
1700  " ",
1701  " ",
1702  " "}
1703  ;
1704  pix = QPixmap(xpm);
1705  } else if (std::string(aIconFile) == "hidden_line_and_surface_removal") {
1706  const char * const xpm[]={
1707  "32 32 40 1",
1708  " c None",
1709  "+ c #FFFFFF",
1710  "@ c #89A2E9",
1711  "# c #5378E3",
1712  "$ c #A2B5ED",
1713  "% c #5379E3",
1714  "& c #5076E3",
1715  "* c #3E69E4",
1716  "= c #0C43F8",
1717  "- c #043FFE",
1718  "; c #CDD9ED",
1719  "> c #BDCDE9",
1720  ", c #FBFCFC",
1721  "' c #406AE4",
1722  ") c #0439FE",
1723  "! c #0137FF",
1724  "~ c #4F75E3",
1725  "{ c #9EB5E3",
1726  "] c #829FE0",
1727  "^ c #B6C6E7",
1728  "/ c #9DB4E3",
1729  "( c #7E9CE0",
1730  "_ c #B2C3E9",
1731  ": c #7E9AE0",
1732  "< c #86A2E1",
1733  "[ c #CAD6ED",
1734  "} c #5177E3",
1735  "| c #829CE0",
1736  "1 c #BCCCE9",
1737  "2 c #3A67E6",
1738  "3 c #0A43FA",
1739  "4 c #95ACE1",
1740  "5 c #BBCBE9",
1741  "6 c #A9BBE5",
1742  "7 c #96AFE1",
1743  "8 c #BDCBE9",
1744  "9 c #4067E4",
1745  "0 c #6485E5",
1746  "a c #E3EAF3",
1747  "b c #CAD6F3",
1748  " ",
1749  " ",
1750  " ++++ ",
1751  " ++++++++@#$+++ ",
1752  " ++@%####&*=-#+;>, ",
1753  " +++++@'=)))))))!)~+{]^++ ",
1754  " +$%&*=)!!!!!!!!!)~+/(]_+++ ",
1755  " +#-))!!!!!!!!!!!)~+/(::<[+ ",
1756  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1757  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1758  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1759  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1760  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1761  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1762  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1763  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1764  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1765  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1766  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1767  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1768  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1769  " +#)!!!!!!!!!!!!!!}+/:::|1+ ",
1770  " +$#}}~23!!!!!!!!)~+/(]45, ",
1771  " +++++++@#}}~23!!)~+678++ ",
1772  " ++++++@#~90+a++ ",
1773  " ++++b++ ",
1774  " ++ ",
1775  " ",
1776  " ",
1777  " ",
1778  " ",
1779  " "}
1780  ;
1781  pix = QPixmap(xpm);
1782  } else if (std::string(aIconFile) == "perspective") {
1783  const char * const xpm[]={
1784  "32 32 3 1",
1785  " c None",
1786  ". c #D5D8D5",
1787  "+ c #000000",
1788  " ",
1789  " ",
1790  " ",
1791  " ",
1792  " ",
1793  " ................ ",
1794  " ....+++++++++++++++. ",
1795  " ...++++..+.........+++. ",
1796  " ..++..............++..+. ",
1797  " .+++++++++++++++++.. .+. ",
1798  " .+...............+. .+. ",
1799  " .+. .+. .+. .+. ",
1800  " .+. .+. .+. .+. ",
1801  " .+. .+. .+. .+. ",
1802  " .+. .+. .+. .+. ",
1803  " .+. .+. .+. .+. ",
1804  " .+. .+. .+. .+. ",
1805  " .+. .+. .+. .+. ",
1806  " .+. .+. .+. .+. ",
1807  " .+. .+......+....+. ",
1808  " .+. ..++++++.+.++++. ",
1809  " .+. .++.......+...+.. ",
1810  " .+. .++. .+..++. ",
1811  " .+. ..+.. .+..+. ",
1812  " .+..++. .+.+. ",
1813  " .+.++. .+++. ",
1814  " .+++.............++. ",
1815  " .+++++++++++++++++. ",
1816  " ................... ",
1817  " ",
1818  " ",
1819  " "}
1820  ;
1821  pix = QPixmap(xpm);
1822  } else if (std::string(aIconFile) == "ortho") {
1823  const char * const xpm[]={
1824  "32 32 3 1",
1825  " c None",
1826  ". c #D5D8D5",
1827  "@ c #000000",
1828  " ",
1829  " ",
1830  " ",
1831  " ................... ",
1832  " ..@@@@@@@@@@@@@@@@@. ",
1833  " ..@@@.............@@@. ",
1834  " ..@@.@. ..@..@. ",
1835  " ..@@ ..@. .@@...@. ",
1836  " ..@@..............@@.. .@. ",
1837  " .@@@@@@@@@@@@@@@@@.. .@. ",
1838  " .@...............@. .@. ",
1839  " .@. .@. .@. .@. ",
1840  " .@. .@. .@. .@. ",
1841  " .@. .@. .@. .@. ",
1842  " .@. .@. .@. .@. ",
1843  " .@. .@. .@. .@. ",
1844  " .@. .@. .@. .@. ",
1845  " .@. .@. .@. .@. ",
1846  " .@. .@. .@. .@. ",
1847  " .@. .@. .@. .@. ",
1848  " .@. .@. .@. .@. ",
1849  " .@. .@........@......@. ",
1850  " .@. .@@@@@@@@@.@.@@@@@@. ",
1851  " .@. .@@+........@....@@.. ",
1852  " .@...@. .@...@... ",
1853  " .@.@@. .@.@@ . ",
1854  " .@@@.............@@@.. ",
1855  " .@@@@@@@@@@@@@@@@@... ",
1856  " ................... ",
1857  " ",
1858  " ",
1859  " "}
1860  ;
1861  pix = QPixmap(xpm);
1862  } else {
1863  G4UImanager* UImanager = G4UImanager::GetUIpointer();
1864  G4int verbose = UImanager->GetVerboseLevel();
1865 
1866  if (verbose >= 2) {
1867  G4cout << "Parameter"<< aIconFile <<" not defined"<< G4endl;
1868  }
1869  return;
1870  }
1871  QToolBar *currentToolbar = NULL;
1872  if (userToolBar) {
1873  if (fToolbarUser == NULL) {
1874  fToolbarUser = new QToolBar();
1875  fToolbarUser->setIconSize (QSize(20,20));
1876  fMainWindow->addToolBar(Qt::TopToolBarArea, fToolbarUser);
1877  }
1878  currentToolbar = fToolbarUser;
1879  } else {
1880  if (fToolbarApp == NULL) {
1881  fToolbarApp = new QToolBar();
1882  fToolbarApp->setIconSize (QSize(20,20));
1883  fMainWindow->addToolBar(Qt::TopToolBarArea, fToolbarApp);
1884  }
1885  currentToolbar = fToolbarApp;
1886  }
1887 
1888  QSignalMapper *signalMapper = new QSignalMapper(this);
1889  QAction *action = currentToolbar->addAction(pix,aLabel, signalMapper, SLOT(map()));
1890 
1891 
1892  // special cases :"open"
1893  if (std::string(aIconFile) == "open") {
1894  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(OpenIconCallback(const QString &)));
1895  QString txt = aCommand + fStringSeparator + aLabel;
1896  signalMapper->setMapping(action, QString(txt));
1897 
1898  // special cases :"save"
1899  } else if (std::string(aIconFile) == "save") {
1900  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(SaveIconCallback(const QString&)));
1901  QString txt = aCommand + fStringSeparator + aLabel;
1902  signalMapper->setMapping(action, QString(txt));
1903 
1904  // special cases : cursor style
1905  } else if ((std::string(aIconFile) == "move") ||
1906  (std::string(aIconFile) == "rotate") ||
1907  (std::string(aIconFile) == "pick") ||
1908  (std::string(aIconFile) == "zoom_out") ||
1909  (std::string(aIconFile) == "zoom_in")) {
1910  action->setCheckable(TRUE);
1911  action->setChecked(TRUE);
1912  action->setData(aIconFile);
1913 
1914  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ChangeCursorStyle(const QString&)));
1915  signalMapper->setMapping(action, QString(aIconFile));
1916 
1917  if (std::string(aIconFile) == "move") {
1918  SetIconMoveSelected();
1919  }
1920  if (std::string(aIconFile) == "rotate") {
1921  SetIconRotateSelected();
1922  }
1923  if (std::string(aIconFile) == "pick") {
1924  SetIconPickSelected();
1925  }
1926  if (std::string(aIconFile) == "zoom_in") {
1927  SetIconZoomInSelected();
1928  }
1929  if (std::string(aIconFile) == "zoom_out") {
1930  SetIconZoomOutSelected();
1931  }
1932 
1933  // special case : surface style
1934  } else if ((std::string(aIconFile) == "hidden_line_removal") ||
1935  (std::string(aIconFile) == "hidden_line_and_surface_removal") ||
1936  (std::string(aIconFile) == "solid") ||
1937  (std::string(aIconFile) == "wireframe")) {
1938  action->setCheckable(TRUE);
1939  action->setChecked(TRUE);
1940  action->setData(aIconFile);
1941  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ChangeSurfaceStyle(const QString&)));
1942  signalMapper->setMapping(action, QString(aIconFile));
1943 
1944  if (std::string(aIconFile) == "hidden_line_removal") {
1945  SetIconHLRSelected();
1946  }
1947  if (std::string(aIconFile) == "hidden_line_and_surface_removal") {
1948  SetIconHLHSRSelected();
1949  }
1950  if (std::string(aIconFile) == "solid") {
1951  SetIconSolidSelected();
1952  }
1953  if (std::string(aIconFile) == "wireframe") {
1954  SetIconWireframeSelected();
1955  }
1956 
1957  // special case : perspective/ortho
1958  } else if ((std::string(aIconFile) == "perspective") ||
1959  (std::string(aIconFile) == "ortho")) {
1960  action->setCheckable(TRUE);
1961  action->setChecked(TRUE);
1962  action->setData(aIconFile);
1963  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ChangePerspectiveOrtho(const QString&)));
1964  signalMapper->setMapping(action, QString(aIconFile));
1965 
1966  if (std::string(aIconFile) == "perspective") {
1967  SetIconPerspectiveSelected();
1968  }
1969  if (std::string(aIconFile) == "ortho") {
1970  SetIconOrthoSelected();
1971  }
1972 
1973  } else {
1974 
1975  // Find the command in the command tree
1977  if(UI==NULL) return;
1978  G4UIcommandTree * treeTop = UI->GetTree();
1979  if (aCommand != NULL) {
1980  if(treeTop->FindPath(aCommand) == NULL) {
1981  G4UImanager* UImanager = G4UImanager::GetUIpointer();
1982  G4int verbose = UImanager->GetVerboseLevel();
1983 
1984  if (verbose >= 2) {
1985  G4cout << "Warning: command '"<< aCommand <<"' does not exist, please define it before using it."<< G4endl;
1986  }
1987  }
1988  }
1989 
1990  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&)));
1991  signalMapper->setMapping(action, QString(aCommand));
1992  }
1993 }
1994 
1995 
1996 
1997 void G4UIQt::ActivateCommand(
1998  G4String newCommand
1999 )
2000 {
2001  if (!fHelpTreeWidget) {
2002  return;
2003  }
2004  // Look for the choosen command "newCommand"
2005  size_t i = newCommand.index(" ");
2006  G4String targetCom ="";
2007  if( i != std::string::npos )
2008  {
2009  G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
2010  newValue.strip(G4String::both);
2011  targetCom = ModifyToFullPathCommand( newValue );
2012  }
2013  if (targetCom != "") {
2014  OpenHelpTreeOnCommand(targetCom.data());
2015  }
2016 
2017  fUITabWidget->setCurrentWidget(fHelpTBWidget);
2018 }
2019 
2020 
2021 
2028 void G4UIQt::InitHelpTreeAndVisParametersWidget()
2029 {
2030 
2031  if (! fHelpTreeWidget ) {
2032  fHelpTreeWidget = new QTreeWidget();
2033  }
2034 
2035  // build widget
2036  fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
2037  QStringList labels;
2038  labels << QString("Command");
2039  fHelpTreeWidget->setHeaderLabels(labels);
2040 
2041 
2042  connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback()));
2043  connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback()));
2044 
2045 }
2052 void G4UIQt::FillHelpTree()
2053 {
2054  if (! fHelpTreeWidget ) {
2055  InitHelpTreeAndVisParametersWidget();
2056  }
2057 
2058  QString searchText = fHelpLine->text();
2059 
2060  if (searchText =="") {
2061  // clear old help tree
2062  // fHelpTreeWidget->clear();
2063  } else {
2064  return;
2065  }
2066 
2067  if (fParameterHelpLabel) {
2068  fParameterHelpLabel->setText("Choose a command in the command tree");
2069  fParameterHelpTable->setVisible(false);
2070  }
2071 
2072  if (fHelpLine) {
2073 #if QT_VERSION < 0x040200
2074  fHelpLine->clear();
2075 #else
2076  fHelpLine->setText("");
2077 #endif
2078  }
2079 
2081  if(UI==NULL) return;
2082  G4UIcommandTree * treeTop = UI->GetTree();
2083 
2084  G4int treeSize = treeTop->GetTreeEntry();
2085  QTreeWidgetItem * newItem = NULL;
2086  QString commandText = "";
2087  for (int a=0;a<treeSize;a++) {
2088  // Creating new item
2089  newItem = NULL;
2090 
2091  commandText = QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed();
2092 
2093  // if already exist, don't create it !
2094  for (int b=0;b<fHelpTreeWidget->topLevelItemCount();b++) {
2095  if (!newItem)
2096  newItem = FindTreeItem(fHelpTreeWidget->topLevelItem(b),commandText);
2097  }
2098 
2099  if (newItem == NULL) {
2100 
2101  newItem = new QTreeWidgetItem();
2102  newItem->setText(0,GetShortCommandPath(commandText));
2103  fHelpTreeWidget->addTopLevelItem(newItem);
2104  }
2105 
2106  // look for childs
2107  CreateHelpTree(newItem,treeTop->GetTree(a+1));
2108  }
2109 
2110 }
2111 
2112 
2113 
2118 void G4UIQt::CreateHelpTree(
2119  QTreeWidgetItem *aParent
2120 ,G4UIcommandTree *aCommandTree
2121 )
2122 {
2123  if (aParent == NULL) return;
2124  if (aCommandTree == NULL) return;
2125 
2126 
2127  // Creating new item
2128  QTreeWidgetItem * newItem;
2129 
2130  QString commandText = "";
2131  // Get the Sub directories
2132  for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
2133 
2134  commandText = QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed();
2135 
2136  // if already exist, don't create it !
2137  newItem = FindTreeItem(aParent,commandText);
2138  if (newItem == NULL) {
2139  newItem = new QTreeWidgetItem();
2140  newItem->setText(0,GetShortCommandPath(commandText));
2141  aParent->addChild(newItem);
2142  }
2143  CreateHelpTree(newItem,aCommandTree->GetTree(a+1));
2144  }
2145 
2146  // Get the Commands
2147 
2148  for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
2149 
2150  QStringList stringList;
2151  commandText = QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed();
2152 
2153  // if already exist, don't create it !
2154  newItem = FindTreeItem(aParent,commandText);
2155  if (newItem == NULL) {
2156  newItem = new QTreeWidgetItem();
2157  newItem->setText(0,GetShortCommandPath(commandText));
2158  aParent->addChild(newItem);
2159 
2160 #if QT_VERSION < 0x040202
2161  fHelpTreeWidget->setItemExpanded(newItem,false);
2162 #else
2163  newItem->setExpanded(false);
2164 #endif
2165  }
2166  }
2167 }
2168 
2169 
2170 
2171 
2177 bool G4UIQt::CreateVisCommandGroupAndToolBox(
2178  G4UIcommand* aCommand
2179 ,QWidget* aParent
2180 ,int aDepthLevel
2181 ,bool isDialog
2182 )
2183 {
2184  QString commandText = QString((char*)(aCommand->GetCommandPath().data())).section("/",-aDepthLevel);
2185 
2186  if (commandText == NULL) {
2187  return false;
2188  }
2189 
2190  // Look if groupBox is create
2191  // QGroupBox* gBoxCommandWidget;
2192  QWidget* newParentWidget = NULL;
2193  bool found = false;
2194  QString commandSection = commandText.left(commandText.indexOf("/"));
2195 
2196  if (aDepthLevel == 1) {
2197  QToolBox* currentParent = dynamic_cast<QToolBox*>(aParent);
2198  if (currentParent != 0){
2199 
2200  // already exists ?
2201  for (int a=0; a<currentParent->count(); a++) {
2202  if (currentParent->itemText(a) == commandSection) {
2203  found = true;
2204  newParentWidget = currentParent->widget(a);
2205  }
2206  }
2207  }
2208  // Not found ? create it
2209  if (!found) {
2210  newParentWidget = new QGroupBox();
2211  newParentWidget->setLayout(new QVBoxLayout());
2212  if (currentParent != 0){
2213  currentParent->addItem(newParentWidget,commandSection);
2214  } else {
2215  if (!aParent->layout()) {
2216  aParent->setLayout(new QVBoxLayout());
2217  }
2218  aParent->layout()->addWidget(newParentWidget);
2219  }
2220 
2221  if (commandText.indexOf("/") == -1) {
2222 
2223  // Guidance
2224  QString guidance;
2225  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
2226  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
2227  guidance += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
2228  }
2229  newParentWidget->setToolTip(guidance);
2230  }
2231 
2232  QScrollArea* sc = dynamic_cast<QScrollArea*>(newParentWidget->parent()->parent());
2233  if (sc != 0) {
2234  sc->ensureWidgetVisible(newParentWidget);
2235 
2236  }
2237  }
2238  } else {
2239 
2240  // try to know if this level is already there
2241  QGroupBox* currentParent = dynamic_cast<QGroupBox*>(aParent);
2242  if (currentParent != 0){
2243 
2244  // if depth==2, then we add a [more parameters inside] to the toolBoxItem parent
2245  // QGroupBox > QWidget > QScrollArea > QToolBox
2246  if (aDepthLevel == 2){
2247  QToolBox* parentToolBox = dynamic_cast<QToolBox*>(currentParent->parent()->parent()->parent());
2248  if (parentToolBox != 0) {
2249  // parentToolBox->setItemText(parentToolBox->indexOf(currentParent),"[more parameters inside]");
2250  }
2251  }
2252  for (int a=0; a<aParent->layout()->count(); a++) {
2253  QGroupBox* gb = dynamic_cast<QGroupBox*>(aParent->layout()->itemAt(a)->widget());
2254  if (gb != 0) {
2255  if (gb->title() == commandSection) {
2256  found = true;
2257  newParentWidget = gb;
2258  }
2259  }
2260  }
2261  }
2262 
2263  // Not found ? create it
2264  if (!found) {
2265  newParentWidget = new QGroupBox();
2266  newParentWidget->setLayout(new QVBoxLayout());
2267  if (!aParent->layout()) {
2268  aParent->setLayout(new QVBoxLayout());
2269  }
2270  aParent->layout()->addWidget(newParentWidget);
2271 
2272  // set toolTip
2273  // Guidance
2274  QString guidance;
2275  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
2276  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
2277  guidance += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
2278  }
2279  newParentWidget->setToolTip(guidance);
2280  }
2281  }
2282 
2283  // fill command groupbox
2284  if (commandText.indexOf("/") == -1) {
2285  if (CreateCommandWidget(aCommand, newParentWidget,isDialog)) {
2286  return true;
2287  }
2288  } else {
2289  CreateVisCommandGroupAndToolBox(aCommand,newParentWidget, aDepthLevel-1,isDialog);
2290  }
2291 
2292  return true;
2293 }
2294 
2295 
2296 
2302 bool G4UIQt::CreateCommandWidget(G4UIcommand* aCommand, QWidget* aParent, bool isDialog) {
2303 
2304  if (aCommand == NULL) {
2305  return false;
2306  }
2307 
2308 
2309  // parameters
2310  G4int n_parameterEntry = aCommand->GetParameterEntries();
2311  if( n_parameterEntry > 0 ) {
2312  G4UIparameter *param;
2313 
2314  // Re-implementation of G4UIparameter.cc
2315  QWidget* paramWidget = new QWidget();
2316  QGridLayout* gridLayout = new QGridLayout();
2317  paramWidget->setLayout(gridLayout);
2318 
2319  // Special case for colour, try to display a color chooser if we found red/green/blue parameter
2320  unsigned int nbColorParameter = 0;
2321  bool isStillColorParameter = false;
2322  bool isColorDialogAdded = false;
2323  QLabel* redLabel = NULL;
2324  QLabel* greenLabel = NULL;
2325  QString redDefaultStr = "";
2326  QString greenDefaultStr = "";
2327  QString blueDefaultStr = "";
2328  QWidget* redInput = NULL;
2329  QWidget* greenInput = NULL;
2330 
2331  for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
2332  QString txt;
2333  param = aCommand->GetParameter(i_thParameter);
2334  QLabel* label = new QLabel(QString((char*)(param->GetParameterName()).data()));
2335 
2336  if ((label->text() == "red") || (label->text() == "red_or_string")){
2337  nbColorParameter ++;
2338  isStillColorParameter = true;
2339  } else if ((label->text() == "green") && isStillColorParameter) {
2340  nbColorParameter ++;
2341  } else if ((label->text() == "blue") && isStillColorParameter) {
2342  nbColorParameter ++;
2343  } else if (!isColorDialogAdded) {
2344 
2345  // not following red/green/blue parameters ?
2346  if (nbColorParameter == 1) {
2347  gridLayout->addWidget(redLabel,i_thParameter-1,0);
2348  gridLayout->addWidget(redInput,i_thParameter-1,1);
2349  } else if (nbColorParameter == 2) {
2350  gridLayout->addWidget(redLabel,i_thParameter-2,0);
2351  gridLayout->addWidget(redInput,i_thParameter-2,1);
2352  gridLayout->addWidget(greenLabel,i_thParameter-1,0);
2353  gridLayout->addWidget(greenInput,i_thParameter-1,1);
2354  }
2355  nbColorParameter = 0;
2356  }
2357  // Check parameter type, could be NULL if not found
2358  QWidget* input = NULL;
2359  if ((QString(QChar(param->GetParameterType())) == "d") || (QString(QChar(param->GetParameterType())) == "i")) {
2360  input = new QLineEdit();
2361  // set default value
2362  dynamic_cast<QLineEdit*>(input)->setText(QString((char*)(param->GetDefaultValue()).data()));
2363 
2364  if (((label->text() == "red") || (label->text() == "red_or_string")) && isStillColorParameter) {
2365  redDefaultStr = QString((char*)(param->GetDefaultValue()).data());
2366  } else if ((label->text() == "green") && isStillColorParameter) {
2367  greenDefaultStr = QString((char*)(param->GetDefaultValue()).data());
2368  } else if ((label->text() == "green") && isStillColorParameter) {
2369  blueDefaultStr = QString((char*)(param->GetDefaultValue()).data());
2370  }
2371 
2372  } else if (QString(QChar(param->GetParameterType())) == "b") {
2373  input = new QWidget();
2374  QHBoxLayout* layout = new QHBoxLayout();
2375  input->setLayout(layout);
2376 
2377  QButtonGroup* buttons = new QButtonGroup();
2378  QRadioButton* radioOff = new QRadioButton("0");
2379  QRadioButton* radioOn = new QRadioButton("1");
2380  buttons->addButton(radioOn);
2381  buttons->addButton(radioOff);
2382  layout->addWidget(radioOn);
2383  layout->addWidget(radioOff);
2384 
2385  // set default value
2386  QString defaultValue = QString((char*)(param->GetDefaultValue()).data());
2387  if (defaultValue == "0") {
2388  radioOff->setChecked(true);
2389  } else if (defaultValue == "1") {
2390  radioOn->setChecked(true);
2391  }
2392  } else if ((QString(QChar(param->GetParameterType())) == "s") && (!param->GetParameterCandidates().isNull())) {
2393  input = new QComboBox();
2394  QString candidates = QString((char*)(param->GetParameterCandidates()).data());
2395  QStringList list = candidates.split (" ");
2396 
2397  // add all candidates to widget
2398  QString defaultValue = QString((char*)(param->GetDefaultValue()).data());
2399  for (int a=0; a<list.size(); a++) {
2400  dynamic_cast<QComboBox*>(input)->addItem(list.at(a));
2401  if (list.at(a) == defaultValue) {
2402  dynamic_cast<QComboBox*>(input)->setCurrentIndex(a);
2403  }
2404  }
2405 
2406  } else if ((QString(QChar(param->GetParameterType())) == "s")) { // string
2407  input = new QLineEdit();
2408  // set default value
2409  dynamic_cast<QLineEdit*>(input)->setText(QString((char*)(param->GetDefaultValue()).data()));
2410 
2411  } else if ((QString(QChar(param->GetParameterType())) == "c")) { // on/off
2412  input = new QWidget();
2413  QHBoxLayout* layout = new QHBoxLayout();
2414  input->setLayout(layout);
2415 
2416  QButtonGroup* buttons = new QButtonGroup();
2417  QRadioButton* radioOff = new QRadioButton("off");
2418  QRadioButton* radioOn = new QRadioButton("on");
2419  buttons->addButton(radioOn);
2420  buttons->addButton(radioOff);
2421  layout->addWidget(radioOn);
2422  layout->addWidget(radioOff);
2423 
2424  // set default value
2425  QString defaultValue = QString((char*)(param->GetDefaultValue()).data());
2426  if (defaultValue == "off") {
2427  radioOff->setChecked(true);
2428  } else if (defaultValue == "on") {
2429  radioOn->setChecked(true);
2430  }
2431 
2432  } else {
2433  input = new QLineEdit();
2434  dynamic_cast<QLineEdit*>(input)->setText(QString((char*)(param->GetDefaultValue()).data()));
2435  }
2436 
2437  txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
2438  if( ! param->GetParameterGuidance().isNull() )
2439  txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
2440 
2441  txt += " Parameter type : " + QString(QChar(param->GetParameterType())) + "\n";
2442  if(param->IsOmittable()){
2443  txt += " Omittable : True\n";
2444  } else {
2445  txt += " Omittable : False\n";
2446  }
2447  if( param->GetCurrentAsDefault() ) {
2448  txt += " Default value : taken from the current value\n";
2449  } else if( ! param->GetDefaultValue().isNull() ) {
2450  txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n";
2451  }
2452  if( ! param->GetParameterRange().isNull() ) {
2453  txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
2454  }
2455  if( ! param->GetParameterCandidates().isNull() ) {
2456  txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
2457  }
2458 
2459  if (isStillColorParameter && (nbColorParameter != 0)) {
2460  if ((label->text() == "red") || (label->text() == "red_or_string")) {
2461  redLabel = label;
2462  redInput = input;
2463  } else if (label->text() == "green") {
2464  greenLabel = label;
2465  greenInput = input;
2466  } else if (label->text() == "blue") {
2467 
2468  // we have all, then add a color chooser
2469 
2470  // Create a pixmap with the default color
2471  QColor qc;
2472  if ((redDefaultStr != "") && (redDefaultStr != "") && (redDefaultStr != "")) {
2473  qc.setRgbF(redDefaultStr.toDouble(),
2474  greenDefaultStr.toDouble(),
2475  blueDefaultStr.toDouble());
2476  }
2477  QPixmap pixmap = QPixmap(QSize(16, 16));
2478  pixmap.fill (qc);
2479  QPainter painter(&pixmap);
2480  painter.setPen(Qt::black);
2481  painter.drawRect(0,0,15,15); // Draw contour
2482 
2483  input = new QPushButton("Change color");
2484  dynamic_cast<QPushButton*>(input)->setIcon(pixmap);
2485  dynamic_cast<QPushButton*>(input)->setAccessibleName(redDefaultStr+" "+greenDefaultStr+" "+blueDefaultStr);
2486  label = new QLabel("Choose color");
2487 
2488  // less 1 because we have to add one to the row number
2489  nbColorParameter--;
2490  gridLayout->addWidget(label,i_thParameter-nbColorParameter,0);
2491  input->setToolTip("Select the current color");
2492  gridLayout->addWidget(input,i_thParameter-nbColorParameter,1);
2493 
2494  // Connect pushButton to ColorDialog in callback
2495  QSignalMapper* signalMapper = new QSignalMapper(this);
2496  signalMapper->setMapping(input,input);
2497  connect(input, SIGNAL(clicked()), signalMapper, SLOT(map()));
2498  connect(signalMapper, SIGNAL(mapped(QWidget*)),this, SLOT(ChangeColorCallback(QWidget*)));
2499 
2500  isColorDialogAdded = true;
2501  isStillColorParameter = false;
2502  }
2503  } else {
2504  gridLayout->addWidget(label,i_thParameter-nbColorParameter,0);
2505  input->setToolTip(txt);
2506  gridLayout->addWidget(input,i_thParameter-nbColorParameter,1);
2507  }
2508  }
2509  // add command name in hidden value at last line position 0
2510  QLabel* name = new QLabel(QString((char*)(aCommand->GetCommandPath().data())));
2511  name->hide();
2512  gridLayout->addWidget(name,n_parameterEntry-nbColorParameter,0);
2513 
2514  QPushButton* applyButton = new QPushButton("Apply");
2515  if (!isDialog) {
2516 
2517  gridLayout->addWidget(applyButton,n_parameterEntry-nbColorParameter,1);
2518 
2519  QSignalMapper* signalMapper = new QSignalMapper(this);
2520  signalMapper->setMapping(applyButton, paramWidget);
2521  connect(applyButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
2522  connect(signalMapper, SIGNAL(mapped(QWidget*)),this, SLOT(VisParameterCallback(QWidget*)));
2523  } else {
2524  // Apply/Cancel buttons
2525 
2526  applyButton->setAutoDefault( TRUE );
2527  applyButton->setDefault( TRUE );
2528 
2529  QPushButton* cancelButton = new QPushButton( tr( "&Cancel" ));
2530  cancelButton->setAutoDefault( TRUE );
2531  gridLayout->addWidget(cancelButton,n_parameterEntry-nbColorParameter,1);
2532  gridLayout->addWidget(applyButton,n_parameterEntry-nbColorParameter,0);
2533 
2534  QSignalMapper* signalMapper = new QSignalMapper(this);
2535  signalMapper->setMapping(applyButton, paramWidget);
2536  connect(applyButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
2537  connect(signalMapper, SIGNAL(mapped(QWidget*)),this, SLOT(VisParameterCallback(QWidget*)));
2538 
2539  QWidget * parentCheck = aParent;
2540  QDialog* parentDialog = NULL;
2541  bool found = false;
2542  while ((parentCheck->parentWidget()) != NULL) {
2543  parentCheck = parentCheck->parentWidget();
2544  parentDialog = dynamic_cast<QDialog*>(parentCheck);
2545  if (parentDialog) {
2546  connect( applyButton, SIGNAL( clicked() ), parentDialog, SLOT( accept() ) );
2547  connect( cancelButton, SIGNAL( clicked() ), parentDialog, SLOT( reject() ) );
2548  found = true;
2549  }
2550  }
2551  if (!found) {
2552  return false;
2553  }
2554  }
2555 
2556  if (!aParent->layout()) {
2557  aParent->setLayout(new QVBoxLayout());
2558  }
2559  aParent->layout()->addWidget(paramWidget);
2560  }
2561 
2562  return true;
2563 }
2564 
2565 
2570 QTreeWidgetItem* G4UIQt::FindTreeItem(
2571  QTreeWidgetItem *aParent
2572 ,const QString& aCommand
2573 )
2574 {
2575  if (aParent == NULL) return NULL;
2576 
2577  // Suppress last "/"
2578  QString myCommand = aCommand;
2579 
2580  if (myCommand.lastIndexOf("/") == (myCommand.size()-1)) {
2581  myCommand = myCommand.left(myCommand.size()-1);
2582  }
2583 
2584  if (GetLongCommandPath(aParent) == myCommand)
2585  return aParent;
2586 
2587  QTreeWidgetItem * tmp = NULL;
2588  for (int a=0;a<aParent->childCount();a++) {
2589  if (!tmp)
2590  tmp = FindTreeItem(aParent->child(a),myCommand);
2591  }
2592  return tmp;
2593 }
2594 
2595 
2596 
2604 QString G4UIQt::GetCommandList (
2605  const G4UIcommand *aCommand
2606  )
2607 {
2608 
2609  QString txt ="";
2610  if (aCommand == NULL)
2611  return txt;
2612 
2613  G4String commandPath = aCommand->GetCommandPath();
2614  G4String rangeString = aCommand->GetRange();
2615  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
2616  G4int n_parameterEntry = aCommand->GetParameterEntries();
2617 
2618  if ((commandPath == "") &&
2619  (rangeString == "") &&
2620  (n_guidanceEntry == 0) &&
2621  (n_parameterEntry == 0)) {
2622  return txt;
2623  }
2624 
2625  if((commandPath.length()-1)!='/') {
2626  txt += "Command " + QString((char*)(commandPath).data()) + "\n";
2627  }
2628  txt += "Guidance :\n";
2629 
2630  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
2631  txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
2632  }
2633  if( ! rangeString.isNull() ) {
2634  txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n";
2635  }
2636  if( n_parameterEntry > 0 ) {
2637  G4UIparameter *param;
2638 
2639  // Re-implementation of G4UIparameter.cc
2640 
2641  for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
2642  param = aCommand->GetParameter(i_thParameter);
2643  txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
2644  if( ! param->GetParameterGuidance().isNull() )
2645  txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
2646  txt += " Parameter type : " + QString(QChar(param->GetParameterType())) + "\n";
2647  if(param->IsOmittable()){
2648  txt += " Omittable : True\n";
2649  } else {
2650  txt += " Omittable : False\n";
2651  }
2652  if( param->GetCurrentAsDefault() ) {
2653  txt += " Default value : taken from the current value\n";
2654  } else if( ! param->GetDefaultValue().isNull() ) {
2655  txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n";
2656  }
2657  if( ! param->GetParameterRange().isNull() ) {
2658  txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
2659  }
2660  if( ! param->GetParameterCandidates().isNull() ) {
2661  txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
2662  }
2663  }
2664  }
2665  return txt;
2666 }
2667 
2668 
2676 void G4UIQt::updateHelpArea (
2677  const G4UIcommand *aCommand
2678 )
2679 {
2680  if (!fParameterHelpLabel)
2681  return;
2682  if (!fParameterHelpTable)
2683  return;
2684 
2685  fParameterHelpLabel->setTextInteractionFlags(Qt::NoTextInteraction);
2686  QString txt;
2687  if (aCommand == NULL)
2688  return;
2689 
2690  G4String commandPath = aCommand->GetCommandPath();
2691  G4String rangeString = aCommand->GetRange();
2692  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
2693  G4int n_parameterEntry = aCommand->GetParameterEntries();
2694 
2695  if ((commandPath == "") &&
2696  (rangeString == "") &&
2697  (n_guidanceEntry == 0) &&
2698  (n_parameterEntry == 0)) {
2699  return;
2700  }
2701 
2702  if((commandPath.length()-1)!='/') {
2703  txt += "<b>Command </b> " + QString((char*)(commandPath).data()) + "<br />";
2704  }
2705  txt += "<b>Guidance :</b> ";
2706 
2707  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
2708  txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "<br />";
2709  }
2710  if( ! rangeString.isNull() ) {
2711  txt += "<b>Range of parameters : </b> " + QString((char*)(rangeString).data()) + "<br />";
2712  } else {
2713  txt += "<br />";
2714  }
2715  fParameterHelpLabel->setHtml(txt);
2716 
2717  if( n_parameterEntry > 0 ) {
2718  G4UIparameter *param;
2719 
2720  // Re-implementation of G4UIparameter.cc
2721 
2722  fParameterHelpTable->clear();
2723  fParameterHelpTable->setRowCount(n_parameterEntry);
2724  fParameterHelpTable->setColumnCount(8);
2725  fParameterHelpTable->setHorizontalHeaderLabels(QStringList() <<
2726  tr("") <<
2727  tr("Parameter") <<
2728  tr("Guidance") <<
2729  tr("Type") <<
2730  tr("Ommitable") <<
2731  tr("Default") <<
2732  tr("Range") <<
2733  tr("Candidate"));
2734  fParameterHelpTable->setColumnWidth(2,60);
2735 
2736  fParameterHelpTable->verticalHeader()->setVisible(false);
2737  fParameterHelpTable->setAlternatingRowColors (true);
2738 #if QT_VERSION < 0x050000
2739  fParameterHelpTable->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
2740  fParameterHelpTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
2741 #else
2742  fParameterHelpTable->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
2743  fParameterHelpTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
2744 #endif
2745  fParameterHelpTable->setWordWrap(true);
2746 
2747  QTableWidgetItem* t = fParameterHelpTable->horizontalHeaderItem(1);
2748  QFont fnt = t->font();
2749  int size = fnt.pointSize();
2750  fnt.setPointSize(size-2);
2751 
2752  for( G4int a=0; a<n_parameterEntry; a++ ) {
2753  param = aCommand->GetParameter(a);
2754  fParameterHelpTable->setItem(a, 0, new QTableWidgetItem(QString::number(a+1)));
2755 
2756  fParameterHelpTable->setItem(a, 1, new QTableWidgetItem(QString((char*)(param->GetParameterName()).data())));
2757  if( ! param->GetParameterGuidance().isNull() ) {
2758  fParameterHelpTable->setItem(a, 2, new QTableWidgetItem(QString((char*)(param->GetParameterGuidance()).data())));
2759  }
2760  fParameterHelpTable->setItem(a, 3, new QTableWidgetItem(QString(QChar(param->GetParameterType()))));
2761 
2762  if(param->IsOmittable()){
2763  fParameterHelpTable->setItem(a, 4, new QTableWidgetItem(QString("True")));
2764  } else {
2765  fParameterHelpTable->setItem(a, 4, new QTableWidgetItem(QString("False")));
2766  }
2767  if( param->GetCurrentAsDefault() ) {
2768  fParameterHelpTable->setItem(a, 5, new QTableWidgetItem(QString("taken from the current value")));
2769  } else if( ! param->GetDefaultValue().isNull() ) {
2770  fParameterHelpTable->setItem(a, 5, new QTableWidgetItem(QString((char*)(param->GetDefaultValue()).data())));
2771  }
2772  if( ! param->GetParameterRange().isNull() ) {
2773  fParameterHelpTable->setItem(a, 6, new QTableWidgetItem(QString((char*)(param->GetParameterRange()).data())));
2774  }
2775  if( ! param->GetParameterCandidates().isNull() ) {
2776  fParameterHelpTable->setItem(a, 7, new QTableWidgetItem(QString((char*)(param->GetParameterCandidates()).data())));
2777  }
2778  // tooltips
2779  for (int b=0; b<8; b++) {
2780  QTableWidgetItem* tmp = fParameterHelpTable->item(a,b);
2781  if (tmp) {
2782  tmp->setToolTip(tmp->text());
2783  tmp->setFlags(Qt::NoItemFlags);
2784  tmp->setForeground(QBrush());
2785  tmp->setFont(fnt);
2786  }
2787  }
2788  fParameterHelpTable->resizeRowToContents(a);
2789  }
2790  for (int c=0; c<8; c++) {
2791  if (c !=2) {
2792  fParameterHelpTable->resizeColumnToContents(c);
2793  }
2794  }
2795  fParameterHelpLabel->setVisible(true);
2796  fParameterHelpTable->setVisible(true);
2797 
2798  }
2799 }
2800 
2801 
2807 G4bool G4UIQt::IsGUICommand(
2808  const G4UIcommand *aCommand
2809 )
2810 {
2811  if (aCommand == NULL)
2812  return false;
2813 
2814  G4int n_parameterEntry = aCommand->GetParameterEntries();
2815 
2816  if( n_parameterEntry > 0 ) {
2817  G4UIparameter *param;
2818 
2819  // Re-implementation of G4UIparameter.cc
2820 
2821  for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
2822  param = aCommand->GetParameter(i_thParameter);
2823  if (QString(QChar(param->GetParameterType())) == "d") {
2824  return true;
2825  }
2826  if (QString(QChar(param->GetParameterType())) == "b") {
2827  return true;
2828  }
2829  if (QString(QChar(param->GetParameterType())) == "i") {
2830  return true;
2831  }
2832  if (QString(QChar(param->GetParameterType())) == "s") {
2833  return true;
2834  }
2835  }
2836  }
2837  return false;
2838 }
2839 
2840 
2843 G4bool G4UIQt::GetHelpChoice(
2844  G4int&
2845 )
2846 {
2847  return true;
2848 }
2849 
2850 
2858 bool G4UIQt::eventFilter( // Should stay with a minuscule eventFilter because of Qt
2859  QObject *aObj
2860 ,QEvent *aEvent
2861 )
2862 {
2863  bool moveCommandCursor = false;
2864  if (aObj == NULL) return false;
2865  if (aEvent == NULL) return false;
2866 
2867  if (aObj == fHistoryTBTableList) {
2868  if (aEvent->type() == QEvent::KeyPress) {
2869  fCommandArea->setFocus();
2870  }
2871  }
2872  if (aObj == fCommandArea) {
2873  if (aEvent->type() == QEvent::KeyPress) {
2874  QKeyEvent *e = static_cast<QKeyEvent*>(aEvent);
2875  if ((e->key() == (Qt::Key_Down)) ||
2876  (e->key() == (Qt::Key_PageDown)) ||
2877  (e->key() == (Qt::Key_Up)) ||
2878  (e->key() == (Qt::Key_PageUp))) {
2879  int selection = fHistoryTBTableList->currentRow();
2880  if (fHistoryTBTableList->count()) {
2881  if (selection == -1) {
2882  selection = fHistoryTBTableList->count()-1;
2883  } else {
2884  if (e->key() == (Qt::Key_Down)) {
2885  if (selection <(fHistoryTBTableList->count()-1))
2886  selection++;
2887  } else if (e->key() == (Qt::Key_PageDown)) {
2888  selection = fHistoryTBTableList->count()-1;
2889  } else if (e->key() == (Qt::Key_Up)) {
2890  if (selection >0)
2891  selection --;
2892  } else if (e->key() == (Qt::Key_PageUp)) {
2893  selection = 0;
2894  }
2895  }
2896  fHistoryTBTableList->clearSelection();
2897 #if QT_VERSION < 0x040202
2898  fHistoryTBTableList->setItemSelected(fHistoryTBTableList->item(selection),true);
2899 #else
2900  fHistoryTBTableList->item(selection)->setSelected(true);
2901 #endif
2902  fHistoryTBTableList->setCurrentItem(fHistoryTBTableList->item(selection));
2903  }
2904  moveCommandCursor = true;
2905  } else if (e->key() == (Qt::Key_Tab)) {
2906  G4String ss = Complete(fCommandArea->text().toStdString().c_str());
2907  fCommandArea->setText((char*)(ss.data()));
2908 
2909  // do not pass by parent, it will disable widget tab focus !
2910  return true;
2911  // L.Garnier : MetaModifier is CTRL for MAC, but I don't want to put a MAC
2912  // specific #ifdef
2913  } else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_A)) {
2914  fCommandArea->home(false);
2915  return true;
2916  } else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_E)) {
2917  fCommandArea->end(false);
2918  return true;
2919  }
2920  }
2921  }
2922  bool res= false;
2923  // change cursor position if needed
2924  if (moveCommandCursor == true) {
2925  fCommandArea->setCursorPosition ( fCommandArea->text().length() );
2926  fCommandArea->setCursorPosition (4);
2927  } else {
2928  // pass the event on to the parent class
2929  res = QObject::eventFilter(aObj, aEvent);
2930  }
2931  return res;
2932 }
2933 
2934 
2935 
2936 
2937 /***************************************************************************/
2938 //
2939 // SLOTS DEFINITIONS
2940 //
2941 /***************************************************************************/
2942 
2945 void G4UIQt::ShowHelpCallback (
2946 )
2947 {
2948  TerminalHelp("");
2949 }
2950 
2951 
2954 void G4UIQt::ClearButtonCallback (
2955 )
2956 {
2957  fCoutTBTextArea->clear();
2958  fG4OutputString.clear();
2959 }
2960 
2963 void G4UIQt::ExitSession (
2964 )
2965 {
2966  SessionTerminate();
2967 }
2968 
2969 void G4UIQt::ExitHelp(
2970 ) const
2971 {
2972 }
2973 
2977 void G4UIQt::CommandEnteredCallback (
2978 )
2979 {
2980  // split by any new line character
2981  QStringList list = fCommandArea->text().split(QRegExp("[\r\n]"),QString::SkipEmptyParts);
2982 
2983  // Apply for all commands
2984  for (int a=0; a< list.size(); a++) {
2985  QString txt (list[a].trimmed());
2986  if (txt != "") {
2987  fHistoryTBTableList->addItem(txt);
2988  fHistoryTBTableList->clearSelection();
2989  fHistoryTBTableList->setCurrentItem(NULL);
2990  fCommandArea->setText("");
2991  G4Qt* interactorManager = G4Qt::getInstance ();
2992  if (interactorManager) {
2993  interactorManager->FlushAndWaitExecution();
2994  }
2995 
2996  G4String command = txt.toStdString().c_str();
2997  if (command(0,4) != "help") {
2998  ApplyShellCommand (command,exitSession,exitPause);
2999  } else {
3000  ActivateCommand(command);
3001  }
3002  }
3003  }
3004  // set the focus to the command line
3005  fCommandArea->setFocus();
3006 
3007  // Rebuild help tree
3008  FillHelpTree();
3009 
3010  if(exitSession==true)
3011  SessionTerminate();
3012 }
3013 
3014 
3019 void G4UIQt::CommandEditedCallback(const QString &)
3020 {
3021  QStringList list = fCommandArea->text().split(QRegExp("[\r\n]"),QString::SkipEmptyParts);
3022 
3023  if (list.size() > 1) { // trigger ActivateCommand
3024  for (int a=0; a<list.size()-1; a++) {
3025  // set only the first part
3026  fCommandArea->setText(list[a]);
3027  // trigger callback
3028  CommandEnteredCallback();
3029  }
3030  // reset unfinished command
3031  fCommandArea->setText(list[list.size()-1]);
3032  }
3033 }
3034 
3035 
3038 void G4UIQt::VisParameterCallback(QWidget* widget){
3039  if (widget == NULL) {
3040  return;
3041  }
3042 
3043  // Look in all the Grid layout, but only column 1 (0 is the parameter name)
3044  QGridLayout* grid = dynamic_cast<QGridLayout*>(widget->layout());
3045  if (grid == 0) {
3046  return;
3047  }
3048  QString command;
3049 #if QT_VERSION < 0x040400
3050  QWidget* name = grid->itemAt(grid->columnCount()*(grid->rowCount()-2))->widget();
3051 #else
3052  QWidget* name = grid->itemAtPosition(grid->rowCount()-1,0)->widget();
3053 #endif
3054  if (dynamic_cast<QLabel*>(name) == 0) {
3055  return;
3056  }
3057  command += (dynamic_cast<QLabel*>(name))->text()+" ";
3058 
3059  for (int a=0;a<grid->rowCount()-1; a++) {
3060 #if QT_VERSION < 0x040400
3061  QWidget* widgetTmp = grid->itemAt(a*grid->columnCount()+1)->widget();
3062 #else
3063  QWidget* widgetTmp = grid->itemAtPosition(a,1)->widget();
3064 #endif
3065 
3066  // 4 kind of widgets : QLineEdit / QComboBox / radioButtonsGroup / QPushButton (color chooser)
3067  if (widgetTmp != NULL) {
3068 
3069  if (dynamic_cast<QLineEdit*>(widgetTmp) != 0) {
3070  command += (dynamic_cast<QLineEdit*>(widgetTmp))->text()+" ";
3071 
3072  } else if (dynamic_cast<QComboBox*>(widgetTmp) != 0){
3073  command += (dynamic_cast<QComboBox*>(widgetTmp))->itemText((dynamic_cast<QComboBox*>(widgetTmp))->currentIndex())+" ";
3074 
3075  // Color chooser
3076  } else if (dynamic_cast<QPushButton*>(widgetTmp) != 0){
3077  command += widgetTmp->accessibleName()+" ";
3078 
3079  // Check for Button group
3080  } else if (dynamic_cast<QWidget*>(widgetTmp) != 0){
3081  if (widgetTmp->layout()->count() > 0){
3082  if (dynamic_cast<QRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()) != 0) {
3083  QAbstractButton * checked = (dynamic_cast<QRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()))->group()->checkedButton();
3084  if (checked != 0) {
3085  command += (dynamic_cast<QRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()))->group()->checkedButton()->text()+" ";
3086  }
3087  }
3088  }
3089 
3090  }
3091  }
3092  }
3093  if (command != "") {
3095  if(UI != NULL) {
3096  UI->ApplyCommand(command.toStdString().c_str());
3097  }
3098  }
3099 }
3100 
3101 
3107 void G4UIQt::ButtonCallback (
3108  const QString& aCommand
3109 )
3110 {
3111  G4String ss = G4String(aCommand.toStdString().c_str());
3112  ss = ss.strip(G4String::leading);
3113 
3115  if(UI==NULL) return;
3116  G4UIcommandTree * treeTop = UI->GetTree();
3117 
3118  G4UIcommand* command = treeTop->FindPath(ss);
3119 
3120  if (command) {
3121  // if is GUI, then open a dialog
3122  if (IsGUICommand(command)) {
3123  QDialog* menuParameterDialog = new QDialog();
3124 
3125  if (CreateVisCommandGroupAndToolBox(command,menuParameterDialog,1,true)) {
3126  menuParameterDialog->setWindowTitle (aCommand);
3127  menuParameterDialog->setSizePolicy (QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
3128 
3129  // exec this dialog, apply the command automaticaly, and return
3130  menuParameterDialog->exec();
3131  return;
3132  }
3133  }
3134  }
3135 
3136  ApplyShellCommand(ss,exitSession,exitPause);
3137 
3138  // Rebuild help tree
3139  FillHelpTree();
3140 
3141  if(exitSession==true)
3142  SessionTerminate();
3143 }
3144 
3145 
3146 
3149 void G4UIQt::HelpTreeClicCallback (
3150 )
3151 {
3152  QTreeWidgetItem* item = NULL;
3153  if (!fHelpTreeWidget)
3154  return ;
3155 
3156  QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
3157  if (list.isEmpty())
3158  return;
3159  item = list.first();
3160  if (!item)
3161  return;
3162 
3164  if(UI==NULL) return;
3165  G4UIcommandTree * treeTop = UI->GetTree();
3166 
3167  std::string itemText = GetLongCommandPath(item).toStdString();
3168 
3169  // check if it is a command path
3170  if (item->childCount() > 0) {
3171  itemText +="/";
3172  }
3173  G4UIcommand* command = treeTop->FindPath(itemText.c_str());
3174 
3175  if (command) {
3176  updateHelpArea(command);
3177  } else { // this is a command
3178  G4UIcommandTree* path = treeTop->FindCommandTree(itemText.c_str());
3179  if ( path) {
3180  // this is not a command, this is a sub directory
3181  // We display the Title
3182  fParameterHelpLabel->setVisible(true);
3183  fParameterHelpLabel->setText(path->GetTitle().data());
3184  fParameterHelpTable->setVisible(false);
3185  }
3186  }
3187 }
3188 
3191 void G4UIQt::HelpTreeDoubleClicCallback (
3192 )
3193 {
3194  HelpTreeClicCallback();
3195 
3196  QTreeWidgetItem* item = NULL;
3197  if (!fHelpTreeWidget)
3198  return ;
3199 
3200  QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
3201  if (list.isEmpty())
3202  return;
3203  item = list.first();
3204  if (!item)
3205  return;
3206 
3207  fCommandArea->clear();
3208  fCommandArea->setText(GetLongCommandPath(item));
3209 }
3210 
3211 
3215 void G4UIQt::CommandHistoryCallback(
3216 )
3217 {
3218  QListWidgetItem* item = NULL;
3219  if (!fHistoryTBTableList)
3220  return ;
3221 
3222 
3223  QList<QListWidgetItem *> list =fHistoryTBTableList->selectedItems();
3224  if (list.isEmpty())
3225  return;
3226  item = list.first();
3227  if (!item)
3228  return;
3229  fCommandArea->setText(item->text());
3230 }
3231 
3232 
3233 void G4UIQt::ThreadComboBoxCallback(int) {
3234  CoutFilterCallback("");
3235 }
3236 
3237 
3238 void G4UIQt::CoutFilterCallback(
3239 const QString &) {
3240 
3241  FilterAllOutputTextArea();
3242 
3243  fCoutTBTextArea->repaint();
3244  fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
3245 
3246  }
3247 
3248 
3249 QString G4UIQt::FilterOutput(
3250  const G4UIOutputString& output
3251 ,const QString& currentThread
3252 ,const QString& filter
3253 ) {
3254 
3255 #ifdef G4MULTITHREADED
3256  if ((currentThread == "All") ||
3257  (currentThread == output.fThread)) {
3258 #else
3259  if (currentThread == "") {
3260 #endif
3261  if (output.fText.contains(QRegExp(filter))) {
3262  return output.fText;
3263  }
3264  }
3265  return "";
3266 }
3267 
3268 
3269 void G4UIQt::FilterAllOutputTextArea() {
3270 
3271  QString currentThread = "";
3272 #ifdef G4MULTITHREADED
3273  currentThread = fThreadsFilterComboBox->currentText();
3274  if (currentThread == "Master") {
3275  currentThread = "";
3276  }
3277 #endif
3278  QString filter = fCoutFilter->text();
3279  G4String previousOutputStream = "";
3280 
3281  fCoutTBTextArea->clear();
3282  fCoutTBTextArea->setTextColor(QColor(Qt::black));
3283 
3284  for (unsigned int a=0; a<fG4OutputString.size(); a++) {
3285  G4UIOutputString out = fG4OutputString[a];
3286  if (FilterOutput(out,currentThread,filter) != "") {
3287 
3288  // changing color ?
3289  if (out.fOutputStream != previousOutputStream) {
3290  previousOutputStream = out.fOutputStream;
3291  if (out.fOutputStream == "info") {
3292  fCoutTBTextArea->setTextColor(QColor(Qt::black));
3293  } else {
3294  fCoutTBTextArea->setTextColor(QColor(Qt::red));
3295  }
3296  }
3297  fCoutTBTextArea->append(out.fText);
3298  }
3299  }
3300  fCoutTBTextArea->setTextColor(QColor(Qt::black));
3301 }
3302 
3303 
3308 void G4UIQt::LookForHelpStringCallback(
3309 )
3310 {
3311  QString searchText = fHelpLine->text();
3312 
3313  fParameterHelpLabel->setText("");
3314  fParameterHelpTable->setVisible(false);
3315  if (searchText =="") {
3316  // clear old help tree
3317  fHelpTreeWidget->clear();
3318 
3319  FillHelpTree();
3320 
3321  return;
3322  } else {
3323  OpenHelpTreeOnCommand(searchText);
3324  }
3325 }
3326 
3327 
3328 void G4UIQt::OpenHelpTreeOnCommand(
3329  const QString & searchText
3330 )
3331 {
3332  // the help tree
3334  if(UI==NULL) return;
3335  G4UIcommandTree * treeTop = UI->GetTree();
3336 
3337  G4int treeSize = treeTop->GetTreeEntry();
3338 
3339  // clear old help tree
3340  fHelpTreeWidget->clear();
3341 
3342  // look for new items
3343 
3344  int tmp = 0;
3345 
3346  QMap<int,QString> commandResultMap;
3347  QMap<int,QString> commandChildResultMap;
3348 
3349  for (int a=0;a<treeSize;a++) {
3350  G4UIcommand* command = treeTop->FindPath(treeTop->GetTree(a+1)->GetPathName().data());
3351  tmp = GetCommandList (command).count(searchText,Qt::CaseInsensitive);
3352  if (tmp >0) {
3353  commandResultMap.insertMulti(tmp,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()));
3354  }
3355  // look for childs
3356  commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a+1),searchText);
3357  // insert new childs
3358  if (!commandChildResultMap.empty()) {
3359  QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
3360  while (i != commandChildResultMap.constEnd()) {
3361  commandResultMap.insertMulti(i.key(),i.value());
3362  i++;
3363  }
3364  commandChildResultMap.clear();
3365  }
3366  }
3367 
3368  // build new help tree
3369  fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
3370  fHelpTreeWidget->setColumnCount(2);
3371  QStringList labels;
3372  labels << QString("Command") << QString("Match");
3373  fHelpTreeWidget->setHeaderLabels(labels);
3374 
3375  if (commandResultMap.empty()) {
3376  fParameterHelpLabel->setText("No match found");
3377  fParameterHelpTable->setVisible(false);
3378  return;
3379  }
3380 
3381  QMap<int,QString>::const_iterator i = commandResultMap.constEnd();
3382  i--;
3383  // 10 maximum progress values
3384  float multValue = 10.0/(float)(i.key());
3385  QString progressChar = "|";
3386  QString progressStr = "|";
3387 
3388  QTreeWidgetItem * newItem;
3389  bool end = false;
3390  while (!end) {
3391  if (i == commandResultMap.constBegin()) {
3392  end = true;
3393  }
3394  for(int a=0;a<int(i.key()*multValue);a++) {
3395  progressStr += progressChar;
3396  }
3397  newItem = new QTreeWidgetItem();
3398  QString commandStr = i.value().trimmed();
3399 
3400  if (commandStr.indexOf("/") == 0) {
3401  commandStr = commandStr.right(commandStr.size()-1);
3402  }
3403 
3404  newItem->setText(0,commandStr);
3405  newItem->setText(1,progressStr);
3406  fHelpTreeWidget->addTopLevelItem(newItem);
3407 #if QT_VERSION < 0x040200
3408 #else
3409  newItem->setForeground ( 1, QBrush(Qt::blue) );
3410 #endif
3411  progressStr = "|";
3412  i--;
3413  }
3414  fHelpTreeWidget->resizeColumnToContents (0);
3415  fHelpTreeWidget->sortItems(1,Qt::DescendingOrder);
3416  // fHelpTreeWidget->setColumnWidth(1,10);//resizeColumnToContents (1);
3417 }
3418 
3419 
3420 
3421 
3422 QMap<int,QString> G4UIQt::LookForHelpStringInChildTree(
3423  G4UIcommandTree *aCommandTree
3424 ,const QString & text
3425  )
3426 {
3427  QMap<int,QString> commandResultMap;
3428  if (aCommandTree == NULL) return commandResultMap;
3429 
3430 
3431  // Get the Sub directories
3432  int tmp = 0;
3433  QMap<int,QString> commandChildResultMap;
3434 
3435  for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
3436  const G4UIcommand* command = aCommandTree->GetGuidance();
3437  tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
3438  if (tmp >0) {
3439  commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()));
3440  }
3441  // look for childs
3442  commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text);
3443 
3444  if (!commandChildResultMap.empty()) {
3445  // insert new childs
3446  QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
3447  while (i != commandChildResultMap.constEnd()) {
3448  commandResultMap.insertMulti(i.key(),i.value());
3449  i++;
3450  }
3451  commandChildResultMap.clear();
3452  }
3453  }
3454  // Get the Commands
3455 
3456  for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
3457  const G4UIcommand* command = aCommandTree->GetCommand(a+1);
3458  tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
3459  if (tmp >0) {
3460  commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()));
3461  }
3462 
3463  }
3464  return commandResultMap;
3465 }
3466 
3467 
3468 QString G4UIQt::GetShortCommandPath(
3469 QString commandPath
3470 )
3471 {
3472  if (commandPath.indexOf("/") == 0) {
3473  commandPath = commandPath.right(commandPath.size()-1);
3474  }
3475 
3476  commandPath = commandPath.right(commandPath.size()-commandPath.lastIndexOf("/",-2)-1);
3477 
3478  if (commandPath.lastIndexOf("/") == (commandPath.size()-1)) {
3479  commandPath = commandPath.left(commandPath.size()-1);
3480  }
3481 
3482  return commandPath;
3483 }
3484 
3485 
3486 QString G4UIQt::GetLongCommandPath(
3487  QTreeWidgetItem* item
3488 )
3489 {
3490  if (item == NULL) return "";
3491 
3492  // rebuild path:
3493  QString itemText = "";
3494  itemText = item->text(0);
3495 
3496  while (item->parent() != NULL) {
3497  itemText = item->parent()->text(0)+"/"+itemText;
3498  item = item->parent();
3499  }
3500  itemText = "/"+itemText;
3501 
3502  return itemText;
3503 }
3504 
3505 
3506 void G4UIQt::ChangeColorCallback(QWidget* widget) {
3507  if (widget == NULL) {
3508  return;
3509  }
3510 
3511  QPushButton* button = dynamic_cast<QPushButton*>(widget);
3512  if (button == 0) {
3513  return;
3514  }
3515  QString value = button->accessibleName();
3516 
3517  QColor old;
3518  old.setRgbF(value.section(" ",0,1).toDouble(),
3519  value.section(" ",1,2).toDouble(),
3520  value.section(" ",2,3).toDouble());
3521 #if QT_VERSION < 0x040500
3522  bool a;
3523  QColor color = QColor(QColorDialog::getRgba (old.rgba(),&a,fUITabWidget));
3524 #else
3525  QColor color = QColorDialog::getColor(old,
3526  fUITabWidget,
3527  "Change color",
3528  QColorDialog::ShowAlphaChannel);
3529 #endif
3530 
3531 
3532  if (color.isValid()) {
3533  // rebuild the widget icon
3534  QPixmap pixmap = QPixmap(QSize(16, 16));
3535  pixmap.fill (color);
3536  QPainter painter(&pixmap);
3537  painter.setPen(Qt::black);
3538  painter.drawRect(0,0,15,15); // Draw contour
3539 
3540  button->setAccessibleName(QString::number(color.redF())+" "+
3541  QString::number(color.greenF())+" "+
3542  QString::number(color.blueF())+" "
3543  );
3544  button->setIcon(pixmap);
3545 
3546 
3547  }
3548 }
3549 
3550 
3551 void G4UIQt::ChangeCursorStyle(const QString& action) {
3552 
3553  // Theses actions should be in the app toolbar
3554 
3555  fMoveSelected = true;
3556  fPickSelected = true;
3557  fRotateSelected = true;
3558  fZoomInSelected = true;
3559  fZoomOutSelected = true;
3560 
3561  if (fToolbarApp == NULL) return;
3562  QList<QAction *> list = fToolbarApp->actions ();
3563  for (int i = 0; i < list.size(); ++i) {
3564  if (list.at(i)->data().toString () == action) {
3565  list.at(i)->setChecked(TRUE);
3566  if (list.at(i)->data().toString () == "pick") {
3567  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/picking true");
3568  }
3569  } else if (list.at(i)->data().toString () == "move") {
3570  fMoveSelected = false;
3571  list.at(i)->setChecked(FALSE);
3572  } else if (list.at(i)->data().toString () == "pick") {
3573  fPickSelected = false;
3574  list.at(i)->setChecked(FALSE);
3575  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/picking false");
3576  } else if (list.at(i)->data().toString () == "rotate") {
3577  fRotateSelected = false;
3578  list.at(i)->setChecked(FALSE);
3579  } else if (list.at(i)->data().toString () == "zoom_in") {
3580  fZoomInSelected = false;
3581  list.at(i)->setChecked(FALSE);
3582  } else if (list.at(i)->data().toString () == "zoom_out") {
3583  fZoomOutSelected = false;
3584  list.at(i)->setChecked(FALSE);
3585  }
3586  }
3587  // FIXME : Should connect this to Vis
3588 }
3589 
3590 
3591 /* A little bit like "void G4OpenGLQtViewer::toggleDrawingAction(int aAction)"
3592  But for all viewers, not only Qt
3593 
3594 FIXME : Should be a feedback when changing viewer !
3595 
3596  */
3597 void G4UIQt::ChangeSurfaceStyle(const QString& action) {
3598 
3599  // Theses actions should be in the app toolbar
3600 
3601  if (fToolbarApp == NULL) return;
3602  QList<QAction *> list = fToolbarApp->actions ();
3603  for (int i = 0; i < list.size(); ++i) {
3604  if (list.at(i)->data().toString () == action) {
3605  list.at(i)->setChecked(TRUE);
3606  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
3607  list.at(i)->setChecked(FALSE);
3608  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3609  list.at(i)->setChecked(FALSE);
3610  } else if (list.at(i)->data().toString () == "solid") {
3611  list.at(i)->setChecked(FALSE);
3612  } else if (list.at(i)->data().toString () == "wireframe") {
3613  list.at(i)->setChecked(FALSE);
3614  }
3615  }
3616  // FIXME : Should connect this to Vis
3617 
3618  if (action == "hidden_line_removal") {
3619  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style w");
3620  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 1");
3621 
3622  } else if (action == "hidden_line_and_surface_removal") {
3623  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style s");
3624  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 1");
3625 
3626  } else if (action == "solid") {
3627  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style s");
3628  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 0");
3629 
3630  } else if (action == "wireframe") {
3631  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style w");
3632  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 0");
3633  }
3634 }
3635 
3636 
3637 void G4UIQt::OpenIconCallback(const QString& aParam) {
3638 
3639  QString aCommand = aParam.left(aParam.indexOf(fStringSeparator));
3640  QString aLabel = aParam.mid(aParam.indexOf(fStringSeparator)+fStringSeparator.length());
3641 
3642  QString nomFich = QFileDialog::getOpenFileName(fMainWindow, aLabel, fLastOpenPath, "Macro files (*.mac)");
3643  if (nomFich != "") {
3644  G4UImanager::GetUIpointer()->ApplyCommand((QString(aCommand)+ QString(" ")+ nomFich).toStdString().c_str());
3645  QDir dir;
3646  fLastOpenPath = dir.absoluteFilePath(nomFich);
3647  }
3648 }
3649 
3650 
3651 void G4UIQt::SaveIconCallback(const QString& aParam) {
3652 
3653  QString aCommand = aParam.left(aParam.indexOf(fStringSeparator));
3654  QString aLabel = aParam.mid(aParam.indexOf(fStringSeparator)+fStringSeparator.length());
3655 
3656  QString nomFich = QFileDialog::getSaveFileName(fMainWindow, aLabel, fLastOpenPath, "Macro files (*.mac)");
3657  if (nomFich != "") {
3658  G4UImanager::GetUIpointer()->ApplyCommand((QString(aCommand)+ QString(" ")+nomFich).toStdString().c_str());
3659  QDir dir;
3660  fLastOpenPath = dir.absoluteFilePath(nomFich);
3661  }
3662 }
3663 
3664 
3665 
3666 void G4UIQt::ChangePerspectiveOrtho(const QString& action) {
3667 
3668  // Theses actions should be in the app toolbar
3669 
3670  if (fToolbarApp == NULL) return;
3671  QList<QAction *> list = fToolbarApp->actions ();
3672  QString checked = "";
3673  for (int i = 0; i < list.size(); ++i) {
3674  if (list.at(i)->data().toString () == action) {
3675  list.at(i)->setChecked(TRUE);
3676  checked = list.at(i)->data().toString ();
3677  } else if (list.at(i)->data().toString () == "persepective") {
3678  list.at(i)->setChecked(FALSE);
3679  } else if (list.at(i)->data().toString () == "ortho") {
3680  list.at(i)->setChecked(FALSE);
3681  }
3682  }
3683 
3684  if ((action == "ortho") && (checked == "ortho")) {
3685  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/projection o");
3686  } else if ((action == "perspective") && (checked == "perspective")) {
3687  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/projection p");
3688  }
3689 }
3690 
3691 
3692 
3693 void G4UIQt::SetIconMoveSelected() {
3694  // Theses actions should be in the app toolbar
3695  fMoveSelected = true;
3696  fRotateSelected = false;
3697  fPickSelected = false;
3698  fZoomInSelected = false;
3699  fZoomOutSelected = false;
3700 
3701  if (fToolbarApp == NULL) return;
3702  QList<QAction *> list = fToolbarApp->actions ();
3703  for (int i = 0; i < list.size(); ++i) {
3704  if (list.at(i)->data().toString () == "move") {
3705  list.at(i)->setChecked(TRUE);
3706  } else if (list.at(i)->data().toString () == "rotate") {
3707  list.at(i)->setChecked(FALSE);
3708  } else if (list.at(i)->data().toString () == "pick") {
3709  list.at(i)->setChecked(FALSE);
3710  } else if (list.at(i)->data().toString () == "zoom_in") {
3711  list.at(i)->setChecked(FALSE);
3712  } else if (list.at(i)->data().toString () == "zoom_out") {
3713  list.at(i)->setChecked(FALSE);
3714  }
3715  }
3716 }
3717 
3718 
3719 void G4UIQt::SetIconRotateSelected() {
3720  // Theses actions should be in the app toolbar
3721  fRotateSelected = true;
3722  fMoveSelected = false;
3723  fPickSelected = false;
3724  fZoomInSelected = false;
3725  fZoomOutSelected = false;
3726 
3727  if (fToolbarApp == NULL) return;
3728  QList<QAction *> list = fToolbarApp->actions ();
3729  for (int i = 0; i < list.size(); ++i) {
3730  if (list.at(i)->data().toString () == "rotate") {
3731  list.at(i)->setChecked(TRUE);
3732  } else if (list.at(i)->data().toString () == "move") {
3733  list.at(i)->setChecked(FALSE);
3734  } else if (list.at(i)->data().toString () == "pick") {
3735  list.at(i)->setChecked(FALSE);
3736  } else if (list.at(i)->data().toString () == "zoom_in") {
3737  list.at(i)->setChecked(FALSE);
3738  } else if (list.at(i)->data().toString () == "zoom_out") {
3739  list.at(i)->setChecked(FALSE);
3740  }
3741  }
3742 }
3743 
3744 
3745 void G4UIQt::SetIconPickSelected() {
3746  // Theses actions should be in the app toolbar
3747  fPickSelected = true;
3748  fMoveSelected = false;
3749  fRotateSelected = false;
3750  fZoomInSelected = false;
3751  fZoomOutSelected = false;
3752 
3753  if (fToolbarApp == NULL) return;
3754  QList<QAction *> list = fToolbarApp->actions ();
3755  for (int i = 0; i < list.size(); ++i) {
3756  if (list.at(i)->data().toString () == "pick") {
3757  list.at(i)->setChecked(TRUE);
3758  } else if (list.at(i)->data().toString () == "move") {
3759  list.at(i)->setChecked(FALSE);
3760  } else if (list.at(i)->data().toString () == "rotate") {
3761  list.at(i)->setChecked(FALSE);
3762  } else if (list.at(i)->data().toString () == "zoom_in") {
3763  list.at(i)->setChecked(FALSE);
3764  } else if (list.at(i)->data().toString () == "zoom_out") {
3765  list.at(i)->setChecked(FALSE);
3766  }
3767  }
3768 }
3769 
3770 
3771 void G4UIQt::SetIconZoomInSelected() {
3772  // Theses actions should be in the app toolbar
3773  fZoomInSelected = true;
3774  fMoveSelected = false;
3775  fRotateSelected = false;
3776  fPickSelected = false;
3777  fZoomOutSelected = false;
3778 
3779  if (fToolbarApp == NULL) return;
3780  QList<QAction *> list = fToolbarApp->actions ();
3781  for (int i = 0; i < list.size(); ++i) {
3782  if (list.at(i)->data().toString () == "zoom_in") {
3783  list.at(i)->setChecked(TRUE);
3784  } else if (list.at(i)->data().toString () == "move") {
3785  list.at(i)->setChecked(FALSE);
3786  } else if (list.at(i)->data().toString () == "rotate") {
3787  list.at(i)->setChecked(FALSE);
3788  } else if (list.at(i)->data().toString () == "pick") {
3789  list.at(i)->setChecked(FALSE);
3790  } else if (list.at(i)->data().toString () == "zoom_out") {
3791  list.at(i)->setChecked(FALSE);
3792  }
3793  }
3794 }
3795 
3796 
3797 void G4UIQt::SetIconZoomOutSelected() {
3798  // Theses actions should be in the app toolbar
3799  fZoomOutSelected = true;
3800  fMoveSelected = false;
3801  fRotateSelected = false;
3802  fPickSelected = false;
3803  fZoomInSelected = false;
3804 
3805  if (fToolbarApp == NULL) return;
3806  QList<QAction *> list = fToolbarApp->actions ();
3807  for (int i = 0; i < list.size(); ++i) {
3808  if (list.at(i)->data().toString () == "zoom_out") {
3809  list.at(i)->setChecked(TRUE);
3810  } else if (list.at(i)->data().toString () == "move") {
3811  list.at(i)->setChecked(FALSE);
3812  } else if (list.at(i)->data().toString () == "rotate") {
3813  list.at(i)->setChecked(FALSE);
3814  } else if (list.at(i)->data().toString () == "pick") {
3815  list.at(i)->setChecked(FALSE);
3816  } else if (list.at(i)->data().toString () == "zoom_in") {
3817  list.at(i)->setChecked(FALSE);
3818  }
3819  }
3820 }
3821 
3822 
3823 void G4UIQt::SetIconSolidSelected() {
3824  // Theses actions should be in the app toolbar
3825 
3826  if (fToolbarApp == NULL) return;
3827  QList<QAction *> list = fToolbarApp->actions ();
3828  for (int i = 0; i < list.size(); ++i) {
3829  if (list.at(i)->data().toString () == "solid") {
3830  list.at(i)->setChecked(TRUE);
3831  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
3832  list.at(i)->setChecked(FALSE);
3833  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3834  list.at(i)->setChecked(FALSE);
3835  } else if (list.at(i)->data().toString () == "wireframe") {
3836  list.at(i)->setChecked(FALSE);
3837  }
3838  }
3839 }
3840 
3841 
3842 void G4UIQt::SetIconWireframeSelected() {
3843  // Theses actions should be in the app toolbar
3844 
3845  if (fToolbarApp == NULL) return;
3846  QList<QAction *> list = fToolbarApp->actions ();
3847  for (int i = 0; i < list.size(); ++i) {
3848  if (list.at(i)->data().toString () == "wireframe") {
3849  list.at(i)->setChecked(TRUE);
3850  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
3851  list.at(i)->setChecked(FALSE);
3852  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3853  list.at(i)->setChecked(FALSE);
3854  } else if (list.at(i)->data().toString () == "solid") {
3855  list.at(i)->setChecked(FALSE);
3856  }
3857  }
3858 }
3859 
3860 
3861 void G4UIQt::SetIconHLRSelected() {
3862  // Theses actions should be in the app toolbar
3863 
3864  if (fToolbarApp == NULL) return;
3865  QList<QAction *> list = fToolbarApp->actions ();
3866  for (int i = 0; i < list.size(); ++i) {
3867  if (list.at(i)->data().toString () == "hidden_line_removal") {
3868  list.at(i)->setChecked(TRUE);
3869  } else if (list.at(i)->data().toString () == "solid") {
3870  list.at(i)->setChecked(FALSE);
3871  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3872  list.at(i)->setChecked(FALSE);
3873  } else if (list.at(i)->data().toString () == "wireframe") {
3874  list.at(i)->setChecked(FALSE);
3875  }
3876  }
3877 }
3878 
3879 
3880 void G4UIQt::SetIconHLHSRSelected() {
3881  // Theses actions should be in the app toolbar
3882 
3883  if (fToolbarApp == NULL) return;
3884  QList<QAction *> list = fToolbarApp->actions ();
3885  for (int i = 0; i < list.size(); ++i) {
3886  if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3887  list.at(i)->setChecked(TRUE);
3888  } else if (list.at(i)->data().toString () == "solid") {
3889  list.at(i)->setChecked(FALSE);
3890  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
3891  list.at(i)->setChecked(FALSE);
3892  } else if (list.at(i)->data().toString () == "wireframe") {
3893  list.at(i)->setChecked(FALSE);
3894  }
3895  }
3896 }
3897 
3898 
3899 void G4UIQt::SetIconPerspectiveSelected() {
3900  // Theses actions should be in the app toolbar
3901 
3902  if (fToolbarApp == NULL) return;
3903  QList<QAction *> list = fToolbarApp->actions ();
3904  for (int i = 0; i < list.size(); ++i) {
3905  if (list.at(i)->data().toString () == "perspective") {
3906  list.at(i)->setChecked(TRUE);
3907  } else if (list.at(i)->data().toString () == "ortho") {
3908  list.at(i)->setChecked(FALSE);
3909  }
3910  }
3911 }
3912 
3913 
3914 
3915 void G4UIQt::SetIconOrthoSelected() {
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 () == "ortho") {
3922  list.at(i)->setChecked(TRUE);
3923  } else if (list.at(i)->data().toString () == "perspective") {
3924  list.at(i)->setChecked(FALSE);
3925  }
3926  }
3927 }
3928 
3929 
3930 
3931 G4QTabWidget::G4QTabWidget(
3932 QWidget* aParent,
3933 int sizeX,
3934 int sizeY
3935 ):QTabWidget(aParent)
3936  ,fTabSelected(false)
3937  ,fLastCreated(-1)
3938 ,fPreferedSizeX(sizeX+6) // margin left+right
3939 ,fPreferedSizeY(sizeY+58) // tab label height + margin left+right
3940 {
3941  setMinimumSize(100,100);
3942  QSizePolicy policy = QSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
3943  setSizePolicy(policy);
3944 }
3945 
3946 G4QTabWidget::G4QTabWidget(
3947 ):QTabWidget()
3948  ,fTabSelected(false)
3949  ,fLastCreated(-1)
3950 ,fPreferedSizeX(0)
3951 ,fPreferedSizeY(0)
3952 {
3953 }
3954 
3955 
3956 G4UIOutputString::G4UIOutputString(
3957 QString text,
3958 G4String origine,
3959 G4String outputStream
3960 ):
3961  fText(text)
3962 ,fThread(origine)
3963 {
3964  if (!GetOutputList().contains(QString(" ")+outputStream+" ")) {
3965  fOutputStream = "info";
3966  } else {
3967  fOutputStream = outputStream;
3968  }
3969 }
3970 
3971 
3972 #if QT_VERSION < 0x040500
3973 void G4UIQt::TabCloseCallback(int){
3974 #else
3975 void G4UIQt::TabCloseCallback(int a){
3976 #endif
3977 #if QT_VERSION < 0x040500
3978 #else
3979  if (fViewerTabWidget == NULL) return;
3980 
3981  // get the address of the widget
3982  QWidget* temp = fViewerTabWidget->widget(a);
3983  // remove the tab
3984  fViewerTabWidget->removeTab (a);
3985 
3986  // delete the widget
3987  delete temp;
3988 #endif
3989 }
3990 
3991 
3992 void G4UIQt::ToolBoxActivated(int a){
3993 
3994  if (fUITabWidget->widget(a) == fHelpTBWidget) {
3995  // Rebuild the help tree
3996  FillHelpTree();
3997  } else if (fUITabWidget->widget(a) == fSceneTreeComponentsTBWidget) {
3998 #if QT_VERSION < 0x040200
3999  fSceneTreeComponentsTBWidget->show();
4000 #else
4001  fSceneTreeComponentsTBWidget->setVisible(true);
4002 #endif
4003  }
4004 }
4005 
4006 
4007 void G4QTabWidget::paintEvent(
4008 QPaintEvent *
4009 )
4010 {
4011 
4012  if (currentWidget()) {
4013 
4014  if ( isTabSelected()) {
4015 
4016  // QCoreApplication::sendPostedEvents () ;
4017 
4018  QString text = tabText (currentIndex());
4019 
4020  if (fLastCreated == -1) {
4021  QTextEdit* edit = dynamic_cast<QTextEdit*>(currentWidget());
4022  if (!edit){
4023  QString paramSelect = QString("/vis/viewer/select ")+text;
4025  if(UI != NULL) {
4026  UI->ApplyCommand(paramSelect.toStdString().c_str());
4027  }
4028  }
4029  } else {
4030  fLastCreated = -1;
4031  }
4032  setTabSelected(false);
4033  }
4034  }
4035 }
4036 
4037 
4038 G4UIDockWidget::G4UIDockWidget(QString txt):
4039  QDockWidget(txt)
4040 {}
4041 
4042 
4043 void G4UIDockWidget::closeEvent(QCloseEvent *aEvent) {
4044  setFloating (false);
4045 
4046  //prevent from closing
4047  aEvent->ignore();
4048  // hide them instead
4049  hide();
4050 }
4051 
4052 #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:175
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:173
G4UIcommandTree * GetTree() const
Definition: G4UImanager.hh:206
G4String & append(const G4String &)
G4String GetDefaultValue() const
void SetCoutDestination(G4UIsession *const value)
Definition: G4UImanager.cc:618
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:694
G4bool GetCurrentAsDefault() const
G4bool isNull() const
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:446