[607] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | // |
---|
[704] | 27 | // $Id: G4UIQt.cc,v 1.15 2008/01/30 11:16:17 lgarnier Exp $ |
---|
[719] | 28 | // GEANT4 tag $Name: HEAD $ |
---|
[607] | 29 | // |
---|
| 30 | // L. Garnier |
---|
| 31 | |
---|
[719] | 32 | #define GEANT4_QT_DEBUG |
---|
[607] | 33 | |
---|
| 34 | #ifdef G4UI_BUILD_QT_SESSION |
---|
| 35 | |
---|
| 36 | #include "G4Types.hh" |
---|
| 37 | |
---|
| 38 | #include <string.h> |
---|
| 39 | |
---|
| 40 | #include "G4UIQt.hh" |
---|
| 41 | #include "G4UImanager.hh" |
---|
| 42 | #include "G4StateManager.hh" |
---|
| 43 | #include "G4UIcommandTree.hh" |
---|
| 44 | #include "G4UIcommandStatus.hh" |
---|
| 45 | |
---|
| 46 | #include "G4Qt.hh" |
---|
| 47 | |
---|
| 48 | #include <qapplication.h> |
---|
| 49 | #include <qlineedit.h> |
---|
| 50 | #include <qwidget.h> |
---|
| 51 | #include <qmenubar.h> |
---|
| 52 | #include <qlayout.h> |
---|
| 53 | #include <qpushbutton.h> |
---|
| 54 | #include <qlabel.h> |
---|
| 55 | #include <qsplitter.h> |
---|
| 56 | #include <qscrollbar.h> |
---|
| 57 | #include <qdialog.h> |
---|
| 58 | #include <qevent.h> |
---|
| 59 | #include <qtextedit.h> |
---|
| 60 | #include <qsignalmapper.h> |
---|
| 61 | |
---|
[608] | 62 | #include <qmainwindow.h> |
---|
[607] | 63 | #if QT_VERSION >= 0x040000 |
---|
| 64 | #include <qmenu.h> |
---|
| 65 | #include <qlistwidget.h> |
---|
| 66 | #include <qtreewidget.h> |
---|
| 67 | #else |
---|
| 68 | #include <qaction.h> |
---|
| 69 | #include <qheader.h> |
---|
| 70 | #include <qlistview.h> |
---|
| 71 | #include <qpopupmenu.h> |
---|
| 72 | #endif |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | #include <stdlib.h> |
---|
| 77 | |
---|
| 78 | // Pourquoi Static et non variables de classe ? |
---|
| 79 | static G4bool exitSession = true; |
---|
| 80 | static G4bool exitPause = true; |
---|
| 81 | |
---|
| 82 | /** Build a Qt window with a menubar, output area and promt area<br> |
---|
| 83 | <pre> |
---|
| 84 | +-----------------------+ |
---|
| 85 | |exit menu| | |
---|
| 86 | | | |
---|
| 87 | | +-------------------+ | |
---|
| 88 | | | | | |
---|
| 89 | | | Output area | | |
---|
| 90 | | | | | |
---|
| 91 | | +-------------------+ | |
---|
| 92 | | | clear | | |
---|
| 93 | | +-------------------+ | |
---|
| 94 | | | promt history | | |
---|
| 95 | | +-------------------+ | |
---|
| 96 | | +-------------------+ | |
---|
| 97 | | |> promt area | | |
---|
| 98 | | +-------------------+ | |
---|
| 99 | +-----------------------+ |
---|
| 100 | </pre> |
---|
| 101 | */ |
---|
| 102 | G4UIQt::G4UIQt ( |
---|
| 103 | int argc |
---|
| 104 | ,char** argv |
---|
| 105 | ) |
---|
| 106 | :fHelpDialog(NULL) |
---|
| 107 | { |
---|
[608] | 108 | #ifdef GEANT4_QT_DEBUG |
---|
[607] | 109 | printf("G4UIQt::Initialise %d %s\n",argc,argv[0]); |
---|
[608] | 110 | #endif |
---|
[607] | 111 | G4Qt* interactorManager = G4Qt::getInstance (argc,argv,(char*)"Qt"); |
---|
| 112 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
| 113 | if(UI!=NULL) UI->SetSession(this); |
---|
| 114 | |
---|
| 115 | fMainWindow = new QMainWindow(); |
---|
| 116 | |
---|
[608] | 117 | #ifdef GEANT4_QT_DEBUG |
---|
[607] | 118 | printf("G4UIQt::Initialise after main window creation\n"); |
---|
[608] | 119 | #endif |
---|
[607] | 120 | #if QT_VERSION < 0x040000 |
---|
| 121 | fMainWindow->setCaption( tr( "G4UI Session" )); |
---|
[697] | 122 | fMainWindow->resize(900,600); |
---|
[607] | 123 | fMainWindow->move(50,100); |
---|
| 124 | #else |
---|
| 125 | fMainWindow->setWindowTitle( tr("G4UI Session") ); |
---|
[697] | 126 | fMainWindow->resize(900,600); |
---|
[607] | 127 | fMainWindow->move(QPoint(50,100)); |
---|
| 128 | #endif |
---|
| 129 | |
---|
[617] | 130 | QSplitter *splitter = new QSplitter(Qt::Vertical,fMainWindow); |
---|
[611] | 131 | |
---|
[610] | 132 | // Set layouts |
---|
| 133 | |
---|
| 134 | QWidget* topWidget = new QWidget(splitter); |
---|
| 135 | QWidget* bottomWidget = new QWidget(splitter); |
---|
| 136 | |
---|
| 137 | QVBoxLayout *layoutTop = new QVBoxLayout(topWidget); |
---|
| 138 | QVBoxLayout *layoutBottom = new QVBoxLayout(bottomWidget); |
---|
| 139 | |
---|
| 140 | // fill them |
---|
| 141 | |
---|
| 142 | fTextArea = new QTextEdit(topWidget); |
---|
| 143 | QPushButton *clearButton = new QPushButton("clear",topWidget); |
---|
[607] | 144 | connect(clearButton, SIGNAL(clicked()), SLOT(ClearButtonCallback())); |
---|
| 145 | |
---|
| 146 | #if QT_VERSION < 0x040000 |
---|
[635] | 147 | |
---|
[610] | 148 | fCommandHistoryArea = new QListView(bottomWidget); |
---|
[620] | 149 | fCommandHistoryArea->setSorting (-1, FALSE); |
---|
[607] | 150 | fCommandHistoryArea->setSelectionMode(QListView::Single); |
---|
[620] | 151 | fCommandHistoryArea->addColumn(""); |
---|
| 152 | fCommandHistoryArea->header()->hide(); |
---|
[608] | 153 | connect(fCommandHistoryArea, SIGNAL(selectionChanged()), SLOT(CommandHistoryCallback())); |
---|
[607] | 154 | #else |
---|
| 155 | fCommandHistoryArea = new QListWidget(); |
---|
| 156 | fCommandHistoryArea->setSelectionMode(QAbstractItemView::SingleSelection); |
---|
[608] | 157 | connect(fCommandHistoryArea, SIGNAL(itemSelectionChanged()), SLOT(CommandHistoryCallback())); |
---|
[607] | 158 | #endif |
---|
| 159 | fCommandHistoryArea->installEventFilter(this); |
---|
[610] | 160 | fCommandLabel = new QLabel("",bottomWidget); |
---|
[607] | 161 | |
---|
[610] | 162 | fCommandArea = new QLineEdit(bottomWidget); |
---|
[607] | 163 | fCommandArea->installEventFilter(this); |
---|
| 164 | #if QT_VERSION < 0x040000 |
---|
| 165 | fCommandArea->setActiveWindow(); |
---|
| 166 | #else |
---|
| 167 | fCommandArea->activateWindow(); |
---|
| 168 | #endif |
---|
| 169 | connect(fCommandArea, SIGNAL(returnPressed()), SLOT(CommandEnteredCallback())); |
---|
| 170 | #if QT_VERSION < 0x040000 |
---|
| 171 | fCommandArea->setFocusPolicy ( QWidget::StrongFocus ); |
---|
| 172 | fCommandArea->setFocus(); |
---|
| 173 | #else |
---|
| 174 | fCommandArea->setFocusPolicy ( Qt::StrongFocus ); |
---|
| 175 | fCommandArea->setFocus(Qt::TabFocusReason); |
---|
| 176 | #endif |
---|
| 177 | fTextArea->setReadOnly(true); |
---|
| 178 | |
---|
| 179 | |
---|
[610] | 180 | #ifdef GEANT4_QT_DEBUG |
---|
| 181 | printf("G4UIQt:: 2\n"); |
---|
| 182 | #endif |
---|
[607] | 183 | |
---|
| 184 | |
---|
| 185 | |
---|
| 186 | layoutTop->addWidget(fTextArea); |
---|
| 187 | layoutTop->addWidget(clearButton); |
---|
| 188 | |
---|
| 189 | #if QT_VERSION >= 0x040000 |
---|
| 190 | topWidget->setLayout(layoutTop); |
---|
| 191 | #endif |
---|
| 192 | |
---|
| 193 | layoutBottom->addWidget(fCommandHistoryArea); |
---|
| 194 | layoutBottom->addWidget(fCommandLabel); |
---|
| 195 | layoutBottom->addWidget(fCommandArea); |
---|
| 196 | #if QT_VERSION >= 0x040000 |
---|
| 197 | |
---|
| 198 | bottomWidget->setLayout(layoutBottom); |
---|
| 199 | splitter->addWidget(topWidget); |
---|
| 200 | splitter->addWidget(bottomWidget); |
---|
| 201 | #endif |
---|
| 202 | |
---|
| 203 | |
---|
| 204 | fMainWindow->setCentralWidget(splitter); |
---|
| 205 | |
---|
| 206 | #if QT_VERSION < 0x040000 |
---|
| 207 | |
---|
| 208 | // Add a quit subMenu |
---|
| 209 | QPopupMenu *fileMenu = new QPopupMenu( fMainWindow); |
---|
[608] | 210 | fileMenu->insertItem( "&Quitter", this, SLOT(ExitSession()), CTRL+Key_Q ); |
---|
[607] | 211 | fMainWindow->menuBar()->insertItem( QString("&File"), fileMenu ); |
---|
| 212 | |
---|
| 213 | // Add a Help menu |
---|
| 214 | QPopupMenu *helpMenu = new QPopupMenu( fMainWindow ); |
---|
| 215 | helpMenu->insertItem( "&Show Help", this, SLOT(ShowHelpCallback()), CTRL+Key_H ); |
---|
| 216 | fMainWindow->menuBar()->insertItem( QString("&Help"), helpMenu ); |
---|
| 217 | |
---|
| 218 | |
---|
| 219 | #else |
---|
| 220 | |
---|
| 221 | // Add a quit subMenu |
---|
| 222 | QMenu *fileMenu = fMainWindow->menuBar()->addMenu("File"); |
---|
[608] | 223 | fileMenu->addAction("Quitter", this, SLOT(ExitSession())); |
---|
[607] | 224 | |
---|
| 225 | // Add a Help menu |
---|
| 226 | QMenu *helpMenu = fMainWindow->menuBar()->addMenu("Help"); |
---|
| 227 | helpMenu->addAction("Show Help", this, SLOT(ShowHelpCallback())); |
---|
| 228 | #endif |
---|
| 229 | |
---|
| 230 | // Set the splitter size. The fTextArea sould be 2/3 on the fMainWindow |
---|
| 231 | #if QT_VERSION < 0x040000 |
---|
| 232 | QValueList<int> vals = splitter->sizes(); |
---|
| 233 | #else |
---|
| 234 | QList<int> vals = splitter->sizes(); |
---|
| 235 | #endif |
---|
| 236 | if(vals.size()==2) { |
---|
| 237 | vals[0] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*3/4; |
---|
| 238 | vals[1] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*1/4; |
---|
| 239 | splitter->setSizes(vals); |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | if(UI!=NULL) UI->SetCoutDestination(this); // TO KEEP |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | |
---|
| 246 | |
---|
| 247 | G4UIQt::~G4UIQt( |
---|
| 248 | ) |
---|
| 249 | { |
---|
| 250 | G4UImanager* UI = G4UImanager::GetUIpointer(); // TO KEEP |
---|
| 251 | if(UI!=NULL) { // TO KEEP |
---|
| 252 | UI->SetSession(NULL); // TO KEEP |
---|
| 253 | UI->SetCoutDestination(NULL); // TO KEEP |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | if (fMainWindow!=NULL) |
---|
| 257 | delete fMainWindow; |
---|
| 258 | } |
---|
| 259 | |
---|
| 260 | |
---|
| 261 | |
---|
| 262 | /** Start the Qt main loop |
---|
| 263 | */ |
---|
| 264 | G4UIsession* G4UIQt::SessionStart ( |
---|
| 265 | ) |
---|
| 266 | { |
---|
| 267 | |
---|
| 268 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
| 269 | |
---|
| 270 | #if QT_VERSION >= 0x040000 |
---|
[608] | 271 | #if QT_VERSION >= 0x040200 |
---|
[607] | 272 | fMainWindow->setVisible(true); |
---|
| 273 | #else |
---|
| 274 | fMainWindow->show(); |
---|
| 275 | #endif |
---|
[608] | 276 | #else |
---|
| 277 | fMainWindow->show(); |
---|
| 278 | #endif |
---|
[607] | 279 | Prompt("session"); |
---|
| 280 | exitSession = false; |
---|
| 281 | |
---|
| 282 | |
---|
[608] | 283 | #ifdef GEANT4_QT_DEBUG |
---|
[607] | 284 | printf("disable secondary loop\n"); |
---|
[608] | 285 | #endif |
---|
[607] | 286 | interactorManager->DisableSecondaryLoop (); // TO KEEP |
---|
[610] | 287 | if ((QApplication*)interactorManager->GetMainInteractor()) |
---|
| 288 | ((QApplication*)interactorManager->GetMainInteractor())->exec(); |
---|
| 289 | |
---|
[607] | 290 | // on ne passe pas le dessous ? FIXME ???? |
---|
| 291 | // je ne pense pas 13/06 |
---|
| 292 | |
---|
| 293 | // void* event; // TO KEEP |
---|
| 294 | // while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
| 295 | // interactorManager->DispatchEvent(event); // TO KEEP |
---|
| 296 | // if(exitSession==true) break; // TO KEEP |
---|
| 297 | // } // TO KEEP |
---|
| 298 | |
---|
| 299 | interactorManager->EnableSecondaryLoop (); |
---|
[608] | 300 | #ifdef GEANT4_QT_DEBUG |
---|
[607] | 301 | printf("enable secondary loop\n"); |
---|
[608] | 302 | #endif |
---|
[607] | 303 | return this; |
---|
| 304 | } |
---|
| 305 | |
---|
| 306 | |
---|
| 307 | /** Display the prompt in the prompt area |
---|
| 308 | @param aPrompt : string to display as the promt label |
---|
| 309 | //FIXME : probablement inutile puisque le seul a afficher qq chose d'autre |
---|
| 310 | que "session" est SecondaryLoop() |
---|
| 311 | */ |
---|
| 312 | void G4UIQt::Prompt ( |
---|
| 313 | G4String aPrompt |
---|
| 314 | ) |
---|
| 315 | { |
---|
| 316 | if (!aPrompt) return; |
---|
| 317 | |
---|
| 318 | fCommandLabel->setText((char*)aPrompt.data()); |
---|
| 319 | } |
---|
| 320 | |
---|
| 321 | |
---|
| 322 | void G4UIQt::SessionTerminate ( |
---|
| 323 | ) |
---|
| 324 | { |
---|
| 325 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
| 326 | fMainWindow->close(); |
---|
| 327 | ((QApplication*)interactorManager->GetMainInteractor())->exit(); |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | |
---|
| 331 | |
---|
| 332 | /** |
---|
| 333 | Called by intercoms/src/G4UImanager.cc<br> |
---|
| 334 | Called by visualization/management/src/G4VisCommands.cc with "EndOfEvent" argument<br> |
---|
| 335 | It have to pause the session command terminal.<br> |
---|
| 336 | Call SecondaryLoop to wait for exit event<br> |
---|
| 337 | @param aState |
---|
| 338 | @see : G4VisCommandReviewKeptEvents::SetNewValue |
---|
| 339 | */ |
---|
| 340 | void G4UIQt::PauseSessionStart ( |
---|
| 341 | G4String aState |
---|
| 342 | ) |
---|
| 343 | { |
---|
| 344 | if (!aState) return; |
---|
| 345 | |
---|
[608] | 346 | #ifdef GEANT4_QT_DEBUG |
---|
[607] | 347 | printf("G4UIQt::PauseSessionStart\n"); |
---|
[608] | 348 | #endif |
---|
[607] | 349 | if(aState=="G4_pause> ") { // TO KEEP |
---|
| 350 | SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP |
---|
| 351 | } // TO KEEP |
---|
| 352 | |
---|
| 353 | if(aState=="EndOfEvent") { // TO KEEP |
---|
| 354 | // Picking with feed back in event data Done here !!! |
---|
| 355 | SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP |
---|
| 356 | } // TO KEEP |
---|
| 357 | } |
---|
| 358 | |
---|
| 359 | |
---|
| 360 | |
---|
| 361 | /** |
---|
| 362 | Begin the secondary loop |
---|
| 363 | @param a_prompt : label to display as the prompt label |
---|
| 364 | */ |
---|
| 365 | void G4UIQt::SecondaryLoop ( |
---|
| 366 | G4String aPrompt |
---|
| 367 | ) |
---|
| 368 | { |
---|
| 369 | if (!aPrompt) return; |
---|
| 370 | |
---|
[608] | 371 | #ifdef GEANT4_QT_DEBUG |
---|
[607] | 372 | printf("G4UIQt::SecondaryLoop\n"); |
---|
[608] | 373 | #endif |
---|
[607] | 374 | G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ? |
---|
| 375 | Prompt(aPrompt); // TO KEEP |
---|
| 376 | exitPause = false; // TO KEEP |
---|
| 377 | void* event; // TO KEEP |
---|
| 378 | while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
| 379 | interactorManager->DispatchEvent(event); // TO KEEP |
---|
| 380 | if(exitPause==true) break; // TO KEEP |
---|
| 381 | } // TO KEEP |
---|
| 382 | Prompt("session"); // TO KEEP |
---|
| 383 | } |
---|
| 384 | |
---|
| 385 | |
---|
| 386 | |
---|
| 387 | /** |
---|
| 388 | Receive a cout from Geant4. We have to display it in the cout zone |
---|
| 389 | @param aString : label to add in the display area |
---|
| 390 | @return 0 |
---|
| 391 | */ |
---|
| 392 | G4int G4UIQt::ReceiveG4cout ( |
---|
| 393 | G4String aString |
---|
| 394 | ) |
---|
| 395 | { |
---|
| 396 | if (!aString) return 0; |
---|
| 397 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
| 398 | if (!interactorManager) return 0; |
---|
| 399 | |
---|
| 400 | #if QT_VERSION < 0x040000 |
---|
| 401 | fTextArea->append(QString((char*)aString.data()).simplifyWhiteSpace()); |
---|
| 402 | fTextArea->verticalScrollBar()->setValue(fTextArea->verticalScrollBar()->maxValue()); |
---|
| 403 | #else |
---|
| 404 | fTextArea->append(QString((char*)aString.data()).trimmed()); |
---|
| 405 | fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum()); |
---|
| 406 | #endif |
---|
| 407 | interactorManager->FlushAndWaitExecution(); |
---|
| 408 | return 0; |
---|
| 409 | } |
---|
| 410 | |
---|
| 411 | |
---|
| 412 | /** |
---|
| 413 | Receive a cerr from Geant4. We have to display it in the cout zone |
---|
| 414 | @param aString : label to add in the display area |
---|
| 415 | @return 0 |
---|
| 416 | */ |
---|
| 417 | G4int G4UIQt::ReceiveG4cerr ( |
---|
| 418 | G4String aString |
---|
| 419 | ) |
---|
| 420 | { |
---|
| 421 | if (!aString) return 0; |
---|
| 422 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
| 423 | if (!interactorManager) return 0; |
---|
| 424 | |
---|
| 425 | #if QT_VERSION < 0x040000 |
---|
| 426 | QColor previousColor = fTextArea->color(); |
---|
| 427 | fTextArea->setColor(Qt::red); |
---|
| 428 | fTextArea->append(QString((char*)aString.data()).simplifyWhiteSpace()); |
---|
| 429 | fTextArea->setColor(previousColor); |
---|
| 430 | fTextArea->verticalScrollBar()->setValue(fTextArea->verticalScrollBar()->maxValue()); |
---|
| 431 | #else |
---|
| 432 | QColor previousColor = fTextArea->textColor(); |
---|
| 433 | fTextArea->setTextColor(Qt::red); |
---|
| 434 | fTextArea->append(QString((char*)aString.data()).trimmed()); |
---|
| 435 | fTextArea->setTextColor(previousColor); |
---|
| 436 | fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum()); |
---|
| 437 | #endif |
---|
| 438 | interactorManager->FlushAndWaitExecution(); |
---|
| 439 | return 0; |
---|
| 440 | } |
---|
| 441 | |
---|
| 442 | |
---|
| 443 | |
---|
| 444 | /** |
---|
| 445 | Add a new menu to the menu bar |
---|
| 446 | @param aName name of menu |
---|
| 447 | @param aLabel label to display |
---|
| 448 | */ |
---|
| 449 | void G4UIQt::AddMenu ( |
---|
| 450 | const char* aName |
---|
| 451 | ,const char* aLabel |
---|
| 452 | ) |
---|
| 453 | { |
---|
| 454 | if (aName == NULL) return; |
---|
| 455 | if (aLabel == NULL) return; |
---|
| 456 | |
---|
| 457 | #if QT_VERSION < 0x040000 |
---|
| 458 | QPopupMenu *fileMenu = new QPopupMenu( fMainWindow); |
---|
| 459 | fMainWindow->menuBar()->insertItem( aLabel, fileMenu ); |
---|
| 460 | #else |
---|
| 461 | QMenu *fileMenu = new QMenu(aLabel); |
---|
| 462 | fMainWindow->menuBar()->insertMenu(fMainWindow->menuBar()->actions().last(),fileMenu); |
---|
| 463 | #endif |
---|
| 464 | |
---|
| 465 | AddInteractor (aName,(G4Interactor)fileMenu); |
---|
| 466 | } |
---|
| 467 | |
---|
| 468 | |
---|
| 469 | /** |
---|
| 470 | Add a new button to a menu |
---|
| 471 | @param aMenu : parent menu |
---|
| 472 | @param aLabel : label to display |
---|
| 473 | @param aCommand : command to execute as a callback |
---|
| 474 | */ |
---|
| 475 | void G4UIQt::AddButton ( |
---|
| 476 | const char* aMenu |
---|
| 477 | ,const char* aLabel |
---|
| 478 | ,const char* aCommand |
---|
| 479 | ) |
---|
| 480 | { |
---|
| 481 | if(aMenu==NULL) return; // TO KEEP |
---|
| 482 | if(aLabel==NULL) return; // TO KEEP |
---|
| 483 | if(aCommand==NULL) return; // TO KEEP |
---|
| 484 | |
---|
| 485 | #if QT_VERSION < 0x040000 |
---|
| 486 | QPopupMenu *parent = (QPopupMenu*)GetInteractor(aMenu); |
---|
| 487 | #else |
---|
| 488 | QMenu *parent = (QMenu*)GetInteractor(aMenu); |
---|
| 489 | #endif |
---|
| 490 | |
---|
| 491 | if(parent==NULL) return; |
---|
| 492 | |
---|
| 493 | QSignalMapper *signalMapper = new QSignalMapper(this); |
---|
[617] | 494 | #if QT_VERSION < 0x030200 |
---|
| 495 | QAction *action = new QAction(QString(aLabel),QString(aLabel),QKeySequence::QKeySequence (),signalMapper, SLOT(map())); |
---|
[620] | 496 | action->addTo(parent); |
---|
| 497 | connect(action,SIGNAL(activated()),signalMapper,SLOT(map())); |
---|
| 498 | |
---|
| 499 | #elif QT_VERSION < 0x040000 |
---|
[607] | 500 | QAction *action = new QAction(QString(aLabel),QKeySequence::QKeySequence (),signalMapper, SLOT(map())); |
---|
| 501 | action->addTo(parent); |
---|
[624] | 502 | connect(action,SIGNAL(activated()),signalMapper,SLOT(map())); |
---|
[620] | 503 | |
---|
[607] | 504 | #else |
---|
| 505 | QAction *action = parent->addAction(aLabel, signalMapper, SLOT(map())); |
---|
[620] | 506 | |
---|
[607] | 507 | #endif |
---|
[620] | 508 | connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&))); |
---|
[607] | 509 | signalMapper->setMapping(action, QString(aCommand)); |
---|
| 510 | } |
---|
| 511 | |
---|
| 512 | |
---|
| 513 | |
---|
| 514 | |
---|
| 515 | /** |
---|
| 516 | Open the help dialog in a separate window.<br> |
---|
| 517 | This will be display as a tree widget.<br> |
---|
| 518 | Implementation of <b>void G4VBasicShell::TerminalHelp(G4String newCommand)</b> |
---|
| 519 | |
---|
| 520 | @param newCommand : open the tree widget item on this command if is set |
---|
| 521 | */ |
---|
| 522 | void G4UIQt::TerminalHelp( |
---|
| 523 | G4String newCommand |
---|
| 524 | ) |
---|
| 525 | { |
---|
| 526 | // Create the help dialog |
---|
| 527 | if (!fHelpDialog) { |
---|
| 528 | #if QT_VERSION < 0x040000 |
---|
[624] | 529 | fHelpDialog = new QDialog(0,0,FALSE,Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WStyle_MinMax ); |
---|
[607] | 530 | #else |
---|
[625] | 531 | fHelpDialog = new QDialog(0,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint); |
---|
[607] | 532 | #endif |
---|
[635] | 533 | QVBoxLayout *vLayout = new QVBoxLayout(fHelpDialog); |
---|
[697] | 534 | QWidget *helpWidget = new QWidget(fHelpDialog); |
---|
[633] | 535 | QSplitter *splitter = new QSplitter(Qt::Horizontal,fHelpDialog); |
---|
[619] | 536 | QPushButton *exitButton = new QPushButton("Exit",fHelpDialog); |
---|
[697] | 537 | exitButton->setAutoDefault(false); |
---|
[607] | 538 | connect(exitButton, SIGNAL(clicked()), fHelpDialog,SLOT(close())); |
---|
[697] | 539 | |
---|
| 540 | QHBoxLayout *helpLayout = new QHBoxLayout(helpWidget); |
---|
| 541 | #if QT_VERSION < 0x040000 |
---|
| 542 | helpLayout->add(new QLabel("Search :",helpWidget)); |
---|
| 543 | #else |
---|
| 544 | helpLayout->addWidget(new QLabel("Search :",helpWidget)); |
---|
| 545 | #endif |
---|
| 546 | helpLine = new QLineEdit(fHelpDialog); |
---|
| 547 | #if QT_VERSION < 0x040000 |
---|
| 548 | helpLayout->add(helpLine); |
---|
[719] | 549 | connect( helpLine, SIGNAL( returnPressed () ), this, SLOT( lookForHelpStringCallback() ) ); |
---|
[697] | 550 | #else |
---|
| 551 | helpLayout->addWidget(helpLine); |
---|
[719] | 552 | connect( helpLine, SIGNAL( editingFinished () ), this, SLOT( lookForHelpStringCallback() ) ); |
---|
[697] | 553 | #endif |
---|
[607] | 554 | |
---|
| 555 | // the help tree |
---|
| 556 | #if QT_VERSION < 0x040000 |
---|
| 557 | fHelpTreeWidget = new QListView(splitter); |
---|
| 558 | #else |
---|
| 559 | fHelpTreeWidget = new QTreeWidget(); |
---|
| 560 | #endif |
---|
[697] | 561 | fHelpTreeWidget = CreateHelpTree(); |
---|
[607] | 562 | |
---|
| 563 | fHelpArea = new QTextEdit(splitter); |
---|
| 564 | fHelpArea->setReadOnly(true); |
---|
| 565 | |
---|
| 566 | // Set layouts |
---|
| 567 | |
---|
[617] | 568 | #if QT_VERSION >= 0x040000 |
---|
[697] | 569 | if (fHelpTreeWidget) |
---|
| 570 | splitter->addWidget(fHelpTreeWidget); |
---|
[607] | 571 | splitter->addWidget(fHelpArea); |
---|
| 572 | #endif |
---|
| 573 | |
---|
| 574 | |
---|
[619] | 575 | #if QT_VERSION >= 0x040000 |
---|
[697] | 576 | vLayout->addWidget(helpWidget); |
---|
| 577 | vLayout->addWidget(splitter,1); |
---|
[619] | 578 | vLayout->addWidget(exitButton); |
---|
[617] | 579 | #else |
---|
[697] | 580 | vLayout->addWidget(helpWidget); |
---|
[719] | 581 | vLayout->addWidget(splitter,1); |
---|
[619] | 582 | vLayout->addWidget(exitButton); |
---|
[617] | 583 | #endif |
---|
[619] | 584 | |
---|
| 585 | // set the splitter size |
---|
[607] | 586 | #if QT_VERSION >= 0x040000 |
---|
[619] | 587 | QList<int> list; |
---|
| 588 | #else |
---|
| 589 | QValueList<int> list; |
---|
| 590 | #endif |
---|
| 591 | list.append( 400 ); |
---|
| 592 | list.append( 400 ); |
---|
| 593 | splitter->setSizes(list); |
---|
| 594 | |
---|
| 595 | #if QT_VERSION >= 0x040000 |
---|
[607] | 596 | fHelpDialog->setLayout(vLayout); |
---|
| 597 | #endif |
---|
| 598 | |
---|
| 599 | } |
---|
| 600 | |
---|
[695] | 601 | ActivateCommand(newCommand); |
---|
| 602 | |
---|
| 603 | #if QT_VERSION < 0x040000 |
---|
| 604 | fHelpDialog->setCaption( tr( "Help on commands" )); |
---|
| 605 | #else |
---|
| 606 | fHelpDialog->setWindowTitle(tr("Help on commands")); |
---|
| 607 | #endif |
---|
| 608 | fHelpDialog->resize(800,600); |
---|
| 609 | fHelpDialog->move(QPoint(400,150)); |
---|
| 610 | fHelpDialog->show(); |
---|
| 611 | fHelpDialog->raise(); |
---|
| 612 | #if QT_VERSION < 0x040000 |
---|
| 613 | fHelpDialog->setActiveWindow(); |
---|
| 614 | #else |
---|
| 615 | fHelpDialog->activateWindow(); |
---|
| 616 | #endif |
---|
| 617 | } |
---|
| 618 | |
---|
[697] | 619 | |
---|
[695] | 620 | void G4UIQt::ActivateCommand( |
---|
| 621 | G4String newCommand |
---|
| 622 | ) |
---|
| 623 | { |
---|
[697] | 624 | if (!fHelpTreeWidget) { |
---|
| 625 | return; |
---|
| 626 | } |
---|
[607] | 627 | // Look for the choosen command "newCommand" |
---|
| 628 | size_t i = newCommand.index(" "); |
---|
| 629 | G4String targetCom=""; |
---|
| 630 | if( i != std::string::npos ) |
---|
| 631 | { |
---|
| 632 | G4String newValue = newCommand(i+1,newCommand.length()-(i+1)); |
---|
| 633 | newValue.strip(G4String::both); |
---|
| 634 | targetCom = ModifyToFullPathCommand( newValue ); |
---|
| 635 | } |
---|
| 636 | if (targetCom != "") { |
---|
| 637 | #if QT_VERSION < 0x040000 |
---|
| 638 | QListViewItem* findItem = NULL; |
---|
| 639 | QListViewItem* tmpItem = fHelpTreeWidget->firstChild(); |
---|
| 640 | while (tmpItem != 0) { |
---|
| 641 | if (!findItem) { |
---|
| 642 | findItem = FindTreeItem(tmpItem,QString((char*)targetCom.data())); |
---|
| 643 | } |
---|
| 644 | tmpItem = tmpItem->nextSibling(); |
---|
| 645 | } |
---|
| 646 | #else |
---|
| 647 | QTreeWidgetItem* findItem = NULL; |
---|
| 648 | for (int a=0;a<fHelpTreeWidget->topLevelItemCount();a++) { |
---|
| 649 | if (!findItem) { |
---|
| 650 | findItem = FindTreeItem(fHelpTreeWidget->topLevelItem(a),QString((char*)targetCom.data())); |
---|
| 651 | } |
---|
| 652 | } |
---|
| 653 | #endif |
---|
| 654 | |
---|
| 655 | if (findItem) { |
---|
| 656 | |
---|
| 657 | //collapsed open item |
---|
| 658 | #if QT_VERSION < 0x040000 |
---|
| 659 | |
---|
| 660 | // FIXME : Has to be checked |
---|
| 661 | QListViewItem* tmpItem = fHelpTreeWidget->firstChild(); |
---|
| 662 | QList<QListViewItem> openItems; |
---|
| 663 | while ((tmpItem != 0) || (!openItems.isEmpty())) { |
---|
| 664 | if (tmpItem->isOpen() ) { |
---|
| 665 | tmpItem->setOpen(false); |
---|
| 666 | openItems.append(tmpItem); |
---|
| 667 | tmpItem = tmpItem->firstChild(); |
---|
| 668 | } else { |
---|
| 669 | tmpItem = tmpItem->nextSibling(); |
---|
| 670 | } |
---|
| 671 | if (tmpItem == 0) { |
---|
| 672 | tmpItem = openItems.take(openItems.count()-1); |
---|
| 673 | } |
---|
| 674 | } |
---|
| 675 | #else |
---|
| 676 | QList<QTreeWidgetItem *> selected; |
---|
| 677 | |
---|
| 678 | selected = fHelpTreeWidget->selectedItems(); |
---|
| 679 | if ( selected.count() != 0 ) { |
---|
| 680 | QTreeWidgetItem * tmp =selected.at( 0 ); |
---|
| 681 | while ( tmp) { |
---|
| 682 | #if QT_VERSION < 0x040202 |
---|
| 683 | fHelpTreeWidget->setItemExpanded(tmp,false); |
---|
| 684 | #else |
---|
| 685 | tmp->setExpanded(false); |
---|
| 686 | #endif |
---|
| 687 | tmp = tmp->parent(); |
---|
| 688 | } |
---|
| 689 | } |
---|
| 690 | #endif |
---|
| 691 | |
---|
| 692 | // clear old selection |
---|
| 693 | fHelpTreeWidget->clearSelection(); |
---|
| 694 | |
---|
| 695 | // set new selection |
---|
| 696 | #if QT_VERSION >= 0x040000 |
---|
| 697 | #if QT_VERSION < 0x040202 |
---|
| 698 | fHelpTreeWidget->setItemSelected(findItem,true); |
---|
| 699 | #else |
---|
| 700 | findItem->setSelected(true); |
---|
| 701 | #endif |
---|
| 702 | #else |
---|
| 703 | findItem->setSelected(true); |
---|
| 704 | #endif |
---|
| 705 | |
---|
| 706 | // expand parent item |
---|
| 707 | while ( findItem) { |
---|
| 708 | #if QT_VERSION < 0x040000 |
---|
| 709 | findItem->setOpen(true); |
---|
| 710 | #else |
---|
| 711 | #if QT_VERSION < 0x040202 |
---|
| 712 | fHelpTreeWidget->setItemExpanded(findItem,true); |
---|
| 713 | #else |
---|
| 714 | findItem->setExpanded(true); |
---|
| 715 | #endif |
---|
| 716 | #endif |
---|
| 717 | findItem = findItem->parent(); |
---|
| 718 | } |
---|
| 719 | |
---|
| 720 | // Call the update of the right textArea |
---|
| 721 | HelpTreeClicCallback(); |
---|
| 722 | } |
---|
| 723 | } |
---|
| 724 | } |
---|
| 725 | |
---|
[697] | 726 | |
---|
| 727 | |
---|
| 728 | /** |
---|
| 729 | Create the help tree widget |
---|
| 730 | @param parent : parent of tree widget |
---|
| 731 | @return the widget containing the tree or NULL if it could not have beeen created |
---|
| 732 | */ |
---|
| 733 | |
---|
| 734 | #if QT_VERSION < 0x040000 |
---|
| 735 | QListView * G4UIQt::CreateHelpTree() |
---|
| 736 | #else |
---|
| 737 | QTreeWidget * G4UIQt::CreateHelpTree() |
---|
| 738 | #endif |
---|
| 739 | { |
---|
| 740 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
| 741 | if(UI==NULL) return NULL; |
---|
| 742 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
| 743 | |
---|
| 744 | |
---|
| 745 | // build widget |
---|
| 746 | #if QT_VERSION < 0x040000 |
---|
| 747 | fHelpTreeWidget->setSelectionMode(QListView::Single); |
---|
| 748 | fHelpTreeWidget->setRootIsDecorated(true); |
---|
| 749 | fHelpTreeWidget->addColumn("Command"); |
---|
| 750 | fHelpTreeWidget->header()->setResizeEnabled(FALSE,1); |
---|
| 751 | #else |
---|
| 752 | fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection); |
---|
| 753 | QStringList labels; |
---|
[700] | 754 | labels << QString("Command"); |
---|
[697] | 755 | fHelpTreeWidget->setHeaderLabels(labels); |
---|
| 756 | #endif |
---|
| 757 | |
---|
| 758 | G4int treeSize = treeTop->GetTreeEntry(); |
---|
| 759 | #if QT_VERSION < 0x040000 |
---|
| 760 | QListViewItem * newItem; |
---|
| 761 | #else |
---|
| 762 | QTreeWidgetItem * newItem; |
---|
| 763 | #endif |
---|
| 764 | for (int a=0;a<treeSize;a++) { |
---|
| 765 | // Creating new item |
---|
| 766 | |
---|
| 767 | #if QT_VERSION < 0x040000 |
---|
| 768 | newItem = new QListViewItem(fHelpTreeWidget); |
---|
| 769 | newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace()); |
---|
| 770 | #else |
---|
| 771 | newItem = new QTreeWidgetItem(fHelpTreeWidget); |
---|
| 772 | newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed()); |
---|
| 773 | #endif |
---|
| 774 | |
---|
| 775 | |
---|
| 776 | // look for childs |
---|
| 777 | CreateChildTree(newItem,treeTop->GetTree(a+1)); |
---|
| 778 | // items.append(newItem); |
---|
| 779 | } |
---|
| 780 | |
---|
| 781 | |
---|
| 782 | #if QT_VERSION < 0x040000 |
---|
| 783 | connect(fHelpTreeWidget, SIGNAL(selectionChanged ()),this, SLOT(HelpTreeClicCallback())); |
---|
| 784 | connect(fHelpTreeWidget, SIGNAL(doubleClicked (QListViewItem*)),this, SLOT(HelpTreeDoubleClicCallback())); |
---|
| 785 | #else |
---|
| 786 | connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback())); |
---|
| 787 | connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback())); |
---|
| 788 | #endif |
---|
| 789 | |
---|
| 790 | return fHelpTreeWidget; |
---|
| 791 | } |
---|
| 792 | |
---|
| 793 | |
---|
| 794 | |
---|
[607] | 795 | /** Fill the Help Tree Widget |
---|
| 796 | @param aParent : parent item to fill |
---|
| 797 | @param aCommandTree : commandTree node associate with this part of the Tree |
---|
| 798 | */ |
---|
| 799 | #if QT_VERSION < 0x040000 |
---|
| 800 | void G4UIQt::CreateChildTree( |
---|
| 801 | QListViewItem *aParent |
---|
| 802 | ,G4UIcommandTree *aCommandTree |
---|
| 803 | #else |
---|
| 804 | void G4UIQt::CreateChildTree( |
---|
| 805 | QTreeWidgetItem *aParent |
---|
| 806 | ,G4UIcommandTree *aCommandTree |
---|
| 807 | #endif |
---|
| 808 | ) |
---|
| 809 | { |
---|
| 810 | if (aParent == NULL) return; |
---|
| 811 | if (aCommandTree == NULL) return; |
---|
| 812 | |
---|
| 813 | |
---|
| 814 | // Creating new item |
---|
| 815 | #if QT_VERSION < 0x040000 |
---|
| 816 | QListViewItem * newItem; |
---|
| 817 | #else |
---|
| 818 | QTreeWidgetItem * newItem; |
---|
| 819 | #endif |
---|
| 820 | |
---|
| 821 | // Get the Sub directories |
---|
| 822 | for (int a=0;a<aCommandTree->GetTreeEntry();a++) { |
---|
| 823 | |
---|
| 824 | #if QT_VERSION < 0x040000 |
---|
| 825 | newItem = new QListViewItem(aParent); |
---|
| 826 | newItem->setText(0,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace()); |
---|
| 827 | |
---|
| 828 | #else |
---|
| 829 | newItem = new QTreeWidgetItem(aParent); |
---|
| 830 | newItem->setText(0,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed()); |
---|
| 831 | #endif |
---|
| 832 | |
---|
| 833 | CreateChildTree(newItem,aCommandTree->GetTree(a+1)); |
---|
| 834 | } |
---|
| 835 | |
---|
| 836 | |
---|
| 837 | |
---|
| 838 | // Get the Commands |
---|
| 839 | |
---|
| 840 | for (int a=0;a<aCommandTree->GetCommandEntry();a++) { |
---|
| 841 | |
---|
| 842 | QStringList stringList; |
---|
| 843 | #if QT_VERSION < 0x040000 |
---|
| 844 | newItem = new QListViewItem(aParent); |
---|
| 845 | newItem->setText(0,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).simplifyWhiteSpace()); |
---|
| 846 | newItem->setOpen(false); |
---|
| 847 | |
---|
| 848 | #else |
---|
| 849 | newItem = new QTreeWidgetItem(aParent); |
---|
| 850 | newItem->setText(0,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed()); |
---|
| 851 | #if QT_VERSION < 0x040202 |
---|
| 852 | fHelpTreeWidget->setItemExpanded(newItem,false); |
---|
| 853 | #else |
---|
| 854 | newItem->setExpanded(false); |
---|
| 855 | #endif |
---|
| 856 | #endif |
---|
| 857 | |
---|
| 858 | } |
---|
| 859 | } |
---|
| 860 | |
---|
| 861 | |
---|
| 862 | /** Find a treeItemWidget in the help tree |
---|
| 863 | @param aCommand item's String to look for |
---|
| 864 | @return item if found, NULL if not |
---|
| 865 | */ |
---|
| 866 | #if QT_VERSION < 0x040000 |
---|
| 867 | QListViewItem* G4UIQt::FindTreeItem( |
---|
| 868 | QListViewItem *aParent |
---|
| 869 | #else |
---|
| 870 | QTreeWidgetItem* G4UIQt::FindTreeItem( |
---|
| 871 | QTreeWidgetItem *aParent |
---|
| 872 | #endif |
---|
| 873 | ,const QString& aCommand |
---|
| 874 | ) |
---|
| 875 | { |
---|
| 876 | if (aParent == NULL) return NULL; |
---|
| 877 | |
---|
| 878 | if (aParent->text(0) == aCommand) |
---|
| 879 | return aParent; |
---|
| 880 | |
---|
| 881 | #if QT_VERSION < 0x040000 |
---|
| 882 | QListViewItem * tmp = NULL; |
---|
| 883 | QListViewItem* tmpItem = aParent->firstChild(); |
---|
| 884 | while (tmpItem != 0) { |
---|
| 885 | if (!tmp) |
---|
| 886 | tmp = FindTreeItem(tmpItem,aCommand); |
---|
| 887 | tmpItem = tmpItem->nextSibling(); |
---|
| 888 | } |
---|
| 889 | |
---|
| 890 | #else |
---|
| 891 | QTreeWidgetItem * tmp = NULL; |
---|
| 892 | for (int a=0;a<aParent->childCount();a++) { |
---|
| 893 | if (!tmp) |
---|
| 894 | tmp = FindTreeItem(aParent->child(a),aCommand); |
---|
| 895 | } |
---|
| 896 | #endif |
---|
| 897 | return tmp; |
---|
| 898 | } |
---|
| 899 | |
---|
| 900 | |
---|
| 901 | /** Build the command list parameters in a QString<br> |
---|
| 902 | Reimplement partialy the G4UIparameter.cc |
---|
| 903 | @param aCommand : command to list parameters |
---|
| 904 | @see G4UIparameter::List() |
---|
| 905 | @see G4UIcommand::List() |
---|
| 906 | @return the command list parameters, or "" if nothing |
---|
| 907 | */ |
---|
| 908 | QString G4UIQt::GetCommandList ( |
---|
| 909 | const G4UIcommand *aCommand |
---|
| 910 | ) |
---|
| 911 | { |
---|
| 912 | |
---|
| 913 | QString txt =""; |
---|
| 914 | if (aCommand == NULL) |
---|
| 915 | return txt; |
---|
| 916 | |
---|
| 917 | G4String commandPath = aCommand->GetCommandPath(); |
---|
| 918 | G4String rangeString = aCommand->GetRange(); |
---|
| 919 | G4int n_guidanceEntry = aCommand->GetGuidanceEntries(); |
---|
| 920 | G4int n_parameterEntry = aCommand->GetParameterEntries(); |
---|
| 921 | |
---|
| 922 | if ((commandPath == "") && |
---|
| 923 | (rangeString == "") && |
---|
| 924 | (n_guidanceEntry == 0) && |
---|
| 925 | (n_parameterEntry == 0)) { |
---|
| 926 | return txt; |
---|
| 927 | } |
---|
| 928 | |
---|
| 929 | if((commandPath.length()-1)!='/') { |
---|
| 930 | txt += "Command " + QString((char*)(commandPath).data()) + "\n"; |
---|
| 931 | } |
---|
| 932 | txt += "Guidance :\n"; |
---|
| 933 | |
---|
| 934 | for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) { |
---|
| 935 | txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n"; |
---|
| 936 | } |
---|
| 937 | if( ! rangeString.isNull() ) { |
---|
| 938 | txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n"; |
---|
| 939 | } |
---|
| 940 | if( n_parameterEntry > 0 ) { |
---|
| 941 | G4UIparameter *param; |
---|
| 942 | |
---|
| 943 | // Re-implementation of G4UIparameter.cc |
---|
| 944 | |
---|
| 945 | for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) { |
---|
| 946 | param = aCommand->GetParameter(i_thParameter); |
---|
| 947 | txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n"; |
---|
| 948 | if( ! param->GetParameterGuidance().isNull() ) |
---|
| 949 | txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ; |
---|
| 950 | txt += " Parameter type : " + QString(QChar(param->GetParameterType())) + "\n"; |
---|
| 951 | if(param->IsOmittable()){ |
---|
| 952 | txt += " Omittable : True\n"; |
---|
| 953 | } else { |
---|
| 954 | txt += " Omittable : False\n"; |
---|
| 955 | } |
---|
| 956 | if( param->GetCurrentAsDefault() ) { |
---|
| 957 | txt += " Default value : taken from the current value\n"; |
---|
| 958 | } else if( ! param->GetDefaultValue().isNull() ) { |
---|
| 959 | txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n"; |
---|
| 960 | } |
---|
| 961 | if( ! param->GetParameterRange().isNull() ) { |
---|
| 962 | txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n"; |
---|
| 963 | } |
---|
| 964 | if( ! param->GetParameterCandidates().isNull() ) { |
---|
| 965 | txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n"; |
---|
| 966 | } |
---|
| 967 | } |
---|
| 968 | } |
---|
| 969 | return txt; |
---|
| 970 | } |
---|
| 971 | |
---|
| 972 | |
---|
| 973 | |
---|
| 974 | /** Implement G4VBasicShell vurtual function |
---|
| 975 | */ |
---|
| 976 | G4bool G4UIQt::GetHelpChoice( |
---|
| 977 | G4int& aInt |
---|
| 978 | ) |
---|
| 979 | { |
---|
[608] | 980 | #ifdef GEANT4_QT_DEBUG |
---|
[607] | 981 | printf("G4UIQt::GetHelpChoice SHOULD NEVER GO HERE"); |
---|
[608] | 982 | #endif |
---|
[607] | 983 | return true; |
---|
| 984 | } |
---|
| 985 | |
---|
| 986 | |
---|
| 987 | /** Implement G4VBasicShell vurtual function |
---|
| 988 | */ |
---|
| 989 | void G4UIQt::ExitHelp( |
---|
| 990 | ) |
---|
| 991 | { |
---|
[608] | 992 | #ifdef GEANT4_QT_DEBUG |
---|
[607] | 993 | printf("G4UIQt::ExitHelp SHOULD NEVER GO HERE"); |
---|
[608] | 994 | #endif |
---|
[607] | 995 | } |
---|
| 996 | |
---|
| 997 | |
---|
| 998 | /** Event filter method. Every event from QtApplication goes here.<br/> |
---|
| 999 | We apply a filter only for the Up and Down Arrow press when the QLineEdit<br/> |
---|
| 1000 | is active. If this filter match, Up arrow we give the previous command<br/> |
---|
| 1001 | and Down arrow will give the next if exist.<br/> |
---|
| 1002 | @param obj Emitter of the event |
---|
| 1003 | @param event Kind of event |
---|
| 1004 | */ |
---|
| 1005 | bool G4UIQt::eventFilter( // Should stay with a minuscule eventFilter because of Qt |
---|
| 1006 | QObject *aObj |
---|
| 1007 | ,QEvent *aEvent |
---|
| 1008 | ) |
---|
| 1009 | { |
---|
| 1010 | if (aObj == NULL) return false; |
---|
| 1011 | if (aEvent == NULL) return false; |
---|
| 1012 | |
---|
| 1013 | if (aObj == fCommandHistoryArea) { |
---|
| 1014 | if (aEvent->type() == QEvent::KeyPress) { |
---|
| 1015 | fCommandArea->setFocus(); |
---|
| 1016 | } |
---|
| 1017 | } |
---|
| 1018 | if (aObj == fCommandArea) { |
---|
| 1019 | if (aEvent->type() == QEvent::KeyPress) { |
---|
| 1020 | QKeyEvent *e = static_cast<QKeyEvent*>(aEvent); |
---|
| 1021 | if ((e->key() == (Qt::Key_Down)) || |
---|
| 1022 | (e->key() == (Qt::Key_PageDown)) || |
---|
| 1023 | (e->key() == (Qt::Key_Up)) || |
---|
| 1024 | (e->key() == (Qt::Key_PageUp))) { |
---|
| 1025 | #if QT_VERSION < 0x040000 |
---|
| 1026 | // count rows... |
---|
| 1027 | QListViewItem* tmpItem = fCommandHistoryArea->firstChild(); |
---|
| 1028 | int selection = -1; |
---|
| 1029 | int index = 0; |
---|
| 1030 | while (tmpItem != 0) { |
---|
| 1031 | if (tmpItem == fCommandHistoryArea->selectedItem()) { |
---|
| 1032 | selection = index; |
---|
| 1033 | } |
---|
| 1034 | index ++; |
---|
| 1035 | tmpItem = tmpItem->nextSibling(); |
---|
| 1036 | } |
---|
| 1037 | if (fCommandHistoryArea->childCount()) { |
---|
| 1038 | if (selection == -1) { |
---|
| 1039 | selection = fCommandHistoryArea->childCount()-1; |
---|
| 1040 | } else { |
---|
| 1041 | if (e->key() == (Qt::Key_Down)) { |
---|
| 1042 | if (selection <(fCommandHistoryArea->childCount()-1)) |
---|
| 1043 | selection++; |
---|
| 1044 | } else if (e->key() == (Qt::Key_PageDown)) { |
---|
| 1045 | selection = fCommandHistoryArea->childCount()-1; |
---|
| 1046 | #else |
---|
| 1047 | int selection = fCommandHistoryArea->currentRow(); |
---|
| 1048 | if (fCommandHistoryArea->count()) { |
---|
| 1049 | if (selection == -1) { |
---|
| 1050 | selection = fCommandHistoryArea->count()-1; |
---|
| 1051 | } else { |
---|
| 1052 | if (e->key() == (Qt::Key_Down)) { |
---|
| 1053 | if (selection <(fCommandHistoryArea->count()-1)) |
---|
| 1054 | selection++; |
---|
| 1055 | } else if (e->key() == (Qt::Key_PageDown)) { |
---|
| 1056 | selection = fCommandHistoryArea->count()-1; |
---|
| 1057 | #endif |
---|
| 1058 | } else if (e->key() == (Qt::Key_Up)) { |
---|
| 1059 | if (selection >0) |
---|
| 1060 | selection --; |
---|
| 1061 | } else if (e->key() == (Qt::Key_PageUp)) { |
---|
| 1062 | selection = 0; |
---|
| 1063 | } |
---|
| 1064 | } |
---|
| 1065 | fCommandHistoryArea->clearSelection(); |
---|
| 1066 | #if QT_VERSION < 0x040000 |
---|
| 1067 | QListViewItem* tmpItem = fCommandHistoryArea->firstChild(); |
---|
| 1068 | int index = 0; |
---|
| 1069 | while (tmpItem != 0) { |
---|
| 1070 | if (index == selection) { |
---|
| 1071 | tmpItem->setSelected(true); |
---|
| 1072 | fCommandHistoryArea->setCurrentItem(tmpItem); |
---|
| 1073 | } |
---|
| 1074 | index ++; |
---|
| 1075 | tmpItem = tmpItem->nextSibling(); |
---|
| 1076 | } |
---|
| 1077 | #else |
---|
| 1078 | #if QT_VERSION < 0x040202 |
---|
| 1079 | fCommandHistoryArea->setItemSelected(fCommandHistoryArea->item(selection),true); |
---|
| 1080 | #else |
---|
| 1081 | fCommandHistoryArea->item(selection)->setSelected(true); |
---|
| 1082 | #endif |
---|
| 1083 | fCommandHistoryArea->setCurrentItem(fCommandHistoryArea->item(selection)); |
---|
| 1084 | #endif |
---|
| 1085 | } |
---|
| 1086 | } else if (e->key() == (Qt::Key_Tab)) { |
---|
| 1087 | #if QT_VERSION < 0x040000 |
---|
| 1088 | G4String ss = Complete(fCommandArea->text().ascii()); |
---|
| 1089 | #else |
---|
| 1090 | G4String ss = Complete(fCommandArea->text().toStdString().c_str()); |
---|
| 1091 | #endif |
---|
| 1092 | fCommandArea->setText((char*)(ss.data())); |
---|
| 1093 | |
---|
| 1094 | // do not pass by parent, it will disable widget tab focus ! |
---|
| 1095 | return true; |
---|
| 1096 | } |
---|
| 1097 | } |
---|
| 1098 | } |
---|
| 1099 | // pass the event on to the parent class |
---|
| 1100 | return QObject::eventFilter(aObj, aEvent); |
---|
| 1101 | } |
---|
| 1102 | |
---|
| 1103 | |
---|
| 1104 | |
---|
| 1105 | |
---|
| 1106 | /***************************************************************************/ |
---|
| 1107 | // |
---|
| 1108 | // SLOTS DEFINITIONS |
---|
| 1109 | // |
---|
| 1110 | /***************************************************************************/ |
---|
| 1111 | |
---|
| 1112 | /** Called when user give "help" command. |
---|
| 1113 | */ |
---|
| 1114 | void G4UIQt::ShowHelpCallback ( |
---|
| 1115 | ) |
---|
| 1116 | { |
---|
| 1117 | TerminalHelp(""); |
---|
| 1118 | } |
---|
| 1119 | |
---|
| 1120 | |
---|
| 1121 | /** Called when user click on clear button. Clear the text Output area |
---|
| 1122 | */ |
---|
| 1123 | void G4UIQt::ClearButtonCallback ( |
---|
| 1124 | ) |
---|
| 1125 | { |
---|
| 1126 | fTextArea->clear(); |
---|
| 1127 | } |
---|
| 1128 | |
---|
[608] | 1129 | /** Called when user exit session |
---|
| 1130 | */ |
---|
| 1131 | void G4UIQt::ExitSession ( |
---|
| 1132 | ) |
---|
| 1133 | { |
---|
| 1134 | SessionTerminate(); |
---|
| 1135 | } |
---|
[607] | 1136 | |
---|
[608] | 1137 | |
---|
[607] | 1138 | /** Callback call when "click on a menu entry.<br> |
---|
| 1139 | Send the associated command to geant4 |
---|
| 1140 | */ |
---|
| 1141 | void G4UIQt::CommandEnteredCallback ( |
---|
| 1142 | ) |
---|
| 1143 | { |
---|
| 1144 | #if QT_VERSION < 0x040000 |
---|
| 1145 | G4String command (fCommandArea->text().ascii()); |
---|
| 1146 | if (fCommandArea->text().simplifyWhiteSpace() != "") { |
---|
| 1147 | |
---|
| 1148 | QListViewItem *newItem = new QListViewItem(fCommandHistoryArea); |
---|
| 1149 | newItem->setText(0,fCommandArea->text()); |
---|
[619] | 1150 | fCommandHistoryArea->insertItem(newItem); |
---|
[620] | 1151 | // now we have to arrange |
---|
| 1152 | QListViewItem *temp= fCommandHistoryArea->lastItem(); |
---|
| 1153 | for (int i=0; i<fCommandHistoryArea->childCount()-1;i++) { |
---|
| 1154 | fCommandHistoryArea->takeItem(temp); |
---|
| 1155 | fCommandHistoryArea->insertItem(temp); |
---|
| 1156 | temp= fCommandHistoryArea->lastItem(); |
---|
| 1157 | } |
---|
[607] | 1158 | #else |
---|
| 1159 | G4String command (fCommandArea->text().toStdString().c_str()); |
---|
| 1160 | if (fCommandArea->text().trimmed() != "") { |
---|
| 1161 | fCommandHistoryArea->addItem(fCommandArea->text()); |
---|
| 1162 | #endif |
---|
| 1163 | fCommandHistoryArea->clearSelection(); |
---|
| 1164 | fCommandHistoryArea->setCurrentItem(NULL); |
---|
| 1165 | fCommandArea->setText(""); |
---|
| 1166 | |
---|
| 1167 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
| 1168 | if (interactorManager) { |
---|
| 1169 | interactorManager->FlushAndWaitExecution(); |
---|
| 1170 | } |
---|
| 1171 | if (command(0,4) != "help") { |
---|
| 1172 | ApplyShellCommand (command,exitSession,exitPause); |
---|
| 1173 | } else { |
---|
| 1174 | TerminalHelp(command); |
---|
| 1175 | } |
---|
| 1176 | if(exitSession==true) |
---|
| 1177 | SessionTerminate(); |
---|
| 1178 | } |
---|
| 1179 | } |
---|
| 1180 | |
---|
| 1181 | |
---|
| 1182 | /** Callback call when "enter" clicked on the command zone.<br> |
---|
| 1183 | Send the command to geant4 |
---|
| 1184 | @param aCommand |
---|
| 1185 | */ |
---|
| 1186 | void G4UIQt::ButtonCallback ( |
---|
| 1187 | const QString& aCommand |
---|
| 1188 | ) |
---|
| 1189 | { |
---|
| 1190 | #if QT_VERSION < 0x040000 |
---|
| 1191 | G4String ss = G4String(aCommand.ascii()); |
---|
| 1192 | #else |
---|
| 1193 | G4String ss = G4String(aCommand.toStdString().c_str()); |
---|
| 1194 | #endif |
---|
| 1195 | ApplyShellCommand(ss,exitSession,exitPause); |
---|
| 1196 | if(exitSession==true) |
---|
| 1197 | SessionTerminate(); |
---|
| 1198 | } |
---|
| 1199 | |
---|
| 1200 | |
---|
| 1201 | |
---|
| 1202 | /** This callback is activated when user selected a item in the help tree |
---|
| 1203 | */ |
---|
| 1204 | void G4UIQt::HelpTreeClicCallback ( |
---|
| 1205 | ) |
---|
| 1206 | { |
---|
| 1207 | #if QT_VERSION < 0x040000 |
---|
| 1208 | QListViewItem* item = NULL; |
---|
| 1209 | #else |
---|
| 1210 | QTreeWidgetItem* item = NULL; |
---|
| 1211 | #endif |
---|
| 1212 | if (!fHelpTreeWidget) |
---|
| 1213 | return ; |
---|
| 1214 | |
---|
| 1215 | if (!fHelpArea) |
---|
| 1216 | return; |
---|
| 1217 | |
---|
| 1218 | #if QT_VERSION < 0x040000 |
---|
| 1219 | item =fHelpTreeWidget->selectedItem(); |
---|
| 1220 | #else |
---|
| 1221 | QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems(); |
---|
| 1222 | if (list.isEmpty()) |
---|
| 1223 | return; |
---|
| 1224 | item = list.first(); |
---|
| 1225 | #endif |
---|
| 1226 | if (!item) |
---|
| 1227 | return; |
---|
| 1228 | |
---|
| 1229 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
| 1230 | if(UI==NULL) return; |
---|
| 1231 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
[699] | 1232 | |
---|
| 1233 | |
---|
| 1234 | |
---|
| 1235 | std::string itemText; |
---|
[607] | 1236 | #if QT_VERSION < 0x040000 |
---|
[699] | 1237 | itemText = std::string(item->text(0).ascii()); |
---|
[607] | 1238 | #else |
---|
[699] | 1239 | itemText = std::string(item->text(0).toStdString()); |
---|
[607] | 1240 | #endif |
---|
[699] | 1241 | |
---|
| 1242 | G4UIcommand* command = treeTop->FindPath(itemText.c_str()); |
---|
| 1243 | |
---|
[607] | 1244 | if (command) { |
---|
| 1245 | #if QT_VERSION >= 0x040000 |
---|
| 1246 | #if QT_VERSION < 0x040200 |
---|
| 1247 | fHelpArea->clear(); |
---|
| 1248 | fHelpArea->append(GetCommandList(command)); |
---|
| 1249 | #else |
---|
| 1250 | fHelpArea->setText(GetCommandList(command)); |
---|
| 1251 | #endif |
---|
| 1252 | #else |
---|
| 1253 | fHelpArea->setText(GetCommandList(command)); |
---|
| 1254 | #endif |
---|
[699] | 1255 | } else { // this is a command |
---|
| 1256 | G4UIcommandTree* path = treeTop->FindCommandTree(itemText.c_str()); |
---|
| 1257 | if ( path) { |
---|
| 1258 | // this is not a command, this is a sub directory |
---|
| 1259 | // We display the Title |
---|
[607] | 1260 | #if QT_VERSION >= 0x040000 |
---|
| 1261 | #if QT_VERSION < 0x040200 |
---|
[699] | 1262 | fHelpArea->clear(); |
---|
| 1263 | fHelpArea->append(path->GetTitle().data()); |
---|
[607] | 1264 | #else |
---|
[699] | 1265 | fHelpArea->setText(path->GetTitle().data()); |
---|
[607] | 1266 | #endif |
---|
| 1267 | #else |
---|
[699] | 1268 | fHelpArea->setText(path->GetTitle().data()); |
---|
[607] | 1269 | #endif |
---|
[699] | 1270 | } |
---|
[607] | 1271 | } |
---|
| 1272 | } |
---|
[699] | 1273 | |
---|
[607] | 1274 | /** This callback is activated when user double clic on a item in the help tree |
---|
| 1275 | */ |
---|
| 1276 | void G4UIQt::HelpTreeDoubleClicCallback ( |
---|
[648] | 1277 | ) |
---|
| 1278 | { |
---|
| 1279 | HelpTreeClicCallback(); |
---|
| 1280 | |
---|
[607] | 1281 | #if QT_VERSION < 0x040000 |
---|
[648] | 1282 | QListViewItem* item = NULL; |
---|
[607] | 1283 | #else |
---|
[648] | 1284 | QTreeWidgetItem* item = NULL; |
---|
[607] | 1285 | #endif |
---|
[648] | 1286 | if (!fHelpTreeWidget) |
---|
| 1287 | return ; |
---|
| 1288 | |
---|
| 1289 | if (!fHelpArea) |
---|
| 1290 | return; |
---|
| 1291 | |
---|
| 1292 | #if QT_VERSION < 0x040000 |
---|
| 1293 | item =fHelpTreeWidget->selectedItem(); |
---|
| 1294 | #else |
---|
| 1295 | QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems(); |
---|
| 1296 | if (list.isEmpty()) |
---|
| 1297 | return; |
---|
| 1298 | item = list.first(); |
---|
| 1299 | #endif |
---|
| 1300 | if (!item) |
---|
| 1301 | return; |
---|
| 1302 | |
---|
[683] | 1303 | fCommandArea->clear(); |
---|
[700] | 1304 | fCommandArea->setText(item->text(0)); |
---|
[607] | 1305 | } |
---|
| 1306 | |
---|
| 1307 | |
---|
| 1308 | /** Callback called when user select an old command in the command history<br> |
---|
| 1309 | Give it to the command area. |
---|
| 1310 | */ |
---|
| 1311 | void G4UIQt::CommandHistoryCallback( |
---|
| 1312 | ) |
---|
| 1313 | { |
---|
| 1314 | #if QT_VERSION < 0x040000 |
---|
| 1315 | QListViewItem* item = NULL; |
---|
| 1316 | #else |
---|
| 1317 | QListWidgetItem* item = NULL; |
---|
| 1318 | #endif |
---|
| 1319 | if (!fCommandHistoryArea) |
---|
| 1320 | return ; |
---|
[632] | 1321 | |
---|
[607] | 1322 | |
---|
| 1323 | #if QT_VERSION < 0x040000 |
---|
[620] | 1324 | item =fCommandHistoryArea->selectedItem(); |
---|
[607] | 1325 | #else |
---|
| 1326 | QList<QListWidgetItem *> list =fCommandHistoryArea->selectedItems(); |
---|
| 1327 | if (list.isEmpty()) |
---|
| 1328 | return; |
---|
| 1329 | item = list.first(); |
---|
| 1330 | #endif |
---|
| 1331 | if (!item) |
---|
| 1332 | return; |
---|
| 1333 | #if QT_VERSION < 0x040000 |
---|
| 1334 | fCommandArea->setText(item->text(0)); |
---|
| 1335 | #else |
---|
| 1336 | fCommandArea->setText(item->text()); |
---|
| 1337 | #endif |
---|
| 1338 | |
---|
| 1339 | } |
---|
| 1340 | |
---|
[697] | 1341 | |
---|
[695] | 1342 | /** Callback called when user give a new string to look for<br> |
---|
[697] | 1343 | Display a list of matching commands descriptions. If no string is set, |
---|
| 1344 | will display the complete help tree |
---|
[695] | 1345 | */ |
---|
| 1346 | void G4UIQt::lookForHelpStringCallback( |
---|
| 1347 | ) |
---|
| 1348 | { |
---|
[698] | 1349 | #if QT_VERSION < 0x040200 |
---|
| 1350 | fHelpArea->clear(); |
---|
| 1351 | #else |
---|
| 1352 | fHelpArea->setText(""); |
---|
| 1353 | #endif |
---|
[697] | 1354 | if (helpLine->text() =="") { |
---|
| 1355 | // clear old help tree |
---|
| 1356 | fHelpTreeWidget->clear(); |
---|
[719] | 1357 | #if QT_VERSION < 0x040200 |
---|
| 1358 | fHelpTreeWidget->removeColumn(1); |
---|
| 1359 | fHelpTreeWidget->removeColumn(0); |
---|
| 1360 | #endif |
---|
[697] | 1361 | CreateHelpTree(); |
---|
| 1362 | return; |
---|
| 1363 | } |
---|
| 1364 | |
---|
[719] | 1365 | #ifdef GEANT4_QT_DEBUG |
---|
| 1366 | printf("G4UIQt::lookForHelpStringCallback\n"); |
---|
| 1367 | #endif |
---|
| 1368 | |
---|
[695] | 1369 | // the help tree |
---|
| 1370 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
| 1371 | if(UI==NULL) return; |
---|
| 1372 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
| 1373 | |
---|
| 1374 | G4int treeSize = treeTop->GetTreeEntry(); |
---|
[697] | 1375 | |
---|
| 1376 | // clear old help tree |
---|
| 1377 | fHelpTreeWidget->clear(); |
---|
[719] | 1378 | #if QT_VERSION < 0x040200 |
---|
| 1379 | fHelpTreeWidget->removeColumn(1); |
---|
| 1380 | fHelpTreeWidget->removeColumn(0); |
---|
| 1381 | #endif |
---|
[697] | 1382 | |
---|
| 1383 | // look for new items |
---|
| 1384 | |
---|
[695] | 1385 | int tmp = 0; |
---|
[719] | 1386 | #if QT_VERSION < 0x040000 |
---|
| 1387 | int multFactor = 1000; // factor special for having double keys in Qt3 |
---|
| 1388 | int doubleKeyAdd = 0; // decay for doubleKeys in Qt3 |
---|
| 1389 | #endif |
---|
| 1390 | |
---|
[697] | 1391 | QMap<int,QString> commandResultMap; |
---|
| 1392 | QMap<int,QString> commandChildResultMap; |
---|
| 1393 | |
---|
[695] | 1394 | for (int a=0;a<treeSize;a++) { |
---|
| 1395 | G4UIcommand* command = treeTop->FindPath(treeTop->GetTree(a+1)->GetPathName().data()); |
---|
[719] | 1396 | #if QT_VERSION > 0x040000 |
---|
[695] | 1397 | tmp = GetCommandList (command).count(helpLine->text(),Qt::CaseInsensitive); |
---|
[719] | 1398 | #else |
---|
| 1399 | tmp = GetCommandList (command).contains(helpLine->text(),false); |
---|
| 1400 | #endif |
---|
[695] | 1401 | if (tmp >0) { |
---|
[719] | 1402 | #if QT_VERSION > 0x040000 |
---|
[697] | 1403 | commandResultMap.insertMulti(tmp,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data())); |
---|
[719] | 1404 | #else // tricky thing for Qt3... |
---|
| 1405 | doubleKeyAdd = 0; |
---|
| 1406 | while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) { |
---|
| 1407 | doubleKeyAdd ++; |
---|
| 1408 | } |
---|
| 1409 | commandResultMap.insert( tmp*multFactor+doubleKeyAdd,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()) ); |
---|
[695] | 1410 | #endif |
---|
| 1411 | } |
---|
| 1412 | // look for childs |
---|
[697] | 1413 | commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a+1),helpLine->text()); |
---|
| 1414 | // insert new childs |
---|
| 1415 | if (!commandChildResultMap.empty()) { |
---|
[719] | 1416 | #if QT_VERSION > 0x040000 |
---|
[697] | 1417 | QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin(); |
---|
| 1418 | while (i != commandChildResultMap.constEnd()) { |
---|
| 1419 | commandResultMap.insertMulti(i.key(),i.value()); |
---|
[719] | 1420 | #else // tricky thing for Qt3... |
---|
| 1421 | QMap<int,QString>::const_iterator i = commandChildResultMap.begin(); |
---|
| 1422 | while (i != commandChildResultMap.end()) { |
---|
| 1423 | doubleKeyAdd = 0; |
---|
| 1424 | while (commandResultMap.find( i.key()*multFactor+doubleKeyAdd) != commandResultMap.end()) { |
---|
| 1425 | doubleKeyAdd ++; |
---|
| 1426 | } |
---|
| 1427 | commandResultMap.insert(i.key()*multFactor+doubleKeyAdd,i.data()); |
---|
| 1428 | #endif |
---|
[697] | 1429 | i++; |
---|
| 1430 | } |
---|
| 1431 | commandChildResultMap.clear(); |
---|
| 1432 | } |
---|
[695] | 1433 | } |
---|
[697] | 1434 | |
---|
| 1435 | // build new help tree |
---|
| 1436 | #if QT_VERSION < 0x040000 |
---|
| 1437 | fHelpTreeWidget->setSelectionMode(QListView::Single); |
---|
| 1438 | fHelpTreeWidget->setRootIsDecorated(true); |
---|
| 1439 | fHelpTreeWidget->addColumn("Command"); |
---|
| 1440 | fHelpTreeWidget->addColumn("Match"); |
---|
| 1441 | // fHelpTreeWidget->header()->setResizeEnabled(FALSE,1); |
---|
| 1442 | #else |
---|
| 1443 | fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection); |
---|
[700] | 1444 | fHelpTreeWidget->setColumnCount(2); |
---|
[697] | 1445 | QStringList labels; |
---|
[700] | 1446 | labels << QString("Command") << QString("Match"); |
---|
[697] | 1447 | fHelpTreeWidget->setHeaderLabels(labels); |
---|
| 1448 | #endif |
---|
| 1449 | |
---|
| 1450 | if (commandResultMap.empty()) { |
---|
| 1451 | #if QT_VERSION < 0x040200 |
---|
| 1452 | fHelpArea->clear(); |
---|
| 1453 | fHelpArea->append("No match found"); |
---|
| 1454 | #else |
---|
| 1455 | fHelpArea->setText("No match found"); |
---|
| 1456 | #endif |
---|
| 1457 | return; |
---|
| 1458 | } |
---|
| 1459 | |
---|
[719] | 1460 | #if QT_VERSION > 0x040000 |
---|
[697] | 1461 | QMap<int,QString>::const_iterator i = commandResultMap.constEnd(); |
---|
[719] | 1462 | #else |
---|
| 1463 | QMap<int,QString>::const_iterator i = commandResultMap.end(); |
---|
| 1464 | #endif |
---|
[697] | 1465 | i--; |
---|
| 1466 | // 10 maximum progress values |
---|
| 1467 | float multValue = 10.0/(float)(i.key()); |
---|
| 1468 | QString progressChar = "|"; |
---|
| 1469 | QString progressStr = "|"; |
---|
| 1470 | |
---|
| 1471 | #if QT_VERSION < 0x040000 |
---|
| 1472 | QListViewItem * newItem; |
---|
| 1473 | #else |
---|
| 1474 | QTreeWidgetItem * newItem; |
---|
| 1475 | #endif |
---|
| 1476 | bool end = false; |
---|
| 1477 | while (!end) { |
---|
[719] | 1478 | #if QT_VERSION > 0x040000 |
---|
[697] | 1479 | if (i == commandResultMap.constBegin()) { |
---|
[719] | 1480 | #else |
---|
| 1481 | if (i == commandResultMap.begin()) { |
---|
| 1482 | #endif |
---|
[697] | 1483 | end = true; |
---|
| 1484 | } |
---|
| 1485 | for(int a=0;a<int(i.key()*multValue);a++) { |
---|
| 1486 | progressStr += progressChar; |
---|
| 1487 | } |
---|
| 1488 | #if QT_VERSION < 0x040000 |
---|
| 1489 | newItem = new QListViewItem(fHelpTreeWidget); |
---|
[719] | 1490 | newItem->setText(0,i.data().simplifyWhiteSpace()); |
---|
[697] | 1491 | #else |
---|
| 1492 | newItem = new QTreeWidgetItem(fHelpTreeWidget); |
---|
| 1493 | newItem->setText(0,i.value().trimmed()); |
---|
[719] | 1494 | #endif |
---|
[700] | 1495 | newItem->setText(1,progressStr); |
---|
[697] | 1496 | |
---|
| 1497 | #if QT_VERSION >= 0x040200 |
---|
[700] | 1498 | newItem->setForeground ( 1, QBrush(Qt::blue) ); |
---|
[697] | 1499 | #endif |
---|
| 1500 | progressStr = "|"; |
---|
| 1501 | i--; |
---|
| 1502 | } |
---|
| 1503 | // FIXME : to be checked on Qt3 |
---|
| 1504 | #if QT_VERSION < 0x040000 |
---|
[700] | 1505 | fHelpTreeWidget->setColumnWidthMode (1,QListView::Maximum); |
---|
[719] | 1506 | fHelpTreeWidget->setSorting(1,false); |
---|
[697] | 1507 | #else |
---|
| 1508 | fHelpTreeWidget->resizeColumnToContents (0); |
---|
[719] | 1509 | fHelpTreeWidget->sortItems(1,Qt::DescendingOrder); |
---|
[700] | 1510 | // fHelpTreeWidget->setColumnWidth(1,10);//resizeColumnToContents (1); |
---|
[697] | 1511 | #endif |
---|
[695] | 1512 | } |
---|
| 1513 | |
---|
[697] | 1514 | |
---|
| 1515 | |
---|
| 1516 | |
---|
| 1517 | QMap<int,QString> G4UIQt::LookForHelpStringInChildTree( |
---|
[695] | 1518 | G4UIcommandTree *aCommandTree |
---|
[697] | 1519 | ,const QString & text |
---|
| 1520 | ) |
---|
[695] | 1521 | { |
---|
[697] | 1522 | QMap<int,QString> commandResultMap; |
---|
| 1523 | if (aCommandTree == NULL) return commandResultMap; |
---|
| 1524 | |
---|
[719] | 1525 | #if QT_VERSION < 0x040000 |
---|
| 1526 | int multFactor = 1000; // factor special for having double keys in Qt3 |
---|
| 1527 | int doubleKeyAdd = 0; // decay for doubleKeys in Qt3 |
---|
| 1528 | #endif |
---|
| 1529 | |
---|
[695] | 1530 | // Get the Sub directories |
---|
| 1531 | int tmp = 0; |
---|
[697] | 1532 | QMap<int,QString> commandChildResultMap; |
---|
| 1533 | |
---|
[695] | 1534 | for (int a=0;a<aCommandTree->GetTreeEntry();a++) { |
---|
| 1535 | const G4UIcommand* command = aCommandTree->GetGuidance(); |
---|
[719] | 1536 | #if QT_VERSION > 0x040000 |
---|
[695] | 1537 | tmp = GetCommandList (command).count(text,Qt::CaseInsensitive); |
---|
[719] | 1538 | #else |
---|
| 1539 | tmp = GetCommandList (command).contains(text,false); |
---|
| 1540 | #endif |
---|
[695] | 1541 | if (tmp >0) { |
---|
[719] | 1542 | #if QT_VERSION > 0x040000 |
---|
[697] | 1543 | commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data())); |
---|
[719] | 1544 | #else // tricky thing for Qt3... |
---|
| 1545 | doubleKeyAdd = 0; |
---|
| 1546 | while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) { |
---|
| 1547 | doubleKeyAdd ++; |
---|
| 1548 | } |
---|
| 1549 | commandResultMap.insert(tmp*multFactor+doubleKeyAdd,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data())); |
---|
| 1550 | #endif |
---|
[695] | 1551 | } |
---|
| 1552 | // look for childs |
---|
[697] | 1553 | commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text); |
---|
| 1554 | |
---|
| 1555 | if (!commandChildResultMap.empty()) { |
---|
| 1556 | // insert new childs |
---|
[719] | 1557 | #if QT_VERSION > 0x040000 |
---|
[697] | 1558 | QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin(); |
---|
| 1559 | while (i != commandChildResultMap.constEnd()) { |
---|
| 1560 | commandResultMap.insertMulti(i.key(),i.value()); |
---|
[719] | 1561 | #else // tricky thing for Qt3... |
---|
| 1562 | QMap<int,QString>::const_iterator i = commandChildResultMap.begin(); |
---|
| 1563 | while (i != commandChildResultMap.end()) { |
---|
| 1564 | doubleKeyAdd = 0; |
---|
| 1565 | while (commandResultMap.find( i.key()*multFactor+doubleKeyAdd) != commandResultMap.end()) { |
---|
| 1566 | doubleKeyAdd ++; |
---|
| 1567 | } |
---|
| 1568 | commandResultMap.insert(i.key()*multFactor+doubleKeyAdd,i.data()); |
---|
| 1569 | #endif |
---|
[697] | 1570 | i++; |
---|
| 1571 | } |
---|
| 1572 | commandChildResultMap.clear(); |
---|
| 1573 | } |
---|
[695] | 1574 | } |
---|
| 1575 | // Get the Commands |
---|
[697] | 1576 | |
---|
[695] | 1577 | for (int a=0;a<aCommandTree->GetCommandEntry();a++) { |
---|
| 1578 | const G4UIcommand* command = aCommandTree->GetCommand(a+1); |
---|
[719] | 1579 | #if QT_VERSION > 0x040000 |
---|
| 1580 | tmp = GetCommandList (command).count(text,Qt::CaseInsensitive); |
---|
| 1581 | #else |
---|
| 1582 | tmp = GetCommandList (command).contains(text,false); |
---|
[695] | 1583 | #endif |
---|
| 1584 | if (tmp >0) { |
---|
[719] | 1585 | #if QT_VERSION > 0x040000 |
---|
[697] | 1586 | commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data())); |
---|
[719] | 1587 | #else // tricky thing for Qt3... |
---|
| 1588 | doubleKeyAdd = 0; |
---|
| 1589 | while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) { |
---|
| 1590 | doubleKeyAdd ++; |
---|
| 1591 | } |
---|
| 1592 | commandResultMap.insert(tmp*multFactor+doubleKeyAdd,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data())); |
---|
| 1593 | #endif |
---|
[695] | 1594 | #ifdef GEANT4_QT_DEBUG |
---|
| 1595 | #endif |
---|
| 1596 | } |
---|
| 1597 | |
---|
| 1598 | } |
---|
[697] | 1599 | return commandResultMap; |
---|
[695] | 1600 | } |
---|
| 1601 | #endif |
---|