Index: trunk/geant4/interfaces/basic/include/G4UIQt.hh
===================================================================
--- trunk/geant4/interfaces/basic/include/G4UIQt.hh	(revision 696)
+++ trunk/geant4/interfaces/basic/include/G4UIQt.hh	(revision 697)
@@ -39,5 +39,5 @@
 
 #include <qobject.h>
-#include <qhash.h>
+#include <qmap.h>
 
 class QMainWindow;
@@ -109,4 +109,10 @@
   void TerminalHelp(G4String);
 #if QT_VERSION < 0x040000
+  QListView * CreateHelpTree();
+#else
+  QTreeWidget * CreateHelpTree();
+#endif
+
+#if QT_VERSION < 0x040000
   void CreateChildTree(QListViewItem*,G4UIcommandTree*);
   QListViewItem* FindTreeItem(QListViewItem *,const QString&);
@@ -122,5 +128,5 @@
   bool eventFilter(QObject*,QEvent*);
   void ActivateCommand(G4String);
-  QHash<QString, int> LookForHelpStringInChildTree(G4UIcommandTree *,const QString&);
+  QMap<int,QString> LookForHelpStringInChildTree(G4UIcommandTree *,const QString&);
 
 
Index: trunk/geant4/interfaces/basic/src/G4UIQt.cc
===================================================================
--- trunk/geant4/interfaces/basic/src/G4UIQt.cc	(revision 696)
+++ trunk/geant4/interfaces/basic/src/G4UIQt.cc	(revision 697)
@@ -120,9 +120,9 @@
 #if QT_VERSION < 0x040000
   fMainWindow->setCaption( tr( "G4UI Session" ));
-  fMainWindow->resize(800,600); 
+  fMainWindow->resize(900,600); 
   fMainWindow->move(50,100);
 #else
   fMainWindow->setWindowTitle( tr("G4UI Session") ); 
-  fMainWindow->resize(800,600); 
+  fMainWindow->resize(900,600); 
   fMainWindow->move(QPoint(50,100));
 #endif
@@ -141,14 +141,5 @@
 
   fTextArea = new QTextEdit(topWidget);
-#ifdef GEANT4_QT_DEBUG
-  printf("G4UIQt:: end\n");
-#endif
-#ifdef GEANT4_QT_DEBUG
-  printf("G4UIQt::PushButton 1\n");
-#endif
   QPushButton *clearButton = new QPushButton("clear",topWidget);
-#ifdef GEANT4_QT_DEBUG
-  printf("G4UIQt::end1\n");
-#endif
   connect(clearButton, SIGNAL(clicked()), SLOT(ClearButtonCallback()));
 
@@ -541,84 +532,40 @@
 #endif
     QVBoxLayout *vLayout = new QVBoxLayout(fHelpDialog);
-    helpLine = new QLineEdit("Look for...",fHelpDialog);
+    QWidget *helpWidget = new QWidget(fHelpDialog);
     QSplitter *splitter = new QSplitter(Qt::Horizontal,fHelpDialog);
     QPushButton *exitButton = new QPushButton("Exit",fHelpDialog);
+    exitButton->setAutoDefault(false);
     connect(exitButton, SIGNAL(clicked()), fHelpDialog,SLOT(close()));
+    
+    QHBoxLayout *helpLayout = new QHBoxLayout(helpWidget);
+#if QT_VERSION < 0x040000
+    helpLayout->add(new QLabel("Search :",helpWidget));
+#else
+    helpLayout->addWidget(new QLabel("Search :",helpWidget));
+#endif
+    helpLine = new QLineEdit(fHelpDialog);
+#if QT_VERSION < 0x040000
+    helpLayout->add(helpLine);
+#else
+    helpLayout->addWidget(helpLine);
+#endif
     connect( helpLine, SIGNAL( editingFinished () ), this, SLOT( lookForHelpStringCallback() ) );
 
-
     // the help tree
-    G4UImanager* UI = G4UImanager::GetUIpointer();
-    if(UI==NULL) return;
-    G4UIcommandTree * treeTop = UI->GetTree();
-
-    // build widget
 #if QT_VERSION < 0x040000
     fHelpTreeWidget = new QListView(splitter);
-    fHelpTreeWidget->setSelectionMode(QListView::Single);
-    fHelpTreeWidget->setRootIsDecorated(true);
-    fHelpTreeWidget->addColumn("Command");
-    fHelpTreeWidget->addColumn("Description",0);
-    //    fHelpTreeWidget->setColumnWidth (1,0);
-    fHelpTreeWidget->header()->setResizeEnabled(FALSE,1);
-    //    QList<QListViewItem *> items;
 #else
     fHelpTreeWidget = new QTreeWidget();
