source: trunk/source/interfaces/basic/src/G4UIQt.cc@ 900

Last change on this file since 900 was 889, checked in by garnier, 17 years ago

See History

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