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