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

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

test qt3

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