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

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

supp d'une fonction en doublon

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