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

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

UIQt on avance

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