G4UIQt.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // L. Garnier
00030 
00031 #ifdef G4UI_BUILD_QT_SESSION
00032 
00033 #include "G4Types.hh"
00034 
00035 #include <string.h>
00036 
00037 #include "G4UIQt.hh"
00038 #include "G4UImanager.hh"
00039 #include "G4StateManager.hh"
00040 #include "G4UIcommandTree.hh"
00041 #include "G4UIcommandStatus.hh"
00042 
00043 #include "G4Qt.hh"
00044 
00045 #include <qapplication.h>
00046 #include <qmessagebox.h>
00047 #include <qlineedit.h>
00048 #include <qwidget.h>
00049 #include <qmenubar.h>
00050 #include <qlayout.h>
00051 #include <qpushbutton.h>
00052 #include <qlabel.h>
00053 #include <qsplitter.h>
00054 #include <qscrollbar.h>
00055 #include <qdialog.h>
00056 #include <qevent.h>
00057 #include <qtextedit.h>
00058 #include <qsignalmapper.h>
00059 #include <qtabwidget.h>
00060 #include <qtabbar.h>
00061 #include <qstringlist.h>
00062 
00063 #include <qmainwindow.h>
00064 #include <qmenu.h>
00065 #include <qlistwidget.h>
00066 #include <qtreewidget.h>
00067 #include <qgroupbox.h>
00068 #include <qscrollarea.h>
00069 #include <qtoolbox.h>
00070 #include <qradiobutton.h>
00071 #include <qbuttongroup.h>
00072 #include <qcombobox.h>
00073 #include <qsignalmapper.h>
00074 #include <qpainter.h>
00075 #include <qcolordialog.h>
00076 #include <qtoolbar.h>
00077 #include <qfiledialog.h>
00078 
00079 
00080 
00081 #include <stdlib.h>
00082 
00083 // Pourquoi Static et non  variables de classe ?
00084 static G4bool exitSession = true;
00085 static G4bool exitPause = true;
00086 
00107 G4UIQt::G4UIQt (
00108  int argc
00109 ,char** argv
00110 )
00111 :fMainWindow(NULL)
00112 ,fCommandLabel(NULL)
00113 ,fCommandArea(NULL)
00114 ,fCoutTBTextArea(NULL)
00115 ,fHelpArea(NULL)
00116 ,fG4cout("")
00117 ,fHelpTreeWidget(NULL)
00118 ,fHelpTBWidget(NULL)
00119 ,fHistoryTBWidget(NULL)
00120 ,fCoutTBWidget(NULL)
00121 ,fSceneTreeComponentsTBWidget(NULL)
00122 ,fHelpLine(NULL)
00123 ,fViewerTabWidget(NULL)
00124 ,fCoutText("Output")
00125 ,fLastQTabSizeX(0)
00126 ,fLastQTabSizeY(0)
00127 ,fToolbarApp(NULL)
00128 ,fToolbarUser(NULL)
00129 ,fMoveSelected(false)
00130 ,fRotateSelected(true)
00131 ,fPickSelected(false)
00132 ,fZoomInSelected(false)
00133 ,fZoomOutSelected(false)
00134 {
00135 
00136   G4Qt* interactorManager = G4Qt::getInstance (argc,argv,(char*)"Qt");
00137   if (!(QApplication*)interactorManager->GetMainInteractor()) {
00138     G4cout        << "G4UIQt : Unable to init Qt. Aborted" << G4endl;
00139   }
00140   
00141   G4UImanager* UI = G4UImanager::GetUIpointer();
00142   if(UI!=NULL) UI->SetSession(this);
00143   if(UI!=NULL) UI->SetG4UIWindow(this);
00144 
00145   // Check if already define in external app QMainWindow
00146   bool found = false;
00147   Q_FOREACH (QWidget *widget, QApplication::allWidgets()) {
00148     if ((found== false) && (widget->inherits("QMainWindow"))) {
00149       found = true;
00150     }
00151   }
00152 
00153   if (found) {
00154     G4cout        << "G4UIQt : Found an external App with a QMainWindow already defined. Aborted" << G4endl;
00155     return ;
00156   }
00157   fMainWindow = new QMainWindow();
00158 
00159  
00160 #ifdef G4DEBUG_INTERFACES_BASIC
00161   printf("G4UIQt::Initialise after main window creation +++++++++++\n");
00162 #endif
00163 
00164 
00165   // the splitter
00166   fMainSplitterWidget = new QSplitter(Qt::Horizontal,fMainWindow);
00167 
00168   QWidget *leftSplitterWidget = new QWidget(fMainSplitterWidget);
00169   QVBoxLayout * layoutLeftSplitterWidget = new QVBoxLayout();
00170   leftSplitterWidget->setLayout(layoutLeftSplitterWidget);
00171   fRightSplitterWidget = new QSplitter(Qt::Vertical,fMainSplitterWidget);
00172 
00173 
00174   fUITabWidget = new QTabWidget();
00175   //  fUITabWidget->setMinimumHeight(100);
00176 
00177   // Set layouts
00178   QWidget* commandLineWidget = new QWidget();
00179   QVBoxLayout *layoutCommandLine = new QVBoxLayout();
00180   commandLineWidget->setLayout(layoutCommandLine);
00181 
00182   // fill them
00183 
00184   fCommandLabel = new QLabel("",commandLineWidget);
00185 
00186   fCommandArea = new QLineEdit(commandLineWidget);
00187   fCommandArea->installEventFilter(this);
00188   fCommandArea->activateWindow();
00189 
00190   fCommandArea->setFocusPolicy ( Qt::StrongFocus );
00191   fCommandArea->setFocus(Qt::TabFocusReason);
00192 
00193   commandLineWidget->setSizePolicy (QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
00194 
00195 
00196   layoutCommandLine->addWidget(fCommandLabel);
00197   layoutCommandLine->addWidget(fCommandArea);
00198 
00199   fHelpTBWidget = new QWidget(fUITabWidget);
00200   fHistoryTBWidget = new QWidget(fUITabWidget);
00201   fSceneTreeComponentsTBWidget = new QTabWidget(fUITabWidget);
00202 
00203 #if QT_VERSION < 0x040200
00204   fSceneTreeComponentsTBWidget->hide();
00205 #else
00206   fSceneTreeComponentsTBWidget->setVisible(false);
00207 #endif
00208 
00209   fEmptyViewerTabLabel = new QLabel("         If you want to have a Viewer, please use /vis/open commands. ");
00210 
00211   layoutLeftSplitterWidget->addWidget(fUITabWidget);
00212 
00213   fCoutTBWidget = new QGroupBox("Output");
00214 
00215   // fill right splitter
00216   fRightSplitterWidget->addWidget(fEmptyViewerTabLabel);
00217   fRightSplitterWidget->addWidget(fCoutTBWidget);
00218   fRightSplitterWidget->addWidget(commandLineWidget);
00219 
00220   // set the splitter size
00221   QList<int> list2;
00222   list2.append(600);
00223   list2.append(150);
00224   //  fRightSplitterWidget->setSizes(list2);
00225 
00226   
00227   CreateVisParametersTBWidget();
00228   CreateHelpTBWidget();
00229   CreateHistoryTBWidget();
00230 
00231   CreateCoutTBWidget();
00232 
00233 
00234   
00235 
00236 
00237   // the right splitter 
00238   fUITabWidget->addTab(fSceneTreeComponentsTBWidget,"Scene tree");
00239   fUITabWidget->addTab(fHelpTBWidget,"Help");
00240   fUITabWidget->addTab(fHistoryTBWidget,"History");
00241   fUITabWidget->setCurrentWidget(fSceneTreeComponentsTBWidget);
00242 
00243   // Only at creation. Will be set visible when sessionStart();
00244  #if QT_VERSION < 0x040200
00245   fEmptyViewerTabLabel->hide();
00246  #else
00247   fEmptyViewerTabLabel->setVisible(false);
00248  #endif
00249 
00250 
00251   fMainSplitterWidget->addWidget(leftSplitterWidget);
00252   fMainSplitterWidget->addWidget(fRightSplitterWidget);
00253   // set the splitter size
00254   QList<int> list;
00255   list.append(200 );
00256   list.append(650);
00257   fMainSplitterWidget->setSizes(list);
00258 
00259 
00260 #ifdef G4DEBUG_INTERFACES_BASIC
00261   printf("G4UIQt::G4UIQt :: 5\n");
00262 #endif
00263 
00264 
00265   fMainWindow->setCentralWidget(fMainSplitterWidget);
00266 
00267 #ifdef G4DEBUG_INTERFACES_BASIC
00268   printf("G4UIQt::G4UIQt :: 6\n");
00269 #endif
00270 
00271   // Connect signal
00272   connect(fCommandArea, SIGNAL(returnPressed()), SLOT(CommandEnteredCallback()));
00273   connect(fUITabWidget, SIGNAL(currentChanged(int)), SLOT(ToolBoxActivated(int)));
00274 
00275   if(UI!=NULL) UI->SetCoutDestination(this);  // TO KEEP
00276 
00277   fMainWindow->setWindowTitle(QFileInfo( QCoreApplication::applicationFilePath() ).fileName()); 
00278   fMainWindow->resize(300,600); 
00279   fMainWindow->move(QPoint(50,50));
00280 
00281   // Set not visible until session start
00282  #if QT_VERSION < 0x040200
00283   fMainWindow->hide();
00284  #else
00285   fMainWindow->setVisible(false);
00286  #endif
00287 
00288 #ifdef G4DEBUG_INTERFACES_BASIC
00289   printf("G4UIQt::G4UIQt END\n");
00290 #endif
00291 }
00292 
00293 
00294 
00295 G4UIQt::~G4UIQt(
00296 ) 
00297 { 
00298 #ifdef G4DEBUG_INTERFACES_BASIC
00299   printf("G4UIQt::~G4UIQt Delete\n");
00300 #endif
00301   G4UImanager* UI = G4UImanager::GetUIpointer();  // TO KEEP
00302   if(UI!=NULL) {  // TO KEEP
00303     UI->SetSession(NULL);  // TO KEEP
00304     UI->SetG4UIWindow(NULL);
00305     UI->SetCoutDestination(NULL);  // TO KEEP
00306   }
00307   
00308   if (fMainWindow!=NULL) {
00309 #ifdef G4DEBUG_INTERFACES_BASIC
00310   printf("G4UIQt::~G4UIQt DELETE fMainWindow\n");
00311 #endif
00312     delete fMainWindow;
00313   }
00314 }
00315 
00318 void G4UIQt::CreateHistoryTBWidget(
00319 ) 
00320 {
00321 
00322   QVBoxLayout *layoutHistoryTB = new QVBoxLayout();
00323   fHistoryTBTableList = new QListWidget();
00324   fHistoryTBTableList->setSelectionMode(QAbstractItemView::SingleSelection);
00325   connect(fHistoryTBTableList, SIGNAL(itemSelectionChanged()), SLOT(CommandHistoryCallback()));
00326   fHistoryTBTableList->installEventFilter(this);
00327 
00328   layoutHistoryTB->addWidget(fHistoryTBTableList);
00329 
00330   fHistoryTBWidget->setLayout(layoutHistoryTB);
00331 }
00332 
00335 void G4UIQt::CreateHelpTBWidget(
00336 ) 
00337 {
00338 
00339   
00340   QWidget *helpWidget = new QWidget();
00341   QHBoxLayout *helpLayout = new QHBoxLayout();
00342   QVBoxLayout *vLayout = new QVBoxLayout();
00343   fHelpVSplitter = new QSplitter(Qt::Horizontal);
00344   fHelpLine = new QLineEdit(fHelpTBWidget);
00345   helpLayout->addWidget(new QLabel("Search :",helpWidget));
00346   helpLayout->addWidget(fHelpLine);
00347   connect( fHelpLine, SIGNAL( editingFinished () ), this, SLOT( LookForHelpStringCallback() ) );
00348   
00349   // Create Help tree
00350   FillHelpTree();
00351   
00352   fHelpArea = new QTextEdit();
00353   fHelpArea->setReadOnly(true);
00354   
00355   // Set layouts
00356   
00357   if (fHelpTreeWidget) {
00358     fHelpVSplitter->addWidget(fHelpTreeWidget);
00359   }
00360   fHelpVSplitter->addWidget(fHelpArea);
00361   
00362   vLayout->addWidget(helpWidget);
00363   vLayout->addWidget(fHelpVSplitter,1);
00364   
00365   fHelpTBWidget->setMinimumSize(50,50);
00366   fHelpTBWidget->setSizePolicy (QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
00367 
00368   // set the splitter size
00369   QList<int> list;
00370   list.append( 50 );
00371   list.append( 50 );
00372   fHelpVSplitter->setSizes(list);
00373   
00374   helpWidget->setLayout(helpLayout);
00375   fHelpTBWidget->setLayout(vLayout);
00376 }
00377 
00378 
00381 void G4UIQt::CreateCoutTBWidget(
00382 ) 
00383 {
00384   QVBoxLayout *layoutCoutTB = new QVBoxLayout();
00385 
00386   fCoutTBTextArea = new QTextEdit(fCoutTBWidget);
00387   fCoutFilter = new QLineEdit(fCoutTBWidget);
00388   QLabel* coutFilterLabel = new QLabel("Filter : ",fCoutTBWidget);
00389 
00390   QPushButton *coutTBClearButton = new QPushButton("clear",fCoutTBWidget);
00391   connect(coutTBClearButton, SIGNAL(clicked()), SLOT(ClearButtonCallback()));
00392   connect(fCoutFilter, SIGNAL(textEdited ( const QString &)), SLOT(CoutFilterCallback( const QString &)));
00393 
00394   fCoutTBTextArea->setReadOnly(true);
00395 
00396   QWidget* coutButtonWidget = new QWidget(fCoutTBWidget);
00397   QHBoxLayout* layoutCoutTBButtons = new QHBoxLayout(coutButtonWidget);
00398   layoutCoutTBButtons->addWidget(coutTBClearButton);
00399   layoutCoutTBButtons->addWidget(coutFilterLabel);
00400   layoutCoutTBButtons->addWidget(fCoutFilter);
00401 
00402   layoutCoutTB->addWidget(fCoutTBTextArea);
00403   layoutCoutTB->addWidget(coutButtonWidget);
00404 
00405   fCoutTBWidget->resize(100,100);
00406   fCoutTBTextArea->setMinimumHeight(10);
00407   fCoutTBWidget->setMinimumHeight(150);
00408   //  fCoutTBTextArea->setSizePolicy (QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
00409   fCoutTBWidget->setSizePolicy (QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
00410   fCoutTBWidget->setLayout(layoutCoutTB);
00411 }
00412 
00413 
00416 void G4UIQt::CreateVisParametersTBWidget(
00417 ) 
00418 {
00419 }
00420 
00421 
00424 QTabWidget* G4UIQt::GetSceneTreeComponentsTBWidget(
00425 )
00426 {
00427   return fSceneTreeComponentsTBWidget;
00428 }
00429 
00430 
00434 bool G4UIQt::AddTabWidget(
00435  QWidget* aWidget
00436 ,QString name
00437 ,int sizeX
00438 ,int sizeY
00439 )
00440 {
00441 #ifdef G4DEBUG_INTERFACES_BASIC
00442   printf("G4UIQt::AddTabWidget %d %d\n",sizeX, sizeY);
00443 #endif
00444 
00445   if (fViewerTabWidget == NULL) {
00446 #ifdef G4DEBUG_INTERFACES_BASIC
00447     printf("G4UIQt::AddTabWidget +++++\n");
00448 #endif
00449 
00450     fViewerTabWidget = new G4QTabWidget(fRightSplitterWidget);
00451 #if QT_VERSION < 0x040500
00452 #else
00453     fViewerTabWidget->setTabsClosable (true); 
00454 #endif
00455     
00456 #if QT_VERSION < 0x040200
00457 #else
00458     fViewerTabWidget->setUsesScrollButtons (true);
00459 #endif
00460     QSizePolicy policy = fViewerTabWidget->sizePolicy();
00461     policy.setHorizontalStretch(1);
00462     policy.setVerticalStretch(1);
00463     fViewerTabWidget->setSizePolicy(policy);
00464     
00465 #if QT_VERSION < 0x040500
00466 #else
00467     connect(fViewerTabWidget,   SIGNAL(tabCloseRequested(int)), this, SLOT(TabCloseCallback(int)));
00468 #endif
00469     connect(fViewerTabWidget, SIGNAL(currentChanged ( int ) ), SLOT(UpdateTabWidget(int))); 
00470   }
00471 
00472   fLastQTabSizeX = sizeX;
00473   fLastQTabSizeY = sizeY;
00474 
00475   if (!aWidget) {
00476     return false;
00477   }
00478 
00479   // Remove QLabel 
00480 
00481   // L.Garnier 26/05/2010 : not exactly the same in qt3. Could cause some
00482   // troubles
00483   if (fEmptyViewerTabLabel != NULL) {
00484     int index = fRightSplitterWidget->indexOf(fEmptyViewerTabLabel);
00485     if ( index != -1) {
00486       fEmptyViewerTabLabel->hide();
00487       fEmptyViewerTabLabel->setParent(NULL);
00488       delete fEmptyViewerTabLabel;
00489       fEmptyViewerTabLabel = NULL;
00490       
00491       fRightSplitterWidget->insertWidget(index,fViewerTabWidget);
00492       
00493       aWidget->setParent(fViewerTabWidget);
00494     }
00495   }
00496 
00497 #ifdef G4DEBUG_INTERFACES_BASIC
00498   printf("G4UIQt::AddTabWidget ADD %d %d + %d %d---------------------------------------------------\n",sizeX, sizeY,sizeX-fViewerTabWidget->width(),sizeY-fViewerTabWidget->height());
00499 #endif
00500 
00501 
00502   // Problems with resize. The widgets are not realy drawn at this step,
00503   // then we have to force them on order to check the size
00504 
00505   fViewerTabWidget->insertTab(fViewerTabWidget->count(),aWidget,name);
00506 
00507   fViewerTabWidget->setCurrentIndex(fViewerTabWidget->count()-1);
00508 
00509   // Set visible
00510  #if QT_VERSION < 0x040200
00511    fViewerTabWidget->setLastTabCreated(fViewerTabWidget->currentIndex());
00512  #else
00513    fViewerTabWidget->setLastTabCreated(fViewerTabWidget->currentIndex());
00514  #endif
00515   
00516    fViewerTabWidget->resize(sizeX,sizeY);
00517 
00518   return true;
00519 }
00520 
00521 
00522 void G4UIQt::UpdateTabWidget(int tabNumber) {
00523 #ifdef G4DEBUG_INTERFACES_BASIC
00524   printf("G4UIQt::UpdateTabWidget %d\n",tabNumber);
00525 #endif
00526   if ( fViewerTabWidget == NULL) {
00527     fViewerTabWidget = new G4QTabWidget;
00528   }
00529   
00530 #ifdef G4DEBUG_INTERFACES_BASIC
00531   printf("G4UIQt::UpdateTabWidget CALL REPAINT tabGL\n");
00532 #endif
00533 
00534   fViewerTabWidget->setCurrentIndex(tabNumber);
00535 
00536   // Send this signal to unblock graphic updates !
00537   fViewerTabWidget->setTabSelected(false);
00538 
00539  #if QT_VERSION < 0x040200
00540   fViewerTabWidget->show();
00541  #else
00542   fViewerTabWidget->setVisible(true);
00543  #endif
00544 
00545   // This will send a paintEvent to OGL Viewers
00546   fViewerTabWidget->setTabSelected(true);
00547 
00548   QCoreApplication::sendPostedEvents () ;
00549 
00550 #ifdef G4DEBUG_INTERFACES_BASIC
00551   printf("G4UIQt::UpdateTabWidget END\n");
00552 #endif
00553 }
00554 
00555 
00558 void G4UIQt::ResizeTabWidget( QResizeEvent* e) {
00559   for (G4int a=0;a<fViewerTabWidget->count() ;a++) {
00560 #ifdef G4DEBUG_INTERFACES_BASIC
00561     printf("G4UIQt::ResizeTabWidget +++++++++++++++++++++++++++++++++++++++\n");
00562 #endif
00563     fViewerTabWidget->widget(a)->resize(e->size());
00564   }
00565 }
00566 
00567 
00570 G4UIsession* G4UIQt::SessionStart (
00571 )
00572 {
00573 #ifdef G4DEBUG_INTERFACES_BASIC
00574   printf("G4UIQt::G4UIQt SessionStart\n");
00575 #endif
00576 
00577   G4Qt* interactorManager = G4Qt::getInstance ();
00578 
00579   Prompt("Session :");
00580   exitSession = false;
00581 /*
00582   if (fEmptyViewerTabLabel != NULL) {
00583     bool visible = false;
00584     if (fViewerTabWidget != NULL) {
00585       if (fViewerTabWidget->isVisible()) {
00586         visible = true;
00587       }
00588     }
00589   }
00590 */
00591   #if QT_VERSION < 0x040200
00592       fMainWindow->show();
00593   #else
00594       fMainWindow->setVisible(true);
00595   #endif
00596   // get the size of the tabbar
00597   int tabBarX = 0;
00598   int tabBarY = 0;
00599 
00600   if (fViewerTabWidget != NULL) {
00601     tabBarX = -fViewerTabWidget->widget(0)->width();
00602     tabBarY = -fViewerTabWidget->widget(0)->height();
00603   }
00604   fMainWindow->resize(tabBarX+fMainWindow->width()+fLastQTabSizeX,tabBarY+fMainWindow->height()+fLastQTabSizeY);
00605 
00606   QCoreApplication::sendPostedEvents () ;
00607 
00608 #ifdef G4DEBUG_INTERFACES_BASIC
00609   printf("G4UIQt::G4UIQt SessionStart2\n");
00610 #endif
00611   interactorManager->DisableSecondaryLoop (); // TO KEEP
00612   if ((QApplication*)interactorManager->GetMainInteractor())
00613     ((QApplication*)interactorManager->GetMainInteractor())->exec();
00614 
00615   // on ne passe pas le dessous ? FIXME ????
00616   // je ne pense pas 13/06
00617 
00618   //   void* event; // TO KEEP
00619   //   while((event = interactorManager->GetEvent())!=NULL) {  // TO KEEP
00620   //     interactorManager->DispatchEvent(event); // TO KEEP
00621   //     if(exitSession==true) break; // TO KEEP
00622   //   } // TO KEEP
00623 
00624   interactorManager->EnableSecondaryLoop ();
00625   return this;
00626 }
00627 
00628 
00634 void G4UIQt::Prompt (
00635  G4String aPrompt
00636 )
00637 {
00638   if (!aPrompt) return;
00639 
00640   fCommandLabel->setText((char*)aPrompt.data());
00641 }
00642 
00643 
00644 
00645 void G4UIQt::SessionTerminate (
00646 )
00647 {
00648   G4Qt* interactorManager = G4Qt::getInstance ();
00649   fMainWindow->close();
00650   ((QApplication*)interactorManager->GetMainInteractor())->exit(); 
00651 }
00652 
00653 
00654 
00663 void G4UIQt::PauseSessionStart (
00664  const G4String& aState
00665 )
00666 {
00667   if (!aState) return;
00668 
00669   if(aState=="G4_pause> ") {  // TO KEEP
00670     SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP
00671   } // TO KEEP
00672 
00673   if(aState=="EndOfEvent") { // TO KEEP
00674     // Picking with feed back in event data Done here !!!
00675     SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP
00676   } // TO KEEP
00677 }
00678 
00679 
00680 
00685 void G4UIQt::SecondaryLoop (
00686  G4String aPrompt
00687 )
00688 {
00689   if (!aPrompt) return;
00690 
00691   G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ?
00692   Prompt(aPrompt); // TO KEEP
00693   exitPause = false; // TO KEEP
00694   void* eventTmp; // TO KEEP
00695   while((eventTmp = interactorManager->GetEvent())!=NULL) {  // TO KEEP
00696     interactorManager->DispatchEvent(eventTmp); // TO KEEP
00697     if(exitPause==true) break; // TO KEEP
00698   } // TO KEEP
00699   Prompt("Session :"); // TO KEEP
00700 }
00701 
00702 
00703 
00709 G4int G4UIQt::ReceiveG4cout (
00710  const G4String& aString
00711  )
00712 {
00713   if (!aString) return 0;
00714   
00715   QStringList newStr;
00716   
00717   // Add to stringList
00718   newStr = QStringList(QString((char*)aString.data()).trimmed());
00719   fG4cout += newStr;
00720  
00721   QStringList result = newStr.filter(fCoutFilter->text());
00722 
00723   if (result.join("\n").isEmpty()) {
00724     return 0;
00725   }
00726   fCoutTBTextArea->append(result.join("\n"));
00727   fCoutTBTextArea->repaint();
00728 
00729   fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
00730 
00731   return 0;
00732 }
00733 
00734 
00740 G4int G4UIQt::ReceiveG4cerr (
00741  const G4String& aString
00742 )
00743 {
00744   if (!aString) return 0;
00745 
00746   QStringList newStr;
00747 
00748   // Add to stringList
00749   newStr = QStringList(QString((char*)aString.data()).trimmed());
00750   fG4cout += newStr;
00751  
00752   QStringList result = newStr.filter(fCoutFilter->text());
00753 
00754   // Suppress space, \n,\t,\r...
00755   if (QString(aString.data()).trimmed() != "") {
00756     QMessageBox::critical(fMainWindow, "Error",aString.data());
00757   }
00758   QColor previousColor = fCoutTBTextArea->textColor();
00759   fCoutTBTextArea->setTextColor(Qt::red);
00760   fCoutTBTextArea->append(result.join("\n"));
00761   fCoutTBTextArea->setTextColor(previousColor);
00762   fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
00763   fCoutTBTextArea->repaint();
00764   return 0;
00765 }
00766 
00767 
00768 
00774 void G4UIQt::AddMenu (
00775  const char* aName
00776 ,const char* aLabel
00777 )
00778 {
00779   if (aName == NULL) return;
00780   if (aLabel == NULL) return;
00781 
00782   QMenu *fileMenu = new QMenu(aLabel);
00783   fMainWindow->menuBar()->addMenu(fileMenu); 
00784 
00785   AddInteractor (aName,(G4Interactor)fileMenu);
00786 }
00787 
00788 
00795 void G4UIQt::AddButton (
00796  const char* aMenu
00797 ,const char* aLabel
00798 ,const char* aCommand
00799 )
00800 {
00801   if(aMenu==NULL) return; // TO KEEP
00802   if(aLabel==NULL) return; // TO KEEP
00803   if(aCommand==NULL) return; // TO KEEP
00804 
00805   QMenu *parentTmp = (QMenu*)GetInteractor(aMenu);
00806 
00807   if(parentTmp==NULL) {
00808     G4cout << "Menu name " << aMenu<< " does not exist, please define it before using it."<< G4endl;
00809   }
00810   
00811   // Find the command in the command tree
00812   G4UImanager* UI = G4UImanager::GetUIpointer();
00813   if(UI==NULL) return;
00814   G4UIcommandTree * treeTop = UI->GetTree();
00815 
00816   G4String cmd = aCommand;
00817   G4int cmdEndPos = cmd.find_first_of(" \t");
00818   if(cmdEndPos!=G4int(std::string::npos)) {
00819     cmd.erase(cmdEndPos);
00820   }
00821   
00822   if(treeTop->FindPath(aCommand) == NULL) {
00823     G4cout << "Warning: command '"<< aCommand <<"' does not exist, please define it before using it."<< G4endl;
00824   }
00825 
00826   QSignalMapper *signalMapper = new QSignalMapper(this);
00827   QAction *action = parentTmp->addAction(aLabel, signalMapper, SLOT(map()));
00828 
00829   connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&)));
00830   signalMapper->setMapping(action, QString(aCommand));
00831 }
00832 
00833 
00834 
00835 
00839 void G4UIQt::AddIcon(const char* aLabel, const char* aIconFile, const char* aCommand, const char* aFileName){
00840   if(aLabel==NULL) return; // TO KEEP
00841   // special case, aCommand could be NULL if aIconFile is not user_icon
00842   if ((aCommand==NULL) && (std::string(aIconFile) == "user_icon")) return; // TO KEEP
00843 
00844   QPixmap pix;
00845   bool userToolBar = false;
00846 
00847   if (std::string(aIconFile) == "user_icon") {
00848     // try to open a file
00849     pix = QPixmap(aFileName);
00850     if (pix.isNull()) {
00851       G4cout << "Warning: file '"<< aFileName <<"' is incorrect or does not exist, this command will not be build"<< G4endl;
00852       return;
00853     }
00854     userToolBar = true; 
00855   } else if (std::string(aIconFile) == "open") {
00856     const char * const xpm[]={
00857       "32 32 33 1",                       
00858           "       c None",                    
00859           "+      c #09091E",                 
00860           "@      c #191B18",                 
00861           "#      c #5F615F",                 
00862           "$      c #777977",                 
00863           "%      c #AEB1AF",                 
00864           "&      c #929491",                 
00865           "*      c #515250",                 
00866           "=      c #858784",                 
00867           "-      c #333533",                 
00868           ";      c #000100",                 
00869           ">      c #272926",                 
00870           ",      c #424341",                 
00871           "'      c #696C6A",                 
00872           ")      c #5F4927",                 
00873           "!      c #583D18",                 
00874           "~      c #6E6A5B",                 
00875           "{      c #47351D",                 
00876           "]      c #E0A554",                 
00877           "^      c #FFD67B",                 
00878           "/      c #EFB465",                 
00879           "(      c #FDBF6C",                 
00880           "_      c #FFCD76",                 
00881           ":      c #806238",                 
00882           "<      c #362611",                 
00883           "[      c #0B0D0A",                 
00884           "}      c #68471B",                 
00885           "|      c #523E22",                 
00886           "1      c #B78A51",                 
00887           "2      c #A17B44",                 
00888           "3      c #D6A45E",                 
00889           "4      c #C29354",                 
00890           "5      c #A1A3A0",                 
00891           "                                ", 
00892           "                                ", 
00893           "                     +@@@#      ", 
00894           "                    $%   +&   * ", 
00895           "                   #=     $  -; ", 
00896           "                           %>;+ ", 
00897           "                           ,;;+ ", 
00898           "  &#$''#'                 >;;;+ ", 
00899           " =)!)!!!!~                *#$'' ", 
00900           " {]^/((_({-  %%%%%%%%%%%        ", 
00901           " {(^_^^^^:<{{{{{{{{{{{{{[&      ", 
00902           " {/_/(((((/]]]]]]]]]]]/]!#      ", 
00903           " {/^(((((_^^^^^^^^^^^^^^:#      ", 
00904           " {/^(((_^^____________^^}$      ", 
00905           " {/^(((((/////////////((!#      ", 
00906           " {/^/^_:<|||||||||||||||@@****1 ", 
00907           " {/^/^(<[)||||||||||||||))!!}<; ", 
00908           " {/^_(:|234444444444444444432)1 ", 
00909           " {/_^/<)34444444444444444443},  ", 
00910           " {/^(2{:41111111111111111142|5  ", 
00911           " {3^3<:31111111111111111143}-   ", 
00912           " {/^2<:31111111111111111441|'   ", 
00913           " {_/<:41111111111111111143},    ", 
00914           " {(4<:31111111111111111144!#    ", 
00915           " )4))44111111111111111144},     ", 
00916           " )2<:31111111111111111144{#     ", 
00917           " @|:14444444444444444444}*      ", 
00918           " ;@434444444444444444434<#      ", 
00919           " ;[))))))))))))))))))))!~       ", 
00920           " ++++++++++++++++++++++;%       ", 
00921           "                                ", 
00922           "                                "}
00923     ;
00924     pix = QPixmap(xpm);
00925 
00926   } else if (std::string(aIconFile) == "save") {
00927     const char * const xpm[]={
00928       "32 32 24 1",                      
00929       "       c None",                    
00930       "+      c #000200",                
00931       "@      c #141E43",                
00932       "#      c #000C56",                
00933       "$      c #494A47",                
00934       "%      c #636662",                
00935       "&      c #312F2A",                
00936       "*      c #191B19",                
00937       "=      c #002992",                
00938       "-      c #003DFF",                
00939       ";      c #041DA5",                
00940       ">      c #A8A9A3",                
00941       ",      c #FDFFFC",                
00942       "'      c #DDE0DD",                
00943       ")      c #818783",                
00944       "!      c #C9CBC8",                
00945       "~      c #0116C3",                
00946       "{      c #C5C8FA",                
00947       "]      c #6596FC",                
00948       "^      c #A0B4F9",                
00949       "/      c #0B2AFD",                
00950       "(      c #799BE3",                
00951       "_      c #5F4826",                
00952       ":      c #D5D8D5",                
00953       "                                ",
00954       "                                ",
00955       "   +++++++++++++++++++++++++    ",
00956       "  +@##+$%%%%%%%%%%%%%%%&*$%&+   ",
00957       "  +=-;@>,,''',,,,,,,',,)&!,)+   ",
00958       "  +;-~@>,,,,,,,,,,,,,,,>$!,)+   ",
00959       "  +=-~@>,,,,,{]]]]]^,,,>*&$&+   ",
00960       "  +=-~@>,,,,,'{^{^^{,,,>*#=#+   ",
00961       "  +=-~@>,,,,,,,,,,,,,,,>@~/=+   ",
00962       "  +=-~@>,,,{{{''''{',,,>@~-=+   ",
00963       "  +=-~@>,,'^]]]]]]({,,,>@~-=+   ",
00964       "  +=-~@>,,,{{{{{{{{{,,,>@~-=+   ",
00965       "  +=-~@>,,,,,'{^{{^{,,,>@~-=+   ",
00966       "  +=-~@>,,,,,]]]]]]],,,>@~-=+   ",
00967       "  +=-~*>,,,,,,,,,,,,,,,>@~-=+   ",
00968       "  +=-~@>,,,,,,,,,,,,,,,>@~-=+   ",
00969       "  +=-/=$%%%%%%%%%%%%%%%$=/-=+   ",
00970       "  +=---;###############;---=+   ",
00971       "  +=---////////////////----=+   ",
00972       "  +=----------------///----=+   ",
00973       "  +=---=@##############@#--=+   ",
00974       "  +=---@+++++++++++*%))_+~-=+   ",
00975       "  +=---#+++++++++++&:,,>@~-=+   ",
00976       "  +=---#+++++++++++$',,>@~-=+   ",
00977       "  +=---#+++++++++++&!,,>@~-=+   ",
00978       "  +=/--#+++++++++++&',,>@~-=+   ",
00979       "   @;--#+++++++++++$',,>@~-=+   ",
00980       "    @;;@+++++++++++*)!>%@=;#+   ",
00981       "     @++++++++++++++*&**++@++   ",
00982       "                                ",
00983       "                                ",
00984       "                                "}
00985     ;
00986     pix = QPixmap(xpm);
00987   } else if (std::string(aIconFile) == "move") {
00988     const char * const xpm[]={
00989         "32 32 16 1",                       
00990           "       c None",                    
00991           ".      c #F1F1F1",                 
00992           "+      c #939393",                 
00993           "@      c #282828",                 
00994           "#      c #787878",                 
00995           "$      c #000000",                 
00996           "%      c #CCCCCC",                 
00997           "&      c #1A1A1A",                 
00998           "*      c #0D0D0D",                 
00999           "=      c #5D5D5D",                 
01000           "-      c #AEAEAE",                 
01001           ";      c #BBBBBB",                 
01002           ">      c #C9C9C9",                 
01003           ",      c #D6D6D6",                 
01004           "'      c #FFFFFF",                 
01005           ")      c #999999",                 
01006           "                                ", 
01007           "                                ", 
01008           "                                ", 
01009           "                                ", 
01010           "               ..               ", 
01011           "               ++               ", 
01012           "              .@@.              ", 
01013           "              #$$#              ", 
01014           "             %&$$*%             ", 
01015           "             =$$$$=             ", 
01016           "            -**$$**-            ", 
01017           "            %;%&*>;%            ", 
01018           "          -%   @&   %-          ", 
01019           "        ,=*;   @&   ;*=,        ", 
01020           "      .#*$$>        >$$*#.      ", 
01021           "    ')&$$$$*@@    @@*$$$$&)'    ", 
01022           "    ')&$$$$*@@    @@*$$$$&+'    ", 
01023           "      .#*$$>        >$$*#.      ", 
01024           "        ,=*;   @&   ;*=,        ", 
01025           "          -%   @&   %-          ", 
01026           "            %;%&*>>%            ", 
01027           "            -**$$**-            ", 
01028           "             =$$$$=             ", 
01029           "             %&$$*%             ", 
01030           "              #$$#              ", 
01031           "              .@@.              ", 
01032           "               ++               ", 
01033           "               ..               ", 
01034           "                                ", 
01035           "                                ", 
01036           "                                ", 
01037           "                                "}
01038       ;
01039   pix = QPixmap(xpm);
01040 
01041   } else if (std::string(aIconFile) == "rotate") {
01042     const char * const xpm[]={
01043         "32 32 27 1",                       
01044           "       c None",                    
01045           ".      c #003333",                 
01046           "+      c #000066",                 
01047           "@      c #1A1A1A",                 
01048           "#      c #003399",                 
01049           "$      c #3333CC",                 
01050           "%      c #000033",                 
01051           "&      c #353535",                 
01052           "*      c #434343",                 
01053           "=      c #336699",                 
01054           "-      c #3399FF",                 
01055           ";      c #003366",                 
01056           ">      c #5D5D5D",                 
01057           ",      c #282828",                 
01058           "'      c #3399CC",                 
01059           ")      c #333333",                 
01060           "!      c #3366CC",                 
01061           "~      c #333399",                 
01062           "{      c #505050",                 
01063           "]      c #666666",                 
01064           "^      c #333366",                 
01065           "/      c #0033CC",                 
01066           "(      c #3366FF",                 
01067           "_      c #336666",                 
01068           ":      c #787878",                 
01069           "<      c #868686",                 
01070           "[      c #6B6B6B",                 
01071           "                   .++@         ", 
01072           "                  #$$%&*        ", 
01073           "                 =--; *>,       ", 
01074           "                 '-=  )>&       ", 
01075           "                !-',  ,>*       ", 
01076           "             !!=--=    >*       ", 
01077           "            =------!!~@&)@      ", 
01078           "             --------!*{{{*&,   ", 
01079           "             -------=){*{{{>>{) ", 
01080           "            ,!-----=  ){&  ,&{{@", 
01081           "          ,*>!----=   &>&     )@", 
01082           "         ){>)~---=    *])      @", 
01083           "        @*>,  --!     ,&@       ", 
01084           "        @{*   '!      ,-!=~^,@  ", 
01085           "        @&    ==      {/(----!^ ", 
01086           "         _           ]:;(----'  ", 
01087           "         ==_         >{+(----~  ", 
01088           "          !-!!======!!(((---!   ", 
01089           "           ='--------------!    ", 
01090           "             =!!!!'!!=; !-!     ", 
01091           "                   &<*  !~      ", 
01092           "              @.  *[*   ;       ", 
01093           "               ;+)>*            ", 
01094           "                 @@             ", 
01095           "                                ", 
01096           "                                ", 
01097           "                                ", 
01098           "                                ", 
01099           "                                ", 
01100           "                                ", 
01101           "                                ", 
01102           "                                "}
01103       ;
01104   pix = QPixmap(xpm);
01105 
01106   } else if (std::string(aIconFile) == "pick") {
01107     const char * const xpm[]={
01108         "32 32 2 1",                        
01109           "       c None",                    
01110           ".      c #000000",                 
01111           "                                ", 
01112           "                                ", 
01113           "                                ", 
01114           "                                ", 
01115           "                                ", 
01116           "                                ", 
01117           "                                ", 
01118           "            .                   ", 
01119           "            ..                  ", 
01120           "            ...                 ", 
01121           "            ....                ", 
01122           "            .....               ", 
01123           "            ......              ", 
01124           "            .......             ", 
01125           "            .......             ", 
01126           "            ........            ", 
01127           "            .....               ", 
01128           "            ......              ", 
01129           "            ..  ..              ", 
01130           "            .   ..              ", 
01131           "                ...             ", 
01132           "                 ..             ", 
01133           "                 ..             ", 
01134           "                                ", 
01135           "                                ", 
01136           "                                ", 
01137           "                                ", 
01138           "                                ", 
01139           "                                ", 
01140           "                                ", 
01141           "                                ", 
01142           "                                "}
01143       ;
01144   pix = QPixmap(xpm);
01145   } else if (std::string(aIconFile) == "zoom_in") {
01146     const char * const xpm[]={
01147         "32 32 11 1",                       
01148           "       c None",                    
01149           ".      c #C9CBC8",                 
01150           "+      c #A8A9A3",                 
01151           "@      c #818783",                 
01152           "#      c #D5D8D5",                 
01153           "$      c #9BCCCC",                 
01154           "%      c #5FC7F4",                 
01155           "&      c #FDFFFC",                 
01156           "*      c #636662",                 
01157           "=      c #9599CE",                 
01158           "-      c #DDE0DD",                 
01159           "                                ", 
01160           "                                ", 
01161           "                                ", 
01162           "                                ", 
01163           "                                ", 
01164           "          .++@@++.              ", 
01165           "         +++..#.+++             ", 
01166           "       .@+...++++#+@.           ", 
01167           "       @$.%%+&&&@%..@           ", 
01168           "      ++.%%%+&&&*%%.++          ", 
01169           "     .+#%%%%+&&&*%%.#+          ", 
01170           "     ++..%%%+&&&*%%%.++         ", 
01171           "     +#.+++++&&&*++++.+         ", 
01172           "     @.+&&&&&&&&&&&&&+@         ", 
01173           "     @#+&&&&&&&&&&&&&+@         ", 
01174           "     @.+&&&&&&&&&&&&&+.         ", 
01175           "     +++@***+&&&****@+.         ", 
01176           "     ....++++&&&*++++..         ", 
01177           "      ++.===+&&&*%=.++          ", 
01178           "       @..==+&&&*=..@#&         ", 
01179           "       .@+#.+&&&@-+@@*@         ", 
01180           "         +++.++++++ *+@*        ", 
01181           "          .+@@@++.  @**+*       ", 
01182           "                    .*@*+*      ", 
01183           "                     .*@*+*     ", 
01184           "                      +*@@*     ", 
01185           "                       .**+     ", 
01186           "                                ", 
01187           "                                ", 
01188           "                                ", 
01189           "                                ", 
01190           "                                "}
01191       ;
01192   pix = QPixmap(xpm);
01193   } else if (std::string(aIconFile) == "zoom_out") {
01194     const char * const xpm[]={
01195         "32 32 11 1",                       
01196           "       c None",                    
01197           ".      c #C9CBC8",                 
01198           "+      c #A8A9A3",                 
01199           "@      c #818783",                 
01200           "#      c #D5D8D5",                 
01201           "$      c #5FC7F4",                 
01202           "%      c #9BCCCC",                 
01203           "&      c #FDFFFC",                 
01204           "*      c #636662",                 
01205           "=      c #9599CE",                 
01206           "-      c #DDE0DD",                 
01207           "                                ", 
01208           "                                ", 
01209           "                                ", 
01210           "                                ", 
01211           "                                ", 
01212           "          .++@@++.              ", 
01213           "         +++..#.+++             ", 
01214           "       .@+..$$$$.#+@.           ", 
01215           "       @%.$$$$$$$$..@           ", 
01216           "      ++.$$$$$$$$$$.++          ", 
01217           "     .+#$$$$$$$$$$$.#+          ", 
01218           "     ++..$$$$$$$$$$$.++         ", 
01219           "     +#.+++++++++++++.+         ", 
01220           "     @.+&&&&&&&&&&&&&+@         ", 
01221           "     @#+&&&&&&&&&&&&&+@         ", 
01222           "     @.+&&&&&&&&&&&&&+.         ", 
01223           "     +++@***********@+.         ", 
01224           "     ....++++++++++++..         ", 
01225           "      ++.===$$$$$$=.++          ", 
01226           "       @..===$$$$=..@#&         ", 
01227           "       .@+#.$$$..-+@@*@         ", 
01228           "         +++#--.+++ *+@*        ", 
01229           "          .+@@@++.  @**+*       ", 
01230           "                    .*@*+*      ", 
01231           "                     .*@*+*     ", 
01232           "                      +*@@*     ", 
01233           "                       .**+     ", 
01234           "                                ", 
01235           "                                ", 
01236           "                                ", 
01237           "                                ", 
01238           "                                "}
01239       ;
01240   pix = QPixmap(xpm);
01241   } else if (std::string(aIconFile) == "wireframe") {
01242     const char * const xpm[]={
01243         "32 32 24 1",                       
01244           "       c None",                    
01245           "+      c #E4E4E4",                 
01246           "@      c #D5D5D5",                 
01247           "#      c #E1E1E1",                 
01248           "$      c #E7E7E7",                 
01249           "%      c #D8D8D8",                 
01250           "&      c #A7A7A7",                 
01251           "*      c #000000",                 
01252           "=      c #989898",                 
01253           "-      c #8A8A8A",                 
01254           ";      c #B5B5B5",                 
01255           ">      c #1B1B1B",                 
01256           ",      c #676767",                 
01257           "'      c #959595",                 
01258           ")      c #4A4A4A",                 
01259           "!      c #878787",                 
01260           "~      c #D3D3D3",                 
01261           "{      c #C4C4C4",                 
01262           "]      c #A4A4A4",                 
01263           "^      c #5B5B5B",                 
01264           "/      c #B3B3B3",                 
01265           "(      c #787878",                 
01266           "_      c #C7C7C7",                 
01267           ":      c #585858",                 
01268           "                                ", 
01269           "                  +@@#          ", 
01270           "          $%@@@@@&****=+        ", 
01271           "        +&********&@-***;       ", 
01272           "   +@@@&**&@@@@@@$  @*-&>&+     ", 
01273           "  +*****&+          %*@ ,**'#   ", 
01274           "  @***)!~           @*{&*****+  ", 
01275           "  @*!]***&+        +-*^**'~!*@  ", 
01276           "  @*~ +@&**&@@@@@@&****&+  ~*@  ", 
01277           "  @*@    +&********&-*=    @*@  ", 
01278           "  @*@      $%@-*-@$ @*@    @*@  ", 
01279           "  @*@         @*@   %*%    @*@  ", 
01280           "  @*@         %*%   %*%    @*@  ", 
01281           "  @*@         %*%   %*%    @*@  ", 
01282           "  @*@         %*%   %*%    @*@  ", 
01283           "  @*@         %*%   %*%    @*@  ", 
01284           "  @*@         %*%   %*%    @*@  ", 
01285           "  @*@         @*@   %*%    @*@  ", 
01286           "  @*@         =*-+  @*@    @*@  ", 
01287           "  @*@    $%@@&****&@-*-+   @*@  ", 
01288           "  @*@ $@&*****&@@&******&~~!*@  ", 
01289           "  @*{/***&@@%$    $@-*-&*****+  ", 
01290           "  @*)*)(-~          @*@ ~)**]   ", 
01291           "  +*******&@@@@+    %*_+]**]    ", 
01292           "   +@@@@@&******&@%+_*^**]#     ", 
01293           "          $%@@@&****:**&+       ", 
01294           "                +%@&**&         ", 
01295           "                    ++          ", 
01296           "                                ", 
01297           "                                ", 
01298           "                                ", 
01299           "                                "}
01300       ;
01301   pix = QPixmap(xpm);
01302   } else if (std::string(aIconFile) == "solid") {
01303     const char * const xpm[]={
01304         "32 32 33 1",                       
01305           "       c None",                    
01306           "+      c #C2DEDE",                 
01307           "@      c #B5D7DF",                 
01308           "#      c #ACD6E6",                 
01309           "$      c #60C0EC",                 
01310           "%      c #4EB7EE",                 
01311           "&      c #53B9ED",                 
01312           "*      c #82CEEA",                 
01313           "=      c #CFDDDA",                 
01314           "-      c #94C9E8",                 
01315           ";      c #0960FF",                 
01316           ">      c #0943FF",                 
01317           ",      c #0949FF",                 
01318           "'      c #3CB3F0",                 
01319           ")      c #71C7EB",                 
01320           "!      c #73CBE5",                 
01321           "~      c #D3DDDB",                 
01322           "{      c #C4DDDE",                 
01323           "]      c #B7D5DF",                 
01324           "^      c #2DACF5",                 
01325           "/      c #59C1ED",                 
01326           "(      c #5FC0ED",                 
01327           "_      c #85CEE9",                 
01328           ":      c #096BFF",                 
01329           "<      c #2AACF6",                 
01330           "[      c #5CBEEC",                 
01331           "}      c #7ACAE4",                 
01332           "|      c #73CAEB",                 
01333           "1      c #71C8E5",                 
01334           "2      c #D1DDDA",                 
01335           "3      c #CBDDD9",                 
01336           "4      c #67C1EB",                 
01337           "5      c #80CDEA",                 
01338           "                                ", 
01339           "                                ", 
01340           "          +@@@@@@#$%&*=         ", 
01341           "        +-;>>>>>>>>>,')!~       ", 
01342           "   {]@@-;>>>>>>>>>>>>^/(_=      ", 
01343           "  {:>>>>>>>>>>>>>>>>><//[)!=    ", 
01344           "  ]>>>>>>>>>>>>>>>>>><////[)}   ", 
01345           "  @>>>>>>>>>>>>>>>>>><//////|   ", 
01346           "  @>>>>>>>>>>>>>>>>>><//////|   ", 
01347           "  @>>>>>>>>>>>>>>>>>><//////|   ", 
01348           "  @>>>>>>>>>>>>>>>>>><//////|   ", 
01349           "  @>>>>>>>>>>>>>>>>>><//////|   ", 
01350           "  @>>>>>>>>>>>>>>>>>><//////|   ", 
01351           "  @>>>>>>>>>>>>>>>>>><//////|   ", 
01352           "  @>>>>>>>>>>>>>>>>>><//////|   ", 
01353           "  @>>>>>>>>>>>>>>>>>><//////|   ", 
01354           "  @>>>>>>>>>>>>>>>>>><//////|   ", 
01355           "  @>>>>>>>>>>>>>>>>>><//////|   ", 
01356           "  @>>>>>>>>>>>>>>>>>><//////|   ", 
01357           "  @>>>>>>>>>>>>>>>>>><//////|   ", 
01358           "  @>>>>>>>>>>>>>>>>>><//////|   ", 
01359           "  @>>>>>>>>>>>>>>>>>></////[1   ", 
01360           "  @>>>>>>>>>>>>>>>>>><////[*2   ", 
01361           "  {:>>>>>>>>>>>>>>>>><//[)12    ", 
01362           "   +@@@@@-;>>>>>>>>>><[)13      ", 
01363           "          {]@@@-;>>>,'*3        ", 
01364           "                +@@#452         ", 
01365           "                                ", 
01366           "                                ", 
01367           "                                ", 
01368           "                                ", 
01369           "                                "}
01370     ;
01371     pix = QPixmap(xpm);
01372   } else if (std::string(aIconFile) == "hidden_line_removal") {
01373     const char * const xpm[]={
01374         "32 32 15 1",                       
01375           "       c None",                    
01376           "+      c #D5D5D5",                 
01377           "@      c #C7C7C7",                 
01378           "#      c #9C9C9C",                 
01379           "$      c #000000",                 
01380           "%      c #8E8E8E",                 
01381           "&      c #808080",                 
01382           "*      c #A9A9A9",                 
01383           "=      c #D8D8D8",                 
01384           "-      c #CACACA",                 
01385           ";      c #181818",                 
01386           ">      c #9F9F9F",                 
01387           ",      c #ACACAC",                 
01388           "'      c #B9B9B9",                 
01389           ")      c #555555",                 
01390           "                                ", 
01391           "                  +@@+          ", 
01392           "          +@@@@@@#$$$$%+        ", 
01393           "        +#$$$$$$$$#@&$$$*       ", 
01394           "   =-@@#$$#@@@@@-=  @$&#;>=     ", 
01395           "  =$$$$$#+          -$@ *$$%+   ", 
01396           "  -$&@-=            -$-  #$$$=  ", 
01397           "  -$@               -$-   +&$-  ", 
01398           "  @$@               @$@    @$@  ", 
01399           "  @$@               @$@    @$@  ", 
01400           "  @$@               @$@    @$@  ", 
01401           "  @$@               @$@    @$@  ", 
01402           "  @$@               @$@    @$@  ", 
01403           "  @$@               @$@    @$@  ", 
01404           "  @$@               @$@    @$@  ", 
01405           "  @$@               @$@    @$@  ", 
01406           "  @$@               @$@    @$@  ", 
01407           "  @$@               @$@    @$@  ", 
01408           "  @$@               @$@    @$@  ", 
01409           "  @$@               @$@    @$@  ", 
01410           "  @$@               @$@    @$@  ", 
01411           "  @$@               @$@    #$=  ", 
01412           "  -$&@@@-=          -$-  =>;,   ", 
01413           "  =$$$$$$$#@@@-=    -$'+#$$,    ", 
01414           "   =-@@@@#$$$$$$#@-+'$)$$#+     ", 
01415           "          =-@@@#$$$$)$$#+       ", 
01416           "                +@@#$$#         ", 
01417           "                    ++          ", 
01418           "                                ", 
01419           "                                ", 
01420           "                                ", 
01421           "                                "}
01422       ;
01423     pix = QPixmap(xpm);
01424   } else if (std::string(aIconFile) == "hidden_line_and_surface_removal") {
01425     const char * const xpm[]={
01426         "32 32 40 1",                       
01427           "       c None",                    
01428           "+      c #FFFFFF",                 
01429           "@      c #89A2E9",                 
01430           "#      c #5378E3",                 
01431           "$      c #A2B5ED",                 
01432           "%      c #5379E3",                 
01433           "&      c #5076E3",                 
01434           "*      c #3E69E4",                 
01435           "=      c #0C43F8",                 
01436           "-      c #043FFE",                 
01437           ";      c #CDD9ED",                 
01438           ">      c #BDCDE9",                 
01439           ",      c #FBFCFC",                 
01440           "'      c #406AE4",                 
01441           ")      c #0439FE",                 
01442           "!      c #0137FF",                 
01443           "~      c #4F75E3",                 
01444           "{      c #9EB5E3",                 
01445           "]      c #829FE0",                 
01446           "^      c #B6C6E7",                 
01447           "/      c #9DB4E3",                 
01448           "(      c #7E9CE0",                 
01449           "_      c #B2C3E9",                 
01450           ":      c #7E9AE0",                 
01451           "<      c #86A2E1",                 
01452           "[      c #CAD6ED",                 
01453           "}      c #5177E3",                 
01454           "|      c #829CE0",                 
01455           "1      c #BCCCE9",                 
01456           "2      c #3A67E6",                 
01457           "3      c #0A43FA",                 
01458           "4      c #95ACE1",                 
01459           "5      c #BBCBE9",                 
01460           "6      c #A9BBE5",                 
01461           "7      c #96AFE1",                 
01462           "8      c #BDCBE9",                 
01463           "9      c #4067E4",                 
01464           "0      c #6485E5",                 
01465           "a      c #E3EAF3",                 
01466           "b      c #CAD6F3",                 
01467           "                                ", 
01468           "                                ", 
01469           "                  ++++          ", 
01470           "          ++++++++@#$+++        ", 
01471           "        ++@%####&*=-#+;>,       ", 
01472           "   +++++@'=)))))))!)~+{]^++     ", 
01473           "   +$%&*=)!!!!!!!!!)~+/(]_+++   ", 
01474           "   +#-))!!!!!!!!!!!)~+/(::<[+   ", 
01475           "   +#)!!!!!!!!!!!!!!}+/::::{+   ", 
01476           "   +#)!!!!!!!!!!!!!!}+/::::{+   ", 
01477           "   +#)!!!!!!!!!!!!!!}+/::::{+   ", 
01478           "   +#)!!!!!!!!!!!!!!}+/::::{+   ", 
01479           "   +#)!!!!!!!!!!!!!!}+/::::{+   ", 
01480           "   +#)!!!!!!!!!!!!!!}+/::::{+   ", 
01481           "   +#)!!!!!!!!!!!!!!}+/::::{+   ", 
01482           "   +#)!!!!!!!!!!!!!!}+/::::{+   ", 
01483           "   +#)!!!!!!!!!!!!!!}+/::::{+   ", 
01484           "   +#)!!!!!!!!!!!!!!}+/::::{+   ", 
01485           "   +#)!!!!!!!!!!!!!!}+/::::{+   ", 
01486           "   +#)!!!!!!!!!!!!!!}+/::::{+   ", 
01487           "   +#)!!!!!!!!!!!!!!}+/::::{+   ", 
01488           "   +#)!!!!!!!!!!!!!!}+/:::|1+   ", 
01489           "   +$#}}~23!!!!!!!!)~+/(]45,    ", 
01490           "   +++++++@#}}~23!!)~+678++     ", 
01491           "          ++++++@#~90+a++       ", 
01492           "                ++++b++         ", 
01493           "                    ++          ", 
01494           "                                ", 
01495           "                                ", 
01496           "                                ", 
01497           "                                ", 
01498           "                                "}
01499       ;
01500     pix = QPixmap(xpm);
01501   } else if (std::string(aIconFile) == "perspective") {
01502     const char * const xpm[]={
01503         "32 32 3 1",                        
01504           "       c None",                    
01505           ".      c #D5D8D5",                 
01506           "+      c #000000",                 
01507           "                                ", 
01508           "                                ", 
01509           "                                ", 
01510           "                                ", 
01511           "                                ", 
01512           "           ................     ", 
01513           "       ....+++++++++++++++.     ", 
01514           "    ...++++..+.........+++.     ", 
01515           "   ..++..............++..+.     ", 
01516           "   .+++++++++++++++++.. .+.     ", 
01517           "   .+...............+.  .+.     ", 
01518           "   .+.      .+.    .+.  .+.     ", 
01519           "   .+.      .+.    .+.  .+.     ", 
01520           "   .+.      .+.    .+.  .+.     ", 
01521           "   .+.      .+.    .+.  .+.     ", 
01522           "   .+.      .+.    .+.  .+.     ", 
01523           "   .+.      .+.    .+.  .+.     ", 
01524           "   .+.      .+.    .+.  .+.     ", 
01525           "   .+.      .+.    .+.  .+.     ", 
01526           "   .+.      .+......+....+.     ", 
01527           "   .+.     ..++++++.+.++++.     ", 
01528           "   .+.    .++.......+...+..     ", 
01529           "   .+.   .++.      .+..++.      ", 
01530           "   .+. ..+..       .+..+.       ", 
01531           "   .+..++.         .+.+.        ", 
01532           "   .+.++.          .+++.        ", 
01533           "   .+++.............++.         ", 
01534           "   .+++++++++++++++++.          ", 
01535           "   ...................          ", 
01536           "                                ", 
01537           "                                ", 
01538           "                                "}
01539       ;
01540     pix = QPixmap(xpm);
01541   } else if (std::string(aIconFile) == "ortho") {
01542     const char * const xpm[]={
01543         "32 32 3 1",                        
01544           "       c None",                    
01545           ".      c #D5D8D5",                 
01546           "@      c #000000",                 
01547           "                                ", 
01548           "                                ", 
01549           "                                ", 
01550           "          ...................   ", 
01551           "         ..@@@@@@@@@@@@@@@@@.   ", 
01552           "       ..@@@.............@@@.   ", 
01553           "      ..@@.@.         ..@..@.   ", 
01554           "    ..@@ ..@.        .@@...@.   ", 
01555           "   ..@@..............@@.. .@.   ", 
01556           "   .@@@@@@@@@@@@@@@@@..   .@.   ", 
01557           "   .@...............@.    .@.   ", 
01558           "   .@.    .@.      .@.    .@.   ", 
01559           "   .@.    .@.      .@.    .@.   ", 
01560           "   .@.    .@.      .@.    .@.   ", 
01561           "   .@.    .@.      .@.    .@.   ", 
01562           "   .@.    .@.      .@.    .@.   ", 
01563           "   .@.    .@.      .@.    .@.   ", 
01564           "   .@.    .@.      .@.    .@.   ", 
01565           "   .@.    .@.      .@.    .@.   ", 
01566           "   .@.    .@.      .@.    .@.   ", 
01567           "   .@.    .@.      .@.    .@.   ", 
01568           "   .@.    .@........@......@.   ", 
01569           "   .@.   .@@@@@@@@@.@.@@@@@@.   ", 
01570           "   .@.  .@@+........@....@@..   ", 
01571           "   .@...@.         .@...@...    ", 
01572           "   .@.@@.          .@.@@ .      ", 
01573           "   .@@@.............@@@..       ", 
01574           "   .@@@@@@@@@@@@@@@@@...        ", 
01575           "   ...................          ", 
01576           "                                ", 
01577           "                                ", 
01578           "                                "}
01579       ;
01580     pix = QPixmap(xpm);
01581   } else {
01582     G4cout << "Parameter"<< aIconFile <<" not defined"<< G4endl;
01583     return;
01584   }
01585   QToolBar *currentToolbar = NULL;
01586   if (userToolBar) {
01587     if (fToolbarUser == NULL) {
01588       fToolbarUser = new QToolBar(fMainWindow);
01589       fToolbarUser->setIconSize (QSize(20,20));
01590       fMainWindow->addToolBar(Qt::TopToolBarArea, fToolbarUser);
01591     }
01592     currentToolbar = fToolbarUser;
01593   } else {
01594     if (fToolbarApp == NULL) {
01595       fToolbarApp = new QToolBar(fMainWindow);
01596       fToolbarApp->setIconSize (QSize(20,20));
01597       fMainWindow->addToolBar(Qt::TopToolBarArea, fToolbarApp);
01598     }
01599     currentToolbar = fToolbarApp;
01600   }
01601 
01602   QSignalMapper *signalMapper = new QSignalMapper(this);
01603   QAction *action = currentToolbar->addAction(pix,aLabel, signalMapper, SLOT(map()));
01604   
01605 
01606   // special cases :"open"
01607   if (std::string(aIconFile) == "open") {
01608     connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(OpenIconCallback(const QString&)));
01609     signalMapper->setMapping(action, QString(aCommand));
01610 
01611   // special cases :"save"
01612   } else if (std::string(aIconFile) == "save") {
01613     connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(SaveIconCallback(const QString&)));
01614     signalMapper->setMapping(action, QString(aCommand));
01615 
01616   // special cases : cursor style
01617   } else if ((std::string(aIconFile) == "move") ||
01618              (std::string(aIconFile) == "rotate") ||
01619              (std::string(aIconFile) == "pick") ||
01620              (std::string(aIconFile) == "zoom_out") ||
01621              (std::string(aIconFile) == "zoom_in")) {
01622     action->setCheckable(TRUE);
01623     action->setChecked(TRUE);
01624     action->setData(aIconFile);
01625 
01626     connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ChangeCursorStyle(const QString&)));
01627     signalMapper->setMapping(action, QString(aIconFile));
01628 
01629     if (std::string(aIconFile) == "move") {
01630       SetIconMoveSelected();
01631     }
01632     if (std::string(aIconFile) == "rotate") {
01633       SetIconRotateSelected();
01634     }
01635     if (std::string(aIconFile) == "pick") {
01636       SetIconPickSelected();
01637     }
01638     if (std::string(aIconFile) == "zoom_in") {
01639       SetIconZoomInSelected();
01640     }
01641     if (std::string(aIconFile) == "zoom_out") {
01642       SetIconZoomOutSelected();
01643     }
01644 
01645     // special case : surface style
01646   } else if ((std::string(aIconFile) == "hidden_line_removal") ||
01647              (std::string(aIconFile) == "hidden_line_and_surface_removal") ||
01648              (std::string(aIconFile) == "solid") ||
01649              (std::string(aIconFile) == "wireframe")) {
01650     action->setCheckable(TRUE);
01651     action->setChecked(TRUE);
01652     action->setData(aIconFile);
01653     connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ChangeSurfaceStyle(const QString&)));
01654     signalMapper->setMapping(action, QString(aIconFile));
01655 
01656     if (std::string(aIconFile) == "hidden_line_removal") {
01657       SetIconHLRSelected();
01658     }
01659     if (std::string(aIconFile) == "hidden_line_and_surface_removal") {
01660       SetIconHLHSRSelected();
01661     }
01662     if (std::string(aIconFile) == "solid") {
01663       SetIconSolidSelected();
01664     }
01665     if (std::string(aIconFile) == "wireframe") {
01666       SetIconWireframeSelected();
01667     }
01668 
01669     // special case : perspective/ortho
01670   } else if ((std::string(aIconFile) == "perspective") ||
01671              (std::string(aIconFile) == "ortho")) {
01672     action->setCheckable(TRUE);
01673     action->setChecked(TRUE);
01674     action->setData(aIconFile);
01675     connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ChangePerspectiveOrtho(const QString&)));
01676     signalMapper->setMapping(action, QString(aIconFile));
01677 
01678     if (std::string(aIconFile) == "perspective") {
01679       SetIconPerspectiveSelected();
01680     }
01681     if (std::string(aIconFile) == "ortho") {
01682       SetIconOrthoSelected();
01683     }
01684 
01685   } else {
01686 
01687     // Find the command in the command tree
01688     G4UImanager* UI = G4UImanager::GetUIpointer();
01689     if(UI==NULL) return;
01690     G4UIcommandTree * treeTop = UI->GetTree();
01691     
01692     if(treeTop->FindPath(aCommand) == NULL) {
01693       G4cout << "Warning: command '"<< aCommand <<"' does not exist, please define it before using it."<< G4endl;
01694     }
01695     
01696     connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&)));
01697     signalMapper->setMapping(action, QString(aCommand));
01698   }
01699 }
01700 
01701 
01702 
01703 void G4UIQt::ActivateCommand(
01704  G4String newCommand
01705 )
01706 {
01707   if (!fHelpTreeWidget) {
01708     return;
01709   }
01710   // Look for the choosen command "newCommand"
01711   size_t i = newCommand.index(" ");
01712   G4String targetCom ="";
01713   if( i != std::string::npos )
01714     {
01715       G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
01716       newValue.strip(G4String::both);
01717       targetCom = ModifyToFullPathCommand( newValue );
01718     }
01719 #ifdef G4DEBUG_INTERFACES_BASIC
01720   printf("G4UIQt::ActivateCommand found : %s \n",targetCom.data());
01721 #endif
01722   if (targetCom != "") {
01723     OpenHelpTreeOnCommand(targetCom.data());
01724   }
01725 
01726   fUITabWidget->setCurrentWidget(fHelpTBWidget);
01727 }
01728 
01729 
01730 
01737 void G4UIQt::InitHelpTreeAndVisParametersWidget()
01738 {
01739 
01740   if (! fHelpTreeWidget ) {
01741     fHelpTreeWidget = new QTreeWidget();
01742   }
01743 
01744   // build widget
01745   fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
01746   QStringList labels;
01747   labels << QString("Command");
01748   fHelpTreeWidget->setHeaderLabels(labels);
01749 
01750 
01751   connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback()));  
01752   connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback()));  
01753 
01754 }
01761 void G4UIQt::FillHelpTree()
01762 {
01763   if (! fHelpTreeWidget ) {
01764     InitHelpTreeAndVisParametersWidget();
01765   }
01766 
01767   QString searchText = fHelpLine->text();
01768 
01769   if (searchText =="") {
01770     // clear old help tree
01771     //    fHelpTreeWidget->clear();
01772   } else {
01773     return; 
01774   }
01775 
01776   if (fHelpArea) {
01777 #if QT_VERSION < 0x040200
01778     fHelpArea->clear();
01779 #else
01780     fHelpArea->setText("");
01781 #endif
01782   }
01783 
01784   if (fHelpLine) {
01785 #if QT_VERSION < 0x040200
01786     fHelpLine->clear();
01787 #else
01788     fHelpLine->setText("");
01789 #endif
01790   }
01791 
01792   G4UImanager* UI = G4UImanager::GetUIpointer();
01793   if(UI==NULL) return;
01794   G4UIcommandTree * treeTop = UI->GetTree();
01795 
01796   G4int treeSize = treeTop->GetTreeEntry();
01797   QTreeWidgetItem * newItem = NULL;
01798   QString commandText = "";
01799   for (int a=0;a<treeSize;a++) {
01800     // Creating new item
01801     newItem = NULL;
01802 
01803     commandText = QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed();
01804 
01805     // if already exist, don't create it !
01806     for (int b=0;b<fHelpTreeWidget->topLevelItemCount();b++) {
01807       if (!newItem)
01808         newItem = FindTreeItem(fHelpTreeWidget->topLevelItem(b),commandText);
01809     }
01810 
01811     if (newItem == NULL) {
01812       
01813       newItem = new QTreeWidgetItem(fHelpTreeWidget);
01814       newItem->setText(0,GetShortCommandPath(commandText));
01815     }
01816 
01817     // look for childs
01818     CreateHelpTree(newItem,treeTop->GetTree(a+1));
01819   }
01820 
01821 }
01822 
01823 
01824 
01829 void G4UIQt::CreateHelpTree(
01830  QTreeWidgetItem *aParent
01831 ,G4UIcommandTree *aCommandTree
01832 )
01833 {
01834   if (aParent == NULL) return;
01835   if (aCommandTree == NULL) return;
01836 
01837 
01838   // Creating new item
01839   QTreeWidgetItem * newItem;
01840 
01841   QString commandText = "";
01842   // Get the Sub directories
01843   for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
01844 
01845     commandText = QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed();
01846     
01847     // if already exist, don't create it !
01848     newItem = FindTreeItem(aParent,commandText);
01849     if (newItem == NULL) {
01850       newItem = new QTreeWidgetItem(aParent);
01851       newItem->setText(0,GetShortCommandPath(commandText));
01852     }
01853     CreateHelpTree(newItem,aCommandTree->GetTree(a+1));
01854   }
01855 
01856   // Get the Commands
01857 
01858   for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
01859     
01860     QStringList stringList;
01861     commandText = QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed();
01862 
01863     // if already exist, don't create it !
01864     newItem = FindTreeItem(aParent,commandText);
01865     if (newItem == NULL) {
01866       newItem = new QTreeWidgetItem(aParent);
01867       newItem->setText(0,GetShortCommandPath(commandText));
01868 
01869 #if QT_VERSION < 0x040202
01870       fHelpTreeWidget->setItemExpanded(newItem,false); 
01871 #else
01872       newItem->setExpanded(false);
01873 #endif
01874     }
01875   }
01876 }
01877 
01878  
01879 
01880 
01886 bool G4UIQt::CreateVisCommandGroupAndToolBox(
01887  G4UIcommand* aCommand
01888 ,QWidget* aParent
01889 ,int aDepthLevel
01890 ,bool isDialog
01891 )
01892 {
01893   QString commandText = QString((char*)(aCommand->GetCommandPath().data())).section("/",-aDepthLevel);
01894 
01895   if (commandText == NULL) {
01896     return false;
01897   }
01898 
01899   // Look if groupBox is create
01900   //  QGroupBox* gBoxCommandWidget;
01901   QWidget* newParentWidget = NULL;
01902   bool found = false;
01903   QString commandSection = commandText.left(commandText.indexOf("/"));
01904   
01905   if (aDepthLevel == 1) {
01906     QToolBox* currentParent = dynamic_cast<QToolBox*>(aParent);
01907     if (currentParent != 0){
01908 
01909       // already exists ?
01910       for (int a=0; a<currentParent->count(); a++) {
01911         if (currentParent->itemText(a) == commandSection) {
01912           found = true;
01913           newParentWidget = currentParent->widget(a);
01914         }
01915       }
01916     }
01917     // Not found ? create it
01918     if (!found) {
01919       newParentWidget = new QGroupBox();
01920       //        newParentWidget->setSizePolicy (QSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum));
01921       newParentWidget->setLayout(new QVBoxLayout());
01922       if (currentParent != 0){
01923         currentParent->addItem(newParentWidget,commandSection);
01924       } else {
01925         if (!aParent->layout()) {
01926           aParent->setLayout(new QVBoxLayout());
01927         }
01928         aParent->layout()->addWidget(newParentWidget);
01929       }
01930 
01931       if (commandText.indexOf("/") == -1) {
01932         
01933         // Guidance
01934         QString guidance;
01935         G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
01936         for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
01937           guidance += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
01938         }
01939         newParentWidget->setToolTip(guidance);
01940       }
01941       
01942       QScrollArea* sc = dynamic_cast<QScrollArea*>(newParentWidget->parent()->parent());
01943       if (sc != 0) {
01944         sc->ensureWidgetVisible(newParentWidget);
01945         //          sc->setSizePolicy (QSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum));
01946         
01947       }
01948     }
01949   } else {
01950 
01951     // try to know if this level is already there
01952     QGroupBox* currentParent = dynamic_cast<QGroupBox*>(aParent);
01953     if (currentParent != 0){
01954 
01955       // if depth==2, then we add a [more parameters inside] to the toolBoxItem parent
01956       // QGroupBox > QWidget > QScrollArea > QToolBox
01957       if (aDepthLevel == 2){
01958         QToolBox* parentToolBox = dynamic_cast<QToolBox*>(currentParent->parent()->parent()->parent());
01959         if (parentToolBox != 0) {
01960           //          parentToolBox->setItemText(parentToolBox->indexOf(currentParent),"[more parameters inside]");
01961         }
01962       }
01963       for (int a=0; a<aParent->layout()->count(); a++) {
01964         QGroupBox* gb = dynamic_cast<QGroupBox*>(aParent->layout()->itemAt(a)->widget());
01965         if (gb != 0) {
01966           if (gb->title() == commandSection) {
01967             found = true;
01968             newParentWidget = gb;
01969           }
01970         }
01971       }
01972     }
01973     
01974     // Not found ? create it
01975     if (!found) {
01976       newParentWidget = new QGroupBox(commandSection);
01977       newParentWidget->setLayout(new QVBoxLayout());
01978       if (!aParent->layout()) {
01979         aParent->setLayout(new QVBoxLayout());
01980       }
01981       aParent->layout()->addWidget(newParentWidget);
01982 
01983       // set toolTip
01984       // Guidance
01985       QString guidance;
01986       G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
01987       for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
01988         guidance += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
01989       }
01990       newParentWidget->setToolTip(guidance);
01991     }
01992   }
01993   
01994   // fill command groupbox
01995   if (commandText.indexOf("/") == -1) {
01996     if (CreateCommandWidget(aCommand, newParentWidget,isDialog)) {
01997       return true;
01998     }
01999   } else {
02000     CreateVisCommandGroupAndToolBox(aCommand,newParentWidget, aDepthLevel-1,isDialog);
02001   }
02002 
02003   return true;
02004 }
02005 
02006 
02007 
02013 bool G4UIQt::CreateCommandWidget(G4UIcommand* aCommand, QWidget* aParent, bool isDialog) {
02014 
02015   if (aCommand == NULL) {
02016     return false;
02017   }
02018 
02019 
02020   // parameters
02021   G4int n_parameterEntry = aCommand->GetParameterEntries();
02022   if( n_parameterEntry > 0 ) {
02023     G4UIparameter *param;
02024       
02025     // Re-implementation of G4UIparameter.cc
02026     QWidget* paramWidget = new QWidget();
02027     QGridLayout* gridLayout = new QGridLayout(paramWidget);
02028       
02029     // Special case for colour, try to display a color chooser if we found red/green/blue parameter
02030     unsigned int nbColorParameter = 0;
02031     bool isStillColorParameter = false;
02032     bool isColorDialogAdded = false;
02033     QLabel* redLabel = NULL;
02034     QLabel* greenLabel = NULL;
02035     QString redDefaultStr = "";
02036     QString greenDefaultStr = "";
02037     QString blueDefaultStr = "";
02038     QWidget* redInput = NULL;
02039     QWidget* greenInput = NULL;
02040 
02041     for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
02042       QString txt;
02043       param = aCommand->GetParameter(i_thParameter);
02044       QLabel* label = new QLabel(QString((char*)(param->GetParameterName()).data()));
02045 
02046       if ((label->text() == "red") || (label->text() == "red_or_string")){
02047         nbColorParameter ++;
02048         isStillColorParameter = true;
02049       } else if ((label->text() == "green") && isStillColorParameter) {
02050         nbColorParameter ++;
02051       } else if ((label->text() == "blue") && isStillColorParameter) {
02052         nbColorParameter ++;
02053       } else if (!isColorDialogAdded) {
02054           
02055         // not following red/green/blue parameters ?
02056         if (nbColorParameter == 1) {
02057           gridLayout->addWidget(redLabel,i_thParameter-1,0);
02058           gridLayout->addWidget(redInput,i_thParameter-1,1);
02059         } else if (nbColorParameter == 2) {
02060           gridLayout->addWidget(redLabel,i_thParameter-2,0);
02061           gridLayout->addWidget(redInput,i_thParameter-2,1);
02062           gridLayout->addWidget(greenLabel,i_thParameter-1,0);
02063           gridLayout->addWidget(greenInput,i_thParameter-1,1);
02064         }
02065         nbColorParameter = 0;
02066       }
02067       // Check parameter type, could be NULL if not found
02068       QWidget* input = NULL;
02069       if ((QString(QChar(param->GetParameterType())) == "d") || (QString(QChar(param->GetParameterType())) == "i")) {
02070         input = new QLineEdit();
02071         // set default value
02072         dynamic_cast<QLineEdit*>(input)->setText(QString((char*)(param->GetDefaultValue()).data()));
02073 
02074         if (((label->text() == "red") || (label->text() == "red_or_string")) && isStillColorParameter) {
02075           redDefaultStr = QString((char*)(param->GetDefaultValue()).data());
02076         } else if ((label->text() == "green") && isStillColorParameter) {
02077           greenDefaultStr = QString((char*)(param->GetDefaultValue()).data());
02078         } else if ((label->text() == "green") && isStillColorParameter) {
02079           blueDefaultStr = QString((char*)(param->GetDefaultValue()).data());
02080         }
02081 
02082       } else if (QString(QChar(param->GetParameterType())) == "b") {
02083         input = new QWidget();
02084         QHBoxLayout* layout = new QHBoxLayout(input);
02085 
02086         QButtonGroup* buttons = new QButtonGroup();
02087         QRadioButton* radioOff = new QRadioButton("0");
02088         QRadioButton* radioOn = new QRadioButton("1");
02089         buttons->addButton(radioOn);
02090         buttons->addButton(radioOff);
02091         layout->addWidget(radioOn);
02092         layout->addWidget(radioOff);
02093 
02094         // set default value
02095         QString defaultValue = QString((char*)(param->GetDefaultValue()).data());
02096         if (defaultValue == "0") {
02097           radioOff->setChecked(true);
02098         } else if (defaultValue == "1") {
02099           radioOn->setChecked(true);
02100         }
02101       } else if ((QString(QChar(param->GetParameterType())) == "s") && (!param->GetParameterCandidates().isNull())) {
02102         input = new QComboBox();
02103         QString candidates = QString((char*)(param->GetParameterCandidates()).data());
02104         QStringList list = candidates.split (" ");
02105 
02106         // add all candidates to widget
02107         QString defaultValue = QString((char*)(param->GetDefaultValue()).data());
02108         for (int a=0; a<list.size(); a++) {
02109           dynamic_cast<QComboBox*>(input)->addItem(list.at(a));
02110           if (list.at(a) == defaultValue) {
02111             dynamic_cast<QComboBox*>(input)->setCurrentIndex(a);
02112           }
02113         }
02114 
02115       } else if ((QString(QChar(param->GetParameterType())) == "s")) {  // string
02116         input = new QLineEdit();
02117         // set default value
02118         dynamic_cast<QLineEdit*>(input)->setText(QString((char*)(param->GetDefaultValue()).data()));
02119 
02120       } else if ((QString(QChar(param->GetParameterType())) == "c")) {  // on/off
02121         input = new QWidget();
02122         QHBoxLayout* layout = new QHBoxLayout(input);
02123 
02124         QButtonGroup* buttons = new QButtonGroup();
02125         QRadioButton* radioOff = new QRadioButton("off");
02126         QRadioButton* radioOn = new QRadioButton("on");
02127         buttons->addButton(radioOn);
02128         buttons->addButton(radioOff);
02129         layout->addWidget(radioOn);
02130         layout->addWidget(radioOff);
02131 
02132         // set default value
02133         QString defaultValue = QString((char*)(param->GetDefaultValue()).data());
02134         if (defaultValue == "off") {
02135           radioOff->setChecked(true);
02136         } else if (defaultValue == "on") {
02137           radioOn->setChecked(true);
02138         }
02139 
02140       } else {
02141         input = new QLineEdit();
02142         dynamic_cast<QLineEdit*>(input)->setText(QString((char*)(param->GetDefaultValue()).data()));
02143       }
02144         
02145       txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
02146       if( ! param->GetParameterGuidance().isNull() )
02147         txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
02148 
02149       txt += " Parameter type  : " + QString(QChar(param->GetParameterType())) + "\n";
02150       if(param->IsOmittable()){
02151         txt += " Omittable       : True\n";
02152       } else {
02153         txt += " Omittable       : False\n";
02154       }
02155       if( param->GetCurrentAsDefault() ) {
02156         txt += " Default value   : taken from the current value\n";
02157       } else if( ! param->GetDefaultValue().isNull() ) {
02158         txt += " Default value   : " + QString((char*)(param->GetDefaultValue()).data())+ "\n";
02159       }
02160       if( ! param->GetParameterRange().isNull() ) {
02161         txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
02162       }
02163       if( ! param->GetParameterCandidates().isNull() ) {
02164         txt += " Candidates      : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
02165       }
02166         
02167       if (isStillColorParameter && (nbColorParameter != 0)) {
02168         if ((label->text() == "red") || (label->text() == "red_or_string")) {
02169           redLabel = label;
02170           redInput = input;
02171         } else if (label->text() == "green") {
02172           greenLabel = label;
02173           greenInput = input;
02174         } else if (label->text() == "blue") {
02175 
02176           // we have all, then add a color chooser
02177 
02178           // Create a pixmap with the default color
02179           QColor qc;
02180           if ((redDefaultStr != "") && (redDefaultStr != "") && (redDefaultStr != "")) {
02181             qc.setRgbF(redDefaultStr.toDouble(),
02182                        greenDefaultStr.toDouble(),
02183                        blueDefaultStr.toDouble());
02184           }
02185           QPixmap pixmap = QPixmap(QSize(16, 16));
02186           pixmap.fill (qc);
02187           QPainter painter(&pixmap);
02188           painter.setPen(Qt::black);
02189           painter.drawRect(0,0,15,15); // Draw contour
02190             
02191           input = new QPushButton("Change color");
02192           dynamic_cast<QPushButton*>(input)->setIcon(pixmap);
02193           dynamic_cast<QPushButton*>(input)->setAccessibleName(redDefaultStr+" "+greenDefaultStr+" "+blueDefaultStr);
02194           label = new QLabel("Choose color");
02195 
02196           // less 1 because we have to add one to the row number
02197           nbColorParameter--;
02198           gridLayout->addWidget(label,i_thParameter-nbColorParameter,0);
02199           input->setToolTip("Select the current color");
02200           gridLayout->addWidget(input,i_thParameter-nbColorParameter,1);
02201 
02202           // Connect pushButton to ColorDialog in callback
02203           QSignalMapper* signalMapper = new QSignalMapper(this);
02204           signalMapper->setMapping(input,input);
02205           connect(input, SIGNAL(clicked()), signalMapper, SLOT(map()));
02206           connect(signalMapper, SIGNAL(mapped(QWidget*)),this, SLOT(ChangeColorCallback(QWidget*)));
02207 
02208           isColorDialogAdded = true;
02209           isStillColorParameter = false;
02210         }
02211       } else {
02212         gridLayout->addWidget(label,i_thParameter-nbColorParameter,0);
02213         input->setToolTip(txt);
02214         gridLayout->addWidget(input,i_thParameter-nbColorParameter,1);
02215       }
02216     }
02217     // add command name in hidden value at last line position 0
02218     QLabel* name = new QLabel(QString((char*)(aCommand->GetCommandPath().data())));
02219     name->hide();
02220     gridLayout->addWidget(name,n_parameterEntry-nbColorParameter,0);
02221 
02222     QPushButton* applyButton = new QPushButton("Apply");
02223     if (!isDialog) {
02224       
02225       gridLayout->addWidget(applyButton,n_parameterEntry-nbColorParameter,1);
02226       
02227       QSignalMapper* signalMapper = new QSignalMapper(this);
02228       signalMapper->setMapping(applyButton, paramWidget);
02229       connect(applyButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
02230       connect(signalMapper, SIGNAL(mapped(QWidget*)),this, SLOT(VisParameterCallback(QWidget*)));
02231     } else {
02232       // Apply/Cancel buttons
02233       
02234       applyButton->setAutoDefault( TRUE );
02235       applyButton->setDefault( TRUE );
02236       gridLayout->addWidget(applyButton,n_parameterEntry-nbColorParameter,0);
02237 
02238       QPushButton* cancelButton = new QPushButton( tr( "&Cancel" ));
02239       cancelButton->setAutoDefault( TRUE );
02240       gridLayout->addWidget(cancelButton,n_parameterEntry-nbColorParameter,1);
02241       
02242       QSignalMapper* signalMapper = new QSignalMapper(this);
02243       signalMapper->setMapping(applyButton, paramWidget);
02244       connect(applyButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
02245       connect(signalMapper, SIGNAL(mapped(QWidget*)),this, SLOT(VisParameterCallback(QWidget*)));
02246 
02247       QWidget * parentCheck = aParent;
02248       QDialog* parentDialog = NULL;
02249       bool found = false;
02250       while ((parentCheck->parentWidget()) != NULL) {
02251         parentCheck = parentCheck->parentWidget();
02252         parentDialog = dynamic_cast<QDialog*>(parentCheck);
02253         if (parentDialog) {
02254           connect( applyButton, SIGNAL( clicked() ), parentDialog, SLOT( accept() ) );
02255           connect( cancelButton, SIGNAL( clicked() ), parentDialog, SLOT( reject() ) );
02256           found = true;
02257         }
02258       }
02259       if (!found) {
02260         return false;
02261       }
02262     }
02263     
02264     if (!aParent->layout()) {
02265       aParent->setLayout(new QVBoxLayout());
02266     }
02267     aParent->layout()->addWidget(paramWidget);
02268   } 
02269 
02270   return true;
02271 }
02272 
02273 
02278 QTreeWidgetItem* G4UIQt::FindTreeItem(
02279  QTreeWidgetItem *aParent
02280 ,const QString& aCommand
02281 )
02282 {
02283   if (aParent == NULL) return NULL;
02284 
02285   // Suppress last "/"
02286   QString myCommand = aCommand;
02287   
02288   if (myCommand.lastIndexOf("/") == (myCommand.size()-1)) {
02289     myCommand = myCommand.left(myCommand.size()-1);
02290   }
02291 
02292   if (GetLongCommandPath(aParent) == myCommand)
02293     return aParent;
02294   
02295   QTreeWidgetItem * tmp = NULL;
02296   for (int a=0;a<aParent->childCount();a++) {
02297     if (!tmp)
02298       tmp = FindTreeItem(aParent->child(a),myCommand);
02299   }
02300   return tmp;
02301 }
02302 
02303 
02304 
02312 QString G4UIQt::GetCommandList (
02313  const G4UIcommand *aCommand
02314 )
02315 {
02316 
02317   QString txt ="";
02318   if (aCommand == NULL)
02319     return txt;
02320 
02321   G4String commandPath = aCommand->GetCommandPath();
02322   G4String rangeString = aCommand->GetRange();
02323   G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
02324   G4int n_parameterEntry = aCommand->GetParameterEntries();
02325   
02326   if ((commandPath == "") && 
02327       (rangeString == "") &&
02328       (n_guidanceEntry == 0) &&
02329       (n_parameterEntry == 0)) {
02330     return txt;
02331   }
02332 
02333   if((commandPath.length()-1)!='/') {
02334     txt += "Command " + QString((char*)(commandPath).data()) + "\n";
02335   }
02336   txt += "Guidance :\n";
02337   
02338   for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
02339     txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
02340   }
02341   if( ! rangeString.isNull() ) {
02342     txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n";
02343   }
02344   if( n_parameterEntry > 0 ) {
02345     G4UIparameter *param;
02346     
02347     // Re-implementation of G4UIparameter.cc
02348     
02349     for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
02350       param = aCommand->GetParameter(i_thParameter);
02351       txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
02352       if( ! param->GetParameterGuidance().isNull() )
02353         txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
02354       txt += " Parameter type  : " + QString(QChar(param->GetParameterType())) + "\n";
02355       if(param->IsOmittable()){
02356         txt += " Omittable       : True\n";
02357       } else {
02358         txt += " Omittable       : False\n";
02359       }
02360       if( param->GetCurrentAsDefault() ) {
02361         txt += " Default value   : taken from the current value\n";
02362       } else if( ! param->GetDefaultValue().isNull() ) {
02363         txt += " Default value   : " + QString((char*)(param->GetDefaultValue()).data())+ "\n";
02364       }
02365       if( ! param->GetParameterRange().isNull() ) {
02366         txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
02367       }
02368       if( ! param->GetParameterCandidates().isNull() ) {
02369         txt += " Candidates      : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
02370       }
02371     }
02372   }
02373   return txt;
02374 }
02375 
02376 
02382 G4bool G4UIQt::IsGUICommand(
02383  const G4UIcommand *aCommand
02384 )
02385 {
02386   if (aCommand == NULL)
02387     return false;
02388 
02389   G4int n_parameterEntry = aCommand->GetParameterEntries();
02390   
02391   if( n_parameterEntry > 0 ) {
02392     G4UIparameter *param;
02393     
02394     // Re-implementation of G4UIparameter.cc
02395     
02396     for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
02397       param = aCommand->GetParameter(i_thParameter);
02398       if (QString(QChar(param->GetParameterType())) == "d") {
02399         return true;
02400       }
02401       if (QString(QChar(param->GetParameterType())) == "b") {
02402         return true;
02403       }
02404       if (QString(QChar(param->GetParameterType())) == "i") {
02405         return true;
02406       }
02407       if (QString(QChar(param->GetParameterType())) == "s" && (!param->GetParameterCandidates().isNull())) {
02408         return true;
02409       }
02410     }
02411   }
02412   return false;
02413 }
02414 
02415 
02418 G4bool G4UIQt::GetHelpChoice(
02419  G4int&
02420 )
02421 {
02422 #ifdef G4DEBUG_INTERFACES_BASIC
02423   printf("G4UIQt::GetHelpChoice SHOULD NEVER GO HERE");
02424 #endif
02425   return true;
02426 }
02427 
02428 
02436 bool G4UIQt::eventFilter( // Should stay with a minuscule eventFilter because of Qt
02437  QObject *aObj
02438 ,QEvent *aEvent
02439 )
02440 {
02441   bool moveCommandCursor = false;
02442   if (aObj == NULL) return false;
02443   if (aEvent == NULL) return false;
02444 
02445   if (aObj == fHistoryTBTableList) {
02446     if (aEvent->type() == QEvent::KeyPress) {
02447       fCommandArea->setFocus();
02448     }
02449   }
02450   if (aObj == fCommandArea) {
02451     if (aEvent->type() == QEvent::KeyPress) {
02452       QKeyEvent *e = static_cast<QKeyEvent*>(aEvent);
02453       if ((e->key() == (Qt::Key_Down)) ||
02454           (e->key() == (Qt::Key_PageDown)) ||
02455           (e->key() == (Qt::Key_Up)) ||
02456           (e->key() == (Qt::Key_PageUp))) {
02457         int selection = fHistoryTBTableList->currentRow();
02458         if (fHistoryTBTableList->count()) {
02459           if (selection == -1) {
02460             selection = fHistoryTBTableList->count()-1;
02461           } else {
02462             if (e->key() == (Qt::Key_Down)) {
02463               if (selection <(fHistoryTBTableList->count()-1))
02464                 selection++;
02465             } else if (e->key() == (Qt::Key_PageDown)) {
02466               selection = fHistoryTBTableList->count()-1;
02467             } else if (e->key() == (Qt::Key_Up)) {
02468               if (selection >0)
02469                 selection --;
02470             } else if (e->key() == (Qt::Key_PageUp)) {
02471               selection = 0;
02472             }
02473           }
02474           fHistoryTBTableList->clearSelection();
02475 #if QT_VERSION < 0x040202
02476           fHistoryTBTableList->setItemSelected(fHistoryTBTableList->item(selection),true);
02477 #else
02478           fHistoryTBTableList->item(selection)->setSelected(true);
02479 #endif      
02480           fHistoryTBTableList->setCurrentItem(fHistoryTBTableList->item(selection));
02481         }
02482         moveCommandCursor = true;
02483       } else if (e->key() == (Qt::Key_Tab)) {
02484         G4String ss = Complete(fCommandArea->text().toStdString().c_str());
02485         fCommandArea->setText((char*)(ss.data()));
02486 
02487         // do not pass by parent, it will disable widget tab focus !
02488         return true;
02489         // L.Garnier : MetaModifier is CTRL for MAC, but I don't want to put a MAC 
02490         // specific #ifdef
02491       } else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_A)) {
02492        fCommandArea->home(false);
02493        return true;
02494       } else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_E)) {
02495        fCommandArea->end(false);
02496        return true;
02497       }
02498     }
02499   }
02500   bool res= false;
02501   // change cursor position if needed
02502   if (moveCommandCursor == true) {
02503 #ifdef G4DEBUG_INTERFACES_BASIC
02504     printf("G4UIQt::eventFilter setCursor Position\n");
02505 #endif
02506     fCommandArea->setCursorPosition ( fCommandArea->text().length() );
02507     fCommandArea->setCursorPosition (4);
02508   } else {
02509     // pass the event on to the parent class
02510     res = QObject::eventFilter(aObj, aEvent);
02511   }
02512   return res;
02513 }
02514 
02515 
02516 
02517 
02518 /***************************************************************************/
02519 //
02520 //             SLOTS DEFINITIONS
02521 //
02522 /***************************************************************************/
02523 
02526 void G4UIQt::ShowHelpCallback (
02527 )
02528 {
02529   TerminalHelp("");
02530 }
02531 
02532 
02535 void G4UIQt::ClearButtonCallback (
02536 )
02537 {
02538   fCoutTBTextArea->clear();
02539   fG4cout.clear();
02540 }
02541 
02544 void G4UIQt::ExitSession (
02545 )
02546 {
02547   SessionTerminate();
02548 }
02549 
02550 void G4UIQt::ExitHelp(
02551 ) const
02552 {
02553 }
02554 
02558 void G4UIQt::CommandEnteredCallback (
02559 )
02560 {
02561   G4String command (fCommandArea->text().toStdString().c_str());
02562   if (fCommandArea->text().trimmed() != "") {
02563     fHistoryTBTableList->addItem(fCommandArea->text());
02564     fHistoryTBTableList->clearSelection();
02565     fHistoryTBTableList->setCurrentItem(NULL);
02566     fCommandArea->setText("");
02567 
02568     G4Qt* interactorManager = G4Qt::getInstance ();
02569     if (interactorManager) { 
02570       interactorManager->FlushAndWaitExecution();
02571     }
02572     if (command(0,4) != "help") {
02573       ApplyShellCommand (command,exitSession,exitPause);
02574     } else {
02575       ActivateCommand(command);
02576     }
02577     // Rebuild help tree
02578     FillHelpTree();
02579 
02580     if(exitSession==true) 
02581       SessionTerminate();
02582   }
02583 }
02584 
02585 
02588 void G4UIQt::VisParameterCallback(QWidget* widget){
02589   if (widget == NULL) {
02590     return;
02591   }
02592   
02593   // Look in all the Grid layout, but only column 1 (0 is the parameter name)
02594   QGridLayout* grid = dynamic_cast<QGridLayout*>(widget->layout());
02595   if (grid == 0) {
02596     return;
02597   }
02598   QString command;
02599 #if QT_VERSION < 0x040400
02600   QWidget* name = grid->itemAt(grid->columnCount()*(grid->rowCount()-2))->widget();
02601 #else
02602   QWidget* name = grid->itemAtPosition(grid->rowCount()-1,0)->widget();
02603 #endif
02604   if (widget == NULL) {
02605     return;
02606   }
02607   if (dynamic_cast<QLabel*>(name) == 0) {
02608     return;
02609   }
02610   command += (dynamic_cast<QLabel*>(name))->text()+" ";
02611   
02612   for (int a=0;a<grid->rowCount()-1; a++) {
02613 #if QT_VERSION < 0x040400
02614     QWidget* widgetTmp = grid->itemAt(a*grid->columnCount()+1)->widget();
02615 #else
02616     QWidget* widgetTmp = grid->itemAtPosition(a,1)->widget();
02617 #endif
02618     
02619     // 4 kind of widgets : QLineEdit / QComboBox / radioButtonsGroup / QPushButton (color chooser)
02620     if (widgetTmp != NULL) {
02621 
02622       if (dynamic_cast<QLineEdit*>(widgetTmp) != 0) {
02623         command += (dynamic_cast<QLineEdit*>(widgetTmp))->text()+" ";
02624 
02625       } else if (dynamic_cast<QComboBox*>(widgetTmp) != 0){
02626         command += (dynamic_cast<QComboBox*>(widgetTmp))->itemText((dynamic_cast<QComboBox*>(widgetTmp))->currentIndex())+" ";
02627 
02628         // Color chooser 
02629       } else if (dynamic_cast<QPushButton*>(widgetTmp) != 0){
02630         command += widgetTmp->accessibleName()+" ";
02631 
02632         // Check for Button group
02633       } else if (dynamic_cast<QWidget*>(widgetTmp) != 0){
02634         if (widgetTmp->layout()->count() > 0){
02635           if (dynamic_cast<QRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()) != 0) {
02636             QAbstractButton * checked = (dynamic_cast<QRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()))->group()->checkedButton();
02637             if (checked != 0) {
02638               command += (dynamic_cast<QRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()))->group()->checkedButton()->text()+" ";
02639             }
02640           }
02641         }
02642 
02643       }
02644     }
02645   }
02646   if (command != "") {
02647     G4UImanager* UI = G4UImanager::GetUIpointer();
02648     if(UI != NULL)  {
02649       UI->ApplyCommand(command.toStdString().c_str());
02650     }
02651   }
02652 }
02653 
02654 
02660 void G4UIQt::ButtonCallback (
02661  const QString& aCommand
02662 )
02663 {
02664   G4String ss = G4String(aCommand.toStdString().c_str());
02665   ss = ss.strip(G4String::leading);
02666 
02667   G4UImanager* UI = G4UImanager::GetUIpointer();
02668   if(UI==NULL) return;
02669   G4UIcommandTree * treeTop = UI->GetTree();
02670 
02671   G4UIcommand* command = treeTop->FindPath(ss);
02672 
02673   if (command) {
02674     // if is GUI, then open a dialog
02675     if (IsGUICommand(command)) {
02676       QDialog* menuParameterDialog = new QDialog();
02677 
02678       if (CreateVisCommandGroupAndToolBox(command,menuParameterDialog,1,true)) {
02679         menuParameterDialog->setWindowTitle (aCommand);
02680         menuParameterDialog->setSizePolicy (QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
02681 
02682         // exec this dialog, apply the command automaticaly, and return
02683         menuParameterDialog->exec();
02684         return;
02685       }
02686     }
02687   }
02688 
02689   ApplyShellCommand(ss,exitSession,exitPause);
02690 
02691   // Rebuild help tree
02692   FillHelpTree();
02693 
02694   if(exitSession==true) 
02695     SessionTerminate();
02696 }
02697 
02698 
02699 
02702 void G4UIQt::HelpTreeClicCallback (
02703 )
02704 {
02705   QTreeWidgetItem* item =  NULL;
02706   if (!fHelpTreeWidget)
02707     return ;
02708 
02709   if (!fHelpArea)
02710     return;
02711   
02712   QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
02713   if (list.isEmpty())
02714     return;
02715   item = list.first();
02716   if (!item)
02717     return;
02718   
02719   G4UImanager* UI = G4UImanager::GetUIpointer();
02720   if(UI==NULL) return;
02721   G4UIcommandTree * treeTop = UI->GetTree();
02722 
02723   std::string itemText = GetLongCommandPath(item).toStdString();
02724   
02725   G4UIcommand* command = treeTop->FindPath(itemText.c_str());
02726 
02727   if (command) {
02728  #if QT_VERSION < 0x040200
02729     fHelpArea->clear();
02730     fHelpArea->append(GetCommandList(command));
02731  #else
02732     fHelpArea->setText(GetCommandList(command));
02733  #endif
02734   } else {  // this is a command
02735     G4UIcommandTree* path = treeTop->FindCommandTree(itemText.c_str());
02736     if ( path) {
02737       // this is not a command, this is a sub directory
02738       // We display the Title
02739  #if QT_VERSION < 0x040200
02740       fHelpArea->clear();
02741       fHelpArea->append(path->GetTitle().data());
02742  #else
02743       fHelpArea->setText(path->GetTitle().data());
02744  #endif
02745     }
02746   }
02747 }
02748  
02751 void G4UIQt::HelpTreeDoubleClicCallback (
02752 )
02753 {
02754   HelpTreeClicCallback();
02755 
02756   QTreeWidgetItem* item =  NULL;
02757   if (!fHelpTreeWidget)
02758     return ;
02759 
02760   if (!fHelpArea)
02761     return;
02762   
02763   QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
02764   if (list.isEmpty())
02765     return;
02766   item = list.first();
02767   if (!item)
02768     return;
02769 
02770   fCommandArea->clear();
02771   fCommandArea->setText(GetLongCommandPath(item));
02772 }
02773 
02774 
02778 void G4UIQt::CommandHistoryCallback(
02779 )
02780 {
02781   QListWidgetItem* item =  NULL;
02782   if (!fHistoryTBTableList)
02783     return ;
02784 
02785   
02786   QList<QListWidgetItem *> list =fHistoryTBTableList->selectedItems();
02787   if (list.isEmpty())
02788     return;
02789   item = list.first();
02790   if (!item)
02791     return;
02792   fCommandArea->setText(item->text());
02793 #ifdef G4DEBUG_INTERFACES_BASIC
02794     printf("G4UIQt::CommandHistoryCallback change text\n");
02795 #endif
02796 }
02797 
02798 
02799 void G4UIQt::CoutFilterCallback(
02800 const QString & text) {
02801 
02802   QStringList result = fG4cout.filter(text);
02803   fCoutTBTextArea->setPlainText(result.join("\n"));
02804 
02805   fCoutTBTextArea->repaint();
02806   fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
02807 
02808  }
02809 
02814 void G4UIQt::LookForHelpStringCallback(
02815 )
02816 {
02817   QString searchText = fHelpLine->text();
02818 
02819 #if QT_VERSION < 0x040200
02820   fHelpArea->clear();
02821 #else
02822   fHelpArea->setText("");
02823 #endif
02824   if (searchText =="") {
02825     // clear old help tree
02826     fHelpTreeWidget->clear();
02827 
02828     FillHelpTree();
02829 
02830     return;
02831   } else {
02832     OpenHelpTreeOnCommand(searchText);
02833   }
02834 }
02835 
02836 
02837 void G4UIQt::OpenHelpTreeOnCommand(
02838  const QString & searchText
02839 )
02840 {
02841   // the help tree
02842   G4UImanager* UI = G4UImanager::GetUIpointer();
02843   if(UI==NULL) return;
02844   G4UIcommandTree * treeTop = UI->GetTree();
02845   
02846   G4int treeSize = treeTop->GetTreeEntry();
02847 
02848   // clear old help tree
02849   fHelpTreeWidget->clear();
02850 
02851   // look for new items
02852 
02853   int tmp = 0;
02854 
02855   QMap<int,QString> commandResultMap;
02856   QMap<int,QString> commandChildResultMap;
02857 
02858   for (int a=0;a<treeSize;a++) {
02859     G4UIcommand* command = treeTop->FindPath(treeTop->GetTree(a+1)->GetPathName().data());
02860     tmp = GetCommandList (command).count(searchText,Qt::CaseInsensitive);
02861     if (tmp >0) {
02862       commandResultMap.insertMulti(tmp,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()));
02863     }
02864     // look for childs
02865     commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a+1),searchText);
02866     // insert new childs
02867     if (!commandChildResultMap.empty()) {
02868       QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
02869       while (i != commandChildResultMap.constEnd()) {
02870         commandResultMap.insertMulti(i.key(),i.value());
02871         i++;
02872       }
02873       commandChildResultMap.clear();
02874     }
02875   }
02876 
02877   // build new help tree
02878   fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
02879   fHelpTreeWidget->setColumnCount(2);
02880   QStringList labels;
02881   labels << QString("Command") << QString("Match");
02882   fHelpTreeWidget->setHeaderLabels(labels);
02883 
02884   if (commandResultMap.empty()) {
02885 #if QT_VERSION < 0x040200
02886     fHelpArea->clear();
02887     fHelpArea->append("No match found");
02888 #else
02889     fHelpArea->setText("No match found");
02890 #endif
02891     return;
02892   }
02893 
02894   QMap<int,QString>::const_iterator i = commandResultMap.constEnd();
02895   i--;
02896   // 10 maximum progress values
02897   float multValue = 10.0/(float)(i.key());
02898   QString progressChar = "|";
02899   QString progressStr = "|";
02900 
02901   QTreeWidgetItem * newItem;
02902   bool end = false;
02903   while (!end) {
02904     if (i == commandResultMap.constBegin()) {
02905       end = true;
02906     }
02907     for(int a=0;a<int(i.key()*multValue);a++) {
02908       progressStr += progressChar;
02909     }
02910     newItem = new QTreeWidgetItem(fHelpTreeWidget);
02911     QString commandStr = i.value().trimmed();
02912 
02913     if (commandStr.indexOf("/") == 0) {
02914       commandStr = commandStr.right(commandStr.size()-1);
02915     }
02916       
02917     newItem->setText(0,commandStr);
02918     newItem->setText(1,progressStr);
02919     
02920 #if QT_VERSION < 0x040200
02921 #else
02922     newItem->setForeground ( 1, QBrush(Qt::blue) );
02923 #endif
02924     progressStr = "|";
02925     i--;
02926   }
02927   fHelpTreeWidget->resizeColumnToContents (0);
02928   fHelpTreeWidget->sortItems(1,Qt::DescendingOrder);
02929   //  fHelpTreeWidget->setColumnWidth(1,10);//resizeColumnToContents (1);
02930 }
02931 
02932 
02933 
02934 
02935 QMap<int,QString> G4UIQt::LookForHelpStringInChildTree(
02936  G4UIcommandTree *aCommandTree
02937 ,const QString & text
02938  )
02939 {
02940   QMap<int,QString> commandResultMap;
02941   if (aCommandTree == NULL) return commandResultMap;
02942   
02943 
02944   // Get the Sub directories
02945   int tmp = 0;
02946   QMap<int,QString> commandChildResultMap;
02947   
02948   for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
02949     const G4UIcommand* command = aCommandTree->GetGuidance();
02950     tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
02951     if (tmp >0) {
02952       commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()));
02953     }
02954     // look for childs
02955     commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text);
02956     
02957     if (!commandChildResultMap.empty()) {
02958       // insert new childs
02959       QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
02960       while (i != commandChildResultMap.constEnd()) {
02961         commandResultMap.insertMulti(i.key(),i.value());
02962         i++;
02963       }
02964       commandChildResultMap.clear();
02965     }
02966   }
02967   // Get the Commands
02968   
02969   for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
02970     const G4UIcommand* command = aCommandTree->GetCommand(a+1);
02971     tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
02972     if (tmp >0) {
02973       commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()));
02974     }
02975     
02976   }
02977   return commandResultMap;
02978 }
02979 
02980   
02981 QString G4UIQt::GetShortCommandPath(
02982 QString commandPath
02983 )
02984 {
02985   if (commandPath.indexOf("/") == 0) {
02986     commandPath = commandPath.right(commandPath.size()-1);
02987   }
02988 
02989   commandPath = commandPath.right(commandPath.size()-commandPath.lastIndexOf("/",-2)-1);
02990  
02991  if (commandPath.lastIndexOf("/") == (commandPath.size()-1)) {
02992     commandPath = commandPath.left(commandPath.size()-1);
02993  }
02994 
02995  return commandPath;
02996 }
02997 
02998 
02999 QString G4UIQt::GetLongCommandPath(
03000  QTreeWidgetItem* item
03001 )
03002 {
03003   if (item == NULL) return "";
03004 
03005   // rebuild path:
03006   QString itemText = "";
03007   itemText = item->text(0);
03008 
03009   while (item->parent() != NULL) {
03010     itemText = item->parent()->text(0)+"/"+itemText;
03011     item = item->parent();
03012   }
03013   itemText = "/"+itemText;
03014   
03015   return itemText;
03016 }
03017 
03018 
03019 void G4UIQt::ChangeColorCallback(QWidget* widget) {
03020   if (widget == NULL) {
03021     return;
03022   }
03023   
03024   QPushButton* button = dynamic_cast<QPushButton*>(widget);
03025   if (button == 0) {
03026     return;
03027   }
03028   QString value = button->accessibleName();
03029 
03030   QColor old;
03031   old.setRgbF(value.section(" ",0,1).toDouble(),
03032               value.section(" ",1,2).toDouble(),
03033               value.section(" ",2,3).toDouble());
03034 #if QT_VERSION < 0x040500
03035   bool a;
03036   QColor color = QColor(QColorDialog::getRgba (old.rgba(),&a,fUITabWidget));
03037 #else
03038   QColor color = QColorDialog::getColor(old,
03039                                         fUITabWidget,
03040                                         "Change color",
03041                                         QColorDialog::ShowAlphaChannel);
03042 #endif
03043 
03044   
03045   if (color.isValid()) {
03046     // rebuild the widget icon
03047     QPixmap pixmap = QPixmap(QSize(16, 16));
03048     pixmap.fill (color);
03049     QPainter painter(&pixmap);
03050     painter.setPen(Qt::black);
03051     painter.drawRect(0,0,15,15); // Draw contour
03052 
03053     button->setAccessibleName(QString::number(color.redF())+" "+
03054                               QString::number(color.greenF())+" "+
03055                               QString::number(color.blueF())+" "
03056                               );
03057     button->setIcon(pixmap);
03058     
03059 
03060   }
03061 }
03062 
03063 
03064 void G4UIQt::ChangeCursorStyle(const QString& action) {
03065 
03066   // Theses actions should be in the app toolbar
03067 
03068   fMoveSelected = true;
03069   fPickSelected = true;
03070   fRotateSelected = true;
03071   fZoomInSelected = true;
03072   fZoomOutSelected = true;
03073   
03074   if (fToolbarApp == NULL) return; 
03075   QList<QAction *> list = fToolbarApp->actions ();
03076   for (int i = 0; i < list.size(); ++i) {
03077     if (list.at(i)->data().toString () == action) {
03078       list.at(i)->setChecked(TRUE);
03079     } else if (list.at(i)->data().toString () == "move") {
03080       fMoveSelected = false;
03081       list.at(i)->setChecked(FALSE);
03082     } else if (list.at(i)->data().toString () == "pick") {
03083       fPickSelected = false;
03084       list.at(i)->setChecked(FALSE);
03085     } else if (list.at(i)->data().toString () == "rotate") {
03086       fRotateSelected = false;
03087       list.at(i)->setChecked(FALSE);
03088     } else if (list.at(i)->data().toString () == "zoom_in") {
03089       fZoomInSelected = false;
03090       list.at(i)->setChecked(FALSE);
03091     } else if (list.at(i)->data().toString () == "zoom_out") {
03092       fZoomOutSelected = false;
03093       list.at(i)->setChecked(FALSE);
03094     }
03095   }
03096   // FIXME : Should connect this to Vis
03097 }
03098 
03099 
03100 /* A little bit like "void G4OpenGLQtViewer::toggleDrawingAction(int aAction)"
03101    But for all viewers, not only Qt
03102 
03103 FIXME : Should be a feedback when changing viewer !
03104 
03105  */
03106 void G4UIQt::ChangeSurfaceStyle(const QString& action) {
03107 
03108   // Theses actions should be in the app toolbar
03109 
03110   if (fToolbarApp == NULL) return; 
03111   QList<QAction *> list = fToolbarApp->actions ();
03112   for (int i = 0; i < list.size(); ++i) {
03113     if (list.at(i)->data().toString () == action) {
03114       list.at(i)->setChecked(TRUE);
03115     } else if (list.at(i)->data().toString () == "hidden_line_removal") {
03116       list.at(i)->setChecked(FALSE);
03117     } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
03118       list.at(i)->setChecked(FALSE);
03119     } else if (list.at(i)->data().toString () == "solid") {
03120       list.at(i)->setChecked(FALSE);
03121     } else if (list.at(i)->data().toString () == "wireframe") {
03122       list.at(i)->setChecked(FALSE);
03123     }
03124   }
03125   // FIXME : Should connect this to Vis
03126 
03127   if (action == "hidden_line_removal") {
03128     G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style w");
03129     G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 1");
03130 
03131   } else if (action == "hidden_line_and_surface_removal") {
03132     G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style s");
03133     G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 1");
03134 
03135   } else if (action == "solid") {
03136     G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style s");
03137     G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 0");
03138 
03139   } else if (action == "wireframe") {
03140     G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style w");
03141     G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 0");
03142   }
03143 }
03144 
03145 
03146 void G4UIQt::OpenIconCallback(const QString& aCommand) {
03147 
03148   QString nomFich = QFileDialog::getOpenFileName(fMainWindow, "Load", "vis", "Macro files (*.mac)");
03149    if (nomFich != "") {
03150      G4UImanager::GetUIpointer()->ApplyCommand((QString(aCommand)+ QString(" ")+ nomFich).toStdString().c_str());
03151    }
03152 }
03153 
03154 
03155 void G4UIQt::SaveIconCallback(const QString& aCommand) {
03156 
03157   QString nomFich = QFileDialog::getSaveFileName(fMainWindow, "Save", "viewerState", "Macro files (*.mac)");
03158   if (nomFich != "") {
03159     G4UImanager::GetUIpointer()->ApplyCommand((QString(aCommand)+ QString(" ")+nomFich).toStdString().c_str());
03160   }
03161 }
03162 
03163 
03164   
03165 void G4UIQt::ChangePerspectiveOrtho(const QString& action) {
03166 
03167   // Theses actions should be in the app toolbar
03168 
03169   if (fToolbarApp == NULL) return; 
03170   QList<QAction *> list = fToolbarApp->actions ();
03171   QString checked = "";
03172   for (int i = 0; i < list.size(); ++i) {
03173     if (list.at(i)->data().toString () == action) {
03174       list.at(i)->setChecked(TRUE);
03175       checked = list.at(i)->data().toString ();
03176     } else if (list.at(i)->data().toString () == "persepective") {
03177       list.at(i)->setChecked(FALSE);
03178     } else if (list.at(i)->data().toString () == "ortho") {
03179       list.at(i)->setChecked(FALSE);
03180     }
03181   }
03182 
03183   if ((action == "ortho") && (checked == "ortho")) {
03184     G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/projection o");
03185   } else if ((action == "perspective") && (checked == "perspective")) {
03186     G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/projection p");
03187   }
03188 }
03189 
03190 
03191 
03192 void G4UIQt::SetIconMoveSelected() {
03193   // Theses actions should be in the app toolbar
03194   fMoveSelected = true;
03195   fRotateSelected = false;
03196   fPickSelected = false;
03197   fZoomInSelected = false;
03198   fZoomOutSelected = false;
03199 
03200   if (fToolbarApp == NULL) return; 
03201   QList<QAction *> list = fToolbarApp->actions ();
03202   for (int i = 0; i < list.size(); ++i) {
03203     if (list.at(i)->data().toString () == "move") {
03204       list.at(i)->setChecked(TRUE);
03205     } else if (list.at(i)->data().toString () == "rotate") {
03206       list.at(i)->setChecked(FALSE);
03207     } else if (list.at(i)->data().toString () == "pick") {
03208       list.at(i)->setChecked(FALSE);
03209     } else if (list.at(i)->data().toString () == "zoom_in") {
03210       list.at(i)->setChecked(FALSE);
03211     } else if (list.at(i)->data().toString () == "zoom_out") {
03212       list.at(i)->setChecked(FALSE);
03213     } 
03214   }
03215 }
03216 
03217 
03218 void G4UIQt::SetIconRotateSelected() {
03219   // Theses actions should be in the app toolbar
03220   fRotateSelected = true;
03221   fMoveSelected = false;
03222   fPickSelected = false;
03223   fZoomInSelected = false;
03224   fZoomOutSelected = false;
03225 
03226   if (fToolbarApp == NULL) return; 
03227   QList<QAction *> list = fToolbarApp->actions ();
03228   for (int i = 0; i < list.size(); ++i) {
03229     if (list.at(i)->data().toString () == "rotate") {
03230       list.at(i)->setChecked(TRUE);
03231     } else if (list.at(i)->data().toString () == "move") {
03232       list.at(i)->setChecked(FALSE);
03233     } else if (list.at(i)->data().toString () == "pick") {
03234       list.at(i)->setChecked(FALSE);
03235     } else if (list.at(i)->data().toString () == "zoom_in") {
03236       list.at(i)->setChecked(FALSE);
03237     } else if (list.at(i)->data().toString () == "zoom_out") {
03238       list.at(i)->setChecked(FALSE);
03239     } 
03240   }
03241 }
03242  
03243 
03244 void G4UIQt::SetIconPickSelected() {
03245   // Theses actions should be in the app toolbar
03246   fPickSelected = true;
03247   fMoveSelected = false;
03248   fRotateSelected = false;
03249   fZoomInSelected = false;
03250   fZoomOutSelected = false;
03251 
03252   if (fToolbarApp == NULL) return; 
03253   QList<QAction *> list = fToolbarApp->actions ();
03254   for (int i = 0; i < list.size(); ++i) {
03255     if (list.at(i)->data().toString () == "pick") {
03256       list.at(i)->setChecked(TRUE);
03257     } else if (list.at(i)->data().toString () == "move") {
03258       list.at(i)->setChecked(FALSE);
03259     } else if (list.at(i)->data().toString () == "rotate") {
03260       list.at(i)->setChecked(FALSE);
03261     } else if (list.at(i)->data().toString () == "zoom_in") {
03262       list.at(i)->setChecked(FALSE);
03263     } else if (list.at(i)->data().toString () == "zoom_out") {
03264       list.at(i)->setChecked(FALSE);
03265     } 
03266   }
03267 }
03268  
03269 
03270 void G4UIQt::SetIconZoomInSelected() {
03271   // Theses actions should be in the app toolbar
03272   fZoomInSelected = true;
03273   fMoveSelected = false;
03274   fRotateSelected = false;
03275   fPickSelected = false;
03276   fZoomOutSelected = false;
03277 
03278   if (fToolbarApp == NULL) return; 
03279   QList<QAction *> list = fToolbarApp->actions ();
03280   for (int i = 0; i < list.size(); ++i) {
03281     if (list.at(i)->data().toString () == "zoom_in") {
03282       list.at(i)->setChecked(TRUE);
03283     } else if (list.at(i)->data().toString () == "move") {
03284       list.at(i)->setChecked(FALSE);
03285     } else if (list.at(i)->data().toString () == "rotate") {
03286       list.at(i)->setChecked(FALSE);
03287     } else if (list.at(i)->data().toString () == "pick") {
03288       list.at(i)->setChecked(FALSE);
03289     } else if (list.at(i)->data().toString () == "zoom_out") {
03290       list.at(i)->setChecked(FALSE);
03291     } 
03292   }
03293 }
03294  
03295 
03296 void G4UIQt::SetIconZoomOutSelected() {
03297   // Theses actions should be in the app toolbar
03298   fZoomOutSelected = true;
03299   fMoveSelected = false;
03300   fRotateSelected = false;
03301   fPickSelected = false;
03302   fZoomInSelected = false;
03303 
03304   if (fToolbarApp == NULL) return; 
03305   QList<QAction *> list = fToolbarApp->actions ();
03306   for (int i = 0; i < list.size(); ++i) {
03307     if (list.at(i)->data().toString () == "zoom_out") {
03308       list.at(i)->setChecked(TRUE);
03309     } else if (list.at(i)->data().toString () == "move") {
03310       list.at(i)->setChecked(FALSE);
03311     } else if (list.at(i)->data().toString () == "rotate") {
03312       list.at(i)->setChecked(FALSE);
03313     } else if (list.at(i)->data().toString () == "pick") {
03314       list.at(i)->setChecked(FALSE);
03315     } else if (list.at(i)->data().toString () == "zoom_in") {
03316       list.at(i)->setChecked(FALSE);
03317     } 
03318   }
03319 }
03320 
03321 
03322 void G4UIQt::SetIconSolidSelected() {
03323   // Theses actions should be in the app toolbar
03324 
03325   if (fToolbarApp == NULL) return; 
03326   QList<QAction *> list = fToolbarApp->actions ();
03327   for (int i = 0; i < list.size(); ++i) {
03328     if (list.at(i)->data().toString () == "solid") {
03329       list.at(i)->setChecked(TRUE);
03330     } else if (list.at(i)->data().toString () == "hidden_line_removal") {
03331       list.at(i)->setChecked(FALSE);
03332     } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
03333       list.at(i)->setChecked(FALSE);
03334     } else if (list.at(i)->data().toString () == "wireframe") {
03335       list.at(i)->setChecked(FALSE);
03336     } 
03337   }
03338 }
03339 
03340 
03341 void G4UIQt::SetIconWireframeSelected() {
03342   // Theses actions should be in the app toolbar
03343 
03344   if (fToolbarApp == NULL) return; 
03345   QList<QAction *> list = fToolbarApp->actions ();
03346   for (int i = 0; i < list.size(); ++i) {
03347     if (list.at(i)->data().toString () == "wireframe") {
03348       list.at(i)->setChecked(TRUE);
03349     } else if (list.at(i)->data().toString () == "hidden_line_removal") {
03350       list.at(i)->setChecked(FALSE);
03351     } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
03352       list.at(i)->setChecked(FALSE);
03353     } else if (list.at(i)->data().toString () == "solid") {
03354       list.at(i)->setChecked(FALSE);
03355     } 
03356   }
03357 }
03358 
03359 
03360 void G4UIQt::SetIconHLRSelected() {
03361   // Theses actions should be in the app toolbar
03362 
03363   if (fToolbarApp == NULL) return; 
03364   QList<QAction *> list = fToolbarApp->actions ();
03365   for (int i = 0; i < list.size(); ++i) {
03366     if (list.at(i)->data().toString () == "hidden_line_removal") {
03367       list.at(i)->setChecked(TRUE);
03368     } else if (list.at(i)->data().toString () == "solid") {
03369       list.at(i)->setChecked(FALSE);
03370     } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
03371       list.at(i)->setChecked(FALSE);
03372     } else if (list.at(i)->data().toString () == "wireframe") {
03373       list.at(i)->setChecked(FALSE);
03374     } 
03375   }
03376 }
03377 
03378 
03379 void G4UIQt::SetIconHLHSRSelected() {
03380   // Theses actions should be in the app toolbar
03381 
03382   if (fToolbarApp == NULL) return; 
03383   QList<QAction *> list = fToolbarApp->actions ();
03384   for (int i = 0; i < list.size(); ++i) {
03385     if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
03386       list.at(i)->setChecked(TRUE);
03387     } else if (list.at(i)->data().toString () == "solid") {
03388       list.at(i)->setChecked(FALSE);
03389     } else if (list.at(i)->data().toString () == "hidden_line_removal") {
03390       list.at(i)->setChecked(FALSE);
03391     } else if (list.at(i)->data().toString () == "wireframe") {
03392       list.at(i)->setChecked(FALSE);
03393     } 
03394   }
03395 }
03396 
03397 
03398 void G4UIQt::SetIconPerspectiveSelected() {
03399   // Theses actions should be in the app toolbar
03400 
03401   if (fToolbarApp == NULL) return; 
03402   QList<QAction *> list = fToolbarApp->actions ();
03403   for (int i = 0; i < list.size(); ++i) {
03404     if (list.at(i)->data().toString () == "perspective") {
03405       list.at(i)->setChecked(TRUE);
03406     } else if (list.at(i)->data().toString () == "ortho") {
03407       list.at(i)->setChecked(FALSE);
03408     } 
03409   }
03410 }
03411 
03412 
03413 
03414 void G4UIQt::SetIconOrthoSelected() {
03415   // Theses actions should be in the app toolbar
03416 
03417   if (fToolbarApp == NULL) return; 
03418   QList<QAction *> list = fToolbarApp->actions ();
03419   for (int i = 0; i < list.size(); ++i) {
03420     if (list.at(i)->data().toString () == "ortho") {
03421       list.at(i)->setChecked(TRUE);
03422     } else if (list.at(i)->data().toString () == "perspective") {
03423       list.at(i)->setChecked(FALSE);
03424     } 
03425   }
03426 }
03427 
03428 
03429 
03430 G4QTabWidget::G4QTabWidget(
03431 QSplitter*& split
03432 ):QTabWidget(split)
03433  ,tabSelected(false)
03434  ,lastCreated(-1)
03435 {
03436 }
03437 
03438 G4QTabWidget::G4QTabWidget(
03439 ):QTabWidget()
03440  ,tabSelected(false)
03441  ,lastCreated(-1)
03442 {
03443 }
03444 
03445 
03446   
03447 #if QT_VERSION < 0x040500
03448 void G4UIQt::TabCloseCallback(int){
03449 #else
03450 void G4UIQt::TabCloseCallback(int a){
03451 #endif
03452 #if QT_VERSION < 0x040500
03453 #else
03454   QWidget* temp = fViewerTabWidget->widget(a);
03455   fViewerTabWidget->removeTab (a);
03456 
03457   delete temp;
03458 
03459   if (fViewerTabWidget->count() == 0) {
03460     if (fEmptyViewerTabLabel == NULL) {
03461       fEmptyViewerTabLabel = new QLabel("         If you want to have a Viewer, please use /vis/open commands. ");
03462     }
03463 
03464   // fill right splitter
03465     fRightSplitterWidget->insertWidget(0,fEmptyViewerTabLabel);
03466 
03467     fMainSplitterWidget->show();
03468     fEmptyViewerTabLabel->show();
03469     fViewerTabWidget->setParent(0);
03470     fViewerTabWidget->setVisible(false);
03471     delete fViewerTabWidget;
03472     fViewerTabWidget = NULL;
03473   }
03474 #endif
03475 }
03476 
03477 
03478 void G4UIQt::ToolBoxActivated(int a){
03479   
03480   if (fUITabWidget->widget(a) == fHelpTBWidget) {
03481     // Rebuild the help tree
03482     FillHelpTree();
03483   } else if (fUITabWidget->widget(a) == fSceneTreeComponentsTBWidget) {
03484 #if QT_VERSION < 0x040200
03485     fSceneTreeComponentsTBWidget->show();
03486 #else
03487     fSceneTreeComponentsTBWidget->setVisible(true);
03488 #endif
03489   }
03490 }
03491 
03492 
03493 void G4QTabWidget::paintEvent(
03494 QPaintEvent *
03495 )
03496 {
03497 
03498   if (currentWidget()) {
03499 
03500     if ( isTabSelected()) {
03501 
03502       QCoreApplication::sendPostedEvents () ;
03503 
03504 #ifdef G4DEBUG_INTERFACES_BASIC
03505       printf("G4QTabWidget::paintEvent OK\n");
03506 #endif
03507       QString text = tabText (currentIndex()); 
03508 
03509       if (lastCreated == -1) {
03510         QString paramSelect = QString("/vis/viewer/select ")+text;
03511         G4UImanager* UI = G4UImanager::GetUIpointer();
03512         if(UI != NULL)  {
03513           UI->ApplyCommand(paramSelect.toStdString().c_str());
03514         }
03515       } else {
03516         lastCreated = -1;
03517       }
03518       setTabSelected(false);
03519     }
03520   }
03521 }
03522 
03523 #endif

Generated on Mon May 27 17:50:06 2013 for Geant4 by  doxygen 1.4.7