[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 | // |
---|
[688] | 27 | // $Id: G4UIQt.cc,v 1.14 2008/01/15 11:04:26 lgarnier Exp $ |
---|
[630] | 28 | // GEANT4 tag $Name: $ |
---|
[607] | 29 | // |
---|
| 30 | // L. Garnier |
---|
| 31 | |
---|
[695] | 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); |
---|
| 549 | #else |
---|
| 550 | helpLayout->addWidget(helpLine); |
---|
| 551 | #endif |
---|
[695] | 552 | connect( helpLine, SIGNAL( editingFinished () ), this, SLOT( lookForHelpStringCallback() ) ); |
---|
[607] | 553 | |
---|
| 554 | // the help tree |
---|
| 555 | #if QT_VERSION < 0x040000 |
---|
| 556 | fHelpTreeWidget = new QListView(splitter); |
---|
| 557 | #else |
---|
| 558 | fHelpTreeWidget = new QTreeWidget(); |
---|
| 559 | #endif |
---|
[697] | 560 | fHelpTreeWidget = CreateHelpTree(); |
---|
[607] | 561 | |
---|
| 562 | fHelpArea = new QTextEdit(splitter); |
---|
| 563 | fHelpArea->setReadOnly(true); |
---|
| 564 | |
---|
| 565 | // Set layouts |
---|
| 566 | |
---|
[617] | 567 | #if QT_VERSION >= 0x040000 |
---|
[697] | 568 | if (fHelpTreeWidget) |
---|
| 569 | splitter->addWidget(fHelpTreeWidget); |
---|
[607] | 570 | splitter->addWidget(fHelpArea); |
---|
| 571 | #endif |
---|
| 572 | |
---|
| 573 | |
---|
[619] | 574 | #if QT_VERSION >= 0x040000 |
---|
[697] | 575 | vLayout->addWidget(helpWidget); |
---|
| 576 | vLayout->addWidget(splitter,1); |
---|
[619] | 577 | vLayout->addWidget(exitButton); |
---|
[617] | 578 | #else |
---|
[697] | 579 | vLayout->addWidget(helpWidget); |
---|
| 580 | vLayout->add(splitter,1); |
---|
[619] | 581 | vLayout->addWidget(exitButton); |
---|
[617] | 582 | #endif |
---|
[619] | 583 | |
---|
| 584 | // set the splitter size |
---|
[607] | 585 | #if QT_VERSION >= 0x040000 |
---|
[619] | 586 | QList<int> list; |
---|
| 587 | #else |
---|
| 588 | QValueList<int> list; |
---|
| 589 | #endif |
---|
| 590 | list.append( 400 ); |
---|
| 591 | list.append( 400 ); |
---|
| 592 | splitter->setSizes(list); |
---|
| 593 | |
---|
| 594 | #if QT_VERSION >= 0x040000 |
---|
[607] | 595 | fHelpDialog->setLayout(vLayout); |
---|
| 596 | #endif |
---|
| 597 | |
---|
| 598 | } |
---|
| 599 | |
---|
[695] | 600 | ActivateCommand(newCommand); |
---|
| 601 | |
---|
| 602 | #if QT_VERSION < 0x040000 |
---|
| 603 | fHelpDialog->setCaption( tr( "Help on commands" )); |
---|
| 604 | #else |
---|
| 605 | fHelpDialog->setWindowTitle(tr("Help on commands")); |
---|
| 606 | #endif |
---|
| 607 | fHelpDialog->resize(800,600); |
---|
| 608 | fHelpDialog->move(QPoint(400,150)); |
---|
| 609 | fHelpDialog->show(); |
---|
| 610 | fHelpDialog->raise(); |
---|
| 611 | #if QT_VERSION < 0x040000 |
---|
| 612 | fHelpDialog->setActiveWindow(); |
---|
| 613 | #else |
---|
| 614 | fHelpDialog->activateWindow(); |
---|
| 615 | #endif |
---|
| 616 | } |
---|
| 617 | |
---|
[697] | 618 | |
---|
[695] | 619 | void G4UIQt::ActivateCommand( |
---|
| 620 | G4String newCommand |
---|
| 621 | ) |
---|
| 622 | { |
---|
[697] | 623 | if (!fHelpTreeWidget) { |
---|
| 624 | return; |
---|
| 625 | } |
---|
[607] | 626 | // Look for the choosen command "newCommand" |
---|
| 627 | size_t i = newCommand.index(" "); |
---|
| 628 | G4String targetCom=""; |
---|
| 629 | if( i != std::string::npos ) |
---|
| 630 | { |
---|
| 631 | G4String newValue = newCommand(i+1,newCommand.length()-(i+1)); |
---|
| 632 | newValue.strip(G4String::both); |
---|
| 633 | targetCom = ModifyToFullPathCommand( newValue ); |
---|
| 634 | } |
---|
| 635 | if (targetCom != "") { |
---|
| 636 | #if QT_VERSION < 0x040000 |
---|
| 637 | QListViewItem* findItem = NULL; |
---|
| 638 | QListViewItem* tmpItem = fHelpTreeWidget->firstChild(); |
---|
| 639 | while (tmpItem != 0) { |
---|
| 640 | if (!findItem) { |
---|
| 641 | findItem = FindTreeItem(tmpItem,QString((char*)targetCom.data())); |
---|
| 642 | } |
---|
| 643 | tmpItem = tmpItem->nextSibling(); |
---|
| 644 | } |
---|
| 645 | #else |
---|
| 646 | QTreeWidgetItem* findItem = NULL; |
---|
| 647 | for (int a=0;a<fHelpTreeWidget->topLevelItemCount();a++) { |
---|
| 648 | if (!findItem) { |
---|
| 649 | findItem = FindTreeItem(fHelpTreeWidget->topLevelItem(a),QString((char*)targetCom.data())); |
---|
| 650 | } |
---|
| 651 | } |
---|
| 652 | #endif |
---|
| 653 | |
---|
| 654 | if (findItem) { |
---|
| 655 | |
---|
| 656 | //collapsed open item |
---|
| 657 | #if QT_VERSION < 0x040000 |
---|
| 658 | |
---|
| 659 | // FIXME : Has to be checked |
---|
| 660 | QListViewItem* tmpItem = fHelpTreeWidget->firstChild(); |
---|
| 661 | QList<QListViewItem> openItems; |
---|
| 662 | while ((tmpItem != 0) || (!openItems.isEmpty())) { |
---|
| 663 | if (tmpItem->isOpen() ) { |
---|
| 664 | tmpItem->setOpen(false); |
---|
| 665 | openItems.append(tmpItem); |
---|
| 666 | tmpItem = tmpItem->firstChild(); |
---|
| 667 | } else { |
---|
| 668 | tmpItem = tmpItem->nextSibling(); |
---|
| 669 | } |
---|
| 670 | if (tmpItem == 0) { |
---|
| 671 | tmpItem = openItems.take(openItems.count()-1); |
---|
| 672 | } |
---|
| 673 | } |
---|
| 674 | #else |
---|
| 675 | QList<QTreeWidgetItem *> selected; |
---|
| 676 | |
---|
| 677 | selected = fHelpTreeWidget->selectedItems(); |
---|
| 678 | if ( selected.count() != 0 ) { |
---|
| 679 | QTreeWidgetItem * tmp =selected.at( 0 ); |
---|
| 680 | while ( tmp) { |
---|
| 681 | #if QT_VERSION < 0x040202 |
---|
| 682 | fHelpTreeWidget->setItemExpanded(tmp,false); |
---|
| 683 | #else |
---|
| 684 | tmp->setExpanded(false); |
---|
| 685 | #endif |
---|
| 686 | tmp = tmp->parent(); |
---|
| 687 | } |
---|
| 688 | } |
---|
| 689 | #endif |
---|
| 690 | |
---|
| 691 | // clear old selection |
---|
| 692 | fHelpTreeWidget->clearSelection(); |
---|
| 693 | |
---|
| 694 | // set new selection |
---|
| 695 | #if QT_VERSION >= 0x040000 |
---|
| 696 | #if QT_VERSION < 0x040202 |
---|
| 697 | fHelpTreeWidget->setItemSelected(findItem,true); |
---|
| 698 | #else |
---|
| 699 | findItem->setSelected(true); |
---|
| 700 | #endif |
---|
| 701 | #else |
---|
| 702 | findItem->setSelected(true); |
---|
| 703 | #endif |
---|
| 704 | |
---|
| 705 | // expand parent item |
---|
| 706 | while ( findItem) { |
---|
| 707 | #if QT_VERSION < 0x040000 |
---|
| 708 | findItem->setOpen(true); |
---|
| 709 | #else |
---|
| 710 | #if QT_VERSION < 0x040202 |
---|
| 711 | fHelpTreeWidget->setItemExpanded(findItem,true); |
---|
| 712 | #else |
---|
| 713 | findItem->setExpanded(true); |
---|
| 714 | #endif |
---|
| 715 | #endif |
---|
| 716 | findItem = findItem->parent(); |
---|
| 717 | } |
---|
| 718 | |
---|
| 719 | // Call the update of the right textArea |
---|
| 720 | HelpTreeClicCallback(); |
---|
| 721 | } |
---|
| 722 | } |
---|
| 723 | } |
---|
| 724 | |
---|
[697] | 725 | |
---|
| 726 | |
---|
| 727 | /** |
---|
| 728 | Create the help tree widget |
---|
| 729 | @param parent : parent of tree widget |
---|
| 730 | @return the widget containing the tree or NULL if it could not have beeen created |
---|
| 731 | */ |
---|
| 732 | |
---|
| 733 | #if QT_VERSION < 0x040000 |
---|
| 734 | QListView * G4UIQt::CreateHelpTree() |
---|
| 735 | #else |
---|
| 736 | QTreeWidget * G4UIQt::CreateHelpTree() |
---|
| 737 | #endif |
---|
| 738 | { |
---|
| 739 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
| 740 | if(UI==NULL) return NULL; |
---|
| 741 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
| 742 | |
---|
| 743 | |
---|
| 744 | // build widget |
---|
| 745 | #if QT_VERSION < 0x040000 |
---|
| 746 | fHelpTreeWidget->setSelectionMode(QListView::Single); |
---|
| 747 | fHelpTreeWidget->setRootIsDecorated(true); |
---|
| 748 | fHelpTreeWidget->addColumn("Command"); |
---|
| 749 | fHelpTreeWidget->addColumn("Description",0); |
---|
| 750 | // fHelpTreeWidget->setColumnWidth (1,0); |
---|
| 751 | fHelpTreeWidget->header()->setResizeEnabled(FALSE,1); |
---|
| 752 | // QList<QListViewItem *> items; |
---|
| 753 | #else |
---|
| 754 | fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection); |
---|
| 755 | fHelpTreeWidget->setColumnCount(2); |
---|
| 756 | fHelpTreeWidget->setColumnHidden(1,true); |
---|
| 757 | QStringList labels; |
---|
| 758 | labels << QString("Command") << QString("Description"); |
---|
| 759 | fHelpTreeWidget->setHeaderLabels(labels); |
---|
| 760 | // QList<QTreeWidgetItem *> items; |
---|
| 761 | #endif |
---|
| 762 | |
---|
| 763 | G4int treeSize = treeTop->GetTreeEntry(); |
---|
| 764 | #if QT_VERSION < 0x040000 |
---|
| 765 | QListViewItem * newItem; |
---|
| 766 | #else |
---|
| 767 | QTreeWidgetItem * newItem; |
---|
| 768 | #endif |
---|
| 769 | for (int a=0;a<treeSize;a++) { |
---|
| 770 | // Creating new item |
---|
| 771 | |
---|
| 772 | #if QT_VERSION < 0x040000 |
---|
| 773 | newItem = new QListViewItem(fHelpTreeWidget); |
---|
| 774 | newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace()); |
---|
| 775 | newItem->setText(1,QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).simplifyWhiteSpace()); |
---|
| 776 | #else |
---|
| 777 | newItem = new QTreeWidgetItem(fHelpTreeWidget); |
---|
| 778 | newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed()); |
---|
| 779 | newItem->setText(1,QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).trimmed()); |
---|
| 780 | #endif |
---|
| 781 | |
---|
| 782 | |
---|
| 783 | // look for childs |
---|
| 784 | CreateChildTree(newItem,treeTop->GetTree(a+1)); |
---|
| 785 | // items.append(newItem); |
---|
| 786 | } |
---|
| 787 | |
---|
| 788 | |
---|
| 789 | #if QT_VERSION < 0x040000 |
---|
| 790 | connect(fHelpTreeWidget, SIGNAL(selectionChanged ()),this, SLOT(HelpTreeClicCallback())); |
---|
| 791 | connect(fHelpTreeWidget, SIGNAL(doubleClicked (QListViewItem*)),this, SLOT(HelpTreeDoubleClicCallback())); |
---|
| 792 | #else |
---|
| 793 | connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback())); |
---|
| 794 | connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback())); |
---|
| 795 | #endif |
---|
| 796 | |
---|
| 797 | return fHelpTreeWidget; |
---|
| 798 | } |
---|
| 799 | |
---|
| 800 | |
---|
| 801 | |
---|
[607] | 802 | /** Fill the Help Tree Widget |
---|
| 803 | @param aParent : parent item to fill |
---|
| 804 | @param aCommandTree : commandTree node associate with this part of the Tree |
---|
| 805 | */ |
---|
| 806 | #if QT_VERSION < 0x040000 |
---|
| 807 | void G4UIQt::CreateChildTree( |
---|
| 808 | QListViewItem *aParent |
---|
| 809 | ,G4UIcommandTree *aCommandTree |
---|
| 810 | #else |
---|
| 811 | void G4UIQt::CreateChildTree( |
---|
| 812 | QTreeWidgetItem *aParent |
---|
| 813 | ,G4UIcommandTree *aCommandTree |
---|
| 814 | #endif |
---|
| 815 | ) |
---|
| 816 | { |
---|
| 817 | if (aParent == NULL) return; |
---|
| 818 | if (aCommandTree == NULL) return; |
---|
| 819 | |
---|
| 820 | |
---|
| 821 | // Creating new item |
---|
| 822 | #if QT_VERSION < 0x040000 |
---|
| 823 | QListViewItem * newItem; |
---|
| 824 | #else |
---|
| 825 | QTreeWidgetItem * newItem; |
---|
| 826 | #endif |
---|
| 827 | |
---|
| 828 | // Get the Sub directories |
---|
| 829 | for (int a=0;a<aCommandTree->GetTreeEntry();a++) { |
---|
| 830 | |
---|
| 831 | #if QT_VERSION < 0x040000 |
---|
| 832 | newItem = new QListViewItem(aParent); |
---|
| 833 | newItem->setText(0,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace()); |
---|
| 834 | newItem->setText(1,QString((char*)(aCommandTree->GetTree(a+1)->GetTitle()).data()).simplifyWhiteSpace()); |
---|
| 835 | |
---|
| 836 | #else |
---|
| 837 | newItem = new QTreeWidgetItem(aParent); |
---|
| 838 | newItem->setText(0,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed()); |
---|
| 839 | newItem->setText(1,QString((char*)(aCommandTree->GetTree(a+1)->GetTitle()).data()).trimmed()); |
---|
| 840 | #endif |
---|
| 841 | |
---|
| 842 | CreateChildTree(newItem,aCommandTree->GetTree(a+1)); |
---|
| 843 | } |
---|
| 844 | |
---|
| 845 | |
---|
| 846 | |
---|
| 847 | // Get the Commands |
---|
| 848 | |
---|
| 849 | for (int a=0;a<aCommandTree->GetCommandEntry();a++) { |
---|
| 850 | |
---|
| 851 | QStringList stringList; |
---|
| 852 | #if QT_VERSION < 0x040000 |
---|
| 853 | newItem = new QListViewItem(aParent); |
---|
| 854 | newItem->setText(0,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).simplifyWhiteSpace()); |
---|
| 855 | newItem->setText(1,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).simplifyWhiteSpace()); |
---|
| 856 | newItem->setOpen(false); |
---|
| 857 | |
---|
| 858 | #else |
---|
| 859 | newItem = new QTreeWidgetItem(aParent); |
---|
| 860 | newItem->setText(0,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed()); |
---|
| 861 | newItem->setText(1,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed()); |
---|
| 862 | #if QT_VERSION < 0x040202 |
---|
| 863 | fHelpTreeWidget->setItemExpanded(newItem,false); |
---|
| 864 | #else |
---|
| 865 | newItem->setExpanded(false); |
---|
| 866 | #endif |
---|
| 867 | #endif |
---|
| 868 | |
---|
| 869 | } |
---|
| 870 | } |
---|
| 871 | |
---|
| 872 | |
---|
| 873 | /** Find a treeItemWidget in the help tree |
---|
| 874 | @param aCommand item's String to look for |
---|
| 875 | @return item if found, NULL if not |
---|
| 876 | */ |
---|
| 877 | #if QT_VERSION < 0x040000 |
---|
| 878 | QListViewItem* G4UIQt::FindTreeItem( |
---|
| 879 | QListViewItem *aParent |
---|
| 880 | #else |
---|
| 881 | QTreeWidgetItem* G4UIQt::FindTreeItem( |
---|
| 882 | QTreeWidgetItem *aParent |
---|
| 883 | #endif |
---|
| 884 | ,const QString& aCommand |
---|
| 885 | ) |
---|
| 886 | { |
---|
| 887 | if (aParent == NULL) return NULL; |
---|
| 888 | |
---|
| 889 | if (aParent->text(0) == aCommand) |
---|
| 890 | return aParent; |
---|
| 891 | |
---|
| 892 | #if QT_VERSION < 0x040000 |
---|
| 893 | QListViewItem * tmp = NULL; |
---|
| 894 | QListViewItem* tmpItem = aParent->firstChild(); |
---|
| 895 | while (tmpItem != 0) { |
---|
| 896 | if (!tmp) |
---|
| 897 | tmp = FindTreeItem(tmpItem,aCommand); |
---|
| 898 | tmpItem = tmpItem->nextSibling(); |
---|
| 899 | } |
---|
| 900 | |
---|
| 901 | #else |
---|
| 902 | QTreeWidgetItem * tmp = NULL; |
---|
| 903 | for (int a=0;a<aParent->childCount();a++) { |
---|
| 904 | if (!tmp) |
---|
| 905 | tmp = FindTreeItem(aParent->child(a),aCommand); |
---|
| 906 | } |
---|
| 907 | #endif |
---|
| 908 | return tmp; |
---|
| 909 | } |
---|
| 910 | |
---|
| 911 | |
---|
| 912 | /** Build the command list parameters in a QString<br> |
---|
| 913 | Reimplement partialy the G4UIparameter.cc |
---|
| 914 | @param aCommand : command to list parameters |
---|
| 915 | @see G4UIparameter::List() |
---|
| 916 | @see G4UIcommand::List() |
---|
| 917 | @return the command list parameters, or "" if nothing |
---|
| 918 | */ |
---|
| 919 | QString G4UIQt::GetCommandList ( |
---|
| 920 | const G4UIcommand *aCommand |
---|
| 921 | ) |
---|
| 922 | { |
---|
| 923 | |
---|
| 924 | QString txt =""; |
---|
| 925 | if (aCommand == NULL) |
---|
| 926 | return txt; |
---|
| 927 | |
---|
| 928 | G4String commandPath = aCommand->GetCommandPath(); |
---|
| 929 | G4String rangeString = aCommand->GetRange(); |
---|
| 930 | G4int n_guidanceEntry = aCommand->GetGuidanceEntries(); |
---|
| 931 | G4int n_parameterEntry = aCommand->GetParameterEntries(); |
---|
| 932 | |
---|
| 933 | if ((commandPath == "") && |
---|
| 934 | (rangeString == "") && |
---|
| 935 | (n_guidanceEntry == 0) && |
---|
| 936 | (n_parameterEntry == 0)) { |
---|
| 937 | return txt; |
---|
| 938 | } |
---|
| 939 | |
---|
| 940 | if((commandPath.length()-1)!='/') { |
---|
| 941 | txt += "Command " + QString((char*)(commandPath).data()) + "\n"; |
---|
| 942 | } |
---|
| 943 | txt += "Guidance :\n"; |
---|
| 944 | |
---|
| 945 | for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) { |
---|
| 946 | txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n"; |
---|
| 947 | } |
---|
| 948 | if( ! rangeString.isNull() ) { |
---|
| 949 | txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n"; |
---|
| 950 | } |
---|
| 951 | if( n_parameterEntry > 0 ) { |
---|
| 952 | G4UIparameter *param; |
---|
| 953 | |
---|
| 954 | // Re-implementation of G4UIparameter.cc |
---|
| 955 | |
---|
| 956 | for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) { |
---|
| 957 | param = aCommand->GetParameter(i_thParameter); |
---|
| 958 | txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n"; |
---|
| 959 | if( ! param->GetParameterGuidance().isNull() ) |
---|
| 960 | txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ; |
---|
| 961 | txt += " Parameter type : " + QString(QChar(param->GetParameterType())) + "\n"; |
---|
| 962 | if(param->IsOmittable()){ |
---|
| 963 | txt += " Omittable : True\n"; |
---|
| 964 | } else { |
---|
| 965 | txt += " Omittable : False\n"; |
---|
| 966 | } |
---|
| 967 | if( param->GetCurrentAsDefault() ) { |
---|
| 968 | txt += " Default value : taken from the current value\n"; |
---|
| 969 | } else if( ! param->GetDefaultValue().isNull() ) { |
---|
| 970 | txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n"; |
---|
| 971 | } |
---|
| 972 | if( ! param->GetParameterRange().isNull() ) { |
---|
| 973 | txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n"; |
---|
| 974 | } |
---|
| 975 | if( ! param->GetParameterCandidates().isNull() ) { |
---|
| 976 | txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n"; |
---|
| 977 | } |
---|
| 978 | } |
---|
| 979 | } |
---|
| 980 | return txt; |
---|
| 981 | } |
---|
| 982 | |
---|
| 983 | |
---|
| 984 | |
---|
| 985 | /** Implement G4VBasicShell vurtual function |
---|
| 986 | */ |
---|
| 987 | G4bool G4UIQt::GetHelpChoice( |
---|
| 988 | G4int& aInt |
---|
| 989 | ) |
---|
| 990 | { |
---|
[608] | 991 | #ifdef GEANT4_QT_DEBUG |
---|
[607] | 992 | printf("G4UIQt::GetHelpChoice SHOULD NEVER GO HERE"); |
---|
[608] | 993 | #endif |
---|
[607] | 994 | return true; |
---|
| 995 | } |
---|
| 996 | |
---|
| 997 | |
---|
| 998 | /** Implement G4VBasicShell vurtual function |
---|
| 999 | */ |
---|
| 1000 | void G4UIQt::ExitHelp( |
---|
| 1001 | ) |
---|
| 1002 | { |
---|
[608] | 1003 | #ifdef GEANT4_QT_DEBUG |
---|
[607] | 1004 | printf("G4UIQt::ExitHelp SHOULD NEVER GO HERE"); |
---|
[608] | 1005 | #endif |
---|
[607] | 1006 | } |
---|
| 1007 | |
---|
| 1008 | |
---|
| 1009 | /** Event filter method. Every event from QtApplication goes here.<br/> |
---|
| 1010 | We apply a filter only for the Up and Down Arrow press when the QLineEdit<br/> |
---|
| 1011 | is active. If this filter match, Up arrow we give the previous command<br/> |
---|
| 1012 | and Down arrow will give the next if exist.<br/> |
---|
| 1013 | @param obj Emitter of the event |
---|
| 1014 | @param event Kind of event |
---|
| 1015 | */ |
---|
| 1016 | bool G4UIQt::eventFilter( // Should stay with a minuscule eventFilter because of Qt |
---|
| 1017 | QObject *aObj |
---|
| 1018 | ,QEvent *aEvent |
---|
| 1019 | ) |
---|
| 1020 | { |
---|
| 1021 | if (aObj == NULL) return false; |
---|
| 1022 | if (aEvent == NULL) return false; |
---|
| 1023 | |
---|
| 1024 | if (aObj == fCommandHistoryArea) { |
---|
| 1025 | if (aEvent->type() == QEvent::KeyPress) { |
---|
| 1026 | fCommandArea->setFocus(); |
---|
| 1027 | } |
---|
| 1028 | } |
---|
| 1029 | if (aObj == fCommandArea) { |
---|
| 1030 | if (aEvent->type() == QEvent::KeyPress) { |
---|
| 1031 | QKeyEvent *e = static_cast<QKeyEvent*>(aEvent); |
---|
| 1032 | if ((e->key() == (Qt::Key_Down)) || |
---|
| 1033 | (e->key() == (Qt::Key_PageDown)) || |
---|
| 1034 | (e->key() == (Qt::Key_Up)) || |
---|
| 1035 | (e->key() == (Qt::Key_PageUp))) { |
---|
| 1036 | #if QT_VERSION < 0x040000 |
---|
| 1037 | // count rows... |
---|
| 1038 | QListViewItem* tmpItem = fCommandHistoryArea->firstChild(); |
---|
| 1039 | int selection = -1; |
---|
| 1040 | int index = 0; |
---|
| 1041 | while (tmpItem != 0) { |
---|
| 1042 | if (tmpItem == fCommandHistoryArea->selectedItem()) { |
---|
| 1043 | selection = index; |
---|
| 1044 | } |
---|
| 1045 | index ++; |
---|
| 1046 | tmpItem = tmpItem->nextSibling(); |
---|
| 1047 | } |
---|
| 1048 | if (fCommandHistoryArea->childCount()) { |
---|
| 1049 | if (selection == -1) { |
---|
| 1050 | selection = fCommandHistoryArea->childCount()-1; |
---|
| 1051 | } else { |
---|
| 1052 | if (e->key() == (Qt::Key_Down)) { |
---|
| 1053 | if (selection <(fCommandHistoryArea->childCount()-1)) |
---|
| 1054 | selection++; |
---|
| 1055 | } else if (e->key() == (Qt::Key_PageDown)) { |
---|
| 1056 | selection = fCommandHistoryArea->childCount()-1; |
---|
| 1057 | #else |
---|
| 1058 | int selection = fCommandHistoryArea->currentRow(); |
---|
| 1059 | if (fCommandHistoryArea->count()) { |
---|
| 1060 | if (selection == -1) { |
---|
| 1061 | selection = fCommandHistoryArea->count()-1; |
---|
| 1062 | } else { |
---|
| 1063 | if (e->key() == (Qt::Key_Down)) { |
---|
| 1064 | if (selection <(fCommandHistoryArea->count()-1)) |
---|
| 1065 | selection++; |
---|
| 1066 | } else if (e->key() == (Qt::Key_PageDown)) { |
---|
| 1067 | selection = fCommandHistoryArea->count()-1; |
---|
| 1068 | #endif |
---|
| 1069 | } else if (e->key() == (Qt::Key_Up)) { |
---|
| 1070 | if (selection >0) |
---|
| 1071 | selection --; |
---|
| 1072 | } else if (e->key() == (Qt::Key_PageUp)) { |
---|
| 1073 | selection = 0; |
---|
| 1074 | } |
---|
| 1075 | } |
---|
| 1076 | fCommandHistoryArea->clearSelection(); |
---|
| 1077 | #if QT_VERSION < 0x040000 |
---|
| 1078 | QListViewItem* tmpItem = fCommandHistoryArea->firstChild(); |
---|
| 1079 | int index = 0; |
---|
| 1080 | while (tmpItem != 0) { |
---|
| 1081 | if (index == selection) { |
---|
| 1082 | tmpItem->setSelected(true); |
---|
| 1083 | fCommandHistoryArea->setCurrentItem(tmpItem); |
---|
| 1084 | } |
---|
| 1085 | index ++; |
---|
| 1086 | tmpItem = tmpItem->nextSibling(); |
---|
| 1087 | } |
---|
| 1088 | #else |
---|
| 1089 | #if QT_VERSION < 0x040202 |
---|
| 1090 | fCommandHistoryArea->setItemSelected(fCommandHistoryArea->item(selection),true); |
---|
| 1091 | #else |
---|
| 1092 | fCommandHistoryArea->item(selection)->setSelected(true); |
---|
| 1093 | #endif |
---|
| 1094 | fCommandHistoryArea->setCurrentItem(fCommandHistoryArea->item(selection)); |
---|
| 1095 | #endif |
---|
| 1096 | } |
---|
| 1097 | } else if (e->key() == (Qt::Key_Tab)) { |
---|
| 1098 | #if QT_VERSION < 0x040000 |
---|
| 1099 | G4String ss = Complete(fCommandArea->text().ascii()); |
---|
| 1100 | #else |
---|
| 1101 | G4String ss = Complete(fCommandArea->text().toStdString().c_str()); |
---|
| 1102 | #endif |
---|
| 1103 | fCommandArea->setText((char*)(ss.data())); |
---|
| 1104 | |
---|
| 1105 | // do not pass by parent, it will disable widget tab focus ! |
---|
| 1106 | return true; |
---|
| 1107 | } |
---|
| 1108 | } |
---|
| 1109 | } |
---|
| 1110 | // pass the event on to the parent class |
---|
| 1111 | return QObject::eventFilter(aObj, aEvent); |
---|
| 1112 | } |
---|
| 1113 | |
---|
| 1114 | |
---|
| 1115 | |
---|
| 1116 | |
---|
| 1117 | /***************************************************************************/ |
---|
| 1118 | // |
---|
| 1119 | // SLOTS DEFINITIONS |
---|
| 1120 | // |
---|
| 1121 | /***************************************************************************/ |
---|
| 1122 | |
---|
| 1123 | /** Called when user give "help" command. |
---|
| 1124 | */ |
---|
| 1125 | void G4UIQt::ShowHelpCallback ( |
---|
| 1126 | ) |
---|
| 1127 | { |
---|
| 1128 | TerminalHelp(""); |
---|
| 1129 | } |
---|
| 1130 | |
---|
| 1131 | |
---|
| 1132 | /** Called when user click on clear button. Clear the text Output area |
---|
| 1133 | */ |
---|
| 1134 | void G4UIQt::ClearButtonCallback ( |
---|
| 1135 | ) |
---|
| 1136 | { |
---|
| 1137 | fTextArea->clear(); |
---|
| 1138 | } |
---|
| 1139 | |
---|
[608] | 1140 | /** Called when user exit session |
---|
| 1141 | */ |
---|
| 1142 | void G4UIQt::ExitSession ( |
---|
| 1143 | ) |
---|
| 1144 | { |
---|
| 1145 | SessionTerminate(); |
---|
| 1146 | } |
---|
[607] | 1147 | |
---|
[608] | 1148 | |
---|
[607] | 1149 | /** Callback call when "click on a menu entry.<br> |
---|
| 1150 | Send the associated command to geant4 |
---|
| 1151 | */ |
---|
| 1152 | void G4UIQt::CommandEnteredCallback ( |
---|
| 1153 | ) |
---|
| 1154 | { |
---|
| 1155 | #if QT_VERSION < 0x040000 |
---|
| 1156 | G4String command (fCommandArea->text().ascii()); |
---|
| 1157 | if (fCommandArea->text().simplifyWhiteSpace() != "") { |
---|
| 1158 | |
---|
| 1159 | QListViewItem *newItem = new QListViewItem(fCommandHistoryArea); |
---|
| 1160 | newItem->setText(0,fCommandArea->text()); |
---|
[619] | 1161 | fCommandHistoryArea->insertItem(newItem); |
---|
[620] | 1162 | // now we have to arrange |
---|
| 1163 | QListViewItem *temp= fCommandHistoryArea->lastItem(); |
---|
| 1164 | for (int i=0; i<fCommandHistoryArea->childCount()-1;i++) { |
---|
| 1165 | fCommandHistoryArea->takeItem(temp); |
---|
| 1166 | fCommandHistoryArea->insertItem(temp); |
---|
| 1167 | temp= fCommandHistoryArea->lastItem(); |
---|
| 1168 | } |
---|
[607] | 1169 | #else |
---|
| 1170 | G4String command (fCommandArea->text().toStdString().c_str()); |
---|
| 1171 | if (fCommandArea->text().trimmed() != "") { |
---|
| 1172 | fCommandHistoryArea->addItem(fCommandArea->text()); |
---|
| 1173 | #endif |
---|
| 1174 | fCommandHistoryArea->clearSelection(); |
---|
| 1175 | fCommandHistoryArea->setCurrentItem(NULL); |
---|
| 1176 | fCommandArea->setText(""); |
---|
| 1177 | |
---|
| 1178 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
| 1179 | if (interactorManager) { |
---|
| 1180 | interactorManager->FlushAndWaitExecution(); |
---|
| 1181 | } |
---|
| 1182 | if (command(0,4) != "help") { |
---|
| 1183 | ApplyShellCommand (command,exitSession,exitPause); |
---|
| 1184 | } else { |
---|
| 1185 | TerminalHelp(command); |
---|
| 1186 | } |
---|
| 1187 | if(exitSession==true) |
---|
| 1188 | SessionTerminate(); |
---|
| 1189 | } |
---|
| 1190 | } |
---|
| 1191 | |
---|
| 1192 | |
---|
| 1193 | /** Callback call when "enter" clicked on the command zone.<br> |
---|
| 1194 | Send the command to geant4 |
---|
| 1195 | @param aCommand |
---|
| 1196 | */ |
---|
| 1197 | void G4UIQt::ButtonCallback ( |
---|
| 1198 | const QString& aCommand |
---|
| 1199 | ) |
---|
| 1200 | { |
---|
| 1201 | #if QT_VERSION < 0x040000 |
---|
| 1202 | G4String ss = G4String(aCommand.ascii()); |
---|
| 1203 | #else |
---|
| 1204 | G4String ss = G4String(aCommand.toStdString().c_str()); |
---|
| 1205 | #endif |
---|
| 1206 | ApplyShellCommand(ss,exitSession,exitPause); |
---|
| 1207 | if(exitSession==true) |
---|
| 1208 | SessionTerminate(); |
---|
| 1209 | } |
---|
| 1210 | |
---|
| 1211 | |
---|
| 1212 | |
---|
| 1213 | /** This callback is activated when user selected a item in the help tree |
---|
| 1214 | */ |
---|
| 1215 | void G4UIQt::HelpTreeClicCallback ( |
---|
| 1216 | ) |
---|
| 1217 | { |
---|
| 1218 | #if QT_VERSION < 0x040000 |
---|
| 1219 | QListViewItem* item = NULL; |
---|
| 1220 | #else |
---|
| 1221 | QTreeWidgetItem* item = NULL; |
---|
| 1222 | #endif |
---|
| 1223 | if (!fHelpTreeWidget) |
---|
| 1224 | return ; |
---|
| 1225 | |
---|
| 1226 | if (!fHelpArea) |
---|
| 1227 | return; |
---|
| 1228 | |
---|
| 1229 | #if QT_VERSION < 0x040000 |
---|
| 1230 | item =fHelpTreeWidget->selectedItem(); |
---|
| 1231 | #else |
---|
| 1232 | QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems(); |
---|
| 1233 | if (list.isEmpty()) |
---|
| 1234 | return; |
---|
| 1235 | item = list.first(); |
---|
| 1236 | #endif |
---|
| 1237 | if (!item) |
---|
| 1238 | return; |
---|
| 1239 | |
---|
| 1240 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
| 1241 | if(UI==NULL) return; |
---|
| 1242 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
[699] | 1243 | |
---|
| 1244 | |
---|
| 1245 | |
---|
| 1246 | std::string itemText; |
---|
[607] | 1247 | #if QT_VERSION < 0x040000 |
---|
[699] | 1248 | itemText = std::string(item->text(0).ascii()); |
---|
[607] | 1249 | #else |
---|
[699] | 1250 | itemText = std::string(item->text(0).toStdString()); |
---|
[607] | 1251 | #endif |
---|
[699] | 1252 | |
---|
| 1253 | G4UIcommand* command = treeTop->FindPath(itemText.c_str()); |
---|
| 1254 | |
---|
[607] | 1255 | if (command) { |
---|
| 1256 | #if QT_VERSION >= 0x040000 |
---|
| 1257 | #if QT_VERSION < 0x040200 |
---|
| 1258 | fHelpArea->clear(); |
---|
| 1259 | fHelpArea->append(GetCommandList(command)); |
---|
| 1260 | #else |
---|
| 1261 | fHelpArea->setText(GetCommandList(command)); |
---|
| 1262 | #endif |
---|
| 1263 | #else |
---|
| 1264 | fHelpArea->setText(GetCommandList(command)); |
---|
| 1265 | #endif |
---|
[699] | 1266 | } else { // this is a command |
---|
| 1267 | G4UIcommandTree* path = treeTop->FindCommandTree(itemText.c_str()); |
---|
| 1268 | if ( path) { |
---|
| 1269 | // this is not a command, this is a sub directory |
---|
| 1270 | // We display the Title |
---|
[607] | 1271 | #if QT_VERSION >= 0x040000 |
---|
| 1272 | #if QT_VERSION < 0x040200 |
---|
[699] | 1273 | fHelpArea->clear(); |
---|
| 1274 | fHelpArea->append(path->GetTitle().data()); |
---|
[607] | 1275 | #else |
---|
[699] | 1276 | fHelpArea->setText(path->GetTitle().data()); |
---|
[607] | 1277 | #endif |
---|
| 1278 | #else |
---|
[699] | 1279 | fHelpArea->setText(path->GetTitle().data()); |
---|
[607] | 1280 | #endif |
---|
[699] | 1281 | } |
---|
[607] | 1282 | } |
---|
| 1283 | } |
---|
[699] | 1284 | |
---|
[607] | 1285 | /** This callback is activated when user double clic on a item in the help tree |
---|
| 1286 | */ |
---|
| 1287 | void G4UIQt::HelpTreeDoubleClicCallback ( |
---|
[648] | 1288 | ) |
---|
| 1289 | { |
---|
| 1290 | HelpTreeClicCallback(); |
---|
| 1291 | |
---|
[607] | 1292 | #if QT_VERSION < 0x040000 |
---|
[648] | 1293 | QListViewItem* item = NULL; |
---|
[607] | 1294 | #else |
---|
[648] | 1295 | QTreeWidgetItem* item = NULL; |
---|
[607] | 1296 | #endif |
---|
[648] | 1297 | if (!fHelpTreeWidget) |
---|
| 1298 | return ; |
---|
| 1299 | |
---|
| 1300 | if (!fHelpArea) |
---|
| 1301 | return; |
---|
| 1302 | |
---|
| 1303 | #if QT_VERSION < 0x040000 |
---|
| 1304 | item =fHelpTreeWidget->selectedItem(); |
---|
| 1305 | #else |
---|
| 1306 | QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems(); |
---|
| 1307 | if (list.isEmpty()) |
---|
| 1308 | return; |
---|
| 1309 | item = list.first(); |
---|
| 1310 | #endif |
---|
| 1311 | if (!item) |
---|
| 1312 | return; |
---|
| 1313 | |
---|
[683] | 1314 | fCommandArea->clear(); |
---|
| 1315 | fCommandArea->setText(item->text(1)); |
---|
[607] | 1316 | } |
---|
| 1317 | |
---|
| 1318 | |
---|
| 1319 | /** Callback called when user select an old command in the command history<br> |
---|
| 1320 | Give it to the command area. |
---|
| 1321 | */ |
---|
| 1322 | void G4UIQt::CommandHistoryCallback( |
---|
| 1323 | ) |
---|
| 1324 | { |
---|
| 1325 | #if QT_VERSION < 0x040000 |
---|
| 1326 | QListViewItem* item = NULL; |
---|
| 1327 | #else |
---|
| 1328 | QListWidgetItem* item = NULL; |
---|
| 1329 | #endif |
---|
| 1330 | if (!fCommandHistoryArea) |
---|
| 1331 | return ; |
---|
[632] | 1332 | |
---|
[607] | 1333 | |
---|
| 1334 | #if QT_VERSION < 0x040000 |
---|
[620] | 1335 | item =fCommandHistoryArea->selectedItem(); |
---|
[607] | 1336 | #else |
---|
| 1337 | QList<QListWidgetItem *> list =fCommandHistoryArea->selectedItems(); |
---|
| 1338 | if (list.isEmpty()) |
---|
| 1339 | return; |
---|
| 1340 | item = list.first(); |
---|
| 1341 | #endif |
---|
| 1342 | if (!item) |
---|
| 1343 | return; |
---|
| 1344 | #if QT_VERSION < 0x040000 |
---|
| 1345 | fCommandArea->setText(item->text(0)); |
---|
| 1346 | #else |
---|
| 1347 | fCommandArea->setText(item->text()); |
---|
| 1348 | #endif |
---|
| 1349 | |
---|
| 1350 | } |
---|
| 1351 | |
---|
[697] | 1352 | |
---|
[695] | 1353 | /** Callback called when user give a new string to look for<br> |
---|
[697] | 1354 | Display a list of matching commands descriptions. If no string is set, |
---|
| 1355 | will display the complete help tree |
---|
[695] | 1356 | */ |
---|
| 1357 | void G4UIQt::lookForHelpStringCallback( |
---|
| 1358 | ) |
---|
| 1359 | { |
---|
[698] | 1360 | #if QT_VERSION < 0x040200 |
---|
| 1361 | fHelpArea->clear(); |
---|
| 1362 | #else |
---|
| 1363 | fHelpArea->setText(""); |
---|
| 1364 | #endif |
---|
[697] | 1365 | if (helpLine->text() =="") { |
---|
| 1366 | // clear old help tree |
---|
| 1367 | fHelpTreeWidget->clear(); |
---|
| 1368 | CreateHelpTree(); |
---|
| 1369 | return; |
---|
| 1370 | } |
---|
| 1371 | |
---|
[695] | 1372 | // the help tree |
---|
| 1373 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
| 1374 | if(UI==NULL) return; |
---|
| 1375 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
| 1376 | |
---|
| 1377 | G4int treeSize = treeTop->GetTreeEntry(); |
---|
[697] | 1378 | |
---|
| 1379 | // clear old help tree |
---|
| 1380 | fHelpTreeWidget->clear(); |
---|
| 1381 | |
---|
| 1382 | // look for new items |
---|
| 1383 | |
---|
[695] | 1384 | int tmp = 0; |
---|
[697] | 1385 | QMap<int,QString> commandResultMap; |
---|
| 1386 | QMap<int,QString> commandChildResultMap; |
---|
| 1387 | |
---|
[695] | 1388 | for (int a=0;a<treeSize;a++) { |
---|
| 1389 | #ifdef GEANT4_QT_DEBUG |
---|
| 1390 | printf("Command %s\n",(char*)(treeTop->GetTree(a+1)->GetPathName()).data()); |
---|
| 1391 | #endif |
---|
| 1392 | G4UIcommand* command = treeTop->FindPath(treeTop->GetTree(a+1)->GetPathName().data()); |
---|
| 1393 | tmp = GetCommandList (command).count(helpLine->text(),Qt::CaseInsensitive); |
---|
| 1394 | if (tmp >0) { |
---|
[697] | 1395 | commandResultMap.insertMulti(tmp,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data())); |
---|
[695] | 1396 | #ifdef GEANT4_QT_DEBUG |
---|
| 1397 | printf("Command %s match %d times \n",(char*)(treeTop->GetTree(a+1)->GetPathName()).data(),tmp); |
---|
| 1398 | #endif |
---|
| 1399 | } |
---|
| 1400 | // look for childs |
---|
[697] | 1401 | commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a+1),helpLine->text()); |
---|
| 1402 | // insert new childs |
---|
| 1403 | if (!commandChildResultMap.empty()) { |
---|
| 1404 | QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin(); |
---|
| 1405 | while (i != commandChildResultMap.constEnd()) { |
---|
| 1406 | commandResultMap.insertMulti(i.key(),i.value()); |
---|
| 1407 | i++; |
---|
| 1408 | } |
---|
| 1409 | commandChildResultMap.clear(); |
---|
| 1410 | } |
---|
[695] | 1411 | } |
---|
[697] | 1412 | |
---|
| 1413 | // build new help tree |
---|
| 1414 | #if QT_VERSION < 0x040000 |
---|
| 1415 | fHelpTreeWidget->setSelectionMode(QListView::Single); |
---|
| 1416 | fHelpTreeWidget->setRootIsDecorated(true); |
---|
| 1417 | fHelpTreeWidget->addColumn("Command"); |
---|
| 1418 | fHelpTreeWidget->addColumn("Description",0); |
---|
| 1419 | fHelpTreeWidget->addColumn("Match"); |
---|
| 1420 | // fHelpTreeWidget->header()->setResizeEnabled(FALSE,1); |
---|
| 1421 | #else |
---|
| 1422 | fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection); |
---|
| 1423 | fHelpTreeWidget->setColumnCount(3); |
---|
| 1424 | fHelpTreeWidget->setColumnHidden(1,true); |
---|
| 1425 | QStringList labels; |
---|
| 1426 | labels << QString("Command") << QString("Description") << QString("Match"); |
---|
| 1427 | fHelpTreeWidget->setHeaderLabels(labels); |
---|
| 1428 | #endif |
---|
| 1429 | |
---|
| 1430 | if (commandResultMap.empty()) { |
---|
| 1431 | #if QT_VERSION < 0x040200 |
---|
| 1432 | fHelpArea->clear(); |
---|
| 1433 | fHelpArea->append("No match found"); |
---|
| 1434 | #else |
---|
| 1435 | fHelpArea->setText("No match found"); |
---|
| 1436 | #endif |
---|
| 1437 | return; |
---|
| 1438 | } |
---|
| 1439 | |
---|
| 1440 | QMap<int,QString>::const_iterator i = commandResultMap.constEnd(); |
---|
| 1441 | i--; |
---|
| 1442 | // 10 maximum progress values |
---|
| 1443 | float multValue = 10.0/(float)(i.key()); |
---|
| 1444 | QString progressChar = "|"; |
---|
| 1445 | QString progressStr = "|"; |
---|
| 1446 | |
---|
| 1447 | #if QT_VERSION < 0x040000 |
---|
| 1448 | QListViewItem * newItem; |
---|
| 1449 | #else |
---|
| 1450 | QTreeWidgetItem * newItem; |
---|
| 1451 | #endif |
---|
| 1452 | bool end = false; |
---|
| 1453 | while (!end) { |
---|
| 1454 | if (i == commandResultMap.constBegin()) { |
---|
| 1455 | end = true; |
---|
| 1456 | } |
---|
| 1457 | for(int a=0;a<int(i.key()*multValue);a++) { |
---|
| 1458 | progressStr += progressChar; |
---|
| 1459 | } |
---|
| 1460 | #if QT_VERSION < 0x040000 |
---|
| 1461 | newItem = new QListViewItem(fHelpTreeWidget); |
---|
| 1462 | newItem->setText(0,i.value().simplifyWhiteSpace()); |
---|
| 1463 | newItem->setText(1,i.value().simplifyWhiteSpace()); |
---|
| 1464 | |
---|
| 1465 | newItem->setText(2,progressStr); |
---|
| 1466 | #else |
---|
| 1467 | newItem = new QTreeWidgetItem(fHelpTreeWidget); |
---|
| 1468 | newItem->setText(0,i.value().trimmed()); |
---|
| 1469 | newItem->setText(1,i.value().trimmed()); |
---|
| 1470 | newItem->setText(2,progressStr); |
---|
| 1471 | #endif |
---|
| 1472 | |
---|
| 1473 | #if QT_VERSION >= 0x040200 |
---|
| 1474 | newItem->setForeground ( 2, QBrush(Qt::blue) ); |
---|
| 1475 | #endif |
---|
| 1476 | progressStr = "|"; |
---|
| 1477 | i--; |
---|
| 1478 | } |
---|
| 1479 | // FIXME : to be checked on Qt3 |
---|
| 1480 | #if QT_VERSION < 0x040000 |
---|
| 1481 | fHelpTreeWidget->setColumnWidthMode (0,QListView::Maximum); |
---|
| 1482 | #else |
---|
| 1483 | fHelpTreeWidget->resizeColumnToContents (0); |
---|
| 1484 | #endif |
---|
[695] | 1485 | } |
---|
| 1486 | |
---|
[697] | 1487 | |
---|
| 1488 | |
---|
| 1489 | |
---|
| 1490 | QMap<int,QString> G4UIQt::LookForHelpStringInChildTree( |
---|
[695] | 1491 | G4UIcommandTree *aCommandTree |
---|
[697] | 1492 | ,const QString & text |
---|
| 1493 | ) |
---|
[695] | 1494 | { |
---|
[697] | 1495 | QMap<int,QString> commandResultMap; |
---|
| 1496 | if (aCommandTree == NULL) return commandResultMap; |
---|
| 1497 | |
---|
[695] | 1498 | // Get the Sub directories |
---|
| 1499 | int tmp = 0; |
---|
[697] | 1500 | QMap<int,QString> commandChildResultMap; |
---|
| 1501 | |
---|
[695] | 1502 | for (int a=0;a<aCommandTree->GetTreeEntry();a++) { |
---|
| 1503 | const G4UIcommand* command = aCommandTree->GetGuidance(); |
---|
| 1504 | #ifdef GEANT4_QT_DEBUG |
---|
[697] | 1505 | printf("Command loop \n"); |
---|
[695] | 1506 | // printf("Command %s\n",(char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()); |
---|
| 1507 | // printf("%s \n",GetCommandList (command).toStdString().c_str()); |
---|
| 1508 | #endif |
---|
| 1509 | tmp = GetCommandList (command).count(text,Qt::CaseInsensitive); |
---|
| 1510 | if (tmp >0) { |
---|
[697] | 1511 | commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data())); |
---|
[695] | 1512 | #ifdef GEANT4_QT_DEBUG |
---|
| 1513 | printf("---Command %s match %d times \n",(char*)(aCommandTree->GetTree(a+1)->GetPathName()).data(),tmp); |
---|
| 1514 | #endif |
---|
| 1515 | } |
---|
| 1516 | // look for childs |
---|
[697] | 1517 | commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text); |
---|
| 1518 | |
---|
| 1519 | if (!commandChildResultMap.empty()) { |
---|
| 1520 | // insert new childs |
---|
| 1521 | QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin(); |
---|
| 1522 | while (i != commandChildResultMap.constEnd()) { |
---|
| 1523 | commandResultMap.insertMulti(i.key(),i.value()); |
---|
| 1524 | i++; |
---|
| 1525 | } |
---|
| 1526 | commandChildResultMap.clear(); |
---|
| 1527 | } |
---|
[695] | 1528 | } |
---|
| 1529 | // Get the Commands |
---|
[697] | 1530 | |
---|
[695] | 1531 | for (int a=0;a<aCommandTree->GetCommandEntry();a++) { |
---|
| 1532 | const G4UIcommand* command = aCommandTree->GetCommand(a+1); |
---|
| 1533 | #ifdef GEANT4_QT_DEBUG |
---|
[697] | 1534 | printf("Command Finale debut\n"); |
---|
[695] | 1535 | // printf("%s \n",GetCommandList (command).toStdString().c_str()); |
---|
| 1536 | #endif |
---|
| 1537 | tmp = GetCommandList (command).count(text,Qt::CaseInsensitive); |
---|
| 1538 | if (tmp >0) { |
---|
[697] | 1539 | commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data())); |
---|
[695] | 1540 | #ifdef GEANT4_QT_DEBUG |
---|
| 1541 | printf("---Command Finale %s match %d times \n",(char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data(),tmp); |
---|
| 1542 | #endif |
---|
| 1543 | } |
---|
| 1544 | |
---|
| 1545 | } |
---|
[697] | 1546 | return commandResultMap; |
---|
[695] | 1547 | } |
---|
| 1548 | #endif |
---|