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

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

bug fix 2?

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