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

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

otpimisations

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