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

Last change on this file since 1317 was 1314, checked in by garnier, 15 years ago

en test pas dans CVS

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