Geant4  10.03
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 101789 2016-11-28 15:31:24Z 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 "G4UIcommand.hh"
40 #include "G4StateManager.hh"
41 #include "G4UIcommandTree.hh"
42 #include "G4UIcommandStatus.hh"
43 #include "G4MTcoutDestination.hh"
44 #include "G4Qt.hh"
45 
46 #include <qapplication.h>
47 #include <qmessagebox.h>
48 #include <qlineedit.h>
49 #include <qwidget.h>
50 #include <qmenubar.h>
51 #include <qlayout.h>
52 #include <qpushbutton.h>
53 #include <qlabel.h>
54 #include <qsplitter.h>
55 #include <qscrollbar.h>
56 #include <qdialog.h>
57 #include <qevent.h>
58 #include <qtextedit.h>
59 #include <qsignalmapper.h>
60 #include <qtabwidget.h>
61 #include <qtabbar.h>
62 #include <qstringlist.h>
63 #include <qtextstream.h>
64 
65 #include <qmainwindow.h>
66 #include <qmenu.h>
67 #include <qlistwidget.h>
68 #include <qtreewidget.h>
69 #include <qheaderview.h>
70 #include <qgroupbox.h>
71 #include <qscrollarea.h>
72 #include <qtoolbox.h>
73 #include <qradiobutton.h>
74 #include <qbuttongroup.h>
75 #include <qcombobox.h>
76 #include <qsignalmapper.h>
77 #include <qpainter.h>
78 #include <qcolordialog.h>
79 #include <qtoolbar.h>
80 #include <qfiledialog.h>
81 #include <qdesktopwidget.h>
82 #include <qtablewidget.h>
83 #include <qcompleter.h>
84 #include <qstandarditemmodel.h>
85 #include <qboxlayout.h>
86 #include <stdlib.h>
87 
88 // Pourquoi Static et non variables de classe ?
89 static G4bool exitSession = true;
90 static G4bool exitPause = true;
91 
112 G4UIQt::G4UIQt (
113  int argc
114 ,char** argv
115 )
116 :fMainWindow(NULL)
117 ,fCommandLabel(NULL)
118 ,fCommandArea(NULL)
119 ,fCoutTBTextArea(NULL)
120 ,fUITabWidget(NULL)
121 ,fCoutFilter(NULL)
122 ,fCompleter(NULL)
123 ,fDefaultIcons(true)
124 ,fHistoryTBTableList(NULL)
125 ,fHelpTreeWidget(NULL)
126 ,fHelpTBWidget(NULL)
127 ,fHistoryTBWidget(NULL)
128 ,fCoutDockWidget(NULL)
129 ,fUIDockWidget(NULL)
130 ,fSceneTreeWidget(NULL)
131 ,fViewerPropertiesWidget(NULL)
132 ,fPickInfosWidget(NULL)
133 ,fHelpLine(NULL)
134 ,fViewerTabWidget(NULL)
135 ,fCoutText("Output")
136 ,fStartPage(NULL)
137 ,fHelpVSplitter(NULL)
138 ,fParameterHelpLabel(NULL)
139 ,fParameterHelpTable(NULL)
140 ,fToolbarApp(NULL)
141 ,fToolbarUser(NULL)
142 ,fStringSeparator("__$$$@%%###__")
143 ,fLastOpenPath("")
144 ,fSearchIcon(NULL)
145 ,fClearIcon(NULL)
146 ,fSaveIcon(NULL)
147 ,fOpenIcon(NULL)
148 ,fMoveIcon(NULL)
149 ,fRotateIcon(NULL)
150 ,fPickIcon(NULL)
151 ,fZoomInIcon(NULL)
152 ,fZoomOutIcon(NULL)
153 ,fWireframeIcon(NULL)
154 ,fSolidIcon(NULL)
155 ,fHiddenLineRemovalIcon(NULL)
156 ,fHiddenLineAndSurfaceRemovalIcon(NULL)
157 ,fPerspectiveIcon(NULL)
158 ,fOrthoIcon(NULL)
159 ,fCommandIcon(NULL)
160 ,fDirIcon(NULL)
161 ,fRunIcon(NULL)
162 ,fParamIcon(NULL)
163 ,fPickTargetIcon(NULL)
164 #ifdef G4MULTITHREADED
165 ,fThreadsFilterComboBox(NULL)
166 #endif
167 ,fDefaultViewerFirstPageHTMLText("")
168 ,fViewerPropertiesDialog(NULL)
169 ,fPickInfosDialog(NULL)
170 ,fMoveSelected(false)
171 ,fRotateSelected(true)
172 ,fPickSelected(false)
173 ,fZoomInSelected(false)
174 ,fZoomOutSelected(false)
175 {
176 
177  G4Qt* interactorManager = G4Qt::getInstance (argc,argv,(char*)"Qt");
178  if (!(QApplication*)interactorManager->GetMainInteractor()) {
179  G4UImanager* UImanager = G4UImanager::GetUIpointer();
180  G4int verbose = UImanager->GetVerboseLevel();
181 
182  if (verbose >= 2) {
183  G4cout << "G4UIQt : Unable to init Qt. Aborted" << G4endl;
184  }
185  }
186 
188  if(UI!=NULL) UI->SetSession(this);
189  if(UI!=NULL) UI->SetG4UIWindow(this);
190 
191  // Check if already define in external app QMainWindow
192  bool found = false;
193  Q_FOREACH (QWidget *widget, QApplication::allWidgets()) {
194  if ((found== false) && (widget->inherits("QMainWindow"))) {
195  found = true;
196  }
197  }
198 
199  if (found) {
200  G4UImanager* UImanager = G4UImanager::GetUIpointer();
201  G4int verbose = UImanager->GetVerboseLevel();
202 
203  if (verbose >= 2) {
204  G4cout << "G4UIQt : Found an external App with a QMainWindow already defined. Aborted" << G4endl;
205  }
206  return ;
207  }
208  CreateIcons();
209 
210  fMainWindow = new QMainWindow();
211 
212  fMainWindow->setCorner( Qt::TopLeftCorner, Qt::LeftDockWidgetArea );
213  fMainWindow->setCorner( Qt::TopRightCorner, Qt::RightDockWidgetArea );
214  fMainWindow->setCorner( Qt::BottomLeftCorner, Qt::LeftDockWidgetArea );
215  fMainWindow->setCorner( Qt::BottomRightCorner, Qt::RightDockWidgetArea );
216 
217  CreateViewerWidget();
218  fMainWindow->addDockWidget(Qt::LeftDockWidgetArea, CreateUITabWidget());
219  fMainWindow->addDockWidget(Qt::BottomDockWidgetArea, CreateCoutTBWidget());
220 
221 
222  // add defaults icons
223  SetDefaultIconsToolbar();
224 
225  if(UI!=NULL) UI->SetCoutDestination(this); // TO KEEP
226 
227 #ifdef G4MULTITHREADED
228  // explicitly request that cout/cerr messages from threads are ALSO propagated to the master.
229  masterG4coutDestination = this;
230 #endif
231 
232  fMainWindow->setWindowTitle(QFileInfo( QCoreApplication::applicationFilePath() ).fileName());
233  fMainWindow->move(QPoint(50,50));
234 
235  // force the size at be correct at the beggining
236  // because the widget is not realized yet, the size of the main window is not up to date. But
237  // we need it in order to add some viewer inside
238  fMainWindow->resize(fUIDockWidget->width()+fCoutDockWidget->width()+20,
239  fUIDockWidget->height()+fCoutDockWidget->height()+20);
240 
241  // set last focus on command line
242  fCommandArea->setFocus(Qt::TabFocusReason);
243 
244  // Allow QTextCursor to be called by another thread :
245  // http://qt-project.org/doc/qt-4.8/qmetatype.html#qRegisterMetaType
246  qRegisterMetaType<QTextCursor>("QTextCursor");
247 
248  // add some tips
249  AddTabWidget(fStartPage,"Useful tips");
250 
251  // Set not visible until session start
252  #if QT_VERSION < 0x040200
253  fMainWindow->hide();
254  #else
255  fMainWindow->setVisible(false);
256  #endif
257 }
258 
259 
260 
261 G4UIQt::~G4UIQt(
262 )
263 {
264  G4UImanager* UI = G4UImanager::GetUIpointer(); // TO KEEP
265  if(UI!=NULL) { // TO KEEP
266  UI->SetSession(NULL); // TO KEEP
267  UI->SetG4UIWindow(NULL);
268  UI->SetCoutDestination(0); // TO KEEP
269 #ifdef G4MULTITHREADED
270  masterG4coutDestination = 0; // set to cout when UI is deleted
271 #endif
272  }
273 
274  if (fMainWindow!=NULL) {
275  delete fMainWindow;
276  }
277 }
278 
279 
280 void G4UIQt::DefaultIcons(bool aVal)
281 {
282  fDefaultIcons = aVal;
283 
284 #if QT_VERSION < 0x040200
285  if (!fMainWindow->isHidden()) {
286 #else
287  if (!fMainWindow->isVisible()) {
288 #endif
289  return;
290  }
291 
292  if (fToolbarApp) {
293  if (aVal) {
294 #if QT_VERSION < 0x040200
295  fToolbarApp->show();
296 #else
297  fToolbarApp->setVisible(true);
298 #endif
299  } else {
300  // Set not visible until session start
301 #if QT_VERSION < 0x040200
302  fToolbarApp->hide();
303 #else
304  fToolbarApp->setVisible(false);
305 #endif
306  }
307  }
308 }
309 
310 
311 void G4UIQt::SetDefaultIconsToolbar(
312 ) {
313 
314  if (fDefaultIcons) {
315  if (fToolbarApp == NULL) {
316  fToolbarApp = new QToolBar();
317  fToolbarApp->setIconSize (QSize(20,20));
318  fMainWindow->addToolBar(Qt::TopToolBarArea, fToolbarApp);
319  }
320 
321  // Open/Save Icons
322  AddIcon("Open macro file","open", "/control/execute");
323  AddIcon("Save viewer state", "save", "/vis/viewer/save");
324 
325  // View parameters
326  QSignalMapper *signalMapperViewerProperties = new QSignalMapper(this);
327  QAction *actionViewerProperties = fToolbarApp->addAction(QIcon(*fParamIcon),"Viewer properties", signalMapperViewerProperties, SLOT(map()));
328  connect(signalMapperViewerProperties, SIGNAL(mapped(int)),this, SLOT(ViewerPropertiesIconCallback(int)));
329  int intVP = 0;
330  signalMapperViewerProperties->setMapping(actionViewerProperties, intVP);
331 
332  // Cursors style icons
333  AddIcon("Move", "move", "");
334  AddIcon("Pick", "pick", "");
335  AddIcon("Zoom out", "zoom_out", "");
336  AddIcon("Zoom in", "zoom_in", "");
337  AddIcon("Rotate", "rotate", "");
338 
339  // Surface Style icons
340  AddIcon("Hidden line removal", "hidden_line_removal", "");
341  AddIcon("Hidden line and hidden surface removal", "hidden_line_and_surface_removal", "");
342  AddIcon("Surfaces", "solid", "");
343  AddIcon("Wireframe", "wireframe", "");
344 
345  // Perspective/Ortho icons
346  AddIcon("Perspective", "perspective","");
347  AddIcon("Orthographic", "ortho","");
348  AddIcon("Run beam on", "runBeamOn","/run/beamOn 1");
349  }
350 }
351 
352 
353 void G4UIQt::CreateIcons(
354 )
355 {
356  const char * const save[]={
357  "32 32 24 1",
358  " c None",
359  "+ c #000200",
360  "@ c #141E43",
361  "# c #000C56",
362  "$ c #494A47",
363  "% c #636662",
364  "& c #312F2A",
365  "* c #191B19",
366  "= c #002992",
367  "- c #003DFF",
368  "; c #041DA5",
369  "> c #A8A9A3",
370  ", c #FDFFFC",
371  "' c #DDE0DD",
372  ") c #818783",
373  "! c #C9CBC8",
374  "~ c #0116C3",
375  "{ c #C5C8FA",
376  "] c #6596FC",
377  "^ c #A0B4F9",
378  "/ c #0B2AFD",
379  "( c #799BE3",
380  "_ c #5F4826",
381  ": c #D5D8D5",
382  " ",
383  " ",
384  " +++++++++++++++++++++++++ ",
385  " +@##+$%%%%%%%%%%%%%%%&*$%&+ ",
386  " +=-;@>,,''',,,,,,,',,)&!,)+ ",
387  " +;-~@>,,,,,,,,,,,,,,,>$!,)+ ",
388  " +=-~@>,,,,,{]]]]]^,,,>*&$&+ ",
389  " +=-~@>,,,,,'{^{^^{,,,>*#=#+ ",
390  " +=-~@>,,,,,,,,,,,,,,,>@~/=+ ",
391  " +=-~@>,,,{{{''''{',,,>@~-=+ ",
392  " +=-~@>,,'^]]]]]]({,,,>@~-=+ ",
393  " +=-~@>,,,{{{{{{{{{,,,>@~-=+ ",
394  " +=-~@>,,,,,'{^{{^{,,,>@~-=+ ",
395  " +=-~@>,,,,,]]]]]]],,,>@~-=+ ",
396  " +=-~*>,,,,,,,,,,,,,,,>@~-=+ ",
397  " +=-~@>,,,,,,,,,,,,,,,>@~-=+ ",
398  " +=-/=$%%%%%%%%%%%%%%%$=/-=+ ",
399  " +=---;###############;---=+ ",
400  " +=---////////////////----=+ ",
401  " +=----------------///----=+ ",
402  " +=---=@##############@#--=+ ",
403  " +=---@+++++++++++*%))_+~-=+ ",
404  " +=---#+++++++++++&:,,>@~-=+ ",
405  " +=---#+++++++++++$',,>@~-=+ ",
406  " +=---#+++++++++++&!,,>@~-=+ ",
407  " +=/--#+++++++++++&',,>@~-=+ ",
408  " @;--#+++++++++++$',,>@~-=+ ",
409  " @;;@+++++++++++*)!>%@=;#+ ",
410  " @++++++++++++++*&**++@++ ",
411  " ",
412  " ",
413  " "}
414  ;
415  fSaveIcon = new QPixmap(save);
416 
417  const char * const search[] = {
418  /* columns rows colors chars-per-pixel */
419  "19 19 8 1",
420  " c #5C5C5C",
421  ". c #7D7D7D",
422  "X c #9B9B9B",
423  "o c #C3C3C3",
424  "O c None",
425  "+ c #000000",
426  "@ c #000000",
427  "# c None",
428  /* pixels */
429  "OOOOOOOOOOOOOOOOOOO",
430  "OOOOOOOOOOOOOOOOOOO",
431  "OOOOOOOo. .oOOOOOO",
432  "OOOOOOX XOOOOO",
433  "OOOOOo XOOX oOOOO",
434  "OOOOO. XOOOOX .OOOO",
435  "OOOOO OOOOOO OOOO",
436  "OOOOO OOOOOO OOOO",
437  "OOOOO. XOOOOo .OOOO",
438  "OOOOOo oOOo oOOOO",
439  "OOOOOOX XOOOO",
440  "OOOOOOOo. . XOOO",
441  "OOOOOOOOOOOOO. XOO",
442  "OOOOOOOOOOOOOO. XOO",
443  "OOOOOOOOOOOOOOOoOOO",
444  "OOOOOOOOOOOOOOOOOOO",
445  "OOOOOOOOOOOOOOOOOOO",
446  "OOOOOOOOOOOOOOOOOOO",
447  "OOOOOOOOOOOOOOOOOOO"
448  };
449  fSearchIcon = new QPixmap(search);
450 
451  const char * const clear[] = {
452  /* columns rows colors chars-per-pixel */
453  "20 20 8 1",
454  " c #020202",
455  ". c #202020",
456  "X c #2C2C2C",
457  "o c #797979",
458  "O c None",
459  "+ c #797979",
460  "@ c #797979",
461  "# c #797979",
462  /* pixels */
463  "OOOOOOOOOOOOOOOOOOOO",
464  "OOOOOOOo oOOOOOOO",
465  "OOOOOXX XXOOOOO",
466  "OOOOOOOOOOOOOOOOOOOO",
467  "OOOOOOOOOOOOOOOOOOOO",
468  "OOOO XXXXXXXXXX OOOO",
469  "OOO XOOOOOOOOOO OOO",
470  "OOOOXOooOooOooO OOOO",
471  "OOOOXOooOooOooO OOOO",
472  "OOOOXOooOooOooO OOOO",
473  "OOOOXOooOooOooO OOOO",
474  "OOOOXOooOooOooO OOOO",
475  "OOOOXOooOooOooO OOOO",
476  "OOOOXOooOooOooO OOOO",
477  "OOOOXOooOooOooO OOOO",
478  "OOOOXOooOooOooO OOOO",
479  "OOOOXOooOooOooO OOOO",
480  "OOOOXOOOOOOOOOO OOOO",
481  "OOOOOooooooooooOOOOO",
482  "OOOOOO........OOOOOO"
483  };
484 
485  fClearIcon = new QPixmap(clear);
486 
487 
488  const char * const open[]={
489  "32 32 33 1",
490  " c None",
491  "+ c #09091E",
492  "@ c #191B18",
493  "# c #5F615F",
494  "$ c #777977",
495  "% c #AEB1AF",
496  "& c #929491",
497  "* c #515250",
498  "= c #858784",
499  "- c #333533",
500  "; c #000100",
501  "> c #272926",
502  ", c #424341",
503  "' c #696C6A",
504  ") c #5F4927",
505  "! c #583D18",
506  "~ c #6E6A5B",
507  "{ c #47351D",
508  "] c #E0A554",
509  "^ c #FFD67B",
510  "/ c #EFB465",
511  "( c #FDBF6C",
512  "_ c #FFCD76",
513  ": c #806238",
514  "< c #362611",
515  "[ c #0B0D0A",
516  "} c #68471B",
517  "| c #523E22",
518  "1 c #B78A51",
519  "2 c #A17B44",
520  "3 c #D6A45E",
521  "4 c #C29354",
522  "5 c #A1A3A0",
523  " ",
524  " ",
525  " +@@@# ",
526  " $% +& * ",
527  " #= $ -; ",
528  " %>;+ ",
529  " ,;;+ ",
530  " &#$''#' >;;;+ ",
531  " =)!)!!!!~ *#$'' ",
532  " {]^/((_({- %%%%%%%%%%% ",
533  " {(^_^^^^:<{{{{{{{{{{{{{[& ",
534  " {/_/(((((/]]]]]]]]]]]/]!# ",
535  " {/^(((((_^^^^^^^^^^^^^^:# ",
536  " {/^(((_^^____________^^}$ ",
537  " {/^(((((/////////////((!# ",
538  " {/^/^_:<|||||||||||||||@@****1 ",
539  " {/^/^(<[)||||||||||||||))!!}<; ",
540  " {/^_(:|234444444444444444432)1 ",
541  " {/_^/<)34444444444444444443}, ",
542  " {/^(2{:41111111111111111142|5 ",
543  " {3^3<:31111111111111111143}- ",
544  " {/^2<:31111111111111111441|' ",
545  " {_/<:41111111111111111143}, ",
546  " {(4<:31111111111111111144!# ",
547  " )4))44111111111111111144}, ",
548  " )2<:31111111111111111144{# ",
549  " @|:14444444444444444444}* ",
550  " ;@434444444444444444434<# ",
551  " ;[))))))))))))))))))))!~ ",
552  " ++++++++++++++++++++++;% ",
553  " ",
554  " "}
555  ;
556  fOpenIcon = new QPixmap(open);
557 
558 
559  const char * const move[]={
560  "32 32 16 1",
561  " c None",
562  ". c #F1F1F1",
563  "+ c #939393",
564  "@ c #282828",
565  "# c #787878",
566  "$ c #000000",
567  "% c #CCCCCC",
568  "& c #1A1A1A",
569  "* c #0D0D0D",
570  "= c #5D5D5D",
571  "- c #AEAEAE",
572  "; c #BBBBBB",
573  "> c #C9C9C9",
574  ", c #D6D6D6",
575  "' c #FFFFFF",
576  ") c #999999",
577  " ",
578  " ",
579  " ",
580  " ",
581  " .. ",
582  " ++ ",
583  " .@@. ",
584  " #$$# ",
585  " %&$$*% ",
586  " =$$$$= ",
587  " -**$$**- ",
588  " %;%&*>;% ",
589  " -% @& %- ",
590  " ,=*; @& ;*=, ",
591  " .#*$$> >$$*#. ",
592  " ')&$$$$*@@ @@*$$$$&)' ",
593  " ')&$$$$*@@ @@*$$$$&+' ",
594  " .#*$$> >$$*#. ",
595  " ,=*; @& ;*=, ",
596  " -% @& %- ",
597  " %;%&*>>% ",
598  " -**$$**- ",
599  " =$$$$= ",
600  " %&$$*% ",
601  " #$$# ",
602  " .@@. ",
603  " ++ ",
604  " .. ",
605  " ",
606  " ",
607  " ",
608  " "}
609  ;
610  fMoveIcon = new QPixmap(move);
611 
612  const char * const rotate[]={
613  "32 32 27 1",
614  " c None",
615  ". c #003333",
616  "+ c #000066",
617  "@ c #1A1A1A",
618  "# c #003399",
619  "$ c #3333CC",
620  "% c #000033",
621  "& c #353535",
622  "* c #434343",
623  "= c #336699",
624  "- c #3399FF",
625  "; c #003366",
626  "> c #5D5D5D",
627  ", c #282828",
628  "' c #3399CC",
629  ") c #333333",
630  "! c #3366CC",
631  "~ c #333399",
632  "{ c #505050",
633  "] c #666666",
634  "^ c #333366",
635  "/ c #0033CC",
636  "( c #3366FF",
637  "_ c #336666",
638  ": c #787878",
639  "< c #868686",
640  "[ c #6B6B6B",
641  " .++@ ",
642  " #$$%&* ",
643  " =--; *>, ",
644  " '-= )>& ",
645  " !-', ,>* ",
646  " !!=--= >* ",
647  " =------!!~@&)@ ",
648  " --------!*{{{*&, ",
649  " -------=){*{{{>>{) ",
650  " ,!-----= ){& ,&{{@",
651  " ,*>!----= &>& )@",
652  " ){>)~---= *]) @",
653  " @*>, --! ,&@ ",
654  " @{* '! ,-!=~^,@ ",
655  " @& == {/(----!^ ",
656  " _ ]:;(----' ",
657  " ==_ >{+(----~ ",
658  " !-!!======!!(((---! ",
659  " ='--------------! ",
660  " =!!!!'!!=; !-! ",
661  " &<* !~ ",
662  " @. *[* ; ",
663  " ;+)>* ",
664  " @@ ",
665  " ",
666  " ",
667  " ",
668  " ",
669  " ",
670  " ",
671  " ",
672  " "}
673  ;
674  fRotateIcon = new QPixmap(rotate);
675 
676  const char * const pick[]={
677  /* columns rows colors chars-per-pixel */
678  "20 20 12 1 ",
679  " c #050804",
680  ". c #222321",
681  "X c #3B3C3A",
682  "o c #4C4E4B",
683  "O c #616360",
684  "+ c #747673",
685  "@ c #8A8C89",
686  "# c #9FA19E",
687  "$ c #BABCB9",
688  "% c #CED0CD",
689  "& c #E4E6E3",
690  "* c None",
691  /* pixels */
692  "*********oo*********",
693  "*********oo*********",
694  "******$O. .O%******",
695  "****&o .O..O O*****",
696  "***&X @**oo**@ X****",
697  "***o $***oo***$ O***",
698  "**% @**********@ %**",
699  "**O.***********& +**",
700  "**.O*****@@*****o.**",
701  "oo .oo**@ #*&XX. oo",
702  "oo .oo**@ #*&oo. oO",
703  "**.O*****##*****oX**",
704  "**O ***********& +**",
705  "**% @****&&****+ &**",
706  "***O $***Xo***# +***",
707  "****X @&*Xo*&+ o****",
708  "*****O o..o +*****",
709  "******%+. X+&******",
710  "*********oo*********",
711  "*********oO*********"
712  };
713  fPickIcon = new QPixmap(pick);
714 
715  const char * const zoom_in[]={
716  "32 32 11 1",
717  " c None",
718  ". c #C9CBC8",
719  "+ c #A8A9A3",
720  "@ c #818783",
721  "# c #D5D8D5",
722  "$ c #9BCCCC",
723  "% c #5FC7F4",
724  "& c #FDFFFC",
725  "* c #636662",
726  "= c #9599CE",
727  "- c #DDE0DD",
728  " ",
729  " ",
730  " ",
731  " ",
732  " ",
733  " .++@@++. ",
734  " +++..#.+++ ",
735  " .@+...++++#+@. ",
736  " @$.%%+&&&@%..@ ",
737  " ++.%%%+&&&*%%.++ ",
738  " .+#%%%%+&&&*%%.#+ ",
739  " ++..%%%+&&&*%%%.++ ",
740  " +#.+++++&&&*++++.+ ",
741  " @.+&&&&&&&&&&&&&+@ ",
742  " @#+&&&&&&&&&&&&&+@ ",
743  " @.+&&&&&&&&&&&&&+. ",
744  " +++@***+&&&****@+. ",
745  " ....++++&&&*++++.. ",
746  " ++.===+&&&*%=.++ ",
747  " @..==+&&&*=..@#& ",
748  " .@+#.+&&&@-+@@*@ ",
749  " +++.++++++ *+@* ",
750  " .+@@@++. @**+* ",
751  " .*@*+* ",
752  " .*@*+* ",
753  " +*@@* ",
754  " .**+ ",
755  " ",
756  " ",
757  " ",
758  " ",
759  " "}
760  ;
761  fZoomInIcon = new QPixmap(zoom_in);
762 
763  const char * const zoom_out[]={
764  "32 32 11 1",
765  " c None",
766  ". c #C9CBC8",
767  "+ c #A8A9A3",
768  "@ c #818783",
769  "# c #D5D8D5",
770  "$ c #5FC7F4",
771  "% c #9BCCCC",
772  "& c #FDFFFC",
773  "* c #636662",
774  "= c #9599CE",
775  "- c #DDE0DD",
776  " ",
777  " ",
778  " ",
779  " ",
780  " ",
781  " .++@@++. ",
782  " +++..#.+++ ",
783  " .@+..$$$$.#+@. ",
784  " @%.$$$$$$$$..@ ",
785  " ++.$$$$$$$$$$.++ ",
786  " .+#$$$$$$$$$$$.#+ ",
787  " ++..$$$$$$$$$$$.++ ",
788  " +#.+++++++++++++.+ ",
789  " @.+&&&&&&&&&&&&&+@ ",
790  " @#+&&&&&&&&&&&&&+@ ",
791  " @.+&&&&&&&&&&&&&+. ",
792  " +++@***********@+. ",
793  " ....++++++++++++.. ",
794  " ++.===$$$$$$=.++ ",
795  " @..===$$$$=..@#& ",
796  " .@+#.$$$..-+@@*@ ",
797  " +++#--.+++ *+@* ",
798  " .+@@@++. @**+* ",
799  " .*@*+* ",
800  " .*@*+* ",
801  " +*@@* ",
802  " .**+ ",
803  " ",
804  " ",
805  " ",
806  " ",
807  " "}
808  ;
809  fZoomOutIcon = new QPixmap(zoom_out);
810 
811  const char * const wireframe[]={
812  "32 32 24 1",
813  " c None",
814  "+ c #E4E4E4",
815  "@ c #D5D5D5",
816  "# c #E1E1E1",
817  "$ c #E7E7E7",
818  "% c #D8D8D8",
819  "& c #A7A7A7",
820  "* c #000000",
821  "= c #989898",
822  "- c #8A8A8A",
823  "; c #B5B5B5",
824  "> c #1B1B1B",
825  ", c #676767",
826  "' c #959595",
827  ") c #4A4A4A",
828  "! c #878787",
829  "~ c #D3D3D3",
830  "{ c #C4C4C4",
831  "] c #A4A4A4",
832  "^ c #5B5B5B",
833  "/ c #B3B3B3",
834  "( c #787878",
835  "_ c #C7C7C7",
836  ": c #585858",
837  " ",
838  " +@@# ",
839  " $%@@@@@&****=+ ",
840  " +&********&@-***; ",
841  " +@@@&**&@@@@@@$ @*-&>&+ ",
842  " +*****&+ %*@ ,**'# ",
843  " @***)!~ @*{&*****+ ",
844  " @*!]***&+ +-*^**'~!*@ ",
845  " @*~ +@&**&@@@@@@&****&+ ~*@ ",
846  " @*@ +&********&-*= @*@ ",
847  " @*@ $%@-*-@$ @*@ @*@ ",
848  " @*@ @*@ %*% @*@ ",
849  " @*@ %*% %*% @*@ ",
850  " @*@ %*% %*% @*@ ",
851  " @*@ %*% %*% @*@ ",
852  " @*@ %*% %*% @*@ ",
853  " @*@ %*% %*% @*@ ",
854  " @*@ @*@ %*% @*@ ",
855  " @*@ =*-+ @*@ @*@ ",
856  " @*@ $%@@&****&@-*-+ @*@ ",
857  " @*@ $@&*****&@@&******&~~!*@ ",
858  " @*{/***&@@%$ $@-*-&*****+ ",
859  " @*)*)(-~ @*@ ~)**] ",
860  " +*******&@@@@+ %*_+]**] ",
861  " +@@@@@&******&@%+_*^**]# ",
862  " $%@@@&****:**&+ ",
863  " +%@&**& ",
864  " ++ ",
865  " ",
866  " ",
867  " ",
868  " "}
869  ;
870  fWireframeIcon = new QPixmap(wireframe);
871 
872  const char * const solid[]={
873  "32 32 33 1",
874  " c None",
875  "+ c #C2DEDE",
876  "@ c #B5D7DF",
877  "# c #ACD6E6",
878  "$ c #60C0EC",
879  "% c #4EB7EE",
880  "& c #53B9ED",
881  "* c #82CEEA",
882  "= c #CFDDDA",
883  "- c #94C9E8",
884  "; c #0960FF",
885  "> c #0943FF",
886  ", c #0949FF",
887  "' c #3CB3F0",
888  ") c #71C7EB",
889  "! c #73CBE5",
890  "~ c #D3DDDB",
891  "{ c #C4DDDE",
892  "] c #B7D5DF",
893  "^ c #2DACF5",
894  "/ c #59C1ED",
895  "( c #5FC0ED",
896  "_ c #85CEE9",
897  ": c #096BFF",
898  "< c #2AACF6",
899  "[ c #5CBEEC",
900  "} c #7ACAE4",
901  "| c #73CAEB",
902  "1 c #71C8E5",
903  "2 c #D1DDDA",
904  "3 c #CBDDD9",
905  "4 c #67C1EB",
906  "5 c #80CDEA",
907  " ",
908  " ",
909  " +@@@@@@#$%&*= ",
910  " +-;>>>>>>>>>,')!~ ",
911  " {]@@-;>>>>>>>>>>>>^/(_= ",
912  " {:>>>>>>>>>>>>>>>>><//[)!= ",
913  " ]>>>>>>>>>>>>>>>>>><////[)} ",
914  " @>>>>>>>>>>>>>>>>>><//////| ",
915  " @>>>>>>>>>>>>>>>>>><//////| ",
916  " @>>>>>>>>>>>>>>>>>><//////| ",
917  " @>>>>>>>>>>>>>>>>>><//////| ",
918  " @>>>>>>>>>>>>>>>>>><//////| ",
919  " @>>>>>>>>>>>>>>>>>><//////| ",
920  " @>>>>>>>>>>>>>>>>>><//////| ",
921  " @>>>>>>>>>>>>>>>>>><//////| ",
922  " @>>>>>>>>>>>>>>>>>><//////| ",
923  " @>>>>>>>>>>>>>>>>>><//////| ",
924  " @>>>>>>>>>>>>>>>>>><//////| ",
925  " @>>>>>>>>>>>>>>>>>><//////| ",
926  " @>>>>>>>>>>>>>>>>>><//////| ",
927  " @>>>>>>>>>>>>>>>>>><//////| ",
928  " @>>>>>>>>>>>>>>>>>></////[1 ",
929  " @>>>>>>>>>>>>>>>>>><////[*2 ",
930  " {:>>>>>>>>>>>>>>>>><//[)12 ",
931  " +@@@@@-;>>>>>>>>>><[)13 ",
932  " {]@@@-;>>>,'*3 ",
933  " +@@#452 ",
934  " ",
935  " ",
936  " ",
937  " ",
938  " "}
939  ;
940  fSolidIcon = new QPixmap(solid);
941 
942  const char * const hidden_line_removal[]={
943  "32 32 15 1",
944  " c None",
945  "+ c #D5D5D5",
946  "@ c #C7C7C7",
947  "# c #9C9C9C",
948  "$ c #000000",
949  "% c #8E8E8E",
950  "& c #808080",
951  "* c #A9A9A9",
952  "= c #D8D8D8",
953  "- c #CACACA",
954  "; c #181818",
955  "> c #9F9F9F",
956  ", c #ACACAC",
957  "' c #B9B9B9",
958  ") c #555555",
959  " ",
960  " +@@+ ",
961  " +@@@@@@#$$$$%+ ",
962  " +#$$$$$$$$#@&$$$* ",
963  " =-@@#$$#@@@@@-= @$&#;>= ",
964  " =$$$$$#+ -$@ *$$%+ ",
965  " -$&@-= -$- #$$$= ",
966  " -$@ -$- +&$- ",
967  " @$@ @$@ @$@ ",
968  " @$@ @$@ @$@ ",
969  " @$@ @$@ @$@ ",
970  " @$@ @$@ @$@ ",
971  " @$@ @$@ @$@ ",
972  " @$@ @$@ @$@ ",
973  " @$@ @$@ @$@ ",
974  " @$@ @$@ @$@ ",
975  " @$@ @$@ @$@ ",
976  " @$@ @$@ @$@ ",
977  " @$@ @$@ @$@ ",
978  " @$@ @$@ @$@ ",
979  " @$@ @$@ @$@ ",
980  " @$@ @$@ #$= ",
981  " -$&@@@-= -$- =>;, ",
982  " =$$$$$$$#@@@-= -$'+#$$, ",
983  " =-@@@@#$$$$$$#@-+'$)$$#+ ",
984  " =-@@@#$$$$)$$#+ ",
985  " +@@#$$# ",
986  " ++ ",
987  " ",
988  " ",
989  " ",
990  " "}
991  ;
992  fHiddenLineRemovalIcon = new QPixmap(hidden_line_removal);
993 
994  const char * const hidden_line_and_surface_removal[]={
995  "32 32 40 1",
996  " c None",
997  "+ c #FFFFFF",
998  "@ c #89A2E9",
999  "# c #5378E3",
1000  "$ c #A2B5ED",
1001  "% c #5379E3",
1002  "& c #5076E3",
1003  "* c #3E69E4",
1004  "= c #0C43F8",
1005  "- c #043FFE",
1006  "; c #CDD9ED",
1007  "> c #BDCDE9",
1008  ", c #FBFCFC",
1009  "' c #406AE4",
1010  ") c #0439FE",
1011  "! c #0137FF",
1012  "~ c #4F75E3",
1013  "{ c #9EB5E3",
1014  "] c #829FE0",
1015  "^ c #B6C6E7",
1016  "/ c #9DB4E3",
1017  "( c #7E9CE0",
1018  "_ c #B2C3E9",
1019  ": c #7E9AE0",
1020  "< c #86A2E1",
1021  "[ c #CAD6ED",
1022  "} c #5177E3",
1023  "| c #829CE0",
1024  "1 c #BCCCE9",
1025  "2 c #3A67E6",
1026  "3 c #0A43FA",
1027  "4 c #95ACE1",
1028  "5 c #BBCBE9",
1029  "6 c #A9BBE5",
1030  "7 c #96AFE1",
1031  "8 c #BDCBE9",
1032  "9 c #4067E4",
1033  "0 c #6485E5",
1034  "a c #E3EAF3",
1035  "b c #CAD6F3",
1036  " ",
1037  " ",
1038  " ++++ ",
1039  " ++++++++@#$+++ ",
1040  " ++@%####&*=-#+;>, ",
1041  " +++++@'=)))))))!)~+{]^++ ",
1042  " +$%&*=)!!!!!!!!!)~+/(]_+++ ",
1043  " +#-))!!!!!!!!!!!)~+/(::<[+ ",
1044  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1045  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1046  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1047  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1048  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1049  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1050  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1051  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1052  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1053  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1054  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1055  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1056  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1057  " +#)!!!!!!!!!!!!!!}+/:::|1+ ",
1058  " +$#}}~23!!!!!!!!)~+/(]45, ",
1059  " +++++++@#}}~23!!)~+678++ ",
1060  " ++++++@#~90+a++ ",
1061  " ++++b++ ",
1062  " ++ ",
1063  " ",
1064  " ",
1065  " ",
1066  " ",
1067  " "}
1068  ;
1069  fHiddenLineAndSurfaceRemovalIcon = new QPixmap(hidden_line_and_surface_removal);
1070 
1071  const char * const perspective[]={
1072  "32 32 3 1",
1073  " c None",
1074  ". c #D5D8D5",
1075  "+ c #000000",
1076  " ",
1077  " ",
1078  " ",
1079  " ",
1080  " ",
1081  " ................ ",
1082  " ....+++++++++++++++. ",
1083  " ...++++..+.........+++. ",
1084  " ..++..............++..+. ",
1085  " .+++++++++++++++++.. .+. ",
1086  " .+...............+. .+. ",
1087  " .+. .+. .+. .+. ",
1088  " .+. .+. .+. .+. ",
1089  " .+. .+. .+. .+. ",
1090  " .+. .+. .+. .+. ",
1091  " .+. .+. .+. .+. ",
1092  " .+. .+. .+. .+. ",
1093  " .+. .+. .+. .+. ",
1094  " .+. .+. .+. .+. ",
1095  " .+. .+......+....+. ",
1096  " .+. ..++++++.+.++++. ",
1097  " .+. .++.......+...+.. ",
1098  " .+. .++. .+..++. ",
1099  " .+. ..+.. .+..+. ",
1100  " .+..++. .+.+. ",
1101  " .+.++. .+++. ",
1102  " .+++.............++. ",
1103  " .+++++++++++++++++. ",
1104  " ................... ",
1105  " ",
1106  " ",
1107  " "}
1108  ;
1109  fPerspectiveIcon = new QPixmap(perspective);
1110 
1111  const char * const ortho[]={
1112  "32 32 3 1",
1113  " c None",
1114  ". c #D5D8D5",
1115  "@ c #000000",
1116  " ",
1117  " ",
1118  " ",
1119  " ................... ",
1120  " ..@@@@@@@@@@@@@@@@@. ",
1121  " ..@@@.............@@@. ",
1122  " ..@@.@. ..@..@. ",
1123  " ..@@ ..@. .@@...@. ",
1124  " ..@@..............@@.. .@. ",
1125  " .@@@@@@@@@@@@@@@@@.. .@. ",
1126  " .@...............@. .@. ",
1127  " .@. .@. .@. .@. ",
1128  " .@. .@. .@. .@. ",
1129  " .@. .@. .@. .@. ",
1130  " .@. .@. .@. .@. ",
1131  " .@. .@. .@. .@. ",
1132  " .@. .@. .@. .@. ",
1133  " .@. .@. .@. .@. ",
1134  " .@. .@. .@. .@. ",
1135  " .@. .@. .@. .@. ",
1136  " .@. .@. .@. .@. ",
1137  " .@. .@........@......@. ",
1138  " .@. .@@@@@@@@@.@.@@@@@@. ",
1139  " .@. .@@+........@....@@.. ",
1140  " .@...@. .@...@... ",
1141  " .@.@@. .@.@@ . ",
1142  " .@@@.............@@@.. ",
1143  " .@@@@@@@@@@@@@@@@@... ",
1144  " ................... ",
1145  " ",
1146  " ",
1147  " "}
1148  ;
1149  fOrthoIcon = new QPixmap(ortho);
1150 
1151  const char * const commandIcon[]={
1152  "20 20 25 1 ",
1153  " c #4ED17F",
1154  ". c #4FD280",
1155  "X c #50D381",
1156  "o c #5BD181",
1157  "O c #5DD382",
1158  "+ c #59D48A",
1159  "@ c #66D68C",
1160  "# c #6FD895",
1161  "$ c #85DEA4",
1162  "% c #8CE0AC",
1163  "& c #96E4B8",
1164  "* c #9EE3B8",
1165  "= c #A8E5BB",
1166  "- c #A7E8C4",
1167  "; c #B2EAC8",
1168  ": c #B9ECD1",
1169  "> c #C2EDD3",
1170  ", c #CBF1DF",
1171  "< c #D4F3E3",
1172  "1 c #DDF4E5",
1173  "2 c #DBF5EC",
1174  "3 c #E5F7F0",
1175  "4 c #EDFAFB",
1176  "5 c #F6FBFE",
1177  "6 c #FEFFFC",
1178  /* pixels */
1179  "66666666666666666666",
1180  "66%++++++++++++++&56",
1181  "6$ o..o......o..o *6",
1182  "6+o...o*<441;@.o..+6",
1183  "6+..o@1553<354$..o+6",
1184  "6+..o<5<@ .*54#o.+6",
1185  "6+o.*52X :5-..@6",
1186  "6+..15% o$+o.+6",
1187  "6+.+55@ .o.+6",
1188  "6O.#54 .X.+6",
1189  "6O #54 .X.+6",
1190  "6O.+55@ .o.+6",
1191  "6+..25% @,*o.@6",
1192  "6+o.*52X :5>.o+6",
1193  "6+..O25<@ X=54#o.+6",
1194  "6+.o.@1553<354$...@6",
1195  "6+o..oo*<44<;@o..o+6",
1196  "6$ .o..o.....o..o *6",
1197  "66%+++++OOOO+++++*66",
1198  "66666666666666666666"
1199  };
1200  fCommandIcon = new QPixmap(commandIcon);
1201 
1202  const char * const dirIcon[]={
1203  "20 20 25 1 ",
1204  " c #DF5959",
1205  ". c #DD5F5F",
1206  "X c #DE7370",
1207  "o c #E06360",
1208  "O c #E06467",
1209  "+ c #E06C6C",
1210  "@ c #E57979",
1211  "# c #E08886",
1212  "$ c #E18D91",
1213  "% c #E19D9B",
1214  "& c #E99B9D",
1215  "* c #E8A2A2",
1216  "= c #EEB2B0",
1217  "- c #EDBBBC",
1218  "; c #EDCBC7",
1219  ": c #E9CDD1",
1220  "> c #F1D5D6",
1221  ", c #F9DFE2",
1222  "< c #EFE8E7",
1223  "1 c #F3E3E4",
1224  "2 c #F8EEEC",
1225  "3 c #FCF6F4",
1226  "4 c #F6F3F9",
1227  "5 c #F2F8FC",
1228  "6 c #FEFFFD",
1229  /* pixels */
1230  "66666666666666666666",
1231  "66$oOOOOOOOOOOOOo%66",
1232  "6# %6",
1233  "6o +,666663:+ o6",
1234  "6o =635533666$ o6",
1235  "6o -65:+ +165X o6",
1236  "6o >6<. 36; O6",
1237  "6o 26- &6>. o6",
1238  "6. o56* @63. o6",
1239  "6. X56& o66. o6",
1240  "6. X56& +63. o6",
1241  "6. o56* @62. o6",
1242  "6o 26- =61 O6",
1243  "6o >6<. o36: o6",
1244  "6o -65:+ @265X o6",
1245  "6o =635543665# O6",
1246  "6o +1666662;+ o6",
1247  "6# %6",
1248  "66$OOOoo....OOOOo%66",
1249  "66666666666666666666"}
1250  ;
1251  fDirIcon = new QPixmap(dirIcon);
1252 
1253 
1254  const char * const runIcon[]={
1255  /* columns rows colors chars-per-pixel */
1256  "20 20 33 1 ",
1257  " c #5CA323",
1258  ". c #5EA03F",
1259  "X c #6DB620",
1260  "o c #66AD3F",
1261  "O c #70B73C",
1262  "+ c #7CC13F",
1263  "@ c #569B41",
1264  "# c #61A14E",
1265  "$ c #70A95D",
1266  "% c #7EB55C",
1267  "& c #85B94E",
1268  "* c #90BE49",
1269  "= c #81B669",
1270  "- c #81B370",
1271  "; c #95CA46",
1272  ": c #A1CD40",
1273  "> c #AED045",
1274  ", c #B3D558",
1275  "< c #9BC87E",
1276  "1 c #AED668",
1277  "2 c #A2D075",
1278  "3 c #C2DC73",
1279  "4 c #A5C98F",
1280  "5 c #C1DC9F",
1281  "6 c #CAE18E",
1282  "7 c #CCE39A",
1283  "8 c #C4DCB6",
1284  "9 c #E3ECBA",
1285  "0 c #EEF3D3",
1286  "q c #F0F7DE",
1287  "w c #F8FAE9",
1288  "e c #FCFFFB",
1289  "r c None",
1290  /* pixels */
1291  "rrrrrrrr%<<2rrrrrrrr",
1292  "rrrrr5=$$$$===rrrrrr",
1293  "rrrr<##$$$$$---&rrrr",
1294  "rrr=###$$$$-----%rrr",
1295  "rr=####$$$$------&rr",
1296  "r2@####7##$-------rr",
1297  "r.@####048$-------Or",
1298  "r.@####q4ee=----$@.r",
1299  " .@@###w4eee5%$#@@@X",
1300  " .@@@..w4eeeeqo..@@X",
1301  " .@..ooe<eeee7Oooo@X",
1302  " ..oooOe2eee6OOOooo ",
1303  "rOooOO+e2ew2+++++O+r",
1304  "r:oO+++e30,;;;;;++Or",
1305  "r :++;:9,>,,>>:;;1rr",
1306  "rr*1;:>,333333,>32rr",
1307  "rrr66,1367777637<rrr",
1308  "rrrr509799999905rrrr",
1309  "rrrrr=8wqwwww8-rrrrr",
1310  "rrrrrrrr4444rrrrrrrr"
1311  };
1312  fRunIcon = new QPixmap(runIcon);
1313 
1314  const char * const paramIcon[]={
1315  /* columns rows colors chars-per-pixel */
1316  "20 20 35 1 ",
1317  " c #2E2525",
1318  ". c #403737",
1319  "X c #423A3A",
1320  "o c #443C3C",
1321  "O c #473F3F",
1322  "+ c #4C4444",
1323  "@ c #4F4848",
1324  "# c #514949",
1325  "$ c #544D4D",
1326  "% c #595252",
1327  "& c #625B5B",
1328  "* c #696262",
1329  "= c #6D6666",
1330  "- c #716B6B",
1331  "; c #726C6C",
1332  ": c #767171",
1333  "> c #7E7878",
1334  ", c #8B8787",
1335  "< c #8C8787",
1336  "1 c #8D8888",
1337  "2 c #918D8D",
1338  "3 c #928E8E",
1339  "4 c #948F8F",
1340  "5 c #9C9898",
1341  "6 c #9D9999",
1342  "7 c #D5D4D4",
1343  "8 c #D8D6D6",
1344  "9 c #DDDBDB",
1345  "0 c #EFEFEF",
1346  "q c #F6F6F6",
1347  "w c None",
1348  "e c None",
1349  "r c None",
1350  "t c gray99",
1351  "y c None",
1352  /* pixels */
1353  "wwwwwwww5 5wwwwwwww",
1354  "wwwwwwww, ,wwwwwwww",
1355  "www&;ww7+ +9ww=-www",
1356  "ww& O# OX *ww",
1357  "ww; >ww",
1358  "wwwO .%%X +www",
1359  "www# 3wwww3 Owww",
1360  "ww7 3wwwwww3 7ww",
1361  "5<+ .wwwwwww0. +<5",
1362  " %wwwwwwww$ ",
1363  " %wwwwwwww$ ",
1364  "5<+ .wwwwwww0X +<5",
1365  "ww9 4wwwwww1 9ww",
1366  "wwwO 30ww03 Owww",
1367  "wwwX X#$X @www",
1368  "ww= =ww",
1369  "ww- +O ++ :ww",
1370  "www*>ww7+ +7ww=:www",
1371  "wwwwwwww1 1wwwwwwww",
1372  "wwwwwwww5 5wwwwwwww"
1373  };
1374  fParamIcon = new QPixmap(paramIcon);
1375 
1376 }
1377 
1378 
1381 QWidget* G4UIQt::CreateHistoryTBWidget(
1382 )
1383 {
1384  fHistoryTBWidget = new QWidget();
1385 
1386  QVBoxLayout *layoutHistoryTB = new QVBoxLayout();
1387  fHistoryTBTableList = new QListWidget();
1388  fHistoryTBTableList->setSelectionMode(QAbstractItemView::SingleSelection);
1389  connect(fHistoryTBTableList, SIGNAL(itemSelectionChanged()), SLOT(CommandHistoryCallback()));
1390 
1391  layoutHistoryTB->addWidget(fHistoryTBTableList);
1392 
1393  fHistoryTBWidget->setLayout(layoutHistoryTB);
1394  return fHistoryTBWidget;
1395 }
1396 
1397 
1400 QWidget* G4UIQt::CreateHelpTBWidget(
1401 )
1402 {
1403  fHelpTBWidget = new QWidget();
1404 
1405  QWidget *helpWidget = new QWidget();
1406  QHBoxLayout *helpLayout = new QHBoxLayout();
1407  QVBoxLayout *vLayout = new QVBoxLayout();
1408  fHelpVSplitter = new QSplitter(Qt::Vertical);
1409  fHelpLine = new QLineEdit();
1410  helpLayout->addWidget(new QLabel("Search :"));
1411  helpLayout->addWidget(fHelpLine);
1412  connect( fHelpLine, SIGNAL( editingFinished () ), this, SLOT( LookForHelpStringCallback() ) );
1413 
1414  // Create Help tree
1415  FillHelpTree();
1416 
1417  fParameterHelpLabel = new QTextEdit();
1418  fParameterHelpLabel->setReadOnly(true);
1419  fParameterHelpTable = new QTableWidget();
1420 
1421  // Set layouts
1422 
1423  if (fHelpTreeWidget) {
1424  fHelpVSplitter->addWidget(fHelpTreeWidget);
1425  }
1426  fHelpVSplitter->addWidget(fParameterHelpLabel);
1427  fHelpVSplitter->addWidget(fParameterHelpTable);
1428 
1429  fParameterHelpLabel->setVisible(false);
1430  fParameterHelpTable->setVisible(false);
1431  QSizePolicy policy = QSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum);
1432  policy.setVerticalStretch(4);
1433  if (fHelpTreeWidget) {
1434  fHelpTreeWidget->setSizePolicy(policy);
1435  }
1436  policy = QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Preferred);
1437  policy.setVerticalStretch(1);
1438  fParameterHelpLabel->setSizePolicy(policy);
1439  fParameterHelpTable->setSizePolicy(policy);
1440 
1441  vLayout->addWidget(helpWidget);
1442  vLayout->addWidget(fHelpVSplitter,1);
1443  vLayout->setContentsMargins(5,5,5,5);
1444 
1445  helpWidget->setLayout(helpLayout);
1446  fHelpTBWidget->setLayout(vLayout);
1447 
1448  return fHelpTBWidget;
1449 }
1450 
1451 
1454 G4UIDockWidget* G4UIQt::CreateCoutTBWidget(
1455 )
1456 {
1457  QWidget* coutTBWidget = new QWidget();
1458 
1459  QVBoxLayout *layoutCoutTB = new QVBoxLayout();
1460 
1461  fCoutTBTextArea = new QTextEdit();
1462 
1463  // set font familly and size
1464  fCoutTBTextArea->setFontFamily("Courier");
1465  fCoutTBTextArea->setFontPointSize(12);
1466 
1467  fCoutFilter = new QLineEdit();
1468  fCoutFilter->setToolTip("Filter output by...");
1469 
1470 #if QT_VERSION > 0x050100
1471  fCoutFilter->addAction(*fSearchIcon,QLineEdit::TrailingPosition);
1472  fCoutFilter->setStyleSheet ("border-radius:7px;");
1473 #else
1474  QPushButton *coutTBFilterButton = new QPushButton();
1475  coutTBFilterButton->setIcon(QIcon(*fSearchIcon));
1476  coutTBFilterButton->setStyleSheet ("padding-left: 0px; border:0px;");
1477  fCoutFilter->setStyleSheet ("padding-right: 0px;");
1478 #endif
1479 
1480  QPushButton *coutTBClearButton = new QPushButton();
1481  coutTBClearButton->setIcon(*fClearIcon);
1482  coutTBClearButton->setToolTip("Clear console output");
1483  coutTBClearButton->setStyleSheet ("border-radius:7px;");
1484  connect(coutTBClearButton, SIGNAL(clicked()), SLOT(ClearButtonCallback()));
1485  connect(fCoutFilter, SIGNAL(textEdited ( const QString &)), SLOT(CoutFilterCallback( const QString &)));
1486 
1487  QPushButton *coutTBSaveOutputButton = new QPushButton();
1488  coutTBSaveOutputButton->setIcon(*fSaveIcon);
1489  coutTBSaveOutputButton->setToolTip("Save console output");
1490  coutTBSaveOutputButton->setStyleSheet ("border-radius:7px;");
1491  connect(coutTBSaveOutputButton, SIGNAL(clicked()), SLOT(SaveOutputCallback()));
1492 
1493  fCoutTBTextArea->setReadOnly(true);
1494 
1495  QWidget* coutButtonWidget = new QWidget();
1496  QHBoxLayout* layoutCoutTBButtons = new QHBoxLayout();
1497 
1498 #ifdef G4MULTITHREADED
1499  // add all candidates to widget
1500  fThreadsFilterComboBox = new QComboBox();
1501  fThreadsFilterComboBox->setInsertPolicy(QComboBox::InsertAlphabetically);
1502  connect(fThreadsFilterComboBox, SIGNAL(activated(int)), this, SLOT(ThreadComboBoxCallback(int)));
1503 
1504  UpdateCoutThreadFilter();
1505 
1506  fThreadsFilterComboBox->setToolTip("Thread selection in output");
1507  layoutCoutTBButtons->addWidget(new QLabel(" Threads:"));
1508  layoutCoutTBButtons->addWidget(fThreadsFilterComboBox);
1509 #endif
1510 
1511  layoutCoutTBButtons->addWidget(fCoutFilter);
1512 #if QT_VERSION <= 0x050100
1513  layoutCoutTBButtons->addWidget(coutTBFilterButton);
1514 #endif
1515  layoutCoutTBButtons->addWidget(coutTBClearButton);
1516  layoutCoutTBButtons->addWidget(coutTBSaveOutputButton);
1517  coutButtonWidget->setLayout(layoutCoutTBButtons);
1518 
1519  // reduce margins
1520  layoutCoutTBButtons->setContentsMargins(3,3,3,0);
1521 
1522  layoutCoutTB->addWidget(coutButtonWidget);
1523  layoutCoutTB->addWidget(fCoutTBTextArea);
1524 
1525  coutTBWidget->setLayout(layoutCoutTB);
1526 
1527  fCoutTBTextArea->setMinimumSize(100,100);
1528 
1529  // Command line :
1530  QWidget* commandLineWidget = new QWidget();
1531  QHBoxLayout *layoutCommandLine = new QHBoxLayout();
1532 
1533  // fill them
1534 
1535  fCommandLabel = new QLabel("");
1536  fCommandArea = new QLineEdit();
1537 
1538  // The QCompleter will be append at SessionStart()
1539 
1540  fCommandArea->activateWindow();
1541 
1542  fCommandArea->setFocusPolicy ( Qt::StrongFocus );
1543  fCommandArea->setFocus(Qt::TabFocusReason);
1544  fCommandArea->setToolTip("Apply command");
1545 
1546 
1547  layoutCommandLine->addWidget(fCommandLabel);
1548  layoutCommandLine->addWidget(fCommandArea);
1549 
1550  // Connect signal
1551  connect(fCommandArea, SIGNAL(returnPressed()), SLOT(CommandEnteredCallback()));
1552  connect(fCommandArea, SIGNAL(textEdited(const QString &)), SLOT(CommandEditedCallback(const QString &)));
1553 
1554 
1555  commandLineWidget->setLayout(layoutCommandLine);
1556  commandLineWidget->setMinimumSize(50,50);
1557 
1558  layoutCoutTB->addWidget(commandLineWidget);
1559 
1560  fCoutDockWidget = new G4UIDockWidget ("Output");
1561  fCoutDockWidget->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
1562 
1563  fCoutDockWidget->setWidget(coutTBWidget);
1564  return fCoutDockWidget;
1565 }
1566 
1567 
1570 QWidget* G4UIQt::CreateVisParametersTBWidget(
1571 )
1572 {
1573  return NULL;
1574 }
1575 
1576 
1579 G4UIDockWidget* G4UIQt::CreateUITabWidget(
1580 )
1581 {
1582  fUITabWidget = new QTabWidget();
1583 
1584  // the left dock
1585  fUITabWidget->addTab(CreateSceneTreeWidget(),"Scene tree");
1586  fUITabWidget->addTab(CreateHelpTBWidget(),"Help");
1587  fUITabWidget->addTab(CreateHistoryTBWidget(),"History");
1588  fUITabWidget->setCurrentWidget(fHelpTBWidget);
1589 
1590  fUITabWidget->setTabToolTip (0,"Scene component tree. Only available in Stored mode");
1591  fUITabWidget->setTabToolTip (1,"Help widget");
1592  fUITabWidget->setTabToolTip (2,"All commands history");
1593  connect(fUITabWidget, SIGNAL(currentChanged(int)), SLOT(ToolBoxActivated(int)));
1594 
1595  fUIDockWidget = new G4UIDockWidget ("Scene tree, Help, History");
1596  fUIDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1597 
1598  fUIDockWidget->setWidget(fUITabWidget);
1599 
1600  return fUIDockWidget;
1601 }
1602 
1603 
1604 QWidget* G4UIQt::CreateSceneTreeWidget(){
1605 
1606  fSceneTreeWidget = new QWidget();
1607  QVBoxLayout* layout = new QVBoxLayout();
1608  fSceneTreeWidget->setLayout(layout);
1609 
1610 #if QT_VERSION < 0x040200
1611  fSceneTreeWidget->hide();
1612 #else
1613  fSceneTreeWidget->setVisible(false);
1614 #endif
1615 
1616  return fSceneTreeWidget;
1617 }
1618 
1619 
1620 void G4UIQt::CreateViewerWidget(){
1621 
1622  // Set layouts
1623 
1624  SetStartPage(std::string("<table width='100%'><tr><td width='30%'></td><td><div ")+
1625  "style='color: rgb(140, 31, 31); font-size: xx-large; font-family: Garamond, serif; padding-bottom: 0px; font-weight: normal'>Geant4: "+
1626  QApplication::applicationName ().toStdString()+
1627  "</div></td><td width='40%'>&nbsp;<br/><i>http://geant4.web.cern.ch/geant4/</i></td></tr></table>"+
1628  "<p>&nbsp;</p>"+
1629  "<div style='background:#EEEEEE;'><b>Tooltips :</b><ul>"+
1630  "<li><b>Start a new viewer :</b><br />"+
1631  "<i>'/vis/open/...'<br />"+
1632  "For example '/vis/open OGL'</i></li>"+
1633  "<li><b>Execute a macro file :</b><br />"+
1634  "<i>'/control/execute my_macro_file'</i></li>"+
1635  "</ul></div>"+
1636 
1637  "<div style='background:#EEEEEE;'><b>Documentation :</b><ul>"+
1638  "<li><b>Visualization tutorial :</b><br />"+
1639  "<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>"+
1640  "<li><b>Visualisation publication :</b><br />"+
1641  "<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>"+
1642  "</ul></div>"+
1643 
1644  "<div style='background:#EEEEEE;'><b>Getting Help :</b><ul>"+
1645  "<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"+
1646  "<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>"+
1647  "</ul></div>"
1648  );
1649 
1650 
1651  // fill right splitter
1652  if (fViewerTabWidget == NULL) {
1653  fViewerTabWidget = new G4QTabWidget();
1654  fMainWindow->setCentralWidget(fViewerTabWidget);
1655 #if QT_VERSION < 0x040500
1656 #else
1657  fViewerTabWidget->setTabsClosable (true);
1658 #endif
1659 
1660 #if QT_VERSION < 0x040200
1661 #else
1662  fViewerTabWidget->setUsesScrollButtons (true);
1663 #endif
1664 
1665 #if QT_VERSION < 0x040500
1666 #else
1667  connect(fViewerTabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(TabCloseCallback(int)));
1668 #endif
1669  connect(fViewerTabWidget, SIGNAL(currentChanged ( int ) ), SLOT(UpdateTabWidget(int)));
1670  }
1671 
1672 // set the QGLWidget size policy
1673  QSizePolicy policy = QSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
1674  policy.setVerticalStretch(4);
1675  fViewerTabWidget->setSizePolicy(policy);
1676 
1677  fViewerTabWidget->setMinimumSize(40,40);
1678 }
1679 
1680 
1683 QWidget* G4UIQt::GetSceneTreeWidget(
1684 )
1685 {
1686  return fSceneTreeWidget;
1687 }
1688 
1691 QWidget* G4UIQt::GetViewerPropertiesWidget(
1692 )
1693 {
1694  if (!fViewerPropertiesDialog) {
1695  CreateViewerPropertiesDialog();
1696  }
1697  return fViewerPropertiesWidget;
1698 }
1699 
1702 QWidget* G4UIQt::GetPickInfosWidget(
1703 )
1704 {
1705  if (!fPickInfosDialog) {
1706  CreatePickInfosDialog();
1707  }
1708  return fPickInfosWidget;
1709 }
1710 
1711 
1714 bool G4UIQt::AddViewerTab(
1715  QWidget* aWidget
1716  ,std::string title
1717  )
1718 {
1719  if (fViewerTabWidget == NULL) {
1720  return false;
1721  }
1722  fViewerTabWidget->addTab(aWidget,title.c_str());
1723 
1724  return true;
1725 }
1726 
1727 
1730 bool G4UIQt::AddViewerTabFromFile(
1731  std::string fileName
1732  ,std::string title
1733  )
1734 {
1735  if (fViewerTabWidget == NULL) {
1736  return false;
1737  }
1738 
1740  if(UI==NULL) return 0;
1741  std::ifstream file(UI->FindMacroPath(fileName.c_str()).data());
1742  if (file) {
1743 
1744  std::string content( (std::istreambuf_iterator<char>(file) ),
1745  (std::istreambuf_iterator<char>() ) );
1746 
1747  QTextEdit* text = new QTextEdit();
1748  text->setAcceptRichText (true);
1749  text->setContentsMargins(5,5,5,5);
1750  text->setText(QString("<pre>")+content.c_str()+"</pre>");
1751  text->setReadOnly(true);
1752  fViewerTabWidget->addTab(text,title.c_str());
1753  } else {
1754  return false;
1755  }
1756  return true;
1757 }
1758 
1759 
1763 bool G4UIQt::AddTabWidget(
1764  QWidget* aWidget
1765 ,QString name
1766 )
1767 {
1768  // Special case for Qt version between 5.0 and 5.1 on Mac OSX
1769  // Due to a bug in this Qt version, we can't put a OpenGL Widget inside the QTabWidget.
1770  // A work around is to put it outside. Returning false will fore the wiewer to put the QGLWidget
1771  // inside a new QWindow.
1772 
1773 #ifdef Q_OS_MAC
1774  #if QT_VERSION < 0x050100
1775  #if QT_VERSION >= 0x050000
1776  QString message = QString(
1777  "This Qt version [")+qVersion ()+"] has some issues with the OpenGL viewer.\n"+
1778  "To prevent problems, you are not allowed to open a Stored nor Immediate viewer.\n" +
1779  "\n" +
1780  "Please upgrade to Qt version >= 5.1\n";
1781 
1782  QMessageBox::warning(fMainWindow, tr("Warning"),
1783  tr(message.toStdString().c_str()),
1784  QMessageBox::Ok);
1785  return false;
1786  #endif
1787  #endif
1788 #endif
1789 
1790  if (fViewerTabWidget == NULL) {
1791  CreateViewerWidget();
1792  }
1793 
1794  if (!aWidget) {
1795  return false;
1796  }
1797 // Has to be added before we put it into the fViewerTabWidget widget
1798  aWidget->setParent(fViewerTabWidget); // Will create in some cases widget outside
1799  // of UI for a really short moment
1800 
1801  fViewerTabWidget->addTab(aWidget,name);
1802 
1803  fViewerTabWidget->setCurrentIndex(fViewerTabWidget->count()-1);
1804 
1805  // Set visible
1806  #if QT_VERSION < 0x040200
1807  fViewerTabWidget->setLastTabCreated(fViewerTabWidget->currentIndex());
1808  #else
1809  fViewerTabWidget->setLastTabCreated(fViewerTabWidget->currentIndex());
1810  #endif
1811 
1812  // Not the good solution, but ensure that the help tree is correctly build when launching a viewer
1813  // It should be done by a notification when adding a command, but that's nit done yet (Geant4.10.1)
1814  FillHelpTree();
1815 
1816  return true;
1817 }
1818 
1819 
1820 void G4UIQt::SetStartPage(
1821 const std::string& text)
1822 {
1823  if (text != "") {
1824  fDefaultViewerFirstPageHTMLText = text;
1825  }
1826  if (!fStartPage) {
1827  fStartPage = new QTextEdit();
1828  fStartPage->setAcceptRichText (true);
1829  fStartPage->setContentsMargins(5,5,5,5);
1830  fStartPage->setReadOnly(true);
1831  }
1832  fStartPage->setText(fDefaultViewerFirstPageHTMLText.c_str());
1833 }
1834 
1835 
1836 void G4UIQt::UpdateTabWidget(int tabNumber) {
1837  if ( fViewerTabWidget == NULL) {
1838  fViewerTabWidget = new G4QTabWidget;
1839  }
1840 
1841  fViewerTabWidget->setCurrentIndex(tabNumber);
1842 
1843  // Send this signal to unblock graphic updates !
1844  fViewerTabWidget->setTabSelected(false);
1845 
1846  #if QT_VERSION < 0x040200
1847  fViewerTabWidget->show();
1848  #else
1849  fViewerTabWidget->setVisible(true);
1850  #endif
1851 
1852  // This will send a paintEvent to OGL Viewers
1853  fViewerTabWidget->setTabSelected(true);
1854 }
1855 
1856 
1859 void G4UIQt::ResizeTabWidget( QResizeEvent* e) {
1860  if ( fViewerTabWidget) {
1861  for (G4int a=0;a<fViewerTabWidget->count() ;a++) {
1862  fViewerTabWidget->widget(a)->resize(e->size());
1863  }
1864  }
1865 }
1866 
1867 
1870 G4UIsession* G4UIQt::SessionStart (
1871 )
1872 {
1873  G4Qt* interactorManager = G4Qt::getInstance ();
1874  Prompt("Session :");
1875  exitSession = false;
1876 
1877  QCoreApplication::sendPostedEvents () ;
1878 
1879  #if QT_VERSION < 0x040200
1880  fMainWindow->show();
1881  #else
1882  fMainWindow->setVisible(true);
1883  #endif
1884 
1885  if (fDefaultIcons) {
1886 #if QT_VERSION < 0x040200
1887  fToolbarApp->show();
1888 #else
1889  fToolbarApp->setVisible(true);
1890 #endif
1891  } else {
1892  // Set not visible until session start
1893 #if QT_VERSION < 0x040200
1894  fToolbarApp->hide();
1895 #else
1896  fToolbarApp->setVisible(false);
1897 #endif
1898  }
1899  // Rebuild help tree (new command could be registered)
1900  FillHelpTree();
1901 
1902  // Rebuild command completion (new command could be registered)
1903  UpdateCommandCompleter();
1904 
1905  // Set event filters
1906  fHistoryTBTableList->installEventFilter(this);
1907  fCommandArea->installEventFilter(this);
1908 
1909  // Focus on command line
1910  fCommandArea->setFocus();
1911 
1912  interactorManager->DisableSecondaryLoop (); // TO KEEP
1913  if ((QApplication*)interactorManager->GetMainInteractor())
1914  ((QApplication*)interactorManager->GetMainInteractor())->exec();
1915 
1916  interactorManager->EnableSecondaryLoop ();
1917  return this;
1918 }
1919 
1920 
1926 void G4UIQt::Prompt (
1927  G4String aPrompt
1928 )
1929 {
1930  if (!aPrompt) return;
1931 
1932  fCommandLabel->setText((char*)aPrompt.data());
1933 }
1934 
1935 
1936 
1937 void G4UIQt::SessionTerminate (
1938 )
1939 {
1940  G4Qt* interactorManager = G4Qt::getInstance ();
1941  fMainWindow->close();
1942  ((QApplication*)interactorManager->GetMainInteractor())->exit();
1943 }
1944 
1945 
1946 
1955 void G4UIQt::PauseSessionStart (
1956  const G4String& aState
1957 )
1958 {
1959  if (!aState) return;
1960 
1961  if(aState=="G4_pause> ") { // TO KEEP
1962  SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP
1963  } // TO KEEP
1964 
1965  if(aState=="EndOfEvent") { // TO KEEP
1966  // Picking with feed back in event data Done here !!!
1967  SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP
1968  } // TO KEEP
1969 }
1970 
1971 
1972 
1977 void G4UIQt::SecondaryLoop (
1978  G4String aPrompt
1979 )
1980 {
1981  if (!aPrompt) return;
1982 
1983  G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ?
1984  Prompt(aPrompt); // TO KEEP
1985  exitPause = false; // TO KEEP
1986  while(1) {
1987  ((QApplication*)interactorManager)->processEvents(QEventLoop::WaitForMoreEvents);
1988  if(exitPause==true) break; // TO KEEP
1989  } // TO KEEP
1990  Prompt("Session :"); // TO KEEP
1991 }
1992 
1993 #ifdef G4MULTITHREADED
1994 #include "G4Threading.hh"
1995 #include "G4AutoLock.hh"
1996 namespace {
1997  G4Mutex ReceiveG4coutMutex = G4MUTEX_INITIALIZER;
1998  G4Mutex ReceiveG4cerrMutex = G4MUTEX_INITIALIZER;
1999 }
2000 #endif
2001 
2007 G4int G4UIQt::ReceiveG4cout (
2008  const G4String& aString
2009  )
2010 {
2011  if (!aString) return 0;
2012 
2013 #ifdef G4MULTITHREADED
2014  G4AutoLock al(&ReceiveG4coutMutex);
2015 #endif
2016 
2017  // Try to be smart :
2018  // "*** This is just a warning message. ***"
2019  if (aString.contains("*** This is just a warning message. ***")) {
2020  return ReceiveG4cerr(aString);
2021  }
2022 
2023  QStringList newStr;
2024 
2025  // Add to string
2026  G4UIOutputString txt = G4UIOutputString(QString((char*)aString.data()).trimmed(),GetThreadPrefix());
2027  fG4OutputString.push_back(txt);
2028 
2029 #ifdef G4MULTITHREADED
2030  QString result = FilterOutput(txt,fThreadsFilterComboBox->currentText(),fCoutFilter->text());
2031 #else
2032  QString result = FilterOutput(txt,"",fCoutFilter->text());
2033 #endif
2034 
2035  if (result.isEmpty()) {
2036  return 0;
2037  }
2038  QColor previousColor = fCoutTBTextArea->textColor();
2039  fCoutTBTextArea->setTextColor(Qt::black);
2040  fCoutTBTextArea->append(result);
2041  fCoutTBTextArea->setTextColor(previousColor);
2042  fCoutTBTextArea->ensureCursorVisible ();
2043 
2044 #ifdef G4MULTITHREADED
2045  UpdateCoutThreadFilter();
2046 #endif
2047  return 0;
2048 }
2049 
2050 
2056 G4int G4UIQt::ReceiveG4cerr (
2057  const G4String& aString
2058 )
2059 {
2060  if (!aString) return 0;
2061 
2062 #ifdef G4MULTITHREADED
2063  G4AutoLock al(&ReceiveG4cerrMutex);
2064 #endif
2065  QStringList newStr;
2066 
2067  // Add to string
2068 
2069  G4UIOutputString txt = G4UIOutputString(QString((char*)aString.data()).trimmed(),
2070  GetThreadPrefix(),
2071  "error");
2072  fG4OutputString.push_back(txt);
2073 
2074 #ifdef G4MULTITHREADED
2075  QString result = FilterOutput(txt,fThreadsFilterComboBox->currentText(),fCoutFilter->text());
2076 #else
2077  QString result = FilterOutput(txt,"",fCoutFilter->text());
2078 #endif
2079  if (result.isEmpty()) {
2080  return 0;
2081  }
2082 
2083  // Suppress space, \n,\t,\r...
2084  if (QString(aString.data()).trimmed() != "") {
2087  // In case of Abort or Quit, the useful error message should be in the last error message !
2088  QMessageBox::critical(fMainWindow, "Error",QString(fLastErrMessage.data())+"\n"+aString.data());
2089  }
2090  }
2091  QColor previousColor = fCoutTBTextArea->textColor();
2092  fCoutTBTextArea->setTextColor(Qt::red);
2093  fCoutTBTextArea->append(result);
2094  fCoutTBTextArea->setTextColor(previousColor);
2095  fCoutTBTextArea->ensureCursorVisible ();
2096 
2097  if (QString(aString.data()).trimmed() != "") {
2098  fLastErrMessage = aString;
2099  }
2100 #ifdef G4MULTITHREADED
2101  UpdateCoutThreadFilter();
2102 #endif
2103  return 0;
2104 }
2105 
2106 
2107 G4String G4UIQt::GetThreadPrefix() {
2108  G4String threadPrefix = "";
2109 #ifdef G4MULTITHREADED
2111  if(UI==NULL) return "";
2112  if (UI->GetThreadCout() != NULL) {
2113  threadPrefix = UI->GetThreadCout()->GetFullPrefixString().data();
2114  if (UI->GetThreadCout()->GetPrefixString() == G4String("G4VIS")) {
2115  return "G4VIS";
2116  }
2117  }
2118 #endif
2119  return threadPrefix;
2120 }
2121 
2122 
2123 #ifdef G4MULTITHREADED
2124 void G4UIQt::UpdateCoutThreadFilter() {
2126  if(UI==NULL) return;
2127 
2128  // add "All" and "Master"
2129  if (fThreadsFilterComboBox->count() < 2) {
2130  if ( fThreadsFilterComboBox->findText("All", Qt::MatchExactly) == -1) {
2131  fThreadsFilterComboBox->addItem("All");
2132  }
2133  }
2134  if (fThreadsFilterComboBox->count() < 2) {
2135  if ( fThreadsFilterComboBox->findText("Master", Qt::MatchExactly) == -1) {
2136  fThreadsFilterComboBox->addItem("Master");
2137  }
2138  }
2139  // Add current Cout
2140  G4String prefix = GetThreadPrefix();
2141  if (prefix != "") {
2142  if ( fThreadsFilterComboBox->findText(prefix.data(), Qt::MatchExactly) == -1) {
2143  fThreadsFilterComboBox->addItem(prefix.data());
2144  }
2145  }
2146 }
2147 #endif
2148 
2149 
2155 void G4UIQt::AddMenu (
2156  const char* aName
2157 ,const char* aLabel
2158 )
2159 {
2160  if (aName == NULL) return;
2161  if (aLabel == NULL) return;
2162 
2163  QMenu *fileMenu = new QMenu(aLabel);
2164  fMainWindow->menuBar()->addMenu(fileMenu);
2165 
2166  AddInteractor (aName,(G4Interactor)fileMenu);
2167 }
2168 
2169 
2176 void G4UIQt::AddButton (
2177  const char* aMenu
2178 ,const char* aLabel
2179 ,const char* aCommand
2180 )
2181 {
2182  if(aMenu==NULL) return; // TO KEEP
2183  if(aLabel==NULL) return; // TO KEEP
2184  if(aCommand==NULL) return; // TO KEEP
2185 
2186  QMenu *parentTmp = (QMenu*)GetInteractor(aMenu);
2187 
2188  if(parentTmp==NULL) {
2189  G4UImanager* UImanager = G4UImanager::GetUIpointer();
2190  G4int verbose = UImanager->GetVerboseLevel();
2191 
2192  if (verbose >= 2) {
2193  G4cout << "Menu name " << aMenu<< " does not exist, please define it before using it."<< G4endl;
2194  }
2195  return;
2196  }
2197 
2198  // Find the command in the command tree
2200  if(UI==NULL) return;
2201  G4UIcommandTree * treeTop = UI->GetTree();
2202 
2203  G4String cmd = aCommand;
2204  G4int cmdEndPos = cmd.find_first_of(" \t");
2205  if(cmdEndPos!=G4int(std::string::npos)) {
2206  cmd.erase(cmdEndPos);
2207  }
2208 
2209  if(treeTop->FindPath(cmd) == NULL) {
2210  if(cmd != "ls" &&
2211  cmd(0,3) != "ls " &&
2212  cmd != "pwd" &&
2213  cmd != "cd" &&
2214  cmd(0,3) != "cd " &&
2215  cmd != "help" &&
2216  cmd(0,5) != "help " &&
2217  cmd(0) != '?' &&
2218  cmd != "hist" &&
2219  cmd != "history" &&
2220  cmd(0) != '!' &&
2221  cmd != "exit" &&
2222  cmd != "cont" &&
2223  cmd != "continue"){
2224  G4UImanager* UImanager = G4UImanager::GetUIpointer();
2225  G4int verbose = UImanager->GetVerboseLevel();
2226 
2227  if (verbose >= 2) {
2228  G4cout << "Warning: command '"<< cmd <<"' does not exist, please define it before using it."<< G4endl;
2229  }
2230  }
2231  }
2232 
2233  QSignalMapper *signalMapper = new QSignalMapper(this);
2234  QAction *action = parentTmp->addAction(aLabel, signalMapper, SLOT(map()));
2235 
2236  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&)));
2237  signalMapper->setMapping(action, QString(aCommand));
2238 }
2239 
2240 
2241 
2242 
2246 void G4UIQt::AddIcon(const char* aLabel, const char* aIconFile, const char* aCommand, const char* aFileName){
2247  if(aLabel==NULL) return; // TO KEEP
2248  // special case, aCommand could be NULL if aIconFile is not user_icon
2249  if (aCommand==NULL) {
2250  if (std::string(aIconFile) == "user_icon") {
2251  return; // TO KEEP
2252  }
2253  }
2254  QPixmap* pix;
2255  bool userToolBar = false;
2256 
2257  if (!fDefaultIcons) {
2258  userToolBar = true;
2259  }
2260  if (std::string(aIconFile) == "user_icon") {
2261  // try to open a file
2262  G4UImanager* UImanager = G4UImanager::GetUIpointer();
2263  pix = new QPixmap(UImanager->FindMacroPath(aFileName).data());
2264  if (pix->isNull()) {
2265  G4int verbose = UImanager->GetVerboseLevel();
2266 
2267  if (verbose >= 2) {
2268  G4cout << "Warning: file '"<< aFileName <<"' is incorrect or does not exist, this command will not be build"<< G4endl;
2269  }
2270  return;
2271  }
2272  } else if (std::string(aIconFile) == "open") {
2273  pix = fOpenIcon;
2274  } else if (std::string(aIconFile) == "save") {
2275  pix = fSaveIcon;
2276  } else if (std::string(aIconFile) == "move") {
2277  pix = fMoveIcon;
2278  } else if (std::string(aIconFile) == "rotate") {
2279  pix = fRotateIcon;
2280  } else if (std::string(aIconFile) == "pick") {
2281  pix = fPickIcon;
2282  } else if (std::string(aIconFile) == "zoom_in") {
2283  pix = fZoomInIcon;
2284  } else if (std::string(aIconFile) == "zoom_out") {
2285  pix = fZoomOutIcon;
2286  } else if (std::string(aIconFile) == "wireframe") {
2287  pix = fWireframeIcon;
2288  } else if (std::string(aIconFile) == "solid") {
2289  pix = fSolidIcon;
2290  } else if (std::string(aIconFile) == "hidden_line_removal") {
2291  pix = fHiddenLineRemovalIcon;
2292  } else if (std::string(aIconFile) == "hidden_line_and_surface_removal") {
2293  pix = fHiddenLineAndSurfaceRemovalIcon;
2294  } else if (std::string(aIconFile) == "perspective") {
2295  pix = fPerspectiveIcon;
2296  } else if (std::string(aIconFile) == "ortho") {
2297  pix = fOrthoIcon;
2298  } else if (std::string(aIconFile) == "runBeamOn") {
2299  pix = fRunIcon;
2300  } else {
2301  G4UImanager* UImanager = G4UImanager::GetUIpointer();
2302  G4int verbose = UImanager->GetVerboseLevel();
2303 
2304  if (verbose >= 2) {
2305  G4cout << "Parameter"<< aIconFile <<" not defined"<< G4endl;
2306  }
2307  return;
2308  }
2309  QToolBar *currentToolbar = NULL;
2310  if (userToolBar) {
2311  if (fToolbarUser == NULL) {
2312  fToolbarUser = new QToolBar();
2313  fToolbarUser->setIconSize (QSize(20,20));
2314  fMainWindow->addToolBar(Qt::TopToolBarArea, fToolbarUser);
2315  }
2316  currentToolbar = fToolbarUser;
2317  } else {
2318  if (fToolbarApp == NULL) {
2319  fToolbarApp = new QToolBar();
2320  fToolbarApp->setIconSize (QSize(20,20));
2321  fMainWindow->addToolBar(Qt::TopToolBarArea, fToolbarApp);
2322  }
2323  currentToolbar = fToolbarApp;
2324  }
2325 
2326  // Check if already present
2327 
2328  QList<QAction*> list = currentToolbar->actions();
2329 
2330  for (int i = 0; i < list.size(); ++i) {
2331  if (list.at(i)->text() == QString(aLabel)) {
2333  if(UI==NULL) return;
2334  G4int verbose = UI->GetVerboseLevel();
2335  if (verbose >= 2) {
2336  G4cout << "Warning: A toolBar icon \""<< aLabel<< "\" already exists with the same name!" << G4endl;
2337  }
2338  }
2339  }
2340 
2341  QSignalMapper *signalMapper = new QSignalMapper(this);
2342  QAction *action = currentToolbar->addAction(QIcon(*pix),aLabel, signalMapper, SLOT(map()));
2343 
2344  // special cases :"open"
2345  if (std::string(aIconFile) == "open") {
2346  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(OpenIconCallback(const QString &)));
2347  QString txt = aCommand + fStringSeparator + aLabel;
2348  signalMapper->setMapping(action, QString(txt));
2349 
2350  // special cases :"save"
2351  } else if (std::string(aIconFile) == "save") {
2352  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(SaveIconCallback(const QString&)));
2353  QString txt = aCommand + fStringSeparator + aLabel;
2354  signalMapper->setMapping(action, QString(txt));
2355 
2356  // special cases : cursor style
2357  } else if ((std::string(aIconFile) == "move") ||
2358  (std::string(aIconFile) == "rotate") ||
2359  (std::string(aIconFile) == "pick") ||
2360  (std::string(aIconFile) == "zoom_out") ||
2361  (std::string(aIconFile) == "zoom_in")) {
2362  action->setCheckable(TRUE);
2363  action->setChecked(TRUE);
2364  action->setData(aIconFile);
2365 
2366  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ChangeCursorAction(const QString&)));
2367  signalMapper->setMapping(action, QString(aIconFile));
2368 
2369  if (std::string(aIconFile) == "move") {
2370  SetIconMoveSelected();
2371  }
2372  if (std::string(aIconFile) == "rotate") {
2373  SetIconRotateSelected();
2374  }
2375  if (std::string(aIconFile) == "pick") {
2376  SetIconPickSelected();
2377  }
2378  if (std::string(aIconFile) == "zoom_in") {
2379  SetIconZoomInSelected();
2380  }
2381  if (std::string(aIconFile) == "zoom_out") {
2382  SetIconZoomOutSelected();
2383  }
2384 
2385  // special case : surface style
2386  } else if ((std::string(aIconFile) == "hidden_line_removal") ||
2387  (std::string(aIconFile) == "hidden_line_and_surface_removal") ||
2388  (std::string(aIconFile) == "solid") ||
2389  (std::string(aIconFile) == "wireframe")) {
2390  action->setCheckable(TRUE);
2391  action->setChecked(TRUE);
2392  action->setData(aIconFile);
2393  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ChangeSurfaceStyle(const QString&)));
2394  signalMapper->setMapping(action, QString(aIconFile));
2395 
2396  if (std::string(aIconFile) == "hidden_line_removal") {
2397  SetIconHLRSelected();
2398  }
2399  if (std::string(aIconFile) == "hidden_line_and_surface_removal") {
2400  SetIconHLHSRSelected();
2401  }
2402  if (std::string(aIconFile) == "solid") {
2403  SetIconSolidSelected();
2404  }
2405  if (std::string(aIconFile) == "wireframe") {
2406  SetIconWireframeSelected();
2407  }
2408 
2409  // special case : perspective/ortho
2410  } else if ((std::string(aIconFile) == "perspective") ||
2411  (std::string(aIconFile) == "ortho")) {
2412  action->setCheckable(TRUE);
2413  action->setChecked(TRUE);
2414  action->setData(aIconFile);
2415  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ChangePerspectiveOrtho(const QString&)));
2416  signalMapper->setMapping(action, QString(aIconFile));
2417 
2418  if (std::string(aIconFile) == "perspective") {
2419  SetIconPerspectiveSelected();
2420  }
2421  if (std::string(aIconFile) == "ortho") {
2422  SetIconOrthoSelected();
2423  }
2424 
2425  } else {
2426 
2427  // Find the command in the command tree
2429  if(UI==NULL) return;
2430  G4UIcommandTree * treeTop = UI->GetTree();
2431  if (aCommand != NULL) {
2432  std::string str = aCommand;
2433  std::string::size_type pos = str.find(" ");
2434  if (pos != std::string::npos)
2435  {
2436  str = str.substr(0,pos).c_str();
2437  }
2438  if(treeTop->FindPath(str.c_str()) == NULL) {
2439  G4UImanager* UImanager = G4UImanager::GetUIpointer();
2440  G4int verbose = UImanager->GetVerboseLevel();
2441 
2442  if (verbose >= 2) {
2443  G4cout << "Warning: command '"<< aCommand <<"' does not exist, please define it before using it."<< G4endl;
2444  }
2445  }
2446  }
2447 
2448  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&)));
2449  signalMapper->setMapping(action, QString(aCommand));
2450  }
2451 }
2452 
2453 
2454 
2455 void G4UIQt::ActivateCommand(
2456  G4String newCommand
2457 )
2458 {
2459  if (!fHelpTreeWidget) {
2460  return;
2461  }
2462  // Look for the choosen command "newCommand"
2463  size_t i = newCommand.index(" ");
2464  G4String targetCom ="";
2465  if( i != std::string::npos )
2466  {
2467  G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
2468  newValue.strip(G4String::both);
2469  targetCom = ModifyToFullPathCommand( newValue );
2470  }
2471  if (targetCom != "") {
2472  OpenHelpTreeOnCommand(targetCom.data());
2473  }
2474 
2475  fUITabWidget->setCurrentWidget(fHelpTBWidget);
2476 }
2477 
2478 
2479 
2486 void G4UIQt::InitHelpTreeAndVisParametersWidget()
2487 {
2488 
2489  if (! fHelpTreeWidget ) {
2490  fHelpTreeWidget = new QTreeWidget();
2491  }
2492 
2493  // build widget
2494  fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
2495  QStringList labels;
2496  labels << QString("Command");
2497  fHelpTreeWidget->setHeaderLabels(labels);
2498 
2499 
2500  connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback()));
2501  connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback()));
2502 
2503 }
2510 void G4UIQt::FillHelpTree()
2511 {
2512  if (! fHelpTreeWidget ) {
2513  InitHelpTreeAndVisParametersWidget();
2514  }
2515 
2516  QString searchText = fHelpLine->text();
2517 
2518  if (searchText =="") {
2519  // clear old help tree
2520  // fHelpTreeWidget->clear();
2521  } else {
2522  return;
2523  }
2524 
2525  if (fParameterHelpLabel) {
2526  fParameterHelpLabel->setText("Choose a command in the command tree");
2527  fParameterHelpTable->setVisible(false);
2528  }
2529 
2530  if (fHelpLine) {
2531 #if QT_VERSION < 0x040200
2532  fHelpLine->clear();
2533 #else
2534  fHelpLine->setText("");
2535 #endif
2536  }
2537 
2539  if(UI==NULL) return;
2540  G4UIcommandTree * treeTop = UI->GetTree();
2541 
2542  G4int treeSize = treeTop->GetTreeEntry();
2543  QTreeWidgetItem * newItem = NULL;
2544  QString commandText = "";
2545  for (int a=0;a<treeSize;a++) {
2546  // Creating new item
2547  newItem = NULL;
2548 
2549  commandText = QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed();
2550 
2551  // if already exist, don't create it !
2552  for (int b=0;b<fHelpTreeWidget->topLevelItemCount();b++) {
2553  if (!newItem)
2554  newItem = FindTreeItem(fHelpTreeWidget->topLevelItem(b),commandText);
2555  }
2556 
2557  if (newItem == NULL) {
2558 
2559  newItem = new QTreeWidgetItem();
2560  newItem->setText(0,GetShortCommandPath(commandText));
2561  fHelpTreeWidget->addTopLevelItem(newItem);
2562  }
2563 
2564  // look for childs
2565  CreateHelpTree(newItem,treeTop->GetTree(a+1));
2566  }
2567 
2568 }
2569 
2570 
2571 
2576 void G4UIQt::CreateHelpTree(
2577  QTreeWidgetItem *aParent
2578 ,G4UIcommandTree *aCommandTree
2579 )
2580 {
2581  if (aParent == NULL) return;
2582  if (aCommandTree == NULL) return;
2583 
2584 
2585  // Creating new item
2586  QTreeWidgetItem * newItem;
2587 
2588  QString commandText = "";
2589  // Get the Sub directories
2590  for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
2591 
2592  commandText = QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed();
2593 
2594  // if already exist, don't create it !
2595  newItem = FindTreeItem(aParent,commandText);
2596  if (newItem == NULL) {
2597  newItem = new QTreeWidgetItem();
2598  newItem->setText(0,GetShortCommandPath(commandText));
2599  aParent->addChild(newItem);
2600  }
2601  CreateHelpTree(newItem,aCommandTree->GetTree(a+1));
2602  }
2603 
2604  // Get the Commands
2605 
2606  for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
2607 
2608  QStringList stringList;
2609  commandText = QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed();
2610 
2611  // if already exist, don't create it !
2612  newItem = FindTreeItem(aParent,commandText);
2613  if (newItem == NULL) {
2614  newItem = new QTreeWidgetItem();
2615  newItem->setText(0,GetShortCommandPath(commandText));
2616  aParent->addChild(newItem);
2617 
2618 #if QT_VERSION < 0x040202
2619  fHelpTreeWidget->setItemExpanded(newItem,false);
2620 #else
2621  newItem->setExpanded(false);
2622 #endif
2623  }
2624  }
2625 }
2626 
2627 
2628 
2629 
2635 bool G4UIQt::CreateVisCommandGroupAndToolBox(
2636  G4UIcommand* aCommand
2637 ,QWidget* aParent
2638 ,int aDepthLevel
2639 ,bool isDialog
2640 )
2641 {
2642  QString commandText = QString((char*)(aCommand->GetCommandPath().data())).section("/",-aDepthLevel);
2643 
2644  if (commandText == NULL) {
2645  return false;
2646  }
2647 
2648  // Look if groupBox is create
2649  // QGroupBox* gBoxCommandWidget;
2650  QWidget* newParentWidget = NULL;
2651  bool found = false;
2652  QString commandSection = commandText.left(commandText.indexOf("/"));
2653 
2654  if (aDepthLevel == 1) {
2655  QToolBox* currentParent = dynamic_cast<QToolBox*>(aParent);
2656  if (currentParent != 0){
2657 
2658  // already exists ?
2659  for (int a=0; a<currentParent->count(); a++) {
2660  if (currentParent->itemText(a) == commandSection) {
2661  found = true;
2662  newParentWidget = currentParent->widget(a);
2663  }
2664  }
2665  }
2666  // Not found ? create it
2667  if (!found) {
2668  newParentWidget = new QGroupBox();
2669  newParentWidget->setLayout(new QVBoxLayout());
2670  if (currentParent != 0){
2671  currentParent->addItem(newParentWidget,commandSection);
2672  } else {
2673  if (!aParent->layout()) {
2674  aParent->setLayout(new QVBoxLayout());
2675  }
2676  aParent->layout()->addWidget(newParentWidget);
2677  }
2678 
2679  if (commandText.indexOf("/") == -1) {
2680 
2681  // Guidance
2682  QString guidance;
2683  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
2684  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
2685  guidance += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
2686  }
2687  newParentWidget->setToolTip(guidance);
2688  }
2689 
2690  QScrollArea* sc = dynamic_cast<QScrollArea*>(newParentWidget->parent()->parent());
2691  if (sc != 0) {
2692  sc->ensureWidgetVisible(newParentWidget);
2693 
2694  }
2695  }
2696  } else {
2697 
2698  // try to know if this level is already there
2699  QGroupBox* currentParent = dynamic_cast<QGroupBox*>(aParent);
2700  if (currentParent != 0){
2701 
2702  // if depth==2, then we add a [more parameters inside] to the toolBoxItem parent
2703  // QGroupBox > QWidget > QScrollArea > QToolBox
2704  if (aDepthLevel == 2){
2705  QToolBox* parentToolBox = dynamic_cast<QToolBox*>(currentParent->parent()->parent()->parent());
2706  if (parentToolBox != 0) {
2707  // parentToolBox->setItemText(parentToolBox->indexOf(currentParent),"[more parameters inside]");
2708  }
2709  }
2710  for (int a=0; a<aParent->layout()->count(); a++) {
2711  QGroupBox* gb = dynamic_cast<QGroupBox*>(aParent->layout()->itemAt(a)->widget());
2712  if (gb != 0) {
2713  if (gb->title() == commandSection) {
2714  found = true;
2715  newParentWidget = gb;
2716  }
2717  }
2718  }
2719  }
2720 
2721  // Not found ? create it
2722  if (!found) {
2723  newParentWidget = new QGroupBox();
2724  newParentWidget->setLayout(new QVBoxLayout());
2725  if (!aParent->layout()) {
2726  aParent->setLayout(new QVBoxLayout());
2727  }
2728  aParent->layout()->addWidget(newParentWidget);
2729 
2730  // set toolTip
2731  // Guidance
2732  QString guidance;
2733  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
2734  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
2735  guidance += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
2736  }
2737  newParentWidget->setToolTip(guidance);
2738  }
2739  }
2740 
2741  // fill command groupbox
2742  if (commandText.indexOf("/") == -1) {
2743  if (CreateCommandWidget(aCommand, newParentWidget,isDialog)) {
2744  return true;
2745  }
2746  } else {
2747  CreateVisCommandGroupAndToolBox(aCommand,newParentWidget, aDepthLevel-1,isDialog);
2748  }
2749 
2750  return true;
2751 }
2752 
2753 
2754 
2760 bool G4UIQt::CreateCommandWidget(G4UIcommand* aCommand, QWidget* aParent, bool isDialog) {
2761 
2762  if (aCommand == NULL) {
2763  return false;
2764  }
2765 
2766 
2767  // parameters
2768  G4int n_parameterEntry = aCommand->GetParameterEntries();
2769  if( n_parameterEntry > 0 ) {
2770  G4UIparameter *param;
2771 
2772  // Re-implementation of G4UIparameter.cc
2773  QWidget* paramWidget = new QWidget();
2774  QGridLayout* gridLayout = new QGridLayout();
2775  paramWidget->setLayout(gridLayout);
2776 
2777  // Special case for colour, try to display a color chooser if we found red/green/blue parameter
2778  unsigned int nbColorParameter = 0;
2779  bool isStillColorParameter = false;
2780  bool isColorDialogAdded = false;
2781  QLabel* redLabel = NULL;
2782  QLabel* greenLabel = NULL;
2783  QString redDefaultStr = "";
2784  QString greenDefaultStr = "";
2785  QString blueDefaultStr = "";
2786  QWidget* redInput = NULL;
2787  QWidget* greenInput = NULL;
2788 
2789  for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
2790  QString txt;
2791  param = aCommand->GetParameter(i_thParameter);
2792  QLabel* label = new QLabel(QString((char*)(param->GetParameterName()).data()));
2793 
2794  if ((label->text() == "red") || (label->text() == "red_or_string")){
2795  nbColorParameter ++;
2796  isStillColorParameter = true;
2797  } else if ((label->text() == "green") && isStillColorParameter) {
2798  nbColorParameter ++;
2799  } else if ((label->text() == "blue") && isStillColorParameter) {
2800  nbColorParameter ++;
2801  } else if (!isColorDialogAdded) {
2802 
2803  // not following red/green/blue parameters ?
2804  if (nbColorParameter == 1) {
2805  gridLayout->addWidget(redLabel,i_thParameter-1,0);
2806  gridLayout->addWidget(redInput,i_thParameter-1,1);
2807  } else if (nbColorParameter == 2) {
2808  gridLayout->addWidget(redLabel,i_thParameter-2,0);
2809  gridLayout->addWidget(redInput,i_thParameter-2,1);
2810  gridLayout->addWidget(greenLabel,i_thParameter-1,0);
2811  gridLayout->addWidget(greenInput,i_thParameter-1,1);
2812  }
2813  nbColorParameter = 0;
2814  }
2815  // Check parameter type, could be NULL if not found
2816  QWidget* input = NULL;
2817  if ((QString(QChar(param->GetParameterType())) == "d") || (QString(QChar(param->GetParameterType())) == "i")) {
2818  input = new QLineEdit();
2819  // set default value
2820  dynamic_cast<QLineEdit*>(input)->setText(QString((char*)(param->GetDefaultValue()).data()));
2821 
2822  if (((label->text() == "red") || (label->text() == "red_or_string")) && isStillColorParameter) {
2823  redDefaultStr = QString((char*)(param->GetDefaultValue()).data());
2824  } else if ((label->text() == "green") && isStillColorParameter) {
2825  greenDefaultStr = QString((char*)(param->GetDefaultValue()).data());
2826  } else if ((label->text() == "green") && isStillColorParameter) {
2827  blueDefaultStr = QString((char*)(param->GetDefaultValue()).data());
2828  }
2829 
2830  } else if (QString(QChar(param->GetParameterType())) == "b") {
2831  input = new QWidget();
2832  QHBoxLayout* layout = new QHBoxLayout();
2833  input->setLayout(layout);
2834 
2835  QButtonGroup* buttons = new QButtonGroup();
2836  QRadioButton* radioOff = new QRadioButton("0");
2837  QRadioButton* radioOn = new QRadioButton("1");
2838  buttons->addButton(radioOn);
2839  buttons->addButton(radioOff);
2840  layout->addWidget(radioOn);
2841  layout->addWidget(radioOff);
2842 
2843  // set default value
2844  QString defaultValue = QString((char*)(param->GetDefaultValue()).data());
2845  if (defaultValue == "0") {
2846  radioOff->setChecked(true);
2847  } else if (defaultValue == "1") {
2848  radioOn->setChecked(true);
2849  }
2850  } else if ((QString(QChar(param->GetParameterType())) == "s") && (!param->GetParameterCandidates().isNull())) {
2851  input = new QComboBox();
2852  QString candidates = QString((char*)(param->GetParameterCandidates()).data());
2853  QStringList list = candidates.split (" ");
2854 
2855  // add all candidates to widget
2856  QString defaultValue = QString((char*)(param->GetDefaultValue()).data());
2857  for (int a=0; a<list.size(); a++) {
2858  dynamic_cast<QComboBox*>(input)->addItem(list.at(a));
2859  if (list.at(a) == defaultValue) {
2860  dynamic_cast<QComboBox*>(input)->setCurrentIndex(a);
2861  }
2862  }
2863 
2864  } else if ((QString(QChar(param->GetParameterType())) == "s")) { // string
2865  input = new QLineEdit();
2866  // set default value
2867  dynamic_cast<QLineEdit*>(input)->setText(QString((char*)(param->GetDefaultValue()).data()));
2868 
2869  } else if ((QString(QChar(param->GetParameterType())) == "c")) { // on/off
2870  input = new QWidget();
2871  QHBoxLayout* layout = new QHBoxLayout();
2872  input->setLayout(layout);
2873 
2874  QButtonGroup* buttons = new QButtonGroup();
2875  QRadioButton* radioOff = new QRadioButton("off");
2876  QRadioButton* radioOn = new QRadioButton("on");
2877  buttons->addButton(radioOn);
2878  buttons->addButton(radioOff);
2879  layout->addWidget(radioOn);
2880  layout->addWidget(radioOff);
2881 
2882  // set default value
2883  QString defaultValue = QString((char*)(param->GetDefaultValue()).data());
2884  if (defaultValue == "off") {
2885  radioOff->setChecked(true);
2886  } else if (defaultValue == "on") {
2887  radioOn->setChecked(true);
2888  }
2889 
2890  } else {
2891  input = new QLineEdit();
2892  dynamic_cast<QLineEdit*>(input)->setText(QString((char*)(param->GetDefaultValue()).data()));
2893  }
2894 
2895  txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
2896  if( ! param->GetParameterGuidance().isNull() )
2897  txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
2898 
2899  txt += " Parameter type : " + QString(QChar(param->GetParameterType())) + "\n";
2900  if(param->IsOmittable()){
2901  txt += " Omittable : True\n";
2902  } else {
2903  txt += " Omittable : False\n";
2904  }
2905  if( param->GetCurrentAsDefault() ) {
2906  txt += " Default value : taken from the current value\n";
2907  } else if( ! param->GetDefaultValue().isNull() ) {
2908  txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n";
2909  }
2910  if( ! param->GetParameterRange().isNull() ) {
2911  txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
2912  }
2913  if( ! param->GetParameterCandidates().isNull() ) {
2914  txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
2915  }
2916 
2917  if (isStillColorParameter && (nbColorParameter != 0)) {
2918  if ((label->text() == "red") || (label->text() == "red_or_string")) {
2919  redLabel = label;
2920  redInput = input;
2921  } else if (label->text() == "green") {
2922  greenLabel = label;
2923  greenInput = input;
2924  } else if (label->text() == "blue") {
2925 
2926  // we have all, then add a color chooser
2927 
2928  // Create a pixmap with the default color
2929  QColor qc;
2930  if ((redDefaultStr != "") && (redDefaultStr != "") && (redDefaultStr != "")) {
2931  qc.setRgbF(redDefaultStr.toDouble(),
2932  greenDefaultStr.toDouble(),
2933  blueDefaultStr.toDouble());
2934  }
2935  QPixmap pixmap = QPixmap(QSize(16, 16));
2936  pixmap.fill (qc);
2937  QPainter painter(&pixmap);
2938  painter.setPen(Qt::black);
2939  painter.drawRect(0,0,15,15); // Draw contour
2940 
2941  input = new QPushButton("Change color");
2942  dynamic_cast<QPushButton*>(input)->setIcon(pixmap);
2943  dynamic_cast<QPushButton*>(input)->setAccessibleName(redDefaultStr+" "+greenDefaultStr+" "+blueDefaultStr);
2944  label = new QLabel("Choose color");
2945 
2946  // less 1 because we have to add one to the row number
2947  nbColorParameter--;
2948  gridLayout->addWidget(label,i_thParameter-nbColorParameter,0);
2949  input->setToolTip("Select the current color");
2950  gridLayout->addWidget(input,i_thParameter-nbColorParameter,1);
2951 
2952  // Connect pushButton to ColorDialog in callback
2953  QSignalMapper* signalMapper = new QSignalMapper(this);
2954  signalMapper->setMapping(input,input);
2955  connect(input, SIGNAL(clicked()), signalMapper, SLOT(map()));
2956  connect(signalMapper, SIGNAL(mapped(QWidget*)),this, SLOT(ChangeColorCallback(QWidget*)));
2957 
2958  isColorDialogAdded = true;
2959  isStillColorParameter = false;
2960  }
2961  } else {
2962  gridLayout->addWidget(label,i_thParameter-nbColorParameter,0);
2963  input->setToolTip(txt);
2964  gridLayout->addWidget(input,i_thParameter-nbColorParameter,1);
2965  }
2966  }
2967  // add command name in hidden value at last line position 0
2968  QLabel* name = new QLabel(QString((char*)(aCommand->GetCommandPath().data())));
2969  name->hide();
2970  gridLayout->addWidget(name,n_parameterEntry-nbColorParameter,0);
2971 
2972  QPushButton* applyButton = new QPushButton("Apply");
2973  if (!isDialog) {
2974 
2975  gridLayout->addWidget(applyButton,n_parameterEntry-nbColorParameter,1);
2976 
2977  QSignalMapper* signalMapper = new QSignalMapper(this);
2978  signalMapper->setMapping(applyButton, paramWidget);
2979  connect(applyButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
2980  connect(signalMapper, SIGNAL(mapped(QWidget*)),this, SLOT(VisParameterCallback(QWidget*)));
2981  } else {
2982  // Apply/Cancel buttons
2983 
2984  applyButton->setAutoDefault( TRUE );
2985  applyButton->setDefault( TRUE );
2986 
2987  QPushButton* cancelButton = new QPushButton( tr( "&Cancel" ));
2988  cancelButton->setAutoDefault( TRUE );
2989  gridLayout->addWidget(cancelButton,n_parameterEntry-nbColorParameter,1);
2990  gridLayout->addWidget(applyButton,n_parameterEntry-nbColorParameter,0);
2991 
2992  QSignalMapper* signalMapper = new QSignalMapper(this);
2993  signalMapper->setMapping(applyButton, paramWidget);
2994  connect(applyButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
2995  connect(signalMapper, SIGNAL(mapped(QWidget*)),this, SLOT(VisParameterCallback(QWidget*)));
2996 
2997  QWidget * parentCheck = aParent;
2998  QDialog* parentDialog = NULL;
2999  bool found = false;
3000  while ((parentCheck->parentWidget()) != NULL) {
3001  parentCheck = parentCheck->parentWidget();
3002  parentDialog = dynamic_cast<QDialog*>(parentCheck);
3003  if (parentDialog) {
3004  connect( applyButton, SIGNAL( clicked() ), parentDialog, SLOT( accept() ) );
3005  connect( cancelButton, SIGNAL( clicked() ), parentDialog, SLOT( reject() ) );
3006  found = true;
3007  }
3008  }
3009  if (!found) {
3010  return false;
3011  }
3012  }
3013 
3014  if (!aParent->layout()) {
3015  aParent->setLayout(new QVBoxLayout());
3016  }
3017  aParent->layout()->addWidget(paramWidget);
3018  }
3019 
3020  return true;
3021 }
3022 
3023 
3028 QTreeWidgetItem* G4UIQt::FindTreeItem(
3029  QTreeWidgetItem *aParent
3030 ,const QString& aCommand
3031 )
3032 {
3033  if (aParent == NULL) return NULL;
3034 
3035  // Suppress last "/"
3036  QString myCommand = aCommand;
3037 
3038  if (myCommand.lastIndexOf("/") == (myCommand.size()-1)) {
3039  myCommand = myCommand.left(myCommand.size()-1);
3040  }
3041 
3042  if (GetLongCommandPath(aParent) == myCommand)
3043  return aParent;
3044 
3045  QTreeWidgetItem * tmp = NULL;
3046  for (int a=0;a<aParent->childCount();a++) {
3047  if (!tmp)
3048  tmp = FindTreeItem(aParent->child(a),myCommand);
3049  }
3050  return tmp;
3051 }
3052 
3053 
3054 
3062 QString G4UIQt::GetCommandList (
3063  const G4UIcommand *aCommand
3064  )
3065 {
3066 
3067  QString txt ="";
3068  if (aCommand == NULL)
3069  return txt;
3070 
3071  G4String commandPath = aCommand->GetCommandPath();
3072  G4String rangeString = aCommand->GetRange();
3073  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
3074  G4int n_parameterEntry = aCommand->GetParameterEntries();
3075 
3076  if ((commandPath == "") &&
3077  (rangeString == "") &&
3078  (n_guidanceEntry == 0) &&
3079  (n_parameterEntry == 0)) {
3080  return txt;
3081  }
3082 
3083  if((commandPath.length()-1)!='/') {
3084  txt += "Command " + QString((char*)(commandPath).data()) + "\n";
3085  }
3086  txt += "Guidance :\n";
3087 
3088  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
3089  txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
3090  }
3091  if( ! rangeString.isNull() ) {
3092  txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n";
3093  }
3094  if( n_parameterEntry > 0 ) {
3095  G4UIparameter *param;
3096 
3097  // Re-implementation of G4UIparameter.cc
3098 
3099  for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
3100  param = aCommand->GetParameter(i_thParameter);
3101  txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
3102  if( ! param->GetParameterGuidance().isNull() )
3103  txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
3104  txt += " Parameter type : " + QString(QChar(param->GetParameterType())) + "\n";
3105  if(param->IsOmittable()){
3106  txt += " Omittable : True\n";
3107  } else {
3108  txt += " Omittable : False\n";
3109  }
3110  if( param->GetCurrentAsDefault() ) {
3111  txt += " Default value : taken from the current value\n";
3112  } else if( ! param->GetDefaultValue().isNull() ) {
3113  txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n";
3114  }
3115  if( ! param->GetParameterRange().isNull() ) {
3116  txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
3117  }
3118  if( ! param->GetParameterCandidates().isNull() ) {
3119  txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
3120  }
3121  }
3122  }
3123  return txt;
3124 }
3125 
3126 
3134 void G4UIQt::updateHelpArea (
3135  const G4UIcommand *aCommand
3136 )
3137 {
3138  if (!fParameterHelpLabel)
3139  return;
3140  if (!fParameterHelpTable)
3141  return;
3142 
3143  fParameterHelpLabel->setTextInteractionFlags(Qt::NoTextInteraction);
3144  QString txt;
3145  if (aCommand == NULL)
3146  return;
3147 
3148  G4String commandPath = aCommand->GetCommandPath();
3149  G4String rangeString = aCommand->GetRange();
3150  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
3151  G4int n_parameterEntry = aCommand->GetParameterEntries();
3152 
3153  if ((commandPath == "") &&
3154  (rangeString == "") &&
3155  (n_guidanceEntry == 0) &&
3156  (n_parameterEntry == 0)) {
3157  return;
3158  }
3159 
3160  if((commandPath.length()-1)!='/') {
3161  txt += "<b>Command </b> " + QString((char*)(commandPath).data()) + "<br />";
3162  }
3163  txt += "<b>Guidance :</b> ";
3164 
3165  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
3166  txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "<br />";
3167  }
3168  if( ! rangeString.isNull() ) {
3169  txt += "<b>Range of parameters : </b> " + QString((char*)(rangeString).data()) + "<br />";
3170  } else {
3171  txt += "<br />";
3172  }
3173  fParameterHelpLabel->setHtml(txt);
3174 
3175  if( n_parameterEntry > 0 ) {
3176  G4UIparameter *param;
3177 
3178  // Re-implementation of G4UIparameter.cc
3179 
3180  fParameterHelpTable->clear();
3181  fParameterHelpTable->setRowCount(n_parameterEntry);
3182  fParameterHelpTable->setColumnCount(8);
3183  fParameterHelpTable->setHorizontalHeaderLabels(QStringList() <<
3184  tr("") <<
3185  tr("Parameter") <<
3186  tr("Guidance") <<
3187  tr("Type") <<
3188  tr("Ommitable") <<
3189  tr("Default") <<
3190  tr("Range") <<
3191  tr("Candidate"));
3192  fParameterHelpTable->setColumnWidth(2,60);
3193 
3194  fParameterHelpTable->verticalHeader()->setVisible(false);
3195  fParameterHelpTable->setAlternatingRowColors (true);
3196 #if QT_VERSION < 0x050000
3197  fParameterHelpTable->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
3198  fParameterHelpTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
3199 #else
3200  fParameterHelpTable->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
3201  fParameterHelpTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
3202 #endif
3203  fParameterHelpTable->setWordWrap(true);
3204 
3205  QTableWidgetItem* t = fParameterHelpTable->horizontalHeaderItem(1);
3206  QFont fnt = t->font();
3207  int size = fnt.pointSize();
3208  fnt.setPointSize(size-2);
3209 
3210  for( G4int a=0; a<n_parameterEntry; a++ ) {
3211  param = aCommand->GetParameter(a);
3212  fParameterHelpTable->setItem(a, 0, new QTableWidgetItem(QString::number(a+1)));
3213 
3214  fParameterHelpTable->setItem(a, 1, new QTableWidgetItem(QString((char*)(param->GetParameterName()).data())));
3215  if( ! param->GetParameterGuidance().isNull() ) {
3216  fParameterHelpTable->setItem(a, 2, new QTableWidgetItem(QString((char*)(param->GetParameterGuidance()).data())));
3217  }
3218  fParameterHelpTable->setItem(a, 3, new QTableWidgetItem(QString(QChar(param->GetParameterType()))));
3219 
3220  if(param->IsOmittable()){
3221  fParameterHelpTable->setItem(a, 4, new QTableWidgetItem(QString("True")));
3222  } else {
3223  fParameterHelpTable->setItem(a, 4, new QTableWidgetItem(QString("False")));
3224  }
3225  if( param->GetCurrentAsDefault() ) {
3226  fParameterHelpTable->setItem(a, 5, new QTableWidgetItem(QString("taken from the current value")));
3227  } else if( ! param->GetDefaultValue().isNull() ) {
3228  fParameterHelpTable->setItem(a, 5, new QTableWidgetItem(QString((char*)(param->GetDefaultValue()).data())));
3229  }
3230  if( ! param->GetParameterRange().isNull() ) {
3231  fParameterHelpTable->setItem(a, 6, new QTableWidgetItem(QString((char*)(param->GetParameterRange()).data())));
3232  }
3233  if( ! param->GetParameterCandidates().isNull() ) {
3234  fParameterHelpTable->setItem(a, 7, new QTableWidgetItem(QString((char*)(param->GetParameterCandidates()).data())));
3235  }
3236  // tooltips
3237  for (int b=0; b<8; b++) {
3238  QTableWidgetItem* tmp = fParameterHelpTable->item(a,b);
3239  if (tmp) {
3240  tmp->setToolTip(tmp->text());
3241  tmp->setFlags(Qt::NoItemFlags);
3242  tmp->setForeground(QBrush());
3243  tmp->setFont(fnt);
3244  }
3245  }
3246  fParameterHelpTable->resizeRowToContents(a);
3247  }
3248  for (int c=0; c<8; c++) {
3249  if (c !=2) {
3250  fParameterHelpTable->resizeColumnToContents(c);
3251  }
3252  }
3253  fParameterHelpLabel->setVisible(true);
3254  fParameterHelpTable->setVisible(true);
3255 
3256  }
3257 }
3258 
3259 
3265 G4bool G4UIQt::IsGUICommand(
3266  const G4UIcommand *aCommand
3267 )
3268 {
3269  if (aCommand == NULL)
3270  return false;
3271 
3272  G4int n_parameterEntry = aCommand->GetParameterEntries();
3273 
3274  if( n_parameterEntry > 0 ) {
3275  G4UIparameter *param;
3276 
3277  // Re-implementation of G4UIparameter.cc
3278 
3279  for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
3280  param = aCommand->GetParameter(i_thParameter);
3281  if (QString(QChar(param->GetParameterType())) == "d") {
3282  return true;
3283  }
3284  if (QString(QChar(param->GetParameterType())) == "b") {
3285  return true;
3286  }
3287  if (QString(QChar(param->GetParameterType())) == "i") {
3288  return true;
3289  }
3290  if (QString(QChar(param->GetParameterType())) == "s") {
3291  return true;
3292  }
3293  }
3294  }
3295  return false;
3296 }
3297 
3298 
3301 G4bool G4UIQt::GetHelpChoice(
3302  G4int&
3303 )
3304 {
3305  return true;
3306 }
3307 
3308 
3316 bool G4UIQt::eventFilter( // Should stay with a minuscule eventFilter because of Qt
3317  QObject *aObj
3318 ,QEvent *aEvent
3319 )
3320 {
3321  bool tabKeyPress = false;
3322  bool moveCommandCursor = false;
3323  if (aObj == NULL) return false;
3324  if (aEvent == NULL) return false;
3325 
3326  if (aObj == fHistoryTBTableList) {
3327  if (aEvent->type() == QEvent::KeyPress) {
3328  fCommandArea->setFocus();
3329  }
3330  }
3331 
3332  if (aObj == fCompleter->popup()) {
3333  if (aEvent->type() == QEvent::KeyPress) {
3334  QKeyEvent *e = static_cast<QKeyEvent*>(aEvent);
3335  if (e->key() == (Qt::Key_Tab)) {
3336  tabKeyPress = true;
3337  }
3338  }
3339  }
3340 
3341  if (aObj == fCommandArea) {
3342  if (aEvent->type() == QEvent::KeyPress) {
3343  QKeyEvent *e = static_cast<QKeyEvent*>(aEvent);
3344  if ((e->key() == (Qt::Key_Down)) ||
3345  (e->key() == (Qt::Key_PageDown)) ||
3346  (e->key() == (Qt::Key_Up)) ||
3347  (e->key() == (Qt::Key_PageUp))) {
3348  int selection = fHistoryTBTableList->currentRow();
3349  if (fHistoryTBTableList->count()) {
3350  if (selection == -1) {
3351  selection = fHistoryTBTableList->count()-1;
3352  } else {
3353  if (e->key() == (Qt::Key_Down)) {
3354  if (selection <(fHistoryTBTableList->count()-1))
3355  selection++;
3356  } else if (e->key() == (Qt::Key_PageDown)) {
3357  selection = fHistoryTBTableList->count()-1;
3358  } else if (e->key() == (Qt::Key_Up)) {
3359  if (selection >0)
3360  selection --;
3361  } else if (e->key() == (Qt::Key_PageUp)) {
3362  selection = 0;
3363  }
3364  }
3365  fHistoryTBTableList->clearSelection();
3366 #if QT_VERSION < 0x040202
3367  fHistoryTBTableList->setItemSelected(fHistoryTBTableList->item(selection),true);
3368 #else
3369  fHistoryTBTableList->item(selection)->setSelected(true);
3370 #endif
3371  fHistoryTBTableList->setCurrentItem(fHistoryTBTableList->item(selection));
3372  }
3373  moveCommandCursor = true;
3374  } else if (e->key() == (Qt::Key_Tab)) {
3375  tabKeyPress = true;
3376  } else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_A)) {
3377  fCommandArea->home(false);
3378  return true;
3379  } else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_E)) {
3380  fCommandArea->end(false);
3381  return true;
3382  }
3383  }
3384  }
3385  if (tabKeyPress == true) {
3386  G4String ss = Complete(fCommandArea->text().toStdString().c_str());
3387  fCommandArea->setText((char*)(ss.data()));
3388  fCommandArea->setFocus();
3389  // do not pass by parent, it will disable widget tab focus !
3390  return true;
3391  // L.Garnier : MetaModifier is CTRL for MAC, but I don't want to put a MAC
3392  // specific #ifdef
3393  }
3394 
3395  bool res= false;
3396  // change cursor position if needed
3397  if (moveCommandCursor == true) {
3398  fCommandArea->setCursorPosition ( fCommandArea->text().length() );
3399  fCommandArea->setCursorPosition (4);
3400  } else {
3401  // pass the event on to the parent class
3402  res = QObject::eventFilter(aObj, aEvent);
3403  }
3404  return res;
3405 }
3406 
3407 
3408 void G4UIQt::UpdateCommandCompleter() {
3409  if (!fCommandArea) return;
3410 
3411  // remove previous one
3412  fCommandArea->setCompleter(NULL);
3413  if (fCompleter) {
3414  if (fCompleter->popup()) {
3415  fCompleter->popup()->removeEventFilter(this);
3416  }
3417  }
3418 
3419  QStandardItemModel* model = CreateCompleterModel("/");
3420  fCompleter = new QCompleter(model);
3421 
3422  // set all dir visibles in completion
3424  G4UIcommandTree * commandTreeTop = UI->GetTree();
3425  G4UIcommandTree* aTree = commandTreeTop->FindCommandTree("/");
3426  if (aTree) {
3427  int Ndir= aTree-> GetTreeEntry();
3428  fCompleter->setMaxVisibleItems(Ndir);
3429  }
3430  fCommandArea->setCompleter(fCompleter);
3431  fCompleter->popup()->installEventFilter(this);
3432 }
3433 
3434 
3435 QStandardItemModel* G4UIQt::CreateCompleterModel(G4String aCmd) {
3436 
3437  QList< QStandardItem*> dirModelList;
3438  QList< QStandardItem*> commandModelList;
3439  QList< QStandardItem*> subDirModelList;
3440  QList< QStandardItem*> subCommandModelList;
3441 
3442  G4String strtmp;
3443  G4int nMatch= 0;
3444 
3445  G4String pName = aCmd;
3446  G4String remainingPath = aCmd;
3447  G4String empty = "";
3448  G4String matchingPath = empty;
3449 
3450  // find the tree
3451  G4int jpre= pName.last('/');
3452  if(jpre != G4int(G4String::npos)) pName.remove(jpre+1);
3454  G4UIcommandTree * commandTreeTop = UI->GetTree();
3455  G4UIcommandTree* aTree = commandTreeTop->FindCommandTree(pName);
3456  if (aTree) {
3457  int Ndir= aTree-> GetTreeEntry();
3458  int Ncmd= aTree-> GetCommandEntry();
3459 
3460  // directory ...
3461  for(G4int idir=1; idir<=Ndir; idir++) {
3462  G4String fpdir= aTree-> GetTree(idir)-> GetPathName();
3463  // matching test
3464  if( fpdir.index(remainingPath, 0) == 0) {
3465  if(nMatch==0) {
3466  matchingPath = fpdir;
3467  } else {
3468  matchingPath = aTree->GetFirstMatchedString(fpdir,matchingPath);
3469  }
3470  nMatch++;
3471 
3472  // append to dir model list
3473  QStandardItem* item1 = new QStandardItem(fpdir.data());
3474  QIcon i = QIcon(*fDirIcon);
3475  item1->setData(1); // dir
3476  item1->setIcon(QIcon(*fDirIcon));
3477  dirModelList.append(item1);
3478 
3479  // Go recursively
3480  QStandardItemModel* subModel = CreateCompleterModel(fpdir.data());
3481  for (int a=0; a< subModel->rowCount(); a++) {
3482 
3483  // copy item (an item could only be part of one model
3484  QStandardItem* tempItem = new QStandardItem(subModel->item(a)->text());
3485  tempItem->setIcon(subModel->item(a)->icon());
3486  tempItem->setToolTip(subModel->item(a)->toolTip());
3487  tempItem->setData(subModel->item(a)->data());
3488 
3489  // dir
3490  if (tempItem->data() == 1) {
3491  subModel->item(a);
3492  subDirModelList.append(tempItem);
3493  }
3494  // command
3495  else if (tempItem->data() == 0) {
3496  subCommandModelList.append(tempItem);
3497  }
3498  }
3499  }
3500  }
3501 
3502  // command ...
3503  G4int n_parameterEntry;
3504  G4String rangeString;
3505  G4int n_guidanceEntry;
3506  G4UIcommand * command;
3507  G4UIparameter *param;
3508  std::string tooltip;
3509  G4String params;
3510 
3511  for(G4int icmd=1; icmd<=Ncmd; icmd++){
3512  tooltip = "";
3513  params = " ";
3514  command = aTree-> GetCommand(icmd);
3515  G4String longCommandName= aTree-> GetPathName() +
3516  command -> GetCommandName();
3517  rangeString = command->GetRange();
3518  n_guidanceEntry = command->GetGuidanceEntries();
3519  n_parameterEntry = command->GetParameterEntries();
3520 
3521 
3522  // matching test
3523  if( longCommandName.index(remainingPath, 0) ==0) {
3524  if(nMatch==0) {
3525  matchingPath= longCommandName + " ";
3526  } else {
3527  strtmp= longCommandName + " ";
3528  matchingPath= aTree->GetFirstMatchedString(matchingPath, strtmp);
3529  }
3530 
3531  // guidance
3532  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
3533  tooltip += std::string((command->GetGuidanceLine(i_thGuidance)).data());
3534  if (i_thGuidance < n_guidanceEntry-1 ) {
3535  tooltip += "\n";
3536  }
3537  }
3538 
3539  // parameters
3540  for( G4int a=0; a<n_parameterEntry; a++ ) {
3541  param = command->GetParameter(a);
3542  params += "<" + param->GetParameterName()+"> ";
3543  }
3544  nMatch++;
3545 
3546  // Append to command model list
3547  QStandardItem* item = new QStandardItem(G4String(longCommandName + params).data());
3548  item->setData(0); // command
3549  item->setIcon(QIcon(*fCommandIcon));
3550  item->setToolTip(tooltip.c_str());
3551 
3552  commandModelList.append(item);
3553  }
3554  }
3555  }
3556 
3557  QStandardItemModel* model = new QStandardItemModel();
3558  // initialize the model
3559  model->setColumnCount(1);
3560 
3561  // concat models
3562  for (int a= 0; a< dirModelList.size(); a++) {
3563  model->appendRow(dirModelList.at(a));
3564  }
3565  for (int a= 0; a< subDirModelList.size(); a++) {
3566  model->appendRow(subDirModelList.at(a));
3567  }
3568  for (int a= 0; a< commandModelList.size(); a++) {
3569  model->appendRow(commandModelList.at(a));
3570  }
3571  for (int a= 0; a< subCommandModelList.size(); a++) {
3572  model->appendRow(subCommandModelList.at(a));
3573  }
3574 
3575  return model;
3576 }
3577 
3578 
3579 /***************************************************************************/
3580 //
3581 // SLOTS DEFINITIONS
3582 //
3583 /***************************************************************************/
3584 
3587 void G4UIQt::ShowHelpCallback (
3588 )
3589 {
3590  TerminalHelp("");
3591 }
3592 
3593 
3596 void G4UIQt::ClearButtonCallback (
3597 )
3598 {
3599  fCoutTBTextArea->clear();
3600  fG4OutputString.clear();
3601 }
3602 
3605 void G4UIQt::ExitSession (
3606 )
3607 {
3608  SessionTerminate();
3609 }
3610 
3611 void G4UIQt::ExitHelp(
3612 ) const
3613 {
3614 }
3615 
3619 void G4UIQt::CommandEnteredCallback (
3620 )
3621 {
3622  // split by any new line character
3623  fCommandArea->setText(fCommandArea->text().trimmed());
3624  QStringList list = fCommandArea->text().split(QRegExp("[\r\n]"),QString::SkipEmptyParts);
3625 
3626  // Apply for all commands
3627  for (int a=0; a< list.size(); a++) {
3628  QString txt (list[a].trimmed());
3629  if (txt != "") {
3630  fHistoryTBTableList->addItem(txt);
3631  fHistoryTBTableList->clearSelection();
3632  fHistoryTBTableList->setCurrentItem(NULL);
3633  fCommandArea->setText("");
3634  G4Qt* interactorManager = G4Qt::getInstance ();
3635  if (interactorManager) {
3636  interactorManager->FlushAndWaitExecution();
3637  }
3638 
3639  G4String command = txt.toStdString().c_str();
3640  if (command(0,4) != "help") {
3641  ApplyShellCommand (command,exitSession,exitPause);
3642  } else {
3643  ActivateCommand(command);
3644  }
3645  }
3646  }
3647  // set the focus to the command line
3648  fCommandArea->setFocus();
3649 
3650  // Rebuild help tree
3651  FillHelpTree();
3652 
3653  // Rebuild command completion
3654  UpdateCommandCompleter();
3655 
3656  if(exitSession==true)
3657  SessionTerminate();
3658 }
3659 
3660 
3665 void G4UIQt::CommandEditedCallback(const QString &)
3666 {
3667  QStringList list = fCommandArea->text().split(QRegExp("[\r\n]"),QString::SkipEmptyParts);
3668 
3669  if (list.size() > 1) { // trigger ActivateCommand
3670  for (int a=0; a<list.size()-1; a++) {
3671  // set only the first part
3672  fCommandArea->setText(list[a]);
3673  // trigger callback
3674  CommandEnteredCallback();
3675  }
3676  // reset unfinished command
3677  fCommandArea->setText(list[list.size()-1]);
3678  }
3679 }
3680 
3681 
3684 void G4UIQt::VisParameterCallback(QWidget* widget){
3685  if (widget == NULL) {
3686  return;
3687  }
3688 
3689  // Look in all the Grid layout, but only column 1 (0 is the parameter name)
3690  QGridLayout* grid = dynamic_cast<QGridLayout*>(widget->layout());
3691  if (grid == 0) {
3692  return;
3693  }
3694  QString command;
3695 #if QT_VERSION < 0x040400
3696  QWidget* name = grid->itemAt(grid->columnCount()*(grid->rowCount()-2))->widget();
3697 #else
3698  QWidget* name = grid->itemAtPosition(grid->rowCount()-1,0)->widget();
3699 #endif
3700  if (dynamic_cast<QLabel*>(name) == 0) {
3701  return;
3702  }
3703  command += (dynamic_cast<QLabel*>(name))->text()+" ";
3704 
3705  for (int a=0;a<grid->rowCount()-1; a++) {
3706 #if QT_VERSION < 0x040400
3707  QWidget* widgetTmp = grid->itemAt(a*grid->columnCount()+1)->widget();
3708 #else
3709  QWidget* widgetTmp = grid->itemAtPosition(a,1)->widget();
3710 #endif
3711 
3712  // 4 kind of widgets : QLineEdit / QComboBox / radioButtonsGroup / QPushButton (color chooser)
3713  if (widgetTmp != NULL) {
3714 
3715  if (dynamic_cast<QLineEdit*>(widgetTmp) != 0) {
3716  command += (dynamic_cast<QLineEdit*>(widgetTmp))->text()+" ";
3717 
3718  } else if (dynamic_cast<QComboBox*>(widgetTmp) != 0){
3719  command += (dynamic_cast<QComboBox*>(widgetTmp))->itemText((dynamic_cast<QComboBox*>(widgetTmp))->currentIndex())+" ";
3720 
3721  // Color chooser
3722  } else if (dynamic_cast<QPushButton*>(widgetTmp) != 0){
3723  command += widgetTmp->accessibleName()+" ";
3724 
3725  // Check for Button group
3726  } else if (dynamic_cast<QWidget*>(widgetTmp) != 0){
3727  if (widgetTmp->layout()->count() > 0){
3728  if (dynamic_cast<QRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()) != 0) {
3729  QAbstractButton * checked = (dynamic_cast<QRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()))->group()->checkedButton();
3730  if (checked != 0) {
3731  command += (dynamic_cast<QRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()))->group()->checkedButton()->text()+" ";
3732  }
3733  }
3734  }
3735 
3736  }
3737  }
3738  }
3739  if (command != "") {
3741  if(UI != NULL) {
3742  UI->ApplyCommand(command.toStdString().c_str());
3743  }
3744  }
3745 }
3746 
3747 
3753 void G4UIQt::ButtonCallback (
3754  const QString& aCommand
3755 )
3756 {
3757  G4String ss = G4String(aCommand.toStdString().c_str());
3758  ss = ss.strip(G4String::leading);
3759 
3761  if(UI==NULL) return;
3762  G4UIcommandTree * treeTop = UI->GetTree();
3763 
3764  G4UIcommand* command = treeTop->FindPath(ss);
3765 
3766  if (command) {
3767  // if is GUI, then open a dialog
3768  if (IsGUICommand(command)) {
3769  QDialog* menuParameterDialog = new QDialog();
3770 
3771  if (CreateVisCommandGroupAndToolBox(command,menuParameterDialog,1,true)) {
3772  menuParameterDialog->setWindowTitle (aCommand);
3773  menuParameterDialog->setSizePolicy (QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
3774 
3775  // exec this dialog, apply the command automaticaly, and return
3776  menuParameterDialog->exec();
3777  return;
3778  }
3779  delete menuParameterDialog;
3780  }
3781  }
3782 
3783  ApplyShellCommand(ss,exitSession,exitPause);
3784 
3785  // Rebuild help tree
3786  FillHelpTree();
3787 
3788  if(exitSession==true)
3789  SessionTerminate();
3790 }
3791 
3792 
3793 
3796 void G4UIQt::HelpTreeClicCallback (
3797 )
3798 {
3799  QTreeWidgetItem* item = NULL;
3800  if (!fHelpTreeWidget)
3801  return ;
3802 
3803  QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
3804  if (list.isEmpty())
3805  return;
3806  item = list.first();
3807  if (!item)
3808  return;
3809 
3811  if(UI==NULL) return;
3812  G4UIcommandTree * treeTop = UI->GetTree();
3813 
3814  std::string itemText = GetLongCommandPath(item).toStdString();
3815 
3816  // check if it is a command path
3817  if (item->childCount() > 0) {
3818  itemText +="/";
3819  }
3820  G4UIcommand* command = treeTop->FindPath(itemText.c_str());
3821 
3822  if (command) {
3823  updateHelpArea(command);
3824  } else { // this is a command
3825  G4UIcommandTree* path = treeTop->FindCommandTree(itemText.c_str());
3826  if ( path) {
3827  // this is not a command, this is a sub directory
3828  // We display the Title
3829  fParameterHelpLabel->setVisible(true);
3830  fParameterHelpLabel->setText(path->GetTitle().data());
3831  fParameterHelpTable->setVisible(false);
3832  }
3833  }
3834 }
3835 
3838 void G4UIQt::HelpTreeDoubleClicCallback (
3839 )
3840 {
3841  HelpTreeClicCallback();
3842 
3843  QTreeWidgetItem* item = NULL;
3844  if (!fHelpTreeWidget)
3845  return ;
3846 
3847  QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
3848  if (list.isEmpty())
3849  return;
3850  item = list.first();
3851  if (!item)
3852  return;
3853 
3854  fCommandArea->clear();
3855  fCommandArea->setText(GetLongCommandPath(item));
3856 }
3857 
3858 
3862 void G4UIQt::CommandHistoryCallback(
3863 )
3864 {
3865  QListWidgetItem* item = NULL;
3866  if (!fHistoryTBTableList)
3867  return ;
3868 
3869 
3870  QList<QListWidgetItem *> list =fHistoryTBTableList->selectedItems();
3871  if (list.isEmpty())
3872  return;
3873  item = list.first();
3874  if (!item)
3875  return;
3876  fCommandArea->setText(item->text());
3877 }
3878 
3879 
3880 void G4UIQt::ThreadComboBoxCallback(int) {
3881  CoutFilterCallback("");
3882 }
3883 
3884 
3885 void G4UIQt::CoutFilterCallback(
3886 const QString &) {
3887 
3888  FilterAllOutputTextArea();
3889 
3890  fCoutTBTextArea->repaint();
3891  fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
3892 
3893  }
3894 
3895 
3896 void G4UIQt::SaveOutputCallback(){
3897  QString fileName = QFileDialog::getSaveFileName(fMainWindow, "Save console output as...", fLastOpenPath, "Save output as...");
3898  if (fileName != "") {
3899 
3900  QFile data(fileName);
3901  if (data.open(QFile::WriteOnly | QFile::Truncate)) {
3902  QTextStream out(&data);
3903  out << fCoutTBTextArea->toPlainText();
3904  out.flush();
3905  }
3906  data.close();
3907  }
3908 }
3909 
3910 
3911 QString G4UIQt::FilterOutput(
3912  const G4UIOutputString& output
3913 ,const QString& currentThread
3914 ,const QString& filter
3915 ) {
3916 
3917 #ifdef G4MULTITHREADED
3918  if ((currentThread == "All") ||
3919  (currentThread == output.fThread)) {
3920 #else
3921  if (currentThread == "") {
3922 #endif
3923  if (output.fText.contains(QRegExp(filter))) {
3924  return output.fText;
3925  }
3926  }
3927  return "";
3928 }
3929 
3930 
3931 void G4UIQt::FilterAllOutputTextArea() {
3932 
3933  QString currentThread = "";
3934 #ifdef G4MULTITHREADED
3935  currentThread = fThreadsFilterComboBox->currentText();
3936  if (currentThread == "Master") {
3937  currentThread = "";
3938  }
3939 #endif
3940  QString filter = fCoutFilter->text();
3941  G4String previousOutputStream = "";
3942 
3943  fCoutTBTextArea->clear();
3944  fCoutTBTextArea->setTextColor(QColor(Qt::black));
3945 
3946  for (unsigned int a=0; a<fG4OutputString.size(); a++) {
3947  G4UIOutputString out = fG4OutputString[a];
3948  if (FilterOutput(out,currentThread,filter) != "") {
3949 
3950  // changing color ?
3951  if (out.fOutputStream != previousOutputStream) {
3952  previousOutputStream = out.fOutputStream;
3953  if (out.fOutputStream == "info") {
3954  fCoutTBTextArea->setTextColor(QColor(Qt::black));
3955  } else {
3956  fCoutTBTextArea->setTextColor(QColor(Qt::red));
3957  }
3958  }
3959  fCoutTBTextArea->append(out.fText);
3960  }
3961  }
3962  fCoutTBTextArea->setTextColor(QColor(Qt::black));
3963 }
3964 
3965 
3970 void G4UIQt::LookForHelpStringCallback(
3971 )
3972 {
3973  fHelpLine->setText(fHelpLine->text().trimmed());
3974  QString searchText = fHelpLine->text();
3975 
3976  fParameterHelpLabel->setText("");
3977  fParameterHelpTable->setVisible(false);
3978  if (searchText =="") {
3979  // clear old help tree
3980  fHelpTreeWidget->clear();
3981 
3982  FillHelpTree();
3983 
3984  return;
3985  } else {
3986  OpenHelpTreeOnCommand(searchText);
3987  }
3988 }
3989 
3990 
3991 void G4UIQt::OpenHelpTreeOnCommand(
3992  const QString & searchText
3993 )
3994 {
3995  // the help tree
3997  if(UI==NULL) return;
3998  G4UIcommandTree * treeTop = UI->GetTree();
3999 
4000  G4int treeSize = treeTop->GetTreeEntry();
4001 
4002  // clear old help tree
4003  fHelpTreeWidget->clear();
4004 
4005  // look for new items
4006 
4007  int tmp = 0;
4008 
4009  QMap<int,QString> commandResultMap;
4010  QMap<int,QString> commandChildResultMap;
4011 
4012  for (int a=0;a<treeSize;a++) {
4013  G4UIcommand* command = treeTop->FindPath(treeTop->GetTree(a+1)->GetPathName().data());
4014  tmp = GetCommandList (command).count(searchText,Qt::CaseInsensitive);
4015  if (tmp >0) {
4016  commandResultMap.insertMulti(tmp,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()));
4017  }
4018  // look for childs
4019  commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a+1),searchText);
4020  // insert new childs
4021  if (!commandChildResultMap.empty()) {
4022  QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
4023  while (i != commandChildResultMap.constEnd()) {
4024  commandResultMap.insertMulti(i.key(),i.value());
4025  i++;
4026  }
4027  commandChildResultMap.clear();
4028  }
4029  }
4030 
4031  // build new help tree
4032  fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
4033  fHelpTreeWidget->setColumnCount(2);
4034  QStringList labels;
4035  labels << QString("Command") << QString("Match");
4036  fHelpTreeWidget->setHeaderLabels(labels);
4037 
4038  if (commandResultMap.empty()) {
4039  fParameterHelpLabel->setText("No match found");
4040  fParameterHelpTable->setVisible(false);
4041  return;
4042  }
4043 
4044  QMap<int,QString>::const_iterator i = commandResultMap.constEnd();
4045  i--;
4046  // 10 maximum progress values
4047  float multValue = 10.0/(float)(i.key());
4048  QString progressChar = "|";
4049  QString progressStr = "|";
4050 
4051  QTreeWidgetItem * newItem;
4052  bool end = false;
4053  while (!end) {
4054  if (i == commandResultMap.constBegin()) {
4055  end = true;
4056  }
4057  for(int a=0;a<int(i.key()*multValue);a++) {
4058  progressStr += progressChar;
4059  }
4060  newItem = new QTreeWidgetItem();
4061  QString commandStr = i.value().trimmed();
4062 
4063  if (commandStr.indexOf("/") == 0) {
4064  commandStr = commandStr.right(commandStr.size()-1);
4065  }
4066 
4067  newItem->setText(0,commandStr);
4068  newItem->setText(1,progressStr);
4069  fHelpTreeWidget->addTopLevelItem(newItem);
4070 #if QT_VERSION < 0x040200
4071 #else
4072  newItem->setForeground ( 1, QBrush(Qt::blue) );
4073 #endif
4074  progressStr = "|";
4075  i--;
4076  }
4077  fHelpTreeWidget->resizeColumnToContents (0);
4078  fHelpTreeWidget->sortItems(1,Qt::DescendingOrder);
4079  // fHelpTreeWidget->setColumnWidth(1,10);//resizeColumnToContents (1);
4080 }
4081 
4082 
4083 
4084 
4085 QMap<int,QString> G4UIQt::LookForHelpStringInChildTree(
4086  G4UIcommandTree *aCommandTree
4087 ,const QString & text
4088  )
4089 {
4090  QMap<int,QString> commandResultMap;
4091  if (aCommandTree == NULL) return commandResultMap;
4092 
4093 
4094  // Get the Sub directories
4095  int tmp = 0;
4096  QMap<int,QString> commandChildResultMap;
4097 
4098  for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
4099  const G4UIcommand* command = aCommandTree->GetGuidance();
4100  tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
4101  if (tmp >0) {
4102  commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()));
4103  }
4104  // look for childs
4105  commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text);
4106 
4107  if (!commandChildResultMap.empty()) {
4108  // insert new childs
4109  QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
4110  while (i != commandChildResultMap.constEnd()) {
4111  commandResultMap.insertMulti(i.key(),i.value());
4112  i++;
4113  }
4114  commandChildResultMap.clear();
4115  }
4116  }
4117  // Get the Commands
4118 
4119  for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
4120  const G4UIcommand* command = aCommandTree->GetCommand(a+1);
4121  tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
4122  if (tmp >0) {
4123  commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()));
4124  }
4125 
4126  }
4127  return commandResultMap;
4128 }
4129 
4130 
4131 QString G4UIQt::GetShortCommandPath(
4132 QString commandPath
4133 )
4134 {
4135  if (commandPath.indexOf("/") == 0) {
4136  commandPath = commandPath.right(commandPath.size()-1);
4137  }
4138 
4139  commandPath = commandPath.right(commandPath.size()-commandPath.lastIndexOf("/",-2)-1);
4140 
4141  if (commandPath.lastIndexOf("/") == (commandPath.size()-1)) {
4142  commandPath = commandPath.left(commandPath.size()-1);
4143  }
4144 
4145  return commandPath;
4146 }
4147 
4148 
4149 QString G4UIQt::GetLongCommandPath(
4150  QTreeWidgetItem* item
4151 )
4152 {
4153  if (item == NULL) return "";
4154 
4155  // rebuild path:
4156  QString itemText = "";
4157  itemText = item->text(0);
4158 
4159  while (item->parent() != NULL) {
4160  itemText = item->parent()->text(0)+"/"+itemText;
4161  item = item->parent();
4162  }
4163  itemText = "/"+itemText;
4164 
4165  return itemText;
4166 }
4167 
4168 
4169 void G4UIQt::ChangeColorCallback(QWidget* widget) {
4170  if (widget == NULL) {
4171  return;
4172  }
4173 
4174  QPushButton* button = dynamic_cast<QPushButton*>(widget);
4175  if (button == 0) {
4176  return;
4177  }
4178  QString value = button->accessibleName();
4179 
4180  QColor old;
4181  old.setRgbF(value.section(" ",0,1).toDouble(),
4182  value.section(" ",1,2).toDouble(),
4183  value.section(" ",2,3).toDouble());
4184 #if QT_VERSION < 0x040500
4185  bool a;
4186  QColor color = QColor(QColorDialog::getRgba (old.rgba(),&a,fUITabWidget));
4187 #else
4188  QColor color = QColorDialog::getColor(old,
4189  fUITabWidget,
4190  "Change color",
4191  QColorDialog::ShowAlphaChannel);
4192 #endif
4193 
4194 
4195  if (color.isValid()) {
4196  // rebuild the widget icon
4197  QPixmap pixmap = QPixmap(QSize(16, 16));
4198  pixmap.fill (color);
4199  QPainter painter(&pixmap);
4200  painter.setPen(Qt::black);
4201  painter.drawRect(0,0,15,15); // Draw contour
4202 
4203  button->setAccessibleName(QString::number(color.redF())+" "+
4204  QString::number(color.greenF())+" "+
4205  QString::number(color.blueF())+" "
4206  );
4207  button->setIcon(pixmap);
4208 
4209 
4210  }
4211 }
4212 
4213 
4214 void G4UIQt::ChangeCursorAction(const QString& action) {
4215 
4216  // Theses actions should be in the app toolbar
4217 
4218  fMoveSelected = true;
4219  fPickSelected = true;
4220  fRotateSelected = true;
4221  fZoomInSelected = true;
4222  fZoomOutSelected = true;
4223 
4224  if (fToolbarApp == NULL) return;
4225  QList<QAction *> list = fToolbarApp->actions ();
4226  for (int i = 0; i < list.size(); ++i) {
4227  if (list.at(i)->data().toString () == action) {
4228  list.at(i)->setChecked(TRUE);
4229  if (list.at(i)->data().toString () == "pick") {
4230  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/picking true");
4231  CreatePickInfosDialog();
4232 
4233  fPickInfosDialog->show();
4234  fPickInfosDialog->raise();
4235  fPickInfosDialog->activateWindow();
4236  }
4237  } else if (list.at(i)->data().toString () == "move") {
4238  fMoveSelected = false;
4239  list.at(i)->setChecked(FALSE);
4240  } else if (list.at(i)->data().toString () == "pick") {
4241  fPickSelected = false;
4242  list.at(i)->setChecked(FALSE);
4243  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/picking false");
4244  fPickInfosDialog->hide();
4245  } else if (list.at(i)->data().toString () == "rotate") {
4246  fRotateSelected = false;
4247  list.at(i)->setChecked(FALSE);
4248  } else if (list.at(i)->data().toString () == "zoom_in") {
4249  fZoomInSelected = false;
4250  list.at(i)->setChecked(FALSE);
4251  } else if (list.at(i)->data().toString () == "zoom_out") {
4252  fZoomOutSelected = false;
4253  list.at(i)->setChecked(FALSE);
4254  }
4255  }
4256  // FIXME : Should connect this to Vis
4257 }
4258 
4259 
4260 /* A little bit like "void G4OpenGLQtViewer::toggleDrawingAction(int aAction)"
4261  But for all viewers, not only Qt
4262 
4263 FIXME : Should be a feedback when changing viewer !
4264 
4265  */
4266 void G4UIQt::ChangeSurfaceStyle(const QString& action) {
4267 
4268  // Theses actions should be in the app toolbar
4269 
4270  if (fToolbarApp == NULL) return;
4271  QList<QAction *> list = fToolbarApp->actions ();
4272  for (int i = 0; i < list.size(); ++i) {
4273  if (list.at(i)->data().toString () == action) {
4274  list.at(i)->setChecked(TRUE);
4275  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
4276  list.at(i)->setChecked(FALSE);
4277  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
4278  list.at(i)->setChecked(FALSE);
4279  } else if (list.at(i)->data().toString () == "solid") {
4280  list.at(i)->setChecked(FALSE);
4281  } else if (list.at(i)->data().toString () == "wireframe") {
4282  list.at(i)->setChecked(FALSE);
4283  }
4284  }
4285  // FIXME : Should connect this to Vis
4286 
4287  if (action == "hidden_line_removal") {
4288  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style w");
4289  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 1");
4290 
4291  } else if (action == "hidden_line_and_surface_removal") {
4292  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style s");
4293  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 1");
4294 
4295  } else if (action == "solid") {
4296  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style s");
4297  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 0");
4298 
4299  } else if (action == "wireframe") {
4300  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style w");
4301  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 0");
4302  }
4303 }
4304 
4305 
4306 void G4UIQt::OpenIconCallback(const QString& aParam) {
4307 
4308  QString aCommand = aParam.left(aParam.indexOf(fStringSeparator));
4309  QString aLabel = aParam.mid(aParam.indexOf(fStringSeparator)+fStringSeparator.length());
4310 
4311  QString nomFich = QFileDialog::getOpenFileName(fMainWindow, aLabel, fLastOpenPath, "Macro files (*.mac)");
4312  if (nomFich != "") {
4313  G4UImanager::GetUIpointer()->ApplyCommand((QString(aCommand)+ QString(" ")+ nomFich).toStdString().c_str());
4314  QDir dir;
4315  fLastOpenPath = dir.absoluteFilePath(nomFich);
4316  }
4317 }
4318 
4319 
4320 void G4UIQt::SaveIconCallback(const QString& aParam) {
4321 
4322  QString aCommand = aParam.left(aParam.indexOf(fStringSeparator));
4323  QString aLabel = aParam.mid(aParam.indexOf(fStringSeparator)+fStringSeparator.length());
4324 
4325  QString nomFich = QFileDialog::getSaveFileName(fMainWindow, aLabel, fLastOpenPath, "Macro files (*.mac)");
4326  if (nomFich != "") {
4327  G4UImanager::GetUIpointer()->ApplyCommand((QString(aCommand)+ QString(" ")+nomFich).toStdString().c_str());
4328  QDir dir;
4329  fLastOpenPath = dir.absoluteFilePath(nomFich);
4330  }
4331 }
4332 
4333 
4334 void G4UIQt::CreateViewerPropertiesDialog() {
4335 
4336  if (fViewerPropertiesDialog != NULL) {
4337  return;
4338  }
4339  fViewerPropertiesDialog = new QDialog();
4340 
4341  fViewerPropertiesDialog->setWindowTitle("Viewer properties");
4342  fViewerPropertiesDialog->setSizePolicy (QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
4343 
4344  if (!fViewerPropertiesWidget) {
4345  fViewerPropertiesWidget = new QWidget();
4346  QVBoxLayout* layoutPropertiesWidget = new QVBoxLayout();
4347  fViewerPropertiesWidget->setLayout(layoutPropertiesWidget);
4348 
4349  CreateEmptyViewerPropertiesWidget();
4350  }
4351 
4352  QVBoxLayout* layoutDialog = new QVBoxLayout();
4353 
4354  layoutDialog->addWidget(fViewerPropertiesWidget);
4355  layoutDialog->setContentsMargins(0,0,0,0);
4356  fViewerPropertiesDialog->setLayout(layoutDialog);
4357 }
4358 
4359 
4360 void G4UIQt::CreatePickInfosDialog() {
4361 
4362  if (fPickInfosDialog != NULL) {
4363  return;
4364  }
4365  fPickInfosDialog = new QDialog();
4366 
4367  fPickInfosDialog->setWindowTitle("Pick infos");
4368  fPickInfosDialog->setSizePolicy (QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
4369 
4370  if (!fPickInfosWidget) {
4371  fPickInfosWidget = new QWidget();
4372  QVBoxLayout* layoutPickInfos = new QVBoxLayout();
4373  fPickInfosWidget->setLayout(layoutPickInfos);
4374 
4375  CreateEmptyPickInfosWidget();
4376  }
4377 
4378  QVBoxLayout* layoutDialog = new QVBoxLayout();
4379 
4380  layoutDialog->addWidget(fPickInfosWidget);
4381  layoutDialog->setContentsMargins(0,0,0,0);
4382  fPickInfosDialog->setLayout(layoutDialog);
4383 }
4384 
4385 
4386 void G4UIQt::CreateEmptyViewerPropertiesWidget() {
4387  QLayoutItem * wItem;
4388  if (fViewerPropertiesWidget->layout()->count()) {
4389  while ((wItem = fViewerPropertiesWidget->layout()->takeAt(0)) != 0) {
4390  delete wItem->widget();
4391  delete wItem;
4392  }
4393  }
4394  // Add empty one
4395  QLabel* label = new QLabel("No viewer - Please open a viewer first");
4396  fViewerPropertiesWidget->layout()->addWidget(label);
4397  fViewerPropertiesDialog->setWindowTitle("No viewer");
4398 }
4399 
4400 
4401 void G4UIQt::CreateEmptyPickInfosWidget() {
4402  QLayoutItem * wItem;
4403  if (fPickInfosWidget->layout()->count()) {
4404  while ((wItem = fPickInfosWidget->layout()->takeAt(0)) != 0) {
4405  delete wItem->widget();
4406  delete wItem;
4407  }
4408  }
4409  // Add empty one
4410  QLabel* label = new QLabel("Click on the object you want to pick");
4411  fPickInfosWidget->layout()->addWidget(label);
4412  fPickInfosDialog->setWindowTitle("Nothing to pick");
4413 }
4414 
4415 
4416 void G4UIQt::ViewerPropertiesIconCallback(int) {
4417 
4418  CreateViewerPropertiesDialog();
4419 
4420  fViewerPropertiesDialog->show();
4421  fViewerPropertiesDialog->raise();
4422  fViewerPropertiesDialog->activateWindow();
4423 }
4424 
4425 
4426 void G4UIQt::ChangePerspectiveOrtho(const QString& action) {
4427 
4428  // Theses actions should be in the app toolbar
4429 
4430  if (fToolbarApp == NULL) return;
4431  QList<QAction *> list = fToolbarApp->actions ();
4432  QString checked = "";
4433  for (int i = 0; i < list.size(); ++i) {
4434  if (list.at(i)->data().toString () == action) {
4435  list.at(i)->setChecked(TRUE);
4436  checked = list.at(i)->data().toString ();
4437  } else if (list.at(i)->data().toString () == "persepective") {
4438  list.at(i)->setChecked(FALSE);
4439  } else if (list.at(i)->data().toString () == "ortho") {
4440  list.at(i)->setChecked(FALSE);
4441  }
4442  }
4443 
4444  if ((action == "ortho") && (checked == "ortho")) {
4445  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/projection o");
4446  } else if ((action == "perspective") && (checked == "perspective")) {
4447  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/projection p");
4448  }
4449 }
4450 
4451 
4452 
4453 void G4UIQt::SetIconMoveSelected() {
4454  // Theses actions should be in the app toolbar
4455  fMoveSelected = true;
4456  fRotateSelected = false;
4457  fPickSelected = false;
4458  fZoomInSelected = false;
4459  fZoomOutSelected = false;
4460 
4461  if (fToolbarApp == NULL) return;
4462  QList<QAction *> list = fToolbarApp->actions ();
4463  for (int i = 0; i < list.size(); ++i) {
4464  if (list.at(i)->data().toString () == "move") {
4465  list.at(i)->setChecked(TRUE);
4466  } else if (list.at(i)->data().toString () == "rotate") {
4467  list.at(i)->setChecked(FALSE);
4468  } else if (list.at(i)->data().toString () == "pick") {
4469  list.at(i)->setChecked(FALSE);
4470  } else if (list.at(i)->data().toString () == "zoom_in") {
4471  list.at(i)->setChecked(FALSE);
4472  } else if (list.at(i)->data().toString () == "zoom_out") {
4473  list.at(i)->setChecked(FALSE);
4474  }
4475  }
4476 }
4477 
4478 
4479 void G4UIQt::SetIconRotateSelected() {
4480  // Theses actions should be in the app toolbar
4481  fRotateSelected = true;
4482  fMoveSelected = false;
4483  fPickSelected = false;
4484  fZoomInSelected = false;
4485  fZoomOutSelected = false;
4486 
4487  if (fToolbarApp == NULL) return;
4488  QList<QAction *> list = fToolbarApp->actions ();
4489  for (int i = 0; i < list.size(); ++i) {
4490  if (list.at(i)->data().toString () == "rotate") {
4491  list.at(i)->setChecked(TRUE);
4492  } else if (list.at(i)->data().toString () == "move") {
4493  list.at(i)->setChecked(FALSE);
4494  } else if (list.at(i)->data().toString () == "pick") {
4495  list.at(i)->setChecked(FALSE);
4496  } else if (list.at(i)->data().toString () == "zoom_in") {
4497  list.at(i)->setChecked(FALSE);
4498  } else if (list.at(i)->data().toString () == "zoom_out") {
4499  list.at(i)->setChecked(FALSE);
4500  }
4501  }
4502 }
4503 
4504 
4505 void G4UIQt::SetIconPickSelected() {
4506  // Theses actions should be in the app toolbar
4507  fPickSelected = true;
4508  fMoveSelected = false;
4509  fRotateSelected = false;
4510  fZoomInSelected = false;
4511  fZoomOutSelected = false;
4512 
4513  QToolBar* bar = fToolbarApp;
4514  if (!fDefaultIcons) {
4515  bar = fToolbarUser;
4516  }
4517  if (!bar) return;
4518 
4519  QList<QAction *> list = bar->actions ();
4520  for (int i = 0; i < list.size(); ++i) {
4521  if (list.at(i)->data().toString () == "pick") {
4522  list.at(i)->setChecked(TRUE);
4523  } else if (list.at(i)->data().toString () == "move") {
4524  list.at(i)->setChecked(FALSE);
4525  } else if (list.at(i)->data().toString () == "rotate") {
4526  list.at(i)->setChecked(FALSE);
4527  } else if (list.at(i)->data().toString () == "zoom_in") {
4528  list.at(i)->setChecked(FALSE);
4529  } else if (list.at(i)->data().toString () == "zoom_out") {
4530  list.at(i)->setChecked(FALSE);
4531  }
4532  }
4533 }
4534 
4535 
4536 void G4UIQt::SetIconZoomInSelected() {
4537  // Theses actions should be in the app toolbar
4538  fZoomInSelected = true;
4539  fMoveSelected = false;
4540  fRotateSelected = false;
4541  fPickSelected = false;
4542  fZoomOutSelected = false;
4543 
4544  QToolBar* bar = fToolbarApp;
4545  if (!fDefaultIcons) {
4546  bar = fToolbarUser;
4547  }
4548  if (!bar) return;
4549 
4550  QList<QAction *> list = bar->actions ();
4551  for (int i = 0; i < list.size(); ++i) {
4552  if (list.at(i)->data().toString () == "zoom_in") {
4553  list.at(i)->setChecked(TRUE);
4554  } else if (list.at(i)->data().toString () == "move") {
4555  list.at(i)->setChecked(FALSE);
4556  } else if (list.at(i)->data().toString () == "rotate") {
4557  list.at(i)->setChecked(FALSE);
4558  } else if (list.at(i)->data().toString () == "pick") {
4559  list.at(i)->setChecked(FALSE);
4560  } else if (list.at(i)->data().toString () == "zoom_out") {
4561  list.at(i)->setChecked(FALSE);
4562  }
4563  }
4564 }
4565 
4566 
4567 void G4UIQt::SetIconZoomOutSelected() {
4568  // Theses actions should be in the app toolbar
4569  fZoomOutSelected = true;
4570  fMoveSelected = false;
4571  fRotateSelected = false;
4572  fPickSelected = false;
4573  fZoomInSelected = false;
4574 
4575  QToolBar* bar = fToolbarApp;
4576  if (!fDefaultIcons) {
4577  bar = fToolbarUser;
4578  }
4579  if (!bar) return;
4580 
4581  QList<QAction *> list = bar->actions ();
4582  for (int i = 0; i < list.size(); ++i) {
4583  if (list.at(i)->data().toString () == "zoom_out") {
4584  list.at(i)->setChecked(TRUE);
4585  } else if (list.at(i)->data().toString () == "move") {
4586  list.at(i)->setChecked(FALSE);
4587  } else if (list.at(i)->data().toString () == "rotate") {
4588  list.at(i)->setChecked(FALSE);
4589  } else if (list.at(i)->data().toString () == "pick") {
4590  list.at(i)->setChecked(FALSE);
4591  } else if (list.at(i)->data().toString () == "zoom_in") {
4592  list.at(i)->setChecked(FALSE);
4593  }
4594  }
4595 }
4596 
4597 
4598 void G4UIQt::SetIconSolidSelected() {
4599  // Theses actions should be in the app toolbar
4600 
4601  QToolBar* bar = fToolbarApp;
4602  if (!fDefaultIcons) {
4603  bar = fToolbarUser;
4604  }
4605  if (!bar) return;
4606 
4607  QList<QAction *> list = bar->actions ();
4608  for (int i = 0; i < list.size(); ++i) {
4609  if (list.at(i)->data().toString () == "solid") {
4610  list.at(i)->setChecked(TRUE);
4611  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
4612  list.at(i)->setChecked(FALSE);
4613  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
4614  list.at(i)->setChecked(FALSE);
4615  } else if (list.at(i)->data().toString () == "wireframe") {
4616  list.at(i)->setChecked(FALSE);
4617  }
4618  }
4619 }
4620 
4621 
4622 void G4UIQt::SetIconWireframeSelected() {
4623  // Theses actions should be in the app toolbar
4624 
4625  QToolBar* bar = fToolbarApp;
4626  if (!fDefaultIcons) {
4627  bar = fToolbarUser;
4628  }
4629  if (!bar) return;
4630 
4631  QList<QAction *> list = bar->actions ();
4632  for (int i = 0; i < list.size(); ++i) {
4633  if (list.at(i)->data().toString () == "wireframe") {
4634  list.at(i)->setChecked(TRUE);
4635  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
4636  list.at(i)->setChecked(FALSE);
4637  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
4638  list.at(i)->setChecked(FALSE);
4639  } else if (list.at(i)->data().toString () == "solid") {
4640  list.at(i)->setChecked(FALSE);
4641  }
4642  }
4643 }
4644 
4645 
4646 void G4UIQt::SetIconHLRSelected() {
4647  // Theses actions should be in the app toolbar
4648 
4649  QToolBar* bar = fToolbarApp;
4650  if (!fDefaultIcons) {
4651  bar = fToolbarUser;
4652  }
4653  if (!bar) return;
4654 
4655 
4656  QList<QAction *> list = bar->actions ();
4657  for (int i = 0; i < list.size(); ++i) {
4658  if (list.at(i)->data().toString () == "hidden_line_removal") {
4659  list.at(i)->setChecked(TRUE);
4660  } else if (list.at(i)->data().toString () == "solid") {
4661  list.at(i)->setChecked(FALSE);
4662  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
4663  list.at(i)->setChecked(FALSE);
4664  } else if (list.at(i)->data().toString () == "wireframe") {
4665  list.at(i)->setChecked(FALSE);
4666  }
4667  }
4668 }
4669 
4670 
4671 void G4UIQt::SetIconHLHSRSelected() {
4672  // Theses actions should be in the app toolbar
4673 
4674  QToolBar* bar = fToolbarApp;
4675  if (!fDefaultIcons) {
4676  bar = fToolbarUser;
4677  }
4678 
4679  if (!bar) return;
4680 
4681  QList<QAction *> list = bar->actions ();
4682  for (int i = 0; i < list.size(); ++i) {
4683  if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
4684  list.at(i)->setChecked(TRUE);
4685  } else if (list.at(i)->data().toString () == "solid") {
4686  list.at(i)->setChecked(FALSE);
4687  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
4688  list.at(i)->setChecked(FALSE);
4689  } else if (list.at(i)->data().toString () == "wireframe") {
4690  list.at(i)->setChecked(FALSE);
4691  }
4692  }
4693 }
4694 
4695 
4696 void G4UIQt::SetIconPerspectiveSelected() {
4697  // Theses actions should be in the app toolbar
4698 
4699  QToolBar* bar = fToolbarApp;
4700  if (!fDefaultIcons) {
4701  bar = fToolbarUser;
4702  }
4703  if (!bar) return;
4704 
4705 
4706  QList<QAction *> list = bar->actions ();
4707  for (int i = 0; i < list.size(); ++i) {
4708  if (list.at(i)->data().toString () == "perspective") {
4709  list.at(i)->setChecked(TRUE);
4710  } else if (list.at(i)->data().toString () == "ortho") {
4711  list.at(i)->setChecked(FALSE);
4712  }
4713  }
4714 }
4715 
4716 
4717 
4718 void G4UIQt::SetIconOrthoSelected() {
4719  // Theses actions should be in the app toolbar
4720 
4721  QToolBar* bar = fToolbarApp;
4722  if (!fDefaultIcons) {
4723  bar = fToolbarUser;
4724  }
4725 
4726  if (!bar) return;
4727 
4728  QList<QAction *> list = bar->actions ();
4729  for (int i = 0; i < list.size(); ++i) {
4730  if (list.at(i)->data().toString () == "ortho") {
4731  list.at(i)->setChecked(TRUE);
4732  } else if (list.at(i)->data().toString () == "perspective") {
4733  list.at(i)->setChecked(FALSE);
4734  }
4735  }
4736 }
4737 
4738 
4739 
4740 G4QTabWidget::G4QTabWidget(
4741 QWidget* aParent,
4742 int sizeX,
4743 int sizeY
4744 ):QTabWidget(aParent)
4745  ,fTabSelected(false)
4746  ,fLastCreated(-1)
4747 ,fPreferedSizeX(sizeX+6) // margin left+right
4748 ,fPreferedSizeY(sizeY+58) // tab label height + margin left+right
4749 {
4750  setMinimumSize(100,100);
4751  QSizePolicy policy = QSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
4752  setSizePolicy(policy);
4753 }
4754 
4755 G4QTabWidget::G4QTabWidget(
4756 ):QTabWidget()
4757  ,fTabSelected(false)
4758  ,fLastCreated(-1)
4759 ,fPreferedSizeX(0)
4760 ,fPreferedSizeY(0)
4761 {
4762 }
4763 
4764 
4765 G4UIOutputString::G4UIOutputString(
4766 QString text,
4767 G4String origine,
4768 G4String outputStream
4769 ):
4770  fText(text)
4771 ,fThread(origine)
4772 {
4773  if (!GetOutputList().contains(QString(" ")+outputStream+" ")) {
4774  fOutputStream = "info";
4775  } else {
4776  fOutputStream = outputStream;
4777  }
4778 }
4779 
4780 
4781 #if QT_VERSION < 0x040500
4782 void G4UIQt::TabCloseCallback(int){
4783 #else
4784 void G4UIQt::TabCloseCallback(int a){
4785 #endif
4786 #if QT_VERSION < 0x040500
4787 #else
4788  if (fViewerTabWidget == NULL) return;
4789 
4790  // get the address of the widget
4791  QWidget* temp = fViewerTabWidget->widget(a);
4792  // remove the tab
4793  fViewerTabWidget->removeTab (a);
4794 
4795  // if last QWidget : Add empty string
4796  bool lastTab = true;
4797  for (int c=0; c<fViewerTabWidget->count(); c++) {
4798  if (fViewerTabWidget->tabText(c).contains("viewer")) {
4799  lastTab = false;
4800  }
4801  }
4802 
4803  if (lastTab) {
4804  CreateEmptyViewerPropertiesWidget();
4805  }
4806  // delete the widget
4807  delete temp;
4808 #endif
4809 }
4810 
4811 
4812 void G4UIQt::ToolBoxActivated(int a){
4813 
4814  if (fUITabWidget->widget(a) == fHelpTBWidget) {
4815  // Rebuild the help tree
4816  FillHelpTree();
4817  } else if (fUITabWidget->widget(a) == fSceneTreeWidget) {
4818 #if QT_VERSION < 0x040200
4819  fSceneTreeWidget->show();
4820 #else
4821  fSceneTreeWidget->setVisible(true);
4822 #endif
4823  }
4824 }
4825 
4826 
4827 void G4QTabWidget::paintEvent(
4828 QPaintEvent *
4829 )
4830 {
4831 
4832  if (currentWidget()) {
4833 
4834  if ( isTabSelected()) {
4835 
4836  // QCoreApplication::sendPostedEvents () ;
4837 
4838  QString text = tabText (currentIndex());
4839 
4840  if (fLastCreated == -1) {
4841  QTextEdit* edit = dynamic_cast<QTextEdit*>(currentWidget());
4842  if (!edit){
4843  QString paramSelect = QString("/vis/viewer/select ")+text;
4845  if(UI != NULL) {
4846  UI->ApplyCommand(paramSelect.toStdString().c_str());
4847  }
4848  }
4849  } else {
4850  fLastCreated = -1;
4851  }
4852  setTabSelected(false);
4853  }
4854  }
4855 }
4856 
4857 
4858 G4UIDockWidget::G4UIDockWidget(QString txt):
4859  QDockWidget(txt)
4860 {}
4861 
4862 
4863 void G4UIDockWidget::closeEvent(QCloseEvent *aEvent) {
4864  setFloating (false);
4865 
4866  //prevent from closing
4867  aEvent->ignore();
4868  // hide them instead
4869  hide();
4870 }
4871 
4872  #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
G4String & remove(str_size)
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
G4UIcommand * FindPath(const char *commandPath) const
G4String strip(G4int strip_Type=trailing, char c=' ')
G4int GetCommandEntry() const
G4String GetParameterName() const
G4UIcommand * GetCommand(G4int i)
G4String GetFullPrefixString() const
G4int GetTreeEntry() const
const char * name(G4int ptype)
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
G4String GetFirstMatchedString(const G4String &, const G4String &) 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
G4int last(char) const
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
static constexpr double bar
Definition: G4SIunits.hh:236
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
static const G4double pos
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:446