-    fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
-    fHelpTreeWidget->setColumnCount(2);
-    fHelpTreeWidget->setColumnHidden(1,true);
-    QStringList labels;
-    labels << QString("Command") << QString("Description");
-    fHelpTreeWidget->setHeaderLabels(labels);
-    //    QList<QTreeWidgetItem *> items;
-#endif
+#endif
+    fHelpTreeWidget = CreateHelpTree();
 
     fHelpArea = new QTextEdit(splitter);
     fHelpArea->setReadOnly(true);
 
-    G4int treeSize = treeTop->GetTreeEntry();
-#if QT_VERSION < 0x040000
-    QListViewItem * newItem;
-#else
-    QTreeWidgetItem * newItem;
-#endif
-    for (int a=0;a<treeSize;a++) {
-      // Creating new item
-
-#if QT_VERSION < 0x040000
-      newItem = new QListViewItem(fHelpTreeWidget);
-      newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace());
-      newItem->setText(1,QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).simplifyWhiteSpace());
-#else
-                                                                                                   //FIXME : Qt 4.2
-                                                                                                   //      QStringList stringList;
-                                                                                                   //      stringList << QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed()  ;
-                                                                                                   //      stringList << QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).trimmed()  ;
-                                                                                                   //      newItem = new QTreeWidgetItem(stringList);
-                                                                                                   // FIXME : Qt 4.0
-      newItem = new QTreeWidgetItem(fHelpTreeWidget);
-      newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed());
-      newItem->setText(1,QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).trimmed());
-#endif
-
-
-      // look for childs
-      CreateChildTree(newItem,treeTop->GetTree(a+1));
-      //      items.append(newItem);
-    }
-
-
-#if QT_VERSION < 0x040000
-    connect(fHelpTreeWidget, SIGNAL(selectionChanged ()),this, SLOT(HelpTreeClicCallback()));  
-    connect(fHelpTreeWidget, SIGNAL(doubleClicked (QListViewItem*)),this, SLOT(HelpTreeDoubleClicCallback()));
-#else
-    connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback()));  
-    connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback()));  
-#endif
-
     // Set layouts
 
 #if QT_VERSION >= 0x040000
-    splitter->addWidget(fHelpTreeWidget);
+    if (fHelpTreeWidget)
+      splitter->addWidget(fHelpTreeWidget);
     splitter->addWidget(fHelpArea);
 #endif
@@ -626,8 +573,10 @@
 
 #if QT_VERSION >= 0x040000
-    vLayout->addWidget(splitter);
+    vLayout->addWidget(helpWidget);
+    vLayout->addWidget(splitter,1);
     vLayout->addWidget(exitButton);
 #else
-    vLayout->add(splitter);
+    vLayout->addWidget(helpWidget);
+    vLayout->add(splitter,1);
     vLayout->addWidget(exitButton);
 #endif
@@ -667,8 +616,12 @@
 }
 
+
 void G4UIQt::ActivateCommand(
  G4String newCommand
 )
 {
+  if (!fHelpTreeWidget) {
+    return;
+  }
   // Look for the choosen command "newCommand"
   size_t i = newCommand.index(" ");
@@ -769,4 +722,81 @@
   }
 }
