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