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

Last change on this file since 1335 was 1335, checked in by garnier, 14 years ago

some changes to check

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