30 #ifdef G4UI_BUILD_QT_SESSION
45 #include <qapplication.h>
46 #include <qmessagebox.h>
47 #include <qlineedit.h>
51 #include <qpushbutton.h>
53 #include <qsplitter.h>
54 #include <qscrollbar.h>
57 #include <qtextedit.h>
58 #if QT_VERSION < 0x050600
59 #include <qsignalmapper.h>
61 #include <qtabwidget.h>
63 #include <qstringlist.h>
64 #include <qtextstream.h>
66 #include <qmainwindow.h>
68 #include <qlistwidget.h>
69 #include <qtreewidget.h>
70 #include <qheaderview.h>
71 #include <qgroupbox.h>
72 #include <qscrollarea.h>
74 #include <qradiobutton.h>
75 #include <qbuttongroup.h>
76 #include <qcombobox.h>
78 #include <qcolordialog.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>
89 static G4bool exitSession =
true;
90 static G4bool exitPause =
true;
119 ,fCoutTBTextArea(NULL)
124 ,fHistoryTBTableList(NULL)
125 ,fHelpTreeWidget(NULL)
127 ,fHistoryTBWidget(NULL)
128 ,fCoutDockWidget(NULL)
130 ,fSceneTreeWidget(NULL)
131 ,fViewerPropertiesWidget(NULL)
132 ,fPickInfosWidget(NULL)
134 ,fViewerTabWidget(NULL)
137 ,fHelpVSplitter(NULL)
138 ,fParameterHelpLabel(NULL)
139 ,fParameterHelpTable(NULL)
142 ,fStringSeparator(
"__$$$@%%###__")
153 ,fWireframeIcon(NULL)
155 ,fHiddenLineRemovalIcon(NULL)
156 ,fHiddenLineAndSurfaceRemovalIcon(NULL)
157 ,fPerspectiveIcon(NULL)
163 ,fPickTargetIcon(NULL)
164 #ifdef G4MULTITHREADED
165 ,fThreadsFilterComboBox(NULL)
167 ,fDefaultViewerFirstPageHTMLText(
"")
168 ,fViewerPropertiesDialog(NULL)
169 ,fPickInfosDialog(NULL)
170 ,fLastCompleteCommand(
"")
171 ,fMoveSelected(
false)
172 ,fRotateSelected(
true)
173 ,fPickSelected(
false)
174 ,fZoomInSelected(
false)
175 ,fZoomOutSelected(
false)
178 G4Qt* interactorManager = G4Qt::getInstance (argc,argv,(
char*)
"Qt");
179 if (!(QApplication*)interactorManager->GetMainInteractor()) {
184 G4cout <<
"G4UIQt : Unable to init Qt. Aborted" <<
G4endl;
194 Q_FOREACH (QWidget *widget, QApplication::allWidgets()) {
195 if ((found==
false) && (widget->inherits(
"QMainWindow"))) {
205 G4cout <<
"G4UIQt : Found an external App with a QMainWindow already defined. Aborted" <<
G4endl;
211 fMainWindow =
new QMainWindow();
212 fMainWindow->setAttribute(Qt::WA_DeleteOnClose);
214 fMainWindow->setCorner( Qt::TopLeftCorner, Qt::LeftDockWidgetArea );
215 fMainWindow->setCorner( Qt::TopRightCorner, Qt::RightDockWidgetArea );
216 fMainWindow->setCorner( Qt::BottomLeftCorner, Qt::LeftDockWidgetArea );
217 fMainWindow->setCorner( Qt::BottomRightCorner, Qt::RightDockWidgetArea );
219 CreateViewerWidget();
220 fMainWindow->addDockWidget(Qt::LeftDockWidgetArea, CreateUITabWidget());
221 fMainWindow->addDockWidget(Qt::BottomDockWidgetArea, CreateCoutTBWidget());
225 SetDefaultIconsToolbar();
229 #ifdef G4MULTITHREADED
231 masterG4coutDestination =
this;
234 fMainWindow->setWindowTitle(QFileInfo( QCoreApplication::applicationFilePath() ).fileName());
235 fMainWindow->move(QPoint(50,50));
240 fMainWindow->resize(fUIDockWidget->width()+fCoutDockWidget->width()+20,
241 fUIDockWidget->height()+fCoutDockWidget->height()+20);
244 fCommandArea->setFocus(Qt::TabFocusReason);
248 qRegisterMetaType<QTextCursor>(
"QTextCursor");
251 AddTabWidget(fStartPage,
"Useful tips");
254 #if QT_VERSION < 0x040200
257 fMainWindow->setVisible(
false);
271 #ifdef G4MULTITHREADED
272 masterG4coutDestination = 0;
278 void G4UIQt::DefaultIcons(
bool aVal)
280 fDefaultIcons = aVal;
282 #if QT_VERSION < 0x040200
283 if (!fMainWindow->isHidden()) {
285 if (!fMainWindow->isVisible()) {
292 #if QT_VERSION < 0x040200
295 fToolbarApp->setVisible(
true);
299 #if QT_VERSION < 0x040200
302 fToolbarApp->setVisible(
false);
309 void G4UIQt::SetDefaultIconsToolbar(
313 if (fToolbarApp == NULL) {
314 fToolbarApp =
new QToolBar();
315 fToolbarApp->setIconSize (QSize(20,20));
316 fMainWindow->addToolBar(Qt::TopToolBarArea, fToolbarApp);
320 AddIcon(
"Open macro file",
"open",
"/control/execute");
321 AddIcon(
"Save viewer state",
"save",
"/vis/viewer/save");
324 #if QT_VERSION < 0x050600
325 QSignalMapper *signalMapperViewerProperties =
new QSignalMapper(
this);
326 QAction *actionViewerProperties = fToolbarApp->addAction(QIcon(*fParamIcon),
"Viewer properties", signalMapperViewerProperties, SLOT(map()));
327 connect(signalMapperViewerProperties, SIGNAL(mapped(
int)),
this, SLOT(ViewerPropertiesIconCallback(
int)));
329 signalMapperViewerProperties->setMapping(actionViewerProperties, intVP);
331 fToolbarApp->addAction(QIcon(*fParamIcon),
"Viewer properties",
this, [=](){ this->ViewerPropertiesIconCallback(0); });
335 AddIcon(
"Move",
"move",
"");
336 AddIcon(
"Pick",
"pick",
"");
337 AddIcon(
"Zoom out",
"zoom_out",
"");
338 AddIcon(
"Zoom in",
"zoom_in",
"");
339 AddIcon(
"Rotate",
"rotate",
"");
342 AddIcon(
"Hidden line removal",
"hidden_line_removal",
"");
343 AddIcon(
"Hidden line and hidden surface removal",
"hidden_line_and_surface_removal",
"");
344 AddIcon(
"Surfaces",
"solid",
"");
345 AddIcon(
"Wireframe",
"wireframe",
"");
348 AddIcon(
"Perspective",
"perspective",
"");
349 AddIcon(
"Orthographic",
"ortho",
"");
350 AddIcon(
"Run beam on",
"runBeamOn",
"/run/beamOn 1");
355 void G4UIQt::CreateIcons(
358 const char *
const save[]={
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 " @++++++++++++++*&**++@++ ",
417 fSaveIcon =
new QPixmap(save);
419 const char *
const search[] = {
431 "OOOOOOOOOOOOOOOOOOO",
432 "OOOOOOOOOOOOOOOOOOO",
433 "OOOOOOOo. .oOOOOOO",
436 "OOOOO. XOOOOX .OOOO",
439 "OOOOO. XOOOOo .OOOO",
443 "OOOOOOOOOOOOO. XOO",
444 "OOOOOOOOOOOOOO. XOO",
445 "OOOOOOOOOOOOOOOoOOO",
446 "OOOOOOOOOOOOOOOOOOO",
447 "OOOOOOOOOOOOOOOOOOO",
448 "OOOOOOOOOOOOOOOOOOO",
449 "OOOOOOOOOOOOOOOOOOO"
451 fSearchIcon =
new QPixmap(search);
453 const char *
const clear[] = {
465 "OOOOOOOOOOOOOOOOOOOO",
468 "OOOOOOOOOOOOOOOOOOOO",
469 "OOOOOOOOOOOOOOOOOOOO",
470 "OOOO XXXXXXXXXX OOOO",
471 "OOO XOOOOOOOOOO OOO",
472 "OOOOXOooOooOooO OOOO",
473 "OOOOXOooOooOooO OOOO",
474 "OOOOXOooOooOooO OOOO",
475 "OOOOXOooOooOooO OOOO",
476 "OOOOXOooOooOooO OOOO",
477 "OOOOXOooOooOooO OOOO",
478 "OOOOXOooOooOooO OOOO",
479 "OOOOXOooOooOooO OOOO",
480 "OOOOXOooOooOooO OOOO",
481 "OOOOXOooOooOooO OOOO",
482 "OOOOXOOOOOOOOOO OOOO",
483 "OOOOOooooooooooOOOOO",
484 "OOOOOO........OOOOOO"
487 fClearIcon =
new QPixmap(clear);
490 const char *
const open[]={
534 " {]^/((_({- %%%%%%%%%%% ",
535 " {(^_^^^^:<{{{{{{{{{{{{{[& ",
536 " {/_/(((((/]]]]]]]]]]]/]!# ",
537 " {/^(((((_^^^^^^^^^^^^^^:# ",
538 " {/^(((_^^____________^^}$ ",
539 " {/^(((((/////////////((!# ",
540 " {/^/^_:<|||||||||||||||@@****1 ",
541 " {/^/^(<[)||||||||||||||))!!}<; ",
542 " {/^_(:|234444444444444444432)1 ",
543 " {/_^/<)34444444444444444443}, ",
544 " {/^(2{:41111111111111111142|5 ",
545 " {3^3<:31111111111111111143}- ",
546 " {/^2<:31111111111111111441|' ",
547 " {_/<:41111111111111111143}, ",
548 " {(4<:31111111111111111144!# ",
549 " )4))44111111111111111144}, ",
550 " )2<:31111111111111111144{# ",
551 " @|:14444444444444444444}* ",
552 " ;@434444444444444444434<# ",
553 " ;[))))))))))))))))))))!~ ",
554 " ++++++++++++++++++++++;% ",
558 fOpenIcon =
new QPixmap(open);
561 const char *
const move[]={
594 " ')&$$$$*@@ @@*$$$$&)' ",
595 " ')&$$$$*@@ @@*$$$$&+' ",
612 fMoveIcon =
new QPixmap(move);
614 const char *
const rotate[]={
650 " --------!*{{{*&, ",
651 " -------=){*{{{>>{) ",
652 " ,!-----= ){& ,&{{@",
660 " !-!!======!!(((---! ",
661 " ='--------------! ",
676 fRotateIcon =
new QPixmap(rotate);
678 const char *
const pick[]={
694 "*********oo*********",
695 "*********oo*********",
696 "******$O. .O%******",
697 "****&o .O..O O*****",
698 "***&X @**oo**@ X****",
699 "***o $***oo***$ O***",
700 "**% @**********@ %**",
701 "**O.***********& +**",
702 "**.O*****@@*****o.**",
703 "oo .oo**@ #*&XX. oo",
704 "oo .oo**@ #*&oo. oO",
705 "**.O*****##*****oX**",
706 "**O ***********& +**",
707 "**% @****&&****+ &**",
708 "***O $***Xo***# +***",
709 "****X @&*Xo*&+ o****",
710 "*****O o..o +*****",
711 "******%+. X+&******",
712 "*********oo*********",
713 "*********oO*********"
715 fPickIcon =
new QPixmap(pick);
717 const char *
const zoom_in[]={
739 " ++.%%%+&&&*%%.++ ",
740 " .+#%%%%+&&&*%%.#+ ",
741 " ++..%%%+&&&*%%%.++ ",
742 " +#.+++++&&&*++++.+ ",
743 " @.+&&&&&&&&&&&&&+@ ",
744 " @#+&&&&&&&&&&&&&+@ ",
745 " @.+&&&&&&&&&&&&&+. ",
746 " +++@***+&&&****@+. ",
747 " ....++++&&&*++++.. ",
748 " ++.===+&&&*%=.++ ",
749 " @..==+&&&*=..@#& ",
750 " .@+#.+&&&@-+@@*@ ",
763 fZoomInIcon =
new QPixmap(zoom_in);
765 const char *
const zoom_out[]={
787 " ++.$$$$$$$$$$.++ ",
788 " .+#$$$$$$$$$$$.#+ ",
789 " ++..$$$$$$$$$$$.++ ",
790 " +#.+++++++++++++.+ ",
791 " @.+&&&&&&&&&&&&&+@ ",
792 " @#+&&&&&&&&&&&&&+@ ",
793 " @.+&&&&&&&&&&&&&+. ",
794 " +++@***********@+. ",
795 " ....++++++++++++.. ",
796 " ++.===$$$$$$=.++ ",
797 " @..===$$$$=..@#& ",
798 " .@+#.$$$..-+@@*@ ",
811 fZoomOutIcon =
new QPixmap(zoom_out);
842 " +&********&@-***; ",
843 " +@@@&**&@@@@@@$ @*-&>&+ ",
844 " +*****&+ %*@ ,**'# ",
845 " @***)!~ @*{&*****+ ",
846 " @*!]***&+ +-*^**'~!*@ ",
847 " @*~ +@&**&@@@@@@&****&+ ~*@ ",
848 " @*@ +&********&-*= @*@ ",
849 " @*@ $%@-*-@$ @*@ @*@ ",
857 " @*@ =*-+ @*@ @*@ ",
858 " @*@ $%@@&****&@-*-+ @*@ ",
859 " @*@ $@&*****&@@&******&~~!*@ ",
860 " @*{/***&@@%$ $@-*-&*****+ ",
861 " @*)*)(-~ @*@ ~)**] ",
862 " +*******&@@@@+ %*_+]**] ",
863 " +@@@@@&******&@%+_*^**]# ",
872 fWireframeIcon =
new QPixmap(wireframe);
874 const char *
const solid[]={
912 " +-;>>>>>>>>>,')!~ ",
913 " {]@@-;>>>>>>>>>>>>^/(_= ",
914 " {:>>>>>>>>>>>>>>>>><//[)!= ",
915 " ]>>>>>>>>>>>>>>>>>><////[)} ",
916 " @>>>>>>>>>>>>>>>>>><//////| ",
917 " @>>>>>>>>>>>>>>>>>><//////| ",
918 " @>>>>>>>>>>>>>>>>>><//////| ",
919 " @>>>>>>>>>>>>>>>>>><//////| ",
920 " @>>>>>>>>>>>>>>>>>><//////| ",
921 " @>>>>>>>>>>>>>>>>>><//////| ",
922 " @>>>>>>>>>>>>>>>>>><//////| ",
923 " @>>>>>>>>>>>>>>>>>><//////| ",
924 " @>>>>>>>>>>>>>>>>>><//////| ",
925 " @>>>>>>>>>>>>>>>>>><//////| ",
926 " @>>>>>>>>>>>>>>>>>><//////| ",
927 " @>>>>>>>>>>>>>>>>>><//////| ",
928 " @>>>>>>>>>>>>>>>>>><//////| ",
929 " @>>>>>>>>>>>>>>>>>><//////| ",
930 " @>>>>>>>>>>>>>>>>>></////[1 ",
931 " @>>>>>>>>>>>>>>>>>><////[*2 ",
932 " {:>>>>>>>>>>>>>>>>><//[)12 ",
933 " +@@@@@-;>>>>>>>>>><[)13 ",
942 fSolidIcon =
new QPixmap(solid);
944 const char *
const hidden_line_removal[]={
964 " +#$$$$$$$$#@&$$$* ",
965 " =-@@#$$#@@@@@-= @$&#;>= ",
966 " =$$$$$#+ -$@ *$$%+ ",
967 " -$&@-= -$- #$$$= ",
983 " -$&@@@-= -$- =>;, ",
984 " =$$$$$$$#@@@-= -$'+#$$, ",
985 " =-@@@@#$$$$$$#@-+'$)$$#+ ",
994 fHiddenLineRemovalIcon =
new QPixmap(hidden_line_removal);
996 const char *
const hidden_line_and_surface_removal[]={
1042 " ++@%####&*=-#+;>, ",
1043 " +++++@'=)))))))!)~+{]^++ ",
1044 " +$%&*=)!!!!!!!!!)~+/(]_+++ ",
1045 " +#-))!!!!!!!!!!!)~+/(::<[+ ",
1046 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1047 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1048 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1049 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1050 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1051 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1052 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1053 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1054 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1055 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1056 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1057 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1058 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1059 " +#)!!!!!!!!!!!!!!}+/:::|1+ ",
1060 " +$#}}~23!!!!!!!!)~+/(]45, ",
1061 " +++++++@#}}~23!!)~+678++ ",
1062 " ++++++@#~90+a++ ",
1071 fHiddenLineAndSurfaceRemovalIcon =
new QPixmap(hidden_line_and_surface_removal);
1073 const char *
const perspective[]={
1083 " ................ ",
1084 " ....+++++++++++++++. ",
1085 " ...++++..+.........+++. ",
1086 " ..++..............++..+. ",
1087 " .+++++++++++++++++.. .+. ",
1088 " .+...............+. .+. ",
1089 " .+. .+. .+. .+. ",
1090 " .+. .+. .+. .+. ",
1091 " .+. .+. .+. .+. ",
1092 " .+. .+. .+. .+. ",
1093 " .+. .+. .+. .+. ",
1094 " .+. .+. .+. .+. ",
1095 " .+. .+. .+. .+. ",
1096 " .+. .+. .+. .+. ",
1097 " .+. .+......+....+. ",
1098 " .+. ..++++++.+.++++. ",
1099 " .+. .++.......+...+.. ",
1100 " .+. .++. .+..++. ",
1101 " .+. ..+.. .+..+. ",
1104 " .+++.............++. ",
1105 " .+++++++++++++++++. ",
1106 " ................... ",
1111 fPerspectiveIcon =
new QPixmap(perspective);
1113 const char *
const ortho[]={
1121 " ................... ",
1122 " ..@@@@@@@@@@@@@@@@@. ",
1123 " ..@@@.............@@@. ",
1124 " ..@@.@. ..@..@. ",
1125 " ..@@ ..@. .@@...@. ",
1126 " ..@@..............@@.. .@. ",
1127 " .@@@@@@@@@@@@@@@@@.. .@. ",
1128 " .@...............@. .@. ",
1129 " .@. .@. .@. .@. ",
1130 " .@. .@. .@. .@. ",
1131 " .@. .@. .@. .@. ",
1132 " .@. .@. .@. .@. ",
1133 " .@. .@. .@. .@. ",
1134 " .@. .@. .@. .@. ",
1135 " .@. .@. .@. .@. ",
1136 " .@. .@. .@. .@. ",
1137 " .@. .@. .@. .@. ",
1138 " .@. .@. .@. .@. ",
1139 " .@. .@........@......@. ",
1140 " .@. .@@@@@@@@@.@.@@@@@@. ",
1141 " .@. .@@+........@....@@.. ",
1142 " .@...@. .@...@... ",
1144 " .@@@.............@@@.. ",
1145 " .@@@@@@@@@@@@@@@@@... ",
1146 " ................... ",
1151 fOrthoIcon =
new QPixmap(ortho);
1153 const char *
const commandIcon[]={
1181 "66666666666666666666",
1182 "66%++++++++++++++&56",
1183 "6$ o..o......o..o *6",
1184 "6+o...o*<441;@.o..+6",
1185 "6+..o@1553<354$..o+6",
1186 "6+..o<5<@ .*54#o.+6",
1195 "6+..O25<@ X=54#o.+6",
1196 "6+.o.@1553<354$...@6",
1197 "6+o..oo*<44<;@o..o+6",
1198 "6$ .o..o.....o..o *6",
1199 "66%+++++OOOO+++++*66",
1200 "66666666666666666666"
1202 fCommandIcon =
new QPixmap(commandIcon);
1204 const char *
const dirIcon[]={
1232 "66666666666666666666",
1233 "66$oOOOOOOOOOOOOo%66",
1236 "6o =635533666$ o6",
1237 "6o -65:+ +165X o6",
1246 "6o -65:+ @265X o6",
1247 "6o =635543665# O6",
1250 "66$OOOoo....OOOOo%66",
1251 "66666666666666666666"}
1253 fDirIcon =
new QPixmap(dirIcon);
1256 const char *
const runIcon[]={
1293 "rrrrrrrr%<<2rrrrrrrr",
1294 "rrrrr5=$$$$===rrrrrr",
1295 "rrrr<##$$$$$---&rrrr",
1296 "rrr=###$$$$-----%rrr",
1297 "rr=####$$$$------&rr",
1298 "r2@####7##$-------rr",
1299 "r.@####048$-------Or",
1300 "r.@####q4ee=----$@.r",
1301 " .@@###w4eee5%$#@@@X",
1302 " .@@@..w4eeeeqo..@@X",
1303 " .@..ooe<eeee7Oooo@X",
1304 " ..oooOe2eee6OOOooo ",
1305 "rOooOO+e2ew2+++++O+r",
1306 "r:oO+++e30,;;;;;++Or",
1307 "r :++;:9,>,,>>:;;1rr",
1308 "rr*1;:>,333333,>32rr",
1309 "rrr66,1367777637<rrr",
1310 "rrrr509799999905rrrr",
1311 "rrrrr=8wqwwww8-rrrrr",
1312 "rrrrrrrr4444rrrrrrrr"
1314 fRunIcon =
new QPixmap(runIcon);
1316 const char *
const paramIcon[]={
1355 "wwwwwwww5 5wwwwwwww",
1356 "wwwwwwww, ,wwwwwwww",
1357 "www&;ww7+ +9ww=-www",
1363 "5<+ .wwwwwww0. +<5",
1366 "5<+ .wwwwwww0X +<5",
1372 "www*>ww7+ +7ww=:www",
1373 "wwwwwwww1 1wwwwwwww",
1374 "wwwwwwww5 5wwwwwwww"
1376 fParamIcon =
new QPixmap(paramIcon);
1383 QWidget* G4UIQt::CreateHistoryTBWidget(
1386 fHistoryTBWidget =
new QWidget();
1388 QVBoxLayout *layoutHistoryTB =
new QVBoxLayout();
1389 fHistoryTBTableList =
new QListWidget();
1390 fHistoryTBTableList->setSelectionMode(QAbstractItemView::SingleSelection);
1391 connect(fHistoryTBTableList, SIGNAL(itemSelectionChanged()), SLOT(CommandHistoryCallback()));
1393 layoutHistoryTB->addWidget(fHistoryTBTableList);
1395 fHistoryTBWidget->setLayout(layoutHistoryTB);
1396 return fHistoryTBWidget;
1402 QWidget* G4UIQt::CreateHelpTBWidget(
1405 fHelpTBWidget =
new QWidget();
1407 QWidget *helpWidget =
new QWidget();
1408 QHBoxLayout *helpLayout =
new QHBoxLayout();
1409 QVBoxLayout *vLayout =
new QVBoxLayout();
1410 fHelpVSplitter =
new QSplitter(Qt::Vertical);
1411 fHelpLine =
new QLineEdit();
1412 helpLayout->addWidget(
new QLabel(
"Search :"));
1413 helpLayout->addWidget(fHelpLine);
1414 connect( fHelpLine, SIGNAL( editingFinished () ),
this, SLOT( LookForHelpStringCallback() ) );
1419 fParameterHelpLabel =
new QTextEdit();
1420 fParameterHelpLabel->setReadOnly(
true);
1421 fParameterHelpTable =
new QTableWidget();
1425 if (fHelpTreeWidget) {
1426 fHelpVSplitter->addWidget(fHelpTreeWidget);
1428 fHelpVSplitter->addWidget(fParameterHelpLabel);
1429 fHelpVSplitter->addWidget(fParameterHelpTable);
1431 fParameterHelpLabel->setVisible(
false);
1432 fParameterHelpTable->setVisible(
false);
1433 QSizePolicy policy = QSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum);
1434 policy.setVerticalStretch(4);
1435 if (fHelpTreeWidget) {
1436 fHelpTreeWidget->setSizePolicy(policy);
1438 policy = QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Preferred);
1439 policy.setVerticalStretch(1);
1440 fParameterHelpLabel->setSizePolicy(policy);
1441 fParameterHelpTable->setSizePolicy(policy);
1443 vLayout->addWidget(helpWidget);
1444 vLayout->addWidget(fHelpVSplitter,1);
1445 vLayout->setContentsMargins(5,5,5,5);
1447 helpWidget->setLayout(helpLayout);
1448 fHelpTBWidget->setLayout(vLayout);
1450 return fHelpTBWidget;
1456 G4UIDockWidget* G4UIQt::CreateCoutTBWidget(
1459 QWidget* coutTBWidget =
new QWidget();
1461 QVBoxLayout *layoutCoutTB =
new QVBoxLayout();
1463 fCoutTBTextArea =
new QTextEdit();
1465 fCoutFilter =
new QLineEdit();
1466 fCoutFilter->setToolTip(
"Filter output by...");
1468 #if QT_VERSION > 0x050100
1469 fCoutFilter->addAction(*fSearchIcon,QLineEdit::TrailingPosition);
1470 fCoutFilter->setStyleSheet (
"border-radius:7px;");
1472 QPushButton *coutTBFilterButton =
new QPushButton();
1473 coutTBFilterButton->setIcon(QIcon(*fSearchIcon));
1474 coutTBFilterButton->setStyleSheet (
"padding-left: 0px; border:0px;");
1475 fCoutFilter->setStyleSheet (
"padding-right: 0px;");
1478 QPushButton *coutTBClearButton =
new QPushButton();
1479 coutTBClearButton->setIcon(*fClearIcon);
1480 coutTBClearButton->setToolTip(
"Clear console output");
1481 coutTBClearButton->setStyleSheet (
"border-radius:7px;");
1482 connect(coutTBClearButton, SIGNAL(clicked()), SLOT(ClearButtonCallback()));
1483 connect(fCoutFilter, SIGNAL(textEdited (
const QString &)), SLOT(CoutFilterCallback(
const QString &)));
1485 QPushButton *coutTBSaveOutputButton =
new QPushButton();
1486 coutTBSaveOutputButton->setIcon(*fSaveIcon);
1487 coutTBSaveOutputButton->setToolTip(
"Save console output");
1488 coutTBSaveOutputButton->setStyleSheet (
"border-radius:7px;");
1489 connect(coutTBSaveOutputButton, SIGNAL(clicked()), SLOT(SaveOutputCallback()));
1491 fCoutTBTextArea->setReadOnly(
true);
1493 QWidget* coutButtonWidget =
new QWidget();
1494 QHBoxLayout* layoutCoutTBButtons =
new QHBoxLayout();
1496 #ifdef G4MULTITHREADED
1498 fThreadsFilterComboBox =
new QComboBox();
1499 fThreadsFilterComboBox->setInsertPolicy(QComboBox::InsertAlphabetically);
1500 connect(fThreadsFilterComboBox, SIGNAL(activated(
int)),
this, SLOT(ThreadComboBoxCallback(
int)));
1502 UpdateCoutThreadFilter();
1504 fThreadsFilterComboBox->setToolTip(
"Thread selection in output");
1505 layoutCoutTBButtons->addWidget(
new QLabel(
" Threads:"));
1506 layoutCoutTBButtons->addWidget(fThreadsFilterComboBox);
1509 layoutCoutTBButtons->addWidget(fCoutFilter);
1510 #if QT_VERSION <= 0x050100
1511 layoutCoutTBButtons->addWidget(coutTBFilterButton);
1513 layoutCoutTBButtons->addWidget(coutTBClearButton);
1514 layoutCoutTBButtons->addWidget(coutTBSaveOutputButton);
1515 coutButtonWidget->setLayout(layoutCoutTBButtons);
1518 layoutCoutTBButtons->setContentsMargins(3,3,3,0);
1520 layoutCoutTB->addWidget(coutButtonWidget);
1521 layoutCoutTB->addWidget(fCoutTBTextArea);
1523 coutTBWidget->setLayout(layoutCoutTB);
1525 fCoutTBTextArea->setMinimumSize(100,100);
1528 QWidget* commandLineWidget =
new QWidget();
1529 QHBoxLayout *layoutCommandLine =
new QHBoxLayout();
1533 fCommandLabel =
new QLabel(
"");
1534 fCommandArea =
new QLineEdit();
1538 fCommandArea->activateWindow();
1540 fCommandArea->setFocusPolicy ( Qt::StrongFocus );
1541 fCommandArea->setFocus(Qt::TabFocusReason);
1542 fCommandArea->setToolTip(
"Apply command");
1545 layoutCommandLine->addWidget(fCommandLabel);
1546 layoutCommandLine->addWidget(fCommandArea);
1549 connect(fCommandArea, SIGNAL(returnPressed()), SLOT(CommandEnteredCallback()));
1550 connect(fCommandArea, SIGNAL(textEdited(
const QString &)), SLOT(CommandEditedCallback(
const QString &)));
1553 commandLineWidget->setLayout(layoutCommandLine);
1554 commandLineWidget->setMinimumSize(50,50);
1556 layoutCoutTB->addWidget(commandLineWidget);
1558 fCoutDockWidget =
new G4UIDockWidget (
"Output");
1559 fCoutDockWidget->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
1561 fCoutDockWidget->setWidget(coutTBWidget);
1562 return fCoutDockWidget;
1568 QWidget* G4UIQt::CreateVisParametersTBWidget(
1577 G4UIDockWidget* G4UIQt::CreateUITabWidget(
1580 fUITabWidget =
new QTabWidget();
1583 fUITabWidget->addTab(CreateSceneTreeWidget(),
"Scene tree");
1584 fUITabWidget->addTab(CreateHelpTBWidget(),
"Help");
1585 fUITabWidget->addTab(CreateHistoryTBWidget(),
"History");
1586 fUITabWidget->setCurrentWidget(fHelpTBWidget);
1588 fUITabWidget->setTabToolTip (0,
"Scene component tree. Only available in Stored mode");
1589 fUITabWidget->setTabToolTip (1,
"Help widget");
1590 fUITabWidget->setTabToolTip (2,
"All commands history");
1591 connect(fUITabWidget, SIGNAL(currentChanged(
int)), SLOT(ToolBoxActivated(
int)));
1593 fUIDockWidget =
new G4UIDockWidget (
"Scene tree, Help, History");
1594 fUIDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1596 fUIDockWidget->setWidget(fUITabWidget);
1598 return fUIDockWidget;
1602 QWidget* G4UIQt::CreateSceneTreeWidget(){
1604 fSceneTreeWidget =
new QWidget();
1605 QVBoxLayout* layout =
new QVBoxLayout();
1606 fSceneTreeWidget->setLayout(layout);
1608 #if QT_VERSION < 0x040200
1609 fSceneTreeWidget->hide();
1611 fSceneTreeWidget->setVisible(
false);
1614 return fSceneTreeWidget;
1618 void G4UIQt::CreateViewerWidget(){
1622 SetStartPage(std::string(
"<table width='100%'><tr><td width='30%'></td><td><div ")+
1623 "style='color: rgb(140, 31, 31); font-size: xx-large; font-family: Garamond, serif; padding-bottom: 0px; font-weight: normal'>Geant4: "+
1624 QApplication::applicationName ().toStdString()+
1625 "</div></td><td width='40%'> <br/><i>http://cern.ch/geant4/</i></td></tr></table>"+
1627 "<div style='background:#EEEEEE;'><b>Tooltips :</b><ul>"+
1628 "<li><b>Start a new viewer :</b><br />"+
1629 "<i>'/vis/open/...'<br />"+
1630 "For example '/vis/open OGL'</i></li>"+
1631 "<li><b>Execute a macro file :</b><br />"+
1632 "<i>'/control/execute my_macro_file'</i></li>"+
1635 "<div style='background:#EEEEEE;'><b>Documentation :</b><ul>"+
1636 "<li><b>Visualisation publication :</b><br />"+
1637 "<i><a href='http://www.worldscientific.com/doi/abs/10.1142/S1793962313400011'>The Geant4 Visualization System - A Multi-Driver Graphics System</b><br />, Allison, J. et al., International Journal of Modeling, Simulation, and Scientific Computing, Vol. 4, Suppl. 1 (2013) 1340001</a>:<br/> http://www.worldscientific.com/doi/abs/10.1142/S1793962313400011</i></li>"+
1640 "<div style='background:#EEEEEE;'><b>Getting Help :</b><ul>"+
1641 "<li><b>If problems arise, try <a href='https://cern.ch/geant4-forum'>browsing the user forum</a> to see whether or not your problem has already been encountered.<br /> If it hasn't, you can post it and Geant4 developers will do their best to find a solution. This is also a good place to<br /> discuss Geant4 topics in general.</b> https://cern.ch/geant4-forum"+
1642 "<li><b>Get a look at <a href='http://cern.ch/geant4/support'>Geant4 User support pages</a>: <i>http://cern.ch/geant4/support</i></b></li>"+
1648 if (fViewerTabWidget == NULL) {
1649 fViewerTabWidget =
new G4QTabWidget();
1650 fMainWindow->setCentralWidget(fViewerTabWidget);
1651 #if QT_VERSION < 0x040500
1653 fViewerTabWidget->setTabsClosable (
true);
1656 #if QT_VERSION < 0x040200
1658 fViewerTabWidget->setUsesScrollButtons (
true);
1661 #if QT_VERSION < 0x040500
1663 connect(fViewerTabWidget, SIGNAL(tabCloseRequested(
int)),
this, SLOT(TabCloseCallback(
int)));
1665 connect(fViewerTabWidget, SIGNAL(currentChanged (
int ) ), SLOT(UpdateTabWidget(
int)));
1669 QSizePolicy policy = QSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
1670 policy.setVerticalStretch(4);
1671 fViewerTabWidget->setSizePolicy(policy);
1673 fViewerTabWidget->setMinimumSize(40,40);
1679 QWidget* G4UIQt::GetSceneTreeWidget(
1682 return fSceneTreeWidget;
1687 QWidget* G4UIQt::GetViewerPropertiesWidget(
1690 if (!fViewerPropertiesDialog) {
1691 CreateViewerPropertiesDialog();
1693 return fViewerPropertiesWidget;
1698 QWidget* G4UIQt::GetPickInfosWidget(
1701 if (!fPickInfosDialog) {
1702 CreatePickInfosDialog();
1704 return fPickInfosWidget;
1710 bool G4UIQt::AddViewerTab(
1715 if (fViewerTabWidget == NULL) {
1718 fViewerTabWidget->addTab(aWidget,title.c_str());
1726 bool G4UIQt::AddViewerTabFromFile(
1727 std::string fileName
1731 if (fViewerTabWidget == NULL) {
1736 if(UI==NULL)
return 0;
1740 std::string content( (std::istreambuf_iterator<char>(
file) ),
1741 (std::istreambuf_iterator<char>() ) );
1743 QTextEdit* text =
new QTextEdit();
1744 text->setAcceptRichText (
true);
1745 text->setContentsMargins(5,5,5,5);
1746 text->setText(QString(
"<pre>")+content.c_str()+
"</pre>");
1747 text->setReadOnly(
true);
1748 fViewerTabWidget->addTab(text,title.c_str());
1759 bool G4UIQt::AddTabWidget(
1770 #if QT_VERSION < 0x050100
1771 #if QT_VERSION >= 0x050000
1773 "This Qt version [")+qVersion ()+
"] has some issues with the OpenGL viewer.\n"+
1774 "To prevent problems, you are not allowed to open a Stored nor Immediate viewer.\n" +
1776 "Please upgrade to Qt version >= 5.1\n";
1778 QMessageBox::warning(fMainWindow, tr(
"Warning"),
1779 tr(message.toStdString().c_str()),
1786 if (fViewerTabWidget == NULL) {
1787 CreateViewerWidget();
1794 aWidget->setParent(fViewerTabWidget);
1797 fViewerTabWidget->addTab(aWidget,name);
1799 fViewerTabWidget->setCurrentIndex(fViewerTabWidget->count()-1);
1802 #if QT_VERSION < 0x040200
1803 fViewerTabWidget->setLastTabCreated(fViewerTabWidget->currentIndex());
1805 fViewerTabWidget->setLastTabCreated(fViewerTabWidget->currentIndex());
1816 void G4UIQt::SetStartPage(
1817 const std::string& text)
1820 fDefaultViewerFirstPageHTMLText = text;
1823 fStartPage =
new QTextEdit();
1824 fStartPage->setAcceptRichText (
true);
1825 fStartPage->setContentsMargins(5,5,5,5);
1826 fStartPage->setReadOnly(
true);
1828 fStartPage->setText(fDefaultViewerFirstPageHTMLText.c_str());
1832 void G4UIQt::UpdateTabWidget(
int tabNumber) {
1833 if ( fViewerTabWidget == NULL) {
1834 fViewerTabWidget =
new G4QTabWidget;
1837 fViewerTabWidget->setCurrentIndex(tabNumber);
1840 fViewerTabWidget->setTabSelected(
false);
1842 #if QT_VERSION < 0x040200
1843 fViewerTabWidget->show();
1845 fViewerTabWidget->setVisible(
true);
1849 fViewerTabWidget->setTabSelected(
true);
1855 void G4UIQt::ResizeTabWidget( QResizeEvent*
e) {
1856 if ( fViewerTabWidget) {
1857 for (
G4int a=0;
a<fViewerTabWidget->count() ;
a++) {
1858 fViewerTabWidget->widget(
a)->resize(e->size());
1869 G4Qt* interactorManager = G4Qt::getInstance ();
1870 Prompt(
"Session :");
1871 exitSession =
false;
1873 QCoreApplication::sendPostedEvents () ;
1875 #if QT_VERSION < 0x040200
1876 fMainWindow->show();
1878 fMainWindow->setVisible(
true);
1881 if (fDefaultIcons) {
1882 #if QT_VERSION < 0x040200
1883 fToolbarApp->show();
1885 fToolbarApp->setVisible(
true);
1889 #if QT_VERSION < 0x040200
1890 fToolbarApp->hide();
1892 fToolbarApp->setVisible(
false);
1899 UpdateCommandCompleter();
1902 fHistoryTBTableList->installEventFilter(
this);
1903 fCommandArea->installEventFilter(
this);
1906 fCommandArea->setFocus();
1908 interactorManager->DisableSecondaryLoop ();
1909 if ((QApplication*)interactorManager->GetMainInteractor())
1910 ((QApplication*)interactorManager->GetMainInteractor())->exec();
1912 interactorManager->EnableSecondaryLoop ();
1920 void G4UIQt::Prompt (
1924 if (!aPrompt)
return;
1926 fCommandLabel->setText((
char*)aPrompt.
data());
1931 void G4UIQt::SessionTerminate (
1934 G4Qt* interactorManager = G4Qt::getInstance ();
1935 fMainWindow->close();
1936 ((QApplication*)interactorManager->GetMainInteractor())->
exit();
1949 void G4UIQt::PauseSessionStart (
1953 if (!aState)
return;
1955 if(aState==
"G4_pause> ") {
1956 SecondaryLoop (
"Pause, type continue to exit this state");
1959 if(aState==
"EndOfEvent") {
1961 SecondaryLoop (
"End of event, type continue to exit this state");
1971 void G4UIQt::SecondaryLoop (
1975 if (!aPrompt)
return;
1977 G4Qt* interactorManager = G4Qt::getInstance ();
1981 ((QApplication*)interactorManager)->processEvents(QEventLoop::WaitForMoreEvents);
1982 if(exitPause==
true)
break;
1984 Prompt(
"Session :");
1987 #ifdef G4MULTITHREADED
2001 G4int G4UIQt::ReceiveG4cout (
2005 if (!aString)
return 0;
2007 #ifdef G4MULTITHREADED
2013 if (aString.
contains(
"*** This is just a warning message. ***")) {
2014 return ReceiveG4cerr(aString);
2020 G4UIOutputString txt = G4UIOutputString(QString((
char*)aString.
data()).trimmed(),GetThreadPrefix());
2021 fG4OutputString.push_back(txt);
2023 #ifdef G4MULTITHREADED
2024 QString result = FilterOutput(txt,fThreadsFilterComboBox->currentText(),fCoutFilter->text());
2026 QString result = FilterOutput(txt,
"",fCoutFilter->text());
2029 if (result.isEmpty()) {
2032 QColor previousColor = fCoutTBTextArea->textColor();
2033 fCoutTBTextArea->setTextColor(Qt::black);
2034 fCoutTBTextArea->append(result);
2035 fCoutTBTextArea->setTextColor(previousColor);
2036 fCoutTBTextArea->ensureCursorVisible ();
2038 #ifdef G4MULTITHREADED
2039 UpdateCoutThreadFilter();
2043 fLastErrMessage = aString;
2053 G4int G4UIQt::ReceiveG4cerr (
2057 if (!aString)
return 0;
2059 #ifdef G4MULTITHREADED
2066 G4UIOutputString txt = G4UIOutputString(QString((
char*)aString.
data()).trimmed(),
2069 fG4OutputString.push_back(txt);
2071 #ifdef G4MULTITHREADED
2072 QString result = FilterOutput(txt,fThreadsFilterComboBox->currentText(),fCoutFilter->text());
2074 QString result = FilterOutput(txt,
"",fCoutFilter->text());
2076 if (result.isEmpty()) {
2081 if (QString(aString.
data()).trimmed() !=
"") {
2085 fLastErrMessage +=
"\n"+aString;
2086 QString criticalMessage = fLastErrMessage.
data();
2087 #if QT_VERSION < 0x050000
2088 criticalMessage = Qt::escape(criticalMessage);
2090 criticalMessage = criticalMessage.toHtmlEscaped();
2092 QMessageBox::critical(fMainWindow,
"Error",QString(fLastErrMessage));
2095 QColor previousColor = fCoutTBTextArea->textColor();
2096 fCoutTBTextArea->setTextColor(Qt::red);
2097 fCoutTBTextArea->append(result);
2098 fCoutTBTextArea->setTextColor(previousColor);
2099 fCoutTBTextArea->ensureCursorVisible ();
2101 if (QString(aString.
data()).trimmed() !=
"") {
2102 fLastErrMessage += aString;
2104 #ifdef G4MULTITHREADED
2105 UpdateCoutThreadFilter();
2111 G4String G4UIQt::GetThreadPrefix() {
2113 #ifdef G4MULTITHREADED
2115 if(UI==NULL)
return "";
2123 return threadPrefix;
2127 #ifdef G4MULTITHREADED
2128 void G4UIQt::UpdateCoutThreadFilter() {
2130 if(UI==NULL)
return;
2133 if (fThreadsFilterComboBox->count() < 2) {
2134 if ( fThreadsFilterComboBox->findText(
"All", Qt::MatchExactly) == -1) {
2135 fThreadsFilterComboBox->addItem(
"All");
2138 if (fThreadsFilterComboBox->count() < 2) {
2139 if ( fThreadsFilterComboBox->findText(
"Master", Qt::MatchExactly) == -1) {
2140 fThreadsFilterComboBox->addItem(
"Master");
2146 if ( fThreadsFilterComboBox->findText(prefix.
data(), Qt::MatchExactly) == -1) {
2147 fThreadsFilterComboBox->addItem(prefix.
data());
2159 void G4UIQt::AddMenu (
2164 if (aName == NULL)
return;
2165 if (aLabel == NULL)
return;
2167 QMenu *fileMenu =
new QMenu(aLabel);
2168 fMainWindow->menuBar()->addMenu(fileMenu);
2180 void G4UIQt::AddButton (
2183 ,
const char* aCommand
2186 if(aMenu==NULL)
return;
2187 if(aLabel==NULL)
return;
2188 if(aCommand==NULL)
return;
2190 QMenu *parentTmp = (QMenu*)GetInteractor(aMenu);
2192 if(parentTmp==NULL) {
2197 G4cout <<
"Menu name " << aMenu<<
" does not exist, please define it before using it."<<
G4endl;
2204 if(UI==NULL)
return;
2208 G4int cmdEndPos = cmd.find_first_of(
" \t");
2209 if(cmdEndPos!=
G4int(std::string::npos)) {
2210 cmd.erase(cmdEndPos);
2213 if(treeTop->
FindPath(cmd) == NULL) {
2215 cmd(0,3) !=
"ls " &&
2218 cmd(0,3) !=
"cd " &&
2220 cmd(0,5) !=
"help " &&
2232 G4cout <<
"Warning: command '"<< cmd <<
"' does not exist, please define it before using it."<<
G4endl;
2237 #if QT_VERSION < 0x050600
2238 QSignalMapper *signalMapper =
new QSignalMapper(
this);
2239 QAction *action = parentTmp->addAction(aLabel, signalMapper, SLOT(map()));
2241 connect(signalMapper, SIGNAL(mapped(
const QString &)),
this, SLOT(ButtonCallback(
const QString&)));
2242 signalMapper->setMapping(action, QString(aCommand));
2244 QString cmd_tmp = QString(aCommand);
2245 parentTmp->addAction(aLabel,
this, [=](){ this->ButtonCallback(cmd_tmp); });
2255 void G4UIQt::AddIcon(
const char* aLabel,
const char* aIconFile,
const char* aCommand,
const char* aFileName){
2256 if(aLabel==NULL)
return;
2258 if (aCommand==NULL) {
2259 if (std::string(aIconFile) ==
"user_icon") {
2264 bool userToolBar =
false;
2266 if (!fDefaultIcons) {
2269 if (std::string(aIconFile) ==
"user_icon") {
2273 if (pix->isNull()) {
2277 G4cout <<
"Warning: file '"<< aFileName <<
"' is incorrect or does not exist, this command will not be build"<<
G4endl;
2281 }
else if (std::string(aIconFile) ==
"open") {
2283 }
else if (std::string(aIconFile) ==
"save") {
2285 }
else if (std::string(aIconFile) ==
"move") {
2287 }
else if (std::string(aIconFile) ==
"rotate") {
2289 }
else if (std::string(aIconFile) ==
"pick") {
2291 }
else if (std::string(aIconFile) ==
"zoom_in") {
2293 }
else if (std::string(aIconFile) ==
"zoom_out") {
2295 }
else if (std::string(aIconFile) ==
"wireframe") {
2296 pix = fWireframeIcon;
2297 }
else if (std::string(aIconFile) ==
"solid") {
2299 }
else if (std::string(aIconFile) ==
"hidden_line_removal") {
2300 pix = fHiddenLineRemovalIcon;
2301 }
else if (std::string(aIconFile) ==
"hidden_line_and_surface_removal") {
2302 pix = fHiddenLineAndSurfaceRemovalIcon;
2303 }
else if (std::string(aIconFile) ==
"perspective") {
2304 pix = fPerspectiveIcon;
2305 }
else if (std::string(aIconFile) ==
"ortho") {
2307 }
else if (std::string(aIconFile) ==
"runBeamOn") {
2314 G4cout <<
"Parameter"<< aIconFile <<
" not defined"<<
G4endl;
2318 QToolBar *currentToolbar = NULL;
2320 if (fToolbarUser == NULL) {
2321 fToolbarUser =
new QToolBar();
2322 fToolbarUser->setIconSize (QSize(20,20));
2323 fMainWindow->addToolBar(Qt::TopToolBarArea, fToolbarUser);
2325 currentToolbar = fToolbarUser;
2327 if (fToolbarApp == NULL) {
2328 fToolbarApp =
new QToolBar();
2329 fToolbarApp->setIconSize (QSize(20,20));
2330 fMainWindow->addToolBar(Qt::TopToolBarArea, fToolbarApp);
2332 currentToolbar = fToolbarApp;
2337 QList<QAction*> list = currentToolbar->actions();
2339 for (
int i = 0; i < list.size(); ++i) {
2340 if (list.at(i)->text() == QString(aLabel)) {
2342 if(UI==NULL)
return;
2345 G4cout <<
"Warning: A toolBar icon \""<< aLabel<<
"\" already exists with the same name!" <<
G4endl;
2350 #if QT_VERSION < 0x050600
2351 QSignalMapper *signalMapper =
new QSignalMapper(
this);
2352 QAction *action = currentToolbar->addAction(QIcon(*pix),aLabel, signalMapper, SLOT(map()));
2355 if (std::string(aIconFile) ==
"open") {
2356 QString txt = aCommand + fStringSeparator + aLabel;
2357 #if QT_VERSION < 0x050600
2358 connect(signalMapper, SIGNAL(mapped(
const QString &)),
this, SLOT(OpenIconCallback(
const QString &)));
2359 signalMapper->setMapping(action, QString(txt));
2361 currentToolbar->addAction(QIcon(*pix), aIconFile,
this, [=](){ this->OpenIconCallback(txt); });
2365 }
else if (std::string(aIconFile) ==
"save") {
2366 QString txt = aCommand + fStringSeparator + aLabel;
2367 #if QT_VERSION < 0x050600
2368 connect(signalMapper, SIGNAL(mapped(
const QString &)),
this, SLOT(SaveIconCallback(
const QString&)));
2369 signalMapper->setMapping(action, QString(txt));
2371 currentToolbar->addAction(QIcon(*pix), aIconFile,
this, [=](){ this->SaveIconCallback(txt); });
2375 }
else if ((std::string(aIconFile) ==
"move") ||
2376 (std::string(aIconFile) ==
"rotate") ||
2377 (std::string(aIconFile) ==
"pick") ||
2378 (std::string(aIconFile) ==
"zoom_out") ||
2379 (std::string(aIconFile) ==
"zoom_in")) {
2380 #if QT_VERSION < 0x050600
2381 connect(signalMapper, SIGNAL(mapped(
const QString &)),
this, SLOT(ChangeCursorAction(
const QString&)));
2382 signalMapper->setMapping(action, QString(aIconFile));
2384 QString txt = QString(aIconFile);
2385 QAction* action = currentToolbar->addAction(QIcon(*pix), aIconFile,
this, [=](){ this->ChangeCursorAction(txt); });
2387 action->setCheckable(
TRUE);
2388 action->setChecked(
TRUE);
2389 action->setData(aIconFile);
2391 if (std::string(aIconFile) ==
"move") {
2392 SetIconMoveSelected();
2394 if (std::string(aIconFile) ==
"rotate") {
2395 SetIconRotateSelected();
2397 if (std::string(aIconFile) ==
"pick") {
2398 SetIconPickSelected();
2400 if (std::string(aIconFile) ==
"zoom_in") {
2401 SetIconZoomInSelected();
2403 if (std::string(aIconFile) ==
"zoom_out") {
2404 SetIconZoomOutSelected();
2408 }
else if ((std::string(aIconFile) ==
"hidden_line_removal") ||
2409 (std::string(aIconFile) ==
"hidden_line_and_surface_removal") ||
2410 (std::string(aIconFile) ==
"solid") ||
2411 (std::string(aIconFile) ==
"wireframe")) {
2412 #if QT_VERSION < 0x050600
2413 connect(signalMapper, SIGNAL(mapped(
const QString &)),
this, SLOT(ChangeSurfaceStyle(
const QString&)));
2414 signalMapper->setMapping(action, QString(aIconFile));
2416 QString txt = QString(aIconFile);
2417 QAction* action = currentToolbar->addAction(QIcon(*pix), aIconFile,
this, [=](){ this->ChangeSurfaceStyle(txt); });
2419 action->setCheckable(
TRUE);
2420 action->setChecked(
TRUE);
2421 action->setData(aIconFile);
2423 if (std::string(aIconFile) ==
"hidden_line_removal") {
2424 SetIconHLRSelected();
2426 if (std::string(aIconFile) ==
"hidden_line_and_surface_removal") {
2427 SetIconHLHSRSelected();
2429 if (std::string(aIconFile) ==
"solid") {
2430 SetIconSolidSelected();
2432 if (std::string(aIconFile) ==
"wireframe") {
2433 SetIconWireframeSelected();
2437 }
else if ((std::string(aIconFile) ==
"perspective") ||
2438 (std::string(aIconFile) ==
"ortho")) {
2439 #if QT_VERSION < 0x050600
2440 connect(signalMapper, SIGNAL(mapped(
const QString &)),
this, SLOT(ChangePerspectiveOrtho(
const QString&)));
2441 signalMapper->setMapping(action, QString(aIconFile));
2443 QString txt = QString(aIconFile);
2444 QAction* action = currentToolbar->addAction(QIcon(*pix), aIconFile,
this, [=](){ this->ChangePerspectiveOrtho(txt); });
2446 action->setCheckable(
TRUE);
2447 action->setChecked(
TRUE);
2448 action->setData(aIconFile);
2450 if (std::string(aIconFile) ==
"perspective") {
2451 SetIconPerspectiveSelected();
2453 if (std::string(aIconFile) ==
"ortho") {
2454 SetIconOrthoSelected();
2461 if(UI==NULL)
return;
2463 if (aCommand != NULL) {
2464 std::string str = aCommand;
2465 std::string::size_type
pos = str.find(
" ");
2466 if (pos != std::string::npos)
2468 str = str.substr(0,pos).c_str();
2470 if(treeTop->
FindPath(str.c_str()) == NULL) {
2475 G4cout <<
"Warning: command '"<< aCommand <<
"' does not exist, please define it before using it."<<
G4endl;
2480 #if QT_VERSION < 0x050600
2481 connect(signalMapper, SIGNAL(mapped(
const QString &)),
this, SLOT(ButtonCallback(
const QString&)));
2482 signalMapper->setMapping(action, QString(aCommand));
2484 QString txt = QString(aCommand);
2485 currentToolbar->addAction(QIcon(*pix), aCommand,
this, [=](){ this->ButtonCallback(txt); });
2492 void G4UIQt::ActivateCommand(
2496 if (!fHelpTreeWidget) {
2500 size_t i = newCommand.
index(
" ");
2502 if( i != std::string::npos )
2504 G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
2506 targetCom = ModifyToFullPathCommand( newValue );
2508 if (targetCom !=
"") {
2509 OpenHelpTreeOnCommand(targetCom.
data());
2512 fUITabWidget->setCurrentWidget(fHelpTBWidget);
2523 void G4UIQt::InitHelpTreeAndVisParametersWidget()
2526 if (! fHelpTreeWidget ) {
2527 fHelpTreeWidget =
new QTreeWidget();
2531 fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
2533 labels << QString(
"Command");
2534 fHelpTreeWidget->setHeaderLabels(labels);
2537 connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),
this, SLOT(HelpTreeClicCallback()));
2538 connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,
int)),
this, SLOT(HelpTreeDoubleClicCallback()));
2547 void G4UIQt::FillHelpTree()
2549 if (! fHelpTreeWidget ) {
2550 InitHelpTreeAndVisParametersWidget();
2553 QString searchText = fHelpLine->text();
2555 if (searchText ==
"") {
2562 if (fParameterHelpLabel) {
2563 fParameterHelpLabel->setText(
"Choose a command in the command tree");
2564 fParameterHelpTable->setVisible(
false);
2568 #if QT_VERSION < 0x040200
2571 fHelpLine->setText(
"");
2576 if(UI==NULL)
return;
2580 QTreeWidgetItem * newItem = NULL;
2581 QString commandText =
"";
2582 for (
int a=0;
a<treeSize;
a++) {
2589 for (
int b=0;
b<fHelpTreeWidget->topLevelItemCount();
b++) {
2591 newItem = FindTreeItem(fHelpTreeWidget->topLevelItem(
b),commandText);
2594 if (newItem == NULL) {
2596 newItem =
new QTreeWidgetItem();
2597 newItem->setText(0,GetShortCommandPath(commandText));
2598 fHelpTreeWidget->addTopLevelItem(newItem);
2602 CreateHelpTree(newItem,treeTop->
GetTree(
a+1));
2613 void G4UIQt::CreateHelpTree(
2614 QTreeWidgetItem *aParent
2618 if (aParent == NULL)
return;
2619 if (aCommandTree == NULL)
return;
2623 QTreeWidgetItem * newItem;
2625 QString commandText =
"";
2632 newItem = FindTreeItem(aParent,commandText);
2633 if (newItem == NULL) {
2634 newItem =
new QTreeWidgetItem();
2635 newItem->setText(0,GetShortCommandPath(commandText));
2636 aParent->addChild(newItem);
2638 CreateHelpTree(newItem,aCommandTree->
GetTree(
a+1));
2645 QStringList stringList;
2649 newItem = FindTreeItem(aParent,commandText);
2650 if (newItem == NULL) {
2651 newItem =
new QTreeWidgetItem();
2652 newItem->setText(0,GetShortCommandPath(commandText));
2653 aParent->addChild(newItem);
2655 #if QT_VERSION < 0x040202
2656 fHelpTreeWidget->setItemExpanded(newItem,
false);
2658 newItem->setExpanded(
false);
2672 bool G4UIQt::CreateVisCommandGroupAndToolBox(
2679 QString commandText = QString((
char*)(aCommand->
GetCommandPath().
data())).section(
"/",-aDepthLevel);
2681 if (commandText == NULL) {
2687 QWidget* newParentWidget = NULL;
2689 QString commandSection = commandText.left(commandText.indexOf(
"/"));
2691 if (aDepthLevel == 1) {
2692 QToolBox* currentParent =
dynamic_cast<QToolBox*
>(aParent);
2693 if (currentParent != 0){
2696 for (
int a=0;
a<currentParent->count();
a++) {
2697 if (currentParent->itemText(
a) == commandSection) {
2699 newParentWidget = currentParent->widget(
a);
2705 newParentWidget =
new QGroupBox();
2706 newParentWidget->setLayout(
new QVBoxLayout());
2707 if (currentParent != 0){
2708 currentParent->addItem(newParentWidget,commandSection);
2710 if (!aParent->layout()) {
2711 aParent->setLayout(
new QVBoxLayout());
2713 aParent->layout()->addWidget(newParentWidget);
2716 if (commandText.indexOf(
"/") == -1) {
2721 for(
G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
2724 newParentWidget->setToolTip(guidance);
2727 QScrollArea*
sc =
dynamic_cast<QScrollArea*
>(newParentWidget->parent()->parent());
2729 sc->ensureWidgetVisible(newParentWidget);
2736 QGroupBox* currentParent =
dynamic_cast<QGroupBox*
>(aParent);
2737 if (currentParent != 0){
2741 if (aDepthLevel == 2){
2742 QToolBox* parentToolBox =
dynamic_cast<QToolBox*
>(currentParent->parent()->parent()->parent());
2743 if (parentToolBox != 0) {
2747 for (
int a=0;
a<aParent->layout()->count();
a++) {
2748 QGroupBox* gb =
dynamic_cast<QGroupBox*
>(aParent->layout()->itemAt(
a)->widget());
2750 if (gb->title() == commandSection) {
2752 newParentWidget = gb;
2760 newParentWidget =
new QGroupBox();
2761 newParentWidget->setLayout(
new QVBoxLayout());
2762 if (!aParent->layout()) {
2763 aParent->setLayout(
new QVBoxLayout());
2765 aParent->layout()->addWidget(newParentWidget);
2771 for(
G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
2774 newParentWidget->setToolTip(guidance);
2779 if (commandText.indexOf(
"/") == -1) {
2780 if (CreateCommandWidget(aCommand, newParentWidget,isDialog)) {
2784 CreateVisCommandGroupAndToolBox(aCommand,newParentWidget, aDepthLevel-1,isDialog);
2797 bool G4UIQt::CreateCommandWidget(
G4UIcommand* aCommand, QWidget* aParent,
bool isDialog) {
2799 if (aCommand == NULL) {
2806 if( n_parameterEntry > 0 ) {
2810 QWidget* paramWidget =
new QWidget();
2811 QGridLayout* gridLayout =
new QGridLayout();
2812 paramWidget->setLayout(gridLayout);
2815 unsigned int nbColorParameter = 0;
2816 bool isStillColorParameter =
false;
2817 bool isColorDialogAdded =
false;
2818 QLabel* redLabel = NULL;
2819 QLabel* greenLabel = NULL;
2820 QString redDefaultStr =
"";
2821 QString greenDefaultStr =
"";
2822 QString blueDefaultStr =
"";
2823 QWidget* redInput = NULL;
2824 QWidget* greenInput = NULL;
2826 for(
G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
2831 if ((label->text() ==
"red") || (label->text() ==
"red_or_string")){
2832 nbColorParameter ++;
2833 isStillColorParameter =
true;
2834 }
else if ((label->text() ==
"green") && isStillColorParameter) {
2835 nbColorParameter ++;
2836 }
else if ((label->text() ==
"blue") && isStillColorParameter) {
2837 nbColorParameter ++;
2838 }
else if (!isColorDialogAdded) {
2841 if (nbColorParameter == 1) {
2842 gridLayout->addWidget(redLabel,i_thParameter-1,0);
2843 gridLayout->addWidget(redInput,i_thParameter-1,1);
2844 }
else if (nbColorParameter == 2) {
2845 gridLayout->addWidget(redLabel,i_thParameter-2,0);
2846 gridLayout->addWidget(redInput,i_thParameter-2,1);
2847 gridLayout->addWidget(greenLabel,i_thParameter-1,0);
2848 gridLayout->addWidget(greenInput,i_thParameter-1,1);
2850 nbColorParameter = 0;
2853 QWidget* input = NULL;
2855 input =
new QLineEdit();
2857 dynamic_cast<QLineEdit*
>(input)->setText(QString((
char*)(param->
GetDefaultValue()).
data()));
2859 if (((label->text() ==
"red") || (label->text() ==
"red_or_string")) && isStillColorParameter) {
2861 }
else if ((label->text() ==
"green") && isStillColorParameter) {
2863 }
else if ((label->text() ==
"green") && isStillColorParameter) {
2868 input =
new QWidget();
2869 QHBoxLayout* layout =
new QHBoxLayout();
2870 input->setLayout(layout);
2872 QButtonGroup* buttons =
new QButtonGroup();
2873 QRadioButton* radioOff =
new QRadioButton(
"0");
2874 QRadioButton* radioOn =
new QRadioButton(
"1");
2875 buttons->addButton(radioOn);
2876 buttons->addButton(radioOff);
2877 layout->addWidget(radioOn);
2878 layout->addWidget(radioOff);
2882 if (defaultValue ==
"0") {
2883 radioOff->setChecked(
true);
2884 }
else if (defaultValue ==
"1") {
2885 radioOn->setChecked(
true);
2888 input =
new QComboBox();
2890 QStringList list = candidates.split (
" ");
2894 for (
int a=0;
a<list.size();
a++) {
2895 dynamic_cast<QComboBox*
>(input)->addItem(list.at(
a));
2896 if (list.at(
a) == defaultValue) {
2897 dynamic_cast<QComboBox*
>(input)->setCurrentIndex(
a);
2902 input =
new QLineEdit();
2904 dynamic_cast<QLineEdit*
>(input)->setText(QString((
char*)(param->
GetDefaultValue()).
data()));
2907 input =
new QWidget();
2908 QHBoxLayout* layout =
new QHBoxLayout();
2909 input->setLayout(layout);
2911 QButtonGroup* buttons =
new QButtonGroup();
2912 QRadioButton* radioOff =
new QRadioButton(
"off");
2913 QRadioButton* radioOn =
new QRadioButton(
"on");
2914 buttons->addButton(radioOn);
2915 buttons->addButton(radioOff);
2916 layout->addWidget(radioOn);
2917 layout->addWidget(radioOff);
2921 if (defaultValue ==
"off") {
2922 radioOff->setChecked(
true);
2923 }
else if (defaultValue ==
"on") {
2924 radioOn->setChecked(
true);
2928 input =
new QLineEdit();
2929 dynamic_cast<QLineEdit*
>(input)->setText(QString((
char*)(param->
GetDefaultValue()).
data()));
2936 txt +=
" Parameter type : " + QString(QChar(param->
GetParameterType())) +
"\n";
2938 txt +=
" Omittable : True\n";
2940 txt +=
" Omittable : False\n";
2943 txt +=
" Default value : taken from the current value\n";
2954 if (isStillColorParameter && (nbColorParameter != 0)) {
2955 if ((label->text() ==
"red") || (label->text() ==
"red_or_string")) {
2958 }
else if (label->text() ==
"green") {
2961 }
else if (label->text() ==
"blue") {
2967 if ((redDefaultStr !=
"") && (redDefaultStr !=
"") && (redDefaultStr !=
"")) {
2968 qc.setRgbF(redDefaultStr.toDouble(),
2969 greenDefaultStr.toDouble(),
2970 blueDefaultStr.toDouble());
2972 QPixmap pixmap = QPixmap(QSize(16, 16));
2974 QPainter painter(&pixmap);
2975 painter.setPen(Qt::black);
2976 painter.drawRect(0,0,15,15);
2978 input =
new QPushButton(
"Change color");
2979 dynamic_cast<QPushButton*
>(input)->setIcon(pixmap);
2980 dynamic_cast<QPushButton*
>(input)->setAccessibleName(redDefaultStr+
" "+greenDefaultStr+
" "+blueDefaultStr);
2981 label =
new QLabel(
"Choose color");
2985 gridLayout->addWidget(label,i_thParameter-nbColorParameter,0);
2986 input->setToolTip(
"Select the current color");
2987 gridLayout->addWidget(input,i_thParameter-nbColorParameter,1);
2990 #if QT_VERSION < 0x050600
2991 QSignalMapper* signalMapper =
new QSignalMapper(
this);
2992 signalMapper->setMapping(input,input);
2993 connect(input, SIGNAL(clicked()), signalMapper, SLOT(map()));
2994 connect(signalMapper, SIGNAL(mapped(QWidget*)),
this, SLOT(ChangeColorCallback(QWidget*)));
2996 connect(dynamic_cast<QPushButton*>(input), &QPushButton::clicked , [=](){ this->ChangeColorCallback(input);});
2998 isColorDialogAdded =
true;
2999 isStillColorParameter =
false;
3002 gridLayout->addWidget(label,i_thParameter-nbColorParameter,0);
3003 input->setToolTip(txt);
3004 gridLayout->addWidget(input,i_thParameter-nbColorParameter,1);
3010 gridLayout->addWidget(name,n_parameterEntry-nbColorParameter,0);
3012 QPushButton* applyButton =
new QPushButton(
"Apply");
3015 gridLayout->addWidget(applyButton,n_parameterEntry-nbColorParameter,1);
3017 #if QT_VERSION < 0x050600
3018 QSignalMapper* signalMapper =
new QSignalMapper(
this);
3019 signalMapper->setMapping(applyButton, paramWidget);
3020 connect(applyButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
3021 connect(signalMapper, SIGNAL(mapped(QWidget*)),
this, SLOT(VisParameterCallback(QWidget*)));
3023 connect(applyButton, &QPushButton::clicked , [=](){ this->VisParameterCallback(paramWidget);});
3028 applyButton->setAutoDefault(
TRUE );
3029 applyButton->setDefault(
TRUE );
3031 QPushButton* cancelButton =
new QPushButton( tr(
"&Cancel" ));
3032 cancelButton->setAutoDefault(
TRUE );
3033 gridLayout->addWidget(cancelButton,n_parameterEntry-nbColorParameter,1);
3034 gridLayout->addWidget(applyButton,n_parameterEntry-nbColorParameter,0);
3036 #if QT_VERSION < 0x050600
3037 QSignalMapper* signalMapper =
new QSignalMapper(
this);
3038 signalMapper->setMapping(applyButton, paramWidget);
3039 connect(applyButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
3040 connect(signalMapper, SIGNAL(mapped(QWidget*)),
this, SLOT(VisParameterCallback(QWidget*)));
3042 connect(applyButton, &QPushButton::clicked , [=](){ this->VisParameterCallback(paramWidget);});
3045 QWidget * parentCheck = aParent;
3046 QDialog* parentDialog = NULL;
3048 while ((parentCheck->parentWidget()) != NULL) {
3049 parentCheck = parentCheck->parentWidget();
3050 parentDialog =
dynamic_cast<QDialog*
>(parentCheck);
3052 connect( applyButton, SIGNAL( clicked() ), parentDialog, SLOT( accept() ) );
3053 connect( cancelButton, SIGNAL( clicked() ), parentDialog, SLOT( reject() ) );
3062 if (!aParent->layout()) {
3063 aParent->setLayout(
new QVBoxLayout());
3065 aParent->layout()->addWidget(paramWidget);
3076 QTreeWidgetItem* G4UIQt::FindTreeItem(
3077 QTreeWidgetItem *aParent
3078 ,
const QString& aCommand
3081 if (aParent == NULL)
return NULL;
3084 QString myCommand = aCommand;
3086 if (myCommand.lastIndexOf(
"/") == (myCommand.size()-1)) {
3087 myCommand = myCommand.left(myCommand.size()-1);
3090 if (GetLongCommandPath(aParent) == myCommand)
3093 QTreeWidgetItem *
tmp = NULL;
3094 for (
int a=0;
a<aParent->childCount();
a++) {
3096 tmp = FindTreeItem(aParent->child(
a),myCommand);
3110 QString G4UIQt::GetCommandList (
3116 if (aCommand == NULL)
3124 if ((commandPath ==
"") &&
3125 (rangeString ==
"") &&
3126 (n_guidanceEntry == 0) &&
3127 (n_parameterEntry == 0)) {
3131 if((commandPath.length()-1)!=
'/') {
3132 txt +=
"Command " + QString((
char*)(commandPath).
data()) +
"\n";
3134 txt +=
"Guidance :\n";
3136 for(
G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
3139 if( ! rangeString.
isNull() ) {
3140 txt +=
" Range of parameters : " + QString((
char*)(rangeString).
data()) +
"\n";
3142 if( n_parameterEntry > 0 ) {
3147 for(
G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
3152 txt +=
" Parameter type : " + QString(QChar(param->
GetParameterType())) +
"\n";
3154 txt +=
" Omittable : True\n";
3156 txt +=
" Omittable : False\n";
3159 txt +=
" Default value : taken from the current value\n";
3182 void G4UIQt::updateHelpArea (
3186 if (!fParameterHelpLabel)
3188 if (!fParameterHelpTable)
3191 fParameterHelpLabel->setTextInteractionFlags(Qt::NoTextInteraction);
3193 if (aCommand == NULL)
3201 if ((commandPath ==
"") &&
3202 (rangeString ==
"") &&
3203 (n_guidanceEntry == 0) &&
3204 (n_parameterEntry == 0)) {
3208 if((commandPath.length()-1)!=
'/') {
3209 txt +=
"<b>Command </b> " + QString((
char*)(commandPath).
data()) +
"<br />";
3211 txt +=
"<b>Guidance :</b> ";
3212 QString tmpGuidance =
"";
3213 for(
G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
3215 #if QT_VERSION < 0x050000
3216 tmpGuidance = Qt::escape(tmpGuidance);
3218 tmpGuidance = tmpGuidance.toHtmlEscaped();
3220 tmpGuidance.replace(
"\n",
"<br />");
3221 txt += tmpGuidance +
"<br />";
3223 if( ! rangeString.
isNull() ) {
3224 QString range = QString((
char*)(rangeString).
data());
3225 #if QT_VERSION < 0x050000
3226 range = Qt::escape(range);
3228 range = range.toHtmlEscaped();
3231 txt +=
"<b>Range of parameters : </b> " + range +
"<br />";
3235 fParameterHelpLabel->setHtml(txt);
3237 if( n_parameterEntry > 0 ) {
3242 fParameterHelpTable->clear();
3243 fParameterHelpTable->setRowCount(n_parameterEntry);
3244 fParameterHelpTable->setColumnCount(8);
3245 fParameterHelpTable->setHorizontalHeaderLabels(QStringList() <<
3254 fParameterHelpTable->setColumnWidth(2,60);
3256 fParameterHelpTable->verticalHeader()->setVisible(
false);
3257 fParameterHelpTable->setAlternatingRowColors (
true);
3258 #if QT_VERSION < 0x050000
3259 fParameterHelpTable->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
3260 fParameterHelpTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
3262 fParameterHelpTable->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
3263 fParameterHelpTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
3265 fParameterHelpTable->setWordWrap(
true);
3267 QTableWidgetItem*
t = fParameterHelpTable->horizontalHeaderItem(1);
3268 QFont fnt = t->font();
3269 int size = fnt.pointSize();
3270 fnt.setPointSize(size-2);
3272 for(
G4int a=0;
a<n_parameterEntry;
a++ ) {
3274 fParameterHelpTable->setItem(
a, 0,
new QTableWidgetItem(QString::number(
a+1)));
3276 fParameterHelpTable->setItem(
a, 1,
new QTableWidgetItem(QString((
char*)(param->
GetParameterName()).
data())));
3280 fParameterHelpTable->setItem(
a, 3,
new QTableWidgetItem(QString(QChar(param->
GetParameterType()))));
3283 fParameterHelpTable->setItem(
a, 4,
new QTableWidgetItem(QString(
"True")));
3285 fParameterHelpTable->setItem(
a, 4,
new QTableWidgetItem(QString(
"False")));
3288 fParameterHelpTable->setItem(
a, 5,
new QTableWidgetItem(QString(
"taken from the current value")));
3290 fParameterHelpTable->setItem(
a, 5,
new QTableWidgetItem(QString((
char*)(param->
GetDefaultValue()).
data())));
3293 fParameterHelpTable->setItem(
a, 6,
new QTableWidgetItem(QString((
char*)(param->
GetParameterRange()).
data())));
3299 for (
int b=0;
b<8;
b++) {
3300 QTableWidgetItem* tmp = fParameterHelpTable->item(
a,
b);
3302 tmp->setToolTip(tmp->text());
3303 tmp->setFlags(Qt::NoItemFlags);
3304 tmp->setForeground(QBrush());
3308 fParameterHelpTable->resizeRowToContents(
a);
3310 for (
int c=0;
c<8;
c++) {
3312 fParameterHelpTable->resizeColumnToContents(
c);
3315 fParameterHelpLabel->setVisible(
true);
3316 fParameterHelpTable->setVisible(
true);
3327 G4bool G4UIQt::IsGUICommand(
3331 if (aCommand == NULL)
3336 if( n_parameterEntry > 0 ) {
3341 for(
G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
3363 G4bool G4UIQt::GetHelpChoice(
3378 bool G4UIQt::eventFilter(
3383 bool tabKeyPress =
false;
3384 bool moveCommandCursor =
false;
3385 if (aObj == NULL)
return false;
3386 if (aEvent == NULL)
return false;
3388 if (aObj == fHistoryTBTableList) {
3389 if (aEvent->type() == QEvent::KeyPress) {
3390 fCommandArea->setFocus();
3394 if (aObj == fCompleter->popup()) {
3395 if (aEvent->type() == QEvent::KeyPress) {
3396 QKeyEvent *e =
static_cast<QKeyEvent*
>(aEvent);
3397 if (e->key() == (Qt::Key_Tab)) {
3400 }
else if ( aEvent->type() == QEvent::Hide ) {
3402 QString
c = fCommandArea->text();
3403 fLastCompleteCommand = c.left(c.indexOf(
"<"));
3407 if (aObj == fCommandArea) {
3408 if (aEvent->type() == QEvent::KeyPress) {
3409 QKeyEvent *e =
static_cast<QKeyEvent*
>(aEvent);
3410 if ((e->key() == (Qt::Key_Down)) ||
3411 (e->key() == (Qt::Key_PageDown)) ||
3412 (e->key() == (Qt::Key_Up)) ||
3413 (e->key() == (Qt::Key_PageUp))) {
3414 int selection = fHistoryTBTableList->currentRow();
3415 if (fHistoryTBTableList->count()) {
3416 if (selection == -1) {
3417 selection = fHistoryTBTableList->count()-1;
3419 if (e->key() == (Qt::Key_Down)) {
3420 if (selection <(fHistoryTBTableList->count()-1))
3422 }
else if (e->key() == (Qt::Key_PageDown)) {
3423 selection = fHistoryTBTableList->count()-1;
3424 }
else if (e->key() == (Qt::Key_Up)) {
3427 }
else if (e->key() == (Qt::Key_PageUp)) {
3431 fHistoryTBTableList->clearSelection();
3432 #if QT_VERSION < 0x040202
3433 fHistoryTBTableList->setItemSelected(fHistoryTBTableList->item(selection),
true);
3435 fHistoryTBTableList->item(selection)->setSelected(
true);
3437 fHistoryTBTableList->setCurrentItem(fHistoryTBTableList->item(selection));
3439 moveCommandCursor =
true;
3440 }
else if (e->key() == (Qt::Key_Tab)) {
3442 }
else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_A)) {
3443 fCommandArea->home(
false);
3445 }
else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_E)) {
3446 fCommandArea->end(
false);
3449 }
else if (aEvent->type() == QEvent::Paint) {
3450 if (fLastCompleteCommand !=
"") {
3451 fCommandArea->setText(fLastCompleteCommand);
3452 fLastCompleteCommand =
"";
3456 if (tabKeyPress ==
true) {
3457 G4String ss = Complete(fCommandArea->text().toStdString().c_str());
3458 fCommandArea->setText((
char*)(ss.
data()));
3459 fCommandArea->setFocus();
3468 if (moveCommandCursor ==
true) {
3469 fCommandArea->setCursorPosition ( fCommandArea->text().length() );
3470 fCommandArea->setCursorPosition (4);
3473 res = QObject::eventFilter(aObj, aEvent);
3479 void G4UIQt::UpdateCommandCompleter() {
3480 if (!fCommandArea)
return;
3483 fCommandArea->setCompleter(NULL);
3485 if (fCompleter->popup()) {
3486 fCompleter->popup()->removeEventFilter(
this);
3490 QStandardItemModel*
model = CreateCompleterModel(
"/");
3491 fCompleter =
new QCompleter(model);
3498 int Ndir= aTree-> GetTreeEntry();
3499 fCompleter->setMaxVisibleItems(Ndir);
3501 fCommandArea->setCompleter(fCompleter);
3502 fCompleter->popup()->installEventFilter(
this);
3506 QStandardItemModel* G4UIQt::CreateCompleterModel(
G4String aCmd) {
3508 QList< QStandardItem*> dirModelList;
3509 QList< QStandardItem*> commandModelList;
3510 QList< QStandardItem*> subDirModelList;
3511 QList< QStandardItem*> subCommandModelList;
3523 if(jpre !=
G4int(G4String::npos)) pName.
remove(jpre+1);
3528 int Ndir= aTree-> GetTreeEntry();
3529 int Ncmd= aTree-> GetCommandEntry();
3532 for(
G4int idir=1; idir<=Ndir; idir++) {
3533 G4String fpdir= aTree-> GetTree(idir)-> GetPathName();
3535 if( fpdir.
index(remainingPath, 0) == 0) {
3537 matchingPath = fpdir;
3544 QStandardItem* item1 =
new QStandardItem(fpdir.
data());
3545 QIcon i = QIcon(*fDirIcon);
3547 item1->setIcon(QIcon(*fDirIcon));
3548 dirModelList.append(item1);
3551 QStandardItemModel* subModel = CreateCompleterModel(fpdir.
data());
3552 for (
int a=0;
a< subModel->rowCount();
a++) {
3555 QStandardItem* tempItem =
new QStandardItem(subModel->item(
a)->text());
3556 tempItem->setIcon(subModel->item(
a)->icon());
3557 tempItem->setToolTip(subModel->item(
a)->toolTip());
3558 tempItem->setData(subModel->item(
a)->data());
3561 if (tempItem->data() == 1) {
3563 subDirModelList.append(tempItem);
3566 else if (tempItem->data() == 0) {
3567 subCommandModelList.append(tempItem);
3574 G4int n_parameterEntry;
3576 G4int n_guidanceEntry;
3579 std::string tooltip;
3582 for(
G4int icmd=1; icmd<=Ncmd; icmd++){
3585 command = aTree-> GetCommand(icmd);
3586 G4String longCommandName= aTree-> GetPathName() +
3587 command -> GetCommandName();
3594 if( longCommandName.
index(remainingPath, 0) ==0) {
3596 matchingPath= longCommandName +
" ";
3598 strtmp= longCommandName +
" ";
3603 for(
G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
3605 if (i_thGuidance < n_guidanceEntry-1 ) {
3611 for(
G4int a=0;
a<n_parameterEntry;
a++ ) {
3622 QStandardItem* item =
new QStandardItem(
G4String(longCommandName + params).
data());
3624 item->setIcon(QIcon(*fCommandIcon));
3625 item->setToolTip(tooltip.c_str());
3627 commandModelList.append(item);
3632 QStandardItemModel* model =
new QStandardItemModel();
3634 model->setColumnCount(1);
3637 for (
int a= 0;
a< dirModelList.size();
a++) {
3638 model->appendRow(dirModelList.at(
a));
3640 for (
int a= 0;
a< subDirModelList.size();
a++) {
3641 model->appendRow(subDirModelList.at(
a));
3643 for (
int a= 0;
a< commandModelList.size();
a++) {
3644 model->appendRow(commandModelList.at(
a));
3646 for (
int a= 0;
a< subCommandModelList.size();
a++) {
3647 model->appendRow(subCommandModelList.at(
a));
3662 void G4UIQt::ShowHelpCallback (
3671 void G4UIQt::ClearButtonCallback (
3674 fCoutTBTextArea->clear();
3675 fG4OutputString.clear();
3680 void G4UIQt::ExitSession (
3686 void G4UIQt::ExitHelp(
3694 void G4UIQt::CommandEnteredCallback (
3698 fCommandArea->setText(fCommandArea->text().trimmed());
3699 QStringList list = fCommandArea->text().split(QRegExp(
"[\r\n]"),QString::SkipEmptyParts);
3702 for (
int a=0;
a< list.size();
a++) {
3703 QString txt (list[
a].trimmed());
3705 fHistoryTBTableList->addItem(txt);
3706 fHistoryTBTableList->clearSelection();
3707 fHistoryTBTableList->setCurrentItem(NULL);
3708 fCommandArea->setText(
"");
3709 G4Qt* interactorManager = G4Qt::getInstance ();
3710 if (interactorManager) {
3711 interactorManager->FlushAndWaitExecution();
3714 G4String command = txt.toStdString().c_str();
3715 if (command(0,4) !=
"help") {
3716 ApplyShellCommand (command,exitSession,exitPause);
3718 ActivateCommand(command);
3723 fCommandArea->setFocus();
3729 UpdateCommandCompleter();
3731 if(exitSession==
true)
3740 void G4UIQt::CommandEditedCallback(
const QString &)
3742 QStringList list = fCommandArea->text().split(QRegExp(
"[\r\n]"),QString::SkipEmptyParts);
3744 if (list.size() > 1) {
3745 for (
int a=0;
a<list.size()-1;
a++) {
3747 fCommandArea->setText(list[
a]);
3749 CommandEnteredCallback();
3752 fCommandArea->setText(list[list.size()-1]);
3759 void G4UIQt::VisParameterCallback(QWidget* widget){
3760 if (widget == NULL) {
3765 QGridLayout* grid =
dynamic_cast<QGridLayout*
>(widget->layout());
3770 #if QT_VERSION < 0x040400
3771 QWidget* name = grid->itemAt(grid->columnCount()*(grid->rowCount()-2))->widget();
3773 QWidget* name = grid->itemAtPosition(grid->rowCount()-1,0)->widget();
3775 if (dynamic_cast<QLabel*>(name) == 0) {
3778 command += (
dynamic_cast<QLabel*
>(
name))->text()+
" ";
3780 for (
int a=0;
a<grid->rowCount()-1;
a++) {
3781 #if QT_VERSION < 0x040400
3782 QWidget* widgetTmp = grid->itemAt(
a*grid->columnCount()+1)->widget();
3784 QWidget* widgetTmp = grid->itemAtPosition(
a,1)->widget();
3788 if (widgetTmp != NULL) {
3790 if (dynamic_cast<QLineEdit*>(widgetTmp) != 0) {
3791 command += (
dynamic_cast<QLineEdit*
>(widgetTmp))->text()+
" ";
3793 }
else if (dynamic_cast<QComboBox*>(widgetTmp) != 0){
3794 command += (
dynamic_cast<QComboBox*
>(widgetTmp))->itemText((dynamic_cast<QComboBox*>(widgetTmp))->currentIndex())+
" ";
3797 }
else if (dynamic_cast<QPushButton*>(widgetTmp) != 0){
3798 command += widgetTmp->accessibleName()+
" ";
3801 }
else if (dynamic_cast<QWidget*>(widgetTmp) != 0){
3802 if (widgetTmp->layout()->count() > 0){
3803 if (dynamic_cast<QRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()) != 0) {
3804 QAbstractButton * checked = (
dynamic_cast<QRadioButton*
>(widgetTmp->layout()->itemAt(0)->widget()))->group()->checkedButton();
3806 command += (
dynamic_cast<QRadioButton*
>(widgetTmp->layout()->itemAt(0)->widget()))->group()->checkedButton()->text()+
" ";
3814 if (command !=
"") {
3828 void G4UIQt::ButtonCallback (
3829 const QString& aCommand
3836 if(UI==NULL)
return;
3843 if (IsGUICommand(command)) {
3844 QDialog* menuParameterDialog =
new QDialog();
3846 if (CreateVisCommandGroupAndToolBox(command,menuParameterDialog,1,
true)) {
3847 menuParameterDialog->setWindowTitle (aCommand);
3848 menuParameterDialog->setSizePolicy (QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
3851 menuParameterDialog->exec();
3854 delete menuParameterDialog;
3858 ApplyShellCommand(ss,exitSession,exitPause);
3863 if(exitSession==
true)
3871 void G4UIQt::HelpTreeClicCallback (
3874 QTreeWidgetItem* item = NULL;
3875 if (!fHelpTreeWidget)
3878 QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
3881 item = list.first();
3886 if(UI==NULL)
return;
3889 std::string itemText = GetLongCommandPath(item).toStdString();
3892 if (item->childCount() > 0) {
3898 updateHelpArea(command);
3904 fParameterHelpLabel->setVisible(
true);
3906 fParameterHelpTable->setVisible(
false);
3913 void G4UIQt::HelpTreeDoubleClicCallback (
3916 HelpTreeClicCallback();
3918 QTreeWidgetItem* item = NULL;
3919 if (!fHelpTreeWidget)
3922 QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
3925 item = list.first();
3929 fCommandArea->clear();
3930 fCommandArea->setText(GetLongCommandPath(item));
3937 void G4UIQt::CommandHistoryCallback(
3940 QListWidgetItem* item = NULL;
3941 if (!fHistoryTBTableList)
3945 QList<QListWidgetItem *> list =fHistoryTBTableList->selectedItems();
3948 item = list.first();
3951 fCommandArea->setText(item->text());
3955 void G4UIQt::ThreadComboBoxCallback(
int) {
3956 CoutFilterCallback(
"");
3960 void G4UIQt::CoutFilterCallback(
3963 FilterAllOutputTextArea();
3965 fCoutTBTextArea->repaint();
3966 fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
3971 void G4UIQt::SaveOutputCallback(){
3972 QString fileName = QFileDialog::getSaveFileName(fMainWindow,
"Save console output as...", fLastOpenPath,
"Save output as...");
3973 if (fileName !=
"") {
3975 QFile
data(fileName);
3976 if (
data.open(QFile::WriteOnly | QFile::Truncate)) {
3977 QTextStream out(&
data);
3978 out << fCoutTBTextArea->toPlainText();
3986 QString G4UIQt::FilterOutput(
3987 const G4UIOutputString& output
3988 ,
const QString& currentThread
3992 #ifdef G4MULTITHREADED
3993 if ((currentThread ==
"All") ||
3994 (currentThread == output.fThread)) {
3996 if (currentThread ==
"") {
3998 if (output.fText.contains(QRegExp(filter))) {
3999 return output.fText;
4006 void G4UIQt::FilterAllOutputTextArea() {
4008 QString currentThread =
"";
4009 #ifdef G4MULTITHREADED
4010 currentThread = fThreadsFilterComboBox->currentText();
4011 if (currentThread ==
"Master") {
4015 QString filter = fCoutFilter->text();
4016 G4String previousOutputStream =
"";
4018 fCoutTBTextArea->clear();
4019 fCoutTBTextArea->setTextColor(QColor(Qt::black));
4021 for (
unsigned int a=0;
a<fG4OutputString.size();
a++) {
4022 G4UIOutputString out = fG4OutputString[
a];
4023 if (FilterOutput(out,currentThread,filter) !=
"") {
4026 if (out.fOutputStream != previousOutputStream) {
4027 previousOutputStream = out.fOutputStream;
4028 if (out.fOutputStream ==
"info") {
4029 fCoutTBTextArea->setTextColor(QColor(Qt::black));
4031 fCoutTBTextArea->setTextColor(QColor(Qt::red));
4034 fCoutTBTextArea->
append(out.fText);
4037 fCoutTBTextArea->setTextColor(QColor(Qt::black));
4045 void G4UIQt::LookForHelpStringCallback(
4048 fHelpLine->setText(fHelpLine->text().trimmed());
4049 QString searchText = fHelpLine->text();
4051 fParameterHelpLabel->setText(
"");
4052 fParameterHelpTable->setVisible(
false);
4053 if (searchText ==
"") {
4055 fHelpTreeWidget->clear();
4061 OpenHelpTreeOnCommand(searchText);
4066 void G4UIQt::OpenHelpTreeOnCommand(
4067 const QString & searchText
4072 if(UI==NULL)
return;
4078 fHelpTreeWidget->clear();
4084 QMap<int,QString> commandResultMap;
4085 QMap<int,QString> commandChildResultMap;
4087 for (
int a=0;
a<treeSize;
a++) {
4089 tmp = GetCommandList (command).count(searchText,Qt::CaseInsensitive);
4094 commandChildResultMap = LookForHelpStringInChildTree(treeTop->
GetTree(
a+1),searchText);
4096 if (!commandChildResultMap.empty()) {
4097 QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
4098 while (i != commandChildResultMap.constEnd()) {
4099 commandResultMap.insertMulti(i.key(),i.value());
4102 commandChildResultMap.clear();
4107 fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
4108 fHelpTreeWidget->setColumnCount(2);
4110 labels << QString(
"Command") << QString(
"Match");
4111 fHelpTreeWidget->setHeaderLabels(labels);
4113 if (commandResultMap.empty()) {
4114 fParameterHelpLabel->setText(
"No match found");
4115 fParameterHelpTable->setVisible(
false);
4119 QMap<int,QString>::const_iterator i = commandResultMap.constEnd();
4122 float multValue = 10.0/(float)(i.key());
4123 QString progressChar =
"|";
4124 QString progressStr =
"|";
4126 QTreeWidgetItem * newItem;
4129 if (i == commandResultMap.constBegin()) {
4132 for(
int a=0;
a<
int(i.key()*multValue);
a++) {
4133 progressStr += progressChar;
4135 newItem =
new QTreeWidgetItem();
4136 QString commandStr = i.value().trimmed();
4138 if (commandStr.indexOf(
"/") == 0) {
4139 commandStr = commandStr.right(commandStr.size()-1);
4142 newItem->setText(0,commandStr);
4143 newItem->setText(1,progressStr);
4144 fHelpTreeWidget->addTopLevelItem(newItem);
4145 #if QT_VERSION < 0x040200
4147 newItem->setForeground ( 1, QBrush(Qt::blue) );
4152 fHelpTreeWidget->resizeColumnToContents (0);
4153 fHelpTreeWidget->sortItems(1,Qt::DescendingOrder);
4160 QMap<int,QString> G4UIQt::LookForHelpStringInChildTree(
4162 ,
const QString & text
4165 QMap<int,QString> commandResultMap;
4166 if (aCommandTree == NULL)
return commandResultMap;
4171 QMap<int,QString> commandChildResultMap;
4175 tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
4180 commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->
GetTree(
a+1),text);
4182 if (!commandChildResultMap.empty()) {
4184 QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
4185 while (i != commandChildResultMap.constEnd()) {
4186 commandResultMap.insertMulti(i.key(),i.value());
4189 commandChildResultMap.clear();
4196 tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
4202 return commandResultMap;
4206 QString G4UIQt::GetShortCommandPath(
4210 if (commandPath.indexOf(
"/") == 0) {
4211 commandPath = commandPath.right(commandPath.size()-1);
4214 commandPath = commandPath.right(commandPath.size()-commandPath.lastIndexOf(
"/",-2)-1);
4216 if (commandPath.lastIndexOf(
"/") == (commandPath.size()-1)) {
4217 commandPath = commandPath.left(commandPath.size()-1);
4224 QString G4UIQt::GetLongCommandPath(
4225 QTreeWidgetItem* item
4228 if (item == NULL)
return "";
4231 QString itemText =
"";
4232 itemText = item->text(0);
4234 while (item->parent() != NULL) {
4235 itemText = item->parent()->text(0)+
"/"+itemText;
4236 item = item->parent();
4238 itemText =
"/"+itemText;
4244 void G4UIQt::ChangeColorCallback(QWidget* widget) {
4245 if (widget == NULL) {
4249 QPushButton* button =
dynamic_cast<QPushButton*
>(widget);
4253 QString
value = button->accessibleName();
4256 old.setRgbF(value.section(
" ",0,1).toDouble(),
4257 value.section(
" ",1,2).toDouble(),
4258 value.section(
" ",2,3).toDouble());
4259 #if QT_VERSION < 0x040500
4261 QColor
color = QColor(QColorDialog::getRgba (old.rgba(),&
a,fUITabWidget));
4263 QColor color = QColorDialog::getColor(old,
4266 QColorDialog::ShowAlphaChannel);
4270 if (color.isValid()) {
4272 QPixmap pixmap = QPixmap(QSize(16, 16));
4273 pixmap.fill (color);
4274 QPainter painter(&pixmap);
4275 painter.setPen(Qt::black);
4276 painter.drawRect(0,0,15,15);
4278 button->setAccessibleName(QString::number(color.redF())+
" "+
4279 QString::number(color.greenF())+
" "+
4280 QString::number(color.blueF())+
" "
4282 button->setIcon(pixmap);
4289 void G4UIQt::ChangeCursorAction(
const QString& action) {
4293 fMoveSelected =
true;
4294 fPickSelected =
true;
4295 fRotateSelected =
true;
4296 fZoomInSelected =
true;
4297 fZoomOutSelected =
true;
4299 if (fToolbarApp == NULL)
return;
4300 QList<QAction *> list = fToolbarApp->actions ();
4301 for (
int i = 0; i < list.size(); ++i) {
4302 if (list.at(i)->data().toString () == action) {
4303 list.at(i)->setChecked(
TRUE);
4304 if (list.at(i)->data().toString () ==
"pick") {
4306 CreatePickInfosDialog();
4308 fPickInfosDialog->show();
4309 fPickInfosDialog->raise();
4310 fPickInfosDialog->activateWindow();
4312 }
else if (list.at(i)->data().toString () ==
"move") {
4313 fMoveSelected =
false;
4314 list.at(i)->setChecked(
FALSE);
4315 }
else if (list.at(i)->data().toString () ==
"pick") {
4316 fPickSelected =
false;
4317 list.at(i)->setChecked(
FALSE);
4319 if (fPickInfosDialog) {
4320 fPickInfosDialog->hide();
4322 }
else if (list.at(i)->data().toString () ==
"rotate") {
4323 fRotateSelected =
false;
4324 list.at(i)->setChecked(
FALSE);
4325 }
else if (list.at(i)->data().toString () ==
"zoom_in") {
4326 fZoomInSelected =
false;
4327 list.at(i)->setChecked(
FALSE);
4328 }
else if (list.at(i)->data().toString () ==
"zoom_out") {
4329 fZoomOutSelected =
false;
4330 list.at(i)->setChecked(
FALSE);
4343 void G4UIQt::ChangeSurfaceStyle(
const QString& action) {
4347 if (fToolbarApp == NULL)
return;
4348 QList<QAction *> list = fToolbarApp->actions ();
4349 for (
int i = 0; i < list.size(); ++i) {
4350 if (list.at(i)->data().toString () == action) {
4351 list.at(i)->setChecked(
TRUE);
4352 }
else if (list.at(i)->data().toString () ==
"hidden_line_removal") {
4353 list.at(i)->setChecked(
FALSE);
4354 }
else if (list.at(i)->data().toString () ==
"hidden_line_and_surface_removal") {
4355 list.at(i)->setChecked(
FALSE);
4356 }
else if (list.at(i)->data().toString () ==
"solid") {
4357 list.at(i)->setChecked(
FALSE);
4358 }
else if (list.at(i)->data().toString () ==
"wireframe") {
4359 list.at(i)->setChecked(
FALSE);
4364 if (action ==
"hidden_line_removal") {
4368 }
else if (action ==
"hidden_line_and_surface_removal") {
4372 }
else if (action ==
"solid") {
4376 }
else if (action ==
"wireframe") {
4383 void G4UIQt::OpenIconCallback(
const QString& aParam) {
4385 QString aCommand = aParam.left(aParam.indexOf(fStringSeparator));
4386 QString aLabel = aParam.mid(aParam.indexOf(fStringSeparator)+fStringSeparator.length());
4388 QString nomFich = QFileDialog::getOpenFileName(fMainWindow, aLabel, fLastOpenPath,
"Macro files (*.mac)");
4389 if (nomFich !=
"") {
4392 fLastOpenPath = dir.absoluteFilePath(nomFich);
4397 void G4UIQt::SaveIconCallback(
const QString& aParam) {
4399 QString aCommand = aParam.left(aParam.indexOf(fStringSeparator));
4400 QString aLabel = aParam.mid(aParam.indexOf(fStringSeparator)+fStringSeparator.length());
4402 QString nomFich = QFileDialog::getSaveFileName(fMainWindow, aLabel, fLastOpenPath,
"Macro files (*.mac)");
4403 if (nomFich !=
"") {
4406 fLastOpenPath = dir.absoluteFilePath(nomFich);
4411 void G4UIQt::CreateViewerPropertiesDialog() {
4413 if (fViewerPropertiesDialog != NULL) {
4416 fViewerPropertiesDialog =
new QDialog();
4418 fViewerPropertiesDialog->setWindowTitle(
"Viewer properties");
4419 fViewerPropertiesDialog->setSizePolicy (QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
4421 if (!fViewerPropertiesWidget) {
4422 fViewerPropertiesWidget =
new QWidget();
4423 QVBoxLayout* layoutPropertiesWidget =
new QVBoxLayout();
4424 fViewerPropertiesWidget->setLayout(layoutPropertiesWidget);
4426 CreateEmptyViewerPropertiesWidget();
4429 QVBoxLayout* layoutDialog =
new QVBoxLayout();
4431 layoutDialog->addWidget(fViewerPropertiesWidget);
4432 layoutDialog->setContentsMargins(0,0,0,0);
4433 fViewerPropertiesDialog->setLayout(layoutDialog);
4437 void G4UIQt::CreatePickInfosDialog() {
4439 if (fPickInfosDialog != NULL) {
4442 fPickInfosDialog =
new QDialog();
4444 fPickInfosDialog->setWindowTitle(
"Pick infos");
4445 fPickInfosDialog->setSizePolicy (QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
4447 if (!fPickInfosWidget) {
4448 fPickInfosWidget =
new QWidget();
4449 QVBoxLayout* layoutPickInfos =
new QVBoxLayout();
4450 fPickInfosWidget->setLayout(layoutPickInfos);
4452 CreateEmptyPickInfosWidget();
4455 QVBoxLayout* layoutDialog =
new QVBoxLayout();
4457 layoutDialog->addWidget(fPickInfosWidget);
4458 layoutDialog->setContentsMargins(0,0,0,0);
4459 fPickInfosDialog->setLayout(layoutDialog);
4460 fPickInfosDialog->setWindowFlags(Qt::WindowStaysOnTopHint);
4465 void G4UIQt::CreateEmptyViewerPropertiesWidget() {
4466 QLayoutItem * wItem;
4467 if (fViewerPropertiesWidget->layout()->count()) {
4468 while ((wItem = fViewerPropertiesWidget->layout()->takeAt(0)) != 0) {
4469 delete wItem->widget();
4474 QLabel* label =
new QLabel(
"No viewer - Please open a viewer first");
4475 fViewerPropertiesWidget->layout()->addWidget(label);
4476 fViewerPropertiesDialog->setWindowTitle(
"No viewer");
4480 void G4UIQt::CreateEmptyPickInfosWidget() {
4481 QLayoutItem * wItem;
4482 if (fPickInfosWidget->layout()->count()) {
4483 while ((wItem = fPickInfosWidget->layout()->takeAt(0)) != 0) {
4484 delete wItem->widget();
4489 QLabel* label =
new QLabel(
"Click on the object you want to pick");
4490 fPickInfosWidget->layout()->addWidget(label);
4491 fPickInfosDialog->setWindowTitle(
"Nothing to pick");
4495 void G4UIQt::ViewerPropertiesIconCallback(
int) {
4497 CreateViewerPropertiesDialog();
4499 fViewerPropertiesDialog->show();
4500 fViewerPropertiesDialog->raise();
4501 fViewerPropertiesDialog->activateWindow();
4505 void G4UIQt::ChangePerspectiveOrtho(
const QString& action) {
4509 if (fToolbarApp == NULL)
return;
4510 QList<QAction *> list = fToolbarApp->actions ();
4511 QString checked =
"";
4512 for (
int i = 0; i < list.size(); ++i) {
4513 if (list.at(i)->data().toString () == action) {
4514 list.at(i)->setChecked(
TRUE);
4515 checked = list.at(i)->data().toString ();
4516 }
else if (list.at(i)->data().toString () ==
"persepective") {
4517 list.at(i)->setChecked(
FALSE);
4518 }
else if (list.at(i)->data().toString () ==
"ortho") {
4519 list.at(i)->setChecked(
FALSE);
4523 if ((action ==
"ortho") && (checked ==
"ortho")) {
4525 }
else if ((action ==
"perspective") && (checked ==
"perspective")) {
4532 void G4UIQt::SetIconMoveSelected() {
4534 fMoveSelected =
true;
4535 fRotateSelected =
false;
4536 fPickSelected =
false;
4537 fZoomInSelected =
false;
4538 fZoomOutSelected =
false;
4540 if (fToolbarApp == NULL)
return;
4541 QList<QAction *> list = fToolbarApp->actions ();
4542 for (
int i = 0; i < list.size(); ++i) {
4543 if (list.at(i)->data().toString () ==
"move") {
4544 list.at(i)->setChecked(
TRUE);
4545 }
else if (list.at(i)->data().toString () ==
"rotate") {
4546 list.at(i)->setChecked(
FALSE);
4547 }
else if (list.at(i)->data().toString () ==
"pick") {
4548 list.at(i)->setChecked(
FALSE);
4549 }
else if (list.at(i)->data().toString () ==
"zoom_in") {
4550 list.at(i)->setChecked(
FALSE);
4551 }
else if (list.at(i)->data().toString () ==
"zoom_out") {
4552 list.at(i)->setChecked(
FALSE);
4558 void G4UIQt::SetIconRotateSelected() {
4560 fRotateSelected =
true;
4561 fMoveSelected =
false;
4562 fPickSelected =
false;
4563 fZoomInSelected =
false;
4564 fZoomOutSelected =
false;
4566 if (fToolbarApp == NULL)
return;
4567 QList<QAction *> list = fToolbarApp->actions ();
4568 for (
int i = 0; i < list.size(); ++i) {
4569 if (list.at(i)->data().toString () ==
"rotate") {
4570 list.at(i)->setChecked(
TRUE);
4571 }
else if (list.at(i)->data().toString () ==
"move") {
4572 list.at(i)->setChecked(
FALSE);
4573 }
else if (list.at(i)->data().toString () ==
"pick") {
4574 list.at(i)->setChecked(
FALSE);
4575 }
else if (list.at(i)->data().toString () ==
"zoom_in") {
4576 list.at(i)->setChecked(
FALSE);
4577 }
else if (list.at(i)->data().toString () ==
"zoom_out") {
4578 list.at(i)->setChecked(
FALSE);
4584 void G4UIQt::SetIconPickSelected() {
4586 fPickSelected =
true;
4587 fMoveSelected =
false;
4588 fRotateSelected =
false;
4589 fZoomInSelected =
false;
4590 fZoomOutSelected =
false;
4592 QToolBar*
bar = fToolbarApp;
4593 if (!fDefaultIcons) {
4598 QList<QAction *> list = bar->actions ();
4599 for (
int i = 0; i < list.size(); ++i) {
4600 if (list.at(i)->data().toString () ==
"pick") {
4601 list.at(i)->setChecked(
TRUE);
4602 }
else if (list.at(i)->data().toString () ==
"move") {
4603 list.at(i)->setChecked(
FALSE);
4604 }
else if (list.at(i)->data().toString () ==
"rotate") {
4605 list.at(i)->setChecked(
FALSE);
4606 }
else if (list.at(i)->data().toString () ==
"zoom_in") {
4607 list.at(i)->setChecked(
FALSE);
4608 }
else if (list.at(i)->data().toString () ==
"zoom_out") {
4609 list.at(i)->setChecked(
FALSE);
4615 void G4UIQt::SetIconZoomInSelected() {
4617 fZoomInSelected =
true;
4618 fMoveSelected =
false;
4619 fRotateSelected =
false;
4620 fPickSelected =
false;
4621 fZoomOutSelected =
false;
4623 QToolBar* bar = fToolbarApp;
4624 if (!fDefaultIcons) {
4629 QList<QAction *> list = bar->actions ();
4630 for (
int i = 0; i < list.size(); ++i) {
4631 if (list.at(i)->data().toString () ==
"zoom_in") {
4632 list.at(i)->setChecked(
TRUE);
4633 }
else if (list.at(i)->data().toString () ==
"move") {
4634 list.at(i)->setChecked(
FALSE);
4635 }
else if (list.at(i)->data().toString () ==
"rotate") {
4636 list.at(i)->setChecked(
FALSE);
4637 }
else if (list.at(i)->data().toString () ==
"pick") {
4638 list.at(i)->setChecked(
FALSE);
4639 }
else if (list.at(i)->data().toString () ==
"zoom_out") {
4640 list.at(i)->setChecked(
FALSE);
4646 void G4UIQt::SetIconZoomOutSelected() {
4648 fZoomOutSelected =
true;
4649 fMoveSelected =
false;
4650 fRotateSelected =
false;
4651 fPickSelected =
false;
4652 fZoomInSelected =
false;
4654 QToolBar* bar = fToolbarApp;
4655 if (!fDefaultIcons) {
4660 QList<QAction *> list = bar->actions ();
4661 for (
int i = 0; i < list.size(); ++i) {
4662 if (list.at(i)->data().toString () ==
"zoom_out") {
4663 list.at(i)->setChecked(
TRUE);
4664 }
else if (list.at(i)->data().toString () ==
"move") {
4665 list.at(i)->setChecked(
FALSE);
4666 }
else if (list.at(i)->data().toString () ==
"rotate") {
4667 list.at(i)->setChecked(
FALSE);
4668 }
else if (list.at(i)->data().toString () ==
"pick") {
4669 list.at(i)->setChecked(
FALSE);
4670 }
else if (list.at(i)->data().toString () ==
"zoom_in") {
4671 list.at(i)->setChecked(
FALSE);
4677 void G4UIQt::SetIconSolidSelected() {
4680 QToolBar* bar = fToolbarApp;
4681 if (!fDefaultIcons) {
4686 QList<QAction *> list = bar->actions ();
4687 for (
int i = 0; i < list.size(); ++i) {
4688 if (list.at(i)->data().toString () ==
"solid") {
4689 list.at(i)->setChecked(
TRUE);
4690 }
else if (list.at(i)->data().toString () ==
"hidden_line_removal") {
4691 list.at(i)->setChecked(
FALSE);
4692 }
else if (list.at(i)->data().toString () ==
"hidden_line_and_surface_removal") {
4693 list.at(i)->setChecked(
FALSE);
4694 }
else if (list.at(i)->data().toString () ==
"wireframe") {
4695 list.at(i)->setChecked(
FALSE);
4701 void G4UIQt::SetIconWireframeSelected() {
4704 QToolBar* bar = fToolbarApp;
4705 if (!fDefaultIcons) {
4710 QList<QAction *> list = bar->actions ();
4711 for (
int i = 0; i < list.size(); ++i) {
4712 if (list.at(i)->data().toString () ==
"wireframe") {
4713 list.at(i)->setChecked(
TRUE);
4714 }
else if (list.at(i)->data().toString () ==
"hidden_line_removal") {
4715 list.at(i)->setChecked(
FALSE);
4716 }
else if (list.at(i)->data().toString () ==
"hidden_line_and_surface_removal") {
4717 list.at(i)->setChecked(
FALSE);
4718 }
else if (list.at(i)->data().toString () ==
"solid") {
4719 list.at(i)->setChecked(
FALSE);
4725 void G4UIQt::SetIconHLRSelected() {
4728 QToolBar* bar = fToolbarApp;
4729 if (!fDefaultIcons) {
4735 QList<QAction *> list = bar->actions ();
4736 for (
int i = 0; i < list.size(); ++i) {
4737 if (list.at(i)->data().toString () ==
"hidden_line_removal") {
4738 list.at(i)->setChecked(
TRUE);
4739 }
else if (list.at(i)->data().toString () ==
"solid") {
4740 list.at(i)->setChecked(
FALSE);
4741 }
else if (list.at(i)->data().toString () ==
"hidden_line_and_surface_removal") {
4742 list.at(i)->setChecked(
FALSE);
4743 }
else if (list.at(i)->data().toString () ==
"wireframe") {
4744 list.at(i)->setChecked(
FALSE);
4750 void G4UIQt::SetIconHLHSRSelected() {
4753 QToolBar* bar = fToolbarApp;
4754 if (!fDefaultIcons) {
4760 QList<QAction *> list = bar->actions ();
4761 for (
int i = 0; i < list.size(); ++i) {
4762 if (list.at(i)->data().toString () ==
"hidden_line_and_surface_removal") {
4763 list.at(i)->setChecked(
TRUE);
4764 }
else if (list.at(i)->data().toString () ==
"solid") {
4765 list.at(i)->setChecked(
FALSE);
4766 }
else if (list.at(i)->data().toString () ==
"hidden_line_removal") {
4767 list.at(i)->setChecked(
FALSE);
4768 }
else if (list.at(i)->data().toString () ==
"wireframe") {
4769 list.at(i)->setChecked(
FALSE);
4775 void G4UIQt::SetIconPerspectiveSelected() {
4778 QToolBar* bar = fToolbarApp;
4779 if (!fDefaultIcons) {
4785 QList<QAction *> list = bar->actions ();
4786 for (
int i = 0; i < list.size(); ++i) {
4787 if (list.at(i)->data().toString () ==
"perspective") {
4788 list.at(i)->setChecked(
TRUE);
4789 }
else if (list.at(i)->data().toString () ==
"ortho") {
4790 list.at(i)->setChecked(
FALSE);
4797 void G4UIQt::SetIconOrthoSelected() {
4800 QToolBar* bar = fToolbarApp;
4801 if (!fDefaultIcons) {
4807 QList<QAction *> list = bar->actions ();
4808 for (
int i = 0; i < list.size(); ++i) {
4809 if (list.at(i)->data().toString () ==
"ortho") {
4810 list.at(i)->setChecked(
TRUE);
4811 }
else if (list.at(i)->data().toString () ==
"perspective") {
4812 list.at(i)->setChecked(
FALSE);
4819 G4QTabWidget::G4QTabWidget(
4823 ):QTabWidget(aParent)
4824 ,fTabSelected(
false)
4826 ,fPreferedSizeX(sizeX+6)
4827 ,fPreferedSizeY(sizeY+58)
4829 setMinimumSize(100,100);
4830 QSizePolicy policy = QSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
4831 setSizePolicy(policy);
4834 G4QTabWidget::G4QTabWidget(
4836 ,fTabSelected(
false)
4844 G4UIOutputString::G4UIOutputString(
4852 if (!GetOutputList().contains(QString(
" ")+outputStream+
" ")) {
4853 fOutputStream =
"info";
4855 fOutputStream = outputStream;
4860 #if QT_VERSION < 0x040500
4861 void G4UIQt::TabCloseCallback(
int){
4863 void G4UIQt::TabCloseCallback(
int a){
4865 #if QT_VERSION < 0x040500
4867 if (fViewerTabWidget == NULL)
return;
4870 QWidget* temp = fViewerTabWidget->widget(a);
4872 fViewerTabWidget->removeTab (a);
4875 bool lastTab =
true;
4876 for (
int c=0; c<fViewerTabWidget->count(); c++) {
4877 if (fViewerTabWidget->tabText(c).contains(
"viewer")) {
4883 CreateEmptyViewerPropertiesWidget();
4891 void G4UIQt::ToolBoxActivated(
int a){
4893 if (fUITabWidget->widget(a) == fHelpTBWidget) {
4896 }
else if (fUITabWidget->widget(a) == fSceneTreeWidget) {
4897 #if QT_VERSION < 0x040200
4898 fSceneTreeWidget->show();
4900 fSceneTreeWidget->setVisible(
true);
4906 void G4QTabWidget::paintEvent(
4911 if (currentWidget()) {
4913 if ( isTabSelected()) {
4917 QString text = tabText (currentIndex());
4919 if (fLastCreated == -1) {
4920 QTextEdit* edit =
dynamic_cast<QTextEdit*
>(currentWidget());
4922 QString paramSelect = QString(
"/vis/viewer/select ")+text;
4931 setTabSelected(
false);
4937 G4UIDockWidget::G4UIDockWidget(QString txt):
4942 void G4UIDockWidget::closeEvent(QCloseEvent *aEvent) {
4943 setFloating (
false);