Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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$
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 "G4StateManager.hh"
40#include "G4UIcommandTree.hh"
41#include "G4UIcommandStatus.hh"
42
43#include "G4Qt.hh"
44
45#include <qapplication.h>
46#include <qmessagebox.h>
47#include <qlineedit.h>
48#include <qwidget.h>
49#include <qmenubar.h>
50#include <qlayout.h>
51#include <qpushbutton.h>
52#include <qlabel.h>
53#include <qsplitter.h>
54#include <qscrollbar.h>
55#include <qdialog.h>
56#include <qevent.h>
57#include <qtextedit.h>
58#include <qsignalmapper.h>
59#include <qtabwidget.h>
60#include <qtabbar.h>
61#include <qstringlist.h>
62
63#include <qmainwindow.h>
64#include <qmenu.h>
65#include <qlistwidget.h>
66#include <qtreewidget.h>
67#include <qgroupbox.h>
68#include <qscrollarea.h>
69#include <qtoolbox.h>
70#include <qradiobutton.h>
71#include <qbuttongroup.h>
72#include <qcombobox.h>
73#include <qsignalmapper.h>
74#include <qpainter.h>
75#include <qcolordialog.h>
76#include <qtoolbar.h>
77#include <qfiledialog.h>
78
79
80
81#include <stdlib.h>
82
83// Pourquoi Static et non variables de classe ?
84static G4bool exitSession = true;
85static G4bool exitPause = true;
86
87/** Build a Qt window with a menubar, output area and promt area<br>
88<pre>
89 +-----------------------+
90 |exit menu| |
91 | |
92 | +-------------------+ |
93 | | | |
94 | | Output area | |
95 | | | |
96 | +-------------------+ |
97 | | clear | |
98 | +-------------------+ |
99 | | promt history | |
100 | +-------------------+ |
101 | +-------------------+ |
102 | |> promt area | |
103 | +-------------------+ |
104 +-----------------------+
105</pre>
106*/
107G4UIQt::G4UIQt (
108 int argc
109,char** argv
110)
111:fMainWindow(NULL)
112,fCommandLabel(NULL)
113,fCommandArea(NULL)
114,fCoutTBTextArea(NULL)
115,fHelpArea(NULL)
116,fG4cout("")
117,fHelpTreeWidget(NULL)
118,fHelpTBWidget(NULL)
119,fHistoryTBWidget(NULL)
120,fCoutTBWidget(NULL)
121,fSceneTreeComponentsTBWidget(NULL)
122,fHelpLine(NULL)
123,fViewerTabWidget(NULL)
124,fCoutText("Output")
125,fLastQTabSizeX(0)
126,fLastQTabSizeY(0)
127,fToolbarApp(NULL)
128,fToolbarUser(NULL)
129,fMoveSelected(false)
130,fRotateSelected(true)
131,fPickSelected(false)
132,fZoomInSelected(false)
133,fZoomOutSelected(false)
134{
135
136 G4Qt* interactorManager = G4Qt::getInstance (argc,argv,(char*)"Qt");
137 if (!(QApplication*)interactorManager->GetMainInteractor()) {
138 G4cout << "G4UIQt : Unable to init Qt. Aborted" << G4endl;
139 }
140
142 if(UI!=NULL) UI->SetSession(this);
143 if(UI!=NULL) UI->SetG4UIWindow(this);
144
145 // Check if already define in external app QMainWindow
146 bool found = false;
147 Q_FOREACH (QWidget *widget, QApplication::allWidgets()) {
148 if ((found== false) && (widget->inherits("QMainWindow"))) {
149 found = true;
150 }
151 }
152
153 if (found) {
154 G4cout << "G4UIQt : Found an external App with a QMainWindow already defined. Aborted" << G4endl;
155 return ;
156 }
157 fMainWindow = new QMainWindow();
158
159
160#ifdef G4DEBUG_INTERFACES_BASIC
161 printf("G4UIQt::Initialise after main window creation +++++++++++\n");
162#endif
163
164
165 // the splitter
166 fMainSplitterWidget = new QSplitter(Qt::Horizontal,fMainWindow);
167
168 QWidget *leftSplitterWidget = new QWidget(fMainSplitterWidget);
169 QVBoxLayout * layoutLeftSplitterWidget = new QVBoxLayout();
170 leftSplitterWidget->setLayout(layoutLeftSplitterWidget);
171 fRightSplitterWidget = new QSplitter(Qt::Vertical,fMainSplitterWidget);
172
173
174 fUITabWidget = new QTabWidget();
175 // fUITabWidget->setMinimumHeight(100);
176
177 // Set layouts
178 QWidget* commandLineWidget = new QWidget();
179 QVBoxLayout *layoutCommandLine = new QVBoxLayout();
180 commandLineWidget->setLayout(layoutCommandLine);
181
182 // fill them
183
184 fCommandLabel = new QLabel("",commandLineWidget);
185
186 fCommandArea = new QLineEdit(commandLineWidget);
187 fCommandArea->installEventFilter(this);
188 fCommandArea->activateWindow();
189
190 fCommandArea->setFocusPolicy ( Qt::StrongFocus );
191 fCommandArea->setFocus(Qt::TabFocusReason);
192
193 commandLineWidget->setSizePolicy (QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
194
195
196 layoutCommandLine->addWidget(fCommandLabel);
197 layoutCommandLine->addWidget(fCommandArea);
198
199 fHelpTBWidget = new QWidget(fUITabWidget);
200 fHistoryTBWidget = new QWidget(fUITabWidget);
201 fSceneTreeComponentsTBWidget = new QTabWidget(fUITabWidget);
202
203#if QT_VERSION < 0x040200
204 fSceneTreeComponentsTBWidget->hide();
205#else
206 fSceneTreeComponentsTBWidget->setVisible(false);
207#endif
208
209 fEmptyViewerTabLabel = new QLabel(" If you want to have a Viewer, please use /vis/open commands. ");
210
211 layoutLeftSplitterWidget->addWidget(fUITabWidget);
212
213 fCoutTBWidget = new QGroupBox("Output");
214
215 // fill right splitter
216 fRightSplitterWidget->addWidget(fEmptyViewerTabLabel);
217 fRightSplitterWidget->addWidget(fCoutTBWidget);
218 fRightSplitterWidget->addWidget(commandLineWidget);
219
220 // set the splitter size
221 QList<int> list2;
222 list2.append(600);
223 list2.append(150);
224 // fRightSplitterWidget->setSizes(list2);
225
226
227 CreateVisParametersTBWidget();
228 CreateHelpTBWidget();
229 CreateHistoryTBWidget();
230
231 CreateCoutTBWidget();
232
233
234
235
236
237 // the right splitter
238 fUITabWidget->addTab(fSceneTreeComponentsTBWidget,"Scene tree");
239 fUITabWidget->addTab(fHelpTBWidget,"Help");
240 fUITabWidget->addTab(fHistoryTBWidget,"History");
241 fUITabWidget->setCurrentWidget(fSceneTreeComponentsTBWidget);
242
243 // Only at creation. Will be set visible when sessionStart();
244 #if QT_VERSION < 0x040200
245 fEmptyViewerTabLabel->hide();
246 #else
247 fEmptyViewerTabLabel->setVisible(false);
248 #endif
249
250
251 fMainSplitterWidget->addWidget(leftSplitterWidget);
252 fMainSplitterWidget->addWidget(fRightSplitterWidget);
253 // set the splitter size
254 QList<int> list;
255 list.append(200 );
256 list.append(650);
257 fMainSplitterWidget->setSizes(list);
258
259
260#ifdef G4DEBUG_INTERFACES_BASIC
261 printf("G4UIQt::G4UIQt :: 5\n");
262#endif
263
264
265 fMainWindow->setCentralWidget(fMainSplitterWidget);
266
267#ifdef G4DEBUG_INTERFACES_BASIC
268 printf("G4UIQt::G4UIQt :: 6\n");
269#endif
270
271 // Connect signal
272 connect(fCommandArea, SIGNAL(returnPressed()), SLOT(CommandEnteredCallback()));
273 connect(fUITabWidget, SIGNAL(currentChanged(int)), SLOT(ToolBoxActivated(int)));
274
275 if(UI!=NULL) UI->SetCoutDestination(this); // TO KEEP
276
277 fMainWindow->setWindowTitle(QFileInfo( QCoreApplication::applicationFilePath() ).fileName());
278 fMainWindow->resize(300,600);
279 fMainWindow->move(QPoint(50,50));
280
281 // Set not visible until session start
282 #if QT_VERSION < 0x040200
283 fMainWindow->hide();
284 #else
285 fMainWindow->setVisible(false);
286 #endif
287
288#ifdef G4DEBUG_INTERFACES_BASIC
289 printf("G4UIQt::G4UIQt END\n");
290#endif
291}
292
293
294
295G4UIQt::~G4UIQt(
296)
297{
298#ifdef G4DEBUG_INTERFACES_BASIC
299 printf("G4UIQt::~G4UIQt Delete\n");
300#endif
301 G4UImanager* UI = G4UImanager::GetUIpointer(); // TO KEEP
302 if(UI!=NULL) { // TO KEEP
303 UI->SetSession(NULL); // TO KEEP
304 UI->SetG4UIWindow(NULL);
305 UI->SetCoutDestination(NULL); // TO KEEP
306 }
307
308 if (fMainWindow!=NULL) {
309#ifdef G4DEBUG_INTERFACES_BASIC
310 printf("G4UIQt::~G4UIQt DELETE fMainWindow\n");
311#endif
312 delete fMainWindow;
313 }
314}
315
316/** Create the History ToolBox Widget
317 */
318void G4UIQt::CreateHistoryTBWidget(
319)
320{
321
322 QVBoxLayout *layoutHistoryTB = new QVBoxLayout();
323 fHistoryTBTableList = new QListWidget();
324 fHistoryTBTableList->setSelectionMode(QAbstractItemView::SingleSelection);
325 connect(fHistoryTBTableList, SIGNAL(itemSelectionChanged()), SLOT(CommandHistoryCallback()));
326 fHistoryTBTableList->installEventFilter(this);
327
328 layoutHistoryTB->addWidget(fHistoryTBTableList);
329
330 fHistoryTBWidget->setLayout(layoutHistoryTB);
331}
332
333/** Create the Help ToolBox Widget
334 */
335void G4UIQt::CreateHelpTBWidget(
336)
337{
338
339
340 QWidget *helpWidget = new QWidget();
341 QHBoxLayout *helpLayout = new QHBoxLayout();
342 QVBoxLayout *vLayout = new QVBoxLayout();
343 fHelpVSplitter = new QSplitter(Qt::Horizontal);
344 fHelpLine = new QLineEdit(fHelpTBWidget);
345 helpLayout->addWidget(new QLabel("Search :",helpWidget));
346 helpLayout->addWidget(fHelpLine);
347 connect( fHelpLine, SIGNAL( editingFinished () ), this, SLOT( LookForHelpStringCallback() ) );
348
349 // Create Help tree
350 FillHelpTree();
351
352 fHelpArea = new QTextEdit();
353 fHelpArea->setReadOnly(true);
354
355 // Set layouts
356
357 if (fHelpTreeWidget) {
358 fHelpVSplitter->addWidget(fHelpTreeWidget);
359 }
360 fHelpVSplitter->addWidget(fHelpArea);
361
362 vLayout->addWidget(helpWidget);
363 vLayout->addWidget(fHelpVSplitter,1);
364
365 fHelpTBWidget->setMinimumSize(50,50);
366 fHelpTBWidget->setSizePolicy (QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
367
368 // set the splitter size
369 QList<int> list;
370 list.append( 50 );
371 list.append( 50 );
372 fHelpVSplitter->setSizes(list);
373
374 helpWidget->setLayout(helpLayout);
375 fHelpTBWidget->setLayout(vLayout);
376}
377
378
379/** Create the Cout ToolBox Widget
380 */
381void G4UIQt::CreateCoutTBWidget(
382)
383{
384 QVBoxLayout *layoutCoutTB = new QVBoxLayout();
385
386 fCoutTBTextArea = new QTextEdit(fCoutTBWidget);
387 fCoutFilter = new QLineEdit(fCoutTBWidget);
388 QLabel* coutFilterLabel = new QLabel("Filter : ",fCoutTBWidget);
389
390 QPushButton *coutTBClearButton = new QPushButton("clear",fCoutTBWidget);
391 connect(coutTBClearButton, SIGNAL(clicked()), SLOT(ClearButtonCallback()));
392 connect(fCoutFilter, SIGNAL(textEdited ( const QString &)), SLOT(CoutFilterCallback( const QString &)));
393
394 fCoutTBTextArea->setReadOnly(true);
395
396 QWidget* coutButtonWidget = new QWidget(fCoutTBWidget);
397 QHBoxLayout* layoutCoutTBButtons = new QHBoxLayout(coutButtonWidget);
398 layoutCoutTBButtons->addWidget(coutTBClearButton);
399 layoutCoutTBButtons->addWidget(coutFilterLabel);
400 layoutCoutTBButtons->addWidget(fCoutFilter);
401
402 layoutCoutTB->addWidget(fCoutTBTextArea);
403 layoutCoutTB->addWidget(coutButtonWidget);
404
405 fCoutTBWidget->resize(100,100);
406 fCoutTBTextArea->setMinimumHeight(10);
407 fCoutTBWidget->setMinimumHeight(150);
408 // fCoutTBTextArea->setSizePolicy (QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
409 fCoutTBWidget->setSizePolicy (QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
410 fCoutTBWidget->setLayout(layoutCoutTB);
411}
412
413
414/** Create the VisParameters ToolBox Widget
415 */
416void G4UIQt::CreateVisParametersTBWidget(
417)
418{
419}
420
421
422/** Get the ViewerComponents ToolBox Widget
423 */
424QTabWidget* G4UIQt::GetSceneTreeComponentsTBWidget(
425)
426{
427 return fSceneTreeComponentsTBWidget;
428}
429
430
431/** Add a new tab widget.
432 Create the tab if it was not done
433*/
434bool G4UIQt::AddTabWidget(
435 QWidget* aWidget
436,QString name
437,int sizeX
438,int sizeY
439)
440{
441#ifdef G4DEBUG_INTERFACES_BASIC
442 printf("G4UIQt::AddTabWidget %d %d\n",sizeX, sizeY);
443#endif
444
445 if (fViewerTabWidget == NULL) {
446#ifdef G4DEBUG_INTERFACES_BASIC
447 printf("G4UIQt::AddTabWidget +++++\n");
448#endif
449
450 fViewerTabWidget = new G4QTabWidget(fRightSplitterWidget);
451#if QT_VERSION < 0x040500
452#else
453 fViewerTabWidget->setTabsClosable (true);
454#endif
455
456#if QT_VERSION < 0x040200
457#else
458 fViewerTabWidget->setUsesScrollButtons (true);
459#endif
460 QSizePolicy policy = fViewerTabWidget->sizePolicy();
461 policy.setHorizontalStretch(1);
462 policy.setVerticalStretch(1);
463 fViewerTabWidget->setSizePolicy(policy);
464
465#if QT_VERSION < 0x040500
466#else
467 connect(fViewerTabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(TabCloseCallback(int)));
468#endif
469 connect(fViewerTabWidget, SIGNAL(currentChanged ( int ) ), SLOT(UpdateTabWidget(int)));
470 }
471
472 fLastQTabSizeX = sizeX;
473 fLastQTabSizeY = sizeY;
474
475 if (!aWidget) {
476 return false;
477 }
478
479 // Remove QLabel
480
481 // L.Garnier 26/05/2010 : not exactly the same in qt3. Could cause some
482 // troubles
483 if (fEmptyViewerTabLabel != NULL) {
484 int index = fRightSplitterWidget->indexOf(fEmptyViewerTabLabel);
485 if ( index != -1) {
486 fEmptyViewerTabLabel->hide();
487 fEmptyViewerTabLabel->setParent(NULL);
488 delete fEmptyViewerTabLabel;
489 fEmptyViewerTabLabel = NULL;
490
491 fRightSplitterWidget->insertWidget(index,fViewerTabWidget);
492
493 aWidget->setParent(fViewerTabWidget);
494 }
495 }
496
497#ifdef G4DEBUG_INTERFACES_BASIC
498 printf("G4UIQt::AddTabWidget ADD %d %d + %d %d---------------------------------------------------\n",sizeX, sizeY,sizeX-fViewerTabWidget->width(),sizeY-fViewerTabWidget->height());
499#endif
500
501
502 // Problems with resize. The widgets are not realy drawn at this step,
503 // then we have to force them on order to check the size
504
505 fViewerTabWidget->insertTab(fViewerTabWidget->count(),aWidget,name);
506
507 fViewerTabWidget->setCurrentIndex(fViewerTabWidget->count()-1);
508
509 // Set visible
510 #if QT_VERSION < 0x040200
511 fViewerTabWidget->setLastTabCreated(fViewerTabWidget->currentIndex());
512 #else
513 fViewerTabWidget->setLastTabCreated(fViewerTabWidget->currentIndex());
514 #endif
515
516 fViewerTabWidget->resize(sizeX,sizeY);
517
518 return true;
519}
520
521
522void G4UIQt::UpdateTabWidget(int tabNumber) {
523#ifdef G4DEBUG_INTERFACES_BASIC
524 printf("G4UIQt::UpdateTabWidget %d\n",tabNumber);
525#endif
526 if ( fViewerTabWidget == NULL) {
527 fViewerTabWidget = new G4QTabWidget;
528 }
529
530#ifdef G4DEBUG_INTERFACES_BASIC
531 printf("G4UIQt::UpdateTabWidget CALL REPAINT tabGL\n");
532#endif
533
534 fViewerTabWidget->setCurrentIndex(tabNumber);
535
536 // Send this signal to unblock graphic updates !
537 fViewerTabWidget->setTabSelected(false);
538
539 #if QT_VERSION < 0x040200
540 fViewerTabWidget->show();
541 #else
542 fViewerTabWidget->setVisible(true);
543 #endif
544
545 // This will send a paintEvent to OGL Viewers
546 fViewerTabWidget->setTabSelected(true);
547
548 QCoreApplication::sendPostedEvents () ;
549
550#ifdef G4DEBUG_INTERFACES_BASIC
551 printf("G4UIQt::UpdateTabWidget END\n");
552#endif
553}
554
555
556/** Send resize event to all tabs
557 */
558void G4UIQt::ResizeTabWidget( QResizeEvent* e) {
559 for (G4int a=0;a<fViewerTabWidget->count() ;a++) {
560#ifdef G4DEBUG_INTERFACES_BASIC
561 printf("G4UIQt::ResizeTabWidget +++++++++++++++++++++++++++++++++++++++\n");
562#endif
563 fViewerTabWidget->widget(a)->resize(e->size());
564 }
565}
566
567
568/** Start the Qt main loop
569*/
570G4UIsession* G4UIQt::SessionStart (
571)
572{
573#ifdef G4DEBUG_INTERFACES_BASIC
574 printf("G4UIQt::G4UIQt SessionStart\n");
575#endif
576
577 G4Qt* interactorManager = G4Qt::getInstance ();
578
579 Prompt("Session :");
580 exitSession = false;
581/*
582 if (fEmptyViewerTabLabel != NULL) {
583 bool visible = false;
584 if (fViewerTabWidget != NULL) {
585 if (fViewerTabWidget->isVisible()) {
586 visible = true;
587 }
588 }
589 }
590*/
591 #if QT_VERSION < 0x040200
592 fMainWindow->show();
593 #else
594 fMainWindow->setVisible(true);
595 #endif
596 // get the size of the tabbar
597 int tabBarX = 0;
598 int tabBarY = 0;
599
600 if (fViewerTabWidget != NULL) {
601 tabBarX = -fViewerTabWidget->widget(0)->width();
602 tabBarY = -fViewerTabWidget->widget(0)->height();
603 }
604 fMainWindow->resize(tabBarX+fMainWindow->width()+fLastQTabSizeX,tabBarY+fMainWindow->height()+fLastQTabSizeY);
605
606 QCoreApplication::sendPostedEvents () ;
607
608#ifdef G4DEBUG_INTERFACES_BASIC
609 printf("G4UIQt::G4UIQt SessionStart2\n");
610#endif
611 interactorManager->DisableSecondaryLoop (); // TO KEEP
612 if ((QApplication*)interactorManager->GetMainInteractor())
613 ((QApplication*)interactorManager->GetMainInteractor())->exec();
614
615 // on ne passe pas le dessous ? FIXME ????
616 // je ne pense pas 13/06
617
618 // void* event; // TO KEEP
619 // while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP
620 // interactorManager->DispatchEvent(event); // TO KEEP
621 // if(exitSession==true) break; // TO KEEP
622 // } // TO KEEP
623
624 interactorManager->EnableSecondaryLoop ();
625 return this;
626}
627
628
629/** Display the prompt in the prompt area
630 @param aPrompt : string to display as the promt label
631 //FIXME : probablement inutile puisque le seul a afficher qq chose d'autre
632 que "session" est SecondaryLoop()
633*/
634void G4UIQt::Prompt (
635 G4String aPrompt
636)
637{
638 if (!aPrompt) return;
639
640 fCommandLabel->setText((char*)aPrompt.data());
641}
642
643
644
645void G4UIQt::SessionTerminate (
646)
647{
648 G4Qt* interactorManager = G4Qt::getInstance ();
649 fMainWindow->close();
650 ((QApplication*)interactorManager->GetMainInteractor())->exit();
651}
652
653
654
655/**
656 Called by intercoms/src/G4UImanager.cc<br>
657 Called by visualization/management/src/G4VisCommands.cc with "EndOfEvent" argument<br>
658 It have to pause the session command terminal.<br>
659 Call SecondaryLoop to wait for exit event<br>
660 @param aState
661 @see : G4VisCommandReviewKeptEvents::SetNewValue
662*/
663void G4UIQt::PauseSessionStart (
664 const G4String& aState
665)
666{
667 if (!aState) return;
668
669 if(aState=="G4_pause> ") { // TO KEEP
670 SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP
671 } // TO KEEP
672
673 if(aState=="EndOfEvent") { // TO KEEP
674 // Picking with feed back in event data Done here !!!
675 SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP
676 } // TO KEEP
677}
678
679
680
681/**
682 Begin the secondary loop
683 @param a_prompt : label to display as the prompt label
684 */
685void G4UIQt::SecondaryLoop (
686 G4String aPrompt
687)
688{
689 if (!aPrompt) return;
690
691 G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ?
692 Prompt(aPrompt); // TO KEEP
693 exitPause = false; // TO KEEP
694 void* eventTmp; // TO KEEP
695 while((eventTmp = interactorManager->GetEvent())!=NULL) { // TO KEEP
696 interactorManager->DispatchEvent(eventTmp); // TO KEEP
697 if(exitPause==true) break; // TO KEEP
698 } // TO KEEP
699 Prompt("Session :"); // TO KEEP
700}
701
702
703
704/**
705 Receive a cout from Geant4. We have to display it in the cout zone
706 @param aString : label to add in the display area
707 @return 0
708*/
709G4int G4UIQt::ReceiveG4cout (
710 const G4String& aString
711 )
712{
713 if (!aString) return 0;
714
715 QStringList newStr;
716
717 // Add to stringList
718 newStr = QStringList(QString((char*)aString.data()).trimmed());
719 fG4cout += newStr;
720
721 QStringList result = newStr.filter(fCoutFilter->text());
722
723 if (result.join("\n").isEmpty()) {
724 return 0;
725 }
726 fCoutTBTextArea->append(result.join("\n"));
727 fCoutTBTextArea->repaint();
728
729 fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
730
731 return 0;
732}
733
734
735/**
736 Receive a cerr from Geant4. We have to display it in the cout zone
737 @param aString : label to add in the display area
738 @return 0
739*/
740G4int G4UIQt::ReceiveG4cerr (
741 const G4String& aString
742)
743{
744 if (!aString) return 0;
745
746 QStringList newStr;
747
748 // Add to stringList
749 newStr = QStringList(QString((char*)aString.data()).trimmed());
750 fG4cout += newStr;
751
752 QStringList result = newStr.filter(fCoutFilter->text());
753
754 // Suppress space, \n,\t,\r...
755 if (QString(aString.data()).trimmed() != "") {
756 QMessageBox::critical(fMainWindow, "Error",aString.data());
757 }
758 QColor previousColor = fCoutTBTextArea->textColor();
759 fCoutTBTextArea->setTextColor(Qt::red);
760 fCoutTBTextArea->append(result.join("\n"));
761 fCoutTBTextArea->setTextColor(previousColor);
762 fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
763 fCoutTBTextArea->repaint();
764 return 0;
765}
766
767
768
769/**
770 Add a new menu to the menu bar
771 @param aName name of menu
772 @param aLabel label to display
773 */
774void G4UIQt::AddMenu (
775 const char* aName
776,const char* aLabel
777)
778{
779 if (aName == NULL) return;
780 if (aLabel == NULL) return;
781
782 QMenu *fileMenu = new QMenu(aLabel);
783 fMainWindow->menuBar()->addMenu(fileMenu);
784
785 AddInteractor (aName,(G4Interactor)fileMenu);
786}
787
788
789/**
790 Add a new button to a menu
791 @param aMenu : parent menu
792 @param aLabel : label to display
793 @param aCommand : command to execute as a callback
794 */
795void G4UIQt::AddButton (
796 const char* aMenu
797,const char* aLabel
798,const char* aCommand
799)
800{
801 if(aMenu==NULL) return; // TO KEEP
802 if(aLabel==NULL) return; // TO KEEP
803 if(aCommand==NULL) return; // TO KEEP
804
805 QMenu *parentTmp = (QMenu*)GetInteractor(aMenu);
806
807 if(parentTmp==NULL) {
808 G4cout << "Menu name " << aMenu<< " does not exist, please define it before using it."<< G4endl;
809 }
810
811 // Find the command in the command tree
813 if(UI==NULL) return;
814 G4UIcommandTree * treeTop = UI->GetTree();
815
816 G4String cmd = aCommand;
817 G4int cmdEndPos = cmd.find_first_of(" \t");
818 if(cmdEndPos!=G4int(std::string::npos)) {
819 cmd.erase(cmdEndPos);
820 }
821
822 if(treeTop->FindPath(aCommand) == NULL) {
823 G4cout << "Warning: command '"<< aCommand <<"' does not exist, please define it before using it."<< G4endl;
824 }
825
826 QSignalMapper *signalMapper = new QSignalMapper(this);
827 QAction *action = parentTmp->addAction(aLabel, signalMapper, SLOT(map()));
828
829 connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&)));
830 signalMapper->setMapping(action, QString(aCommand));
831}
832
833
834
835
836/**
837 special case for the "open" icon. It will open a file selector and map the return file to the given command.
838*/
839void G4UIQt::AddIcon(const char* aLabel, const char* aIconFile, const char* aCommand, const char* aFileName){
840 if(aLabel==NULL) return; // TO KEEP
841 // special case, aCommand could be NULL if aIconFile is not user_icon
842 if ((aCommand==NULL) && (std::string(aIconFile) == "user_icon")) return; // TO KEEP
843
844 QPixmap pix;
845 bool userToolBar = false;
846
847 if (std::string(aIconFile) == "user_icon") {
848 // try to open a file
849 pix = QPixmap(aFileName);
850 if (pix.isNull()) {
851 G4cout << "Warning: file '"<< aFileName <<"' is incorrect or does not exist, this command will not be build"<< G4endl;
852 return;
853 }
854 userToolBar = true;
855 } else if (std::string(aIconFile) == "open") {
856 const char * const xpm[]={
857 "32 32 33 1",
858 " c None",
859 "+ c #09091E",
860 "@ c #191B18",
861 "# c #5F615F",
862 "$ c #777977",
863 "% c #AEB1AF",
864 "& c #929491",
865 "* c #515250",
866 "= c #858784",
867 "- c #333533",
868 "; c #000100",
869 "> c #272926",
870 ", c #424341",
871 "' c #696C6A",
872 ") c #5F4927",
873 "! c #583D18",
874 "~ c #6E6A5B",
875 "{ c #47351D",
876 "] c #E0A554",
877 "^ c #FFD67B",
878 "/ c #EFB465",
879 "( c #FDBF6C",
880 "_ c #FFCD76",
881 ": c #806238",
882 "< c #362611",
883 "[ c #0B0D0A",
884 "} c #68471B",
885 "| c #523E22",
886 "1 c #B78A51",
887 "2 c #A17B44",
888 "3 c #D6A45E",
889 "4 c #C29354",
890 "5 c #A1A3A0",
891 " ",
892 " ",
893 " +@@@# ",
894 " $% +& * ",
895 " #= $ -; ",
896 " %>;+ ",
897 " ,;;+ ",
898 " &#$''#' >;;;+ ",
899 " =)!)!!!!~ *#$'' ",
900 " {]^/((_({- %%%%%%%%%%% ",
901 " {(^_^^^^:<{{{{{{{{{{{{{[& ",
902 " {/_/(((((/]]]]]]]]]]]/]!# ",
903 " {/^(((((_^^^^^^^^^^^^^^:# ",
904 " {/^(((_^^____________^^}$ ",
905 " {/^(((((/////////////((!# ",
906 " {/^/^_:<|||||||||||||||@@****1 ",
907 " {/^/^(<[)||||||||||||||))!!}<; ",
908 " {/^_(:|234444444444444444432)1 ",
909 " {/_^/<)34444444444444444443}, ",
910 " {/^(2{:41111111111111111142|5 ",
911 " {3^3<:31111111111111111143}- ",
912 " {/^2<:31111111111111111441|' ",
913 " {_/<:41111111111111111143}, ",
914 " {(4<:31111111111111111144!# ",
915 " )4))44111111111111111144}, ",
916 " )2<:31111111111111111144{# ",
917 " @|:14444444444444444444}* ",
918 " ;@434444444444444444434<# ",
919 " ;[))))))))))))))))))))!~ ",
920 " ++++++++++++++++++++++;% ",
921 " ",
922 " "}
923 ;
924 pix = QPixmap(xpm);
925
926 } else if (std::string(aIconFile) == "save") {
927 const char * const xpm[]={
928 "32 32 24 1",
929 " c None",
930 "+ c #000200",
931 "@ c #141E43",
932 "# c #000C56",
933 "$ c #494A47",
934 "% c #636662",
935 "& c #312F2A",
936 "* c #191B19",
937 "= c #002992",
938 "- c #003DFF",
939 "; c #041DA5",
940 "> c #A8A9A3",
941 ", c #FDFFFC",
942 "' c #DDE0DD",
943 ") c #818783",
944 "! c #C9CBC8",
945 "~ c #0116C3",
946 "{ c #C5C8FA",
947 "] c #6596FC",
948 "^ c #A0B4F9",
949 "/ c #0B2AFD",
950 "( c #799BE3",
951 "_ c #5F4826",
952 ": c #D5D8D5",
953 " ",
954 " ",
955 " +++++++++++++++++++++++++ ",
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 pix = QPixmap(xpm);
987 } else if (std::string(aIconFile) == "move") {
988 const char * const xpm[]={
989 "32 32 16 1",
990 " c None",
991 ". c #F1F1F1",
992 "+ c #939393",
993 "@ c #282828",
994 "# c #787878",
995 "$ c #000000",
996 "% c #CCCCCC",
997 "& c #1A1A1A",
998 "* c #0D0D0D",
999 "= c #5D5D5D",
1000 "- c #AEAEAE",
1001 "; c #BBBBBB",
1002 "> c #C9C9C9",
1003 ", c #D6D6D6",
1004 "' c #FFFFFF",
1005 ") c #999999",
1006 " ",
1007 " ",
1008 " ",
1009 " ",
1010 " .. ",
1011 " ++ ",
1012 " .@@. ",
1013 " #$$# ",
1014 " %&$$*% ",
1015 " =$$$$= ",
1016 " -**$$**- ",
1017 " %;%&*>;% ",
1018 " -% @& %- ",
1019 " ,=*; @& ;*=, ",
1020 " .#*$$> >$$*#. ",
1021 " ')&$$$$*@@ @@*$$$$&)' ",
1022 " ')&$$$$*@@ @@*$$$$&+' ",
1023 " .#*$$> >$$*#. ",
1024 " ,=*; @& ;*=, ",
1025 " -% @& %- ",
1026 " %;%&*>>% ",
1027 " -**$$**- ",
1028 " =$$$$= ",
1029 " %&$$*% ",
1030 " #$$# ",
1031 " .@@. ",
1032 " ++ ",
1033 " .. ",
1034 " ",
1035 " ",
1036 " ",
1037 " "}
1038 ;
1039 pix = QPixmap(xpm);
1040
1041 } else if (std::string(aIconFile) == "rotate") {
1042 const char * const xpm[]={
1043 "32 32 27 1",
1044 " c None",
1045 ". c #003333",
1046 "+ c #000066",
1047 "@ c #1A1A1A",
1048 "# c #003399",
1049 "$ c #3333CC",
1050 "% c #000033",
1051 "& c #353535",
1052 "* c #434343",
1053 "= c #336699",
1054 "- c #3399FF",
1055 "; c #003366",
1056 "> c #5D5D5D",
1057 ", c #282828",
1058 "' c #3399CC",
1059 ") c #333333",
1060 "! c #3366CC",
1061 "~ c #333399",
1062 "{ c #505050",
1063 "] c #666666",
1064 "^ c #333366",
1065 "/ c #0033CC",
1066 "( c #3366FF",
1067 "_ c #336666",
1068 ": c #787878",
1069 "< c #868686",
1070 "[ c #6B6B6B",
1071 " .++@ ",
1072 " #$$%&* ",
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 pix = QPixmap(xpm);
1105
1106 } else if (std::string(aIconFile) == "pick") {
1107 const char * const xpm[]={
1108 "32 32 2 1",
1109 " c None",
1110 ". c #000000",
1111 " ",
1112 " ",
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 pix = QPixmap(xpm);
1145 } else if (std::string(aIconFile) == "zoom_in") {
1146 const char * const xpm[]={
1147 "32 32 11 1",
1148 " c None",
1149 ". c #C9CBC8",
1150 "+ c #A8A9A3",
1151 "@ c #818783",
1152 "# c #D5D8D5",
1153 "$ c #9BCCCC",
1154 "% c #5FC7F4",
1155 "& c #FDFFFC",
1156 "* c #636662",
1157 "= c #9599CE",
1158 "- c #DDE0DD",
1159 " ",
1160 " ",
1161 " ",
1162 " ",
1163 " ",
1164 " .++@@++. ",
1165 " +++..#.+++ ",
1166 " .@+...++++#+@. ",
1167 " @$.%%+&&&@%..@ ",
1168 " ++.%%%+&&&*%%.++ ",
1169 " .+#%%%%+&&&*%%.#+ ",
1170 " ++..%%%+&&&*%%%.++ ",
1171 " +#.+++++&&&*++++.+ ",
1172 " @.+&&&&&&&&&&&&&+@ ",
1173 " @#+&&&&&&&&&&&&&+@ ",
1174 " @.+&&&&&&&&&&&&&+. ",
1175 " +++@***+&&&****@+. ",
1176 " ....++++&&&*++++.. ",
1177 " ++.===+&&&*%=.++ ",
1178 " @..==+&&&*=..@#& ",
1179 " .@+#.+&&&@-+@@*@ ",
1180 " +++.++++++ *+@* ",
1181 " .+@@@++. @**+* ",
1182 " .*@*+* ",
1183 " .*@*+* ",
1184 " +*@@* ",
1185 " .**+ ",
1186 " ",
1187 " ",
1188 " ",
1189 " ",
1190 " "}
1191 ;
1192 pix = QPixmap(xpm);
1193 } else if (std::string(aIconFile) == "zoom_out") {
1194 const char * const xpm[]={
1195 "32 32 11 1",
1196 " c None",
1197 ". c #C9CBC8",
1198 "+ c #A8A9A3",
1199 "@ c #818783",
1200 "# c #D5D8D5",
1201 "$ c #5FC7F4",
1202 "% c #9BCCCC",
1203 "& c #FDFFFC",
1204 "* c #636662",
1205 "= c #9599CE",
1206 "- c #DDE0DD",
1207 " ",
1208 " ",
1209 " ",
1210 " ",
1211 " ",
1212 " .++@@++. ",
1213 " +++..#.+++ ",
1214 " .@+..$$$$.#+@. ",
1215 " @%.$$$$$$$$..@ ",
1216 " ++.$$$$$$$$$$.++ ",
1217 " .+#$$$$$$$$$$$.#+ ",
1218 " ++..$$$$$$$$$$$.++ ",
1219 " +#.+++++++++++++.+ ",
1220 " @.+&&&&&&&&&&&&&+@ ",
1221 " @#+&&&&&&&&&&&&&+@ ",
1222 " @.+&&&&&&&&&&&&&+. ",
1223 " +++@***********@+. ",
1224 " ....++++++++++++.. ",
1225 " ++.===$$$$$$=.++ ",
1226 " @..===$$$$=..@#& ",
1227 " .@+#.$$$..-+@@*@ ",
1228 " +++#--.+++ *+@* ",
1229 " .+@@@++. @**+* ",
1230 " .*@*+* ",
1231 " .*@*+* ",
1232 " +*@@* ",
1233 " .**+ ",
1234 " ",
1235 " ",
1236 " ",
1237 " ",
1238 " "}
1239 ;
1240 pix = QPixmap(xpm);
1241 } else if (std::string(aIconFile) == "wireframe") {
1242 const char * const xpm[]={
1243 "32 32 24 1",
1244 " c None",
1245 "+ c #E4E4E4",
1246 "@ c #D5D5D5",
1247 "# c #E1E1E1",
1248 "$ c #E7E7E7",
1249 "% c #D8D8D8",
1250 "& c #A7A7A7",
1251 "* c #000000",
1252 "= c #989898",
1253 "- c #8A8A8A",
1254 "; c #B5B5B5",
1255 "> c #1B1B1B",
1256 ", c #676767",
1257 "' c #959595",
1258 ") c #4A4A4A",
1259 "! c #878787",
1260 "~ c #D3D3D3",
1261 "{ c #C4C4C4",
1262 "] c #A4A4A4",
1263 "^ c #5B5B5B",
1264 "/ c #B3B3B3",
1265 "( c #787878",
1266 "_ c #C7C7C7",
1267 ": c #585858",
1268 " ",
1269 " +@@# ",
1270 " $%@@@@@&****=+ ",
1271 " +&********&@-***; ",
1272 " +@@@&**&@@@@@@$ @*-&>&+ ",
1273 " +*****&+ %*@ ,**'# ",
1274 " @***)!~ @*{&*****+ ",
1275 " @*!]***&+ +-*^**'~!*@ ",
1276 " @*~ +@&**&@@@@@@&****&+ ~*@ ",
1277 " @*@ +&********&-*= @*@ ",
1278 " @*@ $%@-*-@$ @*@ @*@ ",
1279 " @*@ @*@ %*% @*@ ",
1280 " @*@ %*% %*% @*@ ",
1281 " @*@ %*% %*% @*@ ",
1282 " @*@ %*% %*% @*@ ",
1283 " @*@ %*% %*% @*@ ",
1284 " @*@ %*% %*% @*@ ",
1285 " @*@ @*@ %*% @*@ ",
1286 " @*@ =*-+ @*@ @*@ ",
1287 " @*@ $%@@&****&@-*-+ @*@ ",
1288 " @*@ $@&*****&@@&******&~~!*@ ",
1289 " @*{/***&@@%$ $@-*-&*****+ ",
1290 " @*)*)(-~ @*@ ~)**] ",
1291 " +*******&@@@@+ %*_+]**] ",
1292 " +@@@@@&******&@%+_*^**]# ",
1293 " $%@@@&****:**&+ ",
1294 " +%@&**& ",
1295 " ++ ",
1296 " ",
1297 " ",
1298 " ",
1299 " "}
1300 ;
1301 pix = QPixmap(xpm);
1302 } else if (std::string(aIconFile) == "solid") {
1303 const char * const xpm[]={
1304 "32 32 33 1",
1305 " c None",
1306 "+ c #C2DEDE",
1307 "@ c #B5D7DF",
1308 "# c #ACD6E6",
1309 "$ c #60C0EC",
1310 "% c #4EB7EE",
1311 "& c #53B9ED",
1312 "* c #82CEEA",
1313 "= c #CFDDDA",
1314 "- c #94C9E8",
1315 "; c #0960FF",
1316 "> c #0943FF",
1317 ", c #0949FF",
1318 "' c #3CB3F0",
1319 ") c #71C7EB",
1320 "! c #73CBE5",
1321 "~ c #D3DDDB",
1322 "{ c #C4DDDE",
1323 "] c #B7D5DF",
1324 "^ c #2DACF5",
1325 "/ c #59C1ED",
1326 "( c #5FC0ED",
1327 "_ c #85CEE9",
1328 ": c #096BFF",
1329 "< c #2AACF6",
1330 "[ c #5CBEEC",
1331 "} c #7ACAE4",
1332 "| c #73CAEB",
1333 "1 c #71C8E5",
1334 "2 c #D1DDDA",
1335 "3 c #CBDDD9",
1336 "4 c #67C1EB",
1337 "5 c #80CDEA",
1338 " ",
1339 " ",
1340 " +@@@@@@#$%&*= ",
1341 " +-;>>>>>>>>>,')!~ ",
1342 " {]@@-;>>>>>>>>>>>>^/(_= ",
1343 " {:>>>>>>>>>>>>>>>>><//[)!= ",
1344 " ]>>>>>>>>>>>>>>>>>><////[)} ",
1345 " @>>>>>>>>>>>>>>>>>><//////| ",
1346 " @>>>>>>>>>>>>>>>>>><//////| ",
1347 " @>>>>>>>>>>>>>>>>>><//////| ",
1348 " @>>>>>>>>>>>>>>>>>><//////| ",
1349 " @>>>>>>>>>>>>>>>>>><//////| ",
1350 " @>>>>>>>>>>>>>>>>>><//////| ",
1351 " @>>>>>>>>>>>>>>>>>><//////| ",
1352 " @>>>>>>>>>>>>>>>>>><//////| ",
1353 " @>>>>>>>>>>>>>>>>>><//////| ",
1354 " @>>>>>>>>>>>>>>>>>><//////| ",
1355 " @>>>>>>>>>>>>>>>>>><//////| ",
1356 " @>>>>>>>>>>>>>>>>>><//////| ",
1357 " @>>>>>>>>>>>>>>>>>><//////| ",
1358 " @>>>>>>>>>>>>>>>>>><//////| ",
1359 " @>>>>>>>>>>>>>>>>>></////[1 ",
1360 " @>>>>>>>>>>>>>>>>>><////[*2 ",
1361 " {:>>>>>>>>>>>>>>>>><//[)12 ",
1362 " +@@@@@-;>>>>>>>>>><[)13 ",
1363 " {]@@@-;>>>,'*3 ",
1364 " +@@#452 ",
1365 " ",
1366 " ",
1367 " ",
1368 " ",
1369 " "}
1370 ;
1371 pix = QPixmap(xpm);
1372 } else if (std::string(aIconFile) == "hidden_line_removal") {
1373 const char * const xpm[]={
1374 "32 32 15 1",
1375 " c None",
1376 "+ c #D5D5D5",
1377 "@ c #C7C7C7",
1378 "# c #9C9C9C",
1379 "$ c #000000",
1380 "% c #8E8E8E",
1381 "& c #808080",
1382 "* c #A9A9A9",
1383 "= c #D8D8D8",
1384 "- c #CACACA",
1385 "; c #181818",
1386 "> c #9F9F9F",
1387 ", c #ACACAC",
1388 "' c #B9B9B9",
1389 ") c #555555",
1390 " ",
1391 " +@@+ ",
1392 " +@@@@@@#$$$$%+ ",
1393 " +#$$$$$$$$#@&$$$* ",
1394 " =-@@#$$#@@@@@-= @$&#;>= ",
1395 " =$$$$$#+ -$@ *$$%+ ",
1396 " -$&@-= -$- #$$$= ",
1397 " -$@ -$- +&$- ",
1398 " @$@ @$@ @$@ ",
1399 " @$@ @$@ @$@ ",
1400 " @$@ @$@ @$@ ",
1401 " @$@ @$@ @$@ ",
1402 " @$@ @$@ @$@ ",
1403 " @$@ @$@ @$@ ",
1404 " @$@ @$@ @$@ ",
1405 " @$@ @$@ @$@ ",
1406 " @$@ @$@ @$@ ",
1407 " @$@ @$@ @$@ ",
1408 " @$@ @$@ @$@ ",
1409 " @$@ @$@ @$@ ",
1410 " @$@ @$@ @$@ ",
1411 " @$@ @$@ #$= ",
1412 " -$&@@@-= -$- =>;, ",
1413 " =$$$$$$$#@@@-= -$'+#$$, ",
1414 " =-@@@@#$$$$$$#@-+'$)$$#+ ",
1415 " =-@@@#$$$$)$$#+ ",
1416 " +@@#$$# ",
1417 " ++ ",
1418 " ",
1419 " ",
1420 " ",
1421 " "}
1422 ;
1423 pix = QPixmap(xpm);
1424 } else if (std::string(aIconFile) == "hidden_line_and_surface_removal") {
1425 const char * const xpm[]={
1426 "32 32 40 1",
1427 " c None",
1428 "+ c #FFFFFF",
1429 "@ c #89A2E9",
1430 "# c #5378E3",
1431 "$ c #A2B5ED",
1432 "% c #5379E3",
1433 "& c #5076E3",
1434 "* c #3E69E4",
1435 "= c #0C43F8",
1436 "- c #043FFE",
1437 "; c #CDD9ED",
1438 "> c #BDCDE9",
1439 ", c #FBFCFC",
1440 "' c #406AE4",
1441 ") c #0439FE",
1442 "! c #0137FF",
1443 "~ c #4F75E3",
1444 "{ c #9EB5E3",
1445 "] c #829FE0",
1446 "^ c #B6C6E7",
1447 "/ c #9DB4E3",
1448 "( c #7E9CE0",
1449 "_ c #B2C3E9",
1450 ": c #7E9AE0",
1451 "< c #86A2E1",
1452 "[ c #CAD6ED",
1453 "} c #5177E3",
1454 "| c #829CE0",
1455 "1 c #BCCCE9",
1456 "2 c #3A67E6",
1457 "3 c #0A43FA",
1458 "4 c #95ACE1",
1459 "5 c #BBCBE9",
1460 "6 c #A9BBE5",
1461 "7 c #96AFE1",
1462 "8 c #BDCBE9",
1463 "9 c #4067E4",
1464 "0 c #6485E5",
1465 "a c #E3EAF3",
1466 "b c #CAD6F3",
1467 " ",
1468 " ",
1469 " ++++ ",
1470 " ++++++++@#$+++ ",
1471 " ++@%####&*=-#+;>, ",
1472 " +++++@'=)))))))!)~+{]^++ ",
1473 " +$%&*=)!!!!!!!!!)~+/(]_+++ ",
1474 " +#-))!!!!!!!!!!!)~+/(::<[+ ",
1475 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1476 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1477 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1478 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1479 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1480 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1481 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1482 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1483 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1484 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1485 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1486 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1487 " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1488 " +#)!!!!!!!!!!!!!!}+/:::|1+ ",
1489 " +$#}}~23!!!!!!!!)~+/(]45, ",
1490 " +++++++@#}}~23!!)~+678++ ",
1491 " ++++++@#~90+a++ ",
1492 " ++++b++ ",
1493 " ++ ",
1494 " ",
1495 " ",
1496 " ",
1497 " ",
1498 " "}
1499 ;
1500 pix = QPixmap(xpm);
1501 } else if (std::string(aIconFile) == "perspective") {
1502 const char * const xpm[]={
1503 "32 32 3 1",
1504 " c None",
1505 ". c #D5D8D5",
1506 "+ c #000000",
1507 " ",
1508 " ",
1509 " ",
1510 " ",
1511 " ",
1512 " ................ ",
1513 " ....+++++++++++++++. ",
1514 " ...++++..+.........+++. ",
1515 " ..++..............++..+. ",
1516 " .+++++++++++++++++.. .+. ",
1517 " .+...............+. .+. ",
1518 " .+. .+. .+. .+. ",
1519 " .+. .+. .+. .+. ",
1520 " .+. .+. .+. .+. ",
1521 " .+. .+. .+. .+. ",
1522 " .+. .+. .+. .+. ",
1523 " .+. .+. .+. .+. ",
1524 " .+. .+. .+. .+. ",
1525 " .+. .+. .+. .+. ",
1526 " .+. .+......+....+. ",
1527 " .+. ..++++++.+.++++. ",
1528 " .+. .++.......+...+.. ",
1529 " .+. .++. .+..++. ",
1530 " .+. ..+.. .+..+. ",
1531 " .+..++. .+.+. ",
1532 " .+.++. .+++. ",
1533 " .+++.............++. ",
1534 " .+++++++++++++++++. ",
1535 " ................... ",
1536 " ",
1537 " ",
1538 " "}
1539 ;
1540 pix = QPixmap(xpm);
1541 } else if (std::string(aIconFile) == "ortho") {
1542 const char * const xpm[]={
1543 "32 32 3 1",
1544 " c None",
1545 ". c #D5D8D5",
1546 "@ c #000000",
1547 " ",
1548 " ",
1549 " ",
1550 " ................... ",
1551 " ..@@@@@@@@@@@@@@@@@. ",
1552 " ..@@@.............@@@. ",
1553 " ..@@.@. ..@..@. ",
1554 " ..@@ ..@. .@@...@. ",
1555 " ..@@..............@@.. .@. ",
1556 " .@@@@@@@@@@@@@@@@@.. .@. ",
1557 " .@...............@. .@. ",
1558 " .@. .@. .@. .@. ",
1559 " .@. .@. .@. .@. ",
1560 " .@. .@. .@. .@. ",
1561 " .@. .@. .@. .@. ",
1562 " .@. .@. .@. .@. ",
1563 " .@. .@. .@. .@. ",
1564 " .@. .@. .@. .@. ",
1565 " .@. .@. .@. .@. ",
1566 " .@. .@. .@. .@. ",
1567 " .@. .@. .@. .@. ",
1568 " .@. .@........@......@. ",
1569 " .@. .@@@@@@@@@.@.@@@@@@. ",
1570 " .@. .@@+........@....@@.. ",
1571 " .@...@. .@...@... ",
1572 " .@.@@. .@.@@ . ",
1573 " .@@@.............@@@.. ",
1574 " .@@@@@@@@@@@@@@@@@... ",
1575 " ................... ",
1576 " ",
1577 " ",
1578 " "}
1579 ;
1580 pix = QPixmap(xpm);
1581 } else {
1582 G4cout << "Parameter"<< aIconFile <<" not defined"<< G4endl;
1583 return;
1584 }
1585 QToolBar *currentToolbar = NULL;
1586 if (userToolBar) {
1587 if (fToolbarUser == NULL) {
1588 fToolbarUser = new QToolBar(fMainWindow);
1589 fToolbarUser->setIconSize (QSize(20,20));
1590 fMainWindow->addToolBar(Qt::TopToolBarArea, fToolbarUser);
1591 }
1592 currentToolbar = fToolbarUser;
1593 } else {
1594 if (fToolbarApp == NULL) {
1595 fToolbarApp = new QToolBar(fMainWindow);
1596 fToolbarApp->setIconSize (QSize(20,20));
1597 fMainWindow->addToolBar(Qt::TopToolBarArea, fToolbarApp);
1598 }
1599 currentToolbar = fToolbarApp;
1600 }
1601
1602 QSignalMapper *signalMapper = new QSignalMapper(this);
1603 QAction *action = currentToolbar->addAction(pix,aLabel, signalMapper, SLOT(map()));
1604
1605
1606 // special cases :"open"
1607 if (std::string(aIconFile) == "open") {
1608 connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(OpenIconCallback(const QString&)));
1609 signalMapper->setMapping(action, QString(aCommand));
1610
1611 // special cases :"save"
1612 } else if (std::string(aIconFile) == "save") {
1613 connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(SaveIconCallback(const QString&)));
1614 signalMapper->setMapping(action, QString(aCommand));
1615
1616 // special cases : cursor style
1617 } else if ((std::string(aIconFile) == "move") ||
1618 (std::string(aIconFile) == "rotate") ||
1619 (std::string(aIconFile) == "pick") ||
1620 (std::string(aIconFile) == "zoom_out") ||
1621 (std::string(aIconFile) == "zoom_in")) {
1622 action->setCheckable(TRUE);
1623 action->setChecked(TRUE);
1624 action->setData(aIconFile);
1625
1626 connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ChangeCursorStyle(const QString&)));
1627 signalMapper->setMapping(action, QString(aIconFile));
1628
1629 if (std::string(aIconFile) == "move") {
1630 SetIconMoveSelected();
1631 }
1632 if (std::string(aIconFile) == "rotate") {
1633 SetIconRotateSelected();
1634 }
1635 if (std::string(aIconFile) == "pick") {
1636 SetIconPickSelected();
1637 }
1638 if (std::string(aIconFile) == "zoom_in") {
1639 SetIconZoomInSelected();
1640 }
1641 if (std::string(aIconFile) == "zoom_out") {
1642 SetIconZoomOutSelected();
1643 }
1644
1645 // special case : surface style
1646 } else if ((std::string(aIconFile) == "hidden_line_removal") ||
1647 (std::string(aIconFile) == "hidden_line_and_surface_removal") ||
1648 (std::string(aIconFile) == "solid") ||
1649 (std::string(aIconFile) == "wireframe")) {
1650 action->setCheckable(TRUE);
1651 action->setChecked(TRUE);
1652 action->setData(aIconFile);
1653 connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ChangeSurfaceStyle(const QString&)));
1654 signalMapper->setMapping(action, QString(aIconFile));
1655
1656 if (std::string(aIconFile) == "hidden_line_removal") {
1657 SetIconHLRSelected();
1658 }
1659 if (std::string(aIconFile) == "hidden_line_and_surface_removal") {
1660 SetIconHLHSRSelected();
1661 }
1662 if (std::string(aIconFile) == "solid") {
1663 SetIconSolidSelected();
1664 }
1665 if (std::string(aIconFile) == "wireframe") {
1666 SetIconWireframeSelected();
1667 }
1668
1669 // special case : perspective/ortho
1670 } else if ((std::string(aIconFile) == "perspective") ||
1671 (std::string(aIconFile) == "ortho")) {
1672 action->setCheckable(TRUE);
1673 action->setChecked(TRUE);
1674 action->setData(aIconFile);
1675 connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ChangePerspectiveOrtho(const QString&)));
1676 signalMapper->setMapping(action, QString(aIconFile));
1677
1678 if (std::string(aIconFile) == "perspective") {
1679 SetIconPerspectiveSelected();
1680 }
1681 if (std::string(aIconFile) == "ortho") {
1682 SetIconOrthoSelected();
1683 }
1684
1685 } else {
1686
1687 // Find the command in the command tree
1689 if(UI==NULL) return;
1690 G4UIcommandTree * treeTop = UI->GetTree();
1691
1692 if(treeTop->FindPath(aCommand) == NULL) {
1693 G4cout << "Warning: command '"<< aCommand <<"' does not exist, please define it before using it."<< G4endl;
1694 }
1695
1696 connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&)));
1697 signalMapper->setMapping(action, QString(aCommand));
1698 }
1699}
1700
1701
1702
1703void G4UIQt::ActivateCommand(
1704 G4String newCommand
1705)
1706{
1707 if (!fHelpTreeWidget) {
1708 return;
1709 }
1710 // Look for the choosen command "newCommand"
1711 size_t i = newCommand.index(" ");
1712 G4String targetCom ="";
1713 if( i != std::string::npos )
1714 {
1715 G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
1716 newValue.strip(G4String::both);
1717 targetCom = ModifyToFullPathCommand( newValue );
1718 }
1719#ifdef G4DEBUG_INTERFACES_BASIC
1720 printf("G4UIQt::ActivateCommand found : %s \n",targetCom.data());
1721#endif
1722 if (targetCom != "") {
1723 OpenHelpTreeOnCommand(targetCom.data());
1724 }
1725
1726 fUITabWidget->setCurrentWidget(fHelpTBWidget);
1727}
1728
1729
1730
1731/**
1732 Create the help tree widget
1733 @param parent : parent of tree widget
1734 @return the widget containing the tree or NULL if it could not have beeen created
1735 */
1736
1737void G4UIQt::InitHelpTreeAndVisParametersWidget()
1738{
1739
1740 if (! fHelpTreeWidget ) {
1741 fHelpTreeWidget = new QTreeWidget();
1742 }
1743
1744 // build widget
1745 fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
1746 QStringList labels;
1747 labels << QString("Command");
1748 fHelpTreeWidget->setHeaderLabels(labels);
1749
1750
1751 connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback()));
1752 connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback()));
1753
1754}
1755/**
1756 Create the help tree widget
1757 @param parent : parent of tree widget
1758 @return the widget containing the tree or NULL if it could not have beeen created
1759 */
1760
1761void G4UIQt::FillHelpTree()
1762{
1763 if (! fHelpTreeWidget ) {
1764 InitHelpTreeAndVisParametersWidget();
1765 }
1766
1767 QString searchText = fHelpLine->text();
1768
1769 if (searchText =="") {
1770 // clear old help tree
1771 // fHelpTreeWidget->clear();
1772 } else {
1773 return;
1774 }
1775
1776 if (fHelpArea) {
1777#if QT_VERSION < 0x040200
1778 fHelpArea->clear();
1779#else
1780 fHelpArea->setText("");
1781#endif
1782 }
1783
1784 if (fHelpLine) {
1785#if QT_VERSION < 0x040200
1786 fHelpLine->clear();
1787#else
1788 fHelpLine->setText("");
1789#endif
1790 }
1791
1793 if(UI==NULL) return;
1794 G4UIcommandTree * treeTop = UI->GetTree();
1795
1796 G4int treeSize = treeTop->GetTreeEntry();
1797 QTreeWidgetItem * newItem = NULL;
1798 QString commandText = "";
1799 for (int a=0;a<treeSize;a++) {
1800 // Creating new item
1801 newItem = NULL;
1802
1803 commandText = QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed();
1804
1805 // if already exist, don't create it !
1806 for (int b=0;b<fHelpTreeWidget->topLevelItemCount();b++) {
1807 if (!newItem)
1808 newItem = FindTreeItem(fHelpTreeWidget->topLevelItem(b),commandText);
1809 }
1810
1811 if (newItem == NULL) {
1812
1813 newItem = new QTreeWidgetItem(fHelpTreeWidget);
1814 newItem->setText(0,GetShortCommandPath(commandText));
1815 }
1816
1817 // look for childs
1818 CreateHelpTree(newItem,treeTop->GetTree(a+1));
1819 }
1820
1821}
1822
1823
1824
1825/** Fill the Help Tree Widget
1826 @param aParent : parent item to fill
1827 @param aCommandTree : commandTree node associate with this part of the Tree
1828*/
1829void G4UIQt::CreateHelpTree(
1830 QTreeWidgetItem *aParent
1831,G4UIcommandTree *aCommandTree
1832)
1833{
1834 if (aParent == NULL) return;
1835 if (aCommandTree == NULL) return;
1836
1837
1838 // Creating new item
1839 QTreeWidgetItem * newItem;
1840
1841 QString commandText = "";
1842 // Get the Sub directories
1843 for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
1844
1845 commandText = QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed();
1846
1847 // if already exist, don't create it !
1848 newItem = FindTreeItem(aParent,commandText);
1849 if (newItem == NULL) {
1850 newItem = new QTreeWidgetItem(aParent);
1851 newItem->setText(0,GetShortCommandPath(commandText));
1852 }
1853 CreateHelpTree(newItem,aCommandTree->GetTree(a+1));
1854 }
1855
1856 // Get the Commands
1857
1858 for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
1859
1860 QStringList stringList;
1861 commandText = QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed();
1862
1863 // if already exist, don't create it !
1864 newItem = FindTreeItem(aParent,commandText);
1865 if (newItem == NULL) {
1866 newItem = new QTreeWidgetItem(aParent);
1867 newItem->setText(0,GetShortCommandPath(commandText));
1868
1869#if QT_VERSION < 0x040202
1870 fHelpTreeWidget->setItemExpanded(newItem,false);
1871#else
1872 newItem->setExpanded(false);
1873#endif
1874 }
1875 }
1876}
1877
1878
1879
1880
1881/**
1882 Add the following command to the corresponding groupbox
1883 If depthLevel is 1 : create ToolBox
1884 If depthLevel is 2 or more : create GroupBox
1885*/
1886bool G4UIQt::CreateVisCommandGroupAndToolBox(
1887 G4UIcommand* aCommand
1888,QWidget* aParent
1889,int aDepthLevel
1890,bool isDialog
1891)
1892{
1893 QString commandText = QString((char*)(aCommand->GetCommandPath().data())).section("/",-aDepthLevel);
1894
1895 if (commandText == NULL) {
1896 return false;
1897 }
1898
1899 // Look if groupBox is create
1900 // QGroupBox* gBoxCommandWidget;
1901 QWidget* newParentWidget = NULL;
1902 bool found = false;
1903 QString commandSection = commandText.left(commandText.indexOf("/"));
1904
1905 if (aDepthLevel == 1) {
1906 QToolBox* currentParent = dynamic_cast<QToolBox*>(aParent);
1907 if (currentParent != 0){
1908
1909 // already exists ?
1910 for (int a=0; a<currentParent->count(); a++) {
1911 if (currentParent->itemText(a) == commandSection) {
1912 found = true;
1913 newParentWidget = currentParent->widget(a);
1914 }
1915 }
1916 }
1917 // Not found ? create it
1918 if (!found) {
1919 newParentWidget = new QGroupBox();
1920 // newParentWidget->setSizePolicy (QSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum));
1921 newParentWidget->setLayout(new QVBoxLayout());
1922 if (currentParent != 0){
1923 currentParent->addItem(newParentWidget,commandSection);
1924 } else {
1925 if (!aParent->layout()) {
1926 aParent->setLayout(new QVBoxLayout());
1927 }
1928 aParent->layout()->addWidget(newParentWidget);
1929 }
1930
1931 if (commandText.indexOf("/") == -1) {
1932
1933 // Guidance
1934 QString guidance;
1935 G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
1936 for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
1937 guidance += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
1938 }
1939 newParentWidget->setToolTip(guidance);
1940 }
1941
1942 QScrollArea* sc = dynamic_cast<QScrollArea*>(newParentWidget->parent()->parent());
1943 if (sc != 0) {
1944 sc->ensureWidgetVisible(newParentWidget);
1945 // sc->setSizePolicy (QSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum));
1946
1947 }
1948 }
1949 } else {
1950
1951 // try to know if this level is already there
1952 QGroupBox* currentParent = dynamic_cast<QGroupBox*>(aParent);
1953 if (currentParent != 0){
1954
1955 // if depth==2, then we add a [more parameters inside] to the toolBoxItem parent
1956 // QGroupBox > QWidget > QScrollArea > QToolBox
1957 if (aDepthLevel == 2){
1958 QToolBox* parentToolBox = dynamic_cast<QToolBox*>(currentParent->parent()->parent()->parent());
1959 if (parentToolBox != 0) {
1960 // parentToolBox->setItemText(parentToolBox->indexOf(currentParent),"[more parameters inside]");
1961 }
1962 }
1963 for (int a=0; a<aParent->layout()->count(); a++) {
1964 QGroupBox* gb = dynamic_cast<QGroupBox*>(aParent->layout()->itemAt(a)->widget());
1965 if (gb != 0) {
1966 if (gb->title() == commandSection) {
1967 found = true;
1968 newParentWidget = gb;
1969 }
1970 }
1971 }
1972 }
1973
1974 // Not found ? create it
1975 if (!found) {
1976 newParentWidget = new QGroupBox(commandSection);
1977 newParentWidget->setLayout(new QVBoxLayout());
1978 if (!aParent->layout()) {
1979 aParent->setLayout(new QVBoxLayout());
1980 }
1981 aParent->layout()->addWidget(newParentWidget);
1982
1983 // set toolTip
1984 // Guidance
1985 QString guidance;
1986 G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
1987 for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
1988 guidance += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
1989 }
1990 newParentWidget->setToolTip(guidance);
1991 }
1992 }
1993
1994 // fill command groupbox
1995 if (commandText.indexOf("/") == -1) {
1996 if (CreateCommandWidget(aCommand, newParentWidget,isDialog)) {
1997 return true;
1998 }
1999 } else {
2000 CreateVisCommandGroupAndToolBox(aCommand,newParentWidget, aDepthLevel-1,isDialog);
2001 }
2002
2003 return true;
2004}
2005
2006
2007
2008/** Create a widget with the command parameters inside
2009 @param command: command line
2010 @parent : parent widget
2011 @isDialog : true if we want apply/cancel button and close at end, false if we want only apply
2012*/
2013bool G4UIQt::CreateCommandWidget(G4UIcommand* aCommand, QWidget* aParent, bool isDialog) {
2014
2015 if (aCommand == NULL) {
2016 return false;
2017 }
2018
2019
2020 // parameters
2021 G4int n_parameterEntry = aCommand->GetParameterEntries();
2022 if( n_parameterEntry > 0 ) {
2023 G4UIparameter *param;
2024
2025 // Re-implementation of G4UIparameter.cc
2026 QWidget* paramWidget = new QWidget();
2027 QGridLayout* gridLayout = new QGridLayout(paramWidget);
2028
2029 // Special case for colour, try to display a color chooser if we found red/green/blue parameter
2030 unsigned int nbColorParameter = 0;
2031 bool isStillColorParameter = false;
2032 bool isColorDialogAdded = false;
2033 QLabel* redLabel = NULL;
2034 QLabel* greenLabel = NULL;
2035 QString redDefaultStr = "";
2036 QString greenDefaultStr = "";
2037 QString blueDefaultStr = "";
2038 QWidget* redInput = NULL;
2039 QWidget* greenInput = NULL;
2040
2041 for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
2042 QString txt;
2043 param = aCommand->GetParameter(i_thParameter);
2044 QLabel* label = new QLabel(QString((char*)(param->GetParameterName()).data()));
2045
2046 if ((label->text() == "red") || (label->text() == "red_or_string")){
2047 nbColorParameter ++;
2048 isStillColorParameter = true;
2049 } else if ((label->text() == "green") && isStillColorParameter) {
2050 nbColorParameter ++;
2051 } else if ((label->text() == "blue") && isStillColorParameter) {
2052 nbColorParameter ++;
2053 } else if (!isColorDialogAdded) {
2054
2055 // not following red/green/blue parameters ?
2056 if (nbColorParameter == 1) {
2057 gridLayout->addWidget(redLabel,i_thParameter-1,0);
2058 gridLayout->addWidget(redInput,i_thParameter-1,1);
2059 } else if (nbColorParameter == 2) {
2060 gridLayout->addWidget(redLabel,i_thParameter-2,0);
2061 gridLayout->addWidget(redInput,i_thParameter-2,1);
2062 gridLayout->addWidget(greenLabel,i_thParameter-1,0);
2063 gridLayout->addWidget(greenInput,i_thParameter-1,1);
2064 }
2065 nbColorParameter = 0;
2066 }
2067 // Check parameter type, could be NULL if not found
2068 QWidget* input = NULL;
2069 if ((QString(QChar(param->GetParameterType())) == "d") || (QString(QChar(param->GetParameterType())) == "i")) {
2070 input = new QLineEdit();
2071 // set default value
2072 dynamic_cast<QLineEdit*>(input)->setText(QString((char*)(param->GetDefaultValue()).data()));
2073
2074 if (((label->text() == "red") || (label->text() == "red_or_string")) && isStillColorParameter) {
2075 redDefaultStr = QString((char*)(param->GetDefaultValue()).data());
2076 } else if ((label->text() == "green") && isStillColorParameter) {
2077 greenDefaultStr = QString((char*)(param->GetDefaultValue()).data());
2078 } else if ((label->text() == "green") && isStillColorParameter) {
2079 blueDefaultStr = QString((char*)(param->GetDefaultValue()).data());
2080 }
2081
2082 } else if (QString(QChar(param->GetParameterType())) == "b") {
2083 input = new QWidget();
2084 QHBoxLayout* layout = new QHBoxLayout(input);
2085
2086 QButtonGroup* buttons = new QButtonGroup();
2087 QRadioButton* radioOff = new QRadioButton("0");
2088 QRadioButton* radioOn = new QRadioButton("1");
2089 buttons->addButton(radioOn);
2090 buttons->addButton(radioOff);
2091 layout->addWidget(radioOn);
2092 layout->addWidget(radioOff);
2093
2094 // set default value
2095 QString defaultValue = QString((char*)(param->GetDefaultValue()).data());
2096 if (defaultValue == "0") {
2097 radioOff->setChecked(true);
2098 } else if (defaultValue == "1") {
2099 radioOn->setChecked(true);
2100 }
2101 } else if ((QString(QChar(param->GetParameterType())) == "s") && (!param->GetParameterCandidates().isNull())) {
2102 input = new QComboBox();
2103 QString candidates = QString((char*)(param->GetParameterCandidates()).data());
2104 QStringList list = candidates.split (" ");
2105
2106 // add all candidates to widget
2107 QString defaultValue = QString((char*)(param->GetDefaultValue()).data());
2108 for (int a=0; a<list.size(); a++) {
2109 dynamic_cast<QComboBox*>(input)->addItem(list.at(a));
2110 if (list.at(a) == defaultValue) {
2111 dynamic_cast<QComboBox*>(input)->setCurrentIndex(a);
2112 }
2113 }
2114
2115 } else if ((QString(QChar(param->GetParameterType())) == "s")) { // string
2116 input = new QLineEdit();
2117 // set default value
2118 dynamic_cast<QLineEdit*>(input)->setText(QString((char*)(param->GetDefaultValue()).data()));
2119
2120 } else if ((QString(QChar(param->GetParameterType())) == "c")) { // on/off
2121 input = new QWidget();
2122 QHBoxLayout* layout = new QHBoxLayout(input);
2123
2124 QButtonGroup* buttons = new QButtonGroup();
2125 QRadioButton* radioOff = new QRadioButton("off");
2126 QRadioButton* radioOn = new QRadioButton("on");
2127 buttons->addButton(radioOn);
2128 buttons->addButton(radioOff);
2129 layout->addWidget(radioOn);
2130 layout->addWidget(radioOff);
2131
2132 // set default value
2133 QString defaultValue = QString((char*)(param->GetDefaultValue()).data());
2134 if (defaultValue == "off") {
2135 radioOff->setChecked(true);
2136 } else if (defaultValue == "on") {
2137 radioOn->setChecked(true);
2138 }
2139
2140 } else {
2141 input = new QLineEdit();
2142 dynamic_cast<QLineEdit*>(input)->setText(QString((char*)(param->GetDefaultValue()).data()));
2143 }
2144
2145 txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
2146 if( ! param->GetParameterGuidance().isNull() )
2147 txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
2148
2149 txt += " Parameter type : " + QString(QChar(param->GetParameterType())) + "\n";
2150 if(param->IsOmittable()){
2151 txt += " Omittable : True\n";
2152 } else {
2153 txt += " Omittable : False\n";
2154 }
2155 if( param->GetCurrentAsDefault() ) {
2156 txt += " Default value : taken from the current value\n";
2157 } else if( ! param->GetDefaultValue().isNull() ) {
2158 txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n";
2159 }
2160 if( ! param->GetParameterRange().isNull() ) {
2161 txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
2162 }
2163 if( ! param->GetParameterCandidates().isNull() ) {
2164 txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
2165 }
2166
2167 if (isStillColorParameter && (nbColorParameter != 0)) {
2168 if ((label->text() == "red") || (label->text() == "red_or_string")) {
2169 redLabel = label;
2170 redInput = input;
2171 } else if (label->text() == "green") {
2172 greenLabel = label;
2173 greenInput = input;
2174 } else if (label->text() == "blue") {
2175
2176 // we have all, then add a color chooser
2177
2178 // Create a pixmap with the default color
2179 QColor qc;
2180 if ((redDefaultStr != "") && (redDefaultStr != "") && (redDefaultStr != "")) {
2181 qc.setRgbF(redDefaultStr.toDouble(),
2182 greenDefaultStr.toDouble(),
2183 blueDefaultStr.toDouble());
2184 }
2185 QPixmap pixmap = QPixmap(QSize(16, 16));
2186 pixmap.fill (qc);
2187 QPainter painter(&pixmap);
2188 painter.setPen(Qt::black);
2189 painter.drawRect(0,0,15,15); // Draw contour
2190
2191 input = new QPushButton("Change color");
2192 dynamic_cast<QPushButton*>(input)->setIcon(pixmap);
2193 dynamic_cast<QPushButton*>(input)->setAccessibleName(redDefaultStr+" "+greenDefaultStr+" "+blueDefaultStr);
2194 label = new QLabel("Choose color");
2195
2196 // less 1 because we have to add one to the row number
2197 nbColorParameter--;
2198 gridLayout->addWidget(label,i_thParameter-nbColorParameter,0);
2199 input->setToolTip("Select the current color");
2200 gridLayout->addWidget(input,i_thParameter-nbColorParameter,1);
2201
2202 // Connect pushButton to ColorDialog in callback
2203 QSignalMapper* signalMapper = new QSignalMapper(this);
2204 signalMapper->setMapping(input,input);
2205 connect(input, SIGNAL(clicked()), signalMapper, SLOT(map()));
2206 connect(signalMapper, SIGNAL(mapped(QWidget*)),this, SLOT(ChangeColorCallback(QWidget*)));
2207
2208 isColorDialogAdded = true;
2209 isStillColorParameter = false;
2210 }
2211 } else {
2212 gridLayout->addWidget(label,i_thParameter-nbColorParameter,0);
2213 input->setToolTip(txt);
2214 gridLayout->addWidget(input,i_thParameter-nbColorParameter,1);
2215 }
2216 }
2217 // add command name in hidden value at last line position 0
2218 QLabel* name = new QLabel(QString((char*)(aCommand->GetCommandPath().data())));
2219 name->hide();
2220 gridLayout->addWidget(name,n_parameterEntry-nbColorParameter,0);
2221
2222 QPushButton* applyButton = new QPushButton("Apply");
2223 if (!isDialog) {
2224
2225 gridLayout->addWidget(applyButton,n_parameterEntry-nbColorParameter,1);
2226
2227 QSignalMapper* signalMapper = new QSignalMapper(this);
2228 signalMapper->setMapping(applyButton, paramWidget);
2229 connect(applyButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
2230 connect(signalMapper, SIGNAL(mapped(QWidget*)),this, SLOT(VisParameterCallback(QWidget*)));
2231 } else {
2232 // Apply/Cancel buttons
2233
2234 applyButton->setAutoDefault( TRUE );
2235 applyButton->setDefault( TRUE );
2236 gridLayout->addWidget(applyButton,n_parameterEntry-nbColorParameter,0);
2237
2238 QPushButton* cancelButton = new QPushButton( tr( "&Cancel" ));
2239 cancelButton->setAutoDefault( TRUE );
2240 gridLayout->addWidget(cancelButton,n_parameterEntry-nbColorParameter,1);
2241
2242 QSignalMapper* signalMapper = new QSignalMapper(this);
2243 signalMapper->setMapping(applyButton, paramWidget);
2244 connect(applyButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
2245 connect(signalMapper, SIGNAL(mapped(QWidget*)),this, SLOT(VisParameterCallback(QWidget*)));
2246
2247 QWidget * parentCheck = aParent;
2248 QDialog* parentDialog = NULL;
2249 bool found = false;
2250 while ((parentCheck->parentWidget()) != NULL) {
2251 parentCheck = parentCheck->parentWidget();
2252 parentDialog = dynamic_cast<QDialog*>(parentCheck);
2253 if (parentDialog) {
2254 connect( applyButton, SIGNAL( clicked() ), parentDialog, SLOT( accept() ) );
2255 connect( cancelButton, SIGNAL( clicked() ), parentDialog, SLOT( reject() ) );
2256 found = true;
2257 }
2258 }
2259 if (!found) {
2260 return false;
2261 }
2262 }
2263
2264 if (!aParent->layout()) {
2265 aParent->setLayout(new QVBoxLayout());
2266 }
2267 aParent->layout()->addWidget(paramWidget);
2268 }
2269
2270 return true;
2271}
2272
2273
2274/** Find a treeItemWidget in the help tree
2275 @param aCommand item's String to look for
2276 @return item if found, NULL if not
2277*/
2278QTreeWidgetItem* G4UIQt::FindTreeItem(
2279 QTreeWidgetItem *aParent
2280,const QString& aCommand
2281)
2282{
2283 if (aParent == NULL) return NULL;
2284
2285 // Suppress last "/"
2286 QString myCommand = aCommand;
2287
2288 if (myCommand.lastIndexOf("/") == (myCommand.size()-1)) {
2289 myCommand = myCommand.left(myCommand.size()-1);
2290 }
2291
2292 if (GetLongCommandPath(aParent) == myCommand)
2293 return aParent;
2294
2295 QTreeWidgetItem * tmp = NULL;
2296 for (int a=0;a<aParent->childCount();a++) {
2297 if (!tmp)
2298 tmp = FindTreeItem(aParent->child(a),myCommand);
2299 }
2300 return tmp;
2301}
2302
2303
2304
2305/** Build the command list parameters in a QString<br>
2306 Reimplement partialy the G4UIparameter.cc
2307 @param aCommand : command to list parameters
2308 @see G4UIparameter::List()
2309 @see G4UIcommand::List()
2310 @return the command list parameters, or "" if nothing
2311*/
2312QString G4UIQt::GetCommandList (
2313 const G4UIcommand *aCommand
2314)
2315{
2316
2317 QString txt ="";
2318 if (aCommand == NULL)
2319 return txt;
2320
2321 G4String commandPath = aCommand->GetCommandPath();
2322 G4String rangeString = aCommand->GetRange();
2323 G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
2324 G4int n_parameterEntry = aCommand->GetParameterEntries();
2325
2326 if ((commandPath == "") &&
2327 (rangeString == "") &&
2328 (n_guidanceEntry == 0) &&
2329 (n_parameterEntry == 0)) {
2330 return txt;
2331 }
2332
2333 if((commandPath.length()-1)!='/') {
2334 txt += "Command " + QString((char*)(commandPath).data()) + "\n";
2335 }
2336 txt += "Guidance :\n";
2337
2338 for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
2339 txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
2340 }
2341 if( ! rangeString.isNull() ) {
2342 txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n";
2343 }
2344 if( n_parameterEntry > 0 ) {
2345 G4UIparameter *param;
2346
2347 // Re-implementation of G4UIparameter.cc
2348
2349 for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
2350 param = aCommand->GetParameter(i_thParameter);
2351 txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
2352 if( ! param->GetParameterGuidance().isNull() )
2353 txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
2354 txt += " Parameter type : " + QString(QChar(param->GetParameterType())) + "\n";
2355 if(param->IsOmittable()){
2356 txt += " Omittable : True\n";
2357 } else {
2358 txt += " Omittable : False\n";
2359 }
2360 if( param->GetCurrentAsDefault() ) {
2361 txt += " Default value : taken from the current value\n";
2362 } else if( ! param->GetDefaultValue().isNull() ) {
2363 txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n";
2364 }
2365 if( ! param->GetParameterRange().isNull() ) {
2366 txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
2367 }
2368 if( ! param->GetParameterCandidates().isNull() ) {
2369 txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
2370 }
2371 }
2372 }
2373 return txt;
2374}
2375
2376
2377/**
2378 Return true if this command takes almost a number (int, double, bool,
2379 string) as an input
2380 or a string with a candidate list
2381 */
2382G4bool G4UIQt::IsGUICommand(
2383 const G4UIcommand *aCommand
2384)
2385{
2386 if (aCommand == NULL)
2387 return false;
2388
2389 G4int n_parameterEntry = aCommand->GetParameterEntries();
2390
2391 if( n_parameterEntry > 0 ) {
2392 G4UIparameter *param;
2393
2394 // Re-implementation of G4UIparameter.cc
2395
2396 for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
2397 param = aCommand->GetParameter(i_thParameter);
2398 if (QString(QChar(param->GetParameterType())) == "d") {
2399 return true;
2400 }
2401 if (QString(QChar(param->GetParameterType())) == "b") {
2402 return true;
2403 }
2404 if (QString(QChar(param->GetParameterType())) == "i") {
2405 return true;
2406 }
2407 if (QString(QChar(param->GetParameterType())) == "s" && (!param->GetParameterCandidates().isNull())) {
2408 return true;
2409 }
2410 }
2411 }
2412 return false;
2413}
2414
2415
2416/** Implement G4VBasicShell vurtual function
2417 */
2418G4bool G4UIQt::GetHelpChoice(
2419 G4int&
2420)
2421{
2422#ifdef G4DEBUG_INTERFACES_BASIC
2423 printf("G4UIQt::GetHelpChoice SHOULD NEVER GO HERE");
2424#endif
2425 return true;
2426}
2427
2428
2429/** Event filter method. Every event from QtApplication goes here.<br/>
2430 We apply a filter only for the Up and Down Arrow press when the QLineEdit<br/>
2431 is active. If this filter match, Up arrow we give the previous command<br/>
2432 and Down arrow will give the next if exist.<br/>
2433 @param obj Emitter of the event
2434 @param event Kind of event
2435*/
2436bool G4UIQt::eventFilter( // Should stay with a minuscule eventFilter because of Qt
2437 QObject *aObj
2438,QEvent *aEvent
2439)
2440{
2441 bool moveCommandCursor = false;
2442 if (aObj == NULL) return false;
2443 if (aEvent == NULL) return false;
2444
2445 if (aObj == fHistoryTBTableList) {
2446 if (aEvent->type() == QEvent::KeyPress) {
2447 fCommandArea->setFocus();
2448 }
2449 }
2450 if (aObj == fCommandArea) {
2451 if (aEvent->type() == QEvent::KeyPress) {
2452 QKeyEvent *e = static_cast<QKeyEvent*>(aEvent);
2453 if ((e->key() == (Qt::Key_Down)) ||
2454 (e->key() == (Qt::Key_PageDown)) ||
2455 (e->key() == (Qt::Key_Up)) ||
2456 (e->key() == (Qt::Key_PageUp))) {
2457 int selection = fHistoryTBTableList->currentRow();
2458 if (fHistoryTBTableList->count()) {
2459 if (selection == -1) {
2460 selection = fHistoryTBTableList->count()-1;
2461 } else {
2462 if (e->key() == (Qt::Key_Down)) {
2463 if (selection <(fHistoryTBTableList->count()-1))
2464 selection++;
2465 } else if (e->key() == (Qt::Key_PageDown)) {
2466 selection = fHistoryTBTableList->count()-1;
2467 } else if (e->key() == (Qt::Key_Up)) {
2468 if (selection >0)
2469 selection --;
2470 } else if (e->key() == (Qt::Key_PageUp)) {
2471 selection = 0;
2472 }
2473 }
2474 fHistoryTBTableList->clearSelection();
2475#if QT_VERSION < 0x040202
2476 fHistoryTBTableList->setItemSelected(fHistoryTBTableList->item(selection),true);
2477#else
2478 fHistoryTBTableList->item(selection)->setSelected(true);
2479#endif
2480 fHistoryTBTableList->setCurrentItem(fHistoryTBTableList->item(selection));
2481 }
2482 moveCommandCursor = true;
2483 } else if (e->key() == (Qt::Key_Tab)) {
2484 G4String ss = Complete(fCommandArea->text().toStdString().c_str());
2485 fCommandArea->setText((char*)(ss.data()));
2486
2487 // do not pass by parent, it will disable widget tab focus !
2488 return true;
2489 // L.Garnier : MetaModifier is CTRL for MAC, but I don't want to put a MAC
2490 // specific #ifdef
2491 } else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_A)) {
2492 fCommandArea->home(false);
2493 return true;
2494 } else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_E)) {
2495 fCommandArea->end(false);
2496 return true;
2497 }
2498 }
2499 }
2500 bool res= false;
2501 // change cursor position if needed
2502 if (moveCommandCursor == true) {
2503#ifdef G4DEBUG_INTERFACES_BASIC
2504 printf("G4UIQt::eventFilter setCursor Position\n");
2505#endif
2506 fCommandArea->setCursorPosition ( fCommandArea->text().length() );
2507 fCommandArea->setCursorPosition (4);
2508 } else {
2509 // pass the event on to the parent class
2510 res = QObject::eventFilter(aObj, aEvent);
2511 }
2512 return res;
2513}
2514
2515
2516
2517
2518/***************************************************************************/
2519//
2520// SLOTS DEFINITIONS
2521//
2522/***************************************************************************/
2523
2524/** Called when user give "help" command.
2525*/
2526void G4UIQt::ShowHelpCallback (
2527)
2528{
2529 TerminalHelp("");
2530}
2531
2532
2533/** Called when user click on clear button. Clear the text Output area
2534*/
2535void G4UIQt::ClearButtonCallback (
2536)
2537{
2538 fCoutTBTextArea->clear();
2539 fG4cout.clear();
2540}
2541
2542/** Called when user exit session
2543*/
2544void G4UIQt::ExitSession (
2545)
2546{
2547 SessionTerminate();
2548}
2549
2550void G4UIQt::ExitHelp(
2551) const
2552{
2553}
2554
2555/** Callback call when "click on a menu entry.<br>
2556 Send the associated command to geant4
2557*/
2558void G4UIQt::CommandEnteredCallback (
2559)
2560{
2561 G4String command (fCommandArea->text().toStdString().c_str());
2562 if (fCommandArea->text().trimmed() != "") {
2563 fHistoryTBTableList->addItem(fCommandArea->text());
2564 fHistoryTBTableList->clearSelection();
2565 fHistoryTBTableList->setCurrentItem(NULL);
2566 fCommandArea->setText("");
2567
2568 G4Qt* interactorManager = G4Qt::getInstance ();
2569 if (interactorManager) {
2570 interactorManager->FlushAndWaitExecution();
2571 }
2572 if (command(0,4) != "help") {
2573 ApplyShellCommand (command,exitSession,exitPause);
2574 } else {
2575 ActivateCommand(command);
2576 }
2577 // Rebuild help tree
2578 FillHelpTree();
2579
2580 if(exitSession==true)
2581 SessionTerminate();
2582 }
2583}
2584
2585
2586/** Callback when one of the scene/vis parameters has changed
2587 */
2588void G4UIQt::VisParameterCallback(QWidget* widget){
2589 if (widget == NULL) {
2590 return;
2591 }
2592
2593 // Look in all the Grid layout, but only column 1 (0 is the parameter name)
2594 QGridLayout* grid = dynamic_cast<QGridLayout*>(widget->layout());
2595 if (grid == 0) {
2596 return;
2597 }
2598 QString command;
2599#if QT_VERSION < 0x040400
2600 QWidget* name = grid->itemAt(grid->columnCount()*(grid->rowCount()-2))->widget();
2601#else
2602 QWidget* name = grid->itemAtPosition(grid->rowCount()-1,0)->widget();
2603#endif
2604 if (widget == NULL) {
2605 return;
2606 }
2607 if (dynamic_cast<QLabel*>(name) == 0) {
2608 return;
2609 }
2610 command += (dynamic_cast<QLabel*>(name))->text()+" ";
2611
2612 for (int a=0;a<grid->rowCount()-1; a++) {
2613#if QT_VERSION < 0x040400
2614 QWidget* widgetTmp = grid->itemAt(a*grid->columnCount()+1)->widget();
2615#else
2616 QWidget* widgetTmp = grid->itemAtPosition(a,1)->widget();
2617#endif
2618
2619 // 4 kind of widgets : QLineEdit / QComboBox / radioButtonsGroup / QPushButton (color chooser)
2620 if (widgetTmp != NULL) {
2621
2622 if (dynamic_cast<QLineEdit*>(widgetTmp) != 0) {
2623 command += (dynamic_cast<QLineEdit*>(widgetTmp))->text()+" ";
2624
2625 } else if (dynamic_cast<QComboBox*>(widgetTmp) != 0){
2626 command += (dynamic_cast<QComboBox*>(widgetTmp))->itemText((dynamic_cast<QComboBox*>(widgetTmp))->currentIndex())+" ";
2627
2628 // Color chooser
2629 } else if (dynamic_cast<QPushButton*>(widgetTmp) != 0){
2630 command += widgetTmp->accessibleName()+" ";
2631
2632 // Check for Button group
2633 } else if (dynamic_cast<QWidget*>(widgetTmp) != 0){
2634 if (widgetTmp->layout()->count() > 0){
2635 if (dynamic_cast<QRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()) != 0) {
2636 QAbstractButton * checked = (dynamic_cast<QRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()))->group()->checkedButton();
2637 if (checked != 0) {
2638 command += (dynamic_cast<QRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()))->group()->checkedButton()->text()+" ";
2639 }
2640 }
2641 }
2642
2643 }
2644 }
2645 }
2646 if (command != "") {
2648 if(UI != NULL) {
2649 UI->ApplyCommand(command.toStdString().c_str());
2650 }
2651 }
2652}
2653
2654
2655/** Callback call when "enter" clicked on the command zone.<br>
2656 If command has no parameters :send the command to geant4
2657 Else, open a dialog for parameters input
2658 @param aCommand
2659*/
2660void G4UIQt::ButtonCallback (
2661 const QString& aCommand
2662)
2663{
2664 G4String ss = G4String(aCommand.toStdString().c_str());
2665 ss = ss.strip(G4String::leading);
2666
2668 if(UI==NULL) return;
2669 G4UIcommandTree * treeTop = UI->GetTree();
2670
2671 G4UIcommand* command = treeTop->FindPath(ss);
2672
2673 if (command) {
2674 // if is GUI, then open a dialog
2675 if (IsGUICommand(command)) {
2676 QDialog* menuParameterDialog = new QDialog();
2677
2678 if (CreateVisCommandGroupAndToolBox(command,menuParameterDialog,1,true)) {
2679 menuParameterDialog->setWindowTitle (aCommand);
2680 menuParameterDialog->setSizePolicy (QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
2681
2682 // exec this dialog, apply the command automaticaly, and return
2683 menuParameterDialog->exec();
2684 return;
2685 }
2686 }
2687 }
2688
2689 ApplyShellCommand(ss,exitSession,exitPause);
2690
2691 // Rebuild help tree
2692 FillHelpTree();
2693
2694 if(exitSession==true)
2695 SessionTerminate();
2696}
2697
2698
2699
2700/** This callback is activated when user selected a item in the help tree
2701*/
2702void G4UIQt::HelpTreeClicCallback (
2703)
2704{
2705 QTreeWidgetItem* item = NULL;
2706 if (!fHelpTreeWidget)
2707 return ;
2708
2709 if (!fHelpArea)
2710 return;
2711
2712 QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
2713 if (list.isEmpty())
2714 return;
2715 item = list.first();
2716 if (!item)
2717 return;
2718
2720 if(UI==NULL) return;
2721 G4UIcommandTree * treeTop = UI->GetTree();
2722
2723 std::string itemText = GetLongCommandPath(item).toStdString();
2724
2725 G4UIcommand* command = treeTop->FindPath(itemText.c_str());
2726
2727 if (command) {
2728 #if QT_VERSION < 0x040200
2729 fHelpArea->clear();
2730 fHelpArea->append(GetCommandList(command));
2731 #else
2732 fHelpArea->setText(GetCommandList(command));
2733 #endif
2734 } else { // this is a command
2735 G4UIcommandTree* path = treeTop->FindCommandTree(itemText.c_str());
2736 if ( path) {
2737 // this is not a command, this is a sub directory
2738 // We display the Title
2739 #if QT_VERSION < 0x040200
2740 fHelpArea->clear();
2741 fHelpArea->append(path->GetTitle().data());
2742 #else
2743 fHelpArea->setText(path->GetTitle().data());
2744 #endif
2745 }
2746 }
2747}
2748
2749/** This callback is activated when user double clic on a item in the help tree
2750*/
2751void G4UIQt::HelpTreeDoubleClicCallback (
2752)
2753{
2754 HelpTreeClicCallback();
2755
2756 QTreeWidgetItem* item = NULL;
2757 if (!fHelpTreeWidget)
2758 return ;
2759
2760 if (!fHelpArea)
2761 return;
2762
2763 QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
2764 if (list.isEmpty())
2765 return;
2766 item = list.first();
2767 if (!item)
2768 return;
2769
2770 fCommandArea->clear();
2771 fCommandArea->setText(GetLongCommandPath(item));
2772}
2773
2774
2775/** Callback called when user select an old command in the command history<br>
2776 Give it to the command area.
2777*/
2778void G4UIQt::CommandHistoryCallback(
2779)
2780{
2781 QListWidgetItem* item = NULL;
2782 if (!fHistoryTBTableList)
2783 return ;
2784
2785
2786 QList<QListWidgetItem *> list =fHistoryTBTableList->selectedItems();
2787 if (list.isEmpty())
2788 return;
2789 item = list.first();
2790 if (!item)
2791 return;
2792 fCommandArea->setText(item->text());
2793#ifdef G4DEBUG_INTERFACES_BASIC
2794 printf("G4UIQt::CommandHistoryCallback change text\n");
2795#endif
2796}
2797
2798
2799void G4UIQt::CoutFilterCallback(
2800const QString & text) {
2801
2802 QStringList result = fG4cout.filter(text);
2803 fCoutTBTextArea->setPlainText(result.join("\n"));
2804
2805 fCoutTBTextArea->repaint();
2806 fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
2807
2808 }
2809
2810/** Callback called when user give a new string to look for<br>
2811 Display a list of matching commands descriptions. If no string is set,
2812 will display the complete help tree
2813*/
2814void G4UIQt::LookForHelpStringCallback(
2815)
2816{
2817 QString searchText = fHelpLine->text();
2818
2819#if QT_VERSION < 0x040200
2820 fHelpArea->clear();
2821#else
2822 fHelpArea->setText("");
2823#endif
2824 if (searchText =="") {
2825 // clear old help tree
2826 fHelpTreeWidget->clear();
2827
2828 FillHelpTree();
2829
2830 return;
2831 } else {
2832 OpenHelpTreeOnCommand(searchText);
2833 }
2834}
2835
2836
2837void G4UIQt::OpenHelpTreeOnCommand(
2838 const QString & searchText
2839)
2840{
2841 // the help tree
2843 if(UI==NULL) return;
2844 G4UIcommandTree * treeTop = UI->GetTree();
2845
2846 G4int treeSize = treeTop->GetTreeEntry();
2847
2848 // clear old help tree
2849 fHelpTreeWidget->clear();
2850
2851 // look for new items
2852
2853 int tmp = 0;
2854
2855 QMap<int,QString> commandResultMap;
2856 QMap<int,QString> commandChildResultMap;
2857
2858 for (int a=0;a<treeSize;a++) {
2859 G4UIcommand* command = treeTop->FindPath(treeTop->GetTree(a+1)->GetPathName().data());
2860 tmp = GetCommandList (command).count(searchText,Qt::CaseInsensitive);
2861 if (tmp >0) {
2862 commandResultMap.insertMulti(tmp,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()));
2863 }
2864 // look for childs
2865 commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a+1),searchText);
2866 // insert new childs
2867 if (!commandChildResultMap.empty()) {
2868 QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
2869 while (i != commandChildResultMap.constEnd()) {
2870 commandResultMap.insertMulti(i.key(),i.value());
2871 i++;
2872 }
2873 commandChildResultMap.clear();
2874 }
2875 }
2876
2877 // build new help tree
2878 fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
2879 fHelpTreeWidget->setColumnCount(2);
2880 QStringList labels;
2881 labels << QString("Command") << QString("Match");
2882 fHelpTreeWidget->setHeaderLabels(labels);
2883
2884 if (commandResultMap.empty()) {
2885#if QT_VERSION < 0x040200
2886 fHelpArea->clear();
2887 fHelpArea->append("No match found");
2888#else
2889 fHelpArea->setText("No match found");
2890#endif
2891 return;
2892 }
2893
2894 QMap<int,QString>::const_iterator i = commandResultMap.constEnd();
2895 i--;
2896 // 10 maximum progress values
2897 float multValue = 10.0/(float)(i.key());
2898 QString progressChar = "|";
2899 QString progressStr = "|";
2900
2901 QTreeWidgetItem * newItem;
2902 bool end = false;
2903 while (!end) {
2904 if (i == commandResultMap.constBegin()) {
2905 end = true;
2906 }
2907 for(int a=0;a<int(i.key()*multValue);a++) {
2908 progressStr += progressChar;
2909 }
2910 newItem = new QTreeWidgetItem(fHelpTreeWidget);
2911 QString commandStr = i.value().trimmed();
2912
2913 if (commandStr.indexOf("/") == 0) {
2914 commandStr = commandStr.right(commandStr.size()-1);
2915 }
2916
2917 newItem->setText(0,commandStr);
2918 newItem->setText(1,progressStr);
2919
2920#if QT_VERSION < 0x040200
2921#else
2922 newItem->setForeground ( 1, QBrush(Qt::blue) );
2923#endif
2924 progressStr = "|";
2925 i--;
2926 }
2927 fHelpTreeWidget->resizeColumnToContents (0);
2928 fHelpTreeWidget->sortItems(1,Qt::DescendingOrder);
2929 // fHelpTreeWidget->setColumnWidth(1,10);//resizeColumnToContents (1);
2930}
2931
2932
2933
2934
2935QMap<int,QString> G4UIQt::LookForHelpStringInChildTree(
2936 G4UIcommandTree *aCommandTree
2937,const QString & text
2938 )
2939{
2940 QMap<int,QString> commandResultMap;
2941 if (aCommandTree == NULL) return commandResultMap;
2942
2943
2944 // Get the Sub directories
2945 int tmp = 0;
2946 QMap<int,QString> commandChildResultMap;
2947
2948 for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
2949 const G4UIcommand* command = aCommandTree->GetGuidance();
2950 tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
2951 if (tmp >0) {
2952 commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()));
2953 }
2954 // look for childs
2955 commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text);
2956
2957 if (!commandChildResultMap.empty()) {
2958 // insert new childs
2959 QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
2960 while (i != commandChildResultMap.constEnd()) {
2961 commandResultMap.insertMulti(i.key(),i.value());
2962 i++;
2963 }
2964 commandChildResultMap.clear();
2965 }
2966 }
2967 // Get the Commands
2968
2969 for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
2970 const G4UIcommand* command = aCommandTree->GetCommand(a+1);
2971 tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
2972 if (tmp >0) {
2973 commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()));
2974 }
2975
2976 }
2977 return commandResultMap;
2978}
2979
2980
2981QString G4UIQt::GetShortCommandPath(
2982QString commandPath
2983)
2984{
2985 if (commandPath.indexOf("/") == 0) {
2986 commandPath = commandPath.right(commandPath.size()-1);
2987 }
2988
2989 commandPath = commandPath.right(commandPath.size()-commandPath.lastIndexOf("/",-2)-1);
2990
2991 if (commandPath.lastIndexOf("/") == (commandPath.size()-1)) {
2992 commandPath = commandPath.left(commandPath.size()-1);
2993 }
2994
2995 return commandPath;
2996}
2997
2998
2999QString G4UIQt::GetLongCommandPath(
3000 QTreeWidgetItem* item
3001)
3002{
3003 if (item == NULL) return "";
3004
3005 // rebuild path:
3006 QString itemText = "";
3007 itemText = item->text(0);
3008
3009 while (item->parent() != NULL) {
3010 itemText = item->parent()->text(0)+"/"+itemText;
3011 item = item->parent();
3012 }
3013 itemText = "/"+itemText;
3014
3015 return itemText;
3016}
3017
3018
3019void G4UIQt::ChangeColorCallback(QWidget* widget) {
3020 if (widget == NULL) {
3021 return;
3022 }
3023
3024 QPushButton* button = dynamic_cast<QPushButton*>(widget);
3025 if (button == 0) {
3026 return;
3027 }
3028 QString value = button->accessibleName();
3029
3030 QColor old;
3031 old.setRgbF(value.section(" ",0,1).toDouble(),
3032 value.section(" ",1,2).toDouble(),
3033 value.section(" ",2,3).toDouble());
3034#if QT_VERSION < 0x040500
3035 bool a;
3036 QColor color = QColor(QColorDialog::getRgba (old.rgba(),&a,fUITabWidget));
3037#else
3038 QColor color = QColorDialog::getColor(old,
3039 fUITabWidget,
3040 "Change color",
3041 QColorDialog::ShowAlphaChannel);
3042#endif
3043
3044
3045 if (color.isValid()) {
3046 // rebuild the widget icon
3047 QPixmap pixmap = QPixmap(QSize(16, 16));
3048 pixmap.fill (color);
3049 QPainter painter(&pixmap);
3050 painter.setPen(Qt::black);
3051 painter.drawRect(0,0,15,15); // Draw contour
3052
3053 button->setAccessibleName(QString::number(color.redF())+" "+
3054 QString::number(color.greenF())+" "+
3055 QString::number(color.blueF())+" "
3056 );
3057 button->setIcon(pixmap);
3058
3059
3060 }
3061}
3062
3063
3064void G4UIQt::ChangeCursorStyle(const QString& action) {
3065
3066 // Theses actions should be in the app toolbar
3067
3068 fMoveSelected = true;
3069 fPickSelected = true;
3070 fRotateSelected = true;
3071 fZoomInSelected = true;
3072 fZoomOutSelected = true;
3073
3074 if (fToolbarApp == NULL) return;
3075 QList<QAction *> list = fToolbarApp->actions ();
3076 for (int i = 0; i < list.size(); ++i) {
3077 if (list.at(i)->data().toString () == action) {
3078 list.at(i)->setChecked(TRUE);
3079 } else if (list.at(i)->data().toString () == "move") {
3080 fMoveSelected = false;
3081 list.at(i)->setChecked(FALSE);
3082 } else if (list.at(i)->data().toString () == "pick") {
3083 fPickSelected = false;
3084 list.at(i)->setChecked(FALSE);
3085 } else if (list.at(i)->data().toString () == "rotate") {
3086 fRotateSelected = false;
3087 list.at(i)->setChecked(FALSE);
3088 } else if (list.at(i)->data().toString () == "zoom_in") {
3089 fZoomInSelected = false;
3090 list.at(i)->setChecked(FALSE);
3091 } else if (list.at(i)->data().toString () == "zoom_out") {
3092 fZoomOutSelected = false;
3093 list.at(i)->setChecked(FALSE);
3094 }
3095 }
3096 // FIXME : Should connect this to Vis
3097}
3098
3099
3100/* A little bit like "void G4OpenGLQtViewer::toggleDrawingAction(int aAction)"
3101 But for all viewers, not only Qt
3102
3103FIXME : Should be a feedback when changing viewer !
3104
3105 */
3106void G4UIQt::ChangeSurfaceStyle(const QString& action) {
3107
3108 // Theses actions should be in the app toolbar
3109
3110 if (fToolbarApp == NULL) return;
3111 QList<QAction *> list = fToolbarApp->actions ();
3112 for (int i = 0; i < list.size(); ++i) {
3113 if (list.at(i)->data().toString () == action) {
3114 list.at(i)->setChecked(TRUE);
3115 } else if (list.at(i)->data().toString () == "hidden_line_removal") {
3116 list.at(i)->setChecked(FALSE);
3117 } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3118 list.at(i)->setChecked(FALSE);
3119 } else if (list.at(i)->data().toString () == "solid") {
3120 list.at(i)->setChecked(FALSE);
3121 } else if (list.at(i)->data().toString () == "wireframe") {
3122 list.at(i)->setChecked(FALSE);
3123 }
3124 }
3125 // FIXME : Should connect this to Vis
3126
3127 if (action == "hidden_line_removal") {
3128 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style w");
3129 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 1");
3130
3131 } else if (action == "hidden_line_and_surface_removal") {
3132 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style s");
3133 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 1");
3134
3135 } else if (action == "solid") {
3136 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style s");
3137 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 0");
3138
3139 } else if (action == "wireframe") {
3140 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style w");
3141 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 0");
3142 }
3143}
3144
3145
3146void G4UIQt::OpenIconCallback(const QString& aCommand) {
3147
3148 QString nomFich = QFileDialog::getOpenFileName(fMainWindow, "Load", "vis", "Macro files (*.mac)");
3149 if (nomFich != "") {
3150 G4UImanager::GetUIpointer()->ApplyCommand((QString(aCommand)+ QString(" ")+ nomFich).toStdString().c_str());
3151 }
3152}
3153
3154
3155void G4UIQt::SaveIconCallback(const QString& aCommand) {
3156
3157 QString nomFich = QFileDialog::getSaveFileName(fMainWindow, "Save", "viewerState", "Macro files (*.mac)");
3158 if (nomFich != "") {
3159 G4UImanager::GetUIpointer()->ApplyCommand((QString(aCommand)+ QString(" ")+nomFich).toStdString().c_str());
3160 }
3161}
3162
3163
3164
3165void G4UIQt::ChangePerspectiveOrtho(const QString& action) {
3166
3167 // Theses actions should be in the app toolbar
3168
3169 if (fToolbarApp == NULL) return;
3170 QList<QAction *> list = fToolbarApp->actions ();
3171 QString checked = "";
3172 for (int i = 0; i < list.size(); ++i) {
3173 if (list.at(i)->data().toString () == action) {
3174 list.at(i)->setChecked(TRUE);
3175 checked = list.at(i)->data().toString ();
3176 } else if (list.at(i)->data().toString () == "persepective") {
3177 list.at(i)->setChecked(FALSE);
3178 } else if (list.at(i)->data().toString () == "ortho") {
3179 list.at(i)->setChecked(FALSE);
3180 }
3181 }
3182
3183 if ((action == "ortho") && (checked == "ortho")) {
3184 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/projection o");
3185 } else if ((action == "perspective") && (checked == "perspective")) {
3186 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/projection p");
3187 }
3188}
3189
3190
3191
3192void G4UIQt::SetIconMoveSelected() {
3193 // Theses actions should be in the app toolbar
3194 fMoveSelected = true;
3195 fRotateSelected = false;
3196 fPickSelected = false;
3197 fZoomInSelected = false;
3198 fZoomOutSelected = false;
3199
3200 if (fToolbarApp == NULL) return;
3201 QList<QAction *> list = fToolbarApp->actions ();
3202 for (int i = 0; i < list.size(); ++i) {
3203 if (list.at(i)->data().toString () == "move") {
3204 list.at(i)->setChecked(TRUE);
3205 } else if (list.at(i)->data().toString () == "rotate") {
3206 list.at(i)->setChecked(FALSE);
3207 } else if (list.at(i)->data().toString () == "pick") {
3208 list.at(i)->setChecked(FALSE);
3209 } else if (list.at(i)->data().toString () == "zoom_in") {
3210 list.at(i)->setChecked(FALSE);
3211 } else if (list.at(i)->data().toString () == "zoom_out") {
3212 list.at(i)->setChecked(FALSE);
3213 }
3214 }
3215}
3216
3217
3218void G4UIQt::SetIconRotateSelected() {
3219 // Theses actions should be in the app toolbar
3220 fRotateSelected = true;
3221 fMoveSelected = false;
3222 fPickSelected = false;
3223 fZoomInSelected = false;
3224 fZoomOutSelected = false;
3225
3226 if (fToolbarApp == NULL) return;
3227 QList<QAction *> list = fToolbarApp->actions ();
3228 for (int i = 0; i < list.size(); ++i) {
3229 if (list.at(i)->data().toString () == "rotate") {
3230 list.at(i)->setChecked(TRUE);
3231 } else if (list.at(i)->data().toString () == "move") {
3232 list.at(i)->setChecked(FALSE);
3233 } else if (list.at(i)->data().toString () == "pick") {
3234 list.at(i)->setChecked(FALSE);
3235 } else if (list.at(i)->data().toString () == "zoom_in") {
3236 list.at(i)->setChecked(FALSE);
3237 } else if (list.at(i)->data().toString () == "zoom_out") {
3238 list.at(i)->setChecked(FALSE);
3239 }
3240 }
3241}
3242
3243
3244void G4UIQt::SetIconPickSelected() {
3245 // Theses actions should be in the app toolbar
3246 fPickSelected = true;
3247 fMoveSelected = false;
3248 fRotateSelected = false;
3249 fZoomInSelected = false;
3250 fZoomOutSelected = false;
3251
3252 if (fToolbarApp == NULL) return;
3253 QList<QAction *> list = fToolbarApp->actions ();
3254 for (int i = 0; i < list.size(); ++i) {
3255 if (list.at(i)->data().toString () == "pick") {
3256 list.at(i)->setChecked(TRUE);
3257 } else if (list.at(i)->data().toString () == "move") {
3258 list.at(i)->setChecked(FALSE);
3259 } else if (list.at(i)->data().toString () == "rotate") {
3260 list.at(i)->setChecked(FALSE);
3261 } else if (list.at(i)->data().toString () == "zoom_in") {
3262 list.at(i)->setChecked(FALSE);
3263 } else if (list.at(i)->data().toString () == "zoom_out") {
3264 list.at(i)->setChecked(FALSE);
3265 }
3266 }
3267}
3268
3269
3270void G4UIQt::SetIconZoomInSelected() {
3271 // Theses actions should be in the app toolbar
3272 fZoomInSelected = true;
3273 fMoveSelected = false;
3274 fRotateSelected = false;
3275 fPickSelected = false;
3276 fZoomOutSelected = false;
3277
3278 if (fToolbarApp == NULL) return;
3279 QList<QAction *> list = fToolbarApp->actions ();
3280 for (int i = 0; i < list.size(); ++i) {
3281 if (list.at(i)->data().toString () == "zoom_in") {
3282 list.at(i)->setChecked(TRUE);
3283 } else if (list.at(i)->data().toString () == "move") {
3284 list.at(i)->setChecked(FALSE);
3285 } else if (list.at(i)->data().toString () == "rotate") {
3286 list.at(i)->setChecked(FALSE);
3287 } else if (list.at(i)->data().toString () == "pick") {
3288 list.at(i)->setChecked(FALSE);
3289 } else if (list.at(i)->data().toString () == "zoom_out") {
3290 list.at(i)->setChecked(FALSE);
3291 }
3292 }
3293}
3294
3295
3296void G4UIQt::SetIconZoomOutSelected() {
3297 // Theses actions should be in the app toolbar
3298 fZoomOutSelected = true;
3299 fMoveSelected = false;
3300 fRotateSelected = false;
3301 fPickSelected = false;
3302 fZoomInSelected = false;
3303
3304 if (fToolbarApp == NULL) return;
3305 QList<QAction *> list = fToolbarApp->actions ();
3306 for (int i = 0; i < list.size(); ++i) {
3307 if (list.at(i)->data().toString () == "zoom_out") {
3308 list.at(i)->setChecked(TRUE);
3309 } else if (list.at(i)->data().toString () == "move") {
3310 list.at(i)->setChecked(FALSE);
3311 } else if (list.at(i)->data().toString () == "rotate") {
3312 list.at(i)->setChecked(FALSE);
3313 } else if (list.at(i)->data().toString () == "pick") {
3314 list.at(i)->setChecked(FALSE);
3315 } else if (list.at(i)->data().toString () == "zoom_in") {
3316 list.at(i)->setChecked(FALSE);
3317 }
3318 }
3319}
3320
3321
3322void G4UIQt::SetIconSolidSelected() {
3323 // Theses actions should be in the app toolbar
3324
3325 if (fToolbarApp == NULL) return;
3326 QList<QAction *> list = fToolbarApp->actions ();
3327 for (int i = 0; i < list.size(); ++i) {
3328 if (list.at(i)->data().toString () == "solid") {
3329 list.at(i)->setChecked(TRUE);
3330 } else if (list.at(i)->data().toString () == "hidden_line_removal") {
3331 list.at(i)->setChecked(FALSE);
3332 } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3333 list.at(i)->setChecked(FALSE);
3334 } else if (list.at(i)->data().toString () == "wireframe") {
3335 list.at(i)->setChecked(FALSE);
3336 }
3337 }
3338}
3339
3340
3341void G4UIQt::SetIconWireframeSelected() {
3342 // Theses actions should be in the app toolbar
3343
3344 if (fToolbarApp == NULL) return;
3345 QList<QAction *> list = fToolbarApp->actions ();
3346 for (int i = 0; i < list.size(); ++i) {
3347 if (list.at(i)->data().toString () == "wireframe") {
3348 list.at(i)->setChecked(TRUE);
3349 } else if (list.at(i)->data().toString () == "hidden_line_removal") {
3350 list.at(i)->setChecked(FALSE);
3351 } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3352 list.at(i)->setChecked(FALSE);
3353 } else if (list.at(i)->data().toString () == "solid") {
3354 list.at(i)->setChecked(FALSE);
3355 }
3356 }
3357}
3358
3359
3360void G4UIQt::SetIconHLRSelected() {
3361 // Theses actions should be in the app toolbar
3362
3363 if (fToolbarApp == NULL) return;
3364 QList<QAction *> list = fToolbarApp->actions ();
3365 for (int i = 0; i < list.size(); ++i) {
3366 if (list.at(i)->data().toString () == "hidden_line_removal") {
3367 list.at(i)->setChecked(TRUE);
3368 } else if (list.at(i)->data().toString () == "solid") {
3369 list.at(i)->setChecked(FALSE);
3370 } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3371 list.at(i)->setChecked(FALSE);
3372 } else if (list.at(i)->data().toString () == "wireframe") {
3373 list.at(i)->setChecked(FALSE);
3374 }
3375 }
3376}
3377
3378
3379void G4UIQt::SetIconHLHSRSelected() {
3380 // Theses actions should be in the app toolbar
3381
3382 if (fToolbarApp == NULL) return;
3383 QList<QAction *> list = fToolbarApp->actions ();
3384 for (int i = 0; i < list.size(); ++i) {
3385 if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
3386 list.at(i)->setChecked(TRUE);
3387 } else if (list.at(i)->data().toString () == "solid") {
3388 list.at(i)->setChecked(FALSE);
3389 } else if (list.at(i)->data().toString () == "hidden_line_removal") {
3390 list.at(i)->setChecked(FALSE);
3391 } else if (list.at(i)->data().toString () == "wireframe") {
3392 list.at(i)->setChecked(FALSE);
3393 }
3394 }
3395}
3396
3397
3398void G4UIQt::SetIconPerspectiveSelected() {
3399 // Theses actions should be in the app toolbar
3400
3401 if (fToolbarApp == NULL) return;
3402 QList<QAction *> list = fToolbarApp->actions ();
3403 for (int i = 0; i < list.size(); ++i) {
3404 if (list.at(i)->data().toString () == "perspective") {
3405 list.at(i)->setChecked(TRUE);
3406 } else if (list.at(i)->data().toString () == "ortho") {
3407 list.at(i)->setChecked(FALSE);
3408 }
3409 }
3410}
3411
3412
3413
3414void G4UIQt::SetIconOrthoSelected() {
3415 // Theses actions should be in the app toolbar
3416
3417 if (fToolbarApp == NULL) return;
3418 QList<QAction *> list = fToolbarApp->actions ();
3419 for (int i = 0; i < list.size(); ++i) {
3420 if (list.at(i)->data().toString () == "ortho") {
3421 list.at(i)->setChecked(TRUE);
3422 } else if (list.at(i)->data().toString () == "perspective") {
3423 list.at(i)->setChecked(FALSE);
3424 }
3425 }
3426}
3427
3428
3429
3430G4QTabWidget::G4QTabWidget(
3431QSplitter*& split
3432):QTabWidget(split)
3433 ,tabSelected(false)
3434 ,lastCreated(-1)
3435{
3436}
3437
3438G4QTabWidget::G4QTabWidget(
3439):QTabWidget()
3440 ,tabSelected(false)
3441 ,lastCreated(-1)
3442{
3443}
3444
3445
3446
3447#if QT_VERSION < 0x040500
3448void G4UIQt::TabCloseCallback(int){
3449#else
3450void G4UIQt::TabCloseCallback(int a){
3451#endif
3452#if QT_VERSION < 0x040500
3453#else
3454 QWidget* temp = fViewerTabWidget->widget(a);
3455 fViewerTabWidget->removeTab (a);
3456
3457 delete temp;
3458
3459 if (fViewerTabWidget->count() == 0) {
3460 if (fEmptyViewerTabLabel == NULL) {
3461 fEmptyViewerTabLabel = new QLabel(" If you want to have a Viewer, please use /vis/open commands. ");
3462 }
3463
3464 // fill right splitter
3465 fRightSplitterWidget->insertWidget(0,fEmptyViewerTabLabel);
3466
3467 fMainSplitterWidget->show();
3468 fEmptyViewerTabLabel->show();
3469 fViewerTabWidget->setParent(0);
3470 fViewerTabWidget->setVisible(false);
3471 delete fViewerTabWidget;
3472 fViewerTabWidget = NULL;
3473 }
3474#endif
3475}
3476
3477
3478void G4UIQt::ToolBoxActivated(int a){
3479
3480 if (fUITabWidget->widget(a) == fHelpTBWidget) {
3481 // Rebuild the help tree
3482 FillHelpTree();
3483 } else if (fUITabWidget->widget(a) == fSceneTreeComponentsTBWidget) {
3484#if QT_VERSION < 0x040200
3485 fSceneTreeComponentsTBWidget->show();
3486#else
3487 fSceneTreeComponentsTBWidget->setVisible(true);
3488#endif
3489 }
3490}
3491
3492
3493void G4QTabWidget::paintEvent(
3494QPaintEvent *
3495)
3496{
3497
3498 if (currentWidget()) {
3499
3500 if ( isTabSelected()) {
3501
3502 QCoreApplication::sendPostedEvents () ;
3503
3504#ifdef G4DEBUG_INTERFACES_BASIC
3505 printf("G4QTabWidget::paintEvent OK\n");
3506#endif
3507 QString text = tabText (currentIndex());
3508
3509 if (lastCreated == -1) {
3510 QString paramSelect = QString("/vis/viewer/select ")+text;
3512 if(UI != NULL) {
3513 UI->ApplyCommand(paramSelect.toStdString().c_str());
3514 }
3515 } else {
3516 lastCreated = -1;
3517 }
3518 setTabSelected(false);
3519 }
3520 }
3521}
3522
3523#endif
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
void * G4Interactor
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
str_size index(const char *, G4int pos=0) const
G4bool isNull() const
G4String strip(G4int strip_Type=trailing, char c=' ')
const char * data() const
G4int GetCommandEntry() const
const G4UIcommand * GetGuidance() const
G4UIcommand * GetCommand(G4int i)
G4int GetTreeEntry() const
const G4String GetPathName() const
G4UIcommandTree * GetTree(G4int i)
G4UIcommandTree * FindCommandTree(const char *commandPath)
const G4String GetTitle() const
G4UIcommand * FindPath(const char *commandPath) const
const G4String & GetGuidanceLine(G4int i) const
Definition: G4UIcommand.hh:132
G4UIparameter * GetParameter(G4int i) const
Definition: G4UIcommand.hh:140
G4int GetGuidanceEntries() const
Definition: G4UIcommand.hh:130
const G4String & GetCommandPath() const
Definition: G4UIcommand.hh:134
G4int GetParameterEntries() const
Definition: G4UIcommand.hh:138
const G4String & GetRange() const
Definition: G4UIcommand.hh:128
void SetCoutDestination(G4UIsession *const value)
Definition: G4UImanager.cc:517
G4UIcommandTree * GetTree() const
Definition: G4UImanager.hh:197
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:369
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:51
void SetSession(G4UIsession *const value)
Definition: G4UImanager.hh:204
void SetG4UIWindow(G4UIsession *const value)
Definition: G4UImanager.hh:206
G4String GetParameterRange() const
G4String GetDefaultValue() const
G4bool IsOmittable() const
G4String GetParameterCandidates() const
G4bool GetCurrentAsDefault() const
char GetParameterType() const
G4String GetParameterName() const
const G4String GetParameterGuidance() const
#define TRUE
Definition: globals.hh:55
#define FALSE
Definition: globals.hh:52