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

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