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

Last change on this file since 1319 was 1318, checked in by garnier, 15 years ago

fix qt3 bug

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