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

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

see history

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