source: trunk/geant4/interfaces/basic/src/G4UIQt.cc @ 528

Last change on this file since 528 was 528, checked in by garnier, 17 years ago

r657@mac-90108: laurentgarnier | 2007-06-22 16:32:25 +0200
desormais la premiere fleche tapee dans la commandArea selectionne le dernier item

  • Property svn:mime-type set to text/cpp
File size: 22.9 KB
RevLine 
[481]1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26//
[484]27// $Id: G4UIQt.cc,v 1.14 2007/05/29 11:09:49 $
[481]28// GEANT4 tag $Name: geant4-08-01 $
29//
[484]30// L. Garnier
[481]31
32//#define DEBUG
33
34#ifdef G4UI_BUILD_QT_SESSION
35
36#include "G4Types.hh"
37
38#include <string.h>
39
40#include "G4UIQt.hh"
41#include "G4UImanager.hh"
42#include "G4StateManager.hh"
43#include "G4UIcommandTree.hh"
44#include "G4UIcommandStatus.hh"
45
46#include "G4Qt.hh"
47
48#include <QtGui/qapplication.h>
49#include <QtGui/qwidget.h>
[487]50#include <QtGui/qmenu.h>
51#include <QtGui/qmenubar.h>
52#include <QtGui/qboxlayout.h>
[488]53#include <QtGui/qpushbutton.h>
54#include <QtGui/qlabel.h>
[495]55#include <QtGui/qsplitter.h>
[500]56#include <QtGui/qscrollbar.h>
[506]57#include <QtGui/qdialog.h>
[518]58#include <QtGui/qevent.h>
[481]59
60#include <stdlib.h>
61
[513]62// Pourquoi Static et non  variables de classe ?
[481]63static G4bool exitSession = true;
64static G4bool exitPause = true;
[524]65
66/**   Build a Qt window with a menubar, output area and promt area<br>
67<pre>
68   +-----------------------+
69   |exit menu|             |
70   |                       |
71   | +-------------------+ |
72   | |                   | |
73   | |  Output area      | |
74   | |                   | |
75   | +-------------------+ |
76   |      | clear |        |
77   | +-------------------+ |
78   | |  promt history    | |
79   | +-------------------+ |
80   | +-------------------+ |
81   | |> promt area       | |
82   | +-------------------+ |
83   +-----------------------+
84</pre>
[481]85*/
86G4UIQt::G4UIQt (
[527]87 int argc
88,char** argv
89)
[513]90  :fHelpDialog(NULL)
[481]91{
[496]92  G4Qt* interactorManager = G4Qt::getInstance ();
[505]93  G4UImanager* UI = G4UImanager::GetUIpointer();
94  if(UI!=NULL) UI->SetSession(this);
[481]95
[494]96  fMainWindow = new QMainWindow();
97  fMainWindow->setWindowTitle( "G4UI Session" );
[500]98  fMainWindow->resize(800,600);
[523]99  fMainWindow->move(QPoint(200,100));
[496]100
[498]101  QSplitter *splitter = new QSplitter(Qt::Vertical);
102  fTextArea = new QTextEdit();
[490]103  QPushButton *clearButton = new QPushButton("clear");
[526]104  connect(clearButton, SIGNAL(clicked()), SLOT(ClearButtonCallback()));
[498]105
[519]106  fCommandHistoryArea = new QListWidget();
107  fCommandHistoryArea->setSelectionMode(QAbstractItemView::SingleSelection);
[526]108  connect(fCommandHistoryArea, SIGNAL(itemSelectionChanged()), SLOT(CommandHistoryCallback()));
[523]109  fCommandHistoryArea->installEventFilter(this);
[498]110  fCommandLabel = new QLabel();
111
[518]112  fCommandArea = new QLineEdit();
113  fCommandArea->installEventFilter(this);
[500]114  fCommandArea->activateWindow();
[526]115  connect(fCommandArea, SIGNAL(returnPressed()), SLOT(CommandEnteredCallback()));
[522]116  //  fCommandArea->setFocusPolicy ( Qt::StrongFocus );
117  //  fCommandArea->setFocus(Qt::TabFocusReason);
[498]118  fTextArea->setReadOnly(true);
119
[505]120
121  // Set layouts
[497]122
[498]123  QWidget* topWidget = new QWidget();
124  QVBoxLayout *layoutTop = new QVBoxLayout;
[481]125
[498]126  QWidget* bottomWidget = new QWidget();
127  QVBoxLayout *layoutBottom = new QVBoxLayout;
[494]128
[490]129
[498]130  layoutTop->addWidget(fTextArea);
131  layoutTop->addWidget(clearButton);
132  topWidget->setLayout(layoutTop);
[494]133
[498]134  layoutBottom->addWidget(fCommandHistoryArea);
135  layoutBottom->addWidget(fCommandLabel);
136  layoutBottom->addWidget(fCommandArea);
137  bottomWidget->setLayout(layoutBottom);
[490]138
[495]139
[522]140  splitter->addWidget(topWidget);
141  splitter->addWidget(bottomWidget);
[498]142  fMainWindow->setCentralWidget(splitter);
[495]143
[513]144  // Add a quit subMenu
[504]145  QMenu *fileMenu = fMainWindow->menuBar()->addMenu("File");
[503]146  fileMenu->addAction("Quitter", fMainWindow, SLOT(close()));
[496]147
[513]148  // Add a Help menu
149  QMenu *helpMenu = fMainWindow->menuBar()->addMenu("Help");
[526]150  helpMenu->addAction("Show Help", this, SLOT(ShowHelpCallback()));
[513]151
[505]152  // Set the splitter size. The fTextArea sould be 2/3 on the fMainWindow
153  QList<int> vals = splitter->sizes();
154  if(vals.size()==2) {
155    vals[0] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*3/4;
156    vals[1] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*1/4;
157    splitter->setSizes(vals);
158  }
[481]159
160
[484]161  if(UI!=NULL) UI->SetCoutDestination(this);  // TO KEEP
[481]162}
[524]163
164
165
[481]166G4UIQt::~G4UIQt(
167)
168{
[484]169  G4UImanager* UI = G4UImanager::GetUIpointer();  // TO KEEP
170  if(UI!=NULL) {  // TO KEEP
171    UI->SetSession(NULL);  // TO KEEP
172    UI->SetCoutDestination(NULL);  // TO KEEP
[481]173  }
[484]174
175 
[494]176  if (fMainWindow!=NULL)
177    delete fMainWindow;
[481]178}
[524]179
180
181
182
183/**   Start the Qt main loop
184*/
[481]185G4UIsession* G4UIQt::SessionStart (
186)
187{
[484]188
[496]189  G4Qt* interactorManager = G4Qt::getInstance ();
[494]190  fMainWindow->show();
191  Prompt("session");
192  exitSession = false;
[481]193
[496]194
195  printf("disable secondary loop\n");
196  interactorManager->DisableSecondaryLoop (); // TO KEEP
197  ((QApplication*)interactorManager->GetMainInteractor())->exec();
198  // on ne passe pas le dessous ? FIXME ????
[506]199  // je ne pense pas 13/06
[496]200
[524]201  //   void* event; // TO KEEP
202  //   while((event = interactorManager->GetEvent())!=NULL) {  // TO KEEP
203  //     interactorManager->DispatchEvent(event); // TO KEEP
204  //     if(exitSession==true) break; // TO KEEP
205  //   } // TO KEEP
[506]206
207  interactorManager->EnableSecondaryLoop ();
[496]208  printf("enable secondary loop\n");
[506]209  return this;
[481]210}
[494]211
[524]212
213/**   Display the prompt in the prompt area
214   @param aPrompt : string to display as the promt label
215   //FIXME : probablement inutile puisque le seul a afficher qq chose d'autre
216   que "session" est SecondaryLoop()
217*/
[481]218void G4UIQt::Prompt (
219 G4String aPrompt
220)
221{
[527]222  if (!aPrompt) return;
[526]223
[500]224  fCommandLabel->setText((char*)aPrompt.data());
[481]225}
[524]226
227
[481]228void G4UIQt::SessionTerminate (
229)
230{
[505]231  G4Qt* interactorManager = G4Qt::getInstance ();
232  fMainWindow->close();
233  ((QApplication*)interactorManager->GetMainInteractor())->exit();
[481]234}
[524]235
236
237
238/**
239   Called by intercoms/src/G4UImanager.cc<br>
240   Called by visualization/management/src/G4VisCommands.cc with "EndOfEvent" argument<br>
241   It have to pause the session command terminal.<br>
242   Call SecondaryLoop to wait for exit event<br>
243   @param aState
244   @see : G4VisCommandReviewKeptEvents::SetNewValue
245*/
[481]246void G4UIQt::PauseSessionStart (
[524]247 G4String aState
[481]248)
249{
[527]250  if (!aState) return;
[526]251
[501]252  printf("G4UIQt::PauseSessionStart\n");
[524]253  if(aState=="G4_pause> ") {  // TO KEEP
[484]254    SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP
255  } // TO KEEP
[481]256
[524]257  if(aState=="EndOfEvent") { // TO KEEP
[481]258    // Picking with feed back in event data Done here !!!
[484]259    SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP
260  } // TO KEEP
[481]261}
[524]262
263
264
265/**
266   Begin the secondary loop
267   @param a_prompt : label to display as the prompt label
268 */
[484]269void G4UIQt::SecondaryLoop (
[524]270 G4String aPrompt
[481]271)
272{
[527]273  if (!aPrompt) return;
[526]274
[501]275  printf("G4UIQt::SecondaryLoop\n");
[484]276  G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ?
[524]277  Prompt(aPrompt); // TO KEEP
[484]278  exitPause = false; // TO KEEP
279  void* event; // TO KEEP
280  while((event = interactorManager->GetEvent())!=NULL) {  // TO KEEP
281    interactorManager->DispatchEvent(event); // TO KEEP
282    if(exitPause==true) break; // TO KEEP
283  } // TO KEEP
284  Prompt("session"); // TO KEEP
[481]285}
[524]286
287
288
[481]289/**
[524]290   Receive a cout from Geant4. We have to display it in the cout zone
291   @param aString : label to add in the display area
[526]292   @return 0
[524]293*/
[484]294G4int G4UIQt::ReceiveG4cout (
[524]295 G4String aString
[481]296)
297{
[527]298  if (!aString) return 0;
[526]299
[524]300  fTextArea->append(QString((char*)aString.data()).trimmed());
[500]301  fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum());
[495]302  return 0;
[481]303}
[524]304
305
[481]306/**
[524]307   Receive a cerr from Geant4. We have to display it in the cout zone
308   @param aString : label to add in the display area
[526]309   @return 0
[524]310*/
[484]311G4int G4UIQt::ReceiveG4cerr (
[524]312 G4String aString
[481]313)
314{
[527]315  if (!aString) return 0;
[526]316
[500]317  QColor previousColor = fTextArea->textColor();
318  fTextArea->setTextColor(Qt::red);
[524]319  fTextArea->append(QString((char*)aString.data()).trimmed());
[500]320  fTextArea->setTextColor(previousColor);
[501]321  fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum());
[495]322  return 0;
[481]323}
[501]324
[524]325
326
327/**
328   Add a new menu to the menu bar
329   @param aName name of menu
330   @param aLabel label to display
331 */
[484]332void G4UIQt::AddMenu (
[524]333 const char* aName
334,const char* aLabel
[481]335)
336{
[526]337  if (aName == NULL) return;
338  if (aLabel == NULL) return;
339
[524]340  QMenu *fileMenu = new QMenu(aLabel);
[513]341  fMainWindow->menuBar()->insertMenu(fMainWindow->menuBar()->actions().last(),fileMenu);
[524]342  AddInteractor (aName,(G4Interactor)fileMenu);
[481]343}
[524]344
345
346/**
347   Add a new button to a menu
348   @param aMenu : parent menu
349   @param aLabel : label to display
350   @param aCommand : command to execute as a callback
351 */
[484]352void G4UIQt::AddButton (
[524]353 const char* aMenu
354,const char* aLabel
355,const char* aCommand
[481]356)
357{
[524]358  if(aMenu==NULL) return; // TO KEEP
359  if(aLabel==NULL) return; // TO KEEP
360  if(aCommand==NULL) return; // TO KEEP
[526]361
[524]362  QMenu *parent = (QMenu*)GetInteractor(aMenu);
[504]363  if(parent==NULL) return;
364 
[526]365  QSignalMapper *signalMapper = new QSignalMapper(this);
[524]366  QAction *action = parent->addAction(aLabel, signalMapper, SLOT(map()));
367  signalMapper->setMapping(action, QString(aCommand));
[526]368  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&)));
[491]369}
[504]370
371
372
[513]373
374/**
[524]375   Open the help dialog in a separate window.<br>
376   This will be display as a tree widget.<br>
377   Implementation of <b>void G4VBasicShell::TerminalHelp(G4String newCommand)</b>
[506]378
[524]379   @param newCommand : open the tree widget item on this command if is set
380*/
381void G4UIQt::TerminalHelp(
382 G4String newCommand
383)
[506]384{
[524]385  // Create the help dialog
[514]386  if (!fHelpDialog) {
387    fHelpDialog = new QDialog;
[506]388
[514]389    QSplitter *splitter = new QSplitter(Qt::Horizontal);
390    fHelpArea = new QTextEdit();
391    QPushButton *exitButton = new QPushButton("Exit");
392    connect(exitButton, SIGNAL(clicked()), fHelpDialog,SLOT(close()));
393    fHelpArea->setReadOnly(true);
[506]394
[514]395    // the help tree
396    G4UImanager* UI = G4UImanager::GetUIpointer();
397    if(UI==NULL) return;
398    G4UIcommandTree * treeTop = UI->GetTree();
[507]399
[514]400    // build widget
401    fHelpTreeWidget = new QTreeWidget();
[515]402    fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
[514]403    fHelpTreeWidget->setColumnCount(2);
404    fHelpTreeWidget->setColumnHidden(1,true);
405    QStringList labels;
406    labels << QString("Command") << QString("Description");
407    fHelpTreeWidget->setHeaderLabels(labels);
408
409    QList<QTreeWidgetItem *> items;
410    G4int treeSize = treeTop->GetTreeEntry();
411    QTreeWidgetItem * newItem;
412    for (int a=0;a<treeSize;a++) {
413      // Creating new item
414      QStringList stringList;
415      stringList << QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed()  ;
416      stringList << QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).trimmed()  ;
417
418      newItem = new QTreeWidgetItem(stringList);
419
420      // look for childs
421      CreateChildTree(newItem,treeTop->GetTree(a+1));
422      items.append(newItem);
423    }
424    fHelpTreeWidget->insertTopLevelItems(0, items);
425
[526]426    connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeCallback())); 
[514]427
428    // Set layouts
429
430    QVBoxLayout *vLayout = new QVBoxLayout;
431
[522]432    splitter->addWidget(fHelpTreeWidget);
433    splitter->addWidget(fHelpArea);
[514]434
435    vLayout->addWidget(splitter);
436    vLayout->addWidget(exitButton);
437    fHelpDialog->setLayout(vLayout);
438
439  }
440
[513]441  // Look for the choosen command "newCommand"
442  size_t i = newCommand.index(" ");
[514]443  G4String targetCom="";
[513]444  if( i != std::string::npos )
[524]445    {
446      G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
447      newValue.strip(G4String::both);
448      targetCom = ModifyToFullPathCommand( newValue );
449    }
[514]450  if (targetCom != "") {
[524]451    QTreeWidgetItem* findItem = NULL;
452    for (int a=0;a<fHelpTreeWidget->topLevelItemCount();a++) {
453      if (!findItem) {
454        findItem = FindTreeItem(fHelpTreeWidget->topLevelItem(a),QString((char*)targetCom.data()));
455      }
[514]456    }
[525]457   
[524]458    if (findItem) {     
[525]459     
[515]460      //collapsed open item
461      QList<QTreeWidgetItem *> selected;
462      selected = fHelpTreeWidget->selectedItems();
463      if ( selected.count() != 0 ) {
[524]464        QTreeWidgetItem * tmp =selected.at( 0 );
465        while ( tmp) {
466          tmp->setExpanded(false);
[525]467          tmp = tmp->parent();
[524]468        }
[514]469      }
[515]470     
[525]471      // clear old selection
472      fHelpTreeWidget->clearSelection();
473
[524]474      // set new selection
475      findItem->setSelected(true);
[515]476     
[524]477      // expand parent item
478      while ( findItem) {
479        findItem->setExpanded(true);
480        findItem = findItem->parent();
481      }
482
[514]483      // Call the update of the right textArea
[526]484      HelpTreeCallback();
[514]485    }
[524]486  }
[515]487  fHelpDialog->setWindowTitle("Help on commands");
[513]488  fHelpDialog->resize(800,600);
489  fHelpDialog->move(QPoint(400,150));
490  fHelpDialog->show();
491  fHelpDialog->raise();
492  fHelpDialog->activateWindow();
[514]493}
[506]494
[507]495
[506]496
[526]497/**   Fill the Help Tree Widget
[524]498   @param aParent : parent item to fill
499   @param aCommandTree : commandTree node associate with this part of the Tree
500*/
501void G4UIQt::CreateChildTree(
502 QTreeWidgetItem *aParent
503,G4UIcommandTree *aCommandTree
504)
505{
[526]506  if (aParent == NULL) return;
507  if (aCommandTree == NULL) return;
[514]508
[526]509
[507]510  // Creating new item
511  QTreeWidgetItem * newItem;
[506]512
[508]513  // Get the Sub directories
[524]514  for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
[526]515
[507]516    QStringList stringList;
[524]517    stringList << QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed()  ;
518    stringList << QString((char*)(aCommandTree->GetTree(a+1)->GetTitle()).data()).trimmed()  ;
[507]519    newItem = new QTreeWidgetItem(stringList);
[508]520
[524]521    CreateChildTree(newItem,aCommandTree->GetTree(a+1));
522    aParent->addChild(newItem);
[507]523  }
[506]524
[508]525
526
527  // Get the Commands
528
[524]529  for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
[508]530   
531    QStringList stringList;
[524]532    stringList << QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed()  ;
533    stringList << QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed()  ;
[508]534    newItem = new QTreeWidgetItem(stringList);
[509]535     
[524]536    aParent->addChild(newItem);
[514]537    newItem->setExpanded(false);
[508]538  }
[507]539}
[509]540
[512]541
[526]542/** Find a treeItemWidget in the help tree
543    @param aCommand item's String to look for
544    @return item if found, NULL if not
[524]545*/
546QTreeWidgetItem* G4UIQt::FindTreeItem(
547 QTreeWidgetItem *aParent
[527]548,const QString& aCommand
[524]549)
550{
[526]551  if (aParent == NULL) return NULL;
552
[524]553  if (aParent->text(0) == aCommand)
554    return aParent;
555 
556  QTreeWidgetItem * tmp = NULL;
557  for (int a=0;a<aParent->childCount();a++) {
558    if (!tmp)
559      tmp = FindTreeItem(aParent->child(a),aCommand);
560  }
561  return tmp;
562}
[511]563
[524]564
[527]565/**   Build the command list parameters in a QString<br>
[524]566   Reimplement partialy the G4UIparameter.cc
567   @param aCommand : command to list parameters
568   @see G4UIparameter::List()
[526]569   @see G4UIcommand::List()
570   @return the command list parameters, or "" if nothing
[524]571*/
[509]572QString G4UIQt::GetCommandList (
[527]573 const G4UIcommand *aCommand
[509]574)
575{
[510]576
[526]577  QString txt ="";
578  if (aCommand == NULL)
579    return txt;
580
[524]581  G4String commandPath = aCommand->GetCommandPath();
582  G4String rangeString = aCommand->GetRange();
583  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
584  G4int n_parameterEntry = aCommand->GetParameterEntries();
[526]585 
586  if ((commandPath == "") &&
587      (rangeString == "") &&
588      (n_guidanceEntry == 0) &&
589      (n_parameterEntry == 0)) {
590    return txt;
591  }
[511]592
[526]593  if((commandPath.length()-1)!='/') {
594    txt += "Command " + QString((char*)(commandPath).data()) + "\n";
595  }
596  txt += "Guidance :\n";
597 
598  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
599    txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
600  }
601  if( ! rangeString.isNull() ) {
602    txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n";
603  }
604  if( n_parameterEntry > 0 ) {
605    G4UIparameter *param;
606   
607    // Re-implementation of G4UIparameter.cc
608   
609    for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
610      param = aCommand->GetParameter(i_thParameter);
611      txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
612      if( ! param->GetParameterGuidance().isNull() )
613        txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
614      txt += " Parameter type  : " + QString(param->GetParameterType())+ "\n";
615      if(param->IsOmittable()){
616        txt += " Omittable       : True\n";
617      } else {
618        txt += " Omittable       : False\n";
619      }
620      if( param->GetCurrentAsDefault() ) {
621        txt += " Default value   : taken from the current value\n";
622      } else if( ! param->GetDefaultValue().isNull() ) {
623        txt += " Default value   : " + QString((char*)(param->GetDefaultValue()).data())+ "\n";
624      }
625      if( ! param->GetParameterRange().isNull() ) {
626        txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
627      }
628      if( ! param->GetParameterCandidates().isNull() ) {
629        txt += " Candidates      : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
630      }
[511]631    }
[526]632  }
[509]633  return txt;
634}
[513]635
[514]636
637
[527]638/**  Implement G4VBasicShell vurtual function
[524]639 */
[517]640G4bool G4UIQt::GetHelpChoice(
641 G4int& aInt
642)
643{
644  printf("G4UIQt::GetHelpChoice SHOULD NEVER GO HERE");
[519]645  return true;
[517]646}
[519]647
[524]648
[527]649/**   Implement G4VBasicShell vurtual function
[524]650*/
[517]651void G4UIQt::ExitHelp(
652)
653{
654  printf("G4UIQt::ExitHelp SHOULD NEVER GO HERE");
655}
[514]656
657
[527]658/**   Event filter method. Every event from QtApplication goes here.<br/>
[524]659   We apply a filter only for the Up and Down Arrow press when the QLineEdit<br/>
660   is active. If this filter match, Up arrow we give the previous command<br/>
661   and Down arrow will give the next if exist.<br/>
662   @param obj Emitter of the event
663   @param event Kind of event
[518]664*/
[528]665bool G4UIQt::eventFilter( // Should stay with a minuscule eventFilter because of Qt
[526]666 QObject *aObj
667,QEvent *aEvent
668)
[518]669{
[526]670  if (aObj == NULL) return false;
671  if (aEvent == NULL) return false;
672
673  if (aObj == fCommandHistoryArea) {
674    if (aEvent->type() == QEvent::KeyPress) {
[523]675      fCommandArea->setFocus();
676    }
677  }
[526]678  if (aObj == fCommandArea) {
679    if (aEvent->type() == QEvent::KeyPress) {
680      QKeyEvent *e = static_cast<QKeyEvent*>(aEvent);
[519]681      if ((e->key() == (Qt::Key_Down)) ||
682          (e->key() == (Qt::Key_PageDown)) ||
683          (e->key() == (Qt::Key_Up)) ||
684          (e->key() == (Qt::Key_PageUp))) {
685        int selection = fCommandHistoryArea->currentRow();
686        if (fCommandHistoryArea->count()) {
687          if (selection == -1) {
688            selection = fCommandHistoryArea->count()-1;
[528]689          } else {
690            if (e->key() == (Qt::Key_Down)) {
691              if (selection <(fCommandHistoryArea->count()-1))
692                selection++;
693            } else if (e->key() == (Qt::Key_PageDown)) {
694              selection = fCommandHistoryArea->count()-1;
695            } else if (e->key() == (Qt::Key_Up)) {
696              if (selection >0)
697                selection --;
698            } else if (e->key() == (Qt::Key_PageUp)) {
699              selection = 0;
700            }
[519]701          }
702          fCommandHistoryArea->clearSelection();
703          fCommandHistoryArea->item(selection)->setSelected(true);
[520]704          fCommandHistoryArea->setCurrentItem(fCommandHistoryArea->item(selection));
[519]705        }
[518]706      }
707    }
708  }
709  // pass the event on to the parent class
[526]710  return QObject::eventFilter(aObj, aEvent);
[518]711}
712
713
714
715
716/***************************************************************************/
[514]717//
718//             SLOTS DEFINITIONS
719//
720/***************************************************************************/
721
[527]722/**   Called when user give "help" command.
[524]723*/
[526]724void G4UIQt::ShowHelpCallback (
[514]725)
726{
[513]727  TerminalHelp("");
728}
729
[524]730
[527]731/**   Called when user click on clear button. Clear the text Output area
[524]732*/
[526]733void G4UIQt::ClearButtonCallback (
[514]734)
735{
736  fTextArea->clear();
737}
738
739
[527]740/**   Callback call when "click on a menu entry.<br>
[524]741   Send the associated command to geant4
742*/
[526]743void G4UIQt::CommandEnteredCallback (
[514]744)
745{
746  G4String command (fCommandArea->text().toStdString().c_str());
[522]747  if (fCommandArea->text().trimmed() != "") {
[519]748    fCommandHistoryArea->addItem(fCommandArea->text());
[520]749    fCommandHistoryArea->clearSelection();
750    fCommandHistoryArea->item(fCommandHistoryArea->count()-1)->setSelected(true);
751    fCommandHistoryArea->setCurrentItem(fCommandHistoryArea->item(fCommandHistoryArea->count()-1));
[514]752
753    if (command(0,4) != "help") {
[524]754      ApplyShellCommand (command,exitSession,exitPause);
[514]755    } else {
756      TerminalHelp(command);
757    }
758    if(exitSession==true)
759      SessionTerminate();
760  }
761  fCommandArea->setText("");
762}
763
[524]764
[527]765/**   Callback call when "enter" clicked on the command zone.<br>
[524]766   Send the command to geant4
767   @param aCommand
768*/
[526]769void G4UIQt::ButtonCallback (
[524]770 const QString& aCommand
[514]771)
772{
[524]773  G4String ss = G4String(aCommand.toStdString().c_str());
[514]774  ApplyShellCommand(ss,exitSession,exitPause);
775  if(exitSession==true)
776    SessionTerminate();
777}
[524]778
779
780
[527]781/**   This callback is activated when user selected a item in the help tree
[524]782*/
[526]783void G4UIQt::HelpTreeCallback (
[514]784)
785{
786  QTreeWidgetItem* item =  NULL;
787  if (!fHelpTreeWidget)
788    return ;
789
790  if (!fHelpArea)
791    return;
792 
[515]793  QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
794  if (list.isEmpty())
795    return;
796  item = list.first();
[514]797  if (!item)
798    return;
799 
800  G4UImanager* UI = G4UImanager::GetUIpointer();
801  if(UI==NULL) return;
802  G4UIcommandTree * treeTop = UI->GetTree();
803  G4UIcommand* command = treeTop->FindPath(item->text (1).toStdString().c_str());
804  if (command) {
805    fHelpArea->setText(GetCommandList(command));
806  } else {
807    // this is not a command, this is a sub directory
808    // We display the Title
809    fHelpArea->setText(item->text (1).toStdString().c_str());
810  }
811}
812
813
[527]814/**   Callback called when user select an old command in the command history<br>
[524]815   Give it to the command area.
816*/
[526]817void G4UIQt::CommandHistoryCallback(
[519]818)
819{
820  QListWidgetItem* item =  NULL;
821  if (!fCommandHistoryArea)
822    return ;
823
824 
825  QList<QListWidgetItem *> list =fCommandHistoryArea->selectedItems();
826  if (list.isEmpty())
827    return;
828  item = list.first();
829  if (!item)
830    return;
831  fCommandArea->setText(item->text());
832
833}
834
[513]835#endif
Note: See TracBrowser for help on using the repository browser.