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

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

Help update

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