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

Last change on this file since 1354 was 1340, checked in by garnier, 15 years ago

update ti head

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