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

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

remove cycle dependency

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