1 | // TODO ! |
---|
2 | |
---|
3 | // |
---|
4 | // ******************************************************************** |
---|
5 | // * License and Disclaimer * |
---|
6 | // * * |
---|
7 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
8 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
9 | // * conditions of the Geant4 Software License, included in the file * |
---|
10 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
11 | // * include a list of copyright holders. * |
---|
12 | // * * |
---|
13 | // * Neither the authors of this software system, nor their employing * |
---|
14 | // * institutes,nor the agencies providing financial support for this * |
---|
15 | // * work make any representation or warranty, express or implied, * |
---|
16 | // * regarding this software system or assume any liability for its * |
---|
17 | // * use. Please see the license in the file LICENSE and URL above * |
---|
18 | // * for the full disclaimer and the limitation of liability. * |
---|
19 | // * * |
---|
20 | // * This code implementation is the result of the scientific and * |
---|
21 | // * technical work of the GEANT4 collaboration. * |
---|
22 | // * By using, copying, modifying or distributing the software (or * |
---|
23 | // * any work based on the software) you agree to acknowledge its * |
---|
24 | // * use in resulting scientific publications, and indicate your * |
---|
25 | // * acceptance of all terms of the Geant4 Software license. * |
---|
26 | // ******************************************************************** |
---|
27 | // |
---|
28 | // |
---|
29 | // $Id: G4UIQt.cc,v 1.14 2007/05/29 11:09:49 $ |
---|
30 | // GEANT4 tag $Name: geant4-08-01 $ |
---|
31 | // |
---|
32 | // L. Garnier |
---|
33 | |
---|
34 | //#define DEBUG |
---|
35 | |
---|
36 | #ifdef G4UI_BUILD_QT_SESSION |
---|
37 | |
---|
38 | #include "G4Types.hh" |
---|
39 | |
---|
40 | #include <string.h> |
---|
41 | |
---|
42 | #include "G4UIQt.hh" |
---|
43 | #include "G4UImanager.hh" |
---|
44 | #include "G4StateManager.hh" |
---|
45 | #include "G4UIcommandTree.hh" |
---|
46 | #include "G4UIcommandStatus.hh" |
---|
47 | |
---|
48 | #include "G4Qt.hh" |
---|
49 | |
---|
50 | #include <QtGui/qapplication.h> |
---|
51 | #include <QtGui/qwidget.h> |
---|
52 | #include <QtGui/qmenu.h> |
---|
53 | #include <QtGui/qmenubar.h> |
---|
54 | #include <QtGui/qboxlayout.h> |
---|
55 | #include <QtGui/qpushbutton.h> |
---|
56 | #include <QtGui/qlabel.h> |
---|
57 | #include <QtGui/qsplitter.h> |
---|
58 | #include <QtGui/qscrollbar.h> |
---|
59 | #include <QtGui/qdialog.h> |
---|
60 | #include <QtGui/qevent.h> |
---|
61 | |
---|
62 | #include <stdlib.h> |
---|
63 | |
---|
64 | // Pourquoi Static et non variables de classe ? |
---|
65 | static G4bool exitSession = true; |
---|
66 | static G4bool exitPause = true; |
---|
67 | /***************************************************************************/ |
---|
68 | /** |
---|
69 | Build a Qt window with a menubar, output area and promt area |
---|
70 | +-----------------------+ |
---|
71 | |exit menu| | |
---|
72 | | | |
---|
73 | | +-------------------+ | |
---|
74 | | | | | |
---|
75 | | | Output area | | |
---|
76 | | | | | |
---|
77 | | +-------------------+ | |
---|
78 | | | clear | | |
---|
79 | | +-------------------+ | |
---|
80 | | | promt history | | |
---|
81 | | +-------------------+ | |
---|
82 | | +-------------------+ | |
---|
83 | | |> promt area | | |
---|
84 | | +-------------------+ | |
---|
85 | +-----------------------+ |
---|
86 | */ |
---|
87 | |
---|
88 | G4UIQt::G4UIQt ( |
---|
89 | int argc, |
---|
90 | char** argv |
---|
91 | ) |
---|
92 | :fHelpDialog(NULL) |
---|
93 | |
---|
94 | /***************************************************************************/ |
---|
95 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
96 | { |
---|
97 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
98 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
99 | if(UI!=NULL) UI->SetSession(this); |
---|
100 | |
---|
101 | fMainWindow = new QMainWindow(); |
---|
102 | fMainWindow->setWindowTitle( "G4UI Session" ); |
---|
103 | fMainWindow->resize(800,600); |
---|
104 | fMainWindow->move(QPoint(300,100)); |
---|
105 | |
---|
106 | QSplitter *splitter = new QSplitter(Qt::Vertical); |
---|
107 | fTextArea = new QTextEdit(); |
---|
108 | QPushButton *clearButton = new QPushButton("clear"); |
---|
109 | connect(clearButton, SIGNAL(clicked()), SLOT(clearButtonCallback())); |
---|
110 | |
---|
111 | fCommandHistoryArea = new QTextEdit(); |
---|
112 | fCommandLabel = new QLabel(); |
---|
113 | |
---|
114 | // fCommandArea = new G4UIQtLineEdit(this); // must surcharge the keyPressEvent function |
---|
115 | fCommandArea = new QLineEdit(); |
---|
116 | fCommandArea->installEventFilter(this); |
---|
117 | fCommandArea->activateWindow(); |
---|
118 | connect(fCommandArea, SIGNAL(returnPressed()), SLOT(commandEnteredCallback())); |
---|
119 | fCommandArea->setFocusPolicy ( Qt::StrongFocus ); |
---|
120 | fCommandArea->setFocus(Qt::TabFocusReason); |
---|
121 | fTextArea->setReadOnly(true); |
---|
122 | fCommandHistoryArea->setReadOnly(true); |
---|
123 | |
---|
124 | // virtual void keyPressEvent(QKeyEvent *e) { |
---|
125 | // if (e->key == Qt::Key_F9) { |
---|
126 | // Do something |
---|
127 | //} |
---|
128 | //} |
---|
129 | |
---|
130 | // Set layouts |
---|
131 | QVBoxLayout *layoutSplitter = new QVBoxLayout; |
---|
132 | |
---|
133 | QWidget* topWidget = new QWidget(); |
---|
134 | QVBoxLayout *layoutTop = new QVBoxLayout; |
---|
135 | |
---|
136 | QWidget* bottomWidget = new QWidget(); |
---|
137 | QVBoxLayout *layoutBottom = new QVBoxLayout; |
---|
138 | |
---|
139 | |
---|
140 | layoutTop->addWidget(fTextArea); |
---|
141 | layoutTop->addWidget(clearButton); |
---|
142 | topWidget->setLayout(layoutTop); |
---|
143 | |
---|
144 | layoutBottom->addWidget(fCommandHistoryArea); |
---|
145 | layoutBottom->addWidget(fCommandLabel); |
---|
146 | layoutBottom->addWidget(fCommandArea); |
---|
147 | bottomWidget->setLayout(layoutBottom); |
---|
148 | |
---|
149 | |
---|
150 | layoutSplitter->addWidget(topWidget); |
---|
151 | layoutSplitter->addWidget(bottomWidget); |
---|
152 | splitter->setLayout(layoutSplitter); |
---|
153 | |
---|
154 | fMainWindow->setCentralWidget(splitter); |
---|
155 | |
---|
156 | // Add a quit subMenu |
---|
157 | QMenu *fileMenu = fMainWindow->menuBar()->addMenu("File"); |
---|
158 | fileMenu->addAction("Quitter", fMainWindow, SLOT(close())); |
---|
159 | |
---|
160 | // Add a Help menu |
---|
161 | QMenu *helpMenu = fMainWindow->menuBar()->addMenu("Help"); |
---|
162 | helpMenu->addAction("Show Help", this, SLOT(showHelpCallback())); |
---|
163 | |
---|
164 | // Set the splitter size. The fTextArea sould be 2/3 on the fMainWindow |
---|
165 | QList<int> vals = splitter->sizes(); |
---|
166 | if(vals.size()==2) { |
---|
167 | vals[0] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*3/4; |
---|
168 | vals[1] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*1/4; |
---|
169 | splitter->setSizes(vals); |
---|
170 | } |
---|
171 | |
---|
172 | |
---|
173 | if(UI!=NULL) UI->SetCoutDestination(this); // TO KEEP |
---|
174 | } |
---|
175 | /***************************************************************************/ |
---|
176 | G4UIQt::~G4UIQt( |
---|
177 | ) |
---|
178 | /***************************************************************************/ |
---|
179 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
180 | { |
---|
181 | G4UImanager* UI = G4UImanager::GetUIpointer(); // TO KEEP |
---|
182 | if(UI!=NULL) { // TO KEEP |
---|
183 | UI->SetSession(NULL); // TO KEEP |
---|
184 | UI->SetCoutDestination(NULL); // TO KEEP |
---|
185 | } |
---|
186 | |
---|
187 | |
---|
188 | if (fMainWindow!=NULL) |
---|
189 | delete fMainWindow; |
---|
190 | } |
---|
191 | /***************************************************************************/ |
---|
192 | /* |
---|
193 | Start the Qt main loop |
---|
194 | */ |
---|
195 | G4UIsession* G4UIQt::SessionStart ( |
---|
196 | ) |
---|
197 | /***************************************************************************/ |
---|
198 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
199 | { |
---|
200 | |
---|
201 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
202 | fMainWindow->show(); |
---|
203 | Prompt("session"); |
---|
204 | exitSession = false; |
---|
205 | |
---|
206 | |
---|
207 | printf("disable secondary loop\n"); |
---|
208 | interactorManager->DisableSecondaryLoop (); // TO KEEP |
---|
209 | ((QApplication*)interactorManager->GetMainInteractor())->exec(); |
---|
210 | // on ne passe pas le dessous ? FIXME ???? |
---|
211 | // je ne pense pas 13/06 |
---|
212 | |
---|
213 | // void* event; // TO KEEP |
---|
214 | // while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
215 | // interactorManager->DispatchEvent(event); // TO KEEP |
---|
216 | // if(exitSession==true) break; // TO KEEP |
---|
217 | // } // TO KEEP |
---|
218 | |
---|
219 | interactorManager->EnableSecondaryLoop (); |
---|
220 | printf("enable secondary loop\n"); |
---|
221 | return this; |
---|
222 | } |
---|
223 | /***************************************************************************/ |
---|
224 | |
---|
225 | /** |
---|
226 | Display the prompt in the prompt area |
---|
227 | */ |
---|
228 | void G4UIQt::Prompt ( |
---|
229 | G4String aPrompt |
---|
230 | ) |
---|
231 | /***************************************************************************/ |
---|
232 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
233 | { |
---|
234 | fCommandLabel->setText((char*)aPrompt.data()); |
---|
235 | } |
---|
236 | /***************************************************************************/ |
---|
237 | void G4UIQt::SessionTerminate ( |
---|
238 | ) |
---|
239 | /***************************************************************************/ |
---|
240 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
241 | { |
---|
242 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
243 | fMainWindow->close(); |
---|
244 | ((QApplication*)interactorManager->GetMainInteractor())->exit(); |
---|
245 | } |
---|
246 | /***************************************************************************/ |
---|
247 | void G4UIQt::PauseSessionStart ( |
---|
248 | G4String a_state |
---|
249 | ) |
---|
250 | /***************************************************************************/ |
---|
251 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
252 | { |
---|
253 | printf("G4UIQt::PauseSessionStart\n"); |
---|
254 | if(a_state=="G4_pause> ") { // TO KEEP |
---|
255 | SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP |
---|
256 | } // TO KEEP |
---|
257 | |
---|
258 | if(a_state=="EndOfEvent") { // TO KEEP |
---|
259 | // Picking with feed back in event data Done here !!! |
---|
260 | SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP |
---|
261 | } // TO KEEP |
---|
262 | } |
---|
263 | /***************************************************************************/ |
---|
264 | void G4UIQt::SecondaryLoop ( |
---|
265 | G4String a_prompt |
---|
266 | ) |
---|
267 | /***************************************************************************/ |
---|
268 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
269 | { |
---|
270 | printf("G4UIQt::SecondaryLoop\n"); |
---|
271 | G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ? |
---|
272 | Prompt(a_prompt); // TO KEEP |
---|
273 | exitPause = false; // TO KEEP |
---|
274 | void* event; // TO KEEP |
---|
275 | while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
276 | interactorManager->DispatchEvent(event); // TO KEEP |
---|
277 | if(exitPause==true) break; // TO KEEP |
---|
278 | } // TO KEEP |
---|
279 | Prompt("session"); // TO KEEP |
---|
280 | } |
---|
281 | /***************************************************************************/ |
---|
282 | /** |
---|
283 | Receive a cout from Geant4. We have to display it in the cout zone |
---|
284 | */ |
---|
285 | G4int G4UIQt::ReceiveG4cout ( |
---|
286 | G4String a_string |
---|
287 | ) |
---|
288 | /***************************************************************************/ |
---|
289 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
290 | { |
---|
291 | fTextArea->append(QString((char*)a_string.data()).trimmed()); |
---|
292 | fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum()); |
---|
293 | return 0; |
---|
294 | } |
---|
295 | /***************************************************************************/ |
---|
296 | /** |
---|
297 | Receive a cerr from Geant4. We have to display it in the cout zone |
---|
298 | */ |
---|
299 | G4int G4UIQt::ReceiveG4cerr ( |
---|
300 | G4String a_string |
---|
301 | ) |
---|
302 | /***************************************************************************/ |
---|
303 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
304 | { |
---|
305 | QColor previousColor = fTextArea->textColor(); |
---|
306 | fTextArea->setTextColor(Qt::red); |
---|
307 | fTextArea->append(QString((char*)a_string.data()).trimmed()); |
---|
308 | fTextArea->setTextColor(previousColor); |
---|
309 | fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum()); |
---|
310 | return 0; |
---|
311 | } |
---|
312 | |
---|
313 | /***************************************************************************/ |
---|
314 | void G4UIQt::AddMenu ( |
---|
315 | const char* a_name |
---|
316 | ,const char* a_label |
---|
317 | ) |
---|
318 | /***************************************************************************/ |
---|
319 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
320 | { |
---|
321 | printf("G4UIQt::AddMenu %s %s\n",a_name,a_label); |
---|
322 | |
---|
323 | // QMenu *fileMenu = fMainWindow->menuBar()->addMenu(a_label); |
---|
324 | QMenu *fileMenu = new QMenu(a_label); |
---|
325 | fMainWindow->menuBar()->insertMenu(fMainWindow->menuBar()->actions().last(),fileMenu); |
---|
326 | AddInteractor (a_name,(G4Interactor)fileMenu); |
---|
327 | } |
---|
328 | /***************************************************************************/ |
---|
329 | void G4UIQt::AddButton ( |
---|
330 | const char* a_menu |
---|
331 | ,const char* a_label |
---|
332 | ,const char* a_command |
---|
333 | ) |
---|
334 | /***************************************************************************/ |
---|
335 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
336 | { |
---|
337 | if(a_menu==NULL) return; // TO KEEP |
---|
338 | if(a_label==NULL) return; // TO KEEP |
---|
339 | if(a_command==NULL) return; // TO KEEP |
---|
340 | QMenu *parent = (QMenu*)GetInteractor(a_menu); |
---|
341 | if(parent==NULL) return; |
---|
342 | |
---|
343 | signalMapper = new QSignalMapper(this); |
---|
344 | QAction *action = parent->addAction(a_label, signalMapper, SLOT(map())); |
---|
345 | signalMapper->setMapping(action, QString(a_command)); |
---|
346 | connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(buttonCallback(const QString&))); |
---|
347 | } |
---|
348 | |
---|
349 | |
---|
350 | |
---|
351 | |
---|
352 | /** |
---|
353 | Open the help dialog in a separate window. |
---|
354 | This will be display as a tree widget |
---|
355 | Implementation of <b>void G4VBasicShell::TerminalHelp(G4String newCommand)</b> |
---|
356 | |
---|
357 | @param newCommand : open the tree widget item on this command if is set |
---|
358 | */ |
---|
359 | void G4UIQt::TerminalHelp(G4String newCommand) |
---|
360 | { |
---|
361 | |
---|
362 | |
---|
363 | if (!fHelpDialog) { |
---|
364 | fHelpDialog = new QDialog; |
---|
365 | |
---|
366 | QSplitter *splitter = new QSplitter(Qt::Horizontal); |
---|
367 | fHelpArea = new QTextEdit(); |
---|
368 | QPushButton *exitButton = new QPushButton("Exit"); |
---|
369 | connect(exitButton, SIGNAL(clicked()), fHelpDialog,SLOT(close())); |
---|
370 | fHelpArea->setReadOnly(true); |
---|
371 | |
---|
372 | // the help tree |
---|
373 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
374 | if(UI==NULL) return; |
---|
375 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
376 | |
---|
377 | |
---|
378 | // en test : creation de doc html |
---|
379 | |
---|
380 | |
---|
381 | treeTop->CreateHTML(); |
---|
382 | printf("************ create file : -%s-**********\n",((char*)treeTop->GetPathName().data())); |
---|
383 | |
---|
384 | |
---|
385 | |
---|
386 | |
---|
387 | |
---|
388 | |
---|
389 | |
---|
390 | // |
---|
391 | // build widget |
---|
392 | fHelpTreeWidget = new QTreeWidget(); |
---|
393 | fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection); |
---|
394 | fHelpTreeWidget->setColumnCount(2); |
---|
395 | fHelpTreeWidget->setColumnHidden(1,true); |
---|
396 | QStringList labels; |
---|
397 | labels << QString("Command") << QString("Description"); |
---|
398 | fHelpTreeWidget->setHeaderLabels(labels); |
---|
399 | |
---|
400 | QList<QTreeWidgetItem *> items; |
---|
401 | G4int treeSize = treeTop->GetTreeEntry(); |
---|
402 | QTreeWidgetItem * newItem; |
---|
403 | for (int a=0;a<treeSize;a++) { |
---|
404 | // Creating new item |
---|
405 | QStringList stringList; |
---|
406 | stringList << QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed() ; |
---|
407 | stringList << QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).trimmed() ; |
---|
408 | |
---|
409 | newItem = new QTreeWidgetItem(stringList); |
---|
410 | |
---|
411 | // look for childs |
---|
412 | CreateChildTree(newItem,treeTop->GetTree(a+1)); |
---|
413 | items.append(newItem); |
---|
414 | } |
---|
415 | fHelpTreeWidget->insertTopLevelItems(0, items); |
---|
416 | |
---|
417 | //connecting callback |
---|
418 | // QSignalMapper signalMapper = new QSignalMapper(this); |
---|
419 | |
---|
420 | connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(helpTreeCallback())); |
---|
421 | |
---|
422 | // Set layouts |
---|
423 | QHBoxLayout *splitterLayout = new QHBoxLayout; |
---|
424 | |
---|
425 | QVBoxLayout *vLayout = new QVBoxLayout; |
---|
426 | |
---|
427 | splitterLayout->addWidget(fHelpTreeWidget); |
---|
428 | splitterLayout->addWidget(fHelpArea); |
---|
429 | splitter->setLayout(splitterLayout); |
---|
430 | |
---|
431 | vLayout->addWidget(splitter); |
---|
432 | vLayout->addWidget(exitButton); |
---|
433 | fHelpDialog->setLayout(vLayout); |
---|
434 | |
---|
435 | } |
---|
436 | |
---|
437 | // Look for the choosen command "newCommand" |
---|
438 | size_t i = newCommand.index(" "); |
---|
439 | G4String targetCom=""; |
---|
440 | if( i != std::string::npos ) |
---|
441 | { |
---|
442 | G4String newValue = newCommand(i+1,newCommand.length()-(i+1)); |
---|
443 | newValue.strip(G4String::both); |
---|
444 | targetCom = ModifyToFullPathCommand( newValue ); |
---|
445 | printf("test : av:%s-- ap:%s--\n",((char*)newValue.data()),((char*)targetCom.data())); |
---|
446 | } |
---|
447 | if (targetCom != "") { |
---|
448 | QList<QTreeWidgetItem *> list = fHelpTreeWidget->findItems(QString(((char*)targetCom.data())),Qt::MatchFixedString,0); |
---|
449 | for (int a=0;a<13;a++) { |
---|
450 | printf("verif.... =%s= +%s+\n",fHelpTreeWidget->topLevelItem(a)->text(0).toStdString().c_str(),((char*)targetCom.data())); |
---|
451 | } |
---|
452 | |
---|
453 | if (!list.isEmpty()) { |
---|
454 | if (list.first()->childCount() >0) |
---|
455 | list.first()->setExpanded(true); |
---|
456 | |
---|
457 | //collapsed open item |
---|
458 | QList<QTreeWidgetItem *> selected; |
---|
459 | selected = fHelpTreeWidget->selectedItems(); |
---|
460 | if ( selected.count() != 0 ) { |
---|
461 | fHelpTreeWidget->collapseItem (selected.at( 0 ) ); |
---|
462 | } |
---|
463 | |
---|
464 | // clear old selection |
---|
465 | fHelpTreeWidget->clearSelection(); |
---|
466 | list.first()->setSelected(true); |
---|
467 | |
---|
468 | // Call the update of the right textArea |
---|
469 | helpTreeCallback(); |
---|
470 | } |
---|
471 | } |
---|
472 | fHelpDialog->setWindowTitle("Help on commands"); |
---|
473 | fHelpDialog->resize(800,600); |
---|
474 | fHelpDialog->move(QPoint(400,150)); |
---|
475 | fHelpDialog->show(); |
---|
476 | fHelpDialog->raise(); |
---|
477 | fHelpDialog->activateWindow(); |
---|
478 | } |
---|
479 | |
---|
480 | |
---|
481 | |
---|
482 | void G4UIQt::CreateChildTree(QTreeWidgetItem *a_parent,G4UIcommandTree *a_commandTree) { |
---|
483 | |
---|
484 | // Creating new item |
---|
485 | QTreeWidgetItem * newItem; |
---|
486 | |
---|
487 | |
---|
488 | // Get the Sub directories |
---|
489 | for (int a=0;a<a_commandTree->GetTreeEntry();a++) { |
---|
490 | |
---|
491 | QStringList stringList; |
---|
492 | stringList << QString((char*)(a_commandTree->GetTree(a+1)->GetPathName()).data()).trimmed() ; |
---|
493 | stringList << QString((char*)(a_commandTree->GetTree(a+1)->GetTitle()).data()).trimmed() ; |
---|
494 | newItem = new QTreeWidgetItem(stringList); |
---|
495 | |
---|
496 | CreateChildTree(newItem,a_commandTree->GetTree(a+1)); |
---|
497 | a_parent->addChild(newItem); |
---|
498 | } |
---|
499 | |
---|
500 | |
---|
501 | |
---|
502 | // Get the Commands |
---|
503 | |
---|
504 | for (int a=0;a<a_commandTree->GetCommandEntry();a++) { |
---|
505 | |
---|
506 | QStringList stringList; |
---|
507 | stringList << QString((char*)(a_commandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed() ; |
---|
508 | stringList << QString((char*)(a_commandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed() ; |
---|
509 | newItem = new QTreeWidgetItem(stringList); |
---|
510 | |
---|
511 | a_parent->addChild(newItem); |
---|
512 | newItem->setExpanded(false); |
---|
513 | } |
---|
514 | } |
---|
515 | |
---|
516 | |
---|
517 | /** |
---|
518 | This fonction return the command list parameters in a QString |
---|
519 | |
---|
520 | */ |
---|
521 | /***************************************************************************/ |
---|
522 | QString G4UIQt::GetCommandList ( |
---|
523 | G4UIcommand *a_command |
---|
524 | ) |
---|
525 | /***************************************************************************/ |
---|
526 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
527 | { |
---|
528 | |
---|
529 | QString txt; |
---|
530 | G4String commandPath = a_command->GetCommandPath(); |
---|
531 | G4String rangeString = a_command->GetRange(); |
---|
532 | |
---|
533 | if((commandPath.length()-1)!='/') |
---|
534 | { |
---|
535 | txt += "Command " + QString((char*)(commandPath).data()) + "\n"; |
---|
536 | } |
---|
537 | txt += "Guidance :\n"; |
---|
538 | G4int n_guidanceEntry = a_command->GetGuidanceEntries(); |
---|
539 | |
---|
540 | for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) |
---|
541 | { txt += QString((char*)(a_command->GetGuidanceLine(i_thGuidance)).data()) + "\n"; } |
---|
542 | if( ! rangeString.isNull() ) |
---|
543 | { txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n"; } |
---|
544 | G4int n_parameterEntry = a_command->GetParameterEntries(); |
---|
545 | if( n_parameterEntry > 0 ) |
---|
546 | { |
---|
547 | G4UIparameter *param; |
---|
548 | |
---|
549 | // Re-implementation of G4UIparameter.cc |
---|
550 | |
---|
551 | for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) |
---|
552 | { param = a_command->GetParameter(i_thParameter); |
---|
553 | txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n"; |
---|
554 | if( ! param->GetParameterGuidance().isNull() ) |
---|
555 | txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ; |
---|
556 | txt += " Parameter type : " + QString(param->GetParameterType())+ "\n"; |
---|
557 | if(param->IsOmittable()) |
---|
558 | { txt += " Omittable : True\n"; } |
---|
559 | else |
---|
560 | { txt += " Omittable : False\n"; } |
---|
561 | if( param->GetCurrentAsDefault() ) |
---|
562 | { txt += " Default value : taken from the current value\n"; } |
---|
563 | else if( ! param->GetDefaultValue().isNull() ) |
---|
564 | { txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n"; } |
---|
565 | if( ! param->GetParameterRange().isNull() ) |
---|
566 | txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n"; |
---|
567 | if( ! param->GetParameterCandidates().isNull() ) |
---|
568 | txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n"; |
---|
569 | } |
---|
570 | } |
---|
571 | return txt; |
---|
572 | } |
---|
573 | |
---|
574 | |
---|
575 | |
---|
576 | /***************************************************************************/ |
---|
577 | void G4UIQt::expandHelpItem ( |
---|
578 | QTreeWidgetItem *a_parent |
---|
579 | ,G4UIcommand* a_expandCommand |
---|
580 | ) |
---|
581 | /***************************************************************************/ |
---|
582 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
583 | { |
---|
584 | } |
---|
585 | |
---|
586 | /***************************************************************************/ |
---|
587 | G4bool G4UIQt::GetHelpChoice( |
---|
588 | G4int& aInt |
---|
589 | ) |
---|
590 | /***************************************************************************/ |
---|
591 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
592 | { |
---|
593 | printf("G4UIQt::GetHelpChoice SHOULD NEVER GO HERE"); |
---|
594 | } |
---|
595 | /***************************************************************************/ |
---|
596 | void G4UIQt::ExitHelp( |
---|
597 | ) |
---|
598 | /***************************************************************************/ |
---|
599 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
600 | { |
---|
601 | printf("G4UIQt::ExitHelp SHOULD NEVER GO HERE"); |
---|
602 | } |
---|
603 | |
---|
604 | |
---|
605 | /** |
---|
606 | Event filter method. Every event from QtApplication goes here. |
---|
607 | We apply a filter only for the Up and Down Arrow press when the QLineEdit |
---|
608 | is active. If this filter match, Up arrow we give the previous command |
---|
609 | and Down arrow will give the next if exist. |
---|
610 | @param obj Emitter of the event |
---|
611 | @param event Kind of event |
---|
612 | */ |
---|
613 | /***************************************************************************/ |
---|
614 | bool G4UIQt::eventFilter( |
---|
615 | QObject *obj |
---|
616 | ,QEvent *event |
---|
617 | ) |
---|
618 | /***************************************************************************/ |
---|
619 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
620 | { |
---|
621 | if (obj == fCommandArea) { |
---|
622 | if (event->type() == QEvent::KeyPress) { |
---|
623 | QKeyEvent *e = static_cast<QKeyEvent*>(event); |
---|
624 | if (e->key() == (Qt::Key_Down)) { |
---|
625 | printf("****************KEY PRESSED DOWN*****\n"); |
---|
626 | } else if (e->key() == (Qt::Key_PageDown)) { |
---|
627 | printf("****************KEY PRESSED PAGE DOWN*****\n"); |
---|
628 | } else if (e->key() == (Qt::Key_Up)) { |
---|
629 | printf("****************KEY PRESSED UP*****\n"); |
---|
630 | } else if (e->key() == (Qt::Key_PageUp)) { |
---|
631 | printf("****************KEY PRESSED PAGE UP*****\n"); |
---|
632 | // } else { |
---|
633 | // return QObject::eventFilter(obj, event); |
---|
634 | } |
---|
635 | // } else { |
---|
636 | // return QObject::eventFilter(obj, event); |
---|
637 | } |
---|
638 | // } else { |
---|
639 | } |
---|
640 | // pass the event on to the parent class |
---|
641 | return QObject::eventFilter(obj, event); |
---|
642 | // return true; |
---|
643 | } |
---|
644 | |
---|
645 | |
---|
646 | |
---|
647 | |
---|
648 | /***************************************************************************/ |
---|
649 | // |
---|
650 | // SLOTS DEFINITIONS |
---|
651 | // |
---|
652 | /***************************************************************************/ |
---|
653 | |
---|
654 | /***************************************************************************/ |
---|
655 | void G4UIQt::showHelpCallback ( |
---|
656 | ) |
---|
657 | /***************************************************************************/ |
---|
658 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
659 | { |
---|
660 | TerminalHelp(""); |
---|
661 | } |
---|
662 | |
---|
663 | /***************************************************************************/ |
---|
664 | void G4UIQt::clearButtonCallback ( |
---|
665 | ) |
---|
666 | /***************************************************************************/ |
---|
667 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
668 | { |
---|
669 | fTextArea->clear(); |
---|
670 | } |
---|
671 | |
---|
672 | |
---|
673 | /** |
---|
674 | Callback call when "click on a menu entry. |
---|
675 | Send the associated command to geant4 |
---|
676 | */ |
---|
677 | void G4UIQt::commandEnteredCallback ( |
---|
678 | ) |
---|
679 | /***************************************************************************/ |
---|
680 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
681 | { |
---|
682 | printf ("debug : callback\n"); |
---|
683 | G4String command (fCommandArea->text().toStdString().c_str()); |
---|
684 | if (fCommandArea->text().toStdString().c_str() != "") { |
---|
685 | fCommandHistoryArea->append(fCommandArea->text()); |
---|
686 | |
---|
687 | if (command(0,4) != "help") { |
---|
688 | ApplyShellCommand (command,exitSession,exitPause); |
---|
689 | } else { |
---|
690 | printf ("terminal help\n"); |
---|
691 | TerminalHelp(command); |
---|
692 | } |
---|
693 | if(exitSession==true) |
---|
694 | SessionTerminate(); |
---|
695 | } |
---|
696 | fCommandArea->setText(""); |
---|
697 | } |
---|
698 | |
---|
699 | /** |
---|
700 | Callback call when "enter" clicked on the command zone. |
---|
701 | Send the command to geant4 |
---|
702 | */ |
---|
703 | void G4UIQt::buttonCallback ( |
---|
704 | const QString& a_command |
---|
705 | ) |
---|
706 | /***************************************************************************/ |
---|
707 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
708 | { |
---|
709 | G4String ss = G4String(a_command.toStdString().c_str()); |
---|
710 | printf ("debug : execute:\n-%s- %d %d \n",ss.data(),exitSession,exitPause); |
---|
711 | ApplyShellCommand(ss,exitSession,exitPause); |
---|
712 | if(exitSession==true) |
---|
713 | SessionTerminate(); |
---|
714 | } |
---|
715 | /** |
---|
716 | This callback is activated when user selected a item in the help tree |
---|
717 | */ |
---|
718 | void G4UIQt::helpTreeCallback ( |
---|
719 | ) |
---|
720 | /***************************************************************************/ |
---|
721 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
722 | { |
---|
723 | // G4bool GetHelpChoice(G4int&); |
---|
724 | QTreeWidgetItem* item = NULL; |
---|
725 | if (!fHelpTreeWidget) |
---|
726 | return ; |
---|
727 | |
---|
728 | if (!fHelpArea) |
---|
729 | return; |
---|
730 | |
---|
731 | QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems(); |
---|
732 | if (list.isEmpty()) |
---|
733 | return; |
---|
734 | item = list.first(); |
---|
735 | if (!item) |
---|
736 | return; |
---|
737 | |
---|
738 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
739 | if(UI==NULL) return; |
---|
740 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
741 | G4UIcommand* command = treeTop->FindPath(item->text (1).toStdString().c_str()); |
---|
742 | if (command) { |
---|
743 | fHelpArea->setText(GetCommandList(command)); |
---|
744 | } else { |
---|
745 | // this is not a command, this is a sub directory |
---|
746 | // We display the Title |
---|
747 | fHelpArea->setText(item->text (1).toStdString().c_str()); |
---|
748 | } |
---|
749 | } |
---|
750 | |
---|
751 | |
---|
752 | #endif |
---|