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.27 2009/10/07 09:12:35 lgarnier Exp $ |
---|
28 | // GEANT4 tag $Name: $ |
---|
29 | // |
---|
30 | // L. Garnier |
---|
31 | |
---|
32 | #ifdef G4UI_BUILD_QT_SESSION |
---|
33 | |
---|
34 | #include "G4Types.hh" |
---|
35 | |
---|
36 | #include <string.h> |
---|
37 | |
---|
38 | #include "G4UIQt.hh" |
---|
39 | #include "G4UImanager.hh" |
---|
40 | #include "G4StateManager.hh" |
---|
41 | #include "G4UIcommandTree.hh" |
---|
42 | #include "G4UIcommandStatus.hh" |
---|
43 | |
---|
44 | #include "G4Qt.hh" |
---|
45 | |
---|
46 | #include <qapplication.h> |
---|
47 | #include <qlineedit.h> |
---|
48 | #include <qwidget.h> |
---|
49 | #include <qmenubar.h> |
---|
50 | #include <qlayout.h> |
---|
51 | #include <qpushbutton.h> |
---|
52 | #include <qlabel.h> |
---|
53 | #include <qsplitter.h> |
---|
54 | #include <qscrollbar.h> |
---|
55 | #include <qdialog.h> |
---|
56 | #include <qevent.h> |
---|
57 | #include <qtextedit.h> |
---|
58 | #include <qsignalmapper.h> |
---|
59 | |
---|
60 | #include <qmainwindow.h> |
---|
61 | #if QT_VERSION >= 0x040000 |
---|
62 | #include <qmenu.h> |
---|
63 | #include <qlistwidget.h> |
---|
64 | #include <qtreewidget.h> |
---|
65 | #else |
---|
66 | #include <qaction.h> |
---|
67 | #include <qheader.h> |
---|
68 | #include <qlistview.h> |
---|
69 | #include <qpopupmenu.h> |
---|
70 | #include <qwidgetlist.h> |
---|
71 | #endif |
---|
72 | |
---|
73 | |
---|
74 | |
---|
75 | #include <stdlib.h> |
---|
76 | |
---|
77 | // Pourquoi Static et non variables de classe ? |
---|
78 | static G4bool exitSession = true; |
---|
79 | static G4bool exitPause = true; |
---|
80 | |
---|
81 | /** Build a Qt window with a menubar, output area and promt area<br> |
---|
82 | <pre> |
---|
83 | +-----------------------+ |
---|
84 | |exit menu| | |
---|
85 | | | |
---|
86 | | +-------------------+ | |
---|
87 | | | | | |
---|
88 | | | Output area | | |
---|
89 | | | | | |
---|
90 | | +-------------------+ | |
---|
91 | | | clear | | |
---|
92 | | +-------------------+ | |
---|
93 | | | promt history | | |
---|
94 | | +-------------------+ | |
---|
95 | | +-------------------+ | |
---|
96 | | |> promt area | | |
---|
97 | | +-------------------+ | |
---|
98 | +-----------------------+ |
---|
99 | </pre> |
---|
100 | */ |
---|
101 | G4UIQt::G4UIQt ( |
---|
102 | int argc |
---|
103 | ,char** argv |
---|
104 | ) |
---|
105 | :fHelpDialog(NULL) |
---|
106 | { |
---|
107 | G4Qt* interactorManager = G4Qt::getInstance (argc,argv,(char*)"Qt"); |
---|
108 | if (!(QApplication*)interactorManager->GetMainInteractor()) { |
---|
109 | G4cout << "G4UIQt : Unable to init Qt. Aborted" << G4endl; |
---|
110 | } |
---|
111 | |
---|
112 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
113 | if(UI!=NULL) UI->SetSession(this); |
---|
114 | |
---|
115 | // Check if already define in external app QMainWindow |
---|
116 | bool found = false; |
---|
117 | #if QT_VERSION < 0x040000 |
---|
118 | // theses lines does nothing exept this one "GLWindow = new QDialog(0..." |
---|
119 | // but if I comment them, it doesn't work... |
---|
120 | QWidgetList *list = QApplication::allWidgets(); |
---|
121 | QWidgetListIt it( *list ); // iterate over the widgets |
---|
122 | QWidget * widget; |
---|
123 | while ( (widget=it.current()) != 0 ) { // for each widget... |
---|
124 | ++it; |
---|
125 | if ((found== false) && (widget->inherits("QMainWindow"))) { |
---|
126 | found = true; |
---|
127 | } |
---|
128 | } |
---|
129 | delete list; // delete the list, not the widgets |
---|
130 | #else |
---|
131 | foreach (QWidget *widget, QApplication::allWidgets()) { |
---|
132 | if ((found== false) && (widget->inherits("QMainWindow"))) { |
---|
133 | found = true; |
---|
134 | } |
---|
135 | } |
---|
136 | #endif |
---|
137 | |
---|
138 | if (found) { |
---|
139 | G4cout << "G4UIQt : Found an external App with a QMainWindow already defined. Aborted" << G4endl; |
---|
140 | return ; |
---|
141 | } |
---|
142 | fMainWindow = new QMainWindow(); |
---|
143 | |
---|
144 | #ifdef G4DEBUG_INTERFACES_BASIC |
---|
145 | printf("G4UIQt::Initialise after main window creation\n"); |
---|
146 | #endif |
---|
147 | #if QT_VERSION < 0x040000 |
---|
148 | fMainWindow->setCaption( tr( "G4UI Session" )); |
---|
149 | fMainWindow->resize(900,600); |
---|
150 | fMainWindow->move(50,100); |
---|
151 | #else |
---|
152 | fMainWindow->setWindowTitle( tr("G4UI Session") ); |
---|
153 | fMainWindow->resize(900,600); |
---|
154 | fMainWindow->move(QPoint(50,100)); |
---|
155 | #endif |
---|
156 | |
---|
157 | QWidget *mainWidget = new QWidget(fMainWindow); |
---|
158 | QSplitter *splitter = new QSplitter(Qt::Vertical,mainWidget); |
---|
159 | |
---|
160 | // Set layouts |
---|
161 | |
---|
162 | QWidget* topWidget = new QWidget(splitter); |
---|
163 | QWidget* bottomWidget = new QWidget(splitter); |
---|
164 | |
---|
165 | QVBoxLayout *layoutTop = new QVBoxLayout(topWidget); |
---|
166 | QVBoxLayout *layoutBottom = new QVBoxLayout(bottomWidget); |
---|
167 | |
---|
168 | // fill them |
---|
169 | |
---|
170 | fTextArea = new QTextEdit(topWidget); |
---|
171 | QPushButton *clearButton = new QPushButton("clear",topWidget); |
---|
172 | connect(clearButton, SIGNAL(clicked()), SLOT(ClearButtonCallback())); |
---|
173 | |
---|
174 | #if QT_VERSION < 0x040000 |
---|
175 | |
---|
176 | fCommandHistoryArea = new QListView(bottomWidget); |
---|
177 | fCommandHistoryArea->setSorting (-1, FALSE); |
---|
178 | fCommandHistoryArea->setSelectionMode(QListView::Single); |
---|
179 | fCommandHistoryArea->addColumn(""); |
---|
180 | fCommandHistoryArea->header()->hide(); |
---|
181 | connect(fCommandHistoryArea, SIGNAL(selectionChanged()), SLOT(CommandHistoryCallback())); |
---|
182 | #else |
---|
183 | fCommandHistoryArea = new QListWidget(); |
---|
184 | fCommandHistoryArea->setSelectionMode(QAbstractItemView::SingleSelection); |
---|
185 | connect(fCommandHistoryArea, SIGNAL(itemSelectionChanged()), SLOT(CommandHistoryCallback())); |
---|
186 | #endif |
---|
187 | fCommandHistoryArea->installEventFilter(this); |
---|
188 | fCommandLabel = new QLabel("",bottomWidget); |
---|
189 | |
---|
190 | fCommandArea = new QLineEdit(bottomWidget); |
---|
191 | fCommandArea->installEventFilter(this); |
---|
192 | #if QT_VERSION < 0x040000 |
---|
193 | fCommandArea->setActiveWindow(); |
---|
194 | #else |
---|
195 | fCommandArea->activateWindow(); |
---|
196 | #endif |
---|
197 | connect(fCommandArea, SIGNAL(returnPressed()), SLOT(CommandEnteredCallback())); |
---|
198 | #if QT_VERSION < 0x040000 |
---|
199 | fCommandArea->setFocusPolicy ( QWidget::StrongFocus ); |
---|
200 | fCommandArea->setFocus(); |
---|
201 | #else |
---|
202 | fCommandArea->setFocusPolicy ( Qt::StrongFocus ); |
---|
203 | fCommandArea->setFocus(Qt::TabFocusReason); |
---|
204 | #endif |
---|
205 | fTextArea->setReadOnly(true); |
---|
206 | |
---|
207 | layoutTop->addWidget(fTextArea); |
---|
208 | layoutTop->addWidget(clearButton); |
---|
209 | |
---|
210 | #if QT_VERSION >= 0x040000 |
---|
211 | // topWidget->setLayout(layoutTop); |
---|
212 | #endif |
---|
213 | |
---|
214 | layoutBottom->addWidget(fCommandHistoryArea); |
---|
215 | layoutBottom->addWidget(fCommandLabel); |
---|
216 | layoutBottom->addWidget(fCommandArea); |
---|
217 | #if QT_VERSION >= 0x040000 |
---|
218 | |
---|
219 | // bottomWidget->setLayout(layoutBottom); |
---|
220 | QVBoxLayout *mainLayout = new QVBoxLayout(mainWidget); |
---|
221 | |
---|
222 | splitter->addWidget(topWidget); |
---|
223 | splitter->addWidget(bottomWidget); |
---|
224 | |
---|
225 | mainLayout->addWidget(splitter); |
---|
226 | |
---|
227 | #endif |
---|
228 | |
---|
229 | fMainWindow->setCentralWidget(mainWidget); |
---|
230 | //fMainWindow->setCentralWidget(splitter); |
---|
231 | |
---|
232 | #if QT_VERSION < 0x040000 |
---|
233 | |
---|
234 | // Add a quit subMenu |
---|
235 | QPopupMenu *fileMenu = new QPopupMenu( fMainWindow); |
---|
236 | fileMenu->insertItem( "&Quit", this, SLOT(ExitSession()), CTRL+Key_Q ); |
---|
237 | fMainWindow->menuBar()->insertItem( QString("&File"), fileMenu ); |
---|
238 | |
---|
239 | // Add a Help menu |
---|
240 | QPopupMenu *helpMenu = new QPopupMenu( fMainWindow ); |
---|
241 | helpMenu->insertItem( "&Show Help", this, SLOT(ShowHelpCallback()), CTRL+Key_H ); |
---|
242 | fMainWindow->menuBar()->insertItem( QString("&Help"), helpMenu ); |
---|
243 | |
---|
244 | |
---|
245 | #else |
---|
246 | |
---|
247 | // Add a quit subMenu |
---|
248 | QMenu *fileMenu = fMainWindow->menuBar()->addMenu("File"); |
---|
249 | fileMenu->addAction("Quit", this, SLOT(ExitSession())); |
---|
250 | |
---|
251 | // Add a Help menu |
---|
252 | QMenu *helpMenu = fMainWindow->menuBar()->addMenu("Help"); |
---|
253 | helpMenu->addAction("Show Help", this, SLOT(ShowHelpCallback())); |
---|
254 | #endif |
---|
255 | |
---|
256 | AddInteractor ("file",(G4Interactor)fileMenu); |
---|
257 | AddInteractor ("help",(G4Interactor)helpMenu); |
---|
258 | |
---|
259 | // Set the splitter size. The fTextArea sould be 2/3 on the fMainWindow |
---|
260 | #if QT_VERSION < 0x040000 |
---|
261 | QValueList<int> vals = splitter->sizes(); |
---|
262 | #else |
---|
263 | QList<int> vals = splitter->sizes(); |
---|
264 | #endif |
---|
265 | // if(vals.size()==2) { |
---|
266 | // vals[0] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*3/4; |
---|
267 | // vals[1] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*1/4; |
---|
268 | // splitter->setSizes(vals); |
---|
269 | // } |
---|
270 | |
---|
271 | if(UI!=NULL) UI->SetCoutDestination(this); // TO KEEP |
---|
272 | } |
---|
273 | |
---|
274 | |
---|
275 | |
---|
276 | G4UIQt::~G4UIQt( |
---|
277 | ) |
---|
278 | { |
---|
279 | G4UImanager* UI = G4UImanager::GetUIpointer(); // TO KEEP |
---|
280 | if(UI!=NULL) { // TO KEEP |
---|
281 | UI->SetSession(NULL); // TO KEEP |
---|
282 | UI->SetCoutDestination(NULL); // TO KEEP |
---|
283 | } |
---|
284 | |
---|
285 | if (fMainWindow!=NULL) |
---|
286 | delete fMainWindow; |
---|
287 | } |
---|
288 | |
---|
289 | |
---|
290 | |
---|
291 | /** Start the Qt main loop |
---|
292 | */ |
---|
293 | G4UIsession* G4UIQt::SessionStart ( |
---|
294 | ) |
---|
295 | { |
---|
296 | |
---|
297 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
298 | |
---|
299 | fMainWindow->show(); |
---|
300 | |
---|
301 | Prompt("session"); |
---|
302 | exitSession = false; |
---|
303 | |
---|
304 | |
---|
305 | interactorManager->DisableSecondaryLoop (); // TO KEEP |
---|
306 | if ((QApplication*)interactorManager->GetMainInteractor()) |
---|
307 | ((QApplication*)interactorManager->GetMainInteractor())->exec(); |
---|
308 | |
---|
309 | // on ne passe pas le dessous ? FIXME ???? |
---|
310 | // je ne pense pas 13/06 |
---|
311 | |
---|
312 | // void* event; // TO KEEP |
---|
313 | // while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
314 | // interactorManager->DispatchEvent(event); // TO KEEP |
---|
315 | // if(exitSession==true) break; // TO KEEP |
---|
316 | // } // TO KEEP |
---|
317 | |
---|
318 | interactorManager->EnableSecondaryLoop (); |
---|
319 | return this; |
---|
320 | } |
---|
321 | |
---|
322 | |
---|
323 | /** Display the prompt in the prompt area |
---|
324 | @param aPrompt : string to display as the promt label |
---|
325 | //FIXME : probablement inutile puisque le seul a afficher qq chose d'autre |
---|
326 | que "session" est SecondaryLoop() |
---|
327 | */ |
---|
328 | void G4UIQt::Prompt ( |
---|
329 | G4String aPrompt |
---|
330 | ) |
---|
331 | { |
---|
332 | if (!aPrompt) return; |
---|
333 | |
---|
334 | fCommandLabel->setText((char*)aPrompt.data()); |
---|
335 | } |
---|
336 | |
---|
337 | |
---|
338 | QMainWindow * G4UIQt::getMainWindow ( |
---|
339 | ) |
---|
340 | { |
---|
341 | return fMainWindow; |
---|
342 | } |
---|
343 | |
---|
344 | void G4UIQt::SessionTerminate ( |
---|
345 | ) |
---|
346 | { |
---|
347 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
348 | fMainWindow->close(); |
---|
349 | ((QApplication*)interactorManager->GetMainInteractor())->exit(); |
---|
350 | } |
---|
351 | |
---|
352 | |
---|
353 | |
---|
354 | /** |
---|
355 | Called by intercoms/src/G4UImanager.cc<br> |
---|
356 | Called by visualization/management/src/G4VisCommands.cc with "EndOfEvent" argument<br> |
---|
357 | It have to pause the session command terminal.<br> |
---|
358 | Call SecondaryLoop to wait for exit event<br> |
---|
359 | @param aState |
---|
360 | @see : G4VisCommandReviewKeptEvents::SetNewValue |
---|
361 | */ |
---|
362 | void G4UIQt::PauseSessionStart ( |
---|
363 | G4String aState |
---|
364 | ) |
---|
365 | { |
---|
366 | if (!aState) return; |
---|
367 | |
---|
368 | if(aState=="G4_pause> ") { // TO KEEP |
---|
369 | SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP |
---|
370 | } // TO KEEP |
---|
371 | |
---|
372 | if(aState=="EndOfEvent") { // TO KEEP |
---|
373 | // Picking with feed back in event data Done here !!! |
---|
374 | SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP |
---|
375 | } // TO KEEP |
---|
376 | } |
---|
377 | |
---|
378 | |
---|
379 | |
---|
380 | /** |
---|
381 | Begin the secondary loop |
---|
382 | @param a_prompt : label to display as the prompt label |
---|
383 | */ |
---|
384 | void G4UIQt::SecondaryLoop ( |
---|
385 | G4String aPrompt |
---|
386 | ) |
---|
387 | { |
---|
388 | if (!aPrompt) return; |
---|
389 | |
---|
390 | G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ? |
---|
391 | Prompt(aPrompt); // TO KEEP |
---|
392 | exitPause = false; // TO KEEP |
---|
393 | void* event; // TO KEEP |
---|
394 | while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
395 | interactorManager->DispatchEvent(event); // TO KEEP |
---|
396 | if(exitPause==true) break; // TO KEEP |
---|
397 | } // TO KEEP |
---|
398 | Prompt("session"); // TO KEEP |
---|
399 | } |
---|
400 | |
---|
401 | |
---|
402 | |
---|
403 | /** |
---|
404 | Receive a cout from Geant4. We have to display it in the cout zone |
---|
405 | @param aString : label to add in the display area |
---|
406 | @return 0 |
---|
407 | */ |
---|
408 | G4int G4UIQt::ReceiveG4cout ( |
---|
409 | G4String aString |
---|
410 | ) |
---|
411 | { |
---|
412 | if (!aString) return 0; |
---|
413 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
414 | if (!interactorManager) return 0; |
---|
415 | |
---|
416 | #if QT_VERSION < 0x040000 |
---|
417 | fTextArea->append(QString((char*)aString.data()).simplifyWhiteSpace()); |
---|
418 | fTextArea->verticalScrollBar()->setValue(fTextArea->verticalScrollBar()->maxValue()); |
---|
419 | #else |
---|
420 | fTextArea->append(QString((char*)aString.data()).trimmed()); |
---|
421 | fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum()); |
---|
422 | #endif |
---|
423 | fTextArea->repaint(); |
---|
424 | // interactorManager->FlushAndWaitExecution(); |
---|
425 | return 0; |
---|
426 | } |
---|
427 | |
---|
428 | |
---|
429 | /** |
---|
430 | Receive a cerr from Geant4. We have to display it in the cout zone |
---|
431 | @param aString : label to add in the display area |
---|
432 | @return 0 |
---|
433 | */ |
---|
434 | G4int G4UIQt::ReceiveG4cerr ( |
---|
435 | G4String aString |
---|
436 | ) |
---|
437 | { |
---|
438 | if (!aString) return 0; |
---|
439 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
440 | if (!interactorManager) return 0; |
---|
441 | |
---|
442 | #if QT_VERSION < 0x040000 |
---|
443 | QColor previousColor = fTextArea->color(); |
---|
444 | fTextArea->setColor(Qt::red); |
---|
445 | fTextArea->append(QString((char*)aString.data()).simplifyWhiteSpace()); |
---|
446 | fTextArea->setColor(previousColor); |
---|
447 | fTextArea->verticalScrollBar()->setValue(fTextArea->verticalScrollBar()->maxValue()); |
---|
448 | #else |
---|
449 | QColor previousColor = fTextArea->textColor(); |
---|
450 | fTextArea->setTextColor(Qt::red); |
---|
451 | fTextArea->append(QString((char*)aString.data()).trimmed()); |
---|
452 | fTextArea->setTextColor(previousColor); |
---|
453 | fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum()); |
---|
454 | #endif |
---|
455 | fTextArea->repaint(); |
---|
456 | // interactorManager->FlushAndWaitExecution(); |
---|
457 | return 0; |
---|
458 | } |
---|
459 | |
---|
460 | |
---|
461 | |
---|
462 | /** |
---|
463 | Add a new menu to the menu bar |
---|
464 | @param aName name of menu |
---|
465 | @param aLabel label to display |
---|
466 | */ |
---|
467 | void G4UIQt::AddMenu ( |
---|
468 | const char* aName |
---|
469 | ,const char* aLabel |
---|
470 | ) |
---|
471 | { |
---|
472 | if (aName == NULL) return; |
---|
473 | if (aLabel == NULL) return; |
---|
474 | |
---|
475 | #if QT_VERSION < 0x040000 |
---|
476 | QPopupMenu *fileMenu = new QPopupMenu( fMainWindow); |
---|
477 | fMainWindow->menuBar()->insertItem( aLabel, fileMenu ); |
---|
478 | #else |
---|
479 | QMenu *fileMenu = new QMenu(aLabel); |
---|
480 | fMainWindow->menuBar()->insertMenu(fMainWindow->menuBar()->actions().last(),fileMenu); |
---|
481 | #endif |
---|
482 | |
---|
483 | AddInteractor (aName,(G4Interactor)fileMenu); |
---|
484 | } |
---|
485 | |
---|
486 | |
---|
487 | /** |
---|
488 | Add a new button to a menu |
---|
489 | @param aMenu : parent menu |
---|
490 | @param aLabel : label to display |
---|
491 | @param aCommand : command to execute as a callback |
---|
492 | */ |
---|
493 | void G4UIQt::AddButton ( |
---|
494 | const char* aMenu |
---|
495 | ,const char* aLabel |
---|
496 | ,const char* aCommand |
---|
497 | ) |
---|
498 | { |
---|
499 | if(aMenu==NULL) return; // TO KEEP |
---|
500 | if(aLabel==NULL) return; // TO KEEP |
---|
501 | if(aCommand==NULL) return; // TO KEEP |
---|
502 | |
---|
503 | #if QT_VERSION < 0x040000 |
---|
504 | QPopupMenu *parent = (QPopupMenu*)GetInteractor(aMenu); |
---|
505 | #else |
---|
506 | QMenu *parent = (QMenu*)GetInteractor(aMenu); |
---|
507 | #endif |
---|
508 | |
---|
509 | if(parent==NULL) return; |
---|
510 | |
---|
511 | QSignalMapper *signalMapper = new QSignalMapper(this); |
---|
512 | #if QT_VERSION < 0x030200 |
---|
513 | QAction *action = new QAction(QString(aLabel),QString(aLabel),QKeySequence::QKeySequence (),signalMapper, SLOT(map())); |
---|
514 | action->addTo(parent); |
---|
515 | connect(action,SIGNAL(activated()),signalMapper,SLOT(map())); |
---|
516 | |
---|
517 | #elif QT_VERSION < 0x040000 |
---|
518 | QAction *action = new QAction(QString(aLabel),QKeySequence::QKeySequence (),signalMapper, SLOT(map())); |
---|
519 | action->addTo(parent); |
---|
520 | connect(action,SIGNAL(activated()),signalMapper,SLOT(map())); |
---|
521 | |
---|
522 | #else |
---|
523 | QAction *action = parent->addAction(aLabel, signalMapper, SLOT(map())); |
---|
524 | |
---|
525 | #endif |
---|
526 | connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&))); |
---|
527 | signalMapper->setMapping(action, QString(aCommand)); |
---|
528 | } |
---|
529 | |
---|
530 | |
---|
531 | |
---|
532 | |
---|
533 | /** |
---|
534 | Open the help dialog in a separate window.<br> |
---|
535 | This will be display as a tree widget.<br> |
---|
536 | Implementation of <b>void G4VBasicShell::TerminalHelp(G4String newCommand)</b> |
---|
537 | |
---|
538 | @param newCommand : open the tree widget item on this command if is set |
---|
539 | */ |
---|
540 | void G4UIQt::TerminalHelp( |
---|
541 | G4String newCommand |
---|
542 | ) |
---|
543 | { |
---|
544 | // Create the help dialog |
---|
545 | if (!fHelpDialog) { |
---|
546 | #if QT_VERSION < 0x040000 |
---|
547 | fHelpDialog = new QDialog(0,0,FALSE,Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WStyle_MinMax ); |
---|
548 | #else |
---|
549 | fHelpDialog = new QDialog(0,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint); |
---|
550 | #endif |
---|
551 | QVBoxLayout *vLayout = new QVBoxLayout(fHelpDialog); |
---|
552 | QWidget *helpWidget = new QWidget(fHelpDialog); |
---|
553 | QSplitter *splitter = new QSplitter(Qt::Horizontal,fHelpDialog); |
---|
554 | QPushButton *exitButton = new QPushButton("Exit",fHelpDialog); |
---|
555 | exitButton->setAutoDefault(false); |
---|
556 | connect(exitButton, SIGNAL(clicked()), fHelpDialog,SLOT(close())); |
---|
557 | |
---|
558 | QHBoxLayout *helpLayout = new QHBoxLayout(helpWidget); |
---|
559 | #if QT_VERSION < 0x040000 |
---|
560 | helpLayout->add(new QLabel("Search :",helpWidget)); |
---|
561 | #else |
---|
562 | helpLayout->addWidget(new QLabel("Search :",helpWidget)); |
---|
563 | #endif |
---|
564 | helpLine = new QLineEdit(fHelpDialog); |
---|
565 | #if QT_VERSION < 0x040000 |
---|
566 | helpLayout->add(helpLine); |
---|
567 | connect( helpLine, SIGNAL( returnPressed () ), this, SLOT( lookForHelpStringCallback() ) ); |
---|
568 | #else |
---|
569 | helpLayout->addWidget(helpLine); |
---|
570 | connect( helpLine, SIGNAL( editingFinished () ), this, SLOT( lookForHelpStringCallback() ) ); |
---|
571 | #endif |
---|
572 | |
---|
573 | // the help tree |
---|
574 | #if QT_VERSION < 0x040000 |
---|
575 | fHelpTreeWidget = new QListView(splitter); |
---|
576 | #else |
---|
577 | fHelpTreeWidget = new QTreeWidget(); |
---|
578 | #endif |
---|
579 | fHelpTreeWidget = CreateHelpTree(); |
---|
580 | |
---|
581 | fHelpArea = new QTextEdit(splitter); |
---|
582 | fHelpArea->setReadOnly(true); |
---|
583 | |
---|
584 | // Set layouts |
---|
585 | |
---|
586 | #if QT_VERSION >= 0x040000 |
---|
587 | if (fHelpTreeWidget) |
---|
588 | splitter->addWidget(fHelpTreeWidget); |
---|
589 | splitter->addWidget(fHelpArea); |
---|
590 | #endif |
---|
591 | |
---|
592 | |
---|
593 | #if QT_VERSION >= 0x040000 |
---|
594 | vLayout->addWidget(helpWidget); |
---|
595 | vLayout->addWidget(splitter,1); |
---|
596 | vLayout->addWidget(exitButton); |
---|
597 | #else |
---|
598 | vLayout->addWidget(helpWidget); |
---|
599 | vLayout->addWidget(splitter,1); |
---|
600 | vLayout->addWidget(exitButton); |
---|
601 | #endif |
---|
602 | |
---|
603 | // set the splitter size |
---|
604 | #if QT_VERSION >= 0x040000 |
---|
605 | QList<int> list; |
---|
606 | #else |
---|
607 | QValueList<int> list; |
---|
608 | #endif |
---|
609 | list.append( 400 ); |
---|
610 | list.append( 400 ); |
---|
611 | splitter->setSizes(list); |
---|
612 | |
---|
613 | #if QT_VERSION >= 0x040000 |
---|
614 | fHelpDialog->setLayout(vLayout); |
---|
615 | #endif |
---|
616 | |
---|
617 | } |
---|
618 | |
---|
619 | ActivateCommand(newCommand); |
---|
620 | |
---|
621 | #if QT_VERSION < 0x040000 |
---|
622 | fHelpDialog->setCaption( tr( "Help on commands" )); |
---|
623 | #else |
---|
624 | fHelpDialog->setWindowTitle(tr("Help on commands")); |
---|
625 | #endif |
---|
626 | fHelpDialog->resize(800,600); |
---|
627 | fHelpDialog->move(QPoint(400,150)); |
---|
628 | fHelpDialog->show(); |
---|
629 | fHelpDialog->raise(); |
---|
630 | #if QT_VERSION < 0x040000 |
---|
631 | fHelpDialog->setActiveWindow(); |
---|
632 | #else |
---|
633 | fHelpDialog->activateWindow(); |
---|
634 | #endif |
---|
635 | } |
---|
636 | |
---|
637 | |
---|
638 | void G4UIQt::ActivateCommand( |
---|
639 | G4String newCommand |
---|
640 | ) |
---|
641 | { |
---|
642 | if (!fHelpTreeWidget) { |
---|
643 | return; |
---|
644 | } |
---|
645 | // Look for the choosen command "newCommand" |
---|
646 | size_t i = newCommand.index(" "); |
---|
647 | G4String targetCom=""; |
---|
648 | if( i != std::string::npos ) |
---|
649 | { |
---|
650 | G4String newValue = newCommand(i+1,newCommand.length()-(i+1)); |
---|
651 | newValue.strip(G4String::both); |
---|
652 | targetCom = ModifyToFullPathCommand( newValue ); |
---|
653 | } |
---|
654 | if (targetCom != "") { |
---|
655 | #if QT_VERSION < 0x040000 |
---|
656 | QListViewItem* findItem = NULL; |
---|
657 | QListViewItem* tmpItem = fHelpTreeWidget->firstChild(); |
---|
658 | while (tmpItem != 0) { |
---|
659 | if (!findItem) { |
---|
660 | findItem = FindTreeItem(tmpItem,QString((char*)targetCom.data())); |
---|
661 | } |
---|
662 | tmpItem = tmpItem->nextSibling(); |
---|
663 | } |
---|
664 | #else |
---|
665 | QTreeWidgetItem* findItem = NULL; |
---|
666 | for (int a=0;a<fHelpTreeWidget->topLevelItemCount();a++) { |
---|
667 | if (!findItem) { |
---|
668 | findItem = FindTreeItem(fHelpTreeWidget->topLevelItem(a),QString((char*)targetCom.data())); |
---|
669 | } |
---|
670 | } |
---|
671 | #endif |
---|
672 | |
---|
673 | if (findItem) { |
---|
674 | |
---|
675 | //collapsed open item |
---|
676 | #if QT_VERSION < 0x040000 |
---|
677 | |
---|
678 | // FIXME : Has to be checked |
---|
679 | QListViewItem* tmpItem = fHelpTreeWidget->firstChild(); |
---|
680 | QList<QListViewItem> openItems; |
---|
681 | while ((tmpItem != 0) || (!openItems.isEmpty())) { |
---|
682 | if (tmpItem->isOpen() ) { |
---|
683 | tmpItem->setOpen(false); |
---|
684 | openItems.append(tmpItem); |
---|
685 | tmpItem = tmpItem->firstChild(); |
---|
686 | } else { |
---|
687 | tmpItem = tmpItem->nextSibling(); |
---|
688 | } |
---|
689 | if (tmpItem == 0) { |
---|
690 | tmpItem = openItems.take(openItems.count()-1); |
---|
691 | } |
---|
692 | } |
---|
693 | #else |
---|
694 | QList<QTreeWidgetItem *> selected; |
---|
695 | |
---|
696 | selected = fHelpTreeWidget->selectedItems(); |
---|
697 | if ( selected.count() != 0 ) { |
---|
698 | QTreeWidgetItem * tmp =selected.at( 0 ); |
---|
699 | while ( tmp) { |
---|
700 | #if QT_VERSION < 0x040202 |
---|
701 | fHelpTreeWidget->setItemExpanded(tmp,false); |
---|
702 | #else |
---|
703 | tmp->setExpanded(false); |
---|
704 | #endif |
---|
705 | tmp = tmp->parent(); |
---|
706 | } |
---|
707 | } |
---|
708 | #endif |
---|
709 | |
---|
710 | // clear old selection |
---|
711 | fHelpTreeWidget->clearSelection(); |
---|
712 | |
---|
713 | // set new selection |
---|
714 | #if QT_VERSION >= 0x040000 |
---|
715 | #if QT_VERSION < 0x040202 |
---|
716 | fHelpTreeWidget->setItemSelected(findItem,true); |
---|
717 | #else |
---|
718 | findItem->setSelected(true); |
---|
719 | #endif |
---|
720 | #else |
---|
721 | findItem->setSelected(true); |
---|
722 | #endif |
---|
723 | |
---|
724 | // expand parent item |
---|
725 | while ( findItem) { |
---|
726 | #if QT_VERSION < 0x040000 |
---|
727 | findItem->setOpen(true); |
---|
728 | #else |
---|
729 | #if QT_VERSION < 0x040202 |
---|
730 | fHelpTreeWidget->setItemExpanded(findItem,true); |
---|
731 | #else |
---|
732 | findItem->setExpanded(true); |
---|
733 | #endif |
---|
734 | #endif |
---|
735 | findItem = findItem->parent(); |
---|
736 | } |
---|
737 | |
---|
738 | // Call the update of the right textArea |
---|
739 | HelpTreeClicCallback(); |
---|
740 | } |
---|
741 | } |
---|
742 | } |
---|
743 | |
---|
744 | |
---|
745 | |
---|
746 | /** |
---|
747 | Create the help tree widget |
---|
748 | @param parent : parent of tree widget |
---|
749 | @return the widget containing the tree or NULL if it could not have beeen created |
---|
750 | */ |
---|
751 | |
---|
752 | #if QT_VERSION < 0x040000 |
---|
753 | QListView * G4UIQt::CreateHelpTree() |
---|
754 | #else |
---|
755 | QTreeWidget * G4UIQt::CreateHelpTree() |
---|
756 | #endif |
---|
757 | { |
---|
758 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
759 | if(UI==NULL) return NULL; |
---|
760 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
761 | |
---|
762 | |
---|
763 | // build widget |
---|
764 | #if QT_VERSION < 0x040000 |
---|
765 | fHelpTreeWidget->setSelectionMode(QListView::Single); |
---|
766 | fHelpTreeWidget->setRootIsDecorated(true); |
---|
767 | fHelpTreeWidget->addColumn("Command"); |
---|
768 | fHelpTreeWidget->header()->setResizeEnabled(FALSE,1); |
---|
769 | #else |
---|
770 | fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection); |
---|
771 | QStringList labels; |
---|
772 | labels << QString("Command"); |
---|
773 | fHelpTreeWidget->setHeaderLabels(labels); |
---|
774 | #endif |
---|
775 | |
---|
776 | G4int treeSize = treeTop->GetTreeEntry(); |
---|
777 | #if QT_VERSION < 0x040000 |
---|
778 | QListViewItem * newItem; |
---|
779 | #else |
---|
780 | QTreeWidgetItem * newItem; |
---|
781 | #endif |
---|
782 | for (int a=0;a<treeSize;a++) { |
---|
783 | // Creating new item |
---|
784 | |
---|
785 | #if QT_VERSION < 0x040000 |
---|
786 | newItem = new QListViewItem(fHelpTreeWidget); |
---|
787 | newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace()); |
---|
788 | #else |
---|
789 | newItem = new QTreeWidgetItem(fHelpTreeWidget); |
---|
790 | newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed()); |
---|
791 | #endif |
---|
792 | |
---|
793 | |
---|
794 | // look for childs |
---|
795 | CreateChildTree(newItem,treeTop->GetTree(a+1)); |
---|
796 | // items.append(newItem); |
---|
797 | } |
---|
798 | |
---|
799 | |
---|
800 | #if QT_VERSION < 0x040000 |
---|
801 | connect(fHelpTreeWidget, SIGNAL(selectionChanged ()),this, SLOT(HelpTreeClicCallback())); |
---|
802 | connect(fHelpTreeWidget, SIGNAL(doubleClicked (QListViewItem*)),this, SLOT(HelpTreeDoubleClicCallback())); |
---|
803 | #else |
---|
804 | connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback())); |
---|
805 | connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback())); |
---|
806 | #endif |
---|
807 | |
---|
808 | return fHelpTreeWidget; |
---|
809 | } |
---|
810 | |
---|
811 | |
---|
812 | |
---|
813 | /** Fill the Help Tree Widget |
---|
814 | @param aParent : parent item to fill |
---|
815 | @param aCommandTree : commandTree node associate with this part of the Tree |
---|
816 | */ |
---|
817 | #if QT_VERSION < 0x040000 |
---|
818 | void G4UIQt::CreateChildTree( |
---|
819 | QListViewItem *aParent |
---|
820 | ,G4UIcommandTree *aCommandTree |
---|
821 | #else |
---|
822 | void G4UIQt::CreateChildTree( |
---|
823 | QTreeWidgetItem *aParent |
---|
824 | ,G4UIcommandTree *aCommandTree |
---|
825 | #endif |
---|
826 | ) |
---|
827 | { |
---|
828 | if (aParent == NULL) return; |
---|
829 | if (aCommandTree == NULL) return; |
---|
830 | |
---|
831 | |
---|
832 | // Creating new item |
---|
833 | #if QT_VERSION < 0x040000 |
---|
834 | QListViewItem * newItem; |
---|
835 | #else |
---|
836 | QTreeWidgetItem * newItem; |
---|
837 | #endif |
---|
838 | |
---|
839 | // Get the Sub directories |
---|
840 | for (int a=0;a<aCommandTree->GetTreeEntry();a++) { |
---|
841 | |
---|
842 | #if QT_VERSION < 0x040000 |
---|
843 | newItem = new QListViewItem(aParent); |
---|
844 | newItem->setText(0,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace()); |
---|
845 | |
---|
846 | #else |
---|
847 | newItem = new QTreeWidgetItem(aParent); |
---|
848 | newItem->setText(0,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed()); |
---|
849 | #endif |
---|
850 | |
---|
851 | CreateChildTree(newItem,aCommandTree->GetTree(a+1)); |
---|
852 | } |
---|
853 | |
---|
854 | |
---|
855 | |
---|
856 | // Get the Commands |
---|
857 | |
---|
858 | for (int a=0;a<aCommandTree->GetCommandEntry();a++) { |
---|
859 | |
---|
860 | QStringList stringList; |
---|
861 | #if QT_VERSION < 0x040000 |
---|
862 | newItem = new QListViewItem(aParent); |
---|
863 | newItem->setText(0,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).simplifyWhiteSpace()); |
---|
864 | newItem->setOpen(false); |
---|
865 | |
---|
866 | #else |
---|
867 | newItem = new QTreeWidgetItem(aParent); |
---|
868 | newItem->setText(0,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed()); |
---|
869 | #if QT_VERSION < 0x040202 |
---|
870 | fHelpTreeWidget->setItemExpanded(newItem,false); |
---|
871 | #else |
---|
872 | newItem->setExpanded(false); |
---|
873 | #endif |
---|
874 | #endif |
---|
875 | |
---|
876 | } |
---|
877 | } |
---|
878 | |
---|
879 | |
---|
880 | /** Find a treeItemWidget in the help tree |
---|
881 | @param aCommand item's String to look for |
---|
882 | @return item if found, NULL if not |
---|
883 | */ |
---|
884 | #if QT_VERSION < 0x040000 |
---|
885 | QListViewItem* G4UIQt::FindTreeItem( |
---|
886 | QListViewItem *aParent |
---|
887 | #else |
---|
888 | QTreeWidgetItem* G4UIQt::FindTreeItem( |
---|
889 | QTreeWidgetItem *aParent |
---|
890 | #endif |
---|
891 | ,const QString& aCommand |
---|
892 | ) |
---|
893 | { |
---|
894 | if (aParent == NULL) return NULL; |
---|
895 | |
---|
896 | if (aParent->text(0) == aCommand) |
---|
897 | return aParent; |
---|
898 | |
---|
899 | #if QT_VERSION < 0x040000 |
---|
900 | QListViewItem * tmp = NULL; |
---|
901 | QListViewItem* tmpItem = aParent->firstChild(); |
---|
902 | while (tmpItem != 0) { |
---|
903 | if (!tmp) |
---|
904 | tmp = FindTreeItem(tmpItem,aCommand); |
---|
905 | tmpItem = tmpItem->nextSibling(); |
---|
906 | } |
---|
907 | |
---|
908 | #else |
---|
909 | QTreeWidgetItem * tmp = NULL; |
---|
910 | for (int a=0;a<aParent->childCount();a++) { |
---|
911 | if (!tmp) |
---|
912 | tmp = FindTreeItem(aParent->child(a),aCommand); |
---|
913 | } |
---|
914 | #endif |
---|
915 | return tmp; |
---|
916 | } |
---|
917 | |
---|
918 | |
---|
919 | /** Build the command list parameters in a QString<br> |
---|
920 | Reimplement partialy the G4UIparameter.cc |
---|
921 | @param aCommand : command to list parameters |
---|
922 | @see G4UIparameter::List() |
---|
923 | @see G4UIcommand::List() |
---|
924 | @return the command list parameters, or "" if nothing |
---|
925 | */ |
---|
926 | QString G4UIQt::GetCommandList ( |
---|
927 | const G4UIcommand *aCommand |
---|
928 | ) |
---|
929 | { |
---|
930 | |
---|
931 | QString txt =""; |
---|
932 | if (aCommand == NULL) |
---|
933 | return txt; |
---|
934 | |
---|
935 | G4String commandPath = aCommand->GetCommandPath(); |
---|
936 | G4String rangeString = aCommand->GetRange(); |
---|
937 | G4int n_guidanceEntry = aCommand->GetGuidanceEntries(); |
---|
938 | G4int n_parameterEntry = aCommand->GetParameterEntries(); |
---|
939 | |
---|
940 | if ((commandPath == "") && |
---|
941 | (rangeString == "") && |
---|
942 | (n_guidanceEntry == 0) && |
---|
943 | (n_parameterEntry == 0)) { |
---|
944 | return txt; |
---|
945 | } |
---|
946 | |
---|
947 | if((commandPath.length()-1)!='/') { |
---|
948 | txt += "Command " + QString((char*)(commandPath).data()) + "\n"; |
---|
949 | } |
---|
950 | txt += "Guidance :\n"; |
---|
951 | |
---|
952 | for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) { |
---|
953 | txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n"; |
---|
954 | } |
---|
955 | if( ! rangeString.isNull() ) { |
---|
956 | txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n"; |
---|
957 | } |
---|
958 | if( n_parameterEntry > 0 ) { |
---|
959 | G4UIparameter *param; |
---|
960 | |
---|
961 | // Re-implementation of G4UIparameter.cc |
---|
962 | |
---|
963 | for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) { |
---|
964 | param = aCommand->GetParameter(i_thParameter); |
---|
965 | txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n"; |
---|
966 | if( ! param->GetParameterGuidance().isNull() ) |
---|
967 | txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ; |
---|
968 | txt += " Parameter type : " + QString(QChar(param->GetParameterType())) + "\n"; |
---|
969 | if(param->IsOmittable()){ |
---|
970 | txt += " Omittable : True\n"; |
---|
971 | } else { |
---|
972 | txt += " Omittable : False\n"; |
---|
973 | } |
---|
974 | if( param->GetCurrentAsDefault() ) { |
---|
975 | txt += " Default value : taken from the current value\n"; |
---|
976 | } else if( ! param->GetDefaultValue().isNull() ) { |
---|
977 | txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n"; |
---|
978 | } |
---|
979 | if( ! param->GetParameterRange().isNull() ) { |
---|
980 | txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n"; |
---|
981 | } |
---|
982 | if( ! param->GetParameterCandidates().isNull() ) { |
---|
983 | txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n"; |
---|
984 | } |
---|
985 | } |
---|
986 | } |
---|
987 | return txt; |
---|
988 | } |
---|
989 | |
---|
990 | |
---|
991 | |
---|
992 | /** Implement G4VBasicShell vurtual function |
---|
993 | */ |
---|
994 | G4bool G4UIQt::GetHelpChoice( |
---|
995 | G4int& |
---|
996 | ) |
---|
997 | { |
---|
998 | #ifdef G4DEBUG_INTERFACES_BASIC |
---|
999 | printf("G4UIQt::GetHelpChoice SHOULD NEVER GO HERE"); |
---|
1000 | #endif |
---|
1001 | return true; |
---|
1002 | } |
---|
1003 | |
---|
1004 | |
---|
1005 | /** Implement G4VBasicShell vurtual function |
---|
1006 | */ |
---|
1007 | void G4UIQt::ExitHelp( |
---|
1008 | ) |
---|
1009 | { |
---|
1010 | #ifdef G4DEBUG_INTERFACES_BASIC |
---|
1011 | printf("G4UIQt::ExitHelp SHOULD NEVER GO HERE"); |
---|
1012 | #endif |
---|
1013 | } |
---|
1014 | |
---|
1015 | |
---|
1016 | /** Event filter method. Every event from QtApplication goes here.<br/> |
---|
1017 | We apply a filter only for the Up and Down Arrow press when the QLineEdit<br/> |
---|
1018 | is active. If this filter match, Up arrow we give the previous command<br/> |
---|
1019 | and Down arrow will give the next if exist.<br/> |
---|
1020 | @param obj Emitter of the event |
---|
1021 | @param event Kind of event |
---|
1022 | */ |
---|
1023 | bool G4UIQt::eventFilter( // Should stay with a minuscule eventFilter because of Qt |
---|
1024 | QObject *aObj |
---|
1025 | ,QEvent *aEvent |
---|
1026 | ) |
---|
1027 | { |
---|
1028 | if (aObj == NULL) return false; |
---|
1029 | if (aEvent == NULL) return false; |
---|
1030 | |
---|
1031 | if (aObj == fCommandHistoryArea) { |
---|
1032 | if (aEvent->type() == QEvent::KeyPress) { |
---|
1033 | fCommandArea->setFocus(); |
---|
1034 | } |
---|
1035 | } |
---|
1036 | if (aObj == fCommandArea) { |
---|
1037 | if (aEvent->type() == QEvent::KeyPress) { |
---|
1038 | QKeyEvent *e = static_cast<QKeyEvent*>(aEvent); |
---|
1039 | if ((e->key() == (Qt::Key_Down)) || |
---|
1040 | (e->key() == (Qt::Key_PageDown)) || |
---|
1041 | (e->key() == (Qt::Key_Up)) || |
---|
1042 | (e->key() == (Qt::Key_PageUp))) { |
---|
1043 | #if QT_VERSION < 0x040000 |
---|
1044 | // count rows... |
---|
1045 | QListViewItem* tmpItem = fCommandHistoryArea->firstChild(); |
---|
1046 | int selection = -1; |
---|
1047 | int index = 0; |
---|
1048 | while (tmpItem != 0) { |
---|
1049 | if (tmpItem == fCommandHistoryArea->selectedItem()) { |
---|
1050 | selection = index; |
---|
1051 | } |
---|
1052 | index ++; |
---|
1053 | tmpItem = tmpItem->nextSibling(); |
---|
1054 | } |
---|
1055 | if (fCommandHistoryArea->childCount()) { |
---|
1056 | if (selection == -1) { |
---|
1057 | selection = fCommandHistoryArea->childCount()-1; |
---|
1058 | } else { |
---|
1059 | if (e->key() == (Qt::Key_Down)) { |
---|
1060 | if (selection <(fCommandHistoryArea->childCount()-1)) |
---|
1061 | selection++; |
---|
1062 | } else if (e->key() == (Qt::Key_PageDown)) { |
---|
1063 | selection = fCommandHistoryArea->childCount()-1; |
---|
1064 | #else |
---|
1065 | int selection = fCommandHistoryArea->currentRow(); |
---|
1066 | if (fCommandHistoryArea->count()) { |
---|
1067 | if (selection == -1) { |
---|
1068 | selection = fCommandHistoryArea->count()-1; |
---|
1069 | } else { |
---|
1070 | if (e->key() == (Qt::Key_Down)) { |
---|
1071 | if (selection <(fCommandHistoryArea->count()-1)) |
---|
1072 | selection++; |
---|
1073 | } else if (e->key() == (Qt::Key_PageDown)) { |
---|
1074 | selection = fCommandHistoryArea->count()-1; |
---|
1075 | #endif |
---|
1076 | } else if (e->key() == (Qt::Key_Up)) { |
---|
1077 | if (selection >0) |
---|
1078 | selection --; |
---|
1079 | } else if (e->key() == (Qt::Key_PageUp)) { |
---|
1080 | selection = 0; |
---|
1081 | } |
---|
1082 | } |
---|
1083 | fCommandHistoryArea->clearSelection(); |
---|
1084 | #if QT_VERSION < 0x040000 |
---|
1085 | QListViewItem* tmpItem = fCommandHistoryArea->firstChild(); |
---|
1086 | int index = 0; |
---|
1087 | while (tmpItem != 0) { |
---|
1088 | if (index == selection) { |
---|
1089 | tmpItem->setSelected(true); |
---|
1090 | fCommandHistoryArea->setCurrentItem(tmpItem); |
---|
1091 | } |
---|
1092 | index ++; |
---|
1093 | tmpItem = tmpItem->nextSibling(); |
---|
1094 | } |
---|
1095 | #else |
---|
1096 | #if QT_VERSION < 0x040202 |
---|
1097 | fCommandHistoryArea->setItemSelected(fCommandHistoryArea->item(selection),true); |
---|
1098 | #else |
---|
1099 | fCommandHistoryArea->item(selection)->setSelected(true); |
---|
1100 | #endif |
---|
1101 | fCommandHistoryArea->setCurrentItem(fCommandHistoryArea->item(selection)); |
---|
1102 | #endif |
---|
1103 | } |
---|
1104 | } else if (e->key() == (Qt::Key_Tab)) { |
---|
1105 | #if QT_VERSION < 0x040000 |
---|
1106 | G4String ss = Complete(fCommandArea->text().ascii()); |
---|
1107 | #else |
---|
1108 | G4String ss = Complete(fCommandArea->text().toStdString().c_str()); |
---|
1109 | #endif |
---|
1110 | fCommandArea->setText((char*)(ss.data())); |
---|
1111 | |
---|
1112 | // do not pass by parent, it will disable widget tab focus ! |
---|
1113 | return true; |
---|
1114 | } |
---|
1115 | } |
---|
1116 | } |
---|
1117 | // pass the event on to the parent class |
---|
1118 | return QObject::eventFilter(aObj, aEvent); |
---|
1119 | } |
---|
1120 | |
---|
1121 | |
---|
1122 | |
---|
1123 | |
---|
1124 | /***************************************************************************/ |
---|
1125 | // |
---|
1126 | // SLOTS DEFINITIONS |
---|
1127 | // |
---|
1128 | /***************************************************************************/ |
---|
1129 | |
---|
1130 | /** Called when user give "help" command. |
---|
1131 | */ |
---|
1132 | void G4UIQt::ShowHelpCallback ( |
---|
1133 | ) |
---|
1134 | { |
---|
1135 | TerminalHelp(""); |
---|
1136 | } |
---|
1137 | |
---|
1138 | |
---|
1139 | /** Called when user click on clear button. Clear the text Output area |
---|
1140 | */ |
---|
1141 | void G4UIQt::ClearButtonCallback ( |
---|
1142 | ) |
---|
1143 | { |
---|
1144 | fTextArea->clear(); |
---|
1145 | } |
---|
1146 | |
---|
1147 | /** Called when user exit session |
---|
1148 | */ |
---|
1149 | void G4UIQt::ExitSession ( |
---|
1150 | ) |
---|
1151 | { |
---|
1152 | SessionTerminate(); |
---|
1153 | } |
---|
1154 | |
---|
1155 | |
---|
1156 | /** Callback call when "click on a menu entry.<br> |
---|
1157 | Send the associated command to geant4 |
---|
1158 | */ |
---|
1159 | void G4UIQt::CommandEnteredCallback ( |
---|
1160 | ) |
---|
1161 | { |
---|
1162 | #if QT_VERSION < 0x040000 |
---|
1163 | G4String command (fCommandArea->text().ascii()); |
---|
1164 | if (fCommandArea->text().simplifyWhiteSpace() != "") { |
---|
1165 | |
---|
1166 | QListViewItem *newItem = new QListViewItem(fCommandHistoryArea); |
---|
1167 | newItem->setText(0,fCommandArea->text()); |
---|
1168 | fCommandHistoryArea->insertItem(newItem); |
---|
1169 | // now we have to arrange |
---|
1170 | QListViewItem *temp= fCommandHistoryArea->lastItem(); |
---|
1171 | for (int i=0; i<fCommandHistoryArea->childCount()-1;i++) { |
---|
1172 | fCommandHistoryArea->takeItem(temp); |
---|
1173 | fCommandHistoryArea->insertItem(temp); |
---|
1174 | temp= fCommandHistoryArea->lastItem(); |
---|
1175 | } |
---|
1176 | #else |
---|
1177 | G4String command (fCommandArea->text().toStdString().c_str()); |
---|
1178 | if (fCommandArea->text().trimmed() != "") { |
---|
1179 | fCommandHistoryArea->addItem(fCommandArea->text()); |
---|
1180 | #endif |
---|
1181 | fCommandHistoryArea->clearSelection(); |
---|
1182 | fCommandHistoryArea->setCurrentItem(NULL); |
---|
1183 | fCommandArea->setText(""); |
---|
1184 | |
---|
1185 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
1186 | if (interactorManager) { |
---|
1187 | interactorManager->FlushAndWaitExecution(); |
---|
1188 | } |
---|
1189 | if (command(0,4) != "help") { |
---|
1190 | ApplyShellCommand (command,exitSession,exitPause); |
---|
1191 | } else { |
---|
1192 | TerminalHelp(command); |
---|
1193 | } |
---|
1194 | if(exitSession==true) |
---|
1195 | SessionTerminate(); |
---|
1196 | } |
---|
1197 | } |
---|
1198 | |
---|
1199 | |
---|
1200 | /** Callback call when "enter" clicked on the command zone.<br> |
---|
1201 | Send the command to geant4 |
---|
1202 | @param aCommand |
---|
1203 | */ |
---|
1204 | void G4UIQt::ButtonCallback ( |
---|
1205 | const QString& aCommand |
---|
1206 | ) |
---|
1207 | { |
---|
1208 | #if QT_VERSION < 0x040000 |
---|
1209 | G4String ss = G4String(aCommand.ascii()); |
---|
1210 | #else |
---|
1211 | G4String ss = G4String(aCommand.toStdString().c_str()); |
---|
1212 | #endif |
---|
1213 | ApplyShellCommand(ss,exitSession,exitPause); |
---|
1214 | if(exitSession==true) |
---|
1215 | SessionTerminate(); |
---|
1216 | } |
---|
1217 | |
---|
1218 | |
---|
1219 | |
---|
1220 | /** This callback is activated when user selected a item in the help tree |
---|
1221 | */ |
---|
1222 | void G4UIQt::HelpTreeClicCallback ( |
---|
1223 | ) |
---|
1224 | { |
---|
1225 | #if QT_VERSION < 0x040000 |
---|
1226 | QListViewItem* item = NULL; |
---|
1227 | #else |
---|
1228 | QTreeWidgetItem* item = NULL; |
---|
1229 | #endif |
---|
1230 | if (!fHelpTreeWidget) |
---|
1231 | return ; |
---|
1232 | |
---|
1233 | if (!fHelpArea) |
---|
1234 | return; |
---|
1235 | |
---|
1236 | #if QT_VERSION < 0x040000 |
---|
1237 | item =fHelpTreeWidget->selectedItem(); |
---|
1238 | #else |
---|
1239 | QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems(); |
---|
1240 | if (list.isEmpty()) |
---|
1241 | return; |
---|
1242 | item = list.first(); |
---|
1243 | #endif |
---|
1244 | if (!item) |
---|
1245 | return; |
---|
1246 | |
---|
1247 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
1248 | if(UI==NULL) return; |
---|
1249 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
1250 | |
---|
1251 | |
---|
1252 | |
---|
1253 | std::string itemText; |
---|
1254 | #if QT_VERSION < 0x040000 |
---|
1255 | itemText = std::string(item->text(0).ascii()); |
---|
1256 | #else |
---|
1257 | itemText = std::string(item->text(0).toStdString()); |
---|
1258 | #endif |
---|
1259 | |
---|
1260 | G4UIcommand* command = treeTop->FindPath(itemText.c_str()); |
---|
1261 | |
---|
1262 | if (command) { |
---|
1263 | #if QT_VERSION >= 0x040000 |
---|
1264 | #if QT_VERSION < 0x040200 |
---|
1265 | fHelpArea->clear(); |
---|
1266 | fHelpArea->append(GetCommandList(command)); |
---|
1267 | #else |
---|
1268 | fHelpArea->setText(GetCommandList(command)); |
---|
1269 | #endif |
---|
1270 | #else |
---|
1271 | fHelpArea->setText(GetCommandList(command)); |
---|
1272 | #endif |
---|
1273 | } else { // this is a command |
---|
1274 | G4UIcommandTree* path = treeTop->FindCommandTree(itemText.c_str()); |
---|
1275 | if ( path) { |
---|
1276 | // this is not a command, this is a sub directory |
---|
1277 | // We display the Title |
---|
1278 | #if QT_VERSION >= 0x040000 |
---|
1279 | #if QT_VERSION < 0x040200 |
---|
1280 | fHelpArea->clear(); |
---|
1281 | fHelpArea->append(path->GetTitle().data()); |
---|
1282 | #else |
---|
1283 | fHelpArea->setText(path->GetTitle().data()); |
---|
1284 | #endif |
---|
1285 | #else |
---|
1286 | fHelpArea->setText(path->GetTitle().data()); |
---|
1287 | #endif |
---|
1288 | } |
---|
1289 | } |
---|
1290 | } |
---|
1291 | |
---|
1292 | /** This callback is activated when user double clic on a item in the help tree |
---|
1293 | */ |
---|
1294 | void G4UIQt::HelpTreeDoubleClicCallback ( |
---|
1295 | ) |
---|
1296 | { |
---|
1297 | HelpTreeClicCallback(); |
---|
1298 | |
---|
1299 | #if QT_VERSION < 0x040000 |
---|
1300 | QListViewItem* item = NULL; |
---|
1301 | #else |
---|
1302 | QTreeWidgetItem* item = NULL; |
---|
1303 | #endif |
---|
1304 | if (!fHelpTreeWidget) |
---|
1305 | return ; |
---|
1306 | |
---|
1307 | if (!fHelpArea) |
---|
1308 | return; |
---|
1309 | |
---|
1310 | #if QT_VERSION < 0x040000 |
---|
1311 | item =fHelpTreeWidget->selectedItem(); |
---|
1312 | #else |
---|
1313 | QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems(); |
---|
1314 | if (list.isEmpty()) |
---|
1315 | return; |
---|
1316 | item = list.first(); |
---|
1317 | #endif |
---|
1318 | if (!item) |
---|
1319 | return; |
---|
1320 | |
---|
1321 | fCommandArea->clear(); |
---|
1322 | fCommandArea->setText(item->text(0)); |
---|
1323 | } |
---|
1324 | |
---|
1325 | |
---|
1326 | /** Callback called when user select an old command in the command history<br> |
---|
1327 | Give it to the command area. |
---|
1328 | */ |
---|
1329 | void G4UIQt::CommandHistoryCallback( |
---|
1330 | ) |
---|
1331 | { |
---|
1332 | #if QT_VERSION < 0x040000 |
---|
1333 | QListViewItem* item = NULL; |
---|
1334 | #else |
---|
1335 | QListWidgetItem* item = NULL; |
---|
1336 | #endif |
---|
1337 | if (!fCommandHistoryArea) |
---|
1338 | return ; |
---|
1339 | |
---|
1340 | |
---|
1341 | #if QT_VERSION < 0x040000 |
---|
1342 | item =fCommandHistoryArea->selectedItem(); |
---|
1343 | #else |
---|
1344 | QList<QListWidgetItem *> list =fCommandHistoryArea->selectedItems(); |
---|
1345 | if (list.isEmpty()) |
---|
1346 | return; |
---|
1347 | item = list.first(); |
---|
1348 | #endif |
---|
1349 | if (!item) |
---|
1350 | return; |
---|
1351 | #if QT_VERSION < 0x040000 |
---|
1352 | fCommandArea->setText(item->text(0)); |
---|
1353 | #else |
---|
1354 | fCommandArea->setText(item->text()); |
---|
1355 | #endif |
---|
1356 | |
---|
1357 | } |
---|
1358 | |
---|
1359 | |
---|
1360 | /** Callback called when user give a new string to look for<br> |
---|
1361 | Display a list of matching commands descriptions. If no string is set, |
---|
1362 | will display the complete help tree |
---|
1363 | */ |
---|
1364 | void G4UIQt::lookForHelpStringCallback( |
---|
1365 | ) |
---|
1366 | { |
---|
1367 | #if QT_VERSION < 0x040200 |
---|
1368 | fHelpArea->clear(); |
---|
1369 | #else |
---|
1370 | fHelpArea->setText(""); |
---|
1371 | #endif |
---|
1372 | if (helpLine->text() =="") { |
---|
1373 | // clear old help tree |
---|
1374 | fHelpTreeWidget->clear(); |
---|
1375 | #if QT_VERSION < 0x040000 |
---|
1376 | fHelpTreeWidget->removeColumn(1); |
---|
1377 | fHelpTreeWidget->removeColumn(0); |
---|
1378 | #endif |
---|
1379 | CreateHelpTree(); |
---|
1380 | return; |
---|
1381 | } |
---|
1382 | |
---|
1383 | // the help tree |
---|
1384 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
1385 | if(UI==NULL) return; |
---|
1386 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
1387 | |
---|
1388 | G4int treeSize = treeTop->GetTreeEntry(); |
---|
1389 | |
---|
1390 | // clear old help tree |
---|
1391 | fHelpTreeWidget->clear(); |
---|
1392 | #if QT_VERSION < 0x040000 |
---|
1393 | fHelpTreeWidget->removeColumn(1); |
---|
1394 | fHelpTreeWidget->removeColumn(0); |
---|
1395 | #endif |
---|
1396 | |
---|
1397 | // look for new items |
---|
1398 | |
---|
1399 | int tmp = 0; |
---|
1400 | #if QT_VERSION < 0x040000 |
---|
1401 | int multFactor = 1000; // factor special for having double keys in Qt3 |
---|
1402 | int doubleKeyAdd = 0; // decay for doubleKeys in Qt3 |
---|
1403 | #endif |
---|
1404 | |
---|
1405 | QMap<int,QString> commandResultMap; |
---|
1406 | QMap<int,QString> commandChildResultMap; |
---|
1407 | |
---|
1408 | for (int a=0;a<treeSize;a++) { |
---|
1409 | G4UIcommand* command = treeTop->FindPath(treeTop->GetTree(a+1)->GetPathName().data()); |
---|
1410 | #if QT_VERSION > 0x040000 |
---|
1411 | tmp = GetCommandList (command).count(helpLine->text(),Qt::CaseInsensitive); |
---|
1412 | #else |
---|
1413 | tmp = GetCommandList (command).contains(helpLine->text(),false); |
---|
1414 | #endif |
---|
1415 | if (tmp >0) { |
---|
1416 | #if QT_VERSION > 0x040000 |
---|
1417 | commandResultMap.insertMulti(tmp,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data())); |
---|
1418 | #else // tricky thing for Qt3... |
---|
1419 | doubleKeyAdd = 0; |
---|
1420 | while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) { |
---|
1421 | doubleKeyAdd ++; |
---|
1422 | } |
---|
1423 | commandResultMap.insert( tmp*multFactor+doubleKeyAdd,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()) ); |
---|
1424 | #endif |
---|
1425 | } |
---|
1426 | // look for childs |
---|
1427 | commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a+1),helpLine->text()); |
---|
1428 | // insert new childs |
---|
1429 | if (!commandChildResultMap.empty()) { |
---|
1430 | #if QT_VERSION > 0x040000 |
---|
1431 | QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin(); |
---|
1432 | while (i != commandChildResultMap.constEnd()) { |
---|
1433 | commandResultMap.insertMulti(i.key(),i.value()); |
---|
1434 | #else // tricky thing for Qt3... |
---|
1435 | QMap<int,QString>::const_iterator i = commandChildResultMap.begin(); |
---|
1436 | while (i != commandChildResultMap.end()) { |
---|
1437 | doubleKeyAdd = 0; |
---|
1438 | while (commandResultMap.find( i.key()*multFactor+doubleKeyAdd) != commandResultMap.end()) { |
---|
1439 | doubleKeyAdd ++; |
---|
1440 | } |
---|
1441 | commandResultMap.insert(i.key()*multFactor+doubleKeyAdd,i.data()); |
---|
1442 | #endif |
---|
1443 | i++; |
---|
1444 | } |
---|
1445 | commandChildResultMap.clear(); |
---|
1446 | } |
---|
1447 | } |
---|
1448 | |
---|
1449 | // build new help tree |
---|
1450 | #if QT_VERSION < 0x040000 |
---|
1451 | fHelpTreeWidget->setSelectionMode(QListView::Single); |
---|
1452 | fHelpTreeWidget->setRootIsDecorated(true); |
---|
1453 | fHelpTreeWidget->addColumn("Command"); |
---|
1454 | fHelpTreeWidget->addColumn("Match"); |
---|
1455 | // fHelpTreeWidget->header()->setResizeEnabled(FALSE,1); |
---|
1456 | #else |
---|
1457 | fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection); |
---|
1458 | fHelpTreeWidget->setColumnCount(2); |
---|
1459 | QStringList labels; |
---|
1460 | labels << QString("Command") << QString("Match"); |
---|
1461 | fHelpTreeWidget->setHeaderLabels(labels); |
---|
1462 | #endif |
---|
1463 | |
---|
1464 | if (commandResultMap.empty()) { |
---|
1465 | #if QT_VERSION < 0x040200 |
---|
1466 | fHelpArea->clear(); |
---|
1467 | fHelpArea->append("No match found"); |
---|
1468 | #else |
---|
1469 | fHelpArea->setText("No match found"); |
---|
1470 | #endif |
---|
1471 | return; |
---|
1472 | } |
---|
1473 | |
---|
1474 | #if QT_VERSION > 0x040000 |
---|
1475 | QMap<int,QString>::const_iterator i = commandResultMap.constEnd(); |
---|
1476 | #else |
---|
1477 | QMap<int,QString>::const_iterator i = commandResultMap.end(); |
---|
1478 | #endif |
---|
1479 | i--; |
---|
1480 | // 10 maximum progress values |
---|
1481 | float multValue = 10.0/(float)(i.key()); |
---|
1482 | QString progressChar = "|"; |
---|
1483 | QString progressStr = "|"; |
---|
1484 | |
---|
1485 | #if QT_VERSION < 0x040000 |
---|
1486 | QListViewItem * newItem; |
---|
1487 | #else |
---|
1488 | QTreeWidgetItem * newItem; |
---|
1489 | #endif |
---|
1490 | bool end = false; |
---|
1491 | while (!end) { |
---|
1492 | #if QT_VERSION > 0x040000 |
---|
1493 | if (i == commandResultMap.constBegin()) { |
---|
1494 | #else |
---|
1495 | if (i == commandResultMap.begin()) { |
---|
1496 | #endif |
---|
1497 | end = true; |
---|
1498 | } |
---|
1499 | for(int a=0;a<int(i.key()*multValue);a++) { |
---|
1500 | progressStr += progressChar; |
---|
1501 | } |
---|
1502 | #if QT_VERSION < 0x040000 |
---|
1503 | newItem = new QListViewItem(fHelpTreeWidget); |
---|
1504 | newItem->setText(0,i.data().simplifyWhiteSpace()); |
---|
1505 | #else |
---|
1506 | newItem = new QTreeWidgetItem(fHelpTreeWidget); |
---|
1507 | newItem->setText(0,i.value().trimmed()); |
---|
1508 | #endif |
---|
1509 | newItem->setText(1,progressStr); |
---|
1510 | |
---|
1511 | #if QT_VERSION >= 0x040200 |
---|
1512 | newItem->setForeground ( 1, QBrush(Qt::blue) ); |
---|
1513 | #endif |
---|
1514 | progressStr = "|"; |
---|
1515 | i--; |
---|
1516 | } |
---|
1517 | // FIXME : to be checked on Qt3 |
---|
1518 | #if QT_VERSION < 0x040000 |
---|
1519 | fHelpTreeWidget->setColumnWidthMode (1,QListView::Maximum); |
---|
1520 | fHelpTreeWidget->setSorting(1,false); |
---|
1521 | #else |
---|
1522 | fHelpTreeWidget->resizeColumnToContents (0); |
---|
1523 | fHelpTreeWidget->sortItems(1,Qt::DescendingOrder); |
---|
1524 | // fHelpTreeWidget->setColumnWidth(1,10);//resizeColumnToContents (1); |
---|
1525 | #endif |
---|
1526 | } |
---|
1527 | |
---|
1528 | |
---|
1529 | |
---|
1530 | |
---|
1531 | QMap<int,QString> G4UIQt::LookForHelpStringInChildTree( |
---|
1532 | G4UIcommandTree *aCommandTree |
---|
1533 | ,const QString & text |
---|
1534 | ) |
---|
1535 | { |
---|
1536 | QMap<int,QString> commandResultMap; |
---|
1537 | if (aCommandTree == NULL) return commandResultMap; |
---|
1538 | |
---|
1539 | #if QT_VERSION < 0x040000 |
---|
1540 | int multFactor = 1000; // factor special for having double keys in Qt3 |
---|
1541 | int doubleKeyAdd = 0; // decay for doubleKeys in Qt3 |
---|
1542 | #endif |
---|
1543 | |
---|
1544 | // Get the Sub directories |
---|
1545 | int tmp = 0; |
---|
1546 | QMap<int,QString> commandChildResultMap; |
---|
1547 | |
---|
1548 | for (int a=0;a<aCommandTree->GetTreeEntry();a++) { |
---|
1549 | const G4UIcommand* command = aCommandTree->GetGuidance(); |
---|
1550 | #if QT_VERSION > 0x040000 |
---|
1551 | tmp = GetCommandList (command).count(text,Qt::CaseInsensitive); |
---|
1552 | #else |
---|
1553 | tmp = GetCommandList (command).contains(text,false); |
---|
1554 | #endif |
---|
1555 | if (tmp >0) { |
---|
1556 | #if QT_VERSION > 0x040000 |
---|
1557 | commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data())); |
---|
1558 | #else // tricky thing for Qt3... |
---|
1559 | doubleKeyAdd = 0; |
---|
1560 | while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) { |
---|
1561 | doubleKeyAdd ++; |
---|
1562 | } |
---|
1563 | commandResultMap.insert(tmp*multFactor+doubleKeyAdd,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data())); |
---|
1564 | #endif |
---|
1565 | } |
---|
1566 | // look for childs |
---|
1567 | commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text); |
---|
1568 | |
---|
1569 | if (!commandChildResultMap.empty()) { |
---|
1570 | // insert new childs |
---|
1571 | #if QT_VERSION > 0x040000 |
---|
1572 | QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin(); |
---|
1573 | while (i != commandChildResultMap.constEnd()) { |
---|
1574 | commandResultMap.insertMulti(i.key(),i.value()); |
---|
1575 | #else // tricky thing for Qt3... |
---|
1576 | QMap<int,QString>::const_iterator i = commandChildResultMap.begin(); |
---|
1577 | while (i != commandChildResultMap.end()) { |
---|
1578 | doubleKeyAdd = 0; |
---|
1579 | while (commandResultMap.find( i.key()*multFactor+doubleKeyAdd) != commandResultMap.end()) { |
---|
1580 | doubleKeyAdd ++; |
---|
1581 | } |
---|
1582 | commandResultMap.insert(i.key()*multFactor+doubleKeyAdd,i.data()); |
---|
1583 | #endif |
---|
1584 | i++; |
---|
1585 | } |
---|
1586 | commandChildResultMap.clear(); |
---|
1587 | } |
---|
1588 | } |
---|
1589 | // Get the Commands |
---|
1590 | |
---|
1591 | for (int a=0;a<aCommandTree->GetCommandEntry();a++) { |
---|
1592 | const G4UIcommand* command = aCommandTree->GetCommand(a+1); |
---|
1593 | #if QT_VERSION > 0x040000 |
---|
1594 | tmp = GetCommandList (command).count(text,Qt::CaseInsensitive); |
---|
1595 | #else |
---|
1596 | tmp = GetCommandList (command).contains(text,false); |
---|
1597 | #endif |
---|
1598 | if (tmp >0) { |
---|
1599 | #if QT_VERSION > 0x040000 |
---|
1600 | commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data())); |
---|
1601 | #else // tricky thing for Qt3... |
---|
1602 | doubleKeyAdd = 0; |
---|
1603 | while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) { |
---|
1604 | doubleKeyAdd ++; |
---|
1605 | } |
---|
1606 | commandResultMap.insert(tmp*multFactor+doubleKeyAdd,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data())); |
---|
1607 | #endif |
---|
1608 | } |
---|
1609 | |
---|
1610 | } |
---|
1611 | return commandResultMap; |
---|
1612 | } |
---|
1613 | #endif |
---|