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