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