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

Last change on this file since 540 was 538, checked in by garnier, 18 years ago

r680@mac-90108: laurentgarnier | 2007-07-03 18:08:15 +0200
ajout de la completion sur G4UIQT

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