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

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

r652@mac-90108: laurentgarnier | 2007-06-22 12:43:09 +0200
en test

  • Property svn:mime-type set to text/cpp
File size: 22.6 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(200,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 
176  if (fMainWindow!=NULL)
177    delete fMainWindow;
178}
179
180
181
182
183/**   Start the Qt main loop
184*/
185G4UIsession* G4UIQt::SessionStart (
186)
187{
188
189  G4Qt* interactorManager = G4Qt::getInstance ();
190  fMainWindow->show();
191  Prompt("session");
192  exitSession = false;
193
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 ????
199  // je ne pense pas 13/06
200
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
206
207  interactorManager->EnableSecondaryLoop ();
208  printf("enable secondary loop\n");
209  return this;
210}
211
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*/
218void G4UIQt::Prompt (
219 G4String aPrompt
220)
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  printf("G4UIQt::PauseSessionStart\n");
249  if(aState=="G4_pause> ") {  // TO KEEP
250    SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP
251  } // TO KEEP
252
253  if(aState=="EndOfEvent") { // TO KEEP
254    // Picking with feed back in event data Done here !!!
255    SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP
256  } // TO KEEP
257}
258
259
260
261/**
262   Begin the secondary loop
263   @param a_prompt : label to display as the prompt label
264 */
265void G4UIQt::SecondaryLoop (
266 G4String aPrompt
267)
268{
269  printf("G4UIQt::SecondaryLoop\n");
270  G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ?
271  Prompt(aPrompt); // TO KEEP
272  exitPause = false; // TO KEEP
273  void* event; // TO KEEP
274  while((event = interactorManager->GetEvent())!=NULL) {  // TO KEEP
275    interactorManager->DispatchEvent(event); // TO KEEP
276    if(exitPause==true) break; // TO KEEP
277  } // TO KEEP
278  Prompt("session"); // TO KEEP
279}
280
281
282
283/**
284   Receive a cout from Geant4. We have to display it in the cout zone
285   @param aString : label to add in the display area
286*/
287G4int G4UIQt::ReceiveG4cout (
288 G4String aString
289)
290{
291  fTextArea->append(QString((char*)aString.data()).trimmed());
292  fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum());
293  return 0;
294}
295
296
297/**
298   Receive a cerr from Geant4. We have to display it in the cout zone
299   @param aString : label to add in the display area
300*/
301G4int G4UIQt::ReceiveG4cerr (
302 G4String aString
303)
304{
305  QColor previousColor = fTextArea->textColor();
306  fTextArea->setTextColor(Qt::red);
307  fTextArea->append(QString((char*)aString.data()).trimmed());
308  fTextArea->setTextColor(previousColor);
309  fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum());
310  return 0;
311}
312
313
314
315/**
316   Add a new menu to the menu bar
317   @param aName name of menu
318   @param aLabel label to display
319 */
320void G4UIQt::AddMenu (
321 const char* aName
322,const char* aLabel
323)
324{
325  QMenu *fileMenu = new QMenu(aLabel);
326  fMainWindow->menuBar()->insertMenu(fMainWindow->menuBar()->actions().last(),fileMenu);
327  AddInteractor (aName,(G4Interactor)fileMenu);
328}
329
330
331/**
332   Add a new button to a menu
333   @param aMenu : parent menu
334   @param aLabel : label to display
335   @param aCommand : command to execute as a callback
336 */
337void G4UIQt::AddButton (
338 const char* aMenu
339,const char* aLabel
340,const char* aCommand
341)
342{
343  if(aMenu==NULL) return; // TO KEEP
344  if(aLabel==NULL) return; // TO KEEP
345  if(aCommand==NULL) return; // TO KEEP
346  QMenu *parent = (QMenu*)GetInteractor(aMenu);
347  if(parent==NULL) return;
348 
349  signalMapper = new QSignalMapper(this);
350  QAction *action = parent->addAction(aLabel, signalMapper, SLOT(map()));
351  signalMapper->setMapping(action, QString(aCommand));
352  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(buttonCallback(const QString&)));
353}
354
355
356
357
358/**
359   Open the help dialog in a separate window.<br>
360   This will be display as a tree widget.<br>
361   Implementation of <b>void G4VBasicShell::TerminalHelp(G4String newCommand)</b>
362
363   @param newCommand : open the tree widget item on this command if is set
364*/
365void G4UIQt::TerminalHelp(
366 G4String newCommand
367)
368{
369  // Create the help dialog
370  if (!fHelpDialog) {
371    fHelpDialog = new QDialog;
372
373    QSplitter *splitter = new QSplitter(Qt::Horizontal);
374    fHelpArea = new QTextEdit();
375    QPushButton *exitButton = new QPushButton("Exit");
376    connect(exitButton, SIGNAL(clicked()), fHelpDialog,SLOT(close()));
377    fHelpArea->setReadOnly(true);
378
379    // the help tree
380    G4UImanager* UI = G4UImanager::GetUIpointer();
381    if(UI==NULL) return;
382    G4UIcommandTree * treeTop = UI->GetTree();
383
384    // build widget
385    fHelpTreeWidget = new QTreeWidget();
386    fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
387    fHelpTreeWidget->setColumnCount(2);
388    fHelpTreeWidget->setColumnHidden(1,true);
389    QStringList labels;
390    labels << QString("Command") << QString("Description");
391    fHelpTreeWidget->setHeaderLabels(labels);
392
393    QList<QTreeWidgetItem *> items;
394    G4int treeSize = treeTop->GetTreeEntry();
395    QTreeWidgetItem * newItem;
396    for (int a=0;a<treeSize;a++) {
397      // Creating new item
398      QStringList stringList;
399      stringList << QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed()  ;
400      stringList << QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).trimmed()  ;
401
402      newItem = new QTreeWidgetItem(stringList);
403
404      // look for childs
405      CreateChildTree(newItem,treeTop->GetTree(a+1));
406      items.append(newItem);
407    }
408    fHelpTreeWidget->insertTopLevelItems(0, items);
409
410    //connecting callback
411    //  QSignalMapper signalMapper = new QSignalMapper(this);
412
413    connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(helpTreeCallback())); 
414
415    // Set layouts
416
417    QVBoxLayout *vLayout = new QVBoxLayout;
418
419    splitter->addWidget(fHelpTreeWidget);
420    splitter->addWidget(fHelpArea);
421
422    vLayout->addWidget(splitter);
423    vLayout->addWidget(exitButton);
424    fHelpDialog->setLayout(vLayout);
425
426  }
427
428  // Look for the choosen command "newCommand"
429  size_t i = newCommand.index(" ");
430  G4String targetCom="";
431  if( i != std::string::npos )
432    {
433      G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
434      newValue.strip(G4String::both);
435      targetCom = ModifyToFullPathCommand( newValue );
436      printf("test : av:%s-- ap:%s--\n",((char*)newValue.data()),((char*)targetCom.data()));
437    }
438  if (targetCom != "") {
439    QTreeWidgetItem* findItem = NULL;
440    for (int a=0;a<fHelpTreeWidget->topLevelItemCount();a++) {
441      if (!findItem) {
442        findItem = FindTreeItem(fHelpTreeWidget->topLevelItem(a),QString((char*)targetCom.data()));
443      }
444    }
445
446    if (findItem) {     
447      // clear old selection
448      fHelpTreeWidget->clearSelection();
449
450      //collapsed open item
451      QList<QTreeWidgetItem *> selected;
452      selected = fHelpTreeWidget->selectedItems();
453      if ( selected.count() != 0 ) {
454        QTreeWidgetItem * tmp =selected.at( 0 );
455        while ( tmp) {
456          tmp->setExpanded(false);
457          tmp = findItem->parent();
458        }
459      }
460     
461      // set new selection
462      findItem->setSelected(true);
463     
464      // expand parent item
465      while ( findItem) {
466        findItem->setExpanded(true);
467        findItem = findItem->parent();
468      }
469
470      // Call the update of the right textArea
471      helpTreeCallback();
472    }
473  }
474  fHelpDialog->setWindowTitle("Help on commands");
475  fHelpDialog->resize(800,600);
476  fHelpDialog->move(QPoint(400,150));
477  fHelpDialog->show();
478  fHelpDialog->raise();
479  fHelpDialog->activateWindow();
480}
481
482
483
484/**
485   Fill the Help Tree Widget
486   @param aParent : parent item to fill
487   @param aCommandTree : commandTree node associate with this part of the Tree
488*/
489void G4UIQt::CreateChildTree(
490 QTreeWidgetItem *aParent
491,G4UIcommandTree *aCommandTree
492)
493{
494
495  // Creating new item
496  QTreeWidgetItem * newItem;
497
498  // Get the Sub directories
499  for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
500   
501    QStringList stringList;
502    stringList << QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed()  ;
503    stringList << QString((char*)(aCommandTree->GetTree(a+1)->GetTitle()).data()).trimmed()  ;
504    newItem = new QTreeWidgetItem(stringList);
505
506    CreateChildTree(newItem,aCommandTree->GetTree(a+1));
507    aParent->addChild(newItem);
508  }
509
510
511
512  // Get the Commands
513
514  for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
515   
516    QStringList stringList;
517    stringList << QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed()  ;
518    stringList << QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed()  ;
519    newItem = new QTreeWidgetItem(stringList);
520     
521    aParent->addChild(newItem);
522    newItem->setExpanded(false);
523  }
524}
525
526
527/**
528*/
529QTreeWidgetItem* G4UIQt::FindTreeItem(
530 QTreeWidgetItem *aParent
531,QString aCommand
532)
533{
534  if (aParent->text(0) == aCommand)
535    return aParent;
536 
537  QTreeWidgetItem * tmp = NULL;
538  for (int a=0;a<aParent->childCount();a++) {
539    if (!tmp)
540      tmp = FindTreeItem(aParent->child(a),aCommand);
541  }
542  return tmp;
543}
544
545
546/**
547   Build the command list parameters in a QString<br>
548   Reimplement partialy the G4UIparameter.cc
549   @param aCommand : command to list parameters
550   @see G4UIparameter::List()
551   @return the command list parameters
552*/
553QString G4UIQt::GetCommandList (
554 G4UIcommand *aCommand
555)
556{
557
558  QString txt;
559  G4String commandPath = aCommand->GetCommandPath();
560  G4String rangeString = aCommand->GetRange();
561
562  if((commandPath.length()-1)!='/')
563    {
564      txt += "Command " + QString((char*)(commandPath).data()) + "\n";
565    }
566  txt += "Guidance :\n";
567  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
568
569  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ )
570    { txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n"; }
571  if( ! rangeString.isNull() )
572    { txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n"; }
573  G4int n_parameterEntry = aCommand->GetParameterEntries();
574  if( n_parameterEntry > 0 )
575    {
576      G4UIparameter *param;
577
578      // Re-implementation of G4UIparameter.cc
579
580      for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ )
581        { param = aCommand->GetParameter(i_thParameter);
582          txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
583          if( ! param->GetParameterGuidance().isNull() )
584            txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
585          txt += " Parameter type  : " + QString(param->GetParameterType())+ "\n";
586          if(param->IsOmittable())
587            { txt += " Omittable       : True\n"; }
588          else
589            { txt += " Omittable       : False\n"; }
590          if( param->GetCurrentAsDefault() )
591            { txt += " Default value   : taken from the current value\n"; }
592          else if( ! param->GetDefaultValue().isNull() )
593            { txt += " Default value   : " + QString((char*)(param->GetDefaultValue()).data())+ "\n"; }
594          if( ! param->GetParameterRange().isNull() )
595            txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
596          if( ! param->GetParameterCandidates().isNull() )
597            txt += " Candidates      : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
598        }
599    }
600  return txt;
601}
602
603
604
605/**
606  Implement G4VBasicShell vurtual function
607 */
608G4bool G4UIQt::GetHelpChoice(
609 G4int& aInt
610)
611{
612  printf("G4UIQt::GetHelpChoice SHOULD NEVER GO HERE");
613  return true;
614}
615
616
617/**
618   Implement G4VBasicShell vurtual function
619*/
620void G4UIQt::ExitHelp(
621)
622{
623  printf("G4UIQt::ExitHelp SHOULD NEVER GO HERE");
624}
625
626
627/**
628   Event filter method. Every event from QtApplication goes here.<br/>
629   We apply a filter only for the Up and Down Arrow press when the QLineEdit<br/>
630   is active. If this filter match, Up arrow we give the previous command<br/>
631   and Down arrow will give the next if exist.<br/>
632   @param obj Emitter of the event
633   @param event Kind of event
634*/
635bool G4UIQt::eventFilter(
636                         QObject *obj
637                         ,QEvent *event
638                         )
639{
640  if (obj == fCommandHistoryArea) {
641    if (event->type() == QEvent::KeyPress) {
642      fCommandArea->setFocus();
643    }
644  }
645  if (obj == fCommandArea) {
646    if (event->type() == QEvent::KeyPress) {
647      QKeyEvent *e = static_cast<QKeyEvent*>(event);
648      if ((e->key() == (Qt::Key_Down)) ||
649          (e->key() == (Qt::Key_PageDown)) ||
650          (e->key() == (Qt::Key_Up)) ||
651          (e->key() == (Qt::Key_PageUp))) {
652        int selection = fCommandHistoryArea->currentRow();
653        for (int a=0;a<fCommandHistoryArea->count();a++) {
654         
655        }
656        if (fCommandHistoryArea->count()) {
657          if (selection == -1) {
658            selection = fCommandHistoryArea->count()-1;
659          }
660          if (e->key() == (Qt::Key_Down)) {
661            if (selection <(fCommandHistoryArea->count()-1))
662              selection++;
663          } else if (e->key() == (Qt::Key_PageDown)) {
664            selection = fCommandHistoryArea->count()-1;
665          } else if (e->key() == (Qt::Key_Up)) {
666            if (selection >0)
667              selection --;
668          } else if (e->key() == (Qt::Key_PageUp)) {
669            selection = 0;
670          }
671          fCommandHistoryArea->clearSelection();
672          fCommandHistoryArea->item(selection)->setSelected(true);
673          fCommandHistoryArea->setCurrentItem(fCommandHistoryArea->item(selection));
674        }
675      }
676    }
677  }
678  // pass the event on to the parent class
679  return QObject::eventFilter(obj, event);
680}
681
682
683
684
685/***************************************************************************/
686//
687//             SLOTS DEFINITIONS
688//
689/***************************************************************************/
690
691/**
692   Called when user give "help" command.
693*/
694void G4UIQt::showHelpCallback (
695)
696{
697  TerminalHelp("");
698}
699
700
701/**
702   Called when user click on clear button. Clear the text Output area
703*/
704void G4UIQt::clearButtonCallback (
705)
706{
707  fTextArea->clear();
708}
709
710
711/**
712   Callback call when "click on a menu entry.<br>
713   Send the associated command to geant4
714*/
715void G4UIQt::commandEnteredCallback (
716)
717{
718  G4String command (fCommandArea->text().toStdString().c_str());
719  if (fCommandArea->text().trimmed() != "") {
720    fCommandHistoryArea->addItem(fCommandArea->text());
721    fCommandHistoryArea->clearSelection();
722    fCommandHistoryArea->item(fCommandHistoryArea->count()-1)->setSelected(true);
723    fCommandHistoryArea->setCurrentItem(fCommandHistoryArea->item(fCommandHistoryArea->count()-1));
724
725    if (command(0,4) != "help") {
726      ApplyShellCommand (command,exitSession,exitPause);
727    } else {
728      TerminalHelp(command);
729    }
730    if(exitSession==true)
731      SessionTerminate();
732  }
733  fCommandArea->setText("");
734}
735
736
737/**
738   Callback call when "enter" clicked on the command zone.<br>
739   Send the command to geant4
740   @param aCommand
741*/
742void G4UIQt::buttonCallback (
743 const QString& aCommand
744)
745{
746  G4String ss = G4String(aCommand.toStdString().c_str());
747  printf ("debug : execute:\n-%s- %d %d \n",ss.data(),exitSession,exitPause);
748  ApplyShellCommand(ss,exitSession,exitPause);
749  if(exitSession==true)
750    SessionTerminate();
751}
752
753
754
755/**
756   This callback is activated when user selected a item in the help tree
757*/
758void G4UIQt::helpTreeCallback (
759)
760{
761  //  G4bool GetHelpChoice(G4int&);
762  QTreeWidgetItem* item =  NULL;
763  if (!fHelpTreeWidget)
764    return ;
765
766  if (!fHelpArea)
767    return;
768 
769  QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
770  if (list.isEmpty())
771    return;
772  item = list.first();
773  if (!item)
774    return;
775 
776  G4UImanager* UI = G4UImanager::GetUIpointer();
777  if(UI==NULL) return;
778  G4UIcommandTree * treeTop = UI->GetTree();
779  G4UIcommand* command = treeTop->FindPath(item->text (1).toStdString().c_str());
780  if (command) {
781    fHelpArea->setText(GetCommandList(command));
782  } else {
783    // this is not a command, this is a sub directory
784    // We display the Title
785    fHelpArea->setText(item->text (1).toStdString().c_str());
786  }
787}
788
789
790/**
791   Callback called when user select an old command in the command history<br>
792   Give it to the command area.
793*/
794void G4UIQt::commandHistoryCallback(
795)
796{
797  QListWidgetItem* item =  NULL;
798  if (!fCommandHistoryArea)
799    return ;
800
801 
802  QList<QListWidgetItem *> list =fCommandHistoryArea->selectedItems();
803  if (list.isEmpty())
804    return;
805  item = list.first();
806  if (!item)
807    return;
808  fCommandArea->setText(item->text());
809
810}
811
812#endif
Note: See TracBrowser for help on using the repository browser.