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

Last change on this file since 1166 was 1163, checked in by garnier, 16 years ago

Update pour les Tabs

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