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

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

r648@mac-90108: laurentgarnier | 2007-06-21 14:53:57 +0200
desormais l envoie d une commande vide ne s ajoute pas a la liste

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