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

Last change on this file since 1013 was 989, checked in by garnier, 15 years ago

fichiers manquants

  • Property svn:mime-type set to text/cpp
File size: 43.9 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26//
27// $Id: G4UIQt.cc,v 1.25 2009/02/16 11:40:26 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 <qsplitter.h>
54#include <qscrollbar.h>
55#include <qdialog.h>
56#include <qevent.h>
57#include <qtextedit.h>
58#include <qsignalmapper.h>
59
60#include <qmainwindow.h>
61#if QT_VERSION >= 0x040000
62#include <qmenu.h>
63#include <qlistwidget.h>
64#include <qtreewidget.h>
65#else
66#include <qaction.h>
67#include <qheader.h>
68#include <qlistview.h>
69#include <qpopupmenu.h>
70#include <qwidgetlist.h>
71#endif
72
73
74
75#include <stdlib.h>
76
77// Pourquoi Static et non  variables de classe ?
78static G4bool exitSession = true;
79static G4bool exitPause = true;
80
81/**   Build a Qt window with a menubar, output area and promt area<br>
82<pre>
83   +-----------------------+
84   |exit menu|             |
85   |                       |
86   | +-------------------+ |
87   | |                   | |
88   | |  Output area      | |
89   | |                   | |
90   | +-------------------+ |
91   |      | clear |        |
92   | +-------------------+ |
93   | |  promt history    | |
94   | +-------------------+ |
95   | +-------------------+ |
96   | |> promt area       | |
97   | +-------------------+ |
98   +-----------------------+
99</pre>
100*/
101G4UIQt::G4UIQt (
102 int argc
103,char** argv
104)
105  :fHelpDialog(NULL)
106{
107  G4Qt* interactorManager = G4Qt::getInstance (argc,argv,(char*)"Qt");
108  if (!(QApplication*)interactorManager->GetMainInteractor()) {
109    G4cout        << "G4UIQt : Unable to init Qt. Aborted" << G4endl;
110  }
111 
112  G4UImanager* UI = G4UImanager::GetUIpointer();
113  if(UI!=NULL) UI->SetSession(this);
114
115  // Check if already define in external app QMainWindow
116  bool found = false;
117#if QT_VERSION < 0x040000
118  // theses lines does nothing exept this one "GLWindow = new QDialog(0..."
119  // but if I comment them, it doesn't work...
120  QWidgetList  *list = QApplication::allWidgets();
121  QWidgetListIt it( *list );         // iterate over the widgets
122  QWidget * widget;
123  while ( (widget=it.current()) != 0 ) {  // for each widget...
124    ++it;
125    if ((found== false) && (widget->inherits("QMainWindow"))) {
126      found = true;
127    }
128  }
129  delete list;                      // delete the list, not the widgets
130#else
131  foreach (QWidget *widget, QApplication::allWidgets()) {
132    if ((found== false) && (widget->inherits("QMainWindow"))) {
133      found = true;
134    }
135  }
136#endif
137
138  if (found) {
139    G4cout        << "G4UIQt : Found an external App with a QMainWindow already defined. Aborted" << G4endl;
140    return ;
141  }
142  fMainWindow = new QMainWindow();
143
144#ifdef G4DEBUG
145  printf("G4UIQt::Initialise after main window creation\n");
146#endif
147#if QT_VERSION < 0x040000
148  fMainWindow->setCaption( tr( "G4UI Session" ));
149  fMainWindow->resize(900,600);
150  fMainWindow->move(50,100);
151#else
152  fMainWindow->setWindowTitle( tr("G4UI Session") );
153  fMainWindow->resize(900,600);
154  fMainWindow->move(QPoint(50,100));
155#endif
156
157  QSplitter *splitter = new QSplitter(Qt::Vertical,fMainWindow);
158
159  // Set layouts
160
161  QWidget* topWidget = new QWidget(splitter);
162  QWidget* bottomWidget = new QWidget(splitter);
163
164  QVBoxLayout *layoutTop = new QVBoxLayout(topWidget);
165  QVBoxLayout *layoutBottom = new QVBoxLayout(bottomWidget);
166
167  // fill them
168
169  fTextArea = new QTextEdit(topWidget);
170  QPushButton *clearButton = new QPushButton("clear",topWidget);
171  connect(clearButton, SIGNAL(clicked()), SLOT(ClearButtonCallback()));
172
173#if QT_VERSION < 0x040000
174
175  fCommandHistoryArea = new QListView(bottomWidget);
176  fCommandHistoryArea->setSorting (-1, FALSE);
177  fCommandHistoryArea->setSelectionMode(QListView::Single);
178  fCommandHistoryArea->addColumn("");
179  fCommandHistoryArea->header()->hide();
180  connect(fCommandHistoryArea, SIGNAL(selectionChanged()), SLOT(CommandHistoryCallback()));
181#else
182  fCommandHistoryArea = new QListWidget();
183  fCommandHistoryArea->setSelectionMode(QAbstractItemView::SingleSelection);
184  connect(fCommandHistoryArea, SIGNAL(itemSelectionChanged()), SLOT(CommandHistoryCallback()));
185#endif
186  fCommandHistoryArea->installEventFilter(this);
187  fCommandLabel = new QLabel("",bottomWidget);
188
189  fCommandArea = new QLineEdit(bottomWidget);
190  fCommandArea->installEventFilter(this);
191#if QT_VERSION < 0x040000
192  fCommandArea->setActiveWindow();
193#else
194  fCommandArea->activateWindow();
195#endif
196  connect(fCommandArea, SIGNAL(returnPressed()), SLOT(CommandEnteredCallback()));
197#if QT_VERSION < 0x040000
198  fCommandArea->setFocusPolicy ( QWidget::StrongFocus );
199  fCommandArea->setFocus();
200#else
201  fCommandArea->setFocusPolicy ( Qt::StrongFocus );
202  fCommandArea->setFocus(Qt::TabFocusReason);
203#endif
204  fTextArea->setReadOnly(true);
205
206  layoutTop->addWidget(fTextArea);
207  layoutTop->addWidget(clearButton);
208
209#if QT_VERSION >= 0x040000
210  topWidget->setLayout(layoutTop);
211#endif
212
213  layoutBottom->addWidget(fCommandHistoryArea);
214  layoutBottom->addWidget(fCommandLabel);
215  layoutBottom->addWidget(fCommandArea);
216#if QT_VERSION >= 0x040000
217
218  bottomWidget->setLayout(layoutBottom);
219  splitter->addWidget(topWidget);
220  splitter->addWidget(bottomWidget);
221#endif
222
223
224  fMainWindow->setCentralWidget(splitter);
225
226#if QT_VERSION < 0x040000
227
228  // Add a quit subMenu
229  QPopupMenu *fileMenu = new QPopupMenu( fMainWindow);
230  fileMenu->insertItem( "&Quit",  this, SLOT(ExitSession()), CTRL+Key_Q );
231  fMainWindow->menuBar()->insertItem( QString("&File"), fileMenu );
232
233  // Add a Help menu
234  QPopupMenu *helpMenu = new QPopupMenu( fMainWindow );
235  helpMenu->insertItem( "&Show Help",  this, SLOT(ShowHelpCallback()), CTRL+Key_H );
236  fMainWindow->menuBar()->insertItem( QString("&Help"), helpMenu );
237
238
239#else
240
241  // Add a quit subMenu
242  QMenu *fileMenu = fMainWindow->menuBar()->addMenu("File");
243  fileMenu->addAction("Quit", this, SLOT(ExitSession()));
244
245  // Add a Help menu
246  QMenu *helpMenu = fMainWindow->menuBar()->addMenu("Help");
247  helpMenu->addAction("Show Help", this, SLOT(ShowHelpCallback()));
248#endif
249
250  AddInteractor ("file",(G4Interactor)fileMenu);
251  AddInteractor ("help",(G4Interactor)helpMenu);
252
253  // Set the splitter size. The fTextArea sould be 2/3 on the fMainWindow
254#if QT_VERSION < 0x040000
255  QValueList<int> vals = splitter->sizes();
256#else
257  QList<int> vals = splitter->sizes();
258#endif
259  if(vals.size()==2) {
260    vals[0] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*3/4;
261    vals[1] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*1/4;
262    splitter->setSizes(vals);
263  }
264
265  if(UI!=NULL) UI->SetCoutDestination(this);  // TO KEEP
266}
267
268
269
270G4UIQt::~G4UIQt(
271)
272{
273  G4UImanager* UI = G4UImanager::GetUIpointer();  // TO KEEP
274  if(UI!=NULL) {  // TO KEEP
275    UI->SetSession(NULL);  // TO KEEP
276    UI->SetCoutDestination(NULL);  // TO KEEP
277  }
278 
279  if (fMainWindow!=NULL)
280    delete fMainWindow;
281}
282
283
284
285/**   Start the Qt main loop
286*/
287G4UIsession* G4UIQt::SessionStart (
288)
289{
290
291  G4Qt* interactorManager = G4Qt::getInstance ();
292
293#if QT_VERSION >= 0x040000
294#if QT_VERSION >= 0x040200
295  fMainWindow->setVisible(true);
296#else
297  fMainWindow->show();
298#endif
299#else
300  fMainWindow->show();
301#endif
302  Prompt("session");
303  exitSession = false;
304
305
306  interactorManager->DisableSecondaryLoop (); // TO KEEP
307  if ((QApplication*)interactorManager->GetMainInteractor())
308    ((QApplication*)interactorManager->GetMainInteractor())->exec();
309
310  // on ne passe pas le dessous ? FIXME ????
311  // je ne pense pas 13/06
312
313  //   void* event; // TO KEEP
314  //   while((event = interactorManager->GetEvent())!=NULL) {  // TO KEEP
315  //     interactorManager->DispatchEvent(event); // TO KEEP
316  //     if(exitSession==true) break; // TO KEEP
317  //   } // TO KEEP
318
319  interactorManager->EnableSecondaryLoop ();
320  return this;
321}
322
323
324/**   Display the prompt in the prompt area
325   @param aPrompt : string to display as the promt label
326   //FIXME : probablement inutile puisque le seul a afficher qq chose d'autre
327   que "session" est SecondaryLoop()
328*/
329void G4UIQt::Prompt (
330 G4String aPrompt
331)
332{
333  if (!aPrompt) return;
334
335  fCommandLabel->setText((char*)aPrompt.data());
336}
337
338
339QMainWindow * G4UIQt::getMainWindow (
340)
341{
342  return fMainWindow;
343}
344
345void G4UIQt::SessionTerminate (
346)
347{
348  G4Qt* interactorManager = G4Qt::getInstance ();
349  fMainWindow->close();
350  ((QApplication*)interactorManager->GetMainInteractor())->exit();
351}
352
353
354
355/**
356   Called by intercoms/src/G4UImanager.cc<br>
357   Called by visualization/management/src/G4VisCommands.cc with "EndOfEvent" argument<br>
358   It have to pause the session command terminal.<br>
359   Call SecondaryLoop to wait for exit event<br>
360   @param aState
361   @see : G4VisCommandReviewKeptEvents::SetNewValue
362*/
363void G4UIQt::PauseSessionStart (
364 G4String aState
365)
366{
367  if (!aState) return;
368
369  if(aState=="G4_pause> ") {  // TO KEEP
370    SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP
371  } // TO KEEP
372
373  if(aState=="EndOfEvent") { // TO KEEP
374    // Picking with feed back in event data Done here !!!
375    SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP
376  } // TO KEEP
377}
378
379
380
381/**
382   Begin the secondary loop
383   @param a_prompt : label to display as the prompt label
384 */
385void G4UIQt::SecondaryLoop (
386 G4String aPrompt
387)
388{
389  if (!aPrompt) return;
390
391  G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ?
392  Prompt(aPrompt); // TO KEEP
393  exitPause = false; // TO KEEP
394  void* event; // TO KEEP
395  while((event = interactorManager->GetEvent())!=NULL) {  // TO KEEP
396    interactorManager->DispatchEvent(event); // TO KEEP
397    if(exitPause==true) break; // TO KEEP
398  } // TO KEEP
399  Prompt("session"); // TO KEEP
400}
401
402
403
404/**
405   Receive a cout from Geant4. We have to display it in the cout zone
406   @param aString : label to add in the display area
407   @return 0
408*/
409G4int G4UIQt::ReceiveG4cout (
410 G4String aString
411)
412{
413  if (!aString) return 0;
414  G4Qt* interactorManager = G4Qt::getInstance ();
415  if (!interactorManager) return 0;
416 
417#if QT_VERSION < 0x040000
418  fTextArea->append(QString((char*)aString.data()).simplifyWhiteSpace());
419  fTextArea->verticalScrollBar()->setValue(fTextArea->verticalScrollBar()->maxValue());
420#else
421  fTextArea->append(QString((char*)aString.data()).trimmed());
422  fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum());
423#endif
424  fTextArea->repaint();
425  //  interactorManager->FlushAndWaitExecution();
426  return 0;
427}
428
429
430/**
431   Receive a cerr from Geant4. We have to display it in the cout zone
432   @param aString : label to add in the display area
433   @return 0
434*/
435G4int G4UIQt::ReceiveG4cerr (
436 G4String aString
437)
438{
439  if (!aString) return 0;
440  G4Qt* interactorManager = G4Qt::getInstance ();
441  if (!interactorManager) return 0;
442
443#if QT_VERSION < 0x040000
444  QColor previousColor = fTextArea->color();
445  fTextArea->setColor(Qt::red);
446  fTextArea->append(QString((char*)aString.data()).simplifyWhiteSpace());
447  fTextArea->setColor(previousColor);
448  fTextArea->verticalScrollBar()->setValue(fTextArea->verticalScrollBar()->maxValue());
449#else
450  QColor previousColor = fTextArea->textColor();
451  fTextArea->setTextColor(Qt::red);
452  fTextArea->append(QString((char*)aString.data()).trimmed());
453  fTextArea->setTextColor(previousColor);
454  fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum());
455#endif
456  fTextArea->repaint();
457  //  interactorManager->FlushAndWaitExecution();
458  return 0;
459}
460
461
462
463/**
464   Add a new menu to the menu bar
465   @param aName name of menu
466   @param aLabel label to display
467 */
468void G4UIQt::AddMenu (
469 const char* aName
470,const char* aLabel
471)
472{
473  if (aName == NULL) return;
474  if (aLabel == NULL) return;
475
476#if QT_VERSION < 0x040000
477  QPopupMenu *fileMenu = new QPopupMenu( fMainWindow);
478  fMainWindow->menuBar()->insertItem( aLabel, fileMenu );
479#else
480  QMenu *fileMenu = new QMenu(aLabel);
481  fMainWindow->menuBar()->insertMenu(fMainWindow->menuBar()->actions().last(),fileMenu);
482#endif
483
484  AddInteractor (aName,(G4Interactor)fileMenu);
485}
486
487
488/**
489   Add a new button to a menu
490   @param aMenu : parent menu
491   @param aLabel : label to display
492   @param aCommand : command to execute as a callback
493 */
494void G4UIQt::AddButton (
495 const char* aMenu
496,const char* aLabel
497,const char* aCommand
498)
499{
500  if(aMenu==NULL) return; // TO KEEP
501  if(aLabel==NULL) return; // TO KEEP
502  if(aCommand==NULL) return; // TO KEEP
503
504#if QT_VERSION < 0x040000
505  QPopupMenu *parent = (QPopupMenu*)GetInteractor(aMenu);
506#else
507  QMenu *parent = (QMenu*)GetInteractor(aMenu);
508#endif
509
510  if(parent==NULL) return;
511 
512  QSignalMapper *signalMapper = new QSignalMapper(this);
513#if QT_VERSION < 0x030200
514  QAction *action = new QAction(QString(aLabel),QString(aLabel),QKeySequence::QKeySequence (),signalMapper, SLOT(map()));
515  action->addTo(parent);
516 connect(action,SIGNAL(activated()),signalMapper,SLOT(map()));
517
518#elif QT_VERSION < 0x040000
519  QAction *action = new QAction(QString(aLabel),QKeySequence::QKeySequence (),signalMapper, SLOT(map()));
520  action->addTo(parent);
521 connect(action,SIGNAL(activated()),signalMapper,SLOT(map()));
522
523#else
524  QAction *action = parent->addAction(aLabel, signalMapper, SLOT(map()));
525
526#endif
527  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&)));
528  signalMapper->setMapping(action, QString(aCommand));
529}
530
531
532
533
534/**
535   Open the help dialog in a separate window.<br>
536   This will be display as a tree widget.<br>
537   Implementation of <b>void G4VBasicShell::TerminalHelp(G4String newCommand)</b>
538
539   @param newCommand : open the tree widget item on this command if is set
540*/
541void G4UIQt::TerminalHelp(
542 G4String newCommand
543)
544{
545  // Create the help dialog
546  if (!fHelpDialog) {
547#if QT_VERSION < 0x040000
548    fHelpDialog = new QDialog(0,0,FALSE,Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WStyle_MinMax );
549#else
550    fHelpDialog = new QDialog(0,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
551#endif
552    QVBoxLayout *vLayout = new QVBoxLayout(fHelpDialog);
553    QWidget *helpWidget = new QWidget(fHelpDialog);
554    QSplitter *splitter = new QSplitter(Qt::Horizontal,fHelpDialog);
555    QPushButton *exitButton = new QPushButton("Exit",fHelpDialog);
556    exitButton->setAutoDefault(false);
557    connect(exitButton, SIGNAL(clicked()), fHelpDialog,SLOT(close()));
558   
559    QHBoxLayout *helpLayout = new QHBoxLayout(helpWidget);
560#if QT_VERSION < 0x040000
561    helpLayout->add(new QLabel("Search :",helpWidget));
562#else
563    helpLayout->addWidget(new QLabel("Search :",helpWidget));
564#endif
565    helpLine = new QLineEdit(fHelpDialog);
566#if QT_VERSION < 0x040000
567    helpLayout->add(helpLine);
568    connect( helpLine, SIGNAL( returnPressed () ), this, SLOT( lookForHelpStringCallback() ) );
569#else
570    helpLayout->addWidget(helpLine);
571    connect( helpLine, SIGNAL( editingFinished () ), this, SLOT( lookForHelpStringCallback() ) );
572#endif
573
574    // the help tree
575#if QT_VERSION < 0x040000
576    fHelpTreeWidget = new QListView(splitter);
577#else
578    fHelpTreeWidget = new QTreeWidget();
579#endif
580    fHelpTreeWidget = CreateHelpTree();
581
582    fHelpArea = new QTextEdit(splitter);
583    fHelpArea->setReadOnly(true);
584
585    // Set layouts
586
587#if QT_VERSION >= 0x040000
588    if (fHelpTreeWidget)
589      splitter->addWidget(fHelpTreeWidget);
590    splitter->addWidget(fHelpArea);
591#endif
592
593
594#if QT_VERSION >= 0x040000
595    vLayout->addWidget(helpWidget);
596    vLayout->addWidget(splitter,1);
597    vLayout->addWidget(exitButton);
598#else
599    vLayout->addWidget(helpWidget);
600    vLayout->addWidget(splitter,1);
601    vLayout->addWidget(exitButton);
602#endif
603
604    // set the splitter size
605#if QT_VERSION >= 0x040000
606    QList<int> list;
607#else
608    QValueList<int> list;
609#endif
610    list.append( 400 );
611    list.append( 400 );
612    splitter->setSizes(list);
613
614#if QT_VERSION >= 0x040000
615    fHelpDialog->setLayout(vLayout);
616#endif
617
618  }
619
620  ActivateCommand(newCommand);
621
622#if QT_VERSION < 0x040000
623  fHelpDialog->setCaption( tr( "Help on commands" ));
624#else
625  fHelpDialog->setWindowTitle(tr("Help on commands"));
626#endif
627  fHelpDialog->resize(800,600);
628  fHelpDialog->move(QPoint(400,150));
629  fHelpDialog->show();
630  fHelpDialog->raise();
631#if QT_VERSION < 0x040000
632  fHelpDialog->setActiveWindow();
633#else
634  fHelpDialog->activateWindow();
635#endif
636}
637
638
639void G4UIQt::ActivateCommand(
640 G4String newCommand
641)
642{
643  if (!fHelpTreeWidget) {
644    return;
645  }
646  // Look for the choosen command "newCommand"
647  size_t i = newCommand.index(" ");
648  G4String targetCom="";
649  if( i != std::string::npos )
650    {
651      G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
652      newValue.strip(G4String::both);
653      targetCom = ModifyToFullPathCommand( newValue );
654    }
655  if (targetCom != "") {
656#if QT_VERSION < 0x040000
657    QListViewItem* findItem = NULL;
658    QListViewItem* tmpItem = fHelpTreeWidget->firstChild();
659    while (tmpItem != 0) {
660      if (!findItem) {
661        findItem = FindTreeItem(tmpItem,QString((char*)targetCom.data()));
662      }
663      tmpItem = tmpItem->nextSibling();
664    }
665#else
666    QTreeWidgetItem* findItem = NULL;
667    for (int a=0;a<fHelpTreeWidget->topLevelItemCount();a++) {
668      if (!findItem) {
669        findItem = FindTreeItem(fHelpTreeWidget->topLevelItem(a),QString((char*)targetCom.data()));
670      }
671    }
672#endif
673   
674    if (findItem) {     
675     
676      //collapsed open item
677#if QT_VERSION < 0x040000
678
679      // FIXME : Has to be checked
680      QListViewItem* tmpItem = fHelpTreeWidget->firstChild();
681      QList<QListViewItem> openItems;
682      while ((tmpItem != 0) || (!openItems.isEmpty())) {
683        if (tmpItem->isOpen() ) {
684          tmpItem->setOpen(false);
685          openItems.append(tmpItem);
686          tmpItem = tmpItem->firstChild();
687        } else {
688          tmpItem = tmpItem->nextSibling();
689        }
690        if (tmpItem == 0) {
691          tmpItem = openItems.take(openItems.count()-1);
692        }
693      }
694#else
695      QList<QTreeWidgetItem *> selected;
696
697      selected = fHelpTreeWidget->selectedItems();
698      if ( selected.count() != 0 ) {
699        QTreeWidgetItem * tmp =selected.at( 0 );
700        while ( tmp) {
701#if QT_VERSION < 0x040202
702              fHelpTreeWidget->setItemExpanded(tmp,false);
703#else
704          tmp->setExpanded(false);
705#endif
706          tmp = tmp->parent();
707        }
708      }
709#endif
710     
711      // clear old selection
712      fHelpTreeWidget->clearSelection();
713
714      // set new selection
715#if QT_VERSION >= 0x040000
716#if QT_VERSION < 0x040202
717      fHelpTreeWidget->setItemSelected(findItem,true);
718#else
719      findItem->setSelected(true);
720#endif     
721#else
722      findItem->setSelected(true);
723#endif
724     
725      // expand parent item
726      while ( findItem) {
727#if QT_VERSION < 0x040000
728        findItem->setOpen(true);
729#else
730#if QT_VERSION < 0x040202
731            fHelpTreeWidget->setItemExpanded(findItem,true);
732#else
733        findItem->setExpanded(true);
734#endif
735#endif
736        findItem = findItem->parent();
737      }
738
739      // Call the update of the right textArea
740      HelpTreeClicCallback();
741    }
742  }
743}
744
745
746
747/**
748   Create the help tree widget
749   @param parent : parent of tree widget
750   @return the widget containing the tree or NULL if it could not have beeen created
751 */
752
753#if QT_VERSION < 0x040000
754QListView * G4UIQt::CreateHelpTree()
755#else
756QTreeWidget * G4UIQt::CreateHelpTree()
757#endif
758{
759  G4UImanager* UI = G4UImanager::GetUIpointer();
760  if(UI==NULL) return NULL;
761  G4UIcommandTree * treeTop = UI->GetTree();
762
763
764  // build widget
765#if QT_VERSION < 0x040000
766  fHelpTreeWidget->setSelectionMode(QListView::Single);
767  fHelpTreeWidget->setRootIsDecorated(true);
768  fHelpTreeWidget->addColumn("Command");
769  fHelpTreeWidget->header()->setResizeEnabled(FALSE,1);
770#else
771  fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
772  QStringList labels;
773  labels << QString("Command");
774  fHelpTreeWidget->setHeaderLabels(labels);
775#endif
776
777  G4int treeSize = treeTop->GetTreeEntry();
778#if QT_VERSION < 0x040000
779  QListViewItem * newItem;
780#else
781  QTreeWidgetItem * newItem;
782#endif
783  for (int a=0;a<treeSize;a++) {
784    // Creating new item
785
786#if QT_VERSION < 0x040000
787    newItem = new QListViewItem(fHelpTreeWidget);
788    newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace());
789#else
790    newItem = new QTreeWidgetItem(fHelpTreeWidget);
791    newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed());
792#endif
793
794
795    // look for childs
796    CreateChildTree(newItem,treeTop->GetTree(a+1));
797    //      items.append(newItem);
798  }
799
800
801#if QT_VERSION < 0x040000
802  connect(fHelpTreeWidget, SIGNAL(selectionChanged ()),this, SLOT(HelpTreeClicCallback())); 
803  connect(fHelpTreeWidget, SIGNAL(doubleClicked (QListViewItem*)),this, SLOT(HelpTreeDoubleClicCallback()));
804#else
805  connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback())); 
806  connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback())); 
807#endif
808
809  return fHelpTreeWidget;
810}
811
812
813
814/**   Fill the Help Tree Widget
815   @param aParent : parent item to fill
816   @param aCommandTree : commandTree node associate with this part of the Tree
817*/
818#if QT_VERSION < 0x040000
819void G4UIQt::CreateChildTree(
820 QListViewItem *aParent
821,G4UIcommandTree *aCommandTree
822#else
823void G4UIQt::CreateChildTree(
824 QTreeWidgetItem *aParent
825,G4UIcommandTree *aCommandTree
826#endif
827)
828{
829  if (aParent == NULL) return;
830  if (aCommandTree == NULL) return;
831
832
833  // Creating new item
834#if QT_VERSION < 0x040000
835  QListViewItem * newItem;
836#else
837  QTreeWidgetItem * newItem;
838#endif
839
840  // Get the Sub directories
841  for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
842
843#if QT_VERSION < 0x040000
844      newItem = new QListViewItem(aParent);
845      newItem->setText(0,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace());
846
847#else
848    newItem = new QTreeWidgetItem(aParent);
849    newItem->setText(0,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed());
850#endif
851
852    CreateChildTree(newItem,aCommandTree->GetTree(a+1));
853  }
854
855
856
857  // Get the Commands
858
859  for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
860   
861    QStringList stringList;
862#if QT_VERSION < 0x040000
863    newItem = new QListViewItem(aParent);
864    newItem->setText(0,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).simplifyWhiteSpace());
865    newItem->setOpen(false);
866
867#else
868    newItem = new QTreeWidgetItem(aParent);
869    newItem->setText(0,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed());
870#if QT_VERSION < 0x040202
871        fHelpTreeWidget->setItemExpanded(newItem,false);
872#else
873    newItem->setExpanded(false);
874#endif
875#endif
876     
877  }
878}
879
880
881
882
883/** Find a treeItemWidget in the help tree
884    @param aCommand item's String to look for
885    @return item if found, NULL if not
886*/
887#if QT_VERSION < 0x040000
888QListViewItem* G4UIQt::FindTreeItem(
889 QListViewItem *aParent
890#else
891QTreeWidgetItem* G4UIQt::FindTreeItem(
892 QTreeWidgetItem *aParent
893#endif
894,const QString& aCommand
895)
896{
897  if (aParent == NULL) return NULL;
898
899  if (aParent->text(0) == aCommand)
900    return aParent;
901 
902#if QT_VERSION < 0x040000
903  QListViewItem * tmp = NULL;
904  QListViewItem* tmpItem = aParent->firstChild();
905    while (tmpItem != 0) {
906      if (!tmp)
907        tmp = FindTreeItem(tmpItem,aCommand);
908      tmpItem = tmpItem->nextSibling();
909    }
910
911#else
912  QTreeWidgetItem * tmp = NULL;
913  for (int a=0;a<aParent->childCount();a++) {
914    if (!tmp)
915      tmp = FindTreeItem(aParent->child(a),aCommand);
916  }
917#endif
918  return tmp;
919}
920
921
922/**   Build the command list parameters in a QString<br>
923   Reimplement partialy the G4UIparameter.cc
924   @param aCommand : command to list parameters
925   @see G4UIparameter::List()
926   @see G4UIcommand::List()
927   @return the command list parameters, or "" if nothing
928*/
929QString G4UIQt::GetCommandList (
930 const G4UIcommand *aCommand
931)
932{
933
934  QString txt ="";
935  if (aCommand == NULL)
936    return txt;
937
938  G4String commandPath = aCommand->GetCommandPath();
939  G4String rangeString = aCommand->GetRange();
940  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
941  G4int n_parameterEntry = aCommand->GetParameterEntries();
942 
943  if ((commandPath == "") &&
944      (rangeString == "") &&
945      (n_guidanceEntry == 0) &&
946      (n_parameterEntry == 0)) {
947    return txt;
948  }
949
950  if((commandPath.length()-1)!='/') {
951    txt += "Command " + QString((char*)(commandPath).data()) + "\n";
952  }
953  txt += "Guidance :\n";
954 
955  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
956    txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
957  }
958  if( ! rangeString.isNull() ) {
959    txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n";
960  }
961  if( n_parameterEntry > 0 ) {
962    G4UIparameter *param;
963   
964    // Re-implementation of G4UIparameter.cc
965   
966    for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
967      param = aCommand->GetParameter(i_thParameter);
968      txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
969      if( ! param->GetParameterGuidance().isNull() )
970        txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
971      txt += " Parameter type  : " + QString(QChar(param->GetParameterType())) + "\n";
972      if(param->IsOmittable()){
973        txt += " Omittable       : True\n";
974      } else {
975        txt += " Omittable       : False\n";
976      }
977      if( param->GetCurrentAsDefault() ) {
978        txt += " Default value   : taken from the current value\n";
979      } else if( ! param->GetDefaultValue().isNull() ) {
980        txt += " Default value   : " + QString((char*)(param->GetDefaultValue()).data())+ "\n";
981      }
982      if( ! param->GetParameterRange().isNull() ) {
983        txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
984      }
985      if( ! param->GetParameterCandidates().isNull() ) {
986        txt += " Candidates      : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
987      }
988    }
989  }
990  return txt;
991}
992
993
994
995/**  Implement G4VBasicShell vurtual function
996 */
997G4bool G4UIQt::GetHelpChoice(
998 G4int& aInt
999)
1000{
1001#ifdef G4DEBUG
1002  printf("G4UIQt::GetHelpChoice SHOULD NEVER GO HERE");
1003#endif
1004  return true;
1005}
1006
1007
1008/**   Implement G4VBasicShell vurtual function
1009*/
1010void G4UIQt::ExitHelp(
1011)
1012{
1013#ifdef G4DEBUG
1014  printf("G4UIQt::ExitHelp SHOULD NEVER GO HERE");
1015#endif
1016}
1017
1018
1019/**   Event filter method. Every event from QtApplication goes here.<br/>
1020   We apply a filter only for the Up and Down Arrow press when the QLineEdit<br/>
1021   is active. If this filter match, Up arrow we give the previous command<br/>
1022   and Down arrow will give the next if exist.<br/>
1023   @param obj Emitter of the event
1024   @param event Kind of event
1025*/
1026bool G4UIQt::eventFilter( // Should stay with a minuscule eventFilter because of Qt
1027 QObject *aObj
1028,QEvent *aEvent
1029)
1030{
1031  if (aObj == NULL) return false;
1032  if (aEvent == NULL) return false;
1033
1034  if (aObj == fCommandHistoryArea) {
1035    if (aEvent->type() == QEvent::KeyPress) {
1036      fCommandArea->setFocus();
1037    }
1038  }
1039  if (aObj == fCommandArea) {
1040    if (aEvent->type() == QEvent::KeyPress) {
1041      QKeyEvent *e = static_cast<QKeyEvent*>(aEvent);
1042      if ((e->key() == (Qt::Key_Down)) ||
1043          (e->key() == (Qt::Key_PageDown)) ||
1044          (e->key() == (Qt::Key_Up)) ||
1045          (e->key() == (Qt::Key_PageUp))) {
1046#if QT_VERSION < 0x040000
1047        // count rows...
1048        QListViewItem* tmpItem = fCommandHistoryArea->firstChild();
1049        int selection = -1;
1050        int index = 0;
1051        while (tmpItem != 0) {
1052          if (tmpItem == fCommandHistoryArea->selectedItem()) {
1053            selection = index;
1054          }
1055          index ++;
1056          tmpItem = tmpItem->nextSibling();
1057        }
1058        if (fCommandHistoryArea->childCount()) {
1059          if (selection == -1) {
1060            selection = fCommandHistoryArea->childCount()-1;
1061          } else {
1062            if (e->key() == (Qt::Key_Down)) {
1063              if (selection <(fCommandHistoryArea->childCount()-1))
1064                selection++;
1065            } else if (e->key() == (Qt::Key_PageDown)) {
1066              selection = fCommandHistoryArea->childCount()-1;
1067#else
1068        int selection = fCommandHistoryArea->currentRow();
1069        if (fCommandHistoryArea->count()) {
1070          if (selection == -1) {
1071            selection = fCommandHistoryArea->count()-1;
1072          } else {
1073            if (e->key() == (Qt::Key_Down)) {
1074              if (selection <(fCommandHistoryArea->count()-1))
1075                selection++;
1076            } else if (e->key() == (Qt::Key_PageDown)) {
1077              selection = fCommandHistoryArea->count()-1;
1078#endif
1079            } else if (e->key() == (Qt::Key_Up)) {
1080              if (selection >0)
1081                selection --;
1082            } else if (e->key() == (Qt::Key_PageUp)) {
1083              selection = 0;
1084            }
1085          }
1086          fCommandHistoryArea->clearSelection();
1087#if QT_VERSION < 0x040000
1088          QListViewItem* tmpItem = fCommandHistoryArea->firstChild();
1089          int index = 0;
1090          while (tmpItem != 0) {
1091            if (index == selection) {
1092              tmpItem->setSelected(true);
1093              fCommandHistoryArea->setCurrentItem(tmpItem);
1094          }
1095          index ++;
1096          tmpItem = tmpItem->nextSibling();
1097        }
1098#else
1099#if QT_VERSION < 0x040202
1100          fCommandHistoryArea->setItemSelected(fCommandHistoryArea->item(selection),true);
1101#else
1102          fCommandHistoryArea->item(selection)->setSelected(true);
1103#endif     
1104          fCommandHistoryArea->setCurrentItem(fCommandHistoryArea->item(selection));
1105#endif
1106        }
1107      } else if (e->key() == (Qt::Key_Tab)) {
1108#if QT_VERSION < 0x040000
1109        G4String ss = Complete(fCommandArea->text().ascii());
1110#else
1111        G4String ss = Complete(fCommandArea->text().toStdString().c_str());
1112#endif
1113        fCommandArea->setText((char*)(ss.data()));
1114
1115        // do not pass by parent, it will disable widget tab focus !
1116        return true;
1117      }
1118    }
1119  }
1120  // pass the event on to the parent class
1121  return QObject::eventFilter(aObj, aEvent);
1122}
1123
1124
1125
1126
1127/***************************************************************************/
1128//
1129//             SLOTS DEFINITIONS
1130//
1131/***************************************************************************/
1132
1133/**   Called when user give "help" command.
1134*/
1135void G4UIQt::ShowHelpCallback (
1136)
1137{
1138  TerminalHelp("");
1139}
1140
1141
1142/**   Called when user click on clear button. Clear the text Output area
1143*/
1144void G4UIQt::ClearButtonCallback (
1145)
1146{
1147  fTextArea->clear();
1148}
1149
1150/**   Called when user exit session
1151*/
1152void G4UIQt::ExitSession (
1153)
1154{
1155  SessionTerminate();
1156}
1157
1158
1159/**   Callback call when "click on a menu entry.<br>
1160   Send the associated command to geant4
1161*/
1162void G4UIQt::CommandEnteredCallback (
1163)
1164{
1165#if QT_VERSION < 0x040000
1166  G4String command (fCommandArea->text().ascii());
1167  if (fCommandArea->text().simplifyWhiteSpace() != "") {
1168
1169    QListViewItem *newItem = new QListViewItem(fCommandHistoryArea);
1170    newItem->setText(0,fCommandArea->text());
1171    fCommandHistoryArea->insertItem(newItem);
1172    // now we have to arrange
1173    QListViewItem *temp= fCommandHistoryArea->lastItem();
1174    for (int i=0; i<fCommandHistoryArea->childCount()-1;i++) {
1175      fCommandHistoryArea->takeItem(temp);
1176      fCommandHistoryArea->insertItem(temp);
1177      temp= fCommandHistoryArea->lastItem();
1178    }
1179#else
1180  G4String command (fCommandArea->text().toStdString().c_str());
1181  if (fCommandArea->text().trimmed() != "") {
1182    fCommandHistoryArea->addItem(fCommandArea->text());
1183#endif
1184    fCommandHistoryArea->clearSelection();
1185    fCommandHistoryArea->setCurrentItem(NULL);
1186    fCommandArea->setText("");
1187
1188    G4Qt* interactorManager = G4Qt::getInstance ();
1189    if (interactorManager) {
1190      interactorManager->FlushAndWaitExecution();
1191    }
1192    if (command(0,4) != "help") {
1193      ApplyShellCommand (command,exitSession,exitPause);
1194    } else {
1195      TerminalHelp(command);
1196    }
1197    if(exitSession==true)
1198      SessionTerminate();
1199  }
1200}
1201
1202
1203/**   Callback call when "enter" clicked on the command zone.<br>
1204   Send the command to geant4
1205   @param aCommand
1206*/
1207void G4UIQt::ButtonCallback (
1208 const QString& aCommand
1209)
1210{
1211#if QT_VERSION < 0x040000
1212  G4String ss = G4String(aCommand.ascii());
1213#else
1214  G4String ss = G4String(aCommand.toStdString().c_str());
1215#endif
1216  ApplyShellCommand(ss,exitSession,exitPause);
1217  if(exitSession==true)
1218    SessionTerminate();
1219}
1220
1221
1222
1223/**   This callback is activated when user selected a item in the help tree
1224*/
1225void G4UIQt::HelpTreeClicCallback (
1226)
1227{
1228#if QT_VERSION < 0x040000
1229  QListViewItem* item =  NULL;
1230#else
1231  QTreeWidgetItem* item =  NULL;
1232#endif
1233  if (!fHelpTreeWidget)
1234    return ;
1235
1236  if (!fHelpArea)
1237    return;
1238 
1239#if QT_VERSION < 0x040000
1240  item =fHelpTreeWidget->selectedItem();
1241#else
1242  QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
1243  if (list.isEmpty())
1244    return;
1245  item = list.first();
1246#endif
1247  if (!item)
1248    return;
1249 
1250  G4UImanager* UI = G4UImanager::GetUIpointer();
1251  if(UI==NULL) return;
1252  G4UIcommandTree * treeTop = UI->GetTree();
1253
1254
1255
1256  std::string itemText;
1257#if QT_VERSION < 0x040000
1258  itemText = std::string(item->text(0).ascii());
1259#else
1260  itemText = std::string(item->text(0).toStdString());
1261#endif
1262
1263  G4UIcommand* command = treeTop->FindPath(itemText.c_str());
1264
1265  if (command) {
1266#if QT_VERSION >= 0x040000
1267#if QT_VERSION < 0x040200
1268    fHelpArea->clear();
1269    fHelpArea->append(GetCommandList(command));
1270#else
1271    fHelpArea->setText(GetCommandList(command));
1272#endif
1273#else
1274    fHelpArea->setText(GetCommandList(command));
1275#endif
1276  } else {  // this is a command
1277    G4UIcommandTree* path = treeTop->FindCommandTree(itemText.c_str());
1278    if ( path) {
1279      // this is not a command, this is a sub directory
1280      // We display the Title
1281#if QT_VERSION >= 0x040000
1282#if QT_VERSION < 0x040200
1283      fHelpArea->clear();
1284      fHelpArea->append(path->GetTitle().data());
1285#else
1286      fHelpArea->setText(path->GetTitle().data());
1287#endif
1288#else
1289      fHelpArea->setText(path->GetTitle().data());
1290#endif
1291    }
1292  }
1293}
1294 
1295/**   This callback is activated when user double clic on a item in the help tree
1296*/
1297void G4UIQt::HelpTreeDoubleClicCallback (
1298)
1299{
1300  HelpTreeClicCallback();
1301
1302#if QT_VERSION < 0x040000
1303  QListViewItem* item =  NULL;
1304#else
1305  QTreeWidgetItem* item =  NULL;
1306#endif
1307  if (!fHelpTreeWidget)
1308    return ;
1309
1310  if (!fHelpArea)
1311    return;
1312 
1313#if QT_VERSION < 0x040000
1314  item =fHelpTreeWidget->selectedItem();
1315#else
1316  QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
1317  if (list.isEmpty())
1318    return;
1319  item = list.first();
1320#endif
1321  if (!item)
1322    return;
1323
1324  fCommandArea->clear();
1325  fCommandArea->setText(item->text(0));
1326}
1327
1328
1329/**   Callback called when user select an old command in the command history<br>
1330   Give it to the command area.
1331*/
1332void G4UIQt::CommandHistoryCallback(
1333)
1334{
1335#if QT_VERSION < 0x040000
1336  QListViewItem* item =  NULL;
1337#else
1338  QListWidgetItem* item =  NULL;
1339#endif
1340  if (!fCommandHistoryArea)
1341    return ;
1342
1343 
1344#if QT_VERSION < 0x040000
1345  item =fCommandHistoryArea->selectedItem();
1346#else
1347  QList<QListWidgetItem *> list =fCommandHistoryArea->selectedItems();
1348  if (list.isEmpty())
1349    return;
1350  item = list.first();
1351#endif
1352  if (!item)
1353    return;
1354#if QT_VERSION < 0x040000
1355  fCommandArea->setText(item->text(0));
1356#else
1357  fCommandArea->setText(item->text());
1358#endif
1359
1360}
1361
1362
1363/**   Callback called when user give a new string to look for<br>
1364   Display a list of matching commands descriptions. If no string is set,
1365   will display the complete help tree
1366*/
1367void G4UIQt::lookForHelpStringCallback(
1368)
1369{
1370#if QT_VERSION < 0x040200
1371  fHelpArea->clear();
1372#else
1373  fHelpArea->setText("");
1374#endif
1375  if (helpLine->text() =="") {
1376    // clear old help tree
1377    fHelpTreeWidget->clear();
1378#if QT_VERSION < 0x040000
1379    fHelpTreeWidget->removeColumn(1);
1380    fHelpTreeWidget->removeColumn(0);
1381#endif
1382    CreateHelpTree();
1383    return;
1384  }
1385
1386  // the help tree
1387  G4UImanager* UI = G4UImanager::GetUIpointer();
1388  if(UI==NULL) return;
1389  G4UIcommandTree * treeTop = UI->GetTree();
1390 
1391  G4int treeSize = treeTop->GetTreeEntry();
1392
1393  // clear old help tree
1394  fHelpTreeWidget->clear();
1395#if QT_VERSION < 0x040000
1396  fHelpTreeWidget->removeColumn(1);
1397  fHelpTreeWidget->removeColumn(0);
1398#endif
1399
1400  // look for new items
1401
1402  int tmp = 0;
1403#if QT_VERSION < 0x040000
1404  int multFactor = 1000; // factor special for having double keys in Qt3
1405  int doubleKeyAdd = 0;  // decay for doubleKeys in Qt3
1406#endif
1407
1408  QMap<int,QString> commandResultMap;
1409  QMap<int,QString> commandChildResultMap;
1410
1411  for (int a=0;a<treeSize;a++) {
1412    G4UIcommand* command = treeTop->FindPath(treeTop->GetTree(a+1)->GetPathName().data());
1413#if QT_VERSION > 0x040000
1414    tmp = GetCommandList (command).count(helpLine->text(),Qt::CaseInsensitive);
1415#else
1416    tmp = GetCommandList (command).contains(helpLine->text(),false);
1417#endif
1418    if (tmp >0) {
1419#if QT_VERSION > 0x040000
1420      commandResultMap.insertMulti(tmp,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()));
1421#else // tricky thing for Qt3...
1422      doubleKeyAdd = 0;
1423      while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) {
1424        doubleKeyAdd ++;
1425      }
1426      commandResultMap.insert( tmp*multFactor+doubleKeyAdd,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()) );
1427#endif
1428    }
1429    // look for childs
1430    commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a+1),helpLine->text());
1431    // insert new childs
1432    if (!commandChildResultMap.empty()) {
1433#if QT_VERSION > 0x040000
1434      QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
1435      while (i != commandChildResultMap.constEnd()) {
1436        commandResultMap.insertMulti(i.key(),i.value());
1437#else // tricky thing for Qt3...
1438      QMap<int,QString>::const_iterator i = commandChildResultMap.begin();
1439      while (i != commandChildResultMap.end()) {
1440        doubleKeyAdd = 0;
1441        while (commandResultMap.find( i.key()*multFactor+doubleKeyAdd) != commandResultMap.end()) {
1442          doubleKeyAdd ++;
1443        }
1444        commandResultMap.insert(i.key()*multFactor+doubleKeyAdd,i.data());
1445#endif
1446        i++;
1447      }
1448      commandChildResultMap.clear();
1449    }
1450  }
1451
1452  // build new help tree
1453#if QT_VERSION < 0x040000
1454  fHelpTreeWidget->setSelectionMode(QListView::Single);
1455  fHelpTreeWidget->setRootIsDecorated(true);
1456  fHelpTreeWidget->addColumn("Command");
1457  fHelpTreeWidget->addColumn("Match");
1458  //  fHelpTreeWidget->header()->setResizeEnabled(FALSE,1);
1459#else
1460  fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
1461  fHelpTreeWidget->setColumnCount(2);
1462  QStringList labels;
1463  labels << QString("Command") << QString("Match");
1464  fHelpTreeWidget->setHeaderLabels(labels);
1465#endif
1466
1467  if (commandResultMap.empty()) {
1468#if QT_VERSION < 0x040200
1469    fHelpArea->clear();
1470    fHelpArea->append("No match found");
1471#else
1472    fHelpArea->setText("No match found");
1473#endif
1474    return;
1475  }
1476
1477#if QT_VERSION > 0x040000
1478  QMap<int,QString>::const_iterator i = commandResultMap.constEnd();
1479#else
1480  QMap<int,QString>::const_iterator i = commandResultMap.end();
1481#endif
1482  i--;
1483  // 10 maximum progress values
1484  float multValue = 10.0/(float)(i.key());
1485  QString progressChar = "|";
1486  QString progressStr = "|";
1487
1488#if QT_VERSION < 0x040000
1489  QListViewItem * newItem;
1490#else
1491  QTreeWidgetItem * newItem;
1492#endif
1493  bool end = false;
1494  while (!end) {
1495#if QT_VERSION > 0x040000
1496    if (i == commandResultMap.constBegin()) {
1497#else
1498    if (i == commandResultMap.begin()) {
1499#endif
1500      end = true;
1501    }
1502    for(int a=0;a<int(i.key()*multValue);a++) {
1503      progressStr += progressChar;
1504    }
1505#if QT_VERSION < 0x040000
1506    newItem = new QListViewItem(fHelpTreeWidget);
1507    newItem->setText(0,i.data().simplifyWhiteSpace());
1508#else
1509    newItem = new QTreeWidgetItem(fHelpTreeWidget);
1510    newItem->setText(0,i.value().trimmed());
1511#endif
1512    newItem->setText(1,progressStr);
1513   
1514#if QT_VERSION >= 0x040200
1515    newItem->setForeground ( 1, QBrush(Qt::blue) );
1516#endif
1517    progressStr = "|";
1518    i--;
1519  }
1520  // FIXME :  to be checked on Qt3
1521#if QT_VERSION < 0x040000
1522  fHelpTreeWidget->setColumnWidthMode (1,QListView::Maximum);
1523  fHelpTreeWidget->setSorting(1,false);
1524#else
1525  fHelpTreeWidget->resizeColumnToContents (0);
1526  fHelpTreeWidget->sortItems(1,Qt::DescendingOrder);
1527  //  fHelpTreeWidget->setColumnWidth(1,10);//resizeColumnToContents (1);
1528#endif
1529}
1530
1531
1532
1533
1534QMap<int,QString> G4UIQt::LookForHelpStringInChildTree(
1535 G4UIcommandTree *aCommandTree
1536,const QString & text
1537 )
1538{
1539  QMap<int,QString> commandResultMap;
1540  if (aCommandTree == NULL) return commandResultMap;
1541 
1542#if QT_VERSION < 0x040000
1543  int multFactor = 1000; // factor special for having double keys in Qt3
1544  int doubleKeyAdd = 0;  // decay for doubleKeys in Qt3
1545#endif
1546
1547  // Get the Sub directories
1548  int tmp = 0;
1549  QMap<int,QString> commandChildResultMap;
1550 
1551  for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
1552    const G4UIcommand* command = aCommandTree->GetGuidance();
1553#if QT_VERSION > 0x040000
1554    tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
1555#else
1556    tmp = GetCommandList (command).contains(text,false);
1557#endif
1558    if (tmp >0) {
1559#if QT_VERSION > 0x040000
1560      commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()));
1561#else // tricky thing for Qt3...
1562      doubleKeyAdd = 0;
1563      while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) {
1564        doubleKeyAdd ++;
1565      }
1566      commandResultMap.insert(tmp*multFactor+doubleKeyAdd,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()));
1567#endif
1568    }
1569    // look for childs
1570    commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text);
1571   
1572    if (!commandChildResultMap.empty()) {
1573      // insert new childs
1574#if QT_VERSION > 0x040000
1575      QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
1576      while (i != commandChildResultMap.constEnd()) {
1577        commandResultMap.insertMulti(i.key(),i.value());
1578#else // tricky thing for Qt3...
1579      QMap<int,QString>::const_iterator i = commandChildResultMap.begin();
1580      while (i != commandChildResultMap.end()) {
1581        doubleKeyAdd = 0;
1582        while (commandResultMap.find( i.key()*multFactor+doubleKeyAdd) != commandResultMap.end()) {
1583          doubleKeyAdd ++;
1584        }
1585        commandResultMap.insert(i.key()*multFactor+doubleKeyAdd,i.data());
1586#endif
1587        i++;
1588      }
1589      commandChildResultMap.clear();
1590    }
1591  }
1592  // Get the Commands
1593 
1594  for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
1595    const G4UIcommand* command = aCommandTree->GetCommand(a+1);
1596#if QT_VERSION > 0x040000
1597    tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
1598#else
1599    tmp = GetCommandList (command).contains(text,false);
1600#endif
1601    if (tmp >0) {
1602#if QT_VERSION > 0x040000
1603      commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()));
1604#else // tricky thing for Qt3...
1605      doubleKeyAdd = 0;
1606      while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) {
1607        doubleKeyAdd ++;
1608      }
1609      commandResultMap.insert(tmp*multFactor+doubleKeyAdd,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()));
1610#endif
1611    }
1612   
1613  }
1614  return commandResultMap;
1615}
1616#endif
Note: See TracBrowser for help on using the repository browser.