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

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

fix qt3 bug

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