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

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

avancement sur la zone de recherche : en bug

  • Property svn:mime-type set to text/cpp
File size: 42.2 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 2008/01/15 11:04:26 lgarnier Exp $
28// GEANT4 tag $Name: $
29//
30// L. Garnier
31
32#define GEANT4_QT_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 <qlineedit.h>
50#include <qwidget.h>
51#include <qmenubar.h>
52#include <qlayout.h>
53#include <qpushbutton.h>
54#include <qlabel.h>
55#include <qsplitter.h>
56#include <qscrollbar.h>
57#include <qdialog.h>
58#include <qevent.h>
59#include <qtextedit.h>
60#include <qsignalmapper.h>
61
62#include <qmainwindow.h>
63#if QT_VERSION >= 0x040000
64#include <qmenu.h>
65#include <qlistwidget.h>
66#include <qtreewidget.h>
67#else
68#include <qaction.h>
69#include <qheader.h>
70#include <qlistview.h>
71#include <qpopupmenu.h>
72#endif
73
74
75
76#include <stdlib.h>
77
78// Pourquoi Static et non variables de classe ?
79static G4bool exitSession = true;
80static G4bool exitPause = true;
81
82/** Build a Qt window with a menubar, output area and promt area<br>
83<pre>
84 +-----------------------+
85 |exit menu| |
86 | |
87 | +-------------------+ |
88 | | | |
89 | | Output area | |
90 | | | |
91 | +-------------------+ |
92 | | clear | |
93 | +-------------------+ |
94 | | promt history | |
95 | +-------------------+ |
96 | +-------------------+ |
97 | |> promt area | |
98 | +-------------------+ |
99 +-----------------------+
100</pre>
101*/
102G4UIQt::G4UIQt (
103 int argc
104,char** argv
105)
106 :fHelpDialog(NULL)
107{
108#ifdef GEANT4_QT_DEBUG
109 printf("G4UIQt::Initialise %d %s\n",argc,argv[0]);
110#endif
111 G4Qt* interactorManager = G4Qt::getInstance (argc,argv,(char*)"Qt");
112 G4UImanager* UI = G4UImanager::GetUIpointer();
113 if(UI!=NULL) UI->SetSession(this);
114
115 fMainWindow = new QMainWindow();
116
117#ifdef GEANT4_QT_DEBUG
118 printf("G4UIQt::Initialise after main window creation\n");
119#endif
120#if QT_VERSION < 0x040000
121 fMainWindow->setCaption( tr( "G4UI Session" ));
122 fMainWindow->resize(900,600);
123 fMainWindow->move(50,100);
124#else
125 fMainWindow->setWindowTitle( tr("G4UI Session") );
126 fMainWindow->resize(900,600);
127 fMainWindow->move(QPoint(50,100));
128#endif
129
130 QSplitter *splitter = new QSplitter(Qt::Vertical,fMainWindow);
131
132 // Set layouts
133
134 QWidget* topWidget = new QWidget(splitter);
135 QWidget* bottomWidget = new QWidget(splitter);
136
137 QVBoxLayout *layoutTop = new QVBoxLayout(topWidget);
138 QVBoxLayout *layoutBottom = new QVBoxLayout(bottomWidget);
139
140 // fill them
141
142 fTextArea = new QTextEdit(topWidget);
143 QPushButton *clearButton = new QPushButton("clear",topWidget);
144 connect(clearButton, SIGNAL(clicked()), SLOT(ClearButtonCallback()));
145
146#if QT_VERSION < 0x040000
147
148 fCommandHistoryArea = new QListView(bottomWidget);
149 fCommandHistoryArea->setSorting (-1, FALSE);
150 fCommandHistoryArea->setSelectionMode(QListView::Single);
151 fCommandHistoryArea->addColumn("");
152 fCommandHistoryArea->header()->hide();
153 connect(fCommandHistoryArea, SIGNAL(selectionChanged()), SLOT(CommandHistoryCallback()));
154#else
155 fCommandHistoryArea = new QListWidget();
156 fCommandHistoryArea->setSelectionMode(QAbstractItemView::SingleSelection);
157 connect(fCommandHistoryArea, SIGNAL(itemSelectionChanged()), SLOT(CommandHistoryCallback()));
158#endif
159 fCommandHistoryArea->installEventFilter(this);
160 fCommandLabel = new QLabel("",bottomWidget);
161
162 fCommandArea = new QLineEdit(bottomWidget);
163 fCommandArea->installEventFilter(this);
164#if QT_VERSION < 0x040000
165 fCommandArea->setActiveWindow();
166#else
167 fCommandArea->activateWindow();
168#endif
169 connect(fCommandArea, SIGNAL(returnPressed()), SLOT(CommandEnteredCallback()));
170#if QT_VERSION < 0x040000
171 fCommandArea->setFocusPolicy ( QWidget::StrongFocus );
172 fCommandArea->setFocus();
173#else
174 fCommandArea->setFocusPolicy ( Qt::StrongFocus );
175 fCommandArea->setFocus(Qt::TabFocusReason);
176#endif
177 fTextArea->setReadOnly(true);
178
179
180#ifdef GEANT4_QT_DEBUG
181 printf("G4UIQt:: 2\n");
182#endif
183
184
185
186 layoutTop->addWidget(fTextArea);
187 layoutTop->addWidget(clearButton);
188
189#if QT_VERSION >= 0x040000
190 topWidget->setLayout(layoutTop);
191#endif
192
193 layoutBottom->addWidget(fCommandHistoryArea);
194 layoutBottom->addWidget(fCommandLabel);
195 layoutBottom->addWidget(fCommandArea);
196#if QT_VERSION >= 0x040000
197
198 bottomWidget->setLayout(layoutBottom);
199 splitter->addWidget(topWidget);
200 splitter->addWidget(bottomWidget);
201#endif
202
203
204 fMainWindow->setCentralWidget(splitter);
205
206#if QT_VERSION < 0x040000
207
208 // Add a quit subMenu
209 QPopupMenu *fileMenu = new QPopupMenu( fMainWindow);
210 fileMenu->insertItem( "&Quitter", this, SLOT(ExitSession()), CTRL+Key_Q );
211 fMainWindow->menuBar()->insertItem( QString("&File"), fileMenu );
212
213 // Add a Help menu
214 QPopupMenu *helpMenu = new QPopupMenu( fMainWindow );
215 helpMenu->insertItem( "&Show Help", this, SLOT(ShowHelpCallback()), CTRL+Key_H );
216 fMainWindow->menuBar()->insertItem( QString("&Help"), helpMenu );
217
218
219#else
220
221 // Add a quit subMenu
222 QMenu *fileMenu = fMainWindow->menuBar()->addMenu("File");
223 fileMenu->addAction("Quitter", this, SLOT(ExitSession()));
224
225 // Add a Help menu
226 QMenu *helpMenu = fMainWindow->menuBar()->addMenu("Help");
227 helpMenu->addAction("Show Help", this, SLOT(ShowHelpCallback()));
228#endif
229
230 // Set the splitter size. The fTextArea sould be 2/3 on the fMainWindow
231#if QT_VERSION < 0x040000
232 QValueList<int> vals = splitter->sizes();
233#else
234 QList<int> vals = splitter->sizes();
235#endif
236 if(vals.size()==2) {
237 vals[0] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*3/4;
238 vals[1] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*1/4;
239 splitter->setSizes(vals);
240 }
241
242 if(UI!=NULL) UI->SetCoutDestination(this); // TO KEEP
243}
244
245
246
247G4UIQt::~G4UIQt(
248)
249{
250 G4UImanager* UI = G4UImanager::GetUIpointer(); // TO KEEP
251 if(UI!=NULL) { // TO KEEP
252 UI->SetSession(NULL); // TO KEEP
253 UI->SetCoutDestination(NULL); // TO KEEP
254 }
255
256 if (fMainWindow!=NULL)
257 delete fMainWindow;
258}
259
260
261
262/** Start the Qt main loop
263*/
264G4UIsession* G4UIQt::SessionStart (
265)
266{
267
268 G4Qt* interactorManager = G4Qt::getInstance ();
269
270#if QT_VERSION >= 0x040000
271#if QT_VERSION >= 0x040200
272 fMainWindow->setVisible(true);
273#else
274 fMainWindow->show();
275#endif
276#else
277 fMainWindow->show();
278#endif
279 Prompt("session");
280 exitSession = false;
281
282
283#ifdef GEANT4_QT_DEBUG
284 printf("disable secondary loop\n");
285#endif
286 interactorManager->DisableSecondaryLoop (); // TO KEEP
287 if ((QApplication*)interactorManager->GetMainInteractor())
288 ((QApplication*)interactorManager->GetMainInteractor())->exec();
289
290 // on ne passe pas le dessous ? FIXME ????
291 // je ne pense pas 13/06
292
293 // void* event; // TO KEEP
294 // while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP
295 // interactorManager->DispatchEvent(event); // TO KEEP
296 // if(exitSession==true) break; // TO KEEP
297 // } // TO KEEP
298
299 interactorManager->EnableSecondaryLoop ();
300#ifdef GEANT4_QT_DEBUG
301 printf("enable secondary loop\n");
302#endif
303 return this;
304}
305
306
307/** Display the prompt in the prompt area
308 @param aPrompt : string to display as the promt label
309 //FIXME : probablement inutile puisque le seul a afficher qq chose d'autre
310 que "session" est SecondaryLoop()
311*/
312void G4UIQt::Prompt (
313 G4String aPrompt
314)
315{
316 if (!aPrompt) return;
317
318 fCommandLabel->setText((char*)aPrompt.data());
319}
320
321
322void G4UIQt::SessionTerminate (
323)
324{
325 G4Qt* interactorManager = G4Qt::getInstance ();
326 fMainWindow->close();
327 ((QApplication*)interactorManager->GetMainInteractor())->exit();
328}
329
330
331
332/**
333 Called by intercoms/src/G4UImanager.cc<br>
334 Called by visualization/management/src/G4VisCommands.cc with "EndOfEvent" argument<br>
335 It have to pause the session command terminal.<br>
336 Call SecondaryLoop to wait for exit event<br>
337 @param aState
338 @see : G4VisCommandReviewKeptEvents::SetNewValue
339*/
340void G4UIQt::PauseSessionStart (
341 G4String aState
342)
343{
344 if (!aState) return;
345
346#ifdef GEANT4_QT_DEBUG
347 printf("G4UIQt::PauseSessionStart\n");
348#endif
349 if(aState=="G4_pause> ") { // TO KEEP
350 SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP
351 } // TO KEEP
352
353 if(aState=="EndOfEvent") { // TO KEEP
354 // Picking with feed back in event data Done here !!!
355 SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP
356 } // TO KEEP
357}
358
359
360
361/**
362 Begin the secondary loop
363 @param a_prompt : label to display as the prompt label
364 */
365void G4UIQt::SecondaryLoop (
366 G4String aPrompt
367)
368{
369 if (!aPrompt) return;
370
371#ifdef GEANT4_QT_DEBUG
372 printf("G4UIQt::SecondaryLoop\n");
373#endif
374 G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ?
375 Prompt(aPrompt); // TO KEEP
376 exitPause = false; // TO KEEP
377 void* event; // TO KEEP
378 while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP
379 interactorManager->DispatchEvent(event); // TO KEEP
380 if(exitPause==true) break; // TO KEEP
381 } // TO KEEP
382 Prompt("session"); // TO KEEP
383}
384
385
386
387/**
388 Receive a cout from Geant4. We have to display it in the cout zone
389 @param aString : label to add in the display area
390 @return 0
391*/
392G4int G4UIQt::ReceiveG4cout (
393 G4String aString
394)
395{
396 if (!aString) return 0;
397 G4Qt* interactorManager = G4Qt::getInstance ();
398 if (!interactorManager) return 0;
399
400#if QT_VERSION < 0x040000
401 fTextArea->append(QString((char*)aString.data()).simplifyWhiteSpace());
402 fTextArea->verticalScrollBar()->setValue(fTextArea->verticalScrollBar()->maxValue());
403#else
404 fTextArea->append(QString((char*)aString.data()).trimmed());
405 fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum());
406#endif
407 interactorManager->FlushAndWaitExecution();
408 return 0;
409}
410
411
412/**
413 Receive a cerr from Geant4. We have to display it in the cout zone
414 @param aString : label to add in the display area
415 @return 0
416*/
417G4int G4UIQt::ReceiveG4cerr (
418 G4String aString
419)
420{
421 if (!aString) return 0;
422 G4Qt* interactorManager = G4Qt::getInstance ();
423 if (!interactorManager) return 0;
424
425#if QT_VERSION < 0x040000
426 QColor previousColor = fTextArea->color();
427 fTextArea->setColor(Qt::red);
428 fTextArea->append(QString((char*)aString.data()).simplifyWhiteSpace());
429 fTextArea->setColor(previousColor);
430 fTextArea->verticalScrollBar()->setValue(fTextArea->verticalScrollBar()->maxValue());
431#else
432 QColor previousColor = fTextArea->textColor();
433 fTextArea->setTextColor(Qt::red);
434 fTextArea->append(QString((char*)aString.data()).trimmed());
435 fTextArea->setTextColor(previousColor);
436 fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum());
437#endif
438 interactorManager->FlushAndWaitExecution();
439 return 0;
440}
441
442
443
444/**
445 Add a new menu to the menu bar
446 @param aName name of menu
447 @param aLabel label to display
448 */
449void G4UIQt::AddMenu (
450 const char* aName
451,const char* aLabel
452)
453{
454 if (aName == NULL) return;
455 if (aLabel == NULL) return;
456
457#if QT_VERSION < 0x040000
458 QPopupMenu *fileMenu = new QPopupMenu( fMainWindow);
459 fMainWindow->menuBar()->insertItem( aLabel, fileMenu );
460#else
461 QMenu *fileMenu = new QMenu(aLabel);
462 fMainWindow->menuBar()->insertMenu(fMainWindow->menuBar()->actions().last(),fileMenu);
463#endif
464
465 AddInteractor (aName,(G4Interactor)fileMenu);
466}
467
468
469/**
470 Add a new button to a menu
471 @param aMenu : parent menu
472 @param aLabel : label to display
473 @param aCommand : command to execute as a callback
474 */
475void G4UIQt::AddButton (
476 const char* aMenu
477,const char* aLabel
478,const char* aCommand
479)
480{
481 if(aMenu==NULL) return; // TO KEEP
482 if(aLabel==NULL) return; // TO KEEP
483 if(aCommand==NULL) return; // TO KEEP
484
485#if QT_VERSION < 0x040000
486 QPopupMenu *parent = (QPopupMenu*)GetInteractor(aMenu);
487#else
488 QMenu *parent = (QMenu*)GetInteractor(aMenu);
489#endif
490
491 if(parent==NULL) return;
492
493 QSignalMapper *signalMapper = new QSignalMapper(this);
494#if QT_VERSION < 0x030200
495 QAction *action = new QAction(QString(aLabel),QString(aLabel),QKeySequence::QKeySequence (),signalMapper, SLOT(map()));
496 action->addTo(parent);
497 connect(action,SIGNAL(activated()),signalMapper,SLOT(map()));
498
499#elif QT_VERSION < 0x040000
500 QAction *action = new QAction(QString(aLabel),QKeySequence::QKeySequence (),signalMapper, SLOT(map()));
501 action->addTo(parent);
502 connect(action,SIGNAL(activated()),signalMapper,SLOT(map()));
503
504#else
505 QAction *action = parent->addAction(aLabel, signalMapper, SLOT(map()));
506
507#endif
508 connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&)));
509 signalMapper->setMapping(action, QString(aCommand));
510}
511
512
513
514
515/**
516 Open the help dialog in a separate window.<br>
517 This will be display as a tree widget.<br>
518 Implementation of <b>void G4VBasicShell::TerminalHelp(G4String newCommand)</b>
519
520 @param newCommand : open the tree widget item on this command if is set
521*/
522void G4UIQt::TerminalHelp(
523 G4String newCommand
524)
525{
526 // Create the help dialog
527 if (!fHelpDialog) {
528#if QT_VERSION < 0x040000
529 fHelpDialog = new QDialog(0,0,FALSE,Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WStyle_MinMax );
530#else
531 fHelpDialog = new QDialog(0,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
532#endif
533 QVBoxLayout *vLayout = new QVBoxLayout(fHelpDialog);
534 QWidget *helpWidget = new QWidget(fHelpDialog);
535 QSplitter *splitter = new QSplitter(Qt::Horizontal,fHelpDialog);
536 QPushButton *exitButton = new QPushButton("Exit",fHelpDialog);
537 exitButton->setAutoDefault(false);
538 connect(exitButton, SIGNAL(clicked()), fHelpDialog,SLOT(close()));
539
540 QHBoxLayout *helpLayout = new QHBoxLayout(helpWidget);
541#if QT_VERSION < 0x040000
542 helpLayout->add(new QLabel("Search :",helpWidget));
543#else
544 helpLayout->addWidget(new QLabel("Search :",helpWidget));
545#endif
546 helpLine = new QLineEdit(fHelpDialog);
547#if QT_VERSION < 0x040000
548 helpLayout->add(helpLine);
549#else
550 helpLayout->addWidget(helpLine);
551#endif
552 connect( helpLine, SIGNAL( editingFinished () ), this, SLOT( lookForHelpStringCallback() ) );
553
554 // the help tree
555#if QT_VERSION < 0x040000
556 fHelpTreeWidget = new QListView(splitter);
557#else
558 fHelpTreeWidget = new QTreeWidget();
559#endif
560 fHelpTreeWidget = CreateHelpTree();
561
562 fHelpArea = new QTextEdit(splitter);
563 fHelpArea->setReadOnly(true);
564
565 // Set layouts
566
567#if QT_VERSION >= 0x040000
568 if (fHelpTreeWidget)
569 splitter->addWidget(fHelpTreeWidget);
570 splitter->addWidget(fHelpArea);
571#endif
572
573
574#if QT_VERSION >= 0x040000
575 vLayout->addWidget(helpWidget);
576 vLayout->addWidget(splitter,1);
577 vLayout->addWidget(exitButton);
578#else
579 vLayout->addWidget(helpWidget);
580 vLayout->add(splitter,1);
581 vLayout->addWidget(exitButton);
582#endif
583
584 // set the splitter size
585#if QT_VERSION >= 0x040000
586 QList<int> list;
587#else
588 QValueList<int> list;
589#endif
590 list.append( 400 );
591 list.append( 400 );
592 splitter->setSizes(list);
593
594#if QT_VERSION >= 0x040000
595 fHelpDialog->setLayout(vLayout);
596#endif
597
598 }
599
600 ActivateCommand(newCommand);
601
602#if QT_VERSION < 0x040000
603 fHelpDialog->setCaption( tr( "Help on commands" ));
604#else
605 fHelpDialog->setWindowTitle(tr("Help on commands"));
606#endif
607 fHelpDialog->resize(800,600);
608 fHelpDialog->move(QPoint(400,150));
609 fHelpDialog->show();
610 fHelpDialog->raise();
611#if QT_VERSION < 0x040000
612 fHelpDialog->setActiveWindow();
613#else
614 fHelpDialog->activateWindow();
615#endif
616}
617
618
619void G4UIQt::ActivateCommand(
620 G4String newCommand
621)
622{
623 if (!fHelpTreeWidget) {
624 return;
625 }
626 // Look for the choosen command "newCommand"
627 size_t i = newCommand.index(" ");
628 G4String targetCom="";
629 if( i != std::string::npos )
630 {
631 G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
632 newValue.strip(G4String::both);
633 targetCom = ModifyToFullPathCommand( newValue );
634 }
635 if (targetCom != "") {
636#if QT_VERSION < 0x040000
637 QListViewItem* findItem = NULL;
638 QListViewItem* tmpItem = fHelpTreeWidget->firstChild();
639 while (tmpItem != 0) {
640 if (!findItem) {
641 findItem = FindTreeItem(tmpItem,QString((char*)targetCom.data()));
642 }
643 tmpItem = tmpItem->nextSibling();
644 }
645#else
646 QTreeWidgetItem* findItem = NULL;
647 for (int a=0;a<fHelpTreeWidget->topLevelItemCount();a++) {
648 if (!findItem) {
649 findItem = FindTreeItem(fHelpTreeWidget->topLevelItem(a),QString((char*)targetCom.data()));
650 }
651 }
652#endif
653
654 if (findItem) {
655
656 //collapsed open item
657#if QT_VERSION < 0x040000
658
659 // FIXME : Has to be checked
660 QListViewItem* tmpItem = fHelpTreeWidget->firstChild();
661 QList<QListViewItem> openItems;
662 while ((tmpItem != 0) || (!openItems.isEmpty())) {
663 if (tmpItem->isOpen() ) {
664 tmpItem->setOpen(false);
665 openItems.append(tmpItem);
666 tmpItem = tmpItem->firstChild();
667 } else {
668 tmpItem = tmpItem->nextSibling();
669 }
670 if (tmpItem == 0) {
671 tmpItem = openItems.take(openItems.count()-1);
672 }
673 }
674#else
675 QList<QTreeWidgetItem *> selected;
676
677 selected = fHelpTreeWidget->selectedItems();
678 if ( selected.count() != 0 ) {
679 QTreeWidgetItem * tmp =selected.at( 0 );
680 while ( tmp) {
681#if QT_VERSION < 0x040202
682 fHelpTreeWidget->setItemExpanded(tmp,false);
683#else
684 tmp->setExpanded(false);
685#endif
686 tmp = tmp->parent();
687 }
688 }
689#endif
690
691 // clear old selection
692 fHelpTreeWidget->clearSelection();
693
694 // set new selection
695#if QT_VERSION >= 0x040000
696#if QT_VERSION < 0x040202
697 fHelpTreeWidget->setItemSelected(findItem,true);
698#else
699 findItem->setSelected(true);
700#endif
701#else
702 findItem->setSelected(true);
703#endif
704
705 // expand parent item
706 while ( findItem) {
707#if QT_VERSION < 0x040000
708 findItem->setOpen(true);
709#else
710#if QT_VERSION < 0x040202
711 fHelpTreeWidget->setItemExpanded(findItem,true);
712#else
713 findItem->setExpanded(true);
714#endif
715#endif
716 findItem = findItem->parent();
717 }
718
719 // Call the update of the right textArea
720 HelpTreeClicCallback();
721 }
722 }
723}
724
725
726
727/**
728 Create the help tree widget
729 @param parent : parent of tree widget
730 @return the widget containing the tree or NULL if it could not have beeen created
731 */
732
733#if QT_VERSION < 0x040000
734QListView * G4UIQt::CreateHelpTree()
735#else
736QTreeWidget * G4UIQt::CreateHelpTree()
737#endif
738{
739 G4UImanager* UI = G4UImanager::GetUIpointer();
740 if(UI==NULL) return NULL;
741 G4UIcommandTree * treeTop = UI->GetTree();
742
743
744 // build widget
745#if QT_VERSION < 0x040000
746 fHelpTreeWidget->setSelectionMode(QListView::Single);
747 fHelpTreeWidget->setRootIsDecorated(true);
748 fHelpTreeWidget->addColumn("Command");
749 fHelpTreeWidget->addColumn("Description",0);
750 // fHelpTreeWidget->setColumnWidth (1,0);
751 fHelpTreeWidget->header()->setResizeEnabled(FALSE,1);
752 // QList<QListViewItem *> items;
753#else
754 fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
755 fHelpTreeWidget->setColumnCount(2);
756 fHelpTreeWidget->setColumnHidden(1,true);
757 QStringList labels;
758 labels << QString("Command") << QString("Description");
759 fHelpTreeWidget->setHeaderLabels(labels);
760 // QList<QTreeWidgetItem *> items;
761#endif
762
763 G4int treeSize = treeTop->GetTreeEntry();
764#if QT_VERSION < 0x040000
765 QListViewItem * newItem;
766#else
767 QTreeWidgetItem * newItem;
768#endif
769 for (int a=0;a<treeSize;a++) {
770 // Creating new item
771
772#if QT_VERSION < 0x040000
773 newItem = new QListViewItem(fHelpTreeWidget);
774 newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace());
775 newItem->setText(1,QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).simplifyWhiteSpace());
776#else
777 newItem = new QTreeWidgetItem(fHelpTreeWidget);
778 newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed());
779 newItem->setText(1,QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).trimmed());
780#endif
781
782
783 // look for childs
784 CreateChildTree(newItem,treeTop->GetTree(a+1));
785 // items.append(newItem);
786 }
787
788
789#if QT_VERSION < 0x040000
790 connect(fHelpTreeWidget, SIGNAL(selectionChanged ()),this, SLOT(HelpTreeClicCallback()));
791 connect(fHelpTreeWidget, SIGNAL(doubleClicked (QListViewItem*)),this, SLOT(HelpTreeDoubleClicCallback()));
792#else
793 connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback()));
794 connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback()));
795#endif
796
797 return fHelpTreeWidget;
798}
799
800
801
802/** Fill the Help Tree Widget
803 @param aParent : parent item to fill
804 @param aCommandTree : commandTree node associate with this part of the Tree
805*/
806#if QT_VERSION < 0x040000
807void G4UIQt::CreateChildTree(
808 QListViewItem *aParent
809,G4UIcommandTree *aCommandTree
810#else
811void G4UIQt::CreateChildTree(
812 QTreeWidgetItem *aParent
813,G4UIcommandTree *aCommandTree
814#endif
815)
816{
817 if (aParent == NULL) return;
818 if (aCommandTree == NULL) return;
819
820
821 // Creating new item
822#if QT_VERSION < 0x040000
823 QListViewItem * newItem;
824#else
825 QTreeWidgetItem * newItem;
826#endif
827
828 // Get the Sub directories
829 for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
830
831#if QT_VERSION < 0x040000
832 newItem = new QListViewItem(aParent);
833 newItem->setText(0,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace());
834 newItem->setText(1,QString((char*)(aCommandTree->GetTree(a+1)->GetTitle()).data()).simplifyWhiteSpace());
835
836#else
837 newItem = new QTreeWidgetItem(aParent);
838 newItem->setText(0,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed());
839 newItem->setText(1,QString((char*)(aCommandTree->GetTree(a+1)->GetTitle()).data()).trimmed());
840#endif
841
842 CreateChildTree(newItem,aCommandTree->GetTree(a+1));
843 }
844
845
846
847 // Get the Commands
848
849 for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
850
851 QStringList stringList;
852#if QT_VERSION < 0x040000
853 newItem = new QListViewItem(aParent);
854 newItem->setText(0,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).simplifyWhiteSpace());
855 newItem->setText(1,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).simplifyWhiteSpace());
856 newItem->setOpen(false);
857
858#else
859 newItem = new QTreeWidgetItem(aParent);
860 newItem->setText(0,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed());
861 newItem->setText(1,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed());
862#if QT_VERSION < 0x040202
863 fHelpTreeWidget->setItemExpanded(newItem,false);
864#else
865 newItem->setExpanded(false);
866#endif
867#endif
868
869 }
870}
871
872
873/** Find a treeItemWidget in the help tree
874 @param aCommand item's String to look for
875 @return item if found, NULL if not
876*/
877#if QT_VERSION < 0x040000
878QListViewItem* G4UIQt::FindTreeItem(
879 QListViewItem *aParent
880#else
881QTreeWidgetItem* G4UIQt::FindTreeItem(
882 QTreeWidgetItem *aParent
883#endif
884,const QString& aCommand
885)
886{
887 if (aParent == NULL) return NULL;
888
889 if (aParent->text(0) == aCommand)
890 return aParent;
891
892#if QT_VERSION < 0x040000
893 QListViewItem * tmp = NULL;
894 QListViewItem* tmpItem = aParent->firstChild();
895 while (tmpItem != 0) {
896 if (!tmp)
897 tmp = FindTreeItem(tmpItem,aCommand);
898 tmpItem = tmpItem->nextSibling();
899 }
900
901#else
902 QTreeWidgetItem * tmp = NULL;
903 for (int a=0;a<aParent->childCount();a++) {
904 if (!tmp)
905 tmp = FindTreeItem(aParent->child(a),aCommand);
906 }
907#endif
908 return tmp;
909}
910
911
912/** Build the command list parameters in a QString<br>
913 Reimplement partialy the G4UIparameter.cc
914 @param aCommand : command to list parameters
915 @see G4UIparameter::List()
916 @see G4UIcommand::List()
917 @return the command list parameters, or "" if nothing
918*/
919QString G4UIQt::GetCommandList (
920 const G4UIcommand *aCommand
921)
922{
923
924 QString txt ="";
925 if (aCommand == NULL)
926 return txt;
927
928 G4String commandPath = aCommand->GetCommandPath();
929 G4String rangeString = aCommand->GetRange();
930 G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
931 G4int n_parameterEntry = aCommand->GetParameterEntries();
932
933 if ((commandPath == "") &&
934 (rangeString == "") &&
935 (n_guidanceEntry == 0) &&
936 (n_parameterEntry == 0)) {
937 return txt;
938 }
939
940 if((commandPath.length()-1)!='/') {
941 txt += "Command " + QString((char*)(commandPath).data()) + "\n";
942 }
943 txt += "Guidance :\n";
944
945 for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
946 txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
947 }
948 if( ! rangeString.isNull() ) {
949 txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n";
950 }
951 if( n_parameterEntry > 0 ) {
952 G4UIparameter *param;
953
954 // Re-implementation of G4UIparameter.cc
955
956 for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
957 param = aCommand->GetParameter(i_thParameter);
958 txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
959 if( ! param->GetParameterGuidance().isNull() )
960 txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
961 txt += " Parameter type : " + QString(QChar(param->GetParameterType())) + "\n";
962 if(param->IsOmittable()){
963 txt += " Omittable : True\n";
964 } else {
965 txt += " Omittable : False\n";
966 }
967 if( param->GetCurrentAsDefault() ) {
968 txt += " Default value : taken from the current value\n";
969 } else if( ! param->GetDefaultValue().isNull() ) {
970 txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n";
971 }
972 if( ! param->GetParameterRange().isNull() ) {
973 txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
974 }
975 if( ! param->GetParameterCandidates().isNull() ) {
976 txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
977 }
978 }
979 }
980 return txt;
981}
982
983
984
985/** Implement G4VBasicShell vurtual function
986 */
987G4bool G4UIQt::GetHelpChoice(
988 G4int& aInt
989)
990{
991#ifdef GEANT4_QT_DEBUG
992 printf("G4UIQt::GetHelpChoice SHOULD NEVER GO HERE");
993#endif
994 return true;
995}
996
997
998/** Implement G4VBasicShell vurtual function
999*/
1000void G4UIQt::ExitHelp(
1001)
1002{
1003#ifdef GEANT4_QT_DEBUG
1004 printf("G4UIQt::ExitHelp SHOULD NEVER GO HERE");
1005#endif
1006}
1007
1008
1009/** Event filter method. Every event from QtApplication goes here.<br/>
1010 We apply a filter only for the Up and Down Arrow press when the QLineEdit<br/>
1011 is active. If this filter match, Up arrow we give the previous command<br/>
1012 and Down arrow will give the next if exist.<br/>
1013 @param obj Emitter of the event
1014 @param event Kind of event
1015*/
1016bool G4UIQt::eventFilter( // Should stay with a minuscule eventFilter because of Qt
1017 QObject *aObj
1018,QEvent *aEvent
1019)
1020{
1021 if (aObj == NULL) return false;
1022 if (aEvent == NULL) return false;
1023
1024 if (aObj == fCommandHistoryArea) {
1025 if (aEvent->type() == QEvent::KeyPress) {
1026 fCommandArea->setFocus();
1027 }
1028 }
1029 if (aObj == fCommandArea) {
1030 if (aEvent->type() == QEvent::KeyPress) {
1031 QKeyEvent *e = static_cast<QKeyEvent*>(aEvent);
1032 if ((e->key() == (Qt::Key_Down)) ||
1033 (e->key() == (Qt::Key_PageDown)) ||
1034 (e->key() == (Qt::Key_Up)) ||
1035 (e->key() == (Qt::Key_PageUp))) {
1036#if QT_VERSION < 0x040000
1037 // count rows...
1038 QListViewItem* tmpItem = fCommandHistoryArea->firstChild();
1039 int selection = -1;
1040 int index = 0;
1041 while (tmpItem != 0) {
1042 if (tmpItem == fCommandHistoryArea->selectedItem()) {
1043 selection = index;
1044 }
1045 index ++;
1046 tmpItem = tmpItem->nextSibling();
1047 }
1048 if (fCommandHistoryArea->childCount()) {
1049 if (selection == -1) {
1050 selection = fCommandHistoryArea->childCount()-1;
1051 } else {
1052 if (e->key() == (Qt::Key_Down)) {
1053 if (selection <(fCommandHistoryArea->childCount()-1))
1054 selection++;
1055 } else if (e->key() == (Qt::Key_PageDown)) {
1056 selection = fCommandHistoryArea->childCount()-1;
1057#else
1058 int selection = fCommandHistoryArea->currentRow();
1059 if (fCommandHistoryArea->count()) {
1060 if (selection == -1) {
1061 selection = fCommandHistoryArea->count()-1;
1062 } else {
1063 if (e->key() == (Qt::Key_Down)) {
1064 if (selection <(fCommandHistoryArea->count()-1))
1065 selection++;
1066 } else if (e->key() == (Qt::Key_PageDown)) {
1067 selection = fCommandHistoryArea->count()-1;
1068#endif
1069 } else if (e->key() == (Qt::Key_Up)) {
1070 if (selection >0)
1071 selection --;
1072 } else if (e->key() == (Qt::Key_PageUp)) {
1073 selection = 0;
1074 }
1075 }
1076 fCommandHistoryArea->clearSelection();
1077#if QT_VERSION < 0x040000
1078 QListViewItem* tmpItem = fCommandHistoryArea->firstChild();
1079 int index = 0;
1080 while (tmpItem != 0) {
1081 if (index == selection) {
1082 tmpItem->setSelected(true);
1083 fCommandHistoryArea->setCurrentItem(tmpItem);
1084 }
1085 index ++;
1086 tmpItem = tmpItem->nextSibling();
1087 }
1088#else
1089#if QT_VERSION < 0x040202
1090 fCommandHistoryArea->setItemSelected(fCommandHistoryArea->item(selection),true);
1091#else
1092 fCommandHistoryArea->item(selection)->setSelected(true);
1093#endif
1094 fCommandHistoryArea->setCurrentItem(fCommandHistoryArea->item(selection));
1095#endif
1096 }
1097 } else if (e->key() == (Qt::Key_Tab)) {
1098#if QT_VERSION < 0x040000
1099 G4String ss = Complete(fCommandArea->text().ascii());
1100#else
1101 G4String ss = Complete(fCommandArea->text().toStdString().c_str());
1102#endif
1103 fCommandArea->setText((char*)(ss.data()));
1104
1105 // do not pass by parent, it will disable widget tab focus !
1106 return true;
1107 }
1108 }
1109 }
1110 // pass the event on to the parent class
1111 return QObject::eventFilter(aObj, aEvent);
1112}
1113
1114
1115
1116
1117/***************************************************************************/
1118//
1119// SLOTS DEFINITIONS
1120//
1121/***************************************************************************/
1122
1123/** Called when user give "help" command.
1124*/
1125void G4UIQt::ShowHelpCallback (
1126)
1127{
1128 TerminalHelp("");
1129}
1130
1131
1132/** Called when user click on clear button. Clear the text Output area
1133*/
1134void G4UIQt::ClearButtonCallback (
1135)
1136{
1137 fTextArea->clear();
1138}
1139
1140/** Called when user exit session
1141*/
1142void G4UIQt::ExitSession (
1143)
1144{
1145 SessionTerminate();
1146}
1147
1148
1149/** Callback call when "click on a menu entry.<br>
1150 Send the associated command to geant4
1151*/
1152void G4UIQt::CommandEnteredCallback (
1153)
1154{
1155#if QT_VERSION < 0x040000
1156 G4String command (fCommandArea->text().ascii());
1157 if (fCommandArea->text().simplifyWhiteSpace() != "") {
1158
1159 QListViewItem *newItem = new QListViewItem(fCommandHistoryArea);
1160 newItem->setText(0,fCommandArea->text());
1161 fCommandHistoryArea->insertItem(newItem);
1162 // now we have to arrange
1163 QListViewItem *temp= fCommandHistoryArea->lastItem();
1164 for (int i=0; i<fCommandHistoryArea->childCount()-1;i++) {
1165 fCommandHistoryArea->takeItem(temp);
1166 fCommandHistoryArea->insertItem(temp);
1167 temp= fCommandHistoryArea->lastItem();
1168 }
1169#else
1170 G4String command (fCommandArea->text().toStdString().c_str());
1171 if (fCommandArea->text().trimmed() != "") {
1172 fCommandHistoryArea->addItem(fCommandArea->text());
1173#endif
1174 fCommandHistoryArea->clearSelection();
1175 fCommandHistoryArea->setCurrentItem(NULL);
1176 fCommandArea->setText("");
1177
1178 G4Qt* interactorManager = G4Qt::getInstance ();
1179 if (interactorManager) {
1180 interactorManager->FlushAndWaitExecution();
1181 }
1182 if (command(0,4) != "help") {
1183 ApplyShellCommand (command,exitSession,exitPause);
1184 } else {
1185 TerminalHelp(command);
1186 }
1187 if(exitSession==true)
1188 SessionTerminate();
1189 }
1190}
1191
1192
1193/** Callback call when "enter" clicked on the command zone.<br>
1194 Send the command to geant4
1195 @param aCommand
1196*/
1197void G4UIQt::ButtonCallback (
1198 const QString& aCommand
1199)
1200{
1201#if QT_VERSION < 0x040000
1202 G4String ss = G4String(aCommand.ascii());
1203#else
1204 G4String ss = G4String(aCommand.toStdString().c_str());
1205#endif
1206 ApplyShellCommand(ss,exitSession,exitPause);
1207 if(exitSession==true)
1208 SessionTerminate();
1209}
1210
1211
1212
1213/** This callback is activated when user selected a item in the help tree
1214*/
1215void G4UIQt::HelpTreeClicCallback (
1216)
1217{
1218#if QT_VERSION < 0x040000
1219 QListViewItem* item = NULL;
1220#else
1221 QTreeWidgetItem* item = NULL;
1222#endif
1223 if (!fHelpTreeWidget)
1224 return ;
1225
1226 if (!fHelpArea)
1227 return;
1228
1229#if QT_VERSION < 0x040000
1230 item =fHelpTreeWidget->selectedItem();
1231#else
1232 QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
1233 if (list.isEmpty())
1234 return;
1235 item = list.first();
1236#endif
1237 if (!item)
1238 return;
1239
1240 G4UImanager* UI = G4UImanager::GetUIpointer();
1241 if(UI==NULL) return;
1242 G4UIcommandTree * treeTop = UI->GetTree();
1243#if QT_VERSION < 0x040000
1244 G4UIcommand* command = treeTop->FindPath(item->text (1).ascii());
1245#else
1246 G4UIcommand* command = treeTop->FindPath(item->text (1).toStdString().c_str());
1247#endif
1248 if (command) {
1249#if QT_VERSION >= 0x040000
1250#if QT_VERSION < 0x040200
1251 fHelpArea->clear();
1252 fHelpArea->append(GetCommandList(command));
1253#else
1254 fHelpArea->setText(GetCommandList(command));
1255#endif
1256#else
1257 fHelpArea->setText(GetCommandList(command));
1258#endif
1259 } else {
1260 // this is not a command, this is a sub directory
1261 // We display the Title
1262#if QT_VERSION >= 0x040000
1263#if QT_VERSION < 0x040200
1264 fHelpArea->clear();
1265 fHelpArea->append(command->GetTitle().data());
1266#else
1267 Command est nulle ici :comment récupérer le titre ?
1268
1269 printf("Command %s\n",(char*)(command->GetCommandPath()).data());
1270 printf("Command %s\n",(char*)(command->GetTitle()).data());
1271 fHelpArea->setText(command->GetTitle().data());
1272#endif
1273#else
1274 fHelpArea->setText(command->GetTitle().data());
1275#endif
1276 }
1277}
1278
1279/** This callback is activated when user double clic on a item in the help tree
1280*/
1281void G4UIQt::HelpTreeDoubleClicCallback (
1282)
1283{
1284 HelpTreeClicCallback();
1285
1286#if QT_VERSION < 0x040000
1287 QListViewItem* item = NULL;
1288#else
1289 QTreeWidgetItem* item = NULL;
1290#endif
1291 if (!fHelpTreeWidget)
1292 return ;
1293
1294 if (!fHelpArea)
1295 return;
1296
1297#if QT_VERSION < 0x040000
1298 item =fHelpTreeWidget->selectedItem();
1299#else
1300 QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
1301 if (list.isEmpty())
1302 return;
1303 item = list.first();
1304#endif
1305 if (!item)
1306 return;
1307
1308 fCommandArea->clear();
1309 fCommandArea->setText(item->text(1));
1310}
1311
1312
1313/** Callback called when user select an old command in the command history<br>
1314 Give it to the command area.
1315*/
1316void G4UIQt::CommandHistoryCallback(
1317)
1318{
1319#if QT_VERSION < 0x040000
1320 QListViewItem* item = NULL;
1321#else
1322 QListWidgetItem* item = NULL;
1323#endif
1324 if (!fCommandHistoryArea)
1325 return ;
1326
1327
1328#if QT_VERSION < 0x040000
1329 item =fCommandHistoryArea->selectedItem();
1330#else
1331 QList<QListWidgetItem *> list =fCommandHistoryArea->selectedItems();
1332 if (list.isEmpty())
1333 return;
1334 item = list.first();
1335#endif
1336 if (!item)
1337 return;
1338#if QT_VERSION < 0x040000
1339 fCommandArea->setText(item->text(0));
1340#else
1341 fCommandArea->setText(item->text());
1342#endif
1343
1344}
1345
1346
1347/** Callback called when user give a new string to look for<br>
1348 Display a list of matching commands descriptions. If no string is set,
1349 will display the complete help tree
1350*/
1351void G4UIQt::lookForHelpStringCallback(
1352)
1353{
1354#if QT_VERSION < 0x040200
1355 fHelpArea->clear();
1356#else
1357 fHelpArea->setText("");
1358#endif
1359 if (helpLine->text() =="") {
1360 // clear old help tree
1361 fHelpTreeWidget->clear();
1362 CreateHelpTree();
1363 return;
1364 }
1365
1366 // the help tree
1367 G4UImanager* UI = G4UImanager::GetUIpointer();
1368 if(UI==NULL) return;
1369 G4UIcommandTree * treeTop = UI->GetTree();
1370
1371 G4int treeSize = treeTop->GetTreeEntry();
1372
1373 // clear old help tree
1374 fHelpTreeWidget->clear();
1375
1376 // look for new items
1377
1378 int tmp = 0;
1379 QMap<int,QString> commandResultMap;
1380 QMap<int,QString> commandChildResultMap;
1381
1382 for (int a=0;a<treeSize;a++) {
1383#ifdef GEANT4_QT_DEBUG
1384 printf("Command %s\n",(char*)(treeTop->GetTree(a+1)->GetPathName()).data());
1385#endif
1386 G4UIcommand* command = treeTop->FindPath(treeTop->GetTree(a+1)->GetPathName().data());
1387 tmp = GetCommandList (command).count(helpLine->text(),Qt::CaseInsensitive);
1388 if (tmp >0) {
1389 commandResultMap.insertMulti(tmp,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()));
1390#ifdef GEANT4_QT_DEBUG
1391 printf("Command %s match %d times \n",(char*)(treeTop->GetTree(a+1)->GetPathName()).data(),tmp);
1392#endif
1393 }
1394 // look for childs
1395 commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a+1),helpLine->text());
1396 // insert new childs
1397 if (!commandChildResultMap.empty()) {
1398 QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
1399 while (i != commandChildResultMap.constEnd()) {
1400 commandResultMap.insertMulti(i.key(),i.value());
1401 i++;
1402 }
1403 commandChildResultMap.clear();
1404 }
1405 }
1406
1407 // build new help tree
1408#if QT_VERSION < 0x040000
1409 fHelpTreeWidget->setSelectionMode(QListView::Single);
1410 fHelpTreeWidget->setRootIsDecorated(true);
1411 fHelpTreeWidget->addColumn("Command");
1412 fHelpTreeWidget->addColumn("Description",0);
1413 fHelpTreeWidget->addColumn("Match");
1414 // fHelpTreeWidget->header()->setResizeEnabled(FALSE,1);
1415#else
1416 fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
1417 fHelpTreeWidget->setColumnCount(3);
1418 fHelpTreeWidget->setColumnHidden(1,true);
1419 QStringList labels;
1420 labels << QString("Command") << QString("Description") << QString("Match");
1421 fHelpTreeWidget->setHeaderLabels(labels);
1422#endif
1423
1424 if (commandResultMap.empty()) {
1425#if QT_VERSION < 0x040200
1426 fHelpArea->clear();
1427 fHelpArea->append("No match found");
1428#else
1429 fHelpArea->setText("No match found");
1430#endif
1431 return;
1432 }
1433
1434 QMap<int,QString>::const_iterator i = commandResultMap.constEnd();
1435 i--;
1436 // 10 maximum progress values
1437 float multValue = 10.0/(float)(i.key());
1438 QString progressChar = "|";
1439 QString progressStr = "|";
1440
1441#if QT_VERSION < 0x040000
1442 QListViewItem * newItem;
1443#else
1444 QTreeWidgetItem * newItem;
1445#endif
1446 bool end = false;
1447 while (!end) {
1448 if (i == commandResultMap.constBegin()) {
1449 end = true;
1450 }
1451 for(int a=0;a<int(i.key()*multValue);a++) {
1452 progressStr += progressChar;
1453 }
1454#if QT_VERSION < 0x040000
1455 newItem = new QListViewItem(fHelpTreeWidget);
1456 newItem->setText(0,i.value().simplifyWhiteSpace());
1457 newItem->setText(1,i.value().simplifyWhiteSpace());
1458
1459 newItem->setText(2,progressStr);
1460#else
1461 newItem = new QTreeWidgetItem(fHelpTreeWidget);
1462 newItem->setText(0,i.value().trimmed());
1463 newItem->setText(1,i.value().trimmed());
1464 newItem->setText(2,progressStr);
1465#endif
1466
1467#if QT_VERSION >= 0x040200
1468 newItem->setForeground ( 2, QBrush(Qt::blue) );
1469#endif
1470 progressStr = "|";
1471 i--;
1472 }
1473 // FIXME : to be checked on Qt3
1474#if QT_VERSION < 0x040000
1475 fHelpTreeWidget->setColumnWidthMode (0,QListView::Maximum);
1476#else
1477 fHelpTreeWidget->resizeColumnToContents (0);
1478#endif
1479}
1480
1481
1482
1483
1484QMap<int,QString> G4UIQt::LookForHelpStringInChildTree(
1485 G4UIcommandTree *aCommandTree
1486,const QString & text
1487 )
1488{
1489 QMap<int,QString> commandResultMap;
1490 if (aCommandTree == NULL) return commandResultMap;
1491
1492 // Get the Sub directories
1493 int tmp = 0;
1494 QMap<int,QString> commandChildResultMap;
1495
1496 for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
1497 const G4UIcommand* command = aCommandTree->GetGuidance();
1498#ifdef GEANT4_QT_DEBUG
1499 printf("Command loop \n");
1500 // printf("Command %s\n",(char*)(aCommandTree->GetTree(a+1)->GetPathName()).data());
1501 // printf("%s \n",GetCommandList (command).toStdString().c_str());
1502#endif
1503 tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
1504 if (tmp >0) {
1505 commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()));
1506#ifdef GEANT4_QT_DEBUG
1507 printf("---Command %s match %d times \n",(char*)(aCommandTree->GetTree(a+1)->GetPathName()).data(),tmp);
1508#endif
1509 }
1510 // look for childs
1511 commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text);
1512
1513 if (!commandChildResultMap.empty()) {
1514 printf("Check -------------------in child %d\n",commandChildResultMap.count());
1515 // insert new childs
1516 QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
1517 while (i != commandChildResultMap.constEnd()) {
1518 commandResultMap.insertMulti(i.key(),i.value());
1519 i++;
1520 }
1521 commandChildResultMap.clear();
1522 }
1523 }
1524 // Get the Commands
1525
1526 for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
1527 const G4UIcommand* command = aCommandTree->GetCommand(a+1);
1528#ifdef GEANT4_QT_DEBUG
1529 printf("Command Finale debut\n");
1530 // printf("%s \n",GetCommandList (command).toStdString().c_str());
1531#endif
1532 tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
1533 if (tmp >0) {
1534 commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()));
1535#ifdef GEANT4_QT_DEBUG
1536 printf("---Command Finale %s match %d times \n",(char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data(),tmp);
1537#endif
1538 }
1539
1540 }
1541 printf("Command Finale retun \n");
1542 return commandResultMap;
1543}
1544#endif
Note: See TracBrowser for help on using the repository browser.