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

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

zone de recherche OK

  • Property svn:mime-type set to text/cpp
File size: 40.5 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->header()->setResizeEnabled(FALSE,1);
750#else
751 fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
752 QStringList labels;
753 labels << QString("Command");
754 fHelpTreeWidget->setHeaderLabels(labels);
755#endif
756
757 G4int treeSize = treeTop->GetTreeEntry();
758#if QT_VERSION < 0x040000
759 QListViewItem * newItem;
760#else
761 QTreeWidgetItem * newItem;
762#endif
763 for (int a=0;a<treeSize;a++) {
764 // Creating new item
765
766#if QT_VERSION < 0x040000
767 newItem = new QListViewItem(fHelpTreeWidget);
768 newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace());
769#else
770 newItem = new QTreeWidgetItem(fHelpTreeWidget);
771 newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed());
772#endif
773
774
775 // look for childs
776 CreateChildTree(newItem,treeTop->GetTree(a+1));
777 // items.append(newItem);
778 }
779
780
781#if QT_VERSION < 0x040000
782 connect(fHelpTreeWidget, SIGNAL(selectionChanged ()),this, SLOT(HelpTreeClicCallback()));
783 connect(fHelpTreeWidget, SIGNAL(doubleClicked (QListViewItem*)),this, SLOT(HelpTreeDoubleClicCallback()));
784#else
785 connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback()));
786 connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback()));
787#endif
788
789 return fHelpTreeWidget;
790}
791
792
793
794/** Fill the Help Tree Widget
795 @param aParent : parent item to fill
796 @param aCommandTree : commandTree node associate with this part of the Tree
797*/
798#if QT_VERSION < 0x040000
799void G4UIQt::CreateChildTree(
800 QListViewItem *aParent
801,G4UIcommandTree *aCommandTree
802#else
803void G4UIQt::CreateChildTree(
804 QTreeWidgetItem *aParent
805,G4UIcommandTree *aCommandTree
806#endif
807)
808{
809 if (aParent == NULL) return;
810 if (aCommandTree == NULL) return;
811
812
813 // Creating new item
814#if QT_VERSION < 0x040000
815 QListViewItem * newItem;
816#else
817 QTreeWidgetItem * newItem;
818#endif
819
820 // Get the Sub directories
821 for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
822
823#if QT_VERSION < 0x040000
824 newItem = new QListViewItem(aParent);
825 newItem->setText(0,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace());
826
827#else
828 newItem = new QTreeWidgetItem(aParent);
829 newItem->setText(0,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed());
830#endif
831
832 CreateChildTree(newItem,aCommandTree->GetTree(a+1));
833 }
834
835
836
837 // Get the Commands
838
839 for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
840
841 QStringList stringList;
842#if QT_VERSION < 0x040000
843 newItem = new QListViewItem(aParent);
844 newItem->setText(0,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).simplifyWhiteSpace());
845 newItem->setOpen(false);
846
847#else
848 newItem = new QTreeWidgetItem(aParent);
849 newItem->setText(0,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed());
850#if QT_VERSION < 0x040202
851 fHelpTreeWidget->setItemExpanded(newItem,false);
852#else
853 newItem->setExpanded(false);
854#endif
855#endif
856
857 }
858}
859
860
861/** Find a treeItemWidget in the help tree
862 @param aCommand item's String to look for
863 @return item if found, NULL if not
864*/
865#if QT_VERSION < 0x040000
866QListViewItem* G4UIQt::FindTreeItem(
867 QListViewItem *aParent
868#else
869QTreeWidgetItem* G4UIQt::FindTreeItem(
870 QTreeWidgetItem *aParent
871#endif
872,const QString& aCommand
873)
874{
875 if (aParent == NULL) return NULL;
876
877 if (aParent->text(0) == aCommand)
878 return aParent;
879
880#if QT_VERSION < 0x040000
881 QListViewItem * tmp = NULL;
882 QListViewItem* tmpItem = aParent->firstChild();
883 while (tmpItem != 0) {
884 if (!tmp)
885 tmp = FindTreeItem(tmpItem,aCommand);
886 tmpItem = tmpItem->nextSibling();
887 }
888
889#else
890 QTreeWidgetItem * tmp = NULL;
891 for (int a=0;a<aParent->childCount();a++) {
892 if (!tmp)
893 tmp = FindTreeItem(aParent->child(a),aCommand);
894 }
895#endif
896 return tmp;
897}
898
899
900/** Build the command list parameters in a QString<br>
901 Reimplement partialy the G4UIparameter.cc
902 @param aCommand : command to list parameters
903 @see G4UIparameter::List()
904 @see G4UIcommand::List()
905 @return the command list parameters, or "" if nothing
906*/
907QString G4UIQt::GetCommandList (
908 const G4UIcommand *aCommand
909)
910{
911
912 QString txt ="";
913 if (aCommand == NULL)
914 return txt;
915
916 G4String commandPath = aCommand->GetCommandPath();
917 G4String rangeString = aCommand->GetRange();
918 G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
919 G4int n_parameterEntry = aCommand->GetParameterEntries();
920
921 if ((commandPath == "") &&
922 (rangeString == "") &&
923 (n_guidanceEntry == 0) &&
924 (n_parameterEntry == 0)) {
925 return txt;
926 }
927
928 if((commandPath.length()-1)!='/') {
929 txt += "Command " + QString((char*)(commandPath).data()) + "\n";
930 }
931 txt += "Guidance :\n";
932
933 for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
934 txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
935 }
936 if( ! rangeString.isNull() ) {
937 txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n";
938 }
939 if( n_parameterEntry > 0 ) {
940 G4UIparameter *param;
941
942 // Re-implementation of G4UIparameter.cc
943
944 for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
945 param = aCommand->GetParameter(i_thParameter);
946 txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
947 if( ! param->GetParameterGuidance().isNull() )
948 txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
949 txt += " Parameter type : " + QString(QChar(param->GetParameterType())) + "\n";
950 if(param->IsOmittable()){
951 txt += " Omittable : True\n";
952 } else {
953 txt += " Omittable : False\n";
954 }
955 if( param->GetCurrentAsDefault() ) {
956 txt += " Default value : taken from the current value\n";
957 } else if( ! param->GetDefaultValue().isNull() ) {
958 txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n";
959 }
960 if( ! param->GetParameterRange().isNull() ) {
961 txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
962 }
963 if( ! param->GetParameterCandidates().isNull() ) {
964 txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
965 }
966 }
967 }
968 return txt;
969}
970
971
972
973/** Implement G4VBasicShell vurtual function
974 */
975G4bool G4UIQt::GetHelpChoice(
976 G4int& aInt
977)
978{
979#ifdef GEANT4_QT_DEBUG
980 printf("G4UIQt::GetHelpChoice SHOULD NEVER GO HERE");
981#endif
982 return true;
983}
984
985
986/** Implement G4VBasicShell vurtual function
987*/
988void G4UIQt::ExitHelp(
989)
990{
991#ifdef GEANT4_QT_DEBUG
992 printf("G4UIQt::ExitHelp SHOULD NEVER GO HERE");
993#endif
994}
995
996
997/** Event filter method. Every event from QtApplication goes here.<br/>
998 We apply a filter only for the Up and Down Arrow press when the QLineEdit<br/>
999 is active. If this filter match, Up arrow we give the previous command<br/>
1000 and Down arrow will give the next if exist.<br/>
1001 @param obj Emitter of the event
1002 @param event Kind of event
1003*/
1004bool G4UIQt::eventFilter( // Should stay with a minuscule eventFilter because of Qt
1005 QObject *aObj
1006,QEvent *aEvent
1007)
1008{
1009 if (aObj == NULL) return false;
1010 if (aEvent == NULL) return false;
1011
1012 if (aObj == fCommandHistoryArea) {
1013 if (aEvent->type() == QEvent::KeyPress) {
1014 fCommandArea->setFocus();
1015 }
1016 }
1017 if (aObj == fCommandArea) {
1018 if (aEvent->type() == QEvent::KeyPress) {
1019 QKeyEvent *e = static_cast<QKeyEvent*>(aEvent);
1020 if ((e->key() == (Qt::Key_Down)) ||
1021 (e->key() == (Qt::Key_PageDown)) ||
1022 (e->key() == (Qt::Key_Up)) ||
1023 (e->key() == (Qt::Key_PageUp))) {
1024#if QT_VERSION < 0x040000
1025 // count rows...
1026 QListViewItem* tmpItem = fCommandHistoryArea->firstChild();
1027 int selection = -1;
1028 int index = 0;
1029 while (tmpItem != 0) {
1030 if (tmpItem == fCommandHistoryArea->selectedItem()) {
1031 selection = index;
1032 }
1033 index ++;
1034 tmpItem = tmpItem->nextSibling();
1035 }
1036 if (fCommandHistoryArea->childCount()) {
1037 if (selection == -1) {
1038 selection = fCommandHistoryArea->childCount()-1;
1039 } else {
1040 if (e->key() == (Qt::Key_Down)) {
1041 if (selection <(fCommandHistoryArea->childCount()-1))
1042 selection++;
1043 } else if (e->key() == (Qt::Key_PageDown)) {
1044 selection = fCommandHistoryArea->childCount()-1;
1045#else
1046 int selection = fCommandHistoryArea->currentRow();
1047 if (fCommandHistoryArea->count()) {
1048 if (selection == -1) {
1049 selection = fCommandHistoryArea->count()-1;
1050 } else {
1051 if (e->key() == (Qt::Key_Down)) {
1052 if (selection <(fCommandHistoryArea->count()-1))
1053 selection++;
1054 } else if (e->key() == (Qt::Key_PageDown)) {
1055 selection = fCommandHistoryArea->count()-1;
1056#endif
1057 } else if (e->key() == (Qt::Key_Up)) {
1058 if (selection >0)
1059 selection --;
1060 } else if (e->key() == (Qt::Key_PageUp)) {
1061 selection = 0;
1062 }
1063 }
1064 fCommandHistoryArea->clearSelection();
1065#if QT_VERSION < 0x040000
1066 QListViewItem* tmpItem = fCommandHistoryArea->firstChild();
1067 int index = 0;
1068 while (tmpItem != 0) {
1069 if (index == selection) {
1070 tmpItem->setSelected(true);
1071 fCommandHistoryArea->setCurrentItem(tmpItem);
1072 }
1073 index ++;
1074 tmpItem = tmpItem->nextSibling();
1075 }
1076#else
1077#if QT_VERSION < 0x040202
1078 fCommandHistoryArea->setItemSelected(fCommandHistoryArea->item(selection),true);
1079#else
1080 fCommandHistoryArea->item(selection)->setSelected(true);
1081#endif
1082 fCommandHistoryArea->setCurrentItem(fCommandHistoryArea->item(selection));
1083#endif
1084 }
1085 } else if (e->key() == (Qt::Key_Tab)) {
1086#if QT_VERSION < 0x040000
1087 G4String ss = Complete(fCommandArea->text().ascii());
1088#else
1089 G4String ss = Complete(fCommandArea->text().toStdString().c_str());
1090#endif
1091 fCommandArea->setText((char*)(ss.data()));
1092
1093 // do not pass by parent, it will disable widget tab focus !
1094 return true;
1095 }
1096 }
1097 }
1098 // pass the event on to the parent class
1099 return QObject::eventFilter(aObj, aEvent);
1100}
1101
1102
1103
1104
1105/***************************************************************************/
1106//
1107// SLOTS DEFINITIONS
1108//
1109/***************************************************************************/
1110
1111/** Called when user give "help" command.
1112*/
1113void G4UIQt::ShowHelpCallback (
1114)
1115{
1116 TerminalHelp("");
1117}
1118
1119
1120/** Called when user click on clear button. Clear the text Output area
1121*/
1122void G4UIQt::ClearButtonCallback (
1123)
1124{
1125 fTextArea->clear();
1126}
1127
1128/** Called when user exit session
1129*/
1130void G4UIQt::ExitSession (
1131)
1132{
1133 SessionTerminate();
1134}
1135
1136
1137/** Callback call when "click on a menu entry.<br>
1138 Send the associated command to geant4
1139*/
1140void G4UIQt::CommandEnteredCallback (
1141)
1142{
1143#if QT_VERSION < 0x040000
1144 G4String command (fCommandArea->text().ascii());
1145 if (fCommandArea->text().simplifyWhiteSpace() != "") {
1146
1147 QListViewItem *newItem = new QListViewItem(fCommandHistoryArea);
1148 newItem->setText(0,fCommandArea->text());
1149 fCommandHistoryArea->insertItem(newItem);
1150 // now we have to arrange
1151 QListViewItem *temp= fCommandHistoryArea->lastItem();
1152 for (int i=0; i<fCommandHistoryArea->childCount()-1;i++) {
1153 fCommandHistoryArea->takeItem(temp);
1154 fCommandHistoryArea->insertItem(temp);
1155 temp= fCommandHistoryArea->lastItem();
1156 }
1157#else
1158 G4String command (fCommandArea->text().toStdString().c_str());
1159 if (fCommandArea->text().trimmed() != "") {
1160 fCommandHistoryArea->addItem(fCommandArea->text());
1161#endif
1162 fCommandHistoryArea->clearSelection();
1163 fCommandHistoryArea->setCurrentItem(NULL);
1164 fCommandArea->setText("");
1165
1166 G4Qt* interactorManager = G4Qt::getInstance ();
1167 if (interactorManager) {
1168 interactorManager->FlushAndWaitExecution();
1169 }
1170 if (command(0,4) != "help") {
1171 ApplyShellCommand (command,exitSession,exitPause);
1172 } else {
1173 TerminalHelp(command);
1174 }
1175 if(exitSession==true)
1176 SessionTerminate();
1177 }
1178}
1179
1180
1181/** Callback call when "enter" clicked on the command zone.<br>
1182 Send the command to geant4
1183 @param aCommand
1184*/
1185void G4UIQt::ButtonCallback (
1186 const QString& aCommand
1187)
1188{
1189#if QT_VERSION < 0x040000
1190 G4String ss = G4String(aCommand.ascii());
1191#else
1192 G4String ss = G4String(aCommand.toStdString().c_str());
1193#endif
1194 ApplyShellCommand(ss,exitSession,exitPause);
1195 if(exitSession==true)
1196 SessionTerminate();
1197}
1198
1199
1200
1201/** This callback is activated when user selected a item in the help tree
1202*/
1203void G4UIQt::HelpTreeClicCallback (
1204)
1205{
1206#if QT_VERSION < 0x040000
1207 QListViewItem* item = NULL;
1208#else
1209 QTreeWidgetItem* item = NULL;
1210#endif
1211 if (!fHelpTreeWidget)
1212 return ;
1213
1214 if (!fHelpArea)
1215 return;
1216
1217#if QT_VERSION < 0x040000
1218 item =fHelpTreeWidget->selectedItem();
1219#else
1220 QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
1221 if (list.isEmpty())
1222 return;
1223 item = list.first();
1224#endif
1225 if (!item)
1226 return;
1227
1228 G4UImanager* UI = G4UImanager::GetUIpointer();
1229 if(UI==NULL) return;
1230 G4UIcommandTree * treeTop = UI->GetTree();
1231
1232
1233
1234 std::string itemText;
1235#if QT_VERSION < 0x040000
1236 itemText = std::string(item->text(0).ascii());
1237#else
1238 itemText = std::string(item->text(0).toStdString());
1239#endif
1240
1241 G4UIcommand* command = treeTop->FindPath(itemText.c_str());
1242
1243 if (command) {
1244#if QT_VERSION >= 0x040000
1245#if QT_VERSION < 0x040200
1246 fHelpArea->clear();
1247 fHelpArea->append(GetCommandList(command));
1248#else
1249 fHelpArea->setText(GetCommandList(command));
1250#endif
1251#else
1252 fHelpArea->setText(GetCommandList(command));
1253#endif
1254 } else { // this is a command
1255 G4UIcommandTree* path = treeTop->FindCommandTree(itemText.c_str());
1256 if ( path) {
1257 // this is not a command, this is a sub directory
1258 // We display the Title
1259#if QT_VERSION >= 0x040000
1260#if QT_VERSION < 0x040200
1261 fHelpArea->clear();
1262 fHelpArea->append(path->GetTitle().data());
1263#else
1264 fHelpArea->setText(path->GetTitle().data());
1265#endif
1266#else
1267 fHelpArea->setText(path->GetTitle().data());
1268#endif
1269 }
1270 }
1271}
1272
1273/** This callback is activated when user double clic on a item in the help tree
1274*/
1275void G4UIQt::HelpTreeDoubleClicCallback (
1276)
1277{
1278 HelpTreeClicCallback();
1279
1280#if QT_VERSION < 0x040000
1281 QListViewItem* item = NULL;
1282#else
1283 QTreeWidgetItem* item = NULL;
1284#endif
1285 if (!fHelpTreeWidget)
1286 return ;
1287
1288 if (!fHelpArea)
1289 return;
1290
1291#if QT_VERSION < 0x040000
1292 item =fHelpTreeWidget->selectedItem();
1293#else
1294 QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
1295 if (list.isEmpty())
1296 return;
1297 item = list.first();
1298#endif
1299 if (!item)
1300 return;
1301
1302 fCommandArea->clear();
1303 fCommandArea->setText(item->text(0));
1304}
1305
1306
1307/** Callback called when user select an old command in the command history<br>
1308 Give it to the command area.
1309*/
1310void G4UIQt::CommandHistoryCallback(
1311)
1312{
1313#if QT_VERSION < 0x040000
1314 QListViewItem* item = NULL;
1315#else
1316 QListWidgetItem* item = NULL;
1317#endif
1318 if (!fCommandHistoryArea)
1319 return ;
1320
1321
1322#if QT_VERSION < 0x040000
1323 item =fCommandHistoryArea->selectedItem();
1324#else
1325 QList<QListWidgetItem *> list =fCommandHistoryArea->selectedItems();
1326 if (list.isEmpty())
1327 return;
1328 item = list.first();
1329#endif
1330 if (!item)
1331 return;
1332#if QT_VERSION < 0x040000
1333 fCommandArea->setText(item->text(0));
1334#else
1335 fCommandArea->setText(item->text());
1336#endif
1337
1338}
1339
1340
1341/** Callback called when user give a new string to look for<br>
1342 Display a list of matching commands descriptions. If no string is set,
1343 will display the complete help tree
1344*/
1345void G4UIQt::lookForHelpStringCallback(
1346)
1347{
1348#if QT_VERSION < 0x040200
1349 fHelpArea->clear();
1350#else
1351 fHelpArea->setText("");
1352#endif
1353 if (helpLine->text() =="") {
1354 // clear old help tree
1355 fHelpTreeWidget->clear();
1356 CreateHelpTree();
1357 return;
1358 }
1359
1360 // the help tree
1361 G4UImanager* UI = G4UImanager::GetUIpointer();
1362 if(UI==NULL) return;
1363 G4UIcommandTree * treeTop = UI->GetTree();
1364
1365 G4int treeSize = treeTop->GetTreeEntry();
1366
1367 // clear old help tree
1368 fHelpTreeWidget->clear();
1369
1370 // look for new items
1371
1372 int tmp = 0;
1373 QMap<int,QString> commandResultMap;
1374 QMap<int,QString> commandChildResultMap;
1375
1376 for (int a=0;a<treeSize;a++) {
1377#ifdef GEANT4_QT_DEBUG
1378 printf("Command %s\n",(char*)(treeTop->GetTree(a+1)->GetPathName()).data());
1379#endif
1380 G4UIcommand* command = treeTop->FindPath(treeTop->GetTree(a+1)->GetPathName().data());
1381 tmp = GetCommandList (command).count(helpLine->text(),Qt::CaseInsensitive);
1382 if (tmp >0) {
1383 commandResultMap.insertMulti(tmp,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()));
1384#ifdef GEANT4_QT_DEBUG
1385 printf("Command %s match %d times \n",(char*)(treeTop->GetTree(a+1)->GetPathName()).data(),tmp);
1386#endif
1387 }
1388 // look for childs
1389 commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a+1),helpLine->text());
1390 // insert new childs
1391 if (!commandChildResultMap.empty()) {
1392 QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
1393 while (i != commandChildResultMap.constEnd()) {
1394 commandResultMap.insertMulti(i.key(),i.value());
1395 i++;
1396 }
1397 commandChildResultMap.clear();
1398 }
1399 }
1400
1401 // build new help tree
1402#if QT_VERSION < 0x040000
1403 fHelpTreeWidget->setSelectionMode(QListView::Single);
1404 fHelpTreeWidget->setRootIsDecorated(true);
1405 fHelpTreeWidget->addColumn("Command");
1406 fHelpTreeWidget->addColumn("Match");
1407 // fHelpTreeWidget->header()->setResizeEnabled(FALSE,1);
1408#else
1409 fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
1410 fHelpTreeWidget->setColumnCount(2);
1411 QStringList labels;
1412 labels << QString("Command") << QString("Match");
1413 fHelpTreeWidget->setHeaderLabels(labels);
1414#endif
1415
1416 if (commandResultMap.empty()) {
1417#if QT_VERSION < 0x040200
1418 fHelpArea->clear();
1419 fHelpArea->append("No match found");
1420#else
1421 fHelpArea->setText("No match found");
1422#endif
1423 return;
1424 }
1425
1426 QMap<int,QString>::const_iterator i = commandResultMap.constEnd();
1427 i--;
1428 // 10 maximum progress values
1429 float multValue = 10.0/(float)(i.key());
1430 QString progressChar = "|";
1431 QString progressStr = "|";
1432
1433#if QT_VERSION < 0x040000
1434 QListViewItem * newItem;
1435#else
1436 QTreeWidgetItem * newItem;
1437#endif
1438 bool end = false;
1439 while (!end) {
1440 if (i == commandResultMap.constBegin()) {
1441 end = true;
1442 }
1443 for(int a=0;a<int(i.key()*multValue);a++) {
1444 progressStr += progressChar;
1445 }
1446#if QT_VERSION < 0x040000
1447 newItem = new QListViewItem(fHelpTreeWidget);
1448 newItem->setText(0,i.value().simplifyWhiteSpace());
1449 newItem->setText(1,progressStr);
1450#else
1451 newItem = new QTreeWidgetItem(fHelpTreeWidget);
1452 newItem->setText(0,i.value().trimmed());
1453 newItem->setText(1,progressStr);
1454#endif
1455
1456#if QT_VERSION >= 0x040200
1457 newItem->setForeground ( 1, QBrush(Qt::blue) );
1458#endif
1459 progressStr = "|";
1460 i--;
1461 }
1462 // FIXME : to be checked on Qt3
1463#if QT_VERSION < 0x040000
1464 fHelpTreeWidget->setColumnWidthMode (1,QListView::Maximum);
1465#else
1466 fHelpTreeWidget->resizeColumnToContents (0);
1467 // fHelpTreeWidget->setColumnWidth(1,10);//resizeColumnToContents (1);
1468#endif
1469}
1470
1471
1472
1473
1474QMap<int,QString> G4UIQt::LookForHelpStringInChildTree(
1475 G4UIcommandTree *aCommandTree
1476,const QString & text
1477 )
1478{
1479 QMap<int,QString> commandResultMap;
1480 if (aCommandTree == NULL) return commandResultMap;
1481
1482 // Get the Sub directories
1483 int tmp = 0;
1484 QMap<int,QString> commandChildResultMap;
1485
1486 for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
1487 const G4UIcommand* command = aCommandTree->GetGuidance();
1488 tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
1489 if (tmp >0) {
1490 commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()));
1491 }
1492 // look for childs
1493 commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text);
1494
1495 if (!commandChildResultMap.empty()) {
1496 // insert new childs
1497 QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
1498 while (i != commandChildResultMap.constEnd()) {
1499 commandResultMap.insertMulti(i.key(),i.value());
1500 i++;
1501 }
1502 commandChildResultMap.clear();
1503 }
1504 }
1505 // Get the Commands
1506
1507 for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
1508 const G4UIcommand* command = aCommandTree->GetCommand(a+1);
1509#ifdef GEANT4_QT_DEBUG
1510 // printf("%s \n",GetCommandList (command).toStdString().c_str());
1511#endif
1512 tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
1513 if (tmp >0) {
1514 commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()));
1515#ifdef GEANT4_QT_DEBUG
1516#endif
1517 }
1518
1519 }
1520 return commandResultMap;
1521}
1522#endif
Note: See TracBrowser for help on using the repository browser.