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

Last change on this file since 1330 was 1329, checked in by garnier, 15 years ago

bug fix 2?

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