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

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

r597@mac-90108: laurentgarnier | 2007-09-18 14:20:01 +0200
correction du ticket #71 par le codage de la fonction FlushAndWaitExecution

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