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