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

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

test qt3

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