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.12 2007/11/15 18:24:27 lgarnier Exp $ |
---|
28 | // GEANT4 tag $Name: $ |
---|
29 | // |
---|
30 | // L. Garnier |
---|
31 | |
---|
32 | //#define DEBUG |
---|
33 | |
---|
34 | #ifdef G4UI_BUILD_QT_SESSION |
---|
35 | |
---|
36 | #include "G4Types.hh" |
---|
37 | |
---|
38 | #include <string.h> |
---|
39 | |
---|
40 | #include "G4UIQt.hh" |
---|
41 | #include "G4UImanager.hh" |
---|
42 | #include "G4StateManager.hh" |
---|
43 | #include "G4UIcommandTree.hh" |
---|
44 | #include "G4UIcommandStatus.hh" |
---|
45 | |
---|
46 | #include "G4Qt.hh" |
---|
47 | |
---|
48 | #include <qapplication.h> |
---|
49 | #include <qlineedit.h> |
---|
50 | #include <qwidget.h> |
---|
51 | #include <qmenubar.h> |
---|
52 | #include <qlayout.h> |
---|
53 | #include <qpushbutton.h> |
---|
54 | #include <qlabel.h> |
---|
55 | #include <qsplitter.h> |
---|
56 | #include <qscrollbar.h> |
---|
57 | #include <qdialog.h> |
---|
58 | #include <qevent.h> |
---|
59 | #include <qtextedit.h> |
---|
60 | #include <qsignalmapper.h> |
---|
61 | |
---|
62 | #include <qmainwindow.h> |
---|
63 | #if QT_VERSION >= 0x040000 |
---|
64 | #include <qmenu.h> |
---|
65 | #include <qlistwidget.h> |
---|
66 | #include <qtreewidget.h> |
---|
67 | #else |
---|
68 | #include <qaction.h> |
---|
69 | #include <qheader.h> |
---|
70 | #include <qlistview.h> |
---|
71 | #include <qpopupmenu.h> |
---|
72 | #endif |
---|
73 | |
---|
74 | |
---|
75 | |
---|
76 | #include <stdlib.h> |
---|
77 | |
---|
78 | // Pourquoi Static et non variables de classe ? |
---|
79 | static G4bool exitSession = true; |
---|
80 | static G4bool exitPause = true; |
---|
81 | |
---|
82 | /** Build a Qt window with a menubar, output area and promt area<br> |
---|
83 | <pre> |
---|
84 | +-----------------------+ |
---|
85 | |exit menu| | |
---|
86 | | | |
---|
87 | | +-------------------+ | |
---|
88 | | | | | |
---|
89 | | | Output area | | |
---|
90 | | | | | |
---|
91 | | +-------------------+ | |
---|
92 | | | clear | | |
---|
93 | | +-------------------+ | |
---|
94 | | | promt history | | |
---|
95 | | +-------------------+ | |
---|
96 | | +-------------------+ | |
---|
97 | | |> promt area | | |
---|
98 | | +-------------------+ | |
---|
99 | +-----------------------+ |
---|
100 | </pre> |
---|
101 | */ |
---|
102 | G4UIQt::G4UIQt ( |
---|
103 | int argc |
---|
104 | ,char** argv |
---|
105 | ) |
---|
106 | :fHelpDialog(NULL) |
---|
107 | { |
---|
108 | #ifdef GEANT4_QT_DEBUG |
---|
109 | printf("G4UIQt::Initialise %d %s\n",argc,argv[0]); |
---|
110 | #endif |
---|
111 | G4Qt* interactorManager = G4Qt::getInstance (argc,argv,(char*)"Qt"); |
---|
112 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
113 | if(UI!=NULL) UI->SetSession(this); |
---|
114 | |
---|
115 | fMainWindow = new QMainWindow(); |
---|
116 | |
---|
117 | #ifdef GEANT4_QT_DEBUG |
---|
118 | printf("G4UIQt::Initialise after main window creation\n"); |
---|
119 | #endif |
---|
120 | #if QT_VERSION < 0x040000 |
---|
121 | fMainWindow->setCaption( tr( "G4UI Session" )); |
---|
122 | fMainWindow->resize(800,600); |
---|
123 | fMainWindow->move(50,100); |
---|
124 | #else |
---|
125 | fMainWindow->setWindowTitle( tr("G4UI Session") ); |
---|
126 | fMainWindow->resize(800,600); |
---|
127 | fMainWindow->move(QPoint(50,100)); |
---|
128 | #endif |
---|
129 | |
---|
130 | QSplitter *splitter = new QSplitter(Qt::Vertical); |
---|
131 | fTextArea = new QTextEdit(fMainWindow); |
---|
132 | QPushButton *clearButton = new QPushButton("clear",fMainWindow); |
---|
133 | connect(clearButton, SIGNAL(clicked()), SLOT(ClearButtonCallback())); |
---|
134 | |
---|
135 | #if QT_VERSION < 0x040000 |
---|
136 | fCommandHistoryArea = new QListView(); |
---|
137 | fCommandHistoryArea->setSelectionMode(QListView::Single); |
---|
138 | connect(fCommandHistoryArea, SIGNAL(selectionChanged()), SLOT(CommandHistoryCallback())); |
---|
139 | #else |
---|
140 | fCommandHistoryArea = new QListWidget(); |
---|
141 | fCommandHistoryArea->setSelectionMode(QAbstractItemView::SingleSelection); |
---|
142 | connect(fCommandHistoryArea, SIGNAL(itemSelectionChanged()), SLOT(CommandHistoryCallback())); |
---|
143 | #endif |
---|
144 | fCommandHistoryArea->installEventFilter(this); |
---|
145 | fCommandLabel = new QLabel("",fMainWindow); |
---|
146 | |
---|
147 | fCommandArea = new QLineEdit(fMainWindow); |
---|
148 | fCommandArea->installEventFilter(this); |
---|
149 | #if QT_VERSION < 0x040000 |
---|
150 | fCommandArea->setActiveWindow(); |
---|
151 | #else |
---|
152 | fCommandArea->activateWindow(); |
---|
153 | #endif |
---|
154 | connect(fCommandArea, SIGNAL(returnPressed()), SLOT(CommandEnteredCallback())); |
---|
155 | #if QT_VERSION < 0x040000 |
---|
156 | fCommandArea->setFocusPolicy ( QWidget::StrongFocus ); |
---|
157 | fCommandArea->setFocus(); |
---|
158 | #else |
---|
159 | fCommandArea->setFocusPolicy ( Qt::StrongFocus ); |
---|
160 | fCommandArea->setFocus(Qt::TabFocusReason); |
---|
161 | #endif |
---|
162 | fTextArea->setReadOnly(true); |
---|
163 | |
---|
164 | |
---|
165 | // Set layouts |
---|
166 | |
---|
167 | #if QT_VERSION < 0x040000 |
---|
168 | QWidget* topWidget = new QWidget(splitter); |
---|
169 | QWidget* bottomWidget = new QWidget(splitter); |
---|
170 | |
---|
171 | QVBoxLayout *layoutTop = new QVBoxLayout(topWidget); |
---|
172 | QVBoxLayout *layoutBottom = new QVBoxLayout(bottomWidget); |
---|
173 | #else |
---|
174 | QWidget* topWidget = new QWidget(); |
---|
175 | QWidget* bottomWidget = new QWidget(); |
---|
176 | |
---|
177 | QVBoxLayout *layoutTop = new QVBoxLayout; |
---|
178 | QVBoxLayout *layoutBottom = new QVBoxLayout; |
---|
179 | #endif |
---|
180 | |
---|
181 | |
---|
182 | |
---|
183 | layoutTop->addWidget(fTextArea); |
---|
184 | layoutTop->addWidget(clearButton); |
---|
185 | |
---|
186 | #if QT_VERSION >= 0x040000 |
---|
187 | topWidget->setLayout(layoutTop); |
---|
188 | #endif |
---|
189 | |
---|
190 | layoutBottom->addWidget(fCommandHistoryArea); |
---|
191 | layoutBottom->addWidget(fCommandLabel); |
---|
192 | layoutBottom->addWidget(fCommandArea); |
---|
193 | #if QT_VERSION >= 0x040000 |
---|
194 | |
---|
195 | bottomWidget->setLayout(layoutBottom); |
---|
196 | splitter->addWidget(topWidget); |
---|
197 | splitter->addWidget(bottomWidget); |
---|
198 | #endif |
---|
199 | |
---|
200 | |
---|
201 | fMainWindow->setCentralWidget(splitter); |
---|
202 | |
---|
203 | #if QT_VERSION < 0x040000 |
---|
204 | |
---|
205 | // Add a quit subMenu |
---|
206 | QPopupMenu *fileMenu = new QPopupMenu( fMainWindow); |
---|
207 | fileMenu->insertItem( "&Quitter", this, SLOT(ExitSession()), CTRL+Key_Q ); |
---|
208 | fMainWindow->menuBar()->insertItem( QString("&File"), fileMenu ); |
---|
209 | |
---|
210 | // Add a Help menu |
---|
211 | QPopupMenu *helpMenu = new QPopupMenu( fMainWindow ); |
---|
212 | helpMenu->insertItem( "&Show Help", this, SLOT(ShowHelpCallback()), CTRL+Key_H ); |
---|
213 | fMainWindow->menuBar()->insertItem( QString("&Help"), helpMenu ); |
---|
214 | |
---|
215 | |
---|
216 | #else |
---|
217 | |
---|
218 | // Add a quit subMenu |
---|
219 | QMenu *fileMenu = fMainWindow->menuBar()->addMenu("File"); |
---|
220 | fileMenu->addAction("Quitter", this, SLOT(ExitSession())); |
---|
221 | |
---|
222 | // Add a Help menu |
---|
223 | QMenu *helpMenu = fMainWindow->menuBar()->addMenu("Help"); |
---|
224 | helpMenu->addAction("Show Help", this, SLOT(ShowHelpCallback())); |
---|
225 | #endif |
---|
226 | |
---|
227 | // Set the splitter size. The fTextArea sould be 2/3 on the fMainWindow |
---|
228 | #if QT_VERSION < 0x040000 |
---|
229 | QValueList<int> vals = splitter->sizes(); |
---|
230 | #else |
---|
231 | QList<int> vals = splitter->sizes(); |
---|
232 | #endif |
---|
233 | if(vals.size()==2) { |
---|
234 | vals[0] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*3/4; |
---|
235 | vals[1] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*1/4; |
---|
236 | splitter->setSizes(vals); |
---|
237 | } |
---|
238 | |
---|
239 | if(UI!=NULL) UI->SetCoutDestination(this); // TO KEEP |
---|
240 | } |
---|
241 | |
---|
242 | |
---|
243 | |
---|
244 | G4UIQt::~G4UIQt( |
---|
245 | ) |
---|
246 | { |
---|
247 | G4UImanager* UI = G4UImanager::GetUIpointer(); // TO KEEP |
---|
248 | if(UI!=NULL) { // TO KEEP |
---|
249 | UI->SetSession(NULL); // TO KEEP |
---|
250 | UI->SetCoutDestination(NULL); // TO KEEP |
---|
251 | } |
---|
252 | |
---|
253 | if (fMainWindow!=NULL) |
---|
254 | delete fMainWindow; |
---|
255 | } |
---|
256 | |
---|
257 | |
---|
258 | |
---|
259 | /** Start the Qt main loop |
---|
260 | */ |
---|
261 | G4UIsession* G4UIQt::SessionStart ( |
---|
262 | ) |
---|
263 | { |
---|
264 | |
---|
265 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
266 | |
---|
267 | #if QT_VERSION >= 0x040000 |
---|
268 | #if QT_VERSION >= 0x040200 |
---|
269 | fMainWindow->setVisible(true); |
---|
270 | #else |
---|
271 | fMainWindow->show(); |
---|
272 | #endif |
---|
273 | #else |
---|
274 | fMainWindow->show(); |
---|
275 | #endif |
---|
276 | Prompt("session"); |
---|
277 | exitSession = false; |
---|
278 | |
---|
279 | |
---|
280 | #ifdef GEANT4_QT_DEBUG |
---|
281 | printf("disable secondary loop\n"); |
---|
282 | #endif |
---|
283 | interactorManager->DisableSecondaryLoop (); // TO KEEP |
---|
284 | ((QApplication*)interactorManager->GetMainInteractor())->exec(); |
---|
285 | // on ne passe pas le dessous ? FIXME ???? |
---|
286 | // je ne pense pas 13/06 |
---|
287 | |
---|
288 | // void* event; // TO KEEP |
---|
289 | // while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
290 | // interactorManager->DispatchEvent(event); // TO KEEP |
---|
291 | // if(exitSession==true) break; // TO KEEP |
---|
292 | // } // TO KEEP |
---|
293 | |
---|
294 | interactorManager->EnableSecondaryLoop (); |
---|
295 | #ifdef GEANT4_QT_DEBUG |
---|
296 | printf("enable secondary loop\n"); |
---|
297 | #endif |
---|
298 | return this; |
---|
299 | } |
---|
300 | |
---|
301 | |
---|
302 | /** Display the prompt in the prompt area |
---|
303 | @param aPrompt : string to display as the promt label |
---|
304 | //FIXME : probablement inutile puisque le seul a afficher qq chose d'autre |
---|
305 | que "session" est SecondaryLoop() |
---|
306 | */ |
---|
307 | void G4UIQt::Prompt ( |
---|
308 | G4String aPrompt |
---|
309 | ) |
---|
310 | { |
---|
311 | if (!aPrompt) return; |
---|
312 | |
---|
313 | fCommandLabel->setText((char*)aPrompt.data()); |
---|
314 | } |
---|
315 | |
---|
316 | |
---|
317 | void G4UIQt::SessionTerminate ( |
---|
318 | ) |
---|
319 | { |
---|
320 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
321 | fMainWindow->close(); |
---|
322 | ((QApplication*)interactorManager->GetMainInteractor())->exit(); |
---|
323 | } |
---|
324 | |
---|
325 | |
---|
326 | |
---|
327 | /** |
---|
328 | Called by intercoms/src/G4UImanager.cc<br> |
---|
329 | Called by visualization/management/src/G4VisCommands.cc with "EndOfEvent" argument<br> |
---|
330 | It have to pause the session command terminal.<br> |
---|
331 | Call SecondaryLoop to wait for exit event<br> |
---|
332 | @param aState |
---|
333 | @see : G4VisCommandReviewKeptEvents::SetNewValue |
---|
334 | */ |
---|
335 | void G4UIQt::PauseSessionStart ( |
---|
336 | G4String aState |
---|
337 | ) |
---|
338 | { |
---|
339 | if (!aState) return; |
---|
340 | |
---|
341 | #ifdef GEANT4_QT_DEBUG |
---|
342 | printf("G4UIQt::PauseSessionStart\n"); |
---|
343 | #endif |
---|
344 | if(aState=="G4_pause> ") { // TO KEEP |
---|
345 | SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP |
---|
346 | } // TO KEEP |
---|
347 | |
---|
348 | if(aState=="EndOfEvent") { // TO KEEP |
---|
349 | // Picking with feed back in event data Done here !!! |
---|
350 | SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP |
---|
351 | } // TO KEEP |
---|
352 | } |
---|
353 | |
---|
354 | |
---|
355 | |
---|
356 | /** |
---|
357 | Begin the secondary loop |
---|
358 | @param a_prompt : label to display as the prompt label |
---|
359 | */ |
---|
360 | void G4UIQt::SecondaryLoop ( |
---|
361 | G4String aPrompt |
---|
362 | ) |
---|
363 | { |
---|
364 | if (!aPrompt) return; |
---|
365 | |
---|
366 | #ifdef GEANT4_QT_DEBUG |
---|
367 | printf("G4UIQt::SecondaryLoop\n"); |
---|
368 | #endif |
---|
369 | G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ? |
---|
370 | Prompt(aPrompt); // TO KEEP |
---|
371 | exitPause = false; // TO KEEP |
---|
372 | void* event; // TO KEEP |
---|
373 | while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
374 | interactorManager->DispatchEvent(event); // TO KEEP |
---|
375 | if(exitPause==true) break; // TO KEEP |
---|
376 | } // TO KEEP |
---|
377 | Prompt("session"); // TO KEEP |
---|
378 | } |
---|
379 | |
---|
380 | |
---|
381 | |
---|
382 | /** |
---|
383 | Receive a cout from Geant4. We have to display it in the cout zone |
---|
384 | @param aString : label to add in the display area |
---|
385 | @return 0 |
---|
386 | */ |
---|
387 | G4int G4UIQt::ReceiveG4cout ( |
---|
388 | G4String aString |
---|
389 | ) |
---|
390 | { |
---|
391 | if (!aString) return 0; |
---|
392 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
393 | if (!interactorManager) return 0; |
---|
394 | |
---|
395 | #if QT_VERSION < 0x040000 |
---|
396 | fTextArea->append(QString((char*)aString.data()).simplifyWhiteSpace()); |
---|
397 | fTextArea->verticalScrollBar()->setValue(fTextArea->verticalScrollBar()->maxValue()); |
---|
398 | #else |
---|
399 | fTextArea->append(QString((char*)aString.data()).trimmed()); |
---|
400 | fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum()); |
---|
401 | #endif |
---|
402 | interactorManager->FlushAndWaitExecution(); |
---|
403 | return 0; |
---|
404 | } |
---|
405 | |
---|
406 | |
---|
407 | /** |
---|
408 | Receive a cerr from Geant4. We have to display it in the cout zone |
---|
409 | @param aString : label to add in the display area |
---|
410 | @return 0 |
---|
411 | */ |
---|
412 | G4int G4UIQt::ReceiveG4cerr ( |
---|
413 | G4String aString |
---|
414 | ) |
---|
415 | { |
---|
416 | if (!aString) return 0; |
---|
417 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
418 | if (!interactorManager) return 0; |
---|
419 | |
---|
420 | #if QT_VERSION < 0x040000 |
---|
421 | QColor previousColor = fTextArea->color(); |
---|
422 | fTextArea->setColor(Qt::red); |
---|
423 | fTextArea->append(QString((char*)aString.data()).simplifyWhiteSpace()); |
---|
424 | fTextArea->setColor(previousColor); |
---|
425 | fTextArea->verticalScrollBar()->setValue(fTextArea->verticalScrollBar()->maxValue()); |
---|
426 | #else |
---|
427 | QColor previousColor = fTextArea->textColor(); |
---|
428 | fTextArea->setTextColor(Qt::red); |
---|
429 | fTextArea->append(QString((char*)aString.data()).trimmed()); |
---|
430 | fTextArea->setTextColor(previousColor); |
---|
431 | fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum()); |
---|
432 | #endif |
---|
433 | interactorManager->FlushAndWaitExecution(); |
---|
434 | return 0; |
---|
435 | } |
---|
436 | |
---|
437 | |
---|
438 | |
---|
439 | /** |
---|
440 | Add a new menu to the menu bar |
---|
441 | @param aName name of menu |
---|
442 | @param aLabel label to display |
---|
443 | */ |
---|
444 | void G4UIQt::AddMenu ( |
---|
445 | const char* aName |
---|
446 | ,const char* aLabel |
---|
447 | ) |
---|
448 | { |
---|
449 | if (aName == NULL) return; |
---|
450 | if (aLabel == NULL) return; |
---|
451 | |
---|
452 | #if QT_VERSION < 0x040000 |
---|
453 | QPopupMenu *fileMenu = new QPopupMenu( fMainWindow); |
---|
454 | fMainWindow->menuBar()->insertItem( aLabel, fileMenu ); |
---|
455 | #else |
---|
456 | QMenu *fileMenu = new QMenu(aLabel); |
---|
457 | fMainWindow->menuBar()->insertMenu(fMainWindow->menuBar()->actions().last(),fileMenu); |
---|
458 | #endif |
---|
459 | |
---|
460 | AddInteractor (aName,(G4Interactor)fileMenu); |
---|
461 | } |
---|
462 | |
---|
463 | |
---|
464 | /** |
---|
465 | Add a new button to a menu |
---|
466 | @param aMenu : parent menu |
---|
467 | @param aLabel : label to display |
---|
468 | @param aCommand : command to execute as a callback |
---|
469 | */ |
---|
470 | void G4UIQt::AddButton ( |
---|
471 | const char* aMenu |
---|
472 | ,const char* aLabel |
---|
473 | ,const char* aCommand |
---|
474 | ) |
---|
475 | { |
---|
476 | if(aMenu==NULL) return; // TO KEEP |
---|
477 | if(aLabel==NULL) return; // TO KEEP |
---|
478 | if(aCommand==NULL) return; // TO KEEP |
---|
479 | |
---|
480 | #if QT_VERSION < 0x040000 |
---|
481 | QPopupMenu *parent = (QPopupMenu*)GetInteractor(aMenu); |
---|
482 | #else |
---|
483 | QMenu *parent = (QMenu*)GetInteractor(aMenu); |
---|
484 | #endif |
---|
485 | |
---|
486 | if(parent==NULL) return; |
---|
487 | |
---|
488 | QSignalMapper *signalMapper = new QSignalMapper(this); |
---|
489 | #if QT_VERSION < 0x040000 |
---|
490 | QAction *action = new QAction(QString(aLabel),QKeySequence::QKeySequence (),signalMapper, SLOT(map())); |
---|
491 | action->addTo(parent); |
---|
492 | #else |
---|
493 | QAction *action = parent->addAction(aLabel, signalMapper, SLOT(map())); |
---|
494 | #endif |
---|
495 | signalMapper->setMapping(action, QString(aCommand)); |
---|
496 | connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&))); |
---|
497 | } |
---|
498 | |
---|
499 | |
---|
500 | |
---|
501 | |
---|
502 | /** |
---|
503 | Open the help dialog in a separate window.<br> |
---|
504 | This will be display as a tree widget.<br> |
---|
505 | Implementation of <b>void G4VBasicShell::TerminalHelp(G4String newCommand)</b> |
---|
506 | |
---|
507 | @param newCommand : open the tree widget item on this command if is set |
---|
508 | */ |
---|
509 | void G4UIQt::TerminalHelp( |
---|
510 | G4String newCommand |
---|
511 | ) |
---|
512 | { |
---|
513 | // Create the help dialog |
---|
514 | if (!fHelpDialog) { |
---|
515 | #if QT_VERSION < 0x040000 |
---|
516 | fHelpDialog = new QDialog(fMainWindow,0,FALSE,Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WStyle_MinMax ); |
---|
517 | #else |
---|
518 | fHelpDialog = new QDialog(fMainWindow,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint); |
---|
519 | #endif |
---|
520 | QSplitter *splitter = new QSplitter(Qt::Horizontal); |
---|
521 | QPushButton *exitButton = new QPushButton("Exit",fMainWindow); |
---|
522 | connect(exitButton, SIGNAL(clicked()), fHelpDialog,SLOT(close())); |
---|
523 | |
---|
524 | // the help tree |
---|
525 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
526 | if(UI==NULL) return; |
---|
527 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
528 | |
---|
529 | // build widget |
---|
530 | #if QT_VERSION < 0x040000 |
---|
531 | fHelpTreeWidget = new QListView(splitter); |
---|
532 | fHelpTreeWidget->setSelectionMode(QListView::Single); |
---|
533 | fHelpTreeWidget->addColumn("Command"); |
---|
534 | fHelpTreeWidget->addColumn("Description"); |
---|
535 | fHelpTreeWidget->hideColumn(1); |
---|
536 | fHelpTreeWidget->header()->setResizeEnabled(FALSE,1); |
---|
537 | // QList<QListViewItem *> items; |
---|
538 | #else |
---|
539 | fHelpTreeWidget = new QTreeWidget(); |
---|
540 | fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection); |
---|
541 | fHelpTreeWidget->setColumnCount(2); |
---|
542 | fHelpTreeWidget->setColumnHidden(1,true); |
---|
543 | QStringList labels; |
---|
544 | labels << QString("Command") << QString("Description"); |
---|
545 | fHelpTreeWidget->setHeaderLabels(labels); |
---|
546 | // QList<QTreeWidgetItem *> items; |
---|
547 | #endif |
---|
548 | |
---|
549 | #if QT_VERSION < 0x040000 |
---|
550 | fHelpArea = new QTextEdit(splitter); |
---|
551 | #else |
---|
552 | fHelpArea = new QTextEdit(); |
---|
553 | #endif |
---|
554 | fHelpArea->setReadOnly(true); |
---|
555 | |
---|
556 | G4int treeSize = treeTop->GetTreeEntry(); |
---|
557 | #if QT_VERSION < 0x040000 |
---|
558 | QListViewItem * newItem; |
---|
559 | #else |
---|
560 | QTreeWidgetItem * newItem; |
---|
561 | #endif |
---|
562 | for (int a=0;a<treeSize;a++) { |
---|
563 | // Creating new item |
---|
564 | |
---|
565 | #if QT_VERSION < 0x040000 |
---|
566 | newItem = new QListViewItem(fHelpTreeWidget); |
---|
567 | newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace()); |
---|
568 | newItem->setText(1,QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).simplifyWhiteSpace()); |
---|
569 | #else |
---|
570 | //FIXME : Qt 4.2 |
---|
571 | // QStringList stringList; |
---|
572 | // stringList << QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed() ; |
---|
573 | // stringList << QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).trimmed() ; |
---|
574 | // newItem = new QTreeWidgetItem(stringList); |
---|
575 | // FIXME : Qt 4.0 |
---|
576 | newItem = new QTreeWidgetItem(fHelpTreeWidget); |
---|
577 | newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed()); |
---|
578 | newItem->setText(1,QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).trimmed()); |
---|
579 | #endif |
---|
580 | |
---|
581 | |
---|
582 | // look for childs |
---|
583 | CreateChildTree(newItem,treeTop->GetTree(a+1)); |
---|
584 | // items.append(newItem); |
---|
585 | } |
---|
586 | |
---|
587 | connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback())); |
---|
588 | connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback(QTreeWidgetItem*,int))); |
---|
589 | |
---|
590 | // Set layouts |
---|
591 | |
---|
592 | #if QT_VERSION < 0x040000 |
---|
593 | QVBoxLayout *vLayout = new QVBoxLayout(fHelpDialog); |
---|
594 | #else |
---|
595 | QVBoxLayout *vLayout = new QVBoxLayout; |
---|
596 | splitter->addWidget(fHelpTreeWidget); |
---|
597 | splitter->addWidget(fHelpArea); |
---|
598 | #endif |
---|
599 | |
---|
600 | |
---|
601 | vLayout->addWidget(splitter); |
---|
602 | vLayout->addWidget(exitButton); |
---|
603 | #if QT_VERSION >= 0x040000 |
---|
604 | fHelpDialog->setLayout(vLayout); |
---|
605 | #endif |
---|
606 | |
---|
607 | } |
---|
608 | |
---|
609 | // Look for the choosen command "newCommand" |
---|
610 | size_t i = newCommand.index(" "); |
---|
611 | G4String targetCom=""; |
---|
612 | if( i != std::string::npos ) |
---|
613 | { |
---|
614 | G4String newValue = newCommand(i+1,newCommand.length()-(i+1)); |
---|
615 | newValue.strip(G4String::both); |
---|
616 | targetCom = ModifyToFullPathCommand( newValue ); |
---|
617 | } |
---|
618 | if (targetCom != "") { |
---|
619 | #if QT_VERSION < 0x040000 |
---|
620 | QListViewItem* findItem = NULL; |
---|
621 | QListViewItem* tmpItem = fHelpTreeWidget->firstChild(); |
---|
622 | while (tmpItem != 0) { |
---|
623 | if (!findItem) { |
---|
624 | findItem = FindTreeItem(tmpItem,QString((char*)targetCom.data())); |
---|
625 | } |
---|
626 | tmpItem = tmpItem->nextSibling(); |
---|
627 | } |
---|
628 | #else |
---|
629 | QTreeWidgetItem* findItem = NULL; |
---|
630 | for (int a=0;a<fHelpTreeWidget->topLevelItemCount();a++) { |
---|
631 | if (!findItem) { |
---|
632 | findItem = FindTreeItem(fHelpTreeWidget->topLevelItem(a),QString((char*)targetCom.data())); |
---|
633 | } |
---|
634 | } |
---|
635 | #endif |
---|
636 | |
---|
637 | if (findItem) { |
---|
638 | |
---|
639 | //collapsed open item |
---|
640 | #if QT_VERSION < 0x040000 |
---|
641 | |
---|
642 | // FIXME : Has to be checked |
---|
643 | QListViewItem* tmpItem = fHelpTreeWidget->firstChild(); |
---|
644 | QList<QListViewItem> openItems; |
---|
645 | while ((tmpItem != 0) || (!openItems.isEmpty())) { |
---|
646 | if (tmpItem->isOpen() ) { |
---|
647 | tmpItem->setOpen(false); |
---|
648 | openItems.append(tmpItem); |
---|
649 | tmpItem = tmpItem->firstChild(); |
---|
650 | } else { |
---|
651 | tmpItem = tmpItem->nextSibling(); |
---|
652 | } |
---|
653 | if (tmpItem == 0) { |
---|
654 | tmpItem = openItems.take(openItems.count()-1); |
---|
655 | } |
---|
656 | } |
---|
657 | #else |
---|
658 | QList<QTreeWidgetItem *> selected; |
---|
659 | |
---|
660 | selected = fHelpTreeWidget->selectedItems(); |
---|
661 | if ( selected.count() != 0 ) { |
---|
662 | QTreeWidgetItem * tmp =selected.at( 0 ); |
---|
663 | while ( tmp) { |
---|
664 | #if QT_VERSION < 0x040202 |
---|
665 | fHelpTreeWidget->setItemExpanded(tmp,false); |
---|
666 | #else |
---|
667 | tmp->setExpanded(false); |
---|
668 | #endif |
---|
669 | tmp = tmp->parent(); |
---|
670 | } |
---|
671 | } |
---|
672 | #endif |
---|
673 | |
---|
674 | // clear old selection |
---|
675 | fHelpTreeWidget->clearSelection(); |
---|
676 | |
---|
677 | // set new selection |
---|
678 | #if QT_VERSION >= 0x040000 |
---|
679 | #if QT_VERSION < 0x040202 |
---|
680 | fHelpTreeWidget->setItemSelected(findItem,true); |
---|
681 | #else |
---|
682 | findItem->setSelected(true); |
---|
683 | #endif |
---|
684 | #else |
---|
685 | findItem->setSelected(true); |
---|
686 | #endif |
---|
687 | |
---|
688 | // expand parent item |
---|
689 | while ( findItem) { |
---|
690 | #if QT_VERSION < 0x040000 |
---|
691 | findItem->setOpen(true); |
---|
692 | #else |
---|
693 | #if QT_VERSION < 0x040202 |
---|
694 | fHelpTreeWidget->setItemExpanded(findItem,true); |
---|
695 | #else |
---|
696 | findItem->setExpanded(true); |
---|
697 | #endif |
---|
698 | #endif |
---|
699 | findItem = findItem->parent(); |
---|
700 | } |
---|
701 | |
---|
702 | // Call the update of the right textArea |
---|
703 | HelpTreeClicCallback(); |
---|
704 | } |
---|
705 | } |
---|
706 | #if QT_VERSION < 0x040000 |
---|
707 | fHelpDialog->setCaption( tr( "Help on commands" )); |
---|
708 | #else |
---|
709 | fHelpDialog->setWindowTitle(tr("Help on commands")); |
---|
710 | #endif |
---|
711 | fHelpDialog->resize(800,600); |
---|
712 | fHelpDialog->move(QPoint(400,150)); |
---|
713 | fHelpDialog->show(); |
---|
714 | fHelpDialog->raise(); |
---|
715 | #if QT_VERSION < 0x040000 |
---|
716 | fHelpDialog->setActiveWindow(); |
---|
717 | #else |
---|
718 | fHelpDialog->activateWindow(); |
---|
719 | #endif |
---|
720 | } |
---|
721 | |
---|
722 | |
---|
723 | |
---|
724 | /** Fill the Help Tree Widget |
---|
725 | @param aParent : parent item to fill |
---|
726 | @param aCommandTree : commandTree node associate with this part of the Tree |
---|
727 | */ |
---|
728 | #if QT_VERSION < 0x040000 |
---|
729 | void G4UIQt::CreateChildTree( |
---|
730 | QListViewItem *aParent |
---|
731 | ,G4UIcommandTree *aCommandTree |
---|
732 | #else |
---|
733 | void G4UIQt::CreateChildTree( |
---|
734 | QTreeWidgetItem *aParent |
---|
735 | ,G4UIcommandTree *aCommandTree |
---|
736 | #endif |
---|
737 | ) |
---|
738 | { |
---|
739 | if (aParent == NULL) return; |
---|
740 | if (aCommandTree == NULL) return; |
---|
741 | |
---|
742 | |
---|
743 | // Creating new item |
---|
744 | #if QT_VERSION < 0x040000 |
---|
745 | QListViewItem * newItem; |
---|
746 | #else |
---|
747 | QTreeWidgetItem * newItem; |
---|
748 | #endif |
---|
749 | |
---|
750 | // Get the Sub directories |
---|
751 | for (int a=0;a<aCommandTree->GetTreeEntry();a++) { |
---|
752 | |
---|
753 | #if QT_VERSION < 0x040000 |
---|
754 | newItem = new QListViewItem(aParent); |
---|
755 | newItem->setText(0,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace()); |
---|
756 | newItem->setText(1,QString((char*)(aCommandTree->GetTree(a+1)->GetTitle()).data()).simplifyWhiteSpace()); |
---|
757 | |
---|
758 | #else |
---|
759 | newItem = new QTreeWidgetItem(aParent); |
---|
760 | newItem->setText(0,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed()); |
---|
761 | newItem->setText(1,QString((char*)(aCommandTree->GetTree(a+1)->GetTitle()).data()).trimmed()); |
---|
762 | #endif |
---|
763 | |
---|
764 | CreateChildTree(newItem,aCommandTree->GetTree(a+1)); |
---|
765 | } |
---|
766 | |
---|
767 | |
---|
768 | |
---|
769 | // Get the Commands |
---|
770 | |
---|
771 | for (int a=0;a<aCommandTree->GetCommandEntry();a++) { |
---|
772 | |
---|
773 | QStringList stringList; |
---|
774 | #if QT_VERSION < 0x040000 |
---|
775 | newItem = new QListViewItem(aParent); |
---|
776 | newItem->setText(0,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).simplifyWhiteSpace()); |
---|
777 | newItem->setText(1,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).simplifyWhiteSpace()); |
---|
778 | newItem->setOpen(false); |
---|
779 | |
---|
780 | #else |
---|
781 | newItem = new QTreeWidgetItem(aParent); |
---|
782 | newItem->setText(0,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed()); |
---|
783 | newItem->setText(1,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed()); |
---|
784 | #if QT_VERSION < 0x040202 |
---|
785 | fHelpTreeWidget->setItemExpanded(newItem,false); |
---|
786 | #else |
---|
787 | newItem->setExpanded(false); |
---|
788 | #endif |
---|
789 | #endif |
---|
790 | |
---|
791 | } |
---|
792 | } |
---|
793 | |
---|
794 | |
---|
795 | /** Find a treeItemWidget in the help tree |
---|
796 | @param aCommand item's String to look for |
---|
797 | @return item if found, NULL if not |
---|
798 | */ |
---|
799 | #if QT_VERSION < 0x040000 |
---|
800 | QListViewItem* G4UIQt::FindTreeItem( |
---|
801 | QListViewItem *aParent |
---|
802 | #else |
---|
803 | QTreeWidgetItem* G4UIQt::FindTreeItem( |
---|
804 | QTreeWidgetItem *aParent |
---|
805 | #endif |
---|
806 | ,const QString& aCommand |
---|
807 | ) |
---|
808 | { |
---|
809 | if (aParent == NULL) return NULL; |
---|
810 | |
---|
811 | if (aParent->text(0) == aCommand) |
---|
812 | return aParent; |
---|
813 | |
---|
814 | #if QT_VERSION < 0x040000 |
---|
815 | QListViewItem * tmp = NULL; |
---|
816 | QListViewItem* tmpItem = aParent->firstChild(); |
---|
817 | while (tmpItem != 0) { |
---|
818 | if (!tmp) |
---|
819 | tmp = FindTreeItem(tmpItem,aCommand); |
---|
820 | tmpItem = tmpItem->nextSibling(); |
---|
821 | } |
---|
822 | |
---|
823 | #else |
---|
824 | QTreeWidgetItem * tmp = NULL; |
---|
825 | for (int a=0;a<aParent->childCount();a++) { |
---|
826 | if (!tmp) |
---|
827 | tmp = FindTreeItem(aParent->child(a),aCommand); |
---|
828 | } |
---|
829 | #endif |
---|
830 | return tmp; |
---|
831 | } |
---|
832 | |
---|
833 | |
---|
834 | /** Build the command list parameters in a QString<br> |
---|
835 | Reimplement partialy the G4UIparameter.cc |
---|
836 | @param aCommand : command to list parameters |
---|
837 | @see G4UIparameter::List() |
---|
838 | @see G4UIcommand::List() |
---|
839 | @return the command list parameters, or "" if nothing |
---|
840 | */ |
---|
841 | QString G4UIQt::GetCommandList ( |
---|
842 | const G4UIcommand *aCommand |
---|
843 | ) |
---|
844 | { |
---|
845 | |
---|
846 | QString txt =""; |
---|
847 | if (aCommand == NULL) |
---|
848 | return txt; |
---|
849 | |
---|
850 | G4String commandPath = aCommand->GetCommandPath(); |
---|
851 | G4String rangeString = aCommand->GetRange(); |
---|
852 | G4int n_guidanceEntry = aCommand->GetGuidanceEntries(); |
---|
853 | G4int n_parameterEntry = aCommand->GetParameterEntries(); |
---|
854 | |
---|
855 | if ((commandPath == "") && |
---|
856 | (rangeString == "") && |
---|
857 | (n_guidanceEntry == 0) && |
---|
858 | (n_parameterEntry == 0)) { |
---|
859 | return txt; |
---|
860 | } |
---|
861 | |
---|
862 | if((commandPath.length()-1)!='/') { |
---|
863 | txt += "Command " + QString((char*)(commandPath).data()) + "\n"; |
---|
864 | } |
---|
865 | txt += "Guidance :\n"; |
---|
866 | |
---|
867 | for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) { |
---|
868 | txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n"; |
---|
869 | } |
---|
870 | if( ! rangeString.isNull() ) { |
---|
871 | txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n"; |
---|
872 | } |
---|
873 | if( n_parameterEntry > 0 ) { |
---|
874 | G4UIparameter *param; |
---|
875 | |
---|
876 | // Re-implementation of G4UIparameter.cc |
---|
877 | |
---|
878 | for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) { |
---|
879 | param = aCommand->GetParameter(i_thParameter); |
---|
880 | txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n"; |
---|
881 | if( ! param->GetParameterGuidance().isNull() ) |
---|
882 | txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ; |
---|
883 | txt += " Parameter type : " + QString(QChar(param->GetParameterType())) + "\n"; |
---|
884 | if(param->IsOmittable()){ |
---|
885 | txt += " Omittable : True\n"; |
---|
886 | } else { |
---|
887 | txt += " Omittable : False\n"; |
---|
888 | } |
---|
889 | if( param->GetCurrentAsDefault() ) { |
---|
890 | txt += " Default value : taken from the current value\n"; |
---|
891 | } else if( ! param->GetDefaultValue().isNull() ) { |
---|
892 | txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n"; |
---|
893 | } |
---|
894 | if( ! param->GetParameterRange().isNull() ) { |
---|
895 | txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n"; |
---|
896 | } |
---|
897 | if( ! param->GetParameterCandidates().isNull() ) { |
---|
898 | txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n"; |
---|
899 | } |
---|
900 | } |
---|
901 | } |
---|
902 | return txt; |
---|
903 | } |
---|
904 | |
---|
905 | |
---|
906 | |
---|
907 | /** Implement G4VBasicShell vurtual function |
---|
908 | */ |
---|
909 | G4bool G4UIQt::GetHelpChoice( |
---|
910 | G4int& aInt |
---|
911 | ) |
---|
912 | { |
---|
913 | #ifdef GEANT4_QT_DEBUG |
---|
914 | printf("G4UIQt::GetHelpChoice SHOULD NEVER GO HERE"); |
---|
915 | #endif |
---|
916 | return true; |
---|
917 | } |
---|
918 | |
---|
919 | |
---|
920 | /** Implement G4VBasicShell vurtual function |
---|
921 | */ |
---|
922 | void G4UIQt::ExitHelp( |
---|
923 | ) |
---|
924 | { |
---|
925 | #ifdef GEANT4_QT_DEBUG |
---|
926 | printf("G4UIQt::ExitHelp SHOULD NEVER GO HERE"); |
---|
927 | #endif |
---|
928 | } |
---|
929 | |
---|
930 | |
---|
931 | /** Event filter method. Every event from QtApplication goes here.<br/> |
---|
932 | We apply a filter only for the Up and Down Arrow press when the QLineEdit<br/> |
---|
933 | is active. If this filter match, Up arrow we give the previous command<br/> |
---|
934 | and Down arrow will give the next if exist.<br/> |
---|
935 | @param obj Emitter of the event |
---|
936 | @param event Kind of event |
---|
937 | */ |
---|
938 | bool G4UIQt::eventFilter( // Should stay with a minuscule eventFilter because of Qt |
---|
939 | QObject *aObj |
---|
940 | ,QEvent *aEvent |
---|
941 | ) |
---|
942 | { |
---|
943 | if (aObj == NULL) return false; |
---|
944 | if (aEvent == NULL) return false; |
---|
945 | |
---|
946 | if (aObj == fCommandHistoryArea) { |
---|
947 | if (aEvent->type() == QEvent::KeyPress) { |
---|
948 | fCommandArea->setFocus(); |
---|
949 | } |
---|
950 | } |
---|
951 | if (aObj == fCommandArea) { |
---|
952 | if (aEvent->type() == QEvent::KeyPress) { |
---|
953 | QKeyEvent *e = static_cast<QKeyEvent*>(aEvent); |
---|
954 | if ((e->key() == (Qt::Key_Down)) || |
---|
955 | (e->key() == (Qt::Key_PageDown)) || |
---|
956 | (e->key() == (Qt::Key_Up)) || |
---|
957 | (e->key() == (Qt::Key_PageUp))) { |
---|
958 | #if QT_VERSION < 0x040000 |
---|
959 | // count rows... |
---|
960 | QListViewItem* tmpItem = fCommandHistoryArea->firstChild(); |
---|
961 | int selection = -1; |
---|
962 | int index = 0; |
---|
963 | while (tmpItem != 0) { |
---|
964 | if (tmpItem == fCommandHistoryArea->selectedItem()) { |
---|
965 | selection = index; |
---|
966 | } |
---|
967 | index ++; |
---|
968 | tmpItem = tmpItem->nextSibling(); |
---|
969 | } |
---|
970 | if (fCommandHistoryArea->childCount()) { |
---|
971 | if (selection == -1) { |
---|
972 | selection = fCommandHistoryArea->childCount()-1; |
---|
973 | } else { |
---|
974 | if (e->key() == (Qt::Key_Down)) { |
---|
975 | if (selection <(fCommandHistoryArea->childCount()-1)) |
---|
976 | selection++; |
---|
977 | } else if (e->key() == (Qt::Key_PageDown)) { |
---|
978 | selection = fCommandHistoryArea->childCount()-1; |
---|
979 | #else |
---|
980 | int selection = fCommandHistoryArea->currentRow(); |
---|
981 | if (fCommandHistoryArea->count()) { |
---|
982 | if (selection == -1) { |
---|
983 | selection = fCommandHistoryArea->count()-1; |
---|
984 | } else { |
---|
985 | if (e->key() == (Qt::Key_Down)) { |
---|
986 | if (selection <(fCommandHistoryArea->count()-1)) |
---|
987 | selection++; |
---|
988 | } else if (e->key() == (Qt::Key_PageDown)) { |
---|
989 | selection = fCommandHistoryArea->count()-1; |
---|
990 | #endif |
---|
991 | } else if (e->key() == (Qt::Key_Up)) { |
---|
992 | if (selection >0) |
---|
993 | selection --; |
---|
994 | } else if (e->key() == (Qt::Key_PageUp)) { |
---|
995 | selection = 0; |
---|
996 | } |
---|
997 | } |
---|
998 | fCommandHistoryArea->clearSelection(); |
---|
999 | #if QT_VERSION < 0x040000 |
---|
1000 | QListViewItem* tmpItem = fCommandHistoryArea->firstChild(); |
---|
1001 | int index = 0; |
---|
1002 | while (tmpItem != 0) { |
---|
1003 | if (index == selection) { |
---|
1004 | tmpItem->setSelected(true); |
---|
1005 | fCommandHistoryArea->setCurrentItem(tmpItem); |
---|
1006 | } |
---|
1007 | index ++; |
---|
1008 | tmpItem = tmpItem->nextSibling(); |
---|
1009 | } |
---|
1010 | #else |
---|
1011 | #if QT_VERSION < 0x040202 |
---|
1012 | fCommandHistoryArea->setItemSelected(fCommandHistoryArea->item(selection),true); |
---|
1013 | #else |
---|
1014 | fCommandHistoryArea->item(selection)->setSelected(true); |
---|
1015 | #endif |
---|
1016 | fCommandHistoryArea->setCurrentItem(fCommandHistoryArea->item(selection)); |
---|
1017 | #endif |
---|
1018 | } |
---|
1019 | } else if (e->key() == (Qt::Key_Tab)) { |
---|
1020 | #if QT_VERSION < 0x040000 |
---|
1021 | G4String ss = Complete(fCommandArea->text().ascii()); |
---|
1022 | #else |
---|
1023 | G4String ss = Complete(fCommandArea->text().toStdString().c_str()); |
---|
1024 | #endif |
---|
1025 | fCommandArea->setText((char*)(ss.data())); |
---|
1026 | |
---|
1027 | // do not pass by parent, it will disable widget tab focus ! |
---|
1028 | return true; |
---|
1029 | } |
---|
1030 | } |
---|
1031 | } |
---|
1032 | // pass the event on to the parent class |
---|
1033 | return QObject::eventFilter(aObj, aEvent); |
---|
1034 | } |
---|
1035 | |
---|
1036 | |
---|
1037 | |
---|
1038 | |
---|
1039 | /***************************************************************************/ |
---|
1040 | // |
---|
1041 | // SLOTS DEFINITIONS |
---|
1042 | // |
---|
1043 | /***************************************************************************/ |
---|
1044 | |
---|
1045 | /** Called when user give "help" command. |
---|
1046 | */ |
---|
1047 | void G4UIQt::ShowHelpCallback ( |
---|
1048 | ) |
---|
1049 | { |
---|
1050 | TerminalHelp(""); |
---|
1051 | } |
---|
1052 | |
---|
1053 | |
---|
1054 | /** Called when user click on clear button. Clear the text Output area |
---|
1055 | */ |
---|
1056 | void G4UIQt::ClearButtonCallback ( |
---|
1057 | ) |
---|
1058 | { |
---|
1059 | fTextArea->clear(); |
---|
1060 | } |
---|
1061 | |
---|
1062 | /** Called when user exit session |
---|
1063 | */ |
---|
1064 | void G4UIQt::ExitSession ( |
---|
1065 | ) |
---|
1066 | { |
---|
1067 | SessionTerminate(); |
---|
1068 | } |
---|
1069 | |
---|
1070 | |
---|
1071 | /** Callback call when "click on a menu entry.<br> |
---|
1072 | Send the associated command to geant4 |
---|
1073 | */ |
---|
1074 | void G4UIQt::CommandEnteredCallback ( |
---|
1075 | ) |
---|
1076 | { |
---|
1077 | #if QT_VERSION < 0x040000 |
---|
1078 | G4String command (fCommandArea->text().ascii()); |
---|
1079 | if (fCommandArea->text().simplifyWhiteSpace() != "") { |
---|
1080 | |
---|
1081 | QListViewItem *newItem = new QListViewItem(fCommandHistoryArea); |
---|
1082 | newItem->setText(0,fCommandArea->text()); |
---|
1083 | #else |
---|
1084 | G4String command (fCommandArea->text().toStdString().c_str()); |
---|
1085 | if (fCommandArea->text().trimmed() != "") { |
---|
1086 | fCommandHistoryArea->addItem(fCommandArea->text()); |
---|
1087 | #endif |
---|
1088 | fCommandHistoryArea->clearSelection(); |
---|
1089 | fCommandHistoryArea->setCurrentItem(NULL); |
---|
1090 | fCommandArea->setText(""); |
---|
1091 | |
---|
1092 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
1093 | if (interactorManager) { |
---|
1094 | interactorManager->FlushAndWaitExecution(); |
---|
1095 | } |
---|
1096 | if (command(0,4) != "help") { |
---|
1097 | ApplyShellCommand (command,exitSession,exitPause); |
---|
1098 | } else { |
---|
1099 | TerminalHelp(command); |
---|
1100 | } |
---|
1101 | #ifdef GEANT4_QT_DEBUG |
---|
1102 | printf("after \n"); |
---|
1103 | #endif |
---|
1104 | if(exitSession==true) |
---|
1105 | SessionTerminate(); |
---|
1106 | } |
---|
1107 | } |
---|
1108 | |
---|
1109 | |
---|
1110 | /** Callback call when "enter" clicked on the command zone.<br> |
---|
1111 | Send the command to geant4 |
---|
1112 | @param aCommand |
---|
1113 | */ |
---|
1114 | void G4UIQt::ButtonCallback ( |
---|
1115 | const QString& aCommand |
---|
1116 | ) |
---|
1117 | { |
---|
1118 | #if QT_VERSION < 0x040000 |
---|
1119 | G4String ss = G4String(aCommand.ascii()); |
---|
1120 | #else |
---|
1121 | G4String ss = G4String(aCommand.toStdString().c_str()); |
---|
1122 | #endif |
---|
1123 | ApplyShellCommand(ss,exitSession,exitPause); |
---|
1124 | if(exitSession==true) |
---|
1125 | SessionTerminate(); |
---|
1126 | } |
---|
1127 | |
---|
1128 | |
---|
1129 | |
---|
1130 | /** This callback is activated when user selected a item in the help tree |
---|
1131 | */ |
---|
1132 | void G4UIQt::HelpTreeClicCallback ( |
---|
1133 | ) |
---|
1134 | { |
---|
1135 | // printf("G4UIQt::HelpTreeClicCallback"); |
---|
1136 | #if QT_VERSION < 0x040000 |
---|
1137 | QListViewItem* item = NULL; |
---|
1138 | #else |
---|
1139 | QTreeWidgetItem* item = NULL; |
---|
1140 | #endif |
---|
1141 | if (!fHelpTreeWidget) |
---|
1142 | return ; |
---|
1143 | |
---|
1144 | if (!fHelpArea) |
---|
1145 | return; |
---|
1146 | |
---|
1147 | #if QT_VERSION < 0x040000 |
---|
1148 | item =fHelpTreeWidget->selectedItem(); |
---|
1149 | #else |
---|
1150 | QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems(); |
---|
1151 | if (list.isEmpty()) |
---|
1152 | return; |
---|
1153 | item = list.first(); |
---|
1154 | #endif |
---|
1155 | if (!item) |
---|
1156 | return; |
---|
1157 | |
---|
1158 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
1159 | if(UI==NULL) return; |
---|
1160 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
1161 | #if QT_VERSION < 0x040000 |
---|
1162 | G4UIcommand* command = treeTop->FindPath(item->text (1).ascii()); |
---|
1163 | #else |
---|
1164 | G4UIcommand* command = treeTop->FindPath(item->text (1).toStdString().c_str()); |
---|
1165 | #endif |
---|
1166 | if (command) { |
---|
1167 | #if QT_VERSION >= 0x040000 |
---|
1168 | #if QT_VERSION < 0x040200 |
---|
1169 | fHelpArea->clear(); |
---|
1170 | fHelpArea->append(GetCommandList(command)); |
---|
1171 | #else |
---|
1172 | fHelpArea->setText(GetCommandList(command)); |
---|
1173 | #endif |
---|
1174 | #else |
---|
1175 | fHelpArea->setText(GetCommandList(command)); |
---|
1176 | #endif |
---|
1177 | } else { |
---|
1178 | // this is not a command, this is a sub directory |
---|
1179 | // We display the Title |
---|
1180 | #if QT_VERSION >= 0x040000 |
---|
1181 | #if QT_VERSION < 0x040200 |
---|
1182 | fHelpArea->clear(); |
---|
1183 | fHelpArea->append(item->text (1)); |
---|
1184 | #else |
---|
1185 | fHelpArea->setText(item->text (1)); |
---|
1186 | #endif |
---|
1187 | #else |
---|
1188 | fHelpArea->setText(item->text (1)); |
---|
1189 | #endif |
---|
1190 | } |
---|
1191 | } |
---|
1192 | |
---|
1193 | /** This callback is activated when user double clic on a item in the help tree |
---|
1194 | */ |
---|
1195 | void G4UIQt::HelpTreeDoubleClicCallback ( |
---|
1196 | #if QT_VERSION < 0x040000 |
---|
1197 | QListViewItem* item |
---|
1198 | #else |
---|
1199 | QTreeWidgetItem* item |
---|
1200 | #endif |
---|
1201 | ,int nb |
---|
1202 | ) |
---|
1203 | { |
---|
1204 | #ifdef GEANT4_QT_DEBUG |
---|
1205 | printf("G4UIQt::HelpTreeDoubleClicCallback"); |
---|
1206 | #endif |
---|
1207 | HelpTreeClicCallback(); |
---|
1208 | fCommandArea->setText(item->text (1)); |
---|
1209 | } |
---|
1210 | |
---|
1211 | |
---|
1212 | /** Callback called when user select an old command in the command history<br> |
---|
1213 | Give it to the command area. |
---|
1214 | */ |
---|
1215 | void G4UIQt::CommandHistoryCallback( |
---|
1216 | ) |
---|
1217 | { |
---|
1218 | #if QT_VERSION < 0x040000 |
---|
1219 | QListViewItem* item = NULL; |
---|
1220 | #else |
---|
1221 | QListWidgetItem* item = NULL; |
---|
1222 | #endif |
---|
1223 | if (!fCommandHistoryArea) |
---|
1224 | return ; |
---|
1225 | |
---|
1226 | |
---|
1227 | #if QT_VERSION < 0x040000 |
---|
1228 | item =fHelpTreeWidget->selectedItem(); |
---|
1229 | #else |
---|
1230 | QList<QListWidgetItem *> list =fCommandHistoryArea->selectedItems(); |
---|
1231 | if (list.isEmpty()) |
---|
1232 | return; |
---|
1233 | item = list.first(); |
---|
1234 | #endif |
---|
1235 | if (!item) |
---|
1236 | return; |
---|
1237 | #if QT_VERSION < 0x040000 |
---|
1238 | fCommandArea->setText(item->text(0)); |
---|
1239 | #else |
---|
1240 | fCommandArea->setText(item->text()); |
---|
1241 | #endif |
---|
1242 | |
---|
1243 | } |
---|
1244 | |
---|
1245 | #endif |
---|