source: trunk/source/interfaces/basic/src/G4UIQt.cc@ 1276

Last change on this file since 1276 was 1275, checked in by garnier, 16 years ago

t

  • Property svn:mime-type set to text/cpp
File size: 56.0 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// $Id: G4UIQt.cc,v 1.38 2010/05/26 14:27:14 lgarnier Exp $
28// GEANT4 tag $Name: $
29//
30// L. Garnier
31
32#ifdef G4UI_BUILD_QT_SESSION
33
34#include "G4Types.hh"
35
36#include <string.h>
37
38#include "G4UIQt.hh"
39#include "G4UImanager.hh"
40#include "G4StateManager.hh"
41#include "G4UIcommandTree.hh"
42#include "G4UIcommandStatus.hh"
43
44#include "G4Qt.hh"
45
46#include <qapplication.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 <qtoolbox.h>
54#include <qsplitter.h>
55#include <qscrollbar.h>
56#include <qdialog.h>
57#include <qevent.h>
58#include <qtextedit.h>
59#include <qsignalmapper.h>
60#include <qtabwidget.h>
61#include <qtabbar.h>
62#include <qstringlist.h>
63
64#include <qmainwindow.h>
65#if QT_VERSION >= 0x040000
66#include <qmenu.h>
67#include <qlistwidget.h>
68#include <qtreewidget.h>
69#else
70#include <qaction.h>
71#include <qheader.h>
72#include <qlistview.h>
73#include <qpopupmenu.h>
74#include <qwidgetlist.h>
75#endif
76
77
78
79#include <stdlib.h>
80
81// Pourquoi Static et non variables de classe ?
82static G4bool exitSession = true;
83static G4bool exitPause = true;
84
85/** Build a Qt window with a menubar, output area and promt area<br>
86<pre>
87 +-----------------------+
88 |exit menu| |
89 | |
90 | +-------------------+ |
91 | | | |
92 | | Output area | |
93 | | | |
94 | +-------------------+ |
95 | | clear | |
96 | +-------------------+ |
97 | | promt history | |
98 | +-------------------+ |
99 | +-------------------+ |
100 | |> promt area | |
101 | +-------------------+ |
102 +-----------------------+
103</pre>
104*/
105G4UIQt::G4UIQt (
106 int argc
107,char** argv
108)
109:fG4cout("")
110,fHelpTreeWidget(NULL)
111,fHelpTBWidget(NULL)
112,fHistoryTBWidget(NULL)
113,fCoutTBWidget(NULL)
114,fVisParametersTBWidget(NULL)
115,fViewComponentsTBWidget(NULL)
116,fTabWidget(NULL)
117,fCoutText("Output")
118{
119
120 G4Qt* interactorManager = G4Qt::getInstance (argc,argv,(char*)"Qt");
121 if (!(QApplication*)interactorManager->GetMainInteractor()) {
122 G4cout << "G4UIQt : Unable to init Qt. Aborted" << G4endl;
123 }
124
125 G4UImanager* UI = G4UImanager::GetUIpointer();
126 if(UI!=NULL) UI->SetSession(this);
127 if(UI!=NULL) UI->SetG4UIWindow(this);
128
129 // Check if already define in external app QMainWindow
130 bool found = false;
131#if QT_VERSION < 0x040000
132 // theses lines does nothing exept this one "GLWindow = new QDialog(0..."
133 // but if I comment them, it doesn't work...
134 QWidgetList *list = QApplication::allWidgets();
135 QWidgetListIt it( *list ); // iterate over the widgets
136 QWidget * widget;
137 while ( (widget=it.current()) != 0 ) { // for each widget...
138 ++it;
139 if ((found== false) && (widget->inherits("QMainWindow"))) {
140 found = true;
141 }
142 }
143 delete list; // delete the list, not the widgets
144#else
145 foreach (QWidget *widget, QApplication::allWidgets()) {
146 if ((found== false) && (widget->inherits("QMainWindow"))) {
147 found = true;
148 }
149 }
150#endif
151
152 if (found) {
153 G4cout << "G4UIQt : Found an external App with a QMainWindow already defined. Aborted" << G4endl;
154 return ;
155 }
156 fMainWindow = new QMainWindow();
157
158#ifdef G4DEBUG_INTERFACES_BASIC
159 printf("G4UIQt::Initialise after main window creation +++++++++++\n");
160#endif
161
162 QWidget *mainWidget = new QWidget(fMainWindow);
163#if QT_VERSION < 0x040000
164 fMyVSplitter = new QSplitter(Qt::Horizontal,fMainWindow);
165 fToolBox = new QToolBox(fMyVSplitter);
166#else
167 fMyVSplitter = new QSplitter(Qt::Horizontal,fMainWindow);
168 fToolBox = new QToolBox();
169#endif
170
171 // Set layouts
172
173 // Add a empty tabwidget
174 fTabWidget = new G4QTabWidget(fMyVSplitter);
175#if QT_VERSION >= 0x040500
176 fTabWidget->setTabsClosable (true);
177#endif
178
179#if QT_VERSION >= 0x040200
180 fTabWidget->setUsesScrollButtons (true);
181#endif
182
183 QWidget* commandLineWidget = new QWidget(mainWidget);
184#if QT_VERSION < 0x040000
185 QVBoxLayout *layoutCommandLine = new QVBoxLayout(commandLineWidget);
186#else
187 QVBoxLayout *layoutCommandLine = new QVBoxLayout();
188#endif
189
190 // fill them
191
192 fCommandLabel = new QLabel("",commandLineWidget);
193
194 fCommandArea = new QLineEdit(commandLineWidget);
195 fCommandArea->installEventFilter(this);
196#if QT_VERSION < 0x040000
197 fCommandArea->setActiveWindow();
198#else
199 fCommandArea->activateWindow();
200#endif
201
202#if QT_VERSION < 0x040000
203 fCommandArea->setFocusPolicy ( QWidget::StrongFocus );
204 fCommandArea->setFocus();
205#else
206 fCommandArea->setFocusPolicy ( Qt::StrongFocus );
207 fCommandArea->setFocus(Qt::TabFocusReason);
208#endif
209
210
211
212 layoutCommandLine->addWidget(fCommandLabel);
213 layoutCommandLine->addWidget(fCommandArea);
214#if QT_VERSION >= 0x040000
215 QVBoxLayout *mainLayout = new QVBoxLayout();
216#else
217 QVBoxLayout *mainLayout = new QVBoxLayout(mainWidget);
218#endif
219
220 fHelpTBWidget = new QWidget(fToolBox);
221 fHistoryTBWidget = new QWidget(fToolBox);
222 fCoutTBWidget = new QWidget(fToolBox);
223 fVisParametersTBWidget = new QWidget(fToolBox);
224 fViewComponentsTBWidget = new QWidget(fToolBox);
225
226 CreateVisParametersTBWidget();
227 CreateViewComponentsTBWidget();
228 CreateHelpTBWidget();
229 CreateCoutTBWidget();
230 CreateHistoryTBWidget();
231
232 // the splitter
233 // fToolBox->addItem(fVisParametersTBWidget,"Vis parameters");
234 // fToolBox->addItem(fViewComponentsTBWidget,"Viewer components");
235 fToolBox->addItem(fHelpTBWidget,"Help");
236 fToolBox->addItem(fCoutTBWidget,"Cout");
237 fToolBox->addItem(fHistoryTBWidget,"History");
238
239
240
241 fToolBox->setSizePolicy (QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed));
242 fTabWidget->setSizePolicy (QSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum));
243
244 QSizePolicy policy = fTabWidget->sizePolicy();
245#if QT_VERSION < 0x040000
246 policy.setHorStretch(1);
247 policy.setVerStretch(1);
248#else
249 policy.setHorizontalStretch(1);
250 policy.setVerticalStretch(1);
251#endif
252 fTabWidget->setSizePolicy(policy);
253
254#if QT_VERSION < 0x040000
255 fEmptyViewerTabLabel = new QLabel(fToolBox," If you want to have a Viewer, please use /vis/open commands. ");
256#else
257 fEmptyViewerTabLabel = new QLabel(" If you want to have a Viewer, please use /vis/open commands. ");
258#endif
259
260 // Only at creation. Will be set visible when sessionStart();
261#if QT_VERSION >= 0x040000
262 #if QT_VERSION >= 0x040200
263 fTabWidget->setVisible(false);
264 fEmptyViewerTabLabel->setVisible(false);
265 #else
266 fTabWidget->hide();
267 fEmptyViewerTabLabel->hide();
268 #endif
269#else
270 fTabWidget->hide();
271 fEmptyViewerTabLabel->hide();
272#endif
273
274
275 // fMyVSplitter->addWidget(fTabWidget);
276
277 // unset parent fot TabWidget
278#if QT_VERSION < 0x040000
279 fTabWidget->reparent(0,0,QPoint(0,0));
280#else
281 fMyVSplitter->addWidget(fToolBox);
282 fMyVSplitter->addWidget(fEmptyViewerTabLabel);
283 fTabWidget->setParent(0);
284#endif
285
286
287#if QT_VERSION >= 0x040000
288 commandLineWidget->setLayout(layoutCommandLine);
289#endif
290 commandLineWidget->setSizePolicy (QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
291 mainLayout->addWidget(fMyVSplitter,1);
292 mainLayout->addWidget(commandLineWidget);
293
294#ifdef G4DEBUG_INTERFACES_BASIC
295 printf("G4UIQt::G4UIQt :: 5\n");
296#endif
297
298#if QT_VERSION >= 0x040000
299 mainWidget->setLayout(mainLayout);
300#endif
301
302 fMainWindow->setCentralWidget(mainWidget);
303
304#if QT_VERSION < 0x040000
305
306 // Add a quit subMenu
307 QPopupMenu *fileMenu = new QPopupMenu( fMainWindow);
308 fileMenu->insertItem( "&Quit", this, SLOT(ExitSession()), CTRL+Key_Q );
309 fMainWindow->menuBar()->insertItem( QString("&File"), fileMenu );
310
311#else
312
313 // Add a quit subMenu
314 QMenu *fileMenu = fMainWindow->menuBar()->addMenu("File");
315 fileMenu->addAction("Quit", this, SLOT(ExitSession()));
316
317#endif
318
319 AddInteractor ("file",(G4Interactor)fileMenu);
320#ifdef G4DEBUG_INTERFACES_BASIC
321 printf("G4UIQt::G4UIQt :: 6\n");
322#endif
323
324 // Connect signal
325 connect(fCommandArea, SIGNAL(returnPressed()), SLOT(CommandEnteredCallback()));
326 connect(fTabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(TabCloseCallback(int)));
327 connect(fTabWidget, SIGNAL(currentChanged ( int ) ), SLOT(UpdateTabWidget(int)));
328 connect(fToolBox, SIGNAL(currentChanged(int)), SLOT(ToolBoxActivated(int)));
329
330 if(UI!=NULL) UI->SetCoutDestination(this); // TO KEEP
331
332#if QT_VERSION < 0x040000
333 fMainWindow->setCaption( tr( "G4UI Session" ));
334 fMainWindow->resize(900,600);
335 fMainWindow->move(50,100);
336#else
337 fMainWindow->setWindowTitle( tr("G4UI Session") );
338 fMainWindow->resize(900,600);
339 fMainWindow->move(QPoint(50,100));
340#endif
341
342 // Set visible
343#if QT_VERSION >= 0x040000
344 #if QT_VERSION >= 0x040200
345 fMainWindow->setVisible(true);
346 #else
347 fMainWindow->show();
348 #endif
349#else
350 fMainWindow->show();
351#endif
352
353#ifdef G4DEBUG_INTERFACES_BASIC
354 printf("G4UIQt::G4UIQt END\n");
355#endif
356}
357
358
359
360G4UIQt::~G4UIQt(
361)
362{
363#ifdef G4DEBUG_INTERFACES_BASIC
364 printf("G4UIQt::~G4UIQt Delete\n");
365#endif
366 G4UImanager* UI = G4UImanager::GetUIpointer(); // TO KEEP
367 if(UI!=NULL) { // TO KEEP
368 UI->SetSession(NULL); // TO KEEP
369 UI->SetG4UIWindow(NULL);
370 UI->SetCoutDestination(NULL); // TO KEEP
371 }
372
373 if (fMainWindow!=NULL) {
374#ifdef G4DEBUG_INTERFACES_BASIC
375 printf("G4UIQt::~G4UIQt DELETE fMainWindow\n");
376#endif
377 delete fMainWindow;
378 }
379}
380
381/** Create the History ToolBox Widget
382 */
383void G4UIQt::CreateHistoryTBWidget(
384)
385{
386
387#if QT_VERSION < 0x040000
388 QVBoxLayout *layoutHistoryTB = new QVBoxLayout(fHistoryTBWidget);
389
390 fHistoryTBTableList = new QListView(fHistoryTBWidget);
391 fHistoryTBTableList->setSorting (-1, FALSE);
392 fHistoryTBTableList->setSelectionMode(QListView::Single);
393 fHistoryTBTableList->addColumn("");
394 fHistoryTBTableList->header()->hide();
395 connect(fHistoryTBTableList, SIGNAL(selectionChanged()), SLOT(CommandHistoryCallback()));
396#else
397 QVBoxLayout *layoutHistoryTB = new QVBoxLayout();
398 fHistoryTBTableList = new QListWidget();
399 fHistoryTBTableList->setSelectionMode(QAbstractItemView::SingleSelection);
400 connect(fHistoryTBTableList, SIGNAL(itemSelectionChanged()), SLOT(CommandHistoryCallback()));
401#endif
402 fHistoryTBTableList->installEventFilter(this);
403
404 layoutHistoryTB->addWidget(fHistoryTBTableList);
405
406#if QT_VERSION >= 0x040000
407 fHistoryTBWidget->setLayout(layoutHistoryTB);
408#endif
409}
410
411/** Create the Help ToolBox Widget
412 */
413void G4UIQt::CreateHelpTBWidget(
414)
415{
416
417
418#if QT_VERSION < 0x040000
419 QWidget *helpWidget = new QWidget(fHelpTBWidget);
420 QHBoxLayout *helpLayout = new QHBoxLayout(helpWidget);
421 fHelpVSplitter = new QSplitter(Qt::Horizontal,fHelpTBWidget);
422#else
423 QWidget *helpWidget = new QWidget();
424 QHBoxLayout *helpLayout = new QHBoxLayout();
425 QVBoxLayout *vLayout = new QVBoxLayout();
426 fHelpVSplitter = new QSplitter(Qt::Horizontal);
427#endif
428 fHelpLine = new QLineEdit(fHelpTBWidget);
429 helpLayout->addWidget(new QLabel("Search :",helpWidget));
430 helpLayout->addWidget(fHelpLine);
431#if QT_VERSION < 0x040000
432 connect( fHelpLine, SIGNAL( returnPressed () ), this, SLOT( LookForHelpStringCallback() ) );
433#else
434 connect( fHelpLine, SIGNAL( editingFinished () ), this, SLOT( LookForHelpStringCallback() ) );
435#endif
436
437 // Create Help tree
438 FillHelpTree();
439
440 fHelpArea = new QTextEdit(fHelpVSplitter);
441 fHelpArea->setReadOnly(true);
442
443 // Set layouts
444
445#if QT_VERSION >= 0x040000
446 if (fHelpTreeWidget) {
447 fHelpVSplitter->addWidget(fHelpTreeWidget);
448 }
449 fHelpVSplitter->addWidget(fHelpArea);
450#endif
451
452
453#if QT_VERSION >= 0x040000
454 vLayout->addWidget(helpWidget);
455 vLayout->addWidget(fHelpVSplitter,1);
456#endif
457
458 fHelpTBWidget->setMinimumSize(50,50);
459 fHelpTBWidget->setSizePolicy (QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
460 // set the splitter size
461#if QT_VERSION >= 0x040000
462 QList<int> list;
463#else
464 QValueList<int> list;
465#endif
466 list.append( 50 );
467 list.append( 50 );
468 fHelpVSplitter->setSizes(list);
469
470#if QT_VERSION >= 0x040000
471 helpWidget->setLayout(helpLayout);
472 fHelpTBWidget->setLayout(vLayout);
473#endif
474}
475
476
477/** Create the Cout ToolBox Widget
478 */
479void G4UIQt::CreateCoutTBWidget(
480)
481{
482#if QT_VERSION >= 0x040000
483 QVBoxLayout *layoutCoutTB = new QVBoxLayout();
484#else
485 QVBoxLayout *layoutCoutTB = new QVBoxLayout(fCoutTBWidget);
486#endif
487
488 fCoutTBTextArea = new QTextEdit(fCoutTBWidget);
489 fCoutFilter = new QLineEdit(fCoutTBWidget);
490 QLabel* coutFilterLabel = new QLabel("Filter : ",fCoutTBWidget);
491
492 QPushButton *coutTBClearButton = new QPushButton("clear",fCoutTBWidget);
493 connect(coutTBClearButton, SIGNAL(clicked()), SLOT(ClearButtonCallback()));
494 connect(fCoutFilter, SIGNAL(textEdited ( const QString &)), SLOT(CoutFilterCallback( const QString &)));
495
496 fCoutTBTextArea->setReadOnly(true);
497
498 QWidget* coutButtonWidget = new QWidget(fCoutTBWidget);
499 QHBoxLayout* layoutCoutTBButtons = new QHBoxLayout(coutButtonWidget);
500 layoutCoutTBButtons->addWidget(coutTBClearButton);
501 layoutCoutTBButtons->addWidget(coutFilterLabel);
502 layoutCoutTBButtons->addWidget(fCoutFilter);
503
504 layoutCoutTB->addWidget(fCoutTBTextArea);
505 layoutCoutTB->addWidget(coutButtonWidget);
506
507#if QT_VERSION >= 0x040000
508 fCoutTBWidget->setLayout(layoutCoutTB);
509#endif
510}
511
512
513/** Create the VisParameters ToolBox Widget
514 */
515void G4UIQt::CreateVisParametersTBWidget(
516)
517{
518}
519
520
521/** Create the ViewComponents ToolBox Widget
522 */
523void G4UIQt::CreateViewComponentsTBWidget(
524)
525{
526}
527
528
529/** Add a new tab widget.
530 Create the tab if it was not done
531*/
532bool G4UIQt::AddTabWidget(
533 QWidget* aWidget
534,QString name
535,int sizeX
536,int sizeY
537)
538{
539#ifdef G4DEBUG_INTERFACES_BASIC
540 printf("G4UIQt::AddTabWidget %d %d\n",sizeX, sizeY);
541#endif
542 if (!aWidget) {
543 return false;
544 }
545
546 // Remove QLabel
547
548 // L.Garnier 26/05/2010 : not exactly the same in qt3. Could cause some
549 // troubles
550#if QT_VERSION >= 0x040000
551 if ( fMyVSplitter->indexOf(fEmptyViewerTabLabel) != -1) {
552#endif
553
554#if QT_VERSION < 0x040000
555 fEmptyViewerTabLabel->reparent(0,0,QPoint(0,0));
556#else
557 fEmptyViewerTabLabel->setParent(0);
558 fMyVSplitter->addWidget(fTabWidget);
559#endif
560
561#if QT_VERSION < 0x040000
562 aWidget->reparent(fTabWidget,0,QPoint(0,0));
563#else
564 aWidget->setParent(fTabWidget);
565#endif
566#if QT_VERSION >= 0x040000
567 }
568#endif
569
570
571#ifdef G4DEBUG_INTERFACES_BASIC
572 printf("G4UIQt::AddTabWidget ADD %d %d + %d %d---------------------------------------------------\n",sizeX, sizeY,sizeX-fTabWidget->width(),sizeY-fTabWidget->height());
573#endif
574
575 fMainWindow->resize(fMainWindow->width()+sizeX-fTabWidget->width(),fMainWindow->height()+sizeY-fTabWidget->height());
576
577 // Problems with resize. The widgets are not realy drawn at this step,
578 // then we have to force them on order to check the size
579
580#if QT_VERSION < 0x040000
581 fTabWidget->insertTab(aWidget,name,fTabWidget->count());
582#else
583 fTabWidget->insertTab(fTabWidget->count(),aWidget,name);
584#endif
585
586#if QT_VERSION < 0x040000
587 fTabWidget->setCurrentPage(fTabWidget->count()-1);
588#else
589 fTabWidget->setCurrentIndex(fTabWidget->count()-1);
590#endif
591
592 // Set visible
593#if QT_VERSION >= 0x040000
594 #if QT_VERSION >= 0x040200
595 fTabWidget->setLastTabCreated(fTabWidget->currentIndex());
596 fMainWindow->setVisible(true);
597 #else
598 fTabWidget->setLastTabCreated(fTabWidget->currentIndex());
599 fMainWindow->show();
600 #endif
601#else
602 fTabWidget->setLastTabCreated(fTabWidget->currentPageIndex());
603 fMainWindow->show();
604#endif
605
606#if QT_VERSION >= 0x040000
607 #if QT_VERSION >= 0x040200
608 fTabWidget->setVisible(true);
609 #else
610 fTabWidget->show();
611 #endif
612#else
613 fTabWidget->show();
614#endif
615
616 return true;
617}
618
619
620void G4UIQt::UpdateTabWidget(int tabNumber) {
621#ifdef G4DEBUG_INTERFACES_BASIC
622 printf("G4UIQt::UpdateTabWidget %d\n",tabNumber);
623#endif
624 if ( fTabWidget == NULL) {
625 fTabWidget = new G4QTabWidget;
626 }
627
628
629#ifdef G4DEBUG_INTERFACES_BASIC
630 printf("G4UIQt::UpdateTabWidget CALL REPAINT tabGL\n");
631#endif
632
633#if QT_VERSION < 0x040000
634 fTabWidget->setCurrentPage(tabNumber);
635#else
636 fTabWidget->setCurrentIndex(tabNumber);
637#endif
638
639 // Send this signal to unblock graphic updates !
640#if QT_VERSION >= 0x040000
641 #if QT_VERSION >= 0x040200
642 fTabWidget->setVisible(true);
643 #else
644 fTabWidget->show();
645 #endif
646#else
647 fTabWidget->show();
648#endif
649
650 // This will send a paintEvent to OGL Viewers
651 fTabWidget->setTabSelected();
652
653#if QT_VERSION < 0x040000
654 QApplication::sendPostedEvents () ;
655#else
656 QCoreApplication::sendPostedEvents () ;
657#endif
658
659#ifdef G4DEBUG_INTERFACES_BASIC
660 printf("G4UIQt::UpdateTabWidget END\n");
661#endif
662}
663
664
665/** Send resize event to all tabs
666 */
667void G4UIQt::ResizeTabWidget( QResizeEvent* e) {
668 for (int a=0;a<fTabWidget->count() ;a++) {
669#ifdef G4DEBUG_INTERFACES_BASIC
670 printf("G4UIQt::ResizeTabWidget +++++++++++++++++++++++++++++++++++++++\n");
671#endif
672#if QT_VERSION < 0x040000
673 fTabWidget->page(a)->resize(e->size());
674#else
675 fTabWidget->widget(a)->resize(e->size());
676#endif
677 }
678}
679
680
681/** Start the Qt main loop
682*/
683G4UIsession* G4UIQt::SessionStart (
684)
685{
686#ifdef G4DEBUG_INTERFACES_BASIC
687 printf("G4UIQt::G4UIQt SessionStart\n");
688#endif
689
690 G4Qt* interactorManager = G4Qt::getInstance ();
691
692 Prompt("Session :");
693 exitSession = false;
694
695#if QT_VERSION >= 0x040000
696 #if QT_VERSION >= 0x040200
697 fTabWidget->setVisible(true);
698 fEmptyViewerTabLabel->setVisible(true);
699 #else
700 fTabWidget->show();
701 fEmptyViewerTabLabel->show();
702 #endif
703#else
704 fTabWidget->show();
705 fEmptyViewerTabLabel->show();
706#endif
707
708
709#if QT_VERSION >= 0x040000
710 #if QT_VERSION >= 0x040200
711 fMainWindow->setVisible(true);
712 #else
713 fMainWindow->show();
714 #endif
715#else
716 fMainWindow->show();
717#endif
718
719#if QT_VERSION < 0x040000
720 QApplication::sendPostedEvents () ;
721#else
722 QCoreApplication::sendPostedEvents () ;
723#endif
724
725#ifdef G4DEBUG_INTERFACES_BASIC
726 printf("G4UIQt::G4UIQt SessionStart2\n");
727#endif
728 interactorManager->DisableSecondaryLoop (); // TO KEEP
729 if ((QApplication*)interactorManager->GetMainInteractor())
730 ((QApplication*)interactorManager->GetMainInteractor())->exec();
731
732 // on ne passe pas le dessous ? FIXME ????
733 // je ne pense pas 13/06
734
735 // void* event; // TO KEEP
736 // while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP
737 // interactorManager->DispatchEvent(event); // TO KEEP
738 // if(exitSession==true) break; // TO KEEP
739 // } // TO KEEP
740
741 interactorManager->EnableSecondaryLoop ();
742 return this;
743}
744
745
746/** Display the prompt in the prompt area
747 @param aPrompt : string to display as the promt label
748 //FIXME : probablement inutile puisque le seul a afficher qq chose d'autre
749 que "session" est SecondaryLoop()
750*/
751void G4UIQt::Prompt (
752 G4String aPrompt
753)
754{
755 if (!aPrompt) return;
756
757 fCommandLabel->setText((char*)aPrompt.data());
758}
759
760
761
762void G4UIQt::SessionTerminate (
763)
764{
765 G4Qt* interactorManager = G4Qt::getInstance ();
766 fMainWindow->close();
767 ((QApplication*)interactorManager->GetMainInteractor())->exit();
768}
769
770
771
772/**
773 Called by intercoms/src/G4UImanager.cc<br>
774 Called by visualization/management/src/G4VisCommands.cc with "EndOfEvent" argument<br>
775 It have to pause the session command terminal.<br>
776 Call SecondaryLoop to wait for exit event<br>
777 @param aState
778 @see : G4VisCommandReviewKeptEvents::SetNewValue
779*/
780void G4UIQt::PauseSessionStart (
781 G4String aState
782)
783{
784 if (!aState) return;
785
786 if(aState=="G4_pause> ") { // TO KEEP
787 SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP
788 } // TO KEEP
789
790 if(aState=="EndOfEvent") { // TO KEEP
791 // Picking with feed back in event data Done here !!!
792 SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP
793 } // TO KEEP
794}
795
796
797
798/**
799 Begin the secondary loop
800 @param a_prompt : label to display as the prompt label
801 */
802void G4UIQt::SecondaryLoop (
803 G4String aPrompt
804)
805{
806 if (!aPrompt) return;
807
808 G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ?
809 Prompt(aPrompt); // TO KEEP
810 exitPause = false; // TO KEEP
811 void* event; // TO KEEP
812 while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP
813 interactorManager->DispatchEvent(event); // TO KEEP
814 if(exitPause==true) break; // TO KEEP
815 } // TO KEEP
816 Prompt("Session :"); // TO KEEP
817}
818
819
820
821/**
822 Receive a cout from Geant4. We have to display it in the cout zone
823 @param aString : label to add in the display area
824 @return 0
825*/
826G4int G4UIQt::ReceiveG4cout (
827 G4String aString
828 )
829{
830 if (!aString) return 0;
831
832 QStringList newStr;
833
834 // Add to stringList
835#if QT_VERSION < 0x040000
836 newStr = QStringList(QString((char*)aString.data()).simplifyWhiteSpace());
837#else
838 newStr = QStringList(QString((char*)aString.data()).trimmed());
839#endif
840 fG4cout += newStr;
841
842#if QT_VERSION >= 0x040000
843 QStringList result = newStr.filter(fCoutFilter->text());
844#else
845 //L. Garnier : in qt3 filter will does nothing
846 QStringList result = "";
847#endif
848
849 if (result.join("\n").isEmpty()) {
850 return 0;
851 }
852 fCoutTBTextArea->append(result.join("\n"));
853 fCoutTBTextArea->repaint();
854
855#if QT_VERSION < 0x040000
856 fCoutTBTextArea->verticalScrollBar()->setValue(fCoutTBTextArea->verticalScrollBar()->maxValue());
857#else
858 fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
859#endif
860
861 return 0;
862}
863
864
865/**
866 Receive a cerr from Geant4. We have to display it in the cout zone
867 @param aString : label to add in the display area
868 @return 0
869*/
870G4int G4UIQt::ReceiveG4cerr (
871 G4String aString
872)
873{
874 if (!aString) return 0;
875
876 QStringList newStr;
877
878 // Add to stringList
879#if QT_VERSION < 0x040000
880 newStr = QStringList(QString((char*)aString.data()).simplifyWhiteSpace());
881#else
882 newStr = QStringList(QString((char*)aString.data()).trimmed());
883#endif
884 fG4cout += newStr;
885
886#if QT_VERSION < 0x040000
887 //L. Garnier : in qt3 filter will does nothing
888 QStringList result = "";
889#else
890 QStringList result = newStr.filter(fCoutFilter->text());
891#endif
892
893#if QT_VERSION < 0x040000
894 QColor previousColor = fCoutTBTextArea->color();
895 fCoutTBTextArea->setColor(Qt::red);
896 fCoutTBTextArea->append(result.join("\n"));
897 fCoutTBTextArea->setColor(previousColor);
898 fCoutTBTextArea->verticalScrollBar()->setValue(fCoutTBTextArea->verticalScrollBar()->maxValue());
899#else
900 QColor previousColor = fCoutTBTextArea->textColor();
901 fCoutTBTextArea->setTextColor(Qt::red);
902 fCoutTBTextArea->append(result.join("\n"));
903 fCoutTBTextArea->setTextColor(previousColor);
904 fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
905#endif
906 fCoutTBTextArea->repaint();
907 return 0;
908}
909
910
911
912/**
913 Add a new menu to the menu bar
914 @param aName name of menu
915 @param aLabel label to display
916 */
917void G4UIQt::AddMenu (
918 const char* aName
919,const char* aLabel
920)
921{
922 if (aName == NULL) return;
923 if (aLabel == NULL) return;
924
925#if QT_VERSION < 0x040000
926 QPopupMenu *fileMenu = new QPopupMenu( fMainWindow);
927 fMainWindow->menuBar()->insertItem( aLabel, fileMenu );
928#else
929 QMenu *fileMenu = new QMenu(aLabel);
930 fMainWindow->menuBar()->insertMenu(fMainWindow->menuBar()->actions().last(),fileMenu);
931#endif
932
933 AddInteractor (aName,(G4Interactor)fileMenu);
934}
935
936
937/**
938 Add a new button to a menu
939 @param aMenu : parent menu
940 @param aLabel : label to display
941 @param aCommand : command to execute as a callback
942 */
943void G4UIQt::AddButton (
944 const char* aMenu
945,const char* aLabel
946,const char* aCommand
947)
948{
949 if(aMenu==NULL) return; // TO KEEP
950 if(aLabel==NULL) return; // TO KEEP
951 if(aCommand==NULL) return; // TO KEEP
952
953#if QT_VERSION < 0x040000
954 QPopupMenu *parent = (QPopupMenu*)GetInteractor(aMenu);
955#else
956 QMenu *parent = (QMenu*)GetInteractor(aMenu);
957#endif
958
959 if(parent==NULL) return;
960
961 QSignalMapper *signalMapper = new QSignalMapper(this);
962#if QT_VERSION < 0x030200
963 QAction *action = new QAction(QString(aLabel),QString(aLabel),QKeySequence(),signalMapper, SLOT(map()));
964 action->addTo(parent);
965 connect(action,SIGNAL(activated()),signalMapper,SLOT(map()));
966
967#elif QT_VERSION < 0x040000
968 QAction *action = new QAction(QString(aLabel),QKeySequence(),signalMapper, SLOT(map()));
969 action->addTo(parent);
970 connect(action,SIGNAL(activated()),signalMapper,SLOT(map()));
971
972#else
973 QAction *action = parent->addAction(aLabel, signalMapper, SLOT(map()));
974
975#endif
976 connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&)));
977 signalMapper->setMapping(action, QString(aCommand));
978}
979
980
981
982
983void G4UIQt::ActivateCommand(
984 G4String newCommand
985)
986{
987 if (!fHelpTreeWidget) {
988 return;
989 }
990 // Look for the choosen command "newCommand"
991 size_t i = newCommand.index(" ");
992 G4String targetCom ="";
993 if( i != std::string::npos )
994 {
995 G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
996 newValue.strip(G4String::both);
997 targetCom = ModifyToFullPathCommand( newValue );
998 }
999#ifdef G4DEBUG_INTERFACES_BASIC
1000 printf("G4UIQt::ActivateCommand found : %s \n",targetCom.data());
1001#endif
1002 if (targetCom != "") {
1003 OpenHelpTreeOnCommand(targetCom.data());
1004 }
1005
1006#if QT_VERSION < 0x040000
1007 fToolBox->setCurrentItem(fHelpTBWidget);
1008#else
1009 fToolBox->setCurrentWidget(fHelpTBWidget);
1010#endif
1011}
1012
1013
1014
1015/**
1016 Create the help tree widget
1017 @param parent : parent of tree widget
1018 @return the widget containing the tree or NULL if it could not have beeen created
1019 */
1020
1021void G4UIQt::InitHelpTree()
1022{
1023
1024 if (! fHelpTreeWidget ) {
1025#if QT_VERSION < 0x040000
1026 fHelpTreeWidget = new QListView(fHelpVSplitter);
1027#else
1028 fHelpTreeWidget = new QTreeWidget();
1029#endif
1030 }
1031
1032
1033 // build widget
1034#if QT_VERSION < 0x040000
1035 fHelpTreeWidget->setSelectionMode(QListView::Single);
1036 fHelpTreeWidget->setRootIsDecorated(true);
1037 fHelpTreeWidget->addColumn("Command");
1038 fHelpTreeWidget->header()->setResizeEnabled(FALSE,1);
1039#else
1040 fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
1041 QStringList labels;
1042 labels << QString("Command");
1043 fHelpTreeWidget->setHeaderLabels(labels);
1044#endif
1045
1046
1047#if QT_VERSION < 0x040000
1048 connect(fHelpTreeWidget, SIGNAL(selectionChanged ()),this, SLOT(HelpTreeClicCallback()));
1049 connect(fHelpTreeWidget, SIGNAL(doubleClicked (QListViewItem*)),this, SLOT(HelpTreeDoubleClicCallback()));
1050#else
1051 connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback()));
1052 connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback()));
1053#endif
1054
1055}
1056/**
1057 Create the help tree widget
1058 @param parent : parent of tree widget
1059 @return the widget containing the tree or NULL if it could not have beeen created
1060 */
1061
1062void G4UIQt::FillHelpTree()
1063{
1064 if (! fHelpTreeWidget ) {
1065 InitHelpTree();
1066 }
1067
1068 G4UImanager* UI = G4UImanager::GetUIpointer();
1069 if(UI==NULL) return;
1070 G4UIcommandTree * treeTop = UI->GetTree();
1071
1072 G4int treeSize = treeTop->GetTreeEntry();
1073#if QT_VERSION < 0x040000
1074 QListViewItem * newItem = NULL;
1075#else
1076 QTreeWidgetItem * newItem = NULL;
1077#endif
1078 QString commandText = "";
1079 for (int a=0;a<treeSize;a++) {
1080 // Creating new item
1081 newItem = NULL;
1082
1083#if QT_VERSION < 0x040000
1084 commandText = QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace();
1085#else
1086 commandText = QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed();
1087#endif
1088
1089 // if already exist, don't create it !
1090#if QT_VERSION < 0x040000
1091 QListViewItem* tmpAddItem = fHelpTreeWidget->firstChild();
1092 while (tmpAddItem != 0) {
1093 if (!newItem) {
1094 newItem = FindTreeItem(tmpAddItem,commandText);
1095 }
1096 tmpAddItem = tmpAddItem->nextSibling();
1097 }
1098#else
1099 for (int b=0;b<fHelpTreeWidget->topLevelItemCount();b++) {
1100 if (!newItem)
1101 newItem = FindTreeItem(fHelpTreeWidget->topLevelItem(b),commandText);
1102 }
1103#endif
1104
1105 if (newItem == NULL) {
1106
1107#if QT_VERSION < 0x040000
1108 newItem = new QListViewItem(fHelpTreeWidget);
1109#else
1110 newItem = new QTreeWidgetItem(fHelpTreeWidget);
1111#endif
1112 newItem->setText(0,GetShortCommandPath(commandText));
1113 }
1114
1115 // look for childs
1116 CreateChildTree(newItem,treeTop->GetTree(a+1));
1117 }
1118
1119}
1120
1121
1122
1123/** Fill the Help Tree Widget
1124 @param aParent : parent item to fill
1125 @param aCommandTree : commandTree node associate with this part of the Tree
1126*/
1127#if QT_VERSION < 0x040000
1128void G4UIQt::CreateChildTree(
1129 QListViewItem *aParent
1130,G4UIcommandTree *aCommandTree
1131#else
1132void G4UIQt::CreateChildTree(
1133 QTreeWidgetItem *aParent
1134,G4UIcommandTree *aCommandTree
1135#endif
1136)
1137{
1138 if (aParent == NULL) return;
1139 if (aCommandTree == NULL) return;
1140
1141
1142 // Creating new item
1143#if QT_VERSION < 0x040000
1144 QListViewItem * newItem;
1145#else
1146 QTreeWidgetItem * newItem;
1147#endif
1148
1149 QString commandText = "";
1150 // Get the Sub directories
1151 for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
1152
1153#if QT_VERSION < 0x040000
1154 commandText = QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace();
1155#else
1156 commandText = QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed();
1157#endif
1158
1159 // if already exist, don't create it !
1160 newItem = FindTreeItem(aParent,commandText);
1161 if (newItem == NULL) {
1162#if QT_VERSION < 0x040000
1163 newItem = new QListViewItem(aParent);
1164#else
1165 newItem = new QTreeWidgetItem(aParent);
1166#endif
1167 newItem->setText(0,GetShortCommandPath(commandText));
1168 }
1169 CreateChildTree(newItem,aCommandTree->GetTree(a+1));
1170 }
1171
1172
1173
1174 // Get the Commands
1175
1176 for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
1177
1178 QStringList stringList;
1179#if QT_VERSION < 0x040000
1180 commandText = QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).simplifyWhiteSpace();
1181#else
1182 commandText = QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed();
1183#endif
1184
1185 // if already exist, don't create it !
1186 newItem = FindTreeItem(aParent,commandText);
1187 if (newItem == NULL) {
1188#if QT_VERSION < 0x040000
1189 newItem = new QListViewItem(aParent);
1190 newItem->setText(0,GetShortCommandPath(commandText));
1191 newItem->setOpen(false);
1192
1193#else
1194 newItem = new QTreeWidgetItem(aParent);
1195 newItem->setText(0,GetShortCommandPath(commandText));
1196#if QT_VERSION < 0x040202
1197 fHelpTreeWidget->setItemExpanded(newItem,false);
1198#else
1199 newItem->setExpanded(false);
1200#endif
1201#endif
1202 }
1203 }
1204}
1205
1206
1207/** Find a treeItemWidget in the help tree
1208 @param aCommand item's String to look for
1209 @return item if found, NULL if not
1210*/
1211#if QT_VERSION < 0x040000
1212QListViewItem* G4UIQt::FindTreeItem(
1213 QListViewItem *aParent
1214#else
1215QTreeWidgetItem* G4UIQt::FindTreeItem(
1216 QTreeWidgetItem *aParent
1217#endif
1218,const QString& aCommand
1219)
1220{
1221 if (aParent == NULL) return NULL;
1222
1223 // Suppress last "/"
1224 QString myCommand = aCommand;
1225
1226#if QT_VERSION < 0x040000
1227 if (myCommand.findRev("/") == ((int)myCommand.length()-1)) {
1228 myCommand = myCommand.left(myCommand.length()-1);
1229#else
1230 if (myCommand.lastIndexOf("/") == (myCommand.size()-1)) {
1231 myCommand = myCommand.left(myCommand.size()-1);
1232#endif
1233 }
1234
1235 if (GetLongCommandPath(aParent) == myCommand)
1236 return aParent;
1237
1238#if QT_VERSION < 0x040000
1239 QListViewItem * tmp = NULL;
1240 QListViewItem* tmpItem = aParent->firstChild();
1241 while (tmpItem != 0) {
1242 if (!tmp)
1243 tmp = FindTreeItem(tmpItem,myCommand);
1244 tmpItem = tmpItem->nextSibling();
1245 }
1246#else
1247 QTreeWidgetItem * tmp = NULL;
1248 for (int a=0;a<aParent->childCount();a++) {
1249 if (!tmp)
1250 tmp = FindTreeItem(aParent->child(a),myCommand);
1251 }
1252#endif
1253 return tmp;
1254}
1255
1256
1257
1258/** Build the command list parameters in a QString<br>
1259 Reimplement partialy the G4UIparameter.cc
1260 @param aCommand : command to list parameters
1261 @see G4UIparameter::List()
1262 @see G4UIcommand::List()
1263 @return the command list parameters, or "" if nothing
1264*/
1265QString G4UIQt::GetCommandList (
1266 const G4UIcommand *aCommand
1267)
1268{
1269
1270 QString txt ="";
1271 if (aCommand == NULL)
1272 return txt;
1273
1274 G4String commandPath = aCommand->GetCommandPath();
1275 G4String rangeString = aCommand->GetRange();
1276 G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
1277 G4int n_parameterEntry = aCommand->GetParameterEntries();
1278
1279 if ((commandPath == "") &&
1280 (rangeString == "") &&
1281 (n_guidanceEntry == 0) &&
1282 (n_parameterEntry == 0)) {
1283 return txt;
1284 }
1285
1286 if((commandPath.length()-1)!='/') {
1287 txt += "Command " + QString((char*)(commandPath).data()) + "\n";
1288 }
1289 txt += "Guidance :\n";
1290
1291 for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
1292 txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
1293 }
1294 if( ! rangeString.isNull() ) {
1295 txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n";
1296 }
1297 if( n_parameterEntry > 0 ) {
1298 G4UIparameter *param;
1299
1300 // Re-implementation of G4UIparameter.cc
1301
1302 for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
1303 param = aCommand->GetParameter(i_thParameter);
1304 txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
1305 if( ! param->GetParameterGuidance().isNull() )
1306 txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
1307 txt += " Parameter type : " + QString(QChar(param->GetParameterType())) + "\n";
1308 if(param->IsOmittable()){
1309 txt += " Omittable : True\n";
1310 } else {
1311 txt += " Omittable : False\n";
1312 }
1313 if( param->GetCurrentAsDefault() ) {
1314 txt += " Default value : taken from the current value\n";
1315 } else if( ! param->GetDefaultValue().isNull() ) {
1316 txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n";
1317 }
1318 if( ! param->GetParameterRange().isNull() ) {
1319 txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
1320 }
1321 if( ! param->GetParameterCandidates().isNull() ) {
1322 txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
1323 }
1324 }
1325 }
1326 return txt;
1327}
1328
1329
1330
1331/** Implement G4VBasicShell vurtual function
1332 */
1333G4bool G4UIQt::GetHelpChoice(
1334 G4int&
1335)
1336{
1337#ifdef G4DEBUG_INTERFACES_BASIC
1338 printf("G4UIQt::GetHelpChoice SHOULD NEVER GO HERE");
1339#endif
1340 return true;
1341}
1342
1343
1344/** Event filter method. Every event from QtApplication goes here.<br/>
1345 We apply a filter only for the Up and Down Arrow press when the QLineEdit<br/>
1346 is active. If this filter match, Up arrow we give the previous command<br/>
1347 and Down arrow will give the next if exist.<br/>
1348 @param obj Emitter of the event
1349 @param event Kind of event
1350*/
1351bool G4UIQt::eventFilter( // Should stay with a minuscule eventFilter because of Qt
1352 QObject *aObj
1353,QEvent *aEvent
1354)
1355{
1356 bool moveCommandCursor = false;
1357 if (aObj == NULL) return false;
1358 if (aEvent == NULL) return false;
1359
1360 if (aObj == fHistoryTBTableList) {
1361 if (aEvent->type() == QEvent::KeyPress) {
1362 fCommandArea->setFocus();
1363 }
1364 }
1365 if (aObj == fCommandArea) {
1366 if (aEvent->type() == QEvent::KeyPress) {
1367 QKeyEvent *e = static_cast<QKeyEvent*>(aEvent);
1368 if ((e->key() == (Qt::Key_Down)) ||
1369 (e->key() == (Qt::Key_PageDown)) ||
1370 (e->key() == (Qt::Key_Up)) ||
1371 (e->key() == (Qt::Key_PageUp))) {
1372#if QT_VERSION < 0x040000
1373 // count rows...
1374 QListViewItem* tmpItem = fHistoryTBTableList->firstChild();
1375 int selection = -1;
1376 int index = 0;
1377 while (tmpItem != 0) {
1378 if (tmpItem == fHistoryTBTableList->selectedItem()) {
1379 selection = index;
1380 }
1381 index ++;
1382 tmpItem = tmpItem->nextSibling();
1383 }
1384 if (fHistoryTBTableList->childCount()) {
1385 if (selection == -1) {
1386 selection = fHistoryTBTableList->childCount()-1;
1387 } else {
1388 if (e->key() == (Qt::Key_Down)) {
1389 if (selection <(fHistoryTBTableList->childCount()-1))
1390 selection++;
1391 } else if (e->key() == (Qt::Key_PageDown)) {
1392 selection = fHistoryTBTableList->childCount()-1;
1393#else
1394 int selection = fHistoryTBTableList->currentRow();
1395 if (fHistoryTBTableList->count()) {
1396 if (selection == -1) {
1397 selection = fHistoryTBTableList->count()-1;
1398 } else {
1399 if (e->key() == (Qt::Key_Down)) {
1400 if (selection <(fHistoryTBTableList->count()-1))
1401 selection++;
1402 } else if (e->key() == (Qt::Key_PageDown)) {
1403 selection = fHistoryTBTableList->count()-1;
1404#endif
1405 } else if (e->key() == (Qt::Key_Up)) {
1406 if (selection >0)
1407 selection --;
1408 } else if (e->key() == (Qt::Key_PageUp)) {
1409 selection = 0;
1410 }
1411 }
1412 fHistoryTBTableList->clearSelection();
1413#if QT_VERSION < 0x040000
1414 QListViewItem* tmpItem = fHistoryTBTableList->firstChild();
1415 int index = 0;
1416 while (tmpItem != 0) {
1417 if (index == selection) {
1418 tmpItem->setSelected(true);
1419 fHistoryTBTableList->setCurrentItem(tmpItem);
1420 }
1421 index ++;
1422 tmpItem = tmpItem->nextSibling();
1423 }
1424#else
1425#if QT_VERSION < 0x040202
1426 fHistoryTBTableList->setItemSelected(fHistoryTBTableList->item(selection),true);
1427#else
1428 fHistoryTBTableList->item(selection)->setSelected(true);
1429#endif
1430 fHistoryTBTableList->setCurrentItem(fHistoryTBTableList->item(selection));
1431#endif
1432 }
1433 moveCommandCursor = true;
1434 } else if (e->key() == (Qt::Key_Tab)) {
1435#if QT_VERSION < 0x040000
1436 G4String ss = Complete(fCommandArea->text().ascii());
1437#else
1438 G4String ss = Complete(fCommandArea->text().toStdString().c_str());
1439#endif
1440 fCommandArea->setText((char*)(ss.data()));
1441
1442 // do not pass by parent, it will disable widget tab focus !
1443 return true;
1444#if QT_VERSION >= 0x040000
1445 // L.Garnier : MetaModifier is CTRL for MAC, but I don't want to put a MAC
1446 // specific #ifdef
1447 } else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_A)) {
1448 fCommandArea->home(false);
1449 return true;
1450 } else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_E)) {
1451 fCommandArea->end(false);
1452 return true;
1453#endif
1454 }
1455 }
1456 }
1457 bool res= false;
1458 // change cursor position if needed
1459 if (moveCommandCursor == true) {
1460#ifdef G4DEBUG_INTERFACES_BASIC
1461 printf("G4UIQt::eventFilter setCursor Position\n");
1462#endif
1463 fCommandArea->setCursorPosition ( fCommandArea->text().length() );
1464 fCommandArea->setCursorPosition (4);
1465 } else {
1466 // pass the event on to the parent class
1467 res = QObject::eventFilter(aObj, aEvent);
1468 }
1469 return res;
1470}
1471
1472
1473
1474
1475/***************************************************************************/
1476//
1477// SLOTS DEFINITIONS
1478//
1479/***************************************************************************/
1480
1481/** Called when user give "help" command.
1482*/
1483void G4UIQt::ShowHelpCallback (
1484)
1485{
1486 TerminalHelp("");
1487}
1488
1489
1490/** Called when user click on clear button. Clear the text Output area
1491*/
1492void G4UIQt::ClearButtonCallback (
1493)
1494{
1495 fCoutTBTextArea->clear();
1496 fG4cout.clear();
1497}
1498
1499/** Called when user exit session
1500*/
1501void G4UIQt::ExitSession (
1502)
1503{
1504 SessionTerminate();
1505}
1506
1507void G4UIQt::ExitHelp(
1508)
1509{
1510}
1511
1512/** Callback call when "click on a menu entry.<br>
1513 Send the associated command to geant4
1514*/
1515void G4UIQt::CommandEnteredCallback (
1516)
1517{
1518#if QT_VERSION < 0x040000
1519 G4String command (fCommandArea->text().ascii());
1520 if (fCommandArea->text().simplifyWhiteSpace() != "") {
1521
1522 QListViewItem *newItem = new QListViewItem(fHistoryTBTableList);
1523 newItem->setText(0,fCommandArea->text());
1524 fHistoryTBTableList->insertItem(newItem);
1525 // now we have to arrange
1526 QListViewItem *temp= fHistoryTBTableList->lastItem();
1527 for (int i=0; i<fHistoryTBTableList->childCount()-1;i++) {
1528 fHistoryTBTableList->takeItem(temp);
1529 fHistoryTBTableList->insertItem(temp);
1530 temp= fHistoryTBTableList->lastItem();
1531 }
1532#else
1533 G4String command (fCommandArea->text().toStdString().c_str());
1534 if (fCommandArea->text().trimmed() != "") {
1535 fHistoryTBTableList->addItem(fCommandArea->text());
1536#endif
1537 fHistoryTBTableList->clearSelection();
1538 fHistoryTBTableList->setCurrentItem(NULL);
1539 fCommandArea->setText("");
1540
1541 G4Qt* interactorManager = G4Qt::getInstance ();
1542 if (interactorManager) {
1543 interactorManager->FlushAndWaitExecution();
1544 }
1545 if (command(0,4) != "help") {
1546 ApplyShellCommand (command,exitSession,exitPause);
1547 } else {
1548 ActivateCommand(command);
1549 }
1550 // Rebuild help tree
1551 FillHelpTree();
1552
1553 if(exitSession==true)
1554 SessionTerminate();
1555 }
1556}
1557
1558
1559/** Callback call when "enter" clicked on the command zone.<br>
1560 Send the command to geant4
1561 @param aCommand
1562*/
1563void G4UIQt::ButtonCallback (
1564 const QString& aCommand
1565)
1566{
1567#if QT_VERSION < 0x040000
1568 G4String ss = G4String(aCommand.ascii());
1569#else
1570 G4String ss = G4String(aCommand.toStdString().c_str());
1571#endif
1572 ApplyShellCommand(ss,exitSession,exitPause);
1573
1574 // Rebuild help tree
1575 FillHelpTree();
1576
1577 if(exitSession==true)
1578 SessionTerminate();
1579}
1580
1581
1582
1583/** This callback is activated when user selected a item in the help tree
1584*/
1585void G4UIQt::HelpTreeClicCallback (
1586)
1587{
1588#if QT_VERSION < 0x040000
1589 QListViewItem* item = NULL;
1590#else
1591 QTreeWidgetItem* item = NULL;
1592#endif
1593 if (!fHelpTreeWidget)
1594 return ;
1595
1596 if (!fHelpArea)
1597 return;
1598
1599#if QT_VERSION < 0x040000
1600 item =fHelpTreeWidget->selectedItem();
1601#else
1602 QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
1603 if (list.isEmpty())
1604 return;
1605 item = list.first();
1606#endif
1607 if (!item)
1608 return;
1609
1610 G4UImanager* UI = G4UImanager::GetUIpointer();
1611 if(UI==NULL) return;
1612 G4UIcommandTree * treeTop = UI->GetTree();
1613
1614#if QT_VERSION < 0x040000
1615 std::string itemText = GetLongCommandPath(item).ascii();
1616#else
1617 std::string itemText = GetLongCommandPath(item).toStdString();
1618#endif
1619
1620 G4UIcommand* command = treeTop->FindPath(itemText.c_str());
1621
1622 if (command) {
1623#if QT_VERSION >= 0x040000
1624#if QT_VERSION < 0x040200
1625 fHelpArea->clear();
1626 fHelpArea->append(GetCommandList(command));
1627#else
1628 fHelpArea->setText(GetCommandList(command));
1629#endif
1630#else
1631 fHelpArea->setText(GetCommandList(command));
1632#endif
1633 } else { // this is a command
1634 G4UIcommandTree* path = treeTop->FindCommandTree(itemText.c_str());
1635 if ( path) {
1636 // this is not a command, this is a sub directory
1637 // We display the Title
1638#if QT_VERSION >= 0x040000
1639#if QT_VERSION < 0x040200
1640 fHelpArea->clear();
1641 fHelpArea->append(path->GetTitle().data());
1642#else
1643 fHelpArea->setText(path->GetTitle().data());
1644#endif
1645#else
1646 fHelpArea->setText(path->GetTitle().data());
1647#endif
1648 }
1649 }
1650}
1651
1652/** This callback is activated when user double clic on a item in the help tree
1653*/
1654void G4UIQt::HelpTreeDoubleClicCallback (
1655)
1656{
1657 HelpTreeClicCallback();
1658
1659#if QT_VERSION < 0x040000
1660 QListViewItem* item = NULL;
1661#else
1662 QTreeWidgetItem* item = NULL;
1663#endif
1664 if (!fHelpTreeWidget)
1665 return ;
1666
1667 if (!fHelpArea)
1668 return;
1669
1670#if QT_VERSION < 0x040000
1671 item =fHelpTreeWidget->selectedItem();
1672#else
1673 QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
1674 if (list.isEmpty())
1675 return;
1676 item = list.first();
1677#endif
1678 if (!item)
1679 return;
1680
1681 fCommandArea->clear();
1682 fCommandArea->setText(GetLongCommandPath(item));
1683}
1684
1685
1686/** Callback called when user select an old command in the command history<br>
1687 Give it to the command area.
1688*/
1689void G4UIQt::CommandHistoryCallback(
1690)
1691{
1692#if QT_VERSION < 0x040000
1693 QListViewItem* item = NULL;
1694#else
1695 QListWidgetItem* item = NULL;
1696#endif
1697 if (!fHistoryTBTableList)
1698 return ;
1699
1700
1701#if QT_VERSION < 0x040000
1702 item =fHistoryTBTableList->selectedItem();
1703#else
1704 QList<QListWidgetItem *> list =fHistoryTBTableList->selectedItems();
1705 if (list.isEmpty())
1706 return;
1707 item = list.first();
1708#endif
1709 if (!item)
1710 return;
1711#if QT_VERSION < 0x040000
1712 fCommandArea->setText(item->text(0));
1713#else
1714 fCommandArea->setText(item->text());
1715#endif
1716#ifdef G4DEBUG_INTERFACES_BASIC
1717 printf("G4UIQt::CommandHistoryCallback change text\n");
1718#endif
1719}
1720
1721
1722void G4UIQt::CoutFilterCallback(
1723const QString & text) {
1724
1725#if QT_VERSION < 0x040000
1726 QStringList result = "";
1727#else
1728 QStringList result = fG4cout.filter(text);
1729#endif
1730
1731 fCoutTBTextArea->setText(result.join("\n"));
1732 fCoutTBTextArea->repaint();
1733#if QT_VERSION < 0x040000
1734 fCoutTBTextArea->verticalScrollBar()->setValue(fCoutTBTextArea->verticalScrollBar()->maxValue());
1735#else
1736 fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
1737#endif
1738
1739 }
1740
1741/** Callback called when user give a new string to look for<br>
1742 Display a list of matching commands descriptions. If no string is set,
1743 will display the complete help tree
1744*/
1745void G4UIQt::LookForHelpStringCallback(
1746)
1747{
1748 QString searchText = fHelpLine->text();
1749
1750#if QT_VERSION < 0x040200
1751 fHelpArea->clear();
1752#else
1753 fHelpArea->setText("");
1754#endif
1755 if (searchText =="") {
1756 // clear old help tree
1757 fHelpTreeWidget->clear();
1758#if QT_VERSION < 0x040000
1759 fHelpTreeWidget->removeColumn(1);
1760 fHelpTreeWidget->removeColumn(0);
1761#endif
1762
1763 FillHelpTree();
1764
1765 return;
1766 } else {
1767 OpenHelpTreeOnCommand(searchText);
1768 }
1769}
1770
1771
1772void G4UIQt::OpenHelpTreeOnCommand(
1773 const QString & searchText
1774)
1775{
1776
1777 // the help tree
1778 G4UImanager* UI = G4UImanager::GetUIpointer();
1779 if(UI==NULL) return;
1780 G4UIcommandTree * treeTop = UI->GetTree();
1781
1782 G4int treeSize = treeTop->GetTreeEntry();
1783
1784 // clear old help tree
1785 fHelpTreeWidget->clear();
1786#if QT_VERSION < 0x040000
1787 fHelpTreeWidget->removeColumn(1);
1788 fHelpTreeWidget->removeColumn(0);
1789#endif
1790
1791 // look for new items
1792
1793 int tmp = 0;
1794#if QT_VERSION < 0x040000
1795 int multFactor = 1000; // factor special for having double keys in Qt3
1796 int doubleKeyAdd = 0; // decay for doubleKeys in Qt3
1797#endif
1798
1799 QMap<int,QString> commandResultMap;
1800 QMap<int,QString> commandChildResultMap;
1801
1802 for (int a=0;a<treeSize;a++) {
1803 G4UIcommand* command = treeTop->FindPath(treeTop->GetTree(a+1)->GetPathName().data());
1804#if QT_VERSION > 0x040000
1805 tmp = GetCommandList (command).count(searchText,Qt::CaseInsensitive);
1806#else
1807 tmp = GetCommandList (command).contains(searchText,false);
1808#endif
1809 if (tmp >0) {
1810#if QT_VERSION > 0x040000
1811 commandResultMap.insertMulti(tmp,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()));
1812#else // tricky thing for Qt3...
1813 doubleKeyAdd = 0;
1814 while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) {
1815 doubleKeyAdd ++;
1816 }
1817 commandResultMap.insert( tmp*multFactor+doubleKeyAdd,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()) );
1818#endif
1819 }
1820 // look for childs
1821 commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a+1),searchText);
1822 // insert new childs
1823 if (!commandChildResultMap.empty()) {
1824#if QT_VERSION > 0x040000
1825 QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
1826 while (i != commandChildResultMap.constEnd()) {
1827 commandResultMap.insertMulti(i.key(),i.value());
1828#else // tricky thing for Qt3...
1829 QMap<int,QString>::const_iterator i = commandChildResultMap.begin();
1830 while (i != commandChildResultMap.end()) {
1831 doubleKeyAdd = 0;
1832 while (commandResultMap.find( i.key()*multFactor+doubleKeyAdd) != commandResultMap.end()) {
1833 doubleKeyAdd ++;
1834 }
1835 commandResultMap.insert(i.key()*multFactor+doubleKeyAdd,i.data());
1836#endif
1837 i++;
1838 }
1839 commandChildResultMap.clear();
1840 }
1841 }
1842
1843 // build new help tree
1844#if QT_VERSION < 0x040000
1845 fHelpTreeWidget->setSelectionMode(QListView::Single);
1846 fHelpTreeWidget->setRootIsDecorated(true);
1847 fHelpTreeWidget->addColumn("Command");
1848 fHelpTreeWidget->addColumn("Match");
1849 // fHelpTreeWidget->header()->setResizeEnabled(FALSE,1);
1850#else
1851 fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
1852 fHelpTreeWidget->setColumnCount(2);
1853 QStringList labels;
1854 labels << QString("Command") << QString("Match");
1855 fHelpTreeWidget->setHeaderLabels(labels);
1856#endif
1857
1858 if (commandResultMap.empty()) {
1859#if QT_VERSION < 0x040200
1860 fHelpArea->clear();
1861 fHelpArea->append("No match found");
1862#else
1863 fHelpArea->setText("No match found");
1864#endif
1865 return;
1866 }
1867
1868#if QT_VERSION > 0x040000
1869 QMap<int,QString>::const_iterator i = commandResultMap.constEnd();
1870#else
1871 QMap<int,QString>::const_iterator i = commandResultMap.end();
1872#endif
1873 i--;
1874 // 10 maximum progress values
1875 float multValue = 10.0/(float)(i.key());
1876 QString progressChar = "|";
1877 QString progressStr = "|";
1878
1879#if QT_VERSION < 0x040000
1880 QListViewItem * newItem;
1881#else
1882 QTreeWidgetItem * newItem;
1883#endif
1884 bool end = false;
1885 while (!end) {
1886#if QT_VERSION > 0x040000
1887 if (i == commandResultMap.constBegin()) {
1888#else
1889 if (i == commandResultMap.begin()) {
1890#endif
1891 end = true;
1892 }
1893 for(int a=0;a<int(i.key()*multValue);a++) {
1894 progressStr += progressChar;
1895 }
1896#if QT_VERSION < 0x040000
1897 newItem = new QListViewItem(fHelpTreeWidget);
1898 newItem->setText(0,i.data().simplifyWhiteSpace());
1899#else
1900 newItem = new QTreeWidgetItem(fHelpTreeWidget);
1901 newItem->setText(0,i.value().trimmed());
1902#endif
1903 newItem->setText(1,progressStr);
1904
1905#if QT_VERSION >= 0x040200
1906 newItem->setForeground ( 1, QBrush(Qt::blue) );
1907#endif
1908 progressStr = "|";
1909 i--;
1910 }
1911 // FIXME : to be checked on Qt3
1912#if QT_VERSION < 0x040000
1913 fHelpTreeWidget->setColumnWidthMode (1,QListView::Maximum);
1914 fHelpTreeWidget->setSorting(1,false);
1915#else
1916 fHelpTreeWidget->resizeColumnToContents (0);
1917 fHelpTreeWidget->sortItems(1,Qt::DescendingOrder);
1918 // fHelpTreeWidget->setColumnWidth(1,10);//resizeColumnToContents (1);
1919#endif
1920}
1921
1922
1923
1924
1925QMap<int,QString> G4UIQt::LookForHelpStringInChildTree(
1926 G4UIcommandTree *aCommandTree
1927,const QString & text
1928 )
1929{
1930 QMap<int,QString> commandResultMap;
1931 if (aCommandTree == NULL) return commandResultMap;
1932
1933#if QT_VERSION < 0x040000
1934 int multFactor = 1000; // factor special for having double keys in Qt3
1935 int doubleKeyAdd = 0; // decay for doubleKeys in Qt3
1936#endif
1937
1938 // Get the Sub directories
1939 int tmp = 0;
1940 QMap<int,QString> commandChildResultMap;
1941
1942 for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
1943 const G4UIcommand* command = aCommandTree->GetGuidance();
1944#if QT_VERSION > 0x040000
1945 tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
1946#else
1947 tmp = GetCommandList (command).contains(text,false);
1948#endif
1949 if (tmp >0) {
1950#if QT_VERSION > 0x040000
1951 commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()));
1952#else // tricky thing for Qt3...
1953 doubleKeyAdd = 0;
1954 while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) {
1955 doubleKeyAdd ++;
1956 }
1957 commandResultMap.insert(tmp*multFactor+doubleKeyAdd,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()));
1958#endif
1959 }
1960 // look for childs
1961 commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text);
1962
1963 if (!commandChildResultMap.empty()) {
1964 // insert new childs
1965#if QT_VERSION > 0x040000
1966 QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
1967 while (i != commandChildResultMap.constEnd()) {
1968 commandResultMap.insertMulti(i.key(),i.value());
1969#else // tricky thing for Qt3...
1970 QMap<int,QString>::const_iterator i = commandChildResultMap.begin();
1971 while (i != commandChildResultMap.end()) {
1972 doubleKeyAdd = 0;
1973 while (commandResultMap.find( i.key()*multFactor+doubleKeyAdd) != commandResultMap.end()) {
1974 doubleKeyAdd ++;
1975 }
1976 commandResultMap.insert(i.key()*multFactor+doubleKeyAdd,i.data());
1977#endif
1978 i++;
1979 }
1980 commandChildResultMap.clear();
1981 }
1982 }
1983 // Get the Commands
1984
1985 for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
1986 const G4UIcommand* command = aCommandTree->GetCommand(a+1);
1987#if QT_VERSION > 0x040000
1988 tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
1989#else
1990 tmp = GetCommandList (command).contains(text,false);
1991#endif
1992 if (tmp >0) {
1993#if QT_VERSION > 0x040000
1994 commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()));
1995#else // tricky thing for Qt3...
1996 doubleKeyAdd = 0;
1997 while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) {
1998 doubleKeyAdd ++;
1999 }
2000 commandResultMap.insert(tmp*multFactor+doubleKeyAdd,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()));
2001#endif
2002 }
2003
2004 }
2005 return commandResultMap;
2006}
2007
2008
2009QString G4UIQt::GetShortCommandPath(
2010QString commandPath
2011)
2012{
2013#if QT_VERSION < 0x040000
2014 if (commandPath.find("/") == 0) {
2015 commandPath = commandPath.right(commandPath.length()-1);
2016#else
2017 if (commandPath.indexOf("/") == 0) {
2018 commandPath = commandPath.right(commandPath.size()-1);
2019#endif
2020 }
2021
2022#if QT_VERSION < 0x040000
2023 commandPath = commandPath.right(commandPath.length()-commandPath.findRev("/",-2)-1);
2024#else
2025 commandPath = commandPath.right(commandPath.size()-commandPath.lastIndexOf("/",-2)-1);
2026#endif
2027
2028#if QT_VERSION < 0x040000
2029 if (commandPath.findRev("/") == ((int)commandPath.length()-1)) {
2030 commandPath = commandPath.left(commandPath.length()-1);
2031 }
2032#else
2033 if (commandPath.lastIndexOf("/") == (commandPath.size()-1)) {
2034 commandPath = commandPath.left(commandPath.size()-1);
2035 }
2036#endif
2037
2038 return commandPath;
2039}
2040
2041
2042QString G4UIQt::GetLongCommandPath(
2043#if QT_VERSION < 0x040000
2044 QListViewItem* item
2045#else
2046 QTreeWidgetItem* item
2047#endif
2048)
2049{
2050 if (item == NULL) return "";
2051
2052 // rebuild path:
2053 QString itemText = "";
2054 itemText = item->text(0);
2055
2056 while (item->parent() != NULL) {
2057 itemText = item->parent()->text(0)+"/"+itemText;
2058 item = item->parent();
2059 }
2060 itemText = "/"+itemText;
2061
2062 return itemText;
2063}
2064
2065G4QTabWidget::G4QTabWidget(
2066QSplitter*& split
2067):QTabWidget(split)
2068 ,tabSelected(false)
2069 ,lastCreated(-1)
2070{
2071}
2072
2073G4QTabWidget::G4QTabWidget(
2074):QTabWidget()
2075 ,tabSelected(false)
2076 ,lastCreated(-1)
2077{
2078}
2079
2080
2081
2082void G4UIQt::TabCloseCallback(int a){
2083#if QT_VERSION < 0x040000
2084 QWidget* temp = fTabWidget->page(a);
2085 fTabWidget->removePage (temp);
2086#else
2087 QWidget* temp = fTabWidget->widget(a);
2088 fTabWidget->removeTab (a);
2089#endif
2090
2091 delete temp;
2092
2093 if (fTabWidget->count() == 0) {
2094#if QT_VERSION < 0x040000
2095 fEmptyViewerTabLabel->reparent(fMyVSplitter,0,QPoint(0,0));
2096 fTabWidget->reparent(0,0,QPoint(0,0));
2097#else
2098 fMyVSplitter->addWidget(fEmptyViewerTabLabel);
2099 fTabWidget->setParent(0);
2100#endif
2101 }
2102}
2103
2104
2105void G4UIQt::ToolBoxActivated(int a){
2106
2107#if QT_VERSION < 0x040000
2108 if (fToolBox->item(a) == fHelpTBWidget) {
2109#else
2110 if (fToolBox->widget(a) == fHelpTBWidget) {
2111#endif
2112 // Rebuild the help tree
2113 FillHelpTree();
2114 }
2115}
2116
2117void G4QTabWidget::paintEvent(
2118QPaintEvent * event
2119)
2120{
2121
2122#if QT_VERSION < 0x040000
2123 if (currentPage()) {
2124#else
2125 if (currentWidget()) {
2126#endif
2127
2128 if ( isTabSelected()) {
2129
2130#if QT_VERSION < 0x040000
2131 QApplication::sendPostedEvents () ;
2132#else
2133 QCoreApplication::sendPostedEvents () ;
2134#endif
2135
2136#ifdef G4DEBUG_INTERFACES_BASIC
2137 printf("G4QTabWidget::paintEvent OK\n");
2138#endif
2139#if QT_VERSION < 0x040000
2140 QString text = label (currentPageIndex());
2141#else
2142 QString text = tabText (currentIndex());
2143#endif
2144
2145 if (lastCreated == -1) {
2146 QString paramSelect = QString("/vis/viewer/select ")+text;
2147 G4UImanager* UI = G4UImanager::GetUIpointer();
2148 if(UI != NULL) {
2149#if QT_VERSION < 0x040000
2150 UI->ApplyCommand(paramSelect.ascii());
2151#else
2152 UI->ApplyCommand(paramSelect.toStdString().c_str());
2153#endif
2154 }
2155 } else {
2156 lastCreated = -1;
2157 }
2158 unselectTab();
2159 repaint();
2160 }
2161 }
2162}
2163
2164#endif
Note: See TracBrowser for help on using the repository browser.