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