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