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

Last change on this file since 585 was 579, checked in by garnier, 18 years ago

r599@mac-90108: laurentgarnier | 2007-09-18 18:43:19 +0200
correction du ticket #72 et la suppresion de la fenetre OpenGL entraine desormais un message d erreur lors du prochain BeamOn

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