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