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
RevLine 
[481]1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26//
[602]27// $Id: G4UIQt.cc,v 1.4 2007/11/09 15:03:21 lgarnier Exp $
[593]28// GEANT4 tag $Name:  $
[481]29//
[484]30// L. Garnier
[481]31
32//#define DEBUG
33
34#ifdef G4UI_BUILD_QT_SESSION
35
36#include "G4Types.hh"
37
38#include <string.h>
39
40#include "G4UIQt.hh"
41#include "G4UImanager.hh"
42#include "G4StateManager.hh"
43#include "G4UIcommandTree.hh"
44#include "G4UIcommandStatus.hh"
45
46#include "G4Qt.hh"
47
[595]48#include <qapplication.h>
49#include <qmainwindow.h>
50#include <qlineedit.h>
51#include <qwidget.h>
[602]52#if QT_VERSION >= 0x040000
[595]53#include <qmenu.h>
[602]54#else
55#include <qpopupmenu.h>
56#endif
[595]57#include <qmenubar.h>
[602]58#include <qlayout.h>
[595]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>
[481]69
[593]70
[481]71#include <stdlib.h>
72
[513]73// Pourquoi Static et non  variables de classe ?
[481]74static G4bool exitSession = true;
75static G4bool exitPause = true;
[524]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>
[481]96*/
97G4UIQt::G4UIQt (
[527]98 int argc
99,char** argv
100)
[513]101  :fHelpDialog(NULL)
[481]102{
[496]103  G4Qt* interactorManager = G4Qt::getInstance ();
[505]104  G4UImanager* UI = G4UImanager::GetUIpointer();
105  if(UI!=NULL) UI->SetSession(this);
[481]106
[494]107  fMainWindow = new QMainWindow();
108  fMainWindow->setWindowTitle( "G4UI Session" );
[500]109  fMainWindow->resize(800,600);
[571]110  fMainWindow->move(QPoint(50,100));
[496]111
[498]112  QSplitter *splitter = new QSplitter(Qt::Vertical);
113  fTextArea = new QTextEdit();
[490]114  QPushButton *clearButton = new QPushButton("clear");
[526]115  connect(clearButton, SIGNAL(clicked()), SLOT(ClearButtonCallback()));
[498]116
[519]117  fCommandHistoryArea = new QListWidget();
118  fCommandHistoryArea->setSelectionMode(QAbstractItemView::SingleSelection);
[526]119  connect(fCommandHistoryArea, SIGNAL(itemSelectionChanged()), SLOT(CommandHistoryCallback()));
[523]120  fCommandHistoryArea->installEventFilter(this);
[498]121  fCommandLabel = new QLabel();
122
[518]123  fCommandArea = new QLineEdit();
124  fCommandArea->installEventFilter(this);
[500]125  fCommandArea->activateWindow();
[526]126  connect(fCommandArea, SIGNAL(returnPressed()), SLOT(CommandEnteredCallback()));
[578]127  fCommandArea->setFocusPolicy ( Qt::StrongFocus );
128  fCommandArea->setFocus(Qt::TabFocusReason);
[498]129  fTextArea->setReadOnly(true);
130
[505]131
132  // Set layouts
[497]133
[498]134  QWidget* topWidget = new QWidget();
135  QVBoxLayout *layoutTop = new QVBoxLayout;
[481]136
[498]137  QWidget* bottomWidget = new QWidget();
138  QVBoxLayout *layoutBottom = new QVBoxLayout;
[494]139
[490]140
[498]141  layoutTop->addWidget(fTextArea);
142  layoutTop->addWidget(clearButton);
143  topWidget->setLayout(layoutTop);
[494]144
[498]145  layoutBottom->addWidget(fCommandHistoryArea);
146  layoutBottom->addWidget(fCommandLabel);
147  layoutBottom->addWidget(fCommandArea);
148  bottomWidget->setLayout(layoutBottom);
[490]149
[495]150
[522]151  splitter->addWidget(topWidget);
152  splitter->addWidget(bottomWidget);
[498]153  fMainWindow->setCentralWidget(splitter);
[495]154
[513]155  // Add a quit subMenu
[504]156  QMenu *fileMenu = fMainWindow->menuBar()->addMenu("File");
[503]157  fileMenu->addAction("Quitter", fMainWindow, SLOT(close()));
[496]158
[513]159  // Add a Help menu
160  QMenu *helpMenu = fMainWindow->menuBar()->addMenu("Help");
[526]161  helpMenu->addAction("Show Help", this, SLOT(ShowHelpCallback()));
[513]162
[505]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  }
[481]170
171
[484]172  if(UI!=NULL) UI->SetCoutDestination(this);  // TO KEEP
[481]173}
[524]174
175
176
[481]177G4UIQt::~G4UIQt(
178)
179{
[484]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
[481]184  }
[484]185 
[494]186  if (fMainWindow!=NULL)
187    delete fMainWindow;
[481]188}
[524]189
190
191
192/**   Start the Qt main loop
193*/
[481]194G4UIsession* G4UIQt::SessionStart (
195)
196{
[484]197
[496]198  G4Qt* interactorManager = G4Qt::getInstance ();
[494]199  fMainWindow->show();
200  Prompt("session");
201  exitSession = false;
[481]202
[496]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 ????
[506]208  // je ne pense pas 13/06
[496]209
[524]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
[506]215
216  interactorManager->EnableSecondaryLoop ();
[496]217  printf("enable secondary loop\n");
[506]218  return this;
[481]219}
[494]220
[524]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*/
[481]227void G4UIQt::Prompt (
228 G4String aPrompt
229)
230{
[527]231  if (!aPrompt) return;
[526]232
[500]233  fCommandLabel->setText((char*)aPrompt.data());
[481]234}
[524]235
236
[481]237void G4UIQt::SessionTerminate (
238)
239{
[505]240  G4Qt* interactorManager = G4Qt::getInstance ();
241  fMainWindow->close();
242  ((QApplication*)interactorManager->GetMainInteractor())->exit();
[481]243}
[524]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*/
[481]255void G4UIQt::PauseSessionStart (
[524]256 G4String aState
[481]257)
258{
[527]259  if (!aState) return;
[526]260
[501]261  printf("G4UIQt::PauseSessionStart\n");
[524]262  if(aState=="G4_pause> ") {  // TO KEEP
[484]263    SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP
264  } // TO KEEP
[481]265
[524]266  if(aState=="EndOfEvent") { // TO KEEP
[481]267    // Picking with feed back in event data Done here !!!
[484]268    SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP
269  } // TO KEEP
[481]270}
[524]271
272
273
274/**
275   Begin the secondary loop
276   @param a_prompt : label to display as the prompt label
277 */
[484]278void G4UIQt::SecondaryLoop (
[524]279 G4String aPrompt
[481]280)
281{
[527]282  if (!aPrompt) return;
[526]283
[501]284  printf("G4UIQt::SecondaryLoop\n");
[484]285  G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ?
[524]286  Prompt(aPrompt); // TO KEEP
[484]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
[481]294}
[524]295
296
297
[481]298/**
[524]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
[526]301   @return 0
[524]302*/
[484]303G4int G4UIQt::ReceiveG4cout (
[524]304 G4String aString
[481]305)
306{
[527]307  if (!aString) return 0;
[578]308  G4Qt* interactorManager = G4Qt::getInstance ();
309  if (!interactorManager) return 0;
310 
[579]311  //  printf(" **************** G4 Cout : %s\n",(char*)aString.data());
[575]312  fTextArea->append(QString((char*)aString.data()).trimmed());
313  fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum());
[578]314  interactorManager->FlushAndWaitExecution();
[495]315  return 0;
[481]316}
[524]317
318
[481]319/**
[524]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
[526]322   @return 0
[524]323*/
[484]324G4int G4UIQt::ReceiveG4cerr (
[524]325 G4String aString
[481]326)
327{
[527]328  if (!aString) return 0;
[578]329  G4Qt* interactorManager = G4Qt::getInstance ();
330  if (!interactorManager) return 0;
[526]331
[500]332  QColor previousColor = fTextArea->textColor();
333  fTextArea->setTextColor(Qt::red);
[524]334  fTextArea->append(QString((char*)aString.data()).trimmed());
[500]335  fTextArea->setTextColor(previousColor);
[501]336  fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum());
[578]337  interactorManager->FlushAndWaitExecution();
[495]338  return 0;
[481]339}
[501]340
[524]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 */
[484]348void G4UIQt::AddMenu (
[524]349 const char* aName
350,const char* aLabel
[481]351)
352{
[526]353  if (aName == NULL) return;
354  if (aLabel == NULL) return;
355
[524]356  QMenu *fileMenu = new QMenu(aLabel);
[513]357  fMainWindow->menuBar()->insertMenu(fMainWindow->menuBar()->actions().last(),fileMenu);
[524]358  AddInteractor (aName,(G4Interactor)fileMenu);
[481]359}
[524]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 */
[484]368void G4UIQt::AddButton (
[524]369 const char* aMenu
370,const char* aLabel
371,const char* aCommand
[481]372)
373{
[524]374  if(aMenu==NULL) return; // TO KEEP
375  if(aLabel==NULL) return; // TO KEEP
376  if(aCommand==NULL) return; // TO KEEP
[526]377
[524]378  QMenu *parent = (QMenu*)GetInteractor(aMenu);
[504]379  if(parent==NULL) return;
380 
[526]381  QSignalMapper *signalMapper = new QSignalMapper(this);
[524]382  QAction *action = parent->addAction(aLabel, signalMapper, SLOT(map()));
383  signalMapper->setMapping(action, QString(aCommand));
[526]384  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&)));
[491]385}
[504]386
387
388
[513]389
390/**
[524]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>
[506]394
[524]395   @param newCommand : open the tree widget item on this command if is set
396*/
397void G4UIQt::TerminalHelp(
398 G4String newCommand
399)
[506]400{
[524]401  // Create the help dialog
[514]402  if (!fHelpDialog) {
[579]403    fHelpDialog = new QDialog(fMainWindow,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
[514]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);
[506]409
[514]410    // the help tree
411    G4UImanager* UI = G4UImanager::GetUIpointer();
412    if(UI==NULL) return;
413    G4UIcommandTree * treeTop = UI->GetTree();
[507]414
[514]415    // build widget
416    fHelpTreeWidget = new QTreeWidget();
[515]417    fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
[514]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
[575]441    connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback())); 
[577]442    connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback(QTreeWidgetItem*,int))); 
[514]443
444    // Set layouts
445
446    QVBoxLayout *vLayout = new QVBoxLayout;
447
[522]448    splitter->addWidget(fHelpTreeWidget);
449    splitter->addWidget(fHelpArea);
[514]450
451    vLayout->addWidget(splitter);
452    vLayout->addWidget(exitButton);
453    fHelpDialog->setLayout(vLayout);
454
455  }
456
[513]457  // Look for the choosen command "newCommand"
458  size_t i = newCommand.index(" ");
[514]459  G4String targetCom="";
[513]460  if( i != std::string::npos )
[524]461    {
462      G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
463      newValue.strip(G4String::both);
464      targetCom = ModifyToFullPathCommand( newValue );
465    }
[514]466  if (targetCom != "") {
[524]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      }
[514]472    }
[525]473   
[524]474    if (findItem) {     
[525]475     
[515]476      //collapsed open item
477      QList<QTreeWidgetItem *> selected;
478      selected = fHelpTreeWidget->selectedItems();
479      if ( selected.count() != 0 ) {
[524]480        QTreeWidgetItem * tmp =selected.at( 0 );
481        while ( tmp) {
482          tmp->setExpanded(false);
[525]483          tmp = tmp->parent();
[524]484        }
[514]485      }
[515]486     
[525]487      // clear old selection
488      fHelpTreeWidget->clearSelection();
489
[524]490      // set new selection
491      findItem->setSelected(true);
[515]492     
[524]493      // expand parent item
494      while ( findItem) {
495        findItem->setExpanded(true);
496        findItem = findItem->parent();
497      }
498
[514]499      // Call the update of the right textArea
[575]500      HelpTreeClicCallback();
[514]501    }
[524]502  }
[515]503  fHelpDialog->setWindowTitle("Help on commands");
[513]504  fHelpDialog->resize(800,600);
505  fHelpDialog->move(QPoint(400,150));
506  fHelpDialog->show();
507  fHelpDialog->raise();
508  fHelpDialog->activateWindow();
[514]509}
[506]510
[507]511
[506]512
[526]513/**   Fill the Help Tree Widget
[524]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{
[526]522  if (aParent == NULL) return;
523  if (aCommandTree == NULL) return;
[514]524
[526]525
[507]526  // Creating new item
527  QTreeWidgetItem * newItem;
[506]528
[508]529  // Get the Sub directories
[524]530  for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
[526]531
[507]532    QStringList stringList;
[524]533    stringList << QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed()  ;
534    stringList << QString((char*)(aCommandTree->GetTree(a+1)->GetTitle()).data()).trimmed()  ;
[507]535    newItem = new QTreeWidgetItem(stringList);
[508]536
[524]537    CreateChildTree(newItem,aCommandTree->GetTree(a+1));
538    aParent->addChild(newItem);
[507]539  }
[506]540
[508]541
542
543  // Get the Commands
544
[524]545  for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
[508]546   
547    QStringList stringList;
[524]548    stringList << QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed()  ;
549    stringList << QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed()  ;
[508]550    newItem = new QTreeWidgetItem(stringList);
[509]551     
[524]552    aParent->addChild(newItem);
[514]553    newItem->setExpanded(false);
[508]554  }
[507]555}
[509]556
[512]557
[526]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
[524]561*/
562QTreeWidgetItem* G4UIQt::FindTreeItem(
563 QTreeWidgetItem *aParent
[527]564,const QString& aCommand
[524]565)
566{
[526]567  if (aParent == NULL) return NULL;
568
[524]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}
[511]579
[524]580
[527]581/**   Build the command list parameters in a QString<br>
[524]582   Reimplement partialy the G4UIparameter.cc
583   @param aCommand : command to list parameters
584   @see G4UIparameter::List()
[526]585   @see G4UIcommand::List()
586   @return the command list parameters, or "" if nothing
[524]587*/
[509]588QString G4UIQt::GetCommandList (
[527]589 const G4UIcommand *aCommand
[509]590)
591{
[510]592
[526]593  QString txt ="";
594  if (aCommand == NULL)
595    return txt;
596
[524]597  G4String commandPath = aCommand->GetCommandPath();
598  G4String rangeString = aCommand->GetRange();
599  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
600  G4int n_parameterEntry = aCommand->GetParameterEntries();
[526]601 
602  if ((commandPath == "") &&
603      (rangeString == "") &&
604      (n_guidanceEntry == 0) &&
605      (n_parameterEntry == 0)) {
606    return txt;
607  }
[511]608
[526]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      }
[511]647    }
[526]648  }
[509]649  return txt;
650}
[513]651
[514]652
653
[527]654/**  Implement G4VBasicShell vurtual function
[524]655 */
[517]656G4bool G4UIQt::GetHelpChoice(
657 G4int& aInt
658)
659{
660  printf("G4UIQt::GetHelpChoice SHOULD NEVER GO HERE");
[519]661  return true;
[517]662}
[519]663
[524]664
[527]665/**   Implement G4VBasicShell vurtual function
[524]666*/
[517]667void G4UIQt::ExitHelp(
668)
669{
670  printf("G4UIQt::ExitHelp SHOULD NEVER GO HERE");
671}
[514]672
673
[527]674/**   Event filter method. Every event from QtApplication goes here.<br/>
[524]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
[518]680*/
[528]681bool G4UIQt::eventFilter( // Should stay with a minuscule eventFilter because of Qt
[526]682 QObject *aObj
683,QEvent *aEvent
684)
[518]685{
[526]686  if (aObj == NULL) return false;
687  if (aEvent == NULL) return false;
688
689  if (aObj == fCommandHistoryArea) {
690    if (aEvent->type() == QEvent::KeyPress) {
[523]691      fCommandArea->setFocus();
692    }
693  }
[526]694  if (aObj == fCommandArea) {
695    if (aEvent->type() == QEvent::KeyPress) {
696      QKeyEvent *e = static_cast<QKeyEvent*>(aEvent);
[519]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;
[528]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            }
[519]717          }
718          fCommandHistoryArea->clearSelection();
719          fCommandHistoryArea->item(selection)->setSelected(true);
[520]720          fCommandHistoryArea->setCurrentItem(fCommandHistoryArea->item(selection));
[519]721        }
[538]722      } else if (e->key() == (Qt::Key_Tab)) {
[602]723#if QT_VERSION < 0x040000
724        G4String ss = Complete(fCommandArea->text().ascii());
725#else
[538]726        G4String ss = Complete(fCommandArea->text().toStdString().c_str());
[602]727#endif
[538]728        fCommandArea->setText((char*)(ss.data()));
729
730        // do not pass by parent, it will disable widget tab focus !
731        return true;
[518]732      }
733    }
734  }
735  // pass the event on to the parent class
[526]736  return QObject::eventFilter(aObj, aEvent);
[518]737}
738
739
740
741
742/***************************************************************************/
[514]743//
744//             SLOTS DEFINITIONS
745//
746/***************************************************************************/
747
[527]748/**   Called when user give "help" command.
[524]749*/
[526]750void G4UIQt::ShowHelpCallback (
[514]751)
752{
[513]753  TerminalHelp("");
754}
755
[524]756
[527]757/**   Called when user click on clear button. Clear the text Output area
[524]758*/
[526]759void G4UIQt::ClearButtonCallback (
[514]760)
761{
762  fTextArea->clear();
763}
764
765
[527]766/**   Callback call when "click on a menu entry.<br>
[524]767   Send the associated command to geant4
768*/
[526]769void G4UIQt::CommandEnteredCallback (
[514]770)
771{
[602]772#if QT_VERSION < 0x040000
773  G4String command (fCommandArea->text().ascii());
774#else
[514]775  G4String command (fCommandArea->text().toStdString().c_str());
[602]776#endif
[522]777  if (fCommandArea->text().trimmed() != "") {
[519]778    fCommandHistoryArea->addItem(fCommandArea->text());
[520]779    fCommandHistoryArea->clearSelection();
[578]780    fCommandHistoryArea->setCurrentItem(NULL);
781    fCommandArea->setText("");
[514]782
[578]783    G4Qt* interactorManager = G4Qt::getInstance ();
784    if (interactorManager) {
785      interactorManager->FlushAndWaitExecution();
786    }
[514]787    if (command(0,4) != "help") {
[524]788      ApplyShellCommand (command,exitSession,exitPause);
[514]789    } else {
790      TerminalHelp(command);
791    }
[578]792    printf("after \n");
[514]793    if(exitSession==true)
794      SessionTerminate();
795  }
796}
797
[524]798
[527]799/**   Callback call when "enter" clicked on the command zone.<br>
[524]800   Send the command to geant4
801   @param aCommand
802*/
[526]803void G4UIQt::ButtonCallback (
[524]804 const QString& aCommand
[514]805)
806{
[602]807#if QT_VERSION < 0x040000
808  G4String ss = G4String(aCommand.ascii());
809#else
[524]810  G4String ss = G4String(aCommand.toStdString().c_str());
[602]811#endif
[514]812  ApplyShellCommand(ss,exitSession,exitPause);
813  if(exitSession==true)
814    SessionTerminate();
815}
[524]816
817
818
[527]819/**   This callback is activated when user selected a item in the help tree
[524]820*/
[575]821void G4UIQt::HelpTreeClicCallback (
[514]822)
823{
[595]824  //  printf("G4UIQt::HelpTreeClicCallback");
[514]825  QTreeWidgetItem* item =  NULL;
826  if (!fHelpTreeWidget)
827    return ;
828
829  if (!fHelpArea)
830    return;
831 
[515]832  QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
833  if (list.isEmpty())
834    return;
835  item = list.first();
[514]836  if (!item)
837    return;
838 
839  G4UImanager* UI = G4UImanager::GetUIpointer();
840  if(UI==NULL) return;
841  G4UIcommandTree * treeTop = UI->GetTree();
[602]842#if QT_VERSION < 0x040000
843  G4UIcommand* command = treeTop->FindPath(item->text (1).ascii());
844#else
[514]845  G4UIcommand* command = treeTop->FindPath(item->text (1).toStdString().c_str());
[602]846#endif
[514]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
[602]852#if QT_VERSION < 0x040000
853    fHelpArea->setText(item->text (1).ascii());
854#else
[514]855    fHelpArea->setText(item->text (1).toStdString().c_str());
[602]856#endif
[514]857  }
858}
859
[575]860/**   This callback is activated when user double clic on a item in the help tree
861*/
862void G4UIQt::HelpTreeDoubleClicCallback (
[577]863QTreeWidgetItem* item
864 ,int nb
[575]865)
866{
[577]867  printf("G4UIQt::HelpTreeDoubleClicCallback");
[575]868  HelpTreeClicCallback();
869  fCommandArea->setText(item->text (1));
870}
871
872
[527]873/**   Callback called when user select an old command in the command history<br>
[524]874   Give it to the command area.
875*/
[526]876void G4UIQt::CommandHistoryCallback(
[519]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
[513]894#endif
Note: See TracBrowser for help on using the repository browser.