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