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

Last change on this file since 601 was 595, checked in by garnier, 18 years ago

r629@mac-90108: laurentgarnier | 2007-11-09 15:34:57 +0100
mise a jour

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