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

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

r643@mac-90108: laurentgarnier | 2007-11-12 19:00:52 +0100
modif pour qt3

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