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

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

try to fix recursive paint

  • Property svn:mime-type set to text/cpp
File size: 56.1 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.39 2010/05/28 13:14:18 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 fTabWidget->setTabSelected(false);
641
642#if QT_VERSION >= 0x040000
643 #if QT_VERSION >= 0x040200
644 fTabWidget->setVisible(true);
645 #else
646 fTabWidget->show();
647 #endif
648#else
649 fTabWidget->show();
650#endif
651
652 // This will send a paintEvent to OGL Viewers
653 fTabWidget->setTabSelected(true);
654
655#if QT_VERSION < 0x040000
656 QApplication::sendPostedEvents () ;
657#else
658 QCoreApplication::sendPostedEvents () ;
659#endif
660
661#ifdef G4DEBUG_INTERFACES_BASIC
662 printf("G4UIQt::UpdateTabWidget END\n");
663#endif
664}
665
666
667/** Send resize event to all tabs
668 */
669void G4UIQt::ResizeTabWidget( QResizeEvent* e) {
670 for (int a=0;a<fTabWidget->count() ;a++) {
671#ifdef G4DEBUG_INTERFACES_BASIC
672 printf("G4UIQt::ResizeTabWidget +++++++++++++++++++++++++++++++++++++++\n");
673#endif
674#if QT_VERSION < 0x040000
675 fTabWidget->page(a)->resize(e->size());
676#else
677 fTabWidget->widget(a)->resize(e->size());
678#endif
679 }
680}
681
682
683/** Start the Qt main loop
684*/
685G4UIsession* G4UIQt::SessionStart (
686)
687{
688#ifdef G4DEBUG_INTERFACES_BASIC
689 printf("G4UIQt::G4UIQt SessionStart\n");
690#endif
691
692 G4Qt* interactorManager = G4Qt::getInstance ();
693
694 Prompt("Session :");
695 exitSession = false;
696
697#if QT_VERSION >= 0x040000
698 #if QT_VERSION >= 0x040200
699 fTabWidget->setVisible(true);
700 fEmptyViewerTabLabel->setVisible(true);
701 #else
702 fTabWidget->show();
703 fEmptyViewerTabLabel->show();
704 #endif
705#else
706 fTabWidget->show();
707 fEmptyViewerTabLabel->show();
708#endif
709
710
711#if QT_VERSION >= 0x040000
712 #if QT_VERSION >= 0x040200
713 fMainWindow->setVisible(true);
714 #else
715 fMainWindow->show();
716 #endif
717#else
718 fMainWindow->show();
719#endif
720
721#if QT_VERSION < 0x040000
722 QApplication::sendPostedEvents () ;
723#else
724 QCoreApplication::sendPostedEvents () ;
725#endif
726
727#ifdef G4DEBUG_INTERFACES_BASIC
728 printf("G4UIQt::G4UIQt SessionStart2\n");
729#endif
730 interactorManager->DisableSecondaryLoop (); // TO KEEP
731 if ((QApplication*)interactorManager->GetMainInteractor())
732 ((QApplication*)interactorManager->GetMainInteractor())->exec();
733
734 // on ne passe pas le dessous ? FIXME ????
735 // je ne pense pas 13/06
736
737 // void* event; // TO KEEP
738 // while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP
739 // interactorManager->DispatchEvent(event); // TO KEEP
740 // if(exitSession==true) break; // TO KEEP
741 // } // TO KEEP
742
743 interactorManager->EnableSecondaryLoop ();
744 return this;
745}
746
747
748/** Display the prompt in the prompt area
749 @param aPrompt : string to display as the promt label
750 //FIXME : probablement inutile puisque le seul a afficher qq chose d'autre
751 que "session" est SecondaryLoop()
752*/
753void G4UIQt::Prompt (
754 G4String aPrompt
755)
756{
757 if (!aPrompt) return;
758
759 fCommandLabel->setText((char*)aPrompt.data());
760}
761
762
763
764void G4UIQt::SessionTerminate (
765)
766{
767 G4Qt* interactorManager = G4Qt::getInstance ();
768 fMainWindow->close();
769 ((QApplication*)interactorManager->GetMainInteractor())->exit();
770}
771
772
773
774/**
775 Called by intercoms/src/G4UImanager.cc<br>
776 Called by visualization/management/src/G4VisCommands.cc with "EndOfEvent" argument<br>
777 It have to pause the session command terminal.<br>
778 Call SecondaryLoop to wait for exit event<br>
779 @param aState
780 @see : G4VisCommandReviewKeptEvents::SetNewValue
781*/
782void G4UIQt::PauseSessionStart (
783 G4String aState
784)
785{
786 if (!aState) return;
787
788 if(aState=="G4_pause> ") { // TO KEEP
789 SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP
790 } // TO KEEP
791
792 if(aState=="EndOfEvent") { // TO KEEP
793 // Picking with feed back in event data Done here !!!
794 SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP
795 } // TO KEEP
796}
797
798
799
800/**
801 Begin the secondary loop
802 @param a_prompt : label to display as the prompt label
803 */
804void G4UIQt::SecondaryLoop (
805 G4String aPrompt
806)
807{
808 if (!aPrompt) return;
809
810 G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ?
811 Prompt(aPrompt); // TO KEEP
812 exitPause = false; // TO KEEP
813 void* event; // TO KEEP
814 while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP
815 interactorManager->DispatchEvent(event); // TO KEEP
816 if(exitPause==true) break; // TO KEEP
817 } // TO KEEP
818 Prompt("Session :"); // TO KEEP
819}
820
821
822
823/**
824 Receive a cout from Geant4. We have to display it in the cout zone
825 @param aString : label to add in the display area
826 @return 0
827*/
828G4int G4UIQt::ReceiveG4cout (
829 G4String aString
830 )
831{
832 if (!aString) return 0;
833
834 QStringList newStr;
835
836 // Add to stringList
837#if QT_VERSION < 0x040000
838 newStr = QStringList(QString((char*)aString.data()).simplifyWhiteSpace());
839#else
840 newStr = QStringList(QString((char*)aString.data()).trimmed());
841#endif
842 fG4cout += newStr;
843
844#if QT_VERSION >= 0x040000
845 QStringList result = newStr.filter(fCoutFilter->text());
846#else
847 //L. Garnier : in qt3 filter will does nothing
848 QStringList result = "";
849#endif
850
851 if (result.join("\n").isEmpty()) {
852 return 0;
853 }
854 fCoutTBTextArea->append(result.join("\n"));
855 fCoutTBTextArea->repaint();
856
857#if QT_VERSION < 0x040000
858 fCoutTBTextArea->verticalScrollBar()->setValue(fCoutTBTextArea->verticalScrollBar()->maxValue());
859#else
860 fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
861#endif
862
863 return 0;
864}
865
866
867/**
868 Receive a cerr from Geant4. We have to display it in the cout zone
869 @param aString : label to add in the display area
870 @return 0
871*/
872G4int G4UIQt::ReceiveG4cerr (
873 G4String aString
874)
875{
876 if (!aString) return 0;
877
878 QStringList newStr;
879
880 // Add to stringList
881#if QT_VERSION < 0x040000
882 newStr = QStringList(QString((char*)aString.data()).simplifyWhiteSpace());
883#else
884 newStr = QStringList(QString((char*)aString.data()).trimmed());
885#endif
886 fG4cout += newStr;
887
888#if QT_VERSION < 0x040000
889 //L. Garnier : in qt3 filter will does nothing
890 QStringList result = "";
891#else
892 QStringList result = newStr.filter(fCoutFilter->text());
893#endif
894
895#if QT_VERSION < 0x040000
896 QColor previousColor = fCoutTBTextArea->color();
897 fCoutTBTextArea->setColor(Qt::red);
898 fCoutTBTextArea->append(result.join("\n"));
899 fCoutTBTextArea->setColor(previousColor);
900 fCoutTBTextArea->verticalScrollBar()->setValue(fCoutTBTextArea->verticalScrollBar()->maxValue());
901#else
902 QColor previousColor = fCoutTBTextArea->textColor();
903 fCoutTBTextArea->setTextColor(Qt::red);
904 fCoutTBTextArea->append(result.join("\n"));
905 fCoutTBTextArea->setTextColor(previousColor);
906 fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
907#endif
908 fCoutTBTextArea->repaint();
909 return 0;
910}
911
912
913
914/**
915 Add a new menu to the menu bar
916 @param aName name of menu
917 @param aLabel label to display
918 */
919void G4UIQt::AddMenu (
920 const char* aName
921,const char* aLabel
922)
923{
924 if (aName == NULL) return;
925 if (aLabel == NULL) return;
926
927#if QT_VERSION < 0x040000
928 QPopupMenu *fileMenu = new QPopupMenu( fMainWindow);
929 fMainWindow->menuBar()->insertItem( aLabel, fileMenu );
930#else
931 QMenu *fileMenu = new QMenu(aLabel);
932 fMainWindow->menuBar()->insertMenu(fMainWindow->menuBar()->actions().last(),fileMenu);
933#endif
934
935 AddInteractor (aName,(G4Interactor)fileMenu);
936}
937
938
939/**
940 Add a new button to a menu
941 @param aMenu : parent menu
942 @param aLabel : label to display
943 @param aCommand : command to execute as a callback
944 */
945void G4UIQt::AddButton (
946 const char* aMenu
947,const char* aLabel
948,const char* aCommand
949)
950{
951 if(aMenu==NULL) return; // TO KEEP
952 if(aLabel==NULL) return; // TO KEEP
953 if(aCommand==NULL) return; // TO KEEP
954
955#if QT_VERSION < 0x040000
956 QPopupMenu *parent = (QPopupMenu*)GetInteractor(aMenu);
957#else
958 QMenu *parent = (QMenu*)GetInteractor(aMenu);
959#endif
960
961 if(parent==NULL) return;
962
963 QSignalMapper *signalMapper = new QSignalMapper(this);
964#if QT_VERSION < 0x030200
965 QAction *action = new QAction(QString(aLabel),QString(aLabel),QKeySequence(),signalMapper, SLOT(map()));
966 action->addTo(parent);
967 connect(action,SIGNAL(activated()),signalMapper,SLOT(map()));
968
969#elif QT_VERSION < 0x040000
970 QAction *action = new QAction(QString(aLabel),QKeySequence(),signalMapper, SLOT(map()));
971 action->addTo(parent);
972 connect(action,SIGNAL(activated()),signalMapper,SLOT(map()));
973
974#else
975 QAction *action = parent->addAction(aLabel, signalMapper, SLOT(map()));
976
977#endif
978 connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&)));
979 signalMapper->setMapping(action, QString(aCommand));
980}
981
982
983
984
985void G4UIQt::ActivateCommand(
986 G4String newCommand
987)
988{
989 if (!fHelpTreeWidget) {
990 return;
991 }
992 // Look for the choosen command "newCommand"
993 size_t i = newCommand.index(" ");
994 G4String targetCom ="";
995 if( i != std::string::npos )
996 {
997 G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
998 newValue.strip(G4String::both);
999 targetCom = ModifyToFullPathCommand( newValue );
1000 }
1001#ifdef G4DEBUG_INTERFACES_BASIC
1002 printf("G4UIQt::ActivateCommand found : %s \n",targetCom.data());
1003#endif
1004 if (targetCom != "") {
1005 OpenHelpTreeOnCommand(targetCom.data());
1006 }
1007
1008#if QT_VERSION < 0x040000
1009 fToolBox->setCurrentItem(fHelpTBWidget);
1010#else
1011 fToolBox->setCurrentWidget(fHelpTBWidget);
1012#endif
1013}
1014
1015
1016
1017/**
1018 Create the help tree widget
1019 @param parent : parent of tree widget
1020 @return the widget containing the tree or NULL if it could not have beeen created
1021 */
1022
1023void G4UIQt::InitHelpTree()
1024{
1025
1026 if (! fHelpTreeWidget ) {
1027#if QT_VERSION < 0x040000
1028 fHelpTreeWidget = new QListView(fHelpVSplitter);
1029#else
1030 fHelpTreeWidget = new QTreeWidget();
1031#endif
1032 }
1033
1034
1035 // build widget
1036#if QT_VERSION < 0x040000
1037 fHelpTreeWidget->setSelectionMode(QListView::Single);
1038 fHelpTreeWidget->setRootIsDecorated(true);
1039 fHelpTreeWidget->addColumn("Command");
1040 fHelpTreeWidget->header()->setResizeEnabled(FALSE,1);
1041#else
1042 fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
1043 QStringList labels;
1044 labels << QString("Command");
1045 fHelpTreeWidget->setHeaderLabels(labels);
1046#endif
1047
1048
1049#if QT_VERSION < 0x040000
1050 connect(fHelpTreeWidget, SIGNAL(selectionChanged ()),this, SLOT(HelpTreeClicCallback()));
1051 connect(fHelpTreeWidget, SIGNAL(doubleClicked (QListViewItem*)),this, SLOT(HelpTreeDoubleClicCallback()));
1052#else
1053 connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback()));
1054 connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback()));
1055#endif
1056
1057}
1058/**
1059 Create the help tree widget
1060 @param parent : parent of tree widget
1061 @return the widget containing the tree or NULL if it could not have beeen created
1062 */
1063
1064void G4UIQt::FillHelpTree()
1065{
1066 if (! fHelpTreeWidget ) {
1067 InitHelpTree();
1068 }
1069
1070 G4UImanager* UI = G4UImanager::GetUIpointer();
1071 if(UI==NULL) return;
1072 G4UIcommandTree * treeTop = UI->GetTree();
1073
1074 G4int treeSize = treeTop->GetTreeEntry();
1075#if QT_VERSION < 0x040000
1076 QListViewItem * newItem = NULL;
1077#else
1078 QTreeWidgetItem * newItem = NULL;
1079#endif
1080 QString commandText = "";
1081 for (int a=0;a<treeSize;a++) {
1082 // Creating new item
1083 newItem = NULL;
1084
1085#if QT_VERSION < 0x040000
1086 commandText = QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace();
1087#else
1088 commandText = QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed();
1089#endif
1090
1091 // if already exist, don't create it !
1092#if QT_VERSION < 0x040000
1093 QListViewItem* tmpAddItem = fHelpTreeWidget->firstChild();
1094 while (tmpAddItem != 0) {
1095 if (!newItem) {
1096 newItem = FindTreeItem(tmpAddItem,commandText);
1097 }
1098 tmpAddItem = tmpAddItem->nextSibling();
1099 }
1100#else
1101 for (int b=0;b<fHelpTreeWidget->topLevelItemCount();b++) {
1102 if (!newItem)
1103 newItem = FindTreeItem(fHelpTreeWidget->topLevelItem(b),commandText);
1104 }
1105#endif
1106
1107 if (newItem == NULL) {
1108
1109#if QT_VERSION < 0x040000
1110 newItem = new QListViewItem(fHelpTreeWidget);
1111#else
1112 newItem = new QTreeWidgetItem(fHelpTreeWidget);
1113#endif
1114 newItem->setText(0,GetShortCommandPath(commandText));
1115 }
1116
1117 // look for childs
1118 CreateChildTree(newItem,treeTop->GetTree(a+1));
1119 }
1120
1121}
1122
1123
1124
1125/** Fill the Help Tree Widget
1126 @param aParent : parent item to fill
1127 @param aCommandTree : commandTree node associate with this part of the Tree
1128*/
1129#if QT_VERSION < 0x040000
1130void G4UIQt::CreateChildTree(
1131 QListViewItem *aParent
1132,G4UIcommandTree *aCommandTree
1133#else
1134void G4UIQt::CreateChildTree(
1135 QTreeWidgetItem *aParent
1136,G4UIcommandTree *aCommandTree
1137#endif
1138)
1139{
1140 if (aParent == NULL) return;
1141 if (aCommandTree == NULL) return;
1142
1143
1144 // Creating new item
1145#if QT_VERSION < 0x040000
1146 QListViewItem * newItem;
1147#else
1148 QTreeWidgetItem * newItem;
1149#endif
1150
1151 QString commandText = "";
1152 // Get the Sub directories
1153 for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
1154
1155#if QT_VERSION < 0x040000
1156 commandText = QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace();
1157#else
1158 commandText = QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed();
1159#endif
1160
1161 // if already exist, don't create it !
1162 newItem = FindTreeItem(aParent,commandText);
1163 if (newItem == NULL) {
1164#if QT_VERSION < 0x040000
1165 newItem = new QListViewItem(aParent);
1166#else
1167 newItem = new QTreeWidgetItem(aParent);
1168#endif
1169 newItem->setText(0,GetShortCommandPath(commandText));
1170 }
1171 CreateChildTree(newItem,aCommandTree->GetTree(a+1));
1172 }
1173
1174
1175
1176 // Get the Commands
1177
1178 for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
1179
1180 QStringList stringList;
1181#if QT_VERSION < 0x040000
1182 commandText = QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).simplifyWhiteSpace();
1183#else
1184 commandText = QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed();
1185#endif
1186
1187 // if already exist, don't create it !
1188 newItem = FindTreeItem(aParent,commandText);
1189 if (newItem == NULL) {
1190#if QT_VERSION < 0x040000
1191 newItem = new QListViewItem(aParent);
1192 newItem->setText(0,GetShortCommandPath(commandText));
1193 newItem->setOpen(false);
1194
1195#else
1196 newItem = new QTreeWidgetItem(aParent);
1197 newItem->setText(0,GetShortCommandPath(commandText));
1198#if QT_VERSION < 0x040202
1199 fHelpTreeWidget->setItemExpanded(newItem,false);
1200#else
1201 newItem->setExpanded(false);
1202#endif
1203#endif
1204 }
1205 }
1206}
1207
1208
1209/** Find a treeItemWidget in the help tree
1210 @param aCommand item's String to look for
1211 @return item if found, NULL if not
1212*/
1213#if QT_VERSION < 0x040000
1214QListViewItem* G4UIQt::FindTreeItem(
1215 QListViewItem *aParent
1216#else
1217QTreeWidgetItem* G4UIQt::FindTreeItem(
1218 QTreeWidgetItem *aParent
1219#endif
1220,const QString& aCommand
1221)
1222{
1223 if (aParent == NULL) return NULL;
1224
1225 // Suppress last "/"
1226 QString myCommand = aCommand;
1227
1228#if QT_VERSION < 0x040000
1229 if (myCommand.findRev("/") == ((int)myCommand.length()-1)) {
1230 myCommand = myCommand.left(myCommand.length()-1);
1231#else
1232 if (myCommand.lastIndexOf("/") == (myCommand.size()-1)) {
1233 myCommand = myCommand.left(myCommand.size()-1);
1234#endif
1235 }
1236
1237 if (GetLongCommandPath(aParent) == myCommand)
1238 return aParent;
1239
1240#if QT_VERSION < 0x040000
1241 QListViewItem * tmp = NULL;
1242 QListViewItem* tmpItem = aParent->firstChild();
1243 while (tmpItem != 0) {
1244 if (!tmp)
1245 tmp = FindTreeItem(tmpItem,myCommand);
1246 tmpItem = tmpItem->nextSibling();
1247 }
1248#else
1249 QTreeWidgetItem * tmp = NULL;
1250 for (int a=0;a<aParent->childCount();a++) {
1251 if (!tmp)
1252 tmp = FindTreeItem(aParent->child(a),myCommand);
1253 }
1254#endif
1255 return tmp;
1256}
1257
1258
1259
1260/** Build the command list parameters in a QString<br>
1261 Reimplement partialy the G4UIparameter.cc
1262 @param aCommand : command to list parameters
1263 @see G4UIparameter::List()
1264 @see G4UIcommand::List()
1265 @return the command list parameters, or "" if nothing
1266*/
1267QString G4UIQt::GetCommandList (
1268 const G4UIcommand *aCommand
1269)
1270{
1271
1272 QString txt ="";
1273 if (aCommand == NULL)
1274 return txt;
1275
1276 G4String commandPath = aCommand->GetCommandPath();
1277 G4String rangeString = aCommand->GetRange();
1278 G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
1279 G4int n_parameterEntry = aCommand->GetParameterEntries();
1280
1281 if ((commandPath == "") &&
1282 (rangeString == "") &&
1283 (n_guidanceEntry == 0) &&
1284 (n_parameterEntry == 0)) {
1285 return txt;
1286 }
1287
1288 if((commandPath.length()-1)!='/') {
1289 txt += "Command " + QString((char*)(commandPath).data()) + "\n";
1290 }
1291 txt += "Guidance :\n";
1292
1293 for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
1294 txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
1295 }
1296 if( ! rangeString.isNull() ) {
1297 txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n";
1298 }
1299 if( n_parameterEntry > 0 ) {
1300 G4UIparameter *param;
1301
1302 // Re-implementation of G4UIparameter.cc
1303
1304 for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
1305 param = aCommand->GetParameter(i_thParameter);
1306 txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
1307 if( ! param->GetParameterGuidance().isNull() )
1308 txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
1309 txt += " Parameter type : " + QString(QChar(param->GetParameterType())) + "\n";
1310 if(param->IsOmittable()){
1311 txt += " Omittable : True\n";
1312 } else {
1313 txt += " Omittable : False\n";
1314 }
1315 if( param->GetCurrentAsDefault() ) {
1316 txt += " Default value : taken from the current value\n";
1317 } else if( ! param->GetDefaultValue().isNull() ) {
1318 txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n";
1319 }
1320 if( ! param->GetParameterRange().isNull() ) {
1321 txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
1322 }
1323 if( ! param->GetParameterCandidates().isNull() ) {
1324 txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
1325 }
1326 }
1327 }
1328 return txt;
1329}
1330
1331
1332
1333/** Implement G4VBasicShell vurtual function
1334 */
1335G4bool G4UIQt::GetHelpChoice(
1336 G4int&
1337)
1338{
1339#ifdef G4DEBUG_INTERFACES_BASIC
1340 printf("G4UIQt::GetHelpChoice SHOULD NEVER GO HERE");
1341#endif
1342 return true;
1343}
1344
1345
1346/** Event filter method. Every event from QtApplication goes here.<br/>
1347 We apply a filter only for the Up and Down Arrow press when the QLineEdit<br/>
1348 is active. If this filter match, Up arrow we give the previous command<br/>
1349 and Down arrow will give the next if exist.<br/>
1350 @param obj Emitter of the event
1351 @param event Kind of event
1352*/
1353bool G4UIQt::eventFilter( // Should stay with a minuscule eventFilter because of Qt
1354 QObject *aObj
1355,QEvent *aEvent
1356)
1357{
1358 bool moveCommandCursor = false;
1359 if (aObj == NULL) return false;
1360 if (aEvent == NULL) return false;
1361
1362 if (aObj == fHistoryTBTableList) {
1363 if (aEvent->type() == QEvent::KeyPress) {
1364 fCommandArea->setFocus();
1365 }
1366 }
1367 if (aObj == fCommandArea) {
1368 if (aEvent->type() == QEvent::KeyPress) {
1369 QKeyEvent *e = static_cast<QKeyEvent*>(aEvent);
1370 if ((e->key() == (Qt::Key_Down)) ||
1371 (e->key() == (Qt::Key_PageDown)) ||
1372 (e->key() == (Qt::Key_Up)) ||
1373 (e->key() == (Qt::Key_PageUp))) {
1374#if QT_VERSION < 0x040000
1375 // count rows...
1376 QListViewItem* tmpItem = fHistoryTBTableList->firstChild();
1377 int selection = -1;
1378 int index = 0;
1379 while (tmpItem != 0) {
1380 if (tmpItem == fHistoryTBTableList->selectedItem()) {
1381 selection = index;
1382 }
1383 index ++;
1384 tmpItem = tmpItem->nextSibling();
1385 }
1386 if (fHistoryTBTableList->childCount()) {
1387 if (selection == -1) {
1388 selection = fHistoryTBTableList->childCount()-1;
1389 } else {
1390 if (e->key() == (Qt::Key_Down)) {
1391 if (selection <(fHistoryTBTableList->childCount()-1))
1392 selection++;
1393 } else if (e->key() == (Qt::Key_PageDown)) {
1394 selection = fHistoryTBTableList->childCount()-1;
1395#else
1396 int selection = fHistoryTBTableList->currentRow();
1397 if (fHistoryTBTableList->count()) {
1398 if (selection == -1) {
1399 selection = fHistoryTBTableList->count()-1;
1400 } else {
1401 if (e->key() == (Qt::Key_Down)) {
1402 if (selection <(fHistoryTBTableList->count()-1))
1403 selection++;
1404 } else if (e->key() == (Qt::Key_PageDown)) {
1405 selection = fHistoryTBTableList->count()-1;
1406#endif
1407 } else if (e->key() == (Qt::Key_Up)) {
1408 if (selection >0)
1409 selection --;
1410 } else if (e->key() == (Qt::Key_PageUp)) {
1411 selection = 0;
1412 }
1413 }
1414 fHistoryTBTableList->clearSelection();
1415#if QT_VERSION < 0x040000
1416 QListViewItem* tmpItem = fHistoryTBTableList->firstChild();
1417 int index = 0;
1418 while (tmpItem != 0) {
1419 if (index == selection) {
1420 tmpItem->setSelected(true);
1421 fHistoryTBTableList->setCurrentItem(tmpItem);
1422 }
1423 index ++;
1424 tmpItem = tmpItem->nextSibling();
1425 }
1426#else
1427#if QT_VERSION < 0x040202
1428 fHistoryTBTableList->setItemSelected(fHistoryTBTableList->item(selection),true);
1429#else
1430 fHistoryTBTableList->item(selection)->setSelected(true);
1431#endif
1432 fHistoryTBTableList->setCurrentItem(fHistoryTBTableList->item(selection));
1433#endif
1434 }
1435 moveCommandCursor = true;
1436 } else if (e->key() == (Qt::Key_Tab)) {
1437#if QT_VERSION < 0x040000
1438 G4String ss = Complete(fCommandArea->text().ascii());
1439#else
1440 G4String ss = Complete(fCommandArea->text().toStdString().c_str());
1441#endif
1442 fCommandArea->setText((char*)(ss.data()));
1443
1444 // do not pass by parent, it will disable widget tab focus !
1445 return true;
1446#if QT_VERSION >= 0x040000
1447 // L.Garnier : MetaModifier is CTRL for MAC, but I don't want to put a MAC
1448 // specific #ifdef
1449 } else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_A)) {
1450 fCommandArea->home(false);
1451 return true;
1452 } else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_E)) {
1453 fCommandArea->end(false);
1454 return true;
1455#endif
1456 }
1457 }
1458 }
1459 bool res= false;
1460 // change cursor position if needed
1461 if (moveCommandCursor == true) {
1462#ifdef G4DEBUG_INTERFACES_BASIC
1463 printf("G4UIQt::eventFilter setCursor Position\n");
1464#endif
1465 fCommandArea->setCursorPosition ( fCommandArea->text().length() );
1466 fCommandArea->setCursorPosition (4);
1467 } else {
1468 // pass the event on to the parent class
1469 res = QObject::eventFilter(aObj, aEvent);
1470 }
1471 return res;
1472}
1473
1474
1475
1476
1477/***************************************************************************/
1478//
1479// SLOTS DEFINITIONS
1480//
1481/***************************************************************************/
1482
1483/** Called when user give "help" command.
1484*/
1485void G4UIQt::ShowHelpCallback (
1486)
1487{
1488 TerminalHelp("");
1489}
1490
1491
1492/** Called when user click on clear button. Clear the text Output area
1493*/
1494void G4UIQt::ClearButtonCallback (
1495)
1496{
1497 fCoutTBTextArea->clear();
1498 fG4cout.clear();
1499}
1500
1501/** Called when user exit session
1502*/
1503void G4UIQt::ExitSession (
1504)
1505{
1506 SessionTerminate();
1507}
1508
1509void G4UIQt::ExitHelp(
1510)
1511{
1512}
1513
1514/** Callback call when "click on a menu entry.<br>
1515 Send the associated command to geant4
1516*/
1517void G4UIQt::CommandEnteredCallback (
1518)
1519{
1520#if QT_VERSION < 0x040000
1521 G4String command (fCommandArea->text().ascii());
1522 if (fCommandArea->text().simplifyWhiteSpace() != "") {
1523
1524 QListViewItem *newItem = new QListViewItem(fHistoryTBTableList);
1525 newItem->setText(0,fCommandArea->text());
1526 fHistoryTBTableList->insertItem(newItem);
1527 // now we have to arrange
1528 QListViewItem *temp= fHistoryTBTableList->lastItem();
1529 for (int i=0; i<fHistoryTBTableList->childCount()-1;i++) {
1530 fHistoryTBTableList->takeItem(temp);
1531 fHistoryTBTableList->insertItem(temp);
1532 temp= fHistoryTBTableList->lastItem();
1533 }
1534#else
1535 G4String command (fCommandArea->text().toStdString().c_str());
1536 if (fCommandArea->text().trimmed() != "") {
1537 fHistoryTBTableList->addItem(fCommandArea->text());
1538#endif
1539 fHistoryTBTableList->clearSelection();
1540 fHistoryTBTableList->setCurrentItem(NULL);
1541 fCommandArea->setText("");
1542
1543 G4Qt* interactorManager = G4Qt::getInstance ();
1544 if (interactorManager) {
1545 interactorManager->FlushAndWaitExecution();
1546 }
1547 if (command(0,4) != "help") {
1548 ApplyShellCommand (command,exitSession,exitPause);
1549 } else {
1550 ActivateCommand(command);
1551 }
1552 // Rebuild help tree
1553 FillHelpTree();
1554
1555 if(exitSession==true)
1556 SessionTerminate();
1557 }
1558}
1559
1560
1561/** Callback call when "enter" clicked on the command zone.<br>
1562 Send the command to geant4
1563 @param aCommand
1564*/
1565void G4UIQt::ButtonCallback (
1566 const QString& aCommand
1567)
1568{
1569#if QT_VERSION < 0x040000
1570 G4String ss = G4String(aCommand.ascii());
1571#else
1572 G4String ss = G4String(aCommand.toStdString().c_str());
1573#endif
1574 ApplyShellCommand(ss,exitSession,exitPause);
1575
1576 // Rebuild help tree
1577 FillHelpTree();
1578
1579 if(exitSession==true)
1580 SessionTerminate();
1581}
1582
1583
1584
1585/** This callback is activated when user selected a item in the help tree
1586*/
1587void G4UIQt::HelpTreeClicCallback (
1588)
1589{
1590#if QT_VERSION < 0x040000
1591 QListViewItem* item = NULL;
1592#else
1593 QTreeWidgetItem* item = NULL;
1594#endif
1595 if (!fHelpTreeWidget)
1596 return ;
1597
1598 if (!fHelpArea)
1599 return;
1600
1601#if QT_VERSION < 0x040000
1602 item =fHelpTreeWidget->selectedItem();
1603#else
1604 QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
1605 if (list.isEmpty())
1606 return;
1607 item = list.first();
1608#endif
1609 if (!item)
1610 return;
1611
1612 G4UImanager* UI = G4UImanager::GetUIpointer();
1613 if(UI==NULL) return;
1614 G4UIcommandTree * treeTop = UI->GetTree();
1615
1616#if QT_VERSION < 0x040000
1617 std::string itemText = GetLongCommandPath(item).ascii();
1618#else
1619 std::string itemText = GetLongCommandPath(item).toStdString();
1620#endif
1621
1622 G4UIcommand* command = treeTop->FindPath(itemText.c_str());
1623
1624 if (command) {
1625#if QT_VERSION >= 0x040000
1626#if QT_VERSION < 0x040200
1627 fHelpArea->clear();
1628 fHelpArea->append(GetCommandList(command));
1629#else
1630 fHelpArea->setText(GetCommandList(command));
1631#endif
1632#else
1633 fHelpArea->setText(GetCommandList(command));
1634#endif
1635 } else { // this is a command
1636 G4UIcommandTree* path = treeTop->FindCommandTree(itemText.c_str());
1637 if ( path) {
1638 // this is not a command, this is a sub directory
1639 // We display the Title
1640#if QT_VERSION >= 0x040000
1641#if QT_VERSION < 0x040200
1642 fHelpArea->clear();
1643 fHelpArea->append(path->GetTitle().data());
1644#else
1645 fHelpArea->setText(path->GetTitle().data());
1646#endif
1647#else
1648 fHelpArea->setText(path->GetTitle().data());
1649#endif
1650 }
1651 }
1652}
1653
1654/** This callback is activated when user double clic on a item in the help tree
1655*/
1656void G4UIQt::HelpTreeDoubleClicCallback (
1657)
1658{
1659 HelpTreeClicCallback();
1660
1661#if QT_VERSION < 0x040000
1662 QListViewItem* item = NULL;
1663#else
1664 QTreeWidgetItem* item = NULL;
1665#endif
1666 if (!fHelpTreeWidget)
1667 return ;
1668
1669 if (!fHelpArea)
1670 return;
1671
1672#if QT_VERSION < 0x040000
1673 item =fHelpTreeWidget->selectedItem();
1674#else
1675 QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
1676 if (list.isEmpty())
1677 return;
1678 item = list.first();
1679#endif
1680 if (!item)
1681 return;
1682
1683 fCommandArea->clear();
1684 fCommandArea->setText(GetLongCommandPath(item));
1685}
1686
1687
1688/** Callback called when user select an old command in the command history<br>
1689 Give it to the command area.
1690*/
1691void G4UIQt::CommandHistoryCallback(
1692)
1693{
1694#if QT_VERSION < 0x040000
1695 QListViewItem* item = NULL;
1696#else
1697 QListWidgetItem* item = NULL;
1698#endif
1699 if (!fHistoryTBTableList)
1700 return ;
1701
1702
1703#if QT_VERSION < 0x040000
1704 item =fHistoryTBTableList->selectedItem();
1705#else
1706 QList<QListWidgetItem *> list =fHistoryTBTableList->selectedItems();
1707 if (list.isEmpty())
1708 return;
1709 item = list.first();
1710#endif
1711 if (!item)
1712 return;
1713#if QT_VERSION < 0x040000
1714 fCommandArea->setText(item->text(0));
1715#else
1716 fCommandArea->setText(item->text());
1717#endif
1718#ifdef G4DEBUG_INTERFACES_BASIC
1719 printf("G4UIQt::CommandHistoryCallback change text\n");
1720#endif
1721}
1722
1723
1724void G4UIQt::CoutFilterCallback(
1725const QString & text) {
1726
1727#if QT_VERSION < 0x040000
1728 QStringList result = "";
1729#else
1730 QStringList result = fG4cout.filter(text);
1731#endif
1732
1733 fCoutTBTextArea->setText(result.join("\n"));
1734 fCoutTBTextArea->repaint();
1735#if QT_VERSION < 0x040000
1736 fCoutTBTextArea->verticalScrollBar()->setValue(fCoutTBTextArea->verticalScrollBar()->maxValue());
1737#else
1738 fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
1739#endif
1740
1741 }
1742
1743/** Callback called when user give a new string to look for<br>
1744 Display a list of matching commands descriptions. If no string is set,
1745 will display the complete help tree
1746*/
1747void G4UIQt::LookForHelpStringCallback(
1748)
1749{
1750 QString searchText = fHelpLine->text();
1751
1752#if QT_VERSION < 0x040200
1753 fHelpArea->clear();
1754#else
1755 fHelpArea->setText("");
1756#endif
1757 if (searchText =="") {
1758 // clear old help tree
1759 fHelpTreeWidget->clear();
1760#if QT_VERSION < 0x040000
1761 fHelpTreeWidget->removeColumn(1);
1762 fHelpTreeWidget->removeColumn(0);
1763#endif
1764
1765 FillHelpTree();
1766
1767 return;
1768 } else {
1769 OpenHelpTreeOnCommand(searchText);
1770 }
1771}
1772
1773
1774void G4UIQt::OpenHelpTreeOnCommand(
1775 const QString & searchText
1776)
1777{
1778
1779 // the help tree
1780 G4UImanager* UI = G4UImanager::GetUIpointer();
1781 if(UI==NULL) return;
1782 G4UIcommandTree * treeTop = UI->GetTree();
1783
1784 G4int treeSize = treeTop->GetTreeEntry();
1785
1786 // clear old help tree
1787 fHelpTreeWidget->clear();
1788#if QT_VERSION < 0x040000
1789 fHelpTreeWidget->removeColumn(1);
1790 fHelpTreeWidget->removeColumn(0);
1791#endif
1792
1793 // look for new items
1794
1795 int tmp = 0;
1796#if QT_VERSION < 0x040000
1797 int multFactor = 1000; // factor special for having double keys in Qt3
1798 int doubleKeyAdd = 0; // decay for doubleKeys in Qt3
1799#endif
1800
1801 QMap<int,QString> commandResultMap;
1802 QMap<int,QString> commandChildResultMap;
1803
1804 for (int a=0;a<treeSize;a++) {
1805 G4UIcommand* command = treeTop->FindPath(treeTop->GetTree(a+1)->GetPathName().data());
1806#if QT_VERSION > 0x040000
1807 tmp = GetCommandList (command).count(searchText,Qt::CaseInsensitive);
1808#else
1809 tmp = GetCommandList (command).contains(searchText,false);
1810#endif
1811 if (tmp >0) {
1812#if QT_VERSION > 0x040000
1813 commandResultMap.insertMulti(tmp,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()));
1814#else // tricky thing for Qt3...
1815 doubleKeyAdd = 0;
1816 while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) {
1817 doubleKeyAdd ++;
1818 }
1819 commandResultMap.insert( tmp*multFactor+doubleKeyAdd,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()) );
1820#endif
1821 }
1822 // look for childs
1823 commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a+1),searchText);
1824 // insert new childs
1825 if (!commandChildResultMap.empty()) {
1826#if QT_VERSION > 0x040000
1827 QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
1828 while (i != commandChildResultMap.constEnd()) {
1829 commandResultMap.insertMulti(i.key(),i.value());
1830#else // tricky thing for Qt3...
1831 QMap<int,QString>::const_iterator i = commandChildResultMap.begin();
1832 while (i != commandChildResultMap.end()) {
1833 doubleKeyAdd = 0;
1834 while (commandResultMap.find( i.key()*multFactor+doubleKeyAdd) != commandResultMap.end()) {
1835 doubleKeyAdd ++;
1836 }
1837 commandResultMap.insert(i.key()*multFactor+doubleKeyAdd,i.data());
1838#endif
1839 i++;
1840 }
1841 commandChildResultMap.clear();
1842 }
1843 }
1844
1845 // build new help tree
1846#if QT_VERSION < 0x040000
1847 fHelpTreeWidget->setSelectionMode(QListView::Single);
1848 fHelpTreeWidget->setRootIsDecorated(true);
1849 fHelpTreeWidget->addColumn("Command");
1850 fHelpTreeWidget->addColumn("Match");
1851 // fHelpTreeWidget->header()->setResizeEnabled(FALSE,1);
1852#else
1853 fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
1854 fHelpTreeWidget->setColumnCount(2);
1855 QStringList labels;
1856 labels << QString("Command") << QString("Match");
1857 fHelpTreeWidget->setHeaderLabels(labels);
1858#endif
1859
1860 if (commandResultMap.empty()) {
1861#if QT_VERSION < 0x040200
1862 fHelpArea->clear();
1863 fHelpArea->append("No match found");
1864#else
1865 fHelpArea->setText("No match found");
1866#endif
1867 return;
1868 }
1869
1870#if QT_VERSION > 0x040000
1871 QMap<int,QString>::const_iterator i = commandResultMap.constEnd();
1872#else
1873 QMap<int,QString>::const_iterator i = commandResultMap.end();
1874#endif
1875 i--;
1876 // 10 maximum progress values
1877 float multValue = 10.0/(float)(i.key());
1878 QString progressChar = "|";
1879 QString progressStr = "|";
1880
1881#if QT_VERSION < 0x040000
1882 QListViewItem * newItem;
1883#else
1884 QTreeWidgetItem * newItem;
1885#endif
1886 bool end = false;
1887 while (!end) {
1888#if QT_VERSION > 0x040000
1889 if (i == commandResultMap.constBegin()) {
1890#else
1891 if (i == commandResultMap.begin()) {
1892#endif
1893 end = true;
1894 }
1895 for(int a=0;a<int(i.key()*multValue);a++) {
1896 progressStr += progressChar;
1897 }
1898#if QT_VERSION < 0x040000
1899 newItem = new QListViewItem(fHelpTreeWidget);
1900 newItem->setText(0,i.data().simplifyWhiteSpace());
1901#else
1902 newItem = new QTreeWidgetItem(fHelpTreeWidget);
1903 newItem->setText(0,i.value().trimmed());
1904#endif
1905 newItem->setText(1,progressStr);
1906
1907#if QT_VERSION >= 0x040200
1908 newItem->setForeground ( 1, QBrush(Qt::blue) );
1909#endif
1910 progressStr = "|";
1911 i--;
1912 }
1913 // FIXME : to be checked on Qt3
1914#if QT_VERSION < 0x040000
1915 fHelpTreeWidget->setColumnWidthMode (1,QListView::Maximum);
1916 fHelpTreeWidget->setSorting(1,false);
1917#else
1918 fHelpTreeWidget->resizeColumnToContents (0);
1919 fHelpTreeWidget->sortItems(1,Qt::DescendingOrder);
1920 // fHelpTreeWidget->setColumnWidth(1,10);//resizeColumnToContents (1);
1921#endif
1922}
1923
1924
1925
1926
1927QMap<int,QString> G4UIQt::LookForHelpStringInChildTree(
1928 G4UIcommandTree *aCommandTree
1929,const QString & text
1930 )
1931{
1932 QMap<int,QString> commandResultMap;
1933 if (aCommandTree == NULL) return commandResultMap;
1934
1935#if QT_VERSION < 0x040000
1936 int multFactor = 1000; // factor special for having double keys in Qt3
1937 int doubleKeyAdd = 0; // decay for doubleKeys in Qt3
1938#endif
1939
1940 // Get the Sub directories
1941 int tmp = 0;
1942 QMap<int,QString> commandChildResultMap;
1943
1944 for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
1945 const G4UIcommand* command = aCommandTree->GetGuidance();
1946#if QT_VERSION > 0x040000
1947 tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
1948#else
1949 tmp = GetCommandList (command).contains(text,false);
1950#endif
1951 if (tmp >0) {
1952#if QT_VERSION > 0x040000
1953 commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()));
1954#else // tricky thing for Qt3...
1955 doubleKeyAdd = 0;
1956 while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) {
1957 doubleKeyAdd ++;
1958 }
1959 commandResultMap.insert(tmp*multFactor+doubleKeyAdd,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()));
1960#endif
1961 }
1962 // look for childs
1963 commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text);
1964
1965 if (!commandChildResultMap.empty()) {
1966 // insert new childs
1967#if QT_VERSION > 0x040000
1968 QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
1969 while (i != commandChildResultMap.constEnd()) {
1970 commandResultMap.insertMulti(i.key(),i.value());
1971#else // tricky thing for Qt3...
1972 QMap<int,QString>::const_iterator i = commandChildResultMap.begin();
1973 while (i != commandChildResultMap.end()) {
1974 doubleKeyAdd = 0;
1975 while (commandResultMap.find( i.key()*multFactor+doubleKeyAdd) != commandResultMap.end()) {
1976 doubleKeyAdd ++;
1977 }
1978 commandResultMap.insert(i.key()*multFactor+doubleKeyAdd,i.data());
1979#endif
1980 i++;
1981 }
1982 commandChildResultMap.clear();
1983 }
1984 }
1985 // Get the Commands
1986
1987 for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
1988 const G4UIcommand* command = aCommandTree->GetCommand(a+1);
1989#if QT_VERSION > 0x040000
1990 tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
1991#else
1992 tmp = GetCommandList (command).contains(text,false);
1993#endif
1994 if (tmp >0) {
1995#if QT_VERSION > 0x040000
1996 commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()));
1997#else // tricky thing for Qt3...
1998 doubleKeyAdd = 0;
1999 while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) {
2000 doubleKeyAdd ++;
2001 }
2002 commandResultMap.insert(tmp*multFactor+doubleKeyAdd,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()));
2003#endif
2004 }
2005
2006 }
2007 return commandResultMap;
2008}
2009
2010
2011QString G4UIQt::GetShortCommandPath(
2012QString commandPath
2013)
2014{
2015#if QT_VERSION < 0x040000
2016 if (commandPath.find("/") == 0) {
2017 commandPath = commandPath.right(commandPath.length()-1);
2018#else
2019 if (commandPath.indexOf("/") == 0) {
2020 commandPath = commandPath.right(commandPath.size()-1);
2021#endif
2022 }
2023
2024#if QT_VERSION < 0x040000
2025 commandPath = commandPath.right(commandPath.length()-commandPath.findRev("/",-2)-1);
2026#else
2027 commandPath = commandPath.right(commandPath.size()-commandPath.lastIndexOf("/",-2)-1);
2028#endif
2029
2030#if QT_VERSION < 0x040000
2031 if (commandPath.findRev("/") == ((int)commandPath.length()-1)) {
2032 commandPath = commandPath.left(commandPath.length()-1);
2033 }
2034#else
2035 if (commandPath.lastIndexOf("/") == (commandPath.size()-1)) {
2036 commandPath = commandPath.left(commandPath.size()-1);
2037 }
2038#endif
2039
2040 return commandPath;
2041}
2042
2043
2044QString G4UIQt::GetLongCommandPath(
2045#if QT_VERSION < 0x040000
2046 QListViewItem* item
2047#else
2048 QTreeWidgetItem* item
2049#endif
2050)
2051{
2052 if (item == NULL) return "";
2053
2054 // rebuild path:
2055 QString itemText = "";
2056 itemText = item->text(0);
2057
2058 while (item->parent() != NULL) {
2059 itemText = item->parent()->text(0)+"/"+itemText;
2060 item = item->parent();
2061 }
2062 itemText = "/"+itemText;
2063
2064 return itemText;
2065}
2066
2067G4QTabWidget::G4QTabWidget(
2068QSplitter*& split
2069):QTabWidget(split)
2070 ,tabSelected(false)
2071 ,lastCreated(-1)
2072{
2073}
2074
2075G4QTabWidget::G4QTabWidget(
2076):QTabWidget()
2077 ,tabSelected(false)
2078 ,lastCreated(-1)
2079{
2080}
2081
2082
2083
2084void G4UIQt::TabCloseCallback(int a){
2085#if QT_VERSION < 0x040000
2086 QWidget* temp = fTabWidget->page(a);
2087 fTabWidget->removePage (temp);
2088#else
2089 QWidget* temp = fTabWidget->widget(a);
2090 fTabWidget->removeTab (a);
2091#endif
2092
2093 delete temp;
2094
2095 if (fTabWidget->count() == 0) {
2096#if QT_VERSION < 0x040000
2097 fEmptyViewerTabLabel->reparent(fMyVSplitter,0,QPoint(0,0));
2098 fTabWidget->reparent(0,0,QPoint(0,0));
2099#else
2100 fMyVSplitter->addWidget(fEmptyViewerTabLabel);
2101 fTabWidget->setParent(0);
2102#endif
2103 }
2104}
2105
2106
2107void G4UIQt::ToolBoxActivated(int a){
2108
2109#if QT_VERSION < 0x040000
2110 if (fToolBox->item(a) == fHelpTBWidget) {
2111#else
2112 if (fToolBox->widget(a) == fHelpTBWidget) {
2113#endif
2114 // Rebuild the help tree
2115 FillHelpTree();
2116 }
2117}
2118
2119void G4QTabWidget::paintEvent(
2120QPaintEvent * event
2121)
2122{
2123
2124#if QT_VERSION < 0x040000
2125 if (currentPage()) {
2126#else
2127 if (currentWidget()) {
2128#endif
2129
2130 if ( isTabSelected()) {
2131
2132#if QT_VERSION < 0x040000
2133 QApplication::sendPostedEvents () ;
2134#else
2135 QCoreApplication::sendPostedEvents () ;
2136#endif
2137
2138#ifdef G4DEBUG_INTERFACES_BASIC
2139 printf("G4QTabWidget::paintEvent OK\n");
2140#endif
2141#if QT_VERSION < 0x040000
2142 QString text = label (currentPageIndex());
2143#else
2144 QString text = tabText (currentIndex());
2145#endif
2146
2147 if (lastCreated == -1) {
2148 QString paramSelect = QString("/vis/viewer/select ")+text;
2149 G4UImanager* UI = G4UImanager::GetUIpointer();
2150 if(UI != NULL) {
2151#if QT_VERSION < 0x040000
2152 UI->ApplyCommand(paramSelect.ascii());
2153#else
2154 UI->ApplyCommand(paramSelect.toStdString().c_str());
2155#endif
2156 }
2157 } else {
2158 lastCreated = -1;
2159 }
2160 setTabSelected(false);
2161 repaint();
2162 }
2163 }
2164}
2165
2166#endif
Note: See TracBrowser for help on using the repository browser.