+
+
+
+/**
+   Create the help tree widget
+   @param parent : parent of tree widget
+   @return the widget containing the tree or NULL if it could not have beeen created
+ */
+
+#if QT_VERSION < 0x040000
+QListView * G4UIQt::CreateHelpTree()
+#else
+QTreeWidget * G4UIQt::CreateHelpTree()
+#endif
+{
+  G4UImanager* UI = G4UImanager::GetUIpointer();
+  if(UI==NULL) return NULL;
+  G4UIcommandTree * treeTop = UI->GetTree();
+
+
+  // build widget
+#if QT_VERSION < 0x040000
+  fHelpTreeWidget->setSelectionMode(QListView::Single);
+  fHelpTreeWidget->setRootIsDecorated(true);
+  fHelpTreeWidget->addColumn("Command");
+  fHelpTreeWidget->addColumn("Description",0);
+  //    fHelpTreeWidget->setColumnWidth (1,0);
+  fHelpTreeWidget->header()->setResizeEnabled(FALSE,1);
+  //    QList<QListViewItem *> items;
+#else
+  fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
+  fHelpTreeWidget->setColumnCount(2);
+  fHelpTreeWidget->setColumnHidden(1,true);
+  QStringList labels;
+  labels << QString("Command") << QString("Description");
+  fHelpTreeWidget->setHeaderLabels(labels);
+  //    QList<QTreeWidgetItem *> items;
+#endif
+
+  G4int treeSize = treeTop->GetTreeEntry();
+#if QT_VERSION < 0x040000
+  QListViewItem * newItem;
+#else
+  QTreeWidgetItem * newItem;
+#endif
+  for (int a=0;a<treeSize;a++) {
+    // Creating new item
+
+#if QT_VERSION < 0x040000
+    newItem = new QListViewItem(fHelpTreeWidget);
+    newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace());
+    newItem->setText(1,QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).simplifyWhiteSpace());
+#else
+    newItem = new QTreeWidgetItem(fHelpTreeWidget);
+    newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed());
+    newItem->setText(1,QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).trimmed());
+#endif
+
+
+    // look for childs
+    CreateChildTree(newItem,treeTop->GetTree(a+1));
+    //      items.append(newItem);
+  }
+
+
+#if QT_VERSION < 0x040000
+  connect(fHelpTreeWidget, SIGNAL(selectionChanged ()),this, SLOT(HelpTreeClicCallback()));  
+  connect(fHelpTreeWidget, SIGNAL(doubleClicked (QListViewItem*)),this, SLOT(HelpTreeDoubleClicCallback()));
+#else
+  connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback()));  
+  connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback()));  
+#endif
+
+  return fHelpTreeWidget;
+}
+
+
 
 /**   Fill the Help Tree Widget
@@ -1310,21 +1340,40 @@
 }
 
+
 /**   Callback called when user give a new string to look for<br>
-   Display a list of matching commands descriptions.
+   Display a list of matching commands descriptions. If no string is set,
+   will display the complete help tree
 */
 void G4UIQt::lookForHelpStringCallback(
 )
 {
-  QString found = "";
+  if (helpLine->text() =="") {
+    // clear old help tree
+    fHelpTreeWidget->clear();
+    CreateHelpTree();
+#if QT_VERSION < 0x040200
+    fHelpArea->clear();
+#else
+    fHelpArea->setText("");
+#endif
+    return;
+  }
+
   // the help tree
   G4UImanager* UI = G4UImanager::GetUIpointer();
   if(UI==NULL) return;
   G4UIcommandTree * treeTop = UI->GetTree();
-#ifdef GEANT4_QT_DEBUG
-  printf("1111 %s\n",helpLine->text().toStdString().c_str());
-#endif
   
   G4int treeSize = treeTop->GetTreeEntry();
+
+  // clear old help tree
+  fHelpTreeWidget->clear();
+
+  // look for new items
+
   int tmp = 0;
+  QMap<int,QString> commandResultMap;
+  QMap<int,QString> commandChildResultMap;
+
   for (int a=0;a<treeSize;a++) {
 #ifdef GEANT4_QT_DEBUG
@@ -1334,4 +1383,5 @@
     tmp = GetCommandList (command).count(helpLine->text(),Qt::CaseInsensitive);
     if (tmp >0) {
+      commandResultMap.insertMulti(tmp,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()));
 #ifdef GEANT4_QT_DEBUG
       printf("Command %s match %d times \n",(char*)(treeTop->GetTree(a+1)->GetPathName()).data(),tmp);
@@ -1339,22 +1389,109 @@
     }
     // look for childs
-    LookForHelpStringInChildTree(treeTop->GetTree(a+1),helpLine->text());
-    tmp = 0;
-  }
-}
-
-QHash<QString, int> G4UIQt::LookForHelpStringInChildTree(
+    commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a+1),helpLine->text());
+    // insert new childs
+    if (!commandChildResultMap.empty()) {
+      QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
+      while (i != commandChildResultMap.constEnd()) {
+        commandResultMap.insertMulti(i.key(),i.value());
+        i++;
+      }
+      commandChildResultMap.clear();
+    }
+  }
+
+  // build new help tree
+#if QT_VERSION < 0x040000
+  fHelpTreeWidget->setSelectionMode(QListView::Single);
+  fHelpTreeWidget->setRootIsDecorated(true);
+  fHelpTreeWidget->addColumn("Command");
+  fHelpTreeWidget->addColumn("Description",0);
+  fHelpTreeWidget->addColumn("Match");
+  //  fHelpTreeWidget->header()->setResizeEnabled(FALSE,1);
+#else
+  fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
+  fHelpTreeWidget->setColumnCount(3);
+  fHelpTreeWidget->setColumnHidden(1,true);
+  QStringList labels;
+  labels << QString("Command") << QString("Description") << QString("Match");
+  fHelpTreeWidget->setHeaderLabels(labels);
+#endif
+
+  if (commandResultMap.empty()) {
+#if QT_VERSION < 0x040200
+    fHelpArea->clear();
+    fHelpArea->append("No match found");
+#else
+    fHelpArea->setText("No match found");
+#endif
+    return;
+  }
+
+  QMap<int,QString>::const_iterator i = commandResultMap.constEnd();
+  i--;
+  // 10 maximum progress values
+  float multValue = 10.0/(float)(i.key());
+  QString progressChar = "|";
+  QString progressStr = "|";
+
+#if QT_VERSION < 0x040000
+  QListViewItem * newItem;
+#else
+  QTreeWidgetItem * newItem;
+#endif
+  bool end = false;
+  while (!end) {
+    if (i == commandResultMap.constBegin()) {
+      end = true;
+    }
+    for(int a=0;a<int(i.key()*multValue);a++) {
+      progressStr += progressChar;
+    }
+#if QT_VERSION < 0x040000
+    newItem = new QListViewItem(fHelpTreeWidget);
+    newItem->setText(0,i.value().simplifyWhiteSpace());
+    newItem->setText(1,i.value().simplifyWhiteSpace());
+    
+    newItem->setText(2,progressStr);
+#else
+    newItem = new QTreeWidgetItem(fHelpTreeWidget);
+    newItem->setText(0,i.value().trimmed());
+    newItem->setText(1,i.value().trimmed());
+    newItem->setText(2,progressStr);
+#endif
+    
+#if QT_VERSION >= 0x040200
+    newItem->setForeground ( 2, QBrush(Qt::blue) );
+#endif
+    progressStr = "|";
+    i--;
+  }
+  // FIXME :  to be checked on Qt3
+#if QT_VERSION < 0x040000
+  fHelpTreeWidget->setColumnWidthMode (0,QListView::Maximum);
+#else
+  fHelpTreeWidget->resizeColumnToContents (0);
+#endif
+}
+
+
+
+
+QMap<int,QString> G4UIQt::LookForHelpStringInChildTree(
  G4UIcommandTree *aCommandTree
- ,const QString & text
-)
-{
-  QHash<QString, int> found;
-  if (aCommandTree == NULL) return found;
-
+,const QString & text
+ )
+{
+  QMap<int,QString> commandResultMap;
+  if (aCommandTree == NULL) return commandResultMap;
+  
   // Get the Sub directories
   int tmp = 0;
+  QMap<int,QString> commandChildResultMap;
+  
   for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
     const G4UIcommand* command = aCommandTree->GetGuidance();
 #ifdef GEANT4_QT_DEBUG
+    printf("Command loop \n");
     //    printf("Command %s\n",(char*)(aCommandTree->GetTree(a+1)->GetPathName()).data());
     //    printf("%s \n",GetCommandList (command).toStdString().c_str());
@@ -1362,5 +1499,5 @@
     tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
     if (tmp >0) {
-      found.insert(QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()),tmp);
+      commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()));
 #ifdef GEANT4_QT_DEBUG
       printf("---Command %s match %d times \n",(char*)(aCommandTree->GetTree(a+1)->GetPathName()).data(),tmp);
@@ -1368,18 +1505,28 @@
     }
     // look for childs
-    LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text);
-  }
-
+    commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text);
+    
+    if (!commandChildResultMap.empty()) {
+      printf("Check -------------------in child %d\n",commandChildResultMap.count());
+      // insert new childs
+      QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
+      while (i != commandChildResultMap.constEnd()) {
+        commandResultMap.insertMulti(i.key(),i.value());
+        i++;
+      }
+      commandChildResultMap.clear();
+    }
+  }
   // Get the Commands
-
+  
   for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
     const G4UIcommand* command = aCommandTree->GetCommand(a+1);
 #ifdef GEANT4_QT_DEBUG
-    //    printf("Command Finale %s\n");
+    printf("Command Finale debut\n");
     //    printf("%s \n",GetCommandList (command).toStdString().c_str());
 #endif
     tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
     if (tmp >0) {
-      found.insert(QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()),tmp);
+      commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()));
 #ifdef GEANT4_QT_DEBUG
       printf("---Command Finale %s match %d times \n",(char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data(),tmp);
@@ -1388,5 +1535,6 @@
     
   }
-  return found;
-}
-#endif
+  printf("Command Finale retun \n");
+  return commandResultMap;
+}
+#endif
