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

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

update

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