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

Last change on this file since 1326 was 1325, checked in by garnier, 15 years ago

modif

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