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

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

Correction du ticket #117

  • Property svn:mime-type set to text/cpp
File size: 43.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.15 2008/01/30 11:16:17 lgarnier Exp $
28// GEANT4 tag $Name: HEAD $
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 connect( helpLine, SIGNAL( returnPressed () ), this, SLOT( lookForHelpStringCallback() ) );
550#else
551 helpLayout->addWidget(helpLine);
552 connect( helpLine, SIGNAL( editingFinished () ), this, SLOT( lookForHelpStringCallback() ) );
553#endif
554
555 // the help tree
556#if QT_VERSION < 0x040000
557 fHelpTreeWidget = new QListView(splitter);
558#else
559 fHelpTreeWidget = new QTreeWidget();
560#endif
561 fHelpTreeWidget = CreateHelpTree();
562
563 fHelpArea = new QTextEdit(splitter);
564 fHelpArea->setReadOnly(true);
565
566 // Set layouts
567
568#if QT_VERSION >= 0x040000
569 if (fHelpTreeWidget)
570 splitter->addWidget(fHelpTreeWidget);
571 splitter->addWidget(fHelpArea);
572#endif
573
574
575#if QT_VERSION >= 0x040000
576 vLayout->addWidget(helpWidget);
577 vLayout->addWidget(splitter,1);
578 vLayout->addWidget(exitButton);
579#else
580 vLayout->addWidget(helpWidget);
581 vLayout->addWidget(splitter,1);
582 vLayout->addWidget(exitButton);
583#endif
584
585 // set the splitter size
586#if QT_VERSION >= 0x040000
587 QList<int> list;
588#else
589 QValueList<int> list;
590#endif
591 list.append( 400 );
592 list.append( 400 );
593 splitter->setSizes(list);
594
595#if QT_VERSION >= 0x040000
596 fHelpDialog->setLayout(vLayout);
597#endif
598
599 }
600
601 ActivateCommand(newCommand);
602
603#if QT_VERSION < 0x040000
604 fHelpDialog->setCaption( tr( "Help on commands" ));
605#else
606 fHelpDialog->setWindowTitle(tr("Help on commands"));
607#endif
608 fHelpDialog->resize(800,600);
609 fHelpDialog->move(QPoint(400,150));
610 fHelpDialog->show();
611 fHelpDialog->raise();
612#if QT_VERSION < 0x040000
613 fHelpDialog->setActiveWindow();
614#else
615 fHelpDialog->activateWindow();
616#endif
617}
618
619
620void G4UIQt::ActivateCommand(
621 G4String newCommand
622)
623{
624 if (!fHelpTreeWidget) {
625 return;
626 }
627 // Look for the choosen command "newCommand"
628 size_t i = newCommand.index(" ");
629 G4String targetCom="";
630 if( i != std::string::npos )
631 {
632 G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
633 newValue.strip(G4String::both);
634 targetCom = ModifyToFullPathCommand( newValue );
635 }
636 if (targetCom != "") {
637#if QT_VERSION < 0x040000
638 QListViewItem* findItem = NULL;
639 QListViewItem* tmpItem = fHelpTreeWidget->firstChild();
640 while (tmpItem != 0) {
641 if (!findItem) {
642 findItem = FindTreeItem(tmpItem,QString((char*)targetCom.data()));
643 }
644 tmpItem = tmpItem->nextSibling();
645 }
646#else
647 QTreeWidgetItem* findItem = NULL;
648 for (int a=0;a<fHelpTreeWidget->topLevelItemCount();a++) {
649 if (!findItem) {
650 findItem = FindTreeItem(fHelpTreeWidget->topLevelItem(a),QString((char*)targetCom.data()));
651 }
652 }
653#endif
654
655 if (findItem) {
656
657 //collapsed open item
658#if QT_VERSION < 0x040000
659
660 // FIXME : Has to be checked
661 QListViewItem* tmpItem = fHelpTreeWidget->firstChild();
662 QList<QListViewItem> openItems;
663 while ((tmpItem != 0) || (!openItems.isEmpty())) {
664 if (tmpItem->isOpen() ) {
665 tmpItem->setOpen(false);
666 openItems.append(tmpItem);
667 tmpItem = tmpItem->firstChild();
668 } else {
669 tmpItem = tmpItem->nextSibling();
670 }
671 if (tmpItem == 0) {
672 tmpItem = openItems.take(openItems.count()-1);
673 }
674 }
675#else
676 QList<QTreeWidgetItem *> selected;
677
678 selected = fHelpTreeWidget->selectedItems();
679 if ( selected.count() != 0 ) {
680 QTreeWidgetItem * tmp =selected.at( 0 );
681 while ( tmp) {
682#if QT_VERSION < 0x040202
683 fHelpTreeWidget->setItemExpanded(tmp,false);
684#else
685 tmp->setExpanded(false);
686#endif
687 tmp = tmp->parent();
688 }
689 }
690#endif
691
692 // clear old selection
693 fHelpTreeWidget->clearSelection();
694
695 // set new selection
696#if QT_VERSION >= 0x040000
697#if QT_VERSION < 0x040202
698 fHelpTreeWidget->setItemSelected(findItem,true);
699#else
700 findItem->setSelected(true);
701#endif
702#else
703 findItem->setSelected(true);
704#endif
705
706 // expand parent item
707 while ( findItem) {
708#if QT_VERSION < 0x040000
709 findItem->setOpen(true);
710#else
711#if QT_VERSION < 0x040202
712 fHelpTreeWidget->setItemExpanded(findItem,true);
713#else
714 findItem->setExpanded(true);
715#endif
716#endif
717 findItem = findItem->parent();
718 }
719
720 // Call the update of the right textArea
721 HelpTreeClicCallback();
722 }
723 }
724}
725
726
727
728/**
729 Create the help tree widget
730 @param parent : parent of tree widget
731 @return the widget containing the tree or NULL if it could not have beeen created
732 */
733
734#if QT_VERSION < 0x040000
735QListView * G4UIQt::CreateHelpTree()
736#else
737QTreeWidget * G4UIQt::CreateHelpTree()
738#endif
739{
740 G4UImanager* UI = G4UImanager::GetUIpointer();
741 if(UI==NULL) return NULL;
742 G4UIcommandTree * treeTop = UI->GetTree();
743
744
745 // build widget
746#if QT_VERSION < 0x040000
747 fHelpTreeWidget->setSelectionMode(QListView::Single);
748 fHelpTreeWidget->setRootIsDecorated(true);
749 fHelpTreeWidget->addColumn("Command");
750 fHelpTreeWidget->header()->setResizeEnabled(FALSE,1);
751#else
752 fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
753 QStringList labels;
754 labels << QString("Command");
755 fHelpTreeWidget->setHeaderLabels(labels);
756#endif
757
758 G4int treeSize = treeTop->GetTreeEntry();
759#if QT_VERSION < 0x040000
760 QListViewItem * newItem;
761#else
762 QTreeWidgetItem * newItem;
763#endif
764 for (int a=0;a<treeSize;a++) {
765 // Creating new item
766
767#if QT_VERSION < 0x040000
768 newItem = new QListViewItem(fHelpTreeWidget);
769 newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace());
770#else
771 newItem = new QTreeWidgetItem(fHelpTreeWidget);
772 newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed());
773#endif
774
775
776 // look for childs
777 CreateChildTree(newItem,treeTop->GetTree(a+1));
778 // items.append(newItem);
779 }
780
781
782#if QT_VERSION < 0x040000
783 connect(fHelpTreeWidget, SIGNAL(selectionChanged ()),this, SLOT(HelpTreeClicCallback()));
784 connect(fHelpTreeWidget, SIGNAL(doubleClicked (QListViewItem*)),this, SLOT(HelpTreeDoubleClicCallback()));
785#else
786 connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback()));
787 connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback()));
788#endif
789
790 return fHelpTreeWidget;
791}
792
793
794
795/** Fill the Help Tree Widget
796 @param aParent : parent item to fill
797 @param aCommandTree : commandTree node associate with this part of the Tree
798*/
799#if QT_VERSION < 0x040000
800void G4UIQt::CreateChildTree(
801 QListViewItem *aParent
802,G4UIcommandTree *aCommandTree
803#else
804void G4UIQt::CreateChildTree(
805 QTreeWidgetItem *aParent
806,G4UIcommandTree *aCommandTree
807#endif
808)
809{
810 if (aParent == NULL) return;
811 if (aCommandTree == NULL) return;
812
813
814 // Creating new item
815#if QT_VERSION < 0x040000
816 QListViewItem * newItem;
817#else
818 QTreeWidgetItem * newItem;
819#endif
820
821 // Get the Sub directories
822 for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
823
824#if QT_VERSION < 0x040000
825 newItem = new QListViewItem(aParent);
826 newItem->setText(0,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace());
827
828#else
829 newItem = new QTreeWidgetItem(aParent);
830 newItem->setText(0,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed());
831#endif
832
833 CreateChildTree(newItem,aCommandTree->GetTree(a+1));
834 }
835
836
837
838 // Get the Commands
839
840 for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
841
842 QStringList stringList;
843#if QT_VERSION < 0x040000
844 newItem = new QListViewItem(aParent);
845 newItem->setText(0,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).simplifyWhiteSpace());
846 newItem->setOpen(false);
847
848#else
849 newItem = new QTreeWidgetItem(aParent);
850 newItem->setText(0,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed());
851#if QT_VERSION < 0x040202
852 fHelpTreeWidget->setItemExpanded(newItem,false);
853#else
854 newItem->setExpanded(false);
855#endif
856#endif
857
858 }
859}
860
861
862/** Find a treeItemWidget in the help tree
863 @param aCommand item's String to look for
864 @return item if found, NULL if not
865*/
866#if QT_VERSION < 0x040000
867QListViewItem* G4UIQt::FindTreeItem(
868 QListViewItem *aParent
869#else
870QTreeWidgetItem* G4UIQt::FindTreeItem(
871 QTreeWidgetItem *aParent
872#endif
873,const QString& aCommand
874)
875{
876 if (aParent == NULL) return NULL;
877
878 if (aParent->text(0) == aCommand)
879 return aParent;
880
881#if QT_VERSION < 0x040000
882 QListViewItem * tmp = NULL;
883 QListViewItem* tmpItem = aParent->firstChild();
884 while (tmpItem != 0) {
885 if (!tmp)
886 tmp = FindTreeItem(tmpItem,aCommand);
887 tmpItem = tmpItem->nextSibling();
888 }
889
890#else
891 QTreeWidgetItem * tmp = NULL;
892 for (int a=0;a<aParent->childCount();a++) {
893 if (!tmp)
894 tmp = FindTreeItem(aParent->child(a),aCommand);
895 }
896#endif
897 return tmp;
898}
899
900
901/** Build the command list parameters in a QString<br>
902 Reimplement partialy the G4UIparameter.cc
903 @param aCommand : command to list parameters
904 @see G4UIparameter::List()
905 @see G4UIcommand::List()
906 @return the command list parameters, or "" if nothing
907*/
908QString G4UIQt::GetCommandList (
909 const G4UIcommand *aCommand
910)
911{
912
913 QString txt ="";
914 if (aCommand == NULL)
915 return txt;
916
917 G4String commandPath = aCommand->GetCommandPath();
918 G4String rangeString = aCommand->GetRange();
919 G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
920 G4int n_parameterEntry = aCommand->GetParameterEntries();
921
922 if ((commandPath == "") &&
923 (rangeString == "") &&
924 (n_guidanceEntry == 0) &&
925 (n_parameterEntry == 0)) {
926 return txt;
927 }
928
929 if((commandPath.length()-1)!='/') {
930 txt += "Command " + QString((char*)(commandPath).data()) + "\n";
931 }
932 txt += "Guidance :\n";
933
934 for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
935 txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
936 }
937 if( ! rangeString.isNull() ) {
938 txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n";
939 }
940 if( n_parameterEntry > 0 ) {
941 G4UIparameter *param;
942
943 // Re-implementation of G4UIparameter.cc
944
945 for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
946 param = aCommand->GetParameter(i_thParameter);
947 txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
948 if( ! param->GetParameterGuidance().isNull() )
949 txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
950 txt += " Parameter type : " + QString(QChar(param->GetParameterType())) + "\n";
951 if(param->IsOmittable()){
952 txt += " Omittable : True\n";
953 } else {
954 txt += " Omittable : False\n";
955 }
956 if( param->GetCurrentAsDefault() ) {
957 txt += " Default value : taken from the current value\n";
958 } else if( ! param->GetDefaultValue().isNull() ) {
959 txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n";
960 }
961 if( ! param->GetParameterRange().isNull() ) {
962 txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
963 }
964 if( ! param->GetParameterCandidates().isNull() ) {
965 txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
966 }
967 }
968 }
969 return txt;
970}
971
972
973
974/** Implement G4VBasicShell vurtual function
975 */
976G4bool G4UIQt::GetHelpChoice(
977 G4int& aInt
978)
979{
980#ifdef GEANT4_QT_DEBUG
981 printf("G4UIQt::GetHelpChoice SHOULD NEVER GO HERE");
982#endif
983 return true;
984}
985
986
987/** Implement G4VBasicShell vurtual function
988*/
989void G4UIQt::ExitHelp(
990)
991{
992#ifdef GEANT4_QT_DEBUG
993 printf("G4UIQt::ExitHelp SHOULD NEVER GO HERE");
994#endif
995}
996
997
998/** Event filter method. Every event from QtApplication goes here.<br/>
999 We apply a filter only for the Up and Down Arrow press when the QLineEdit<br/>
1000 is active. If this filter match, Up arrow we give the previous command<br/>
1001 and Down arrow will give the next if exist.<br/>
1002 @param obj Emitter of the event
1003 @param event Kind of event
1004*/
1005bool G4UIQt::eventFilter( // Should stay with a minuscule eventFilter because of Qt
1006 QObject *aObj
1007,QEvent *aEvent
1008)
1009{
1010 if (aObj == NULL) return false;
1011 if (aEvent == NULL) return false;
1012
1013 if (aObj == fCommandHistoryArea) {
1014 if (aEvent->type() == QEvent::KeyPress) {
1015 fCommandArea->setFocus();
1016 }
1017 }
1018 if (aObj == fCommandArea) {
1019 if (aEvent->type() == QEvent::KeyPress) {
1020 QKeyEvent *e = static_cast<QKeyEvent*>(aEvent);
1021 if ((e->key() == (Qt::Key_Down)) ||
1022 (e->key() == (Qt::Key_PageDown)) ||
1023 (e->key() == (Qt::Key_Up)) ||
1024 (e->key() == (Qt::Key_PageUp))) {
1025#if QT_VERSION < 0x040000
1026 // count rows...
1027 QListViewItem* tmpItem = fCommandHistoryArea->firstChild();
1028 int selection = -1;
1029 int index = 0;
1030 while (tmpItem != 0) {
1031 if (tmpItem == fCommandHistoryArea->selectedItem()) {
1032 selection = index;
1033 }
1034 index ++;
1035 tmpItem = tmpItem->nextSibling();
1036 }
1037 if (fCommandHistoryArea->childCount()) {
1038 if (selection == -1) {
1039 selection = fCommandHistoryArea->childCount()-1;
1040 } else {
1041 if (e->key() == (Qt::Key_Down)) {
1042 if (selection <(fCommandHistoryArea->childCount()-1))
1043 selection++;
1044 } else if (e->key() == (Qt::Key_PageDown)) {
1045 selection = fCommandHistoryArea->childCount()-1;
1046#else
1047 int selection = fCommandHistoryArea->currentRow();
1048 if (fCommandHistoryArea->count()) {
1049 if (selection == -1) {
1050 selection = fCommandHistoryArea->count()-1;
1051 } else {
1052 if (e->key() == (Qt::Key_Down)) {
1053 if (selection <(fCommandHistoryArea->count()-1))
1054 selection++;
1055 } else if (e->key() == (Qt::Key_PageDown)) {
1056 selection = fCommandHistoryArea->count()-1;
1057#endif
1058 } else if (e->key() == (Qt::Key_Up)) {
1059 if (selection >0)
1060 selection --;
1061 } else if (e->key() == (Qt::Key_PageUp)) {
1062 selection = 0;
1063 }
1064 }
1065 fCommandHistoryArea->clearSelection();
1066#if QT_VERSION < 0x040000
1067 QListViewItem* tmpItem = fCommandHistoryArea->firstChild();
1068 int index = 0;
1069 while (tmpItem != 0) {
1070 if (index == selection) {
1071 tmpItem->setSelected(true);
1072 fCommandHistoryArea->setCurrentItem(tmpItem);
1073 }
1074 index ++;
1075 tmpItem = tmpItem->nextSibling();
1076 }
1077#else
1078#if QT_VERSION < 0x040202
1079 fCommandHistoryArea->setItemSelected(fCommandHistoryArea->item(selection),true);
1080#else
1081 fCommandHistoryArea->item(selection)->setSelected(true);
1082#endif
1083 fCommandHistoryArea->setCurrentItem(fCommandHistoryArea->item(selection));
1084#endif
1085 }
1086 } else if (e->key() == (Qt::Key_Tab)) {
1087#if QT_VERSION < 0x040000
1088 G4String ss = Complete(fCommandArea->text().ascii());
1089#else
1090 G4String ss = Complete(fCommandArea->text().toStdString().c_str());
1091#endif
1092 fCommandArea->setText((char*)(ss.data()));
1093
1094 // do not pass by parent, it will disable widget tab focus !
1095 return true;
1096 }
1097 }
1098 }
1099 // pass the event on to the parent class
1100 return QObject::eventFilter(aObj, aEvent);
1101}
1102
1103
1104
1105
1106/***************************************************************************/
1107//
1108// SLOTS DEFINITIONS
1109//
1110/***************************************************************************/
1111
1112/** Called when user give "help" command.
1113*/
1114void G4UIQt::ShowHelpCallback (
1115)
1116{
1117 TerminalHelp("");
1118}
1119
1120
1121/** Called when user click on clear button. Clear the text Output area
1122*/
1123void G4UIQt::ClearButtonCallback (
1124)
1125{
1126 fTextArea->clear();
1127}
1128
1129/** Called when user exit session
1130*/
1131void G4UIQt::ExitSession (
1132)
1133{
1134 SessionTerminate();
1135}
1136
1137
1138/** Callback call when "click on a menu entry.<br>
1139 Send the associated command to geant4
1140*/
1141void G4UIQt::CommandEnteredCallback (
1142)
1143{
1144#if QT_VERSION < 0x040000
1145 G4String command (fCommandArea->text().ascii());
1146 if (fCommandArea->text().simplifyWhiteSpace() != "") {
1147
1148 QListViewItem *newItem = new QListViewItem(fCommandHistoryArea);
1149 newItem->setText(0,fCommandArea->text());
1150 fCommandHistoryArea->insertItem(newItem);
1151 // now we have to arrange
1152 QListViewItem *temp= fCommandHistoryArea->lastItem();
1153 for (int i=0; i<fCommandHistoryArea->childCount()-1;i++) {
1154 fCommandHistoryArea->takeItem(temp);
1155 fCommandHistoryArea->insertItem(temp);
1156 temp= fCommandHistoryArea->lastItem();
1157 }
1158#else
1159 G4String command (fCommandArea->text().toStdString().c_str());
1160 if (fCommandArea->text().trimmed() != "") {
1161 fCommandHistoryArea->addItem(fCommandArea->text());
1162#endif
1163 fCommandHistoryArea->clearSelection();
1164 fCommandHistoryArea->setCurrentItem(NULL);
1165 fCommandArea->setText("");
1166
1167 G4Qt* interactorManager = G4Qt::getInstance ();
1168 if (interactorManager) {
1169 interactorManager->FlushAndWaitExecution();
1170 }
1171 if (command(0,4) != "help") {
1172 ApplyShellCommand (command,exitSession,exitPause);
1173 } else {
1174 TerminalHelp(command);
1175 }
1176 if(exitSession==true)
1177 SessionTerminate();
1178 }
1179}
1180
1181
1182/** Callback call when "enter" clicked on the command zone.<br>
1183 Send the command to geant4
1184 @param aCommand
1185*/
1186void G4UIQt::ButtonCallback (
1187 const QString& aCommand
1188)
1189{
1190#if QT_VERSION < 0x040000
1191 G4String ss = G4String(aCommand.ascii());
1192#else
1193 G4String ss = G4String(aCommand.toStdString().c_str());
1194#endif
1195 ApplyShellCommand(ss,exitSession,exitPause);
1196 if(exitSession==true)
1197 SessionTerminate();
1198}
1199
1200
1201
1202/** This callback is activated when user selected a item in the help tree
1203*/
1204void G4UIQt::HelpTreeClicCallback (
1205)
1206{
1207#if QT_VERSION < 0x040000
1208 QListViewItem* item = NULL;
1209#else
1210 QTreeWidgetItem* item = NULL;
1211#endif
1212 if (!fHelpTreeWidget)
1213 return ;
1214
1215 if (!fHelpArea)
1216 return;
1217
1218#if QT_VERSION < 0x040000
1219 item =fHelpTreeWidget->selectedItem();
1220#else
1221 QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
1222 if (list.isEmpty())
1223 return;
1224 item = list.first();
1225#endif
1226 if (!item)
1227 return;
1228
1229 G4UImanager* UI = G4UImanager::GetUIpointer();
1230 if(UI==NULL) return;
1231 G4UIcommandTree * treeTop = UI->GetTree();
1232
1233
1234
1235 std::string itemText;
1236#if QT_VERSION < 0x040000
1237 itemText = std::string(item->text(0).ascii());
1238#else
1239 itemText = std::string(item->text(0).toStdString());
1240#endif
1241
1242 G4UIcommand* command = treeTop->FindPath(itemText.c_str());
1243
1244 if (command) {
1245#if QT_VERSION >= 0x040000
1246#if QT_VERSION < 0x040200
1247 fHelpArea->clear();
1248 fHelpArea->append(GetCommandList(command));
1249#else
1250 fHelpArea->setText(GetCommandList(command));
1251#endif
1252#else
1253 fHelpArea->setText(GetCommandList(command));
1254#endif
1255 } else { // this is a command
1256 G4UIcommandTree* path = treeTop->FindCommandTree(itemText.c_str());
1257 if ( path) {
1258 // this is not a command, this is a sub directory
1259 // We display the Title
1260#if QT_VERSION >= 0x040000
1261#if QT_VERSION < 0x040200
1262 fHelpArea->clear();
1263 fHelpArea->append(path->GetTitle().data());
1264#else
1265 fHelpArea->setText(path->GetTitle().data());
1266#endif
1267#else
1268 fHelpArea->setText(path->GetTitle().data());
1269#endif
1270 }
1271 }
1272}
1273
1274/** This callback is activated when user double clic on a item in the help tree
1275*/
1276void G4UIQt::HelpTreeDoubleClicCallback (
1277)
1278{
1279 HelpTreeClicCallback();
1280
1281#if QT_VERSION < 0x040000
1282 QListViewItem* item = NULL;
1283#else
1284 QTreeWidgetItem* item = NULL;
1285#endif
1286 if (!fHelpTreeWidget)
1287 return ;
1288
1289 if (!fHelpArea)
1290 return;
1291
1292#if QT_VERSION < 0x040000
1293 item =fHelpTreeWidget->selectedItem();
1294#else
1295 QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
1296 if (list.isEmpty())
1297 return;
1298 item = list.first();
1299#endif
1300 if (!item)
1301 return;
1302
1303 fCommandArea->clear();
1304 fCommandArea->setText(item->text(0));
1305}
1306
1307
1308/** Callback called when user select an old command in the command history<br>
1309 Give it to the command area.
1310*/
1311void G4UIQt::CommandHistoryCallback(
1312)
1313{
1314#if QT_VERSION < 0x040000
1315 QListViewItem* item = NULL;
1316#else
1317 QListWidgetItem* item = NULL;
1318#endif
1319 if (!fCommandHistoryArea)
1320 return ;
1321
1322
1323#if QT_VERSION < 0x040000
1324 item =fCommandHistoryArea->selectedItem();
1325#else
1326 QList<QListWidgetItem *> list =fCommandHistoryArea->selectedItems();
1327 if (list.isEmpty())
1328 return;
1329 item = list.first();
1330#endif
1331 if (!item)
1332 return;
1333#if QT_VERSION < 0x040000
1334 fCommandArea->setText(item->text(0));
1335#else
1336 fCommandArea->setText(item->text());
1337#endif
1338
1339}
1340
1341
1342/** Callback called when user give a new string to look for<br>
1343 Display a list of matching commands descriptions. If no string is set,
1344 will display the complete help tree
1345*/
1346void G4UIQt::lookForHelpStringCallback(
1347)
1348{
1349#if QT_VERSION < 0x040200
1350 fHelpArea->clear();
1351#else
1352 fHelpArea->setText("");
1353#endif
1354 if (helpLine->text() =="") {
1355 // clear old help tree
1356 fHelpTreeWidget->clear();
1357#if QT_VERSION < 0x040200
1358 fHelpTreeWidget->removeColumn(1);
1359 fHelpTreeWidget->removeColumn(0);
1360#endif
1361 CreateHelpTree();
1362 return;
1363 }
1364
1365#ifdef GEANT4_QT_DEBUG
1366 printf("G4UIQt::lookForHelpStringCallback\n");
1367#endif
1368
1369 // the help tree
1370 G4UImanager* UI = G4UImanager::GetUIpointer();
1371 if(UI==NULL) return;
1372 G4UIcommandTree * treeTop = UI->GetTree();
1373
1374 G4int treeSize = treeTop->GetTreeEntry();
1375
1376 // clear old help tree
1377 fHelpTreeWidget->clear();
1378#if QT_VERSION < 0x040200
1379 fHelpTreeWidget->removeColumn(1);
1380 fHelpTreeWidget->removeColumn(0);
1381#endif
1382
1383 // look for new items
1384
1385 int tmp = 0;
1386#if QT_VERSION < 0x040000
1387 int multFactor = 1000; // factor special for having double keys in Qt3
1388 int doubleKeyAdd = 0; // decay for doubleKeys in Qt3
1389#endif
1390
1391 QMap<int,QString> commandResultMap;
1392 QMap<int,QString> commandChildResultMap;
1393
1394 for (int a=0;a<treeSize;a++) {
1395 G4UIcommand* command = treeTop->FindPath(treeTop->GetTree(a+1)->GetPathName().data());
1396#if QT_VERSION > 0x040000
1397 tmp = GetCommandList (command).count(helpLine->text(),Qt::CaseInsensitive);
1398#else
1399 tmp = GetCommandList (command).contains(helpLine->text(),false);
1400#endif
1401 if (tmp >0) {
1402#if QT_VERSION > 0x040000
1403 commandResultMap.insertMulti(tmp,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()));
1404#else // tricky thing for Qt3...
1405 doubleKeyAdd = 0;
1406 while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) {
1407 doubleKeyAdd ++;
1408 }
1409 commandResultMap.insert( tmp*multFactor+doubleKeyAdd,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()) );
1410#endif
1411 }
1412 // look for childs
1413 commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a+1),helpLine->text());
1414 // insert new childs
1415 if (!commandChildResultMap.empty()) {
1416#if QT_VERSION > 0x040000
1417 QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
1418 while (i != commandChildResultMap.constEnd()) {
1419 commandResultMap.insertMulti(i.key(),i.value());
1420#else // tricky thing for Qt3...
1421 QMap<int,QString>::const_iterator i = commandChildResultMap.begin();
1422 while (i != commandChildResultMap.end()) {
1423 doubleKeyAdd = 0;
1424 while (commandResultMap.find( i.key()*multFactor+doubleKeyAdd) != commandResultMap.end()) {
1425 doubleKeyAdd ++;
1426 }
1427 commandResultMap.insert(i.key()*multFactor+doubleKeyAdd,i.data());
1428#endif
1429 i++;
1430 }
1431 commandChildResultMap.clear();
1432 }
1433 }
1434
1435 // build new help tree
1436#if QT_VERSION < 0x040000
1437 fHelpTreeWidget->setSelectionMode(QListView::Single);
1438 fHelpTreeWidget->setRootIsDecorated(true);
1439 fHelpTreeWidget->addColumn("Command");
1440 fHelpTreeWidget->addColumn("Match");
1441 // fHelpTreeWidget->header()->setResizeEnabled(FALSE,1);
1442#else
1443 fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
1444 fHelpTreeWidget->setColumnCount(2);
1445 QStringList labels;
1446 labels << QString("Command") << QString("Match");
1447 fHelpTreeWidget->setHeaderLabels(labels);
1448#endif
1449
1450 if (commandResultMap.empty()) {
1451#if QT_VERSION < 0x040200
1452 fHelpArea->clear();
1453 fHelpArea->append("No match found");
1454#else
1455 fHelpArea->setText("No match found");
1456#endif
1457 return;
1458 }
1459
1460#if QT_VERSION > 0x040000
1461 QMap<int,QString>::const_iterator i = commandResultMap.constEnd();
1462#else
1463 QMap<int,QString>::const_iterator i = commandResultMap.end();
1464#endif
1465 i--;
1466 // 10 maximum progress values
1467 float multValue = 10.0/(float)(i.key());
1468 QString progressChar = "|";
1469 QString progressStr = "|";
1470
1471#if QT_VERSION < 0x040000
1472 QListViewItem * newItem;
1473#else
1474 QTreeWidgetItem * newItem;
1475#endif
1476 bool end = false;
1477 while (!end) {
1478#if QT_VERSION > 0x040000
1479 if (i == commandResultMap.constBegin()) {
1480#else
1481 if (i == commandResultMap.begin()) {
1482#endif
1483 end = true;
1484 }
1485 for(int a=0;a<int(i.key()*multValue);a++) {
1486 progressStr += progressChar;
1487 }
1488#if QT_VERSION < 0x040000
1489 newItem = new QListViewItem(fHelpTreeWidget);
1490 newItem->setText(0,i.data().simplifyWhiteSpace());
1491#else
1492 newItem = new QTreeWidgetItem(fHelpTreeWidget);
1493 newItem->setText(0,i.value().trimmed());
1494#endif
1495 newItem->setText(1,progressStr);
1496
1497#if QT_VERSION >= 0x040200
1498 newItem->setForeground ( 1, QBrush(Qt::blue) );
1499#endif
1500 progressStr = "|";
1501 i--;
1502 }
1503 // FIXME : to be checked on Qt3
1504#if QT_VERSION < 0x040000
1505 fHelpTreeWidget->setColumnWidthMode (1,QListView::Maximum);
1506 fHelpTreeWidget->setSorting(1,false);
1507#else
1508 fHelpTreeWidget->resizeColumnToContents (0);
1509 fHelpTreeWidget->sortItems(1,Qt::DescendingOrder);
1510 // fHelpTreeWidget->setColumnWidth(1,10);//resizeColumnToContents (1);
1511#endif
1512}
1513
1514
1515
1516
1517QMap<int,QString> G4UIQt::LookForHelpStringInChildTree(
1518 G4UIcommandTree *aCommandTree
1519,const QString & text
1520 )
1521{
1522 QMap<int,QString> commandResultMap;
1523 if (aCommandTree == NULL) return commandResultMap;
1524
1525#if QT_VERSION < 0x040000
1526 int multFactor = 1000; // factor special for having double keys in Qt3
1527 int doubleKeyAdd = 0; // decay for doubleKeys in Qt3
1528#endif
1529
1530 // Get the Sub directories
1531 int tmp = 0;
1532 QMap<int,QString> commandChildResultMap;
1533
1534 for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
1535 const G4UIcommand* command = aCommandTree->GetGuidance();
1536#if QT_VERSION > 0x040000
1537 tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
1538#else
1539 tmp = GetCommandList (command).contains(text,false);
1540#endif
1541 if (tmp >0) {
1542#if QT_VERSION > 0x040000
1543 commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()));
1544#else // tricky thing for Qt3...
1545 doubleKeyAdd = 0;
1546 while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) {
1547 doubleKeyAdd ++;
1548 }
1549 commandResultMap.insert(tmp*multFactor+doubleKeyAdd,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()));
1550#endif
1551 }
1552 // look for childs
1553 commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text);
1554
1555 if (!commandChildResultMap.empty()) {
1556 // insert new childs
1557#if QT_VERSION > 0x040000
1558 QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
1559 while (i != commandChildResultMap.constEnd()) {
1560 commandResultMap.insertMulti(i.key(),i.value());
1561#else // tricky thing for Qt3...
1562 QMap<int,QString>::const_iterator i = commandChildResultMap.begin();
1563 while (i != commandChildResultMap.end()) {
1564 doubleKeyAdd = 0;
1565 while (commandResultMap.find( i.key()*multFactor+doubleKeyAdd) != commandResultMap.end()) {
1566 doubleKeyAdd ++;
1567 }
1568 commandResultMap.insert(i.key()*multFactor+doubleKeyAdd,i.data());
1569#endif
1570 i++;
1571 }
1572 commandChildResultMap.clear();
1573 }
1574 }
1575 // Get the Commands
1576
1577 for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
1578 const G4UIcommand* command = aCommandTree->GetCommand(a+1);
1579#if QT_VERSION > 0x040000
1580 tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
1581#else
1582 tmp = GetCommandList (command).contains(text,false);
1583#endif
1584 if (tmp >0) {
1585#if QT_VERSION > 0x040000
1586 commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()));
1587#else // tricky thing for Qt3...
1588 doubleKeyAdd = 0;
1589 while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) {
1590 doubleKeyAdd ++;
1591 }
1592 commandResultMap.insert(tmp*multFactor+doubleKeyAdd,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()));
1593#endif
1594#ifdef GEANT4_QT_DEBUG
1595#endif
1596 }
1597
1598 }
1599 return commandResultMap;
1600}
1601#endif
Note: See TracBrowser for help on using the repository browser.