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

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

update ti head

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