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

Last change on this file since 1304 was 1304, checked in by garnier, 14 years ago

bug fix

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