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

Last change on this file since 1324 was 1321, checked in by garnier, 15 years ago

fix warning

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