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