Changeset 604
- Timestamp:
- Nov 15, 2007, 11:55:51 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/geant4/interfaces/basic/src/G4UIQt.cc
r603 r604 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 // 27 // $Id: G4UIQt.cc,v 1.4 2007/11/09 15:03:21 lgarnier Exp $ 28 // GEANT4 tag $Name: $ 29 // 30 // L. Garnier 1 /**************************************************************************** 2 ** Meta object code from reading C++ file 'G4UIQt.hh' 3 ** 4 ** Created: Mon Oct 1 10:59:35 2007 5 ** by: The Qt Meta Object Compiler version 59 (Qt 4.2.2) 6 ** 7 ** WARNING! All changes made in this file will be lost! 8 *****************************************************************************/ 31 9 32 //#define DEBUG 10 #if QT_VERSION >= 0x040202 33 11 34 12 #ifdef G4UI_BUILD_QT_SESSION 35 13 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 <qmainwindow.h> 50 #include <qlineedit.h> 51 #include <qwidget.h> 52 #include <qmenubar.h> 53 #include <qlayout.h> 54 #include <qpushbutton.h> 55 #include <qlabel.h> 56 #include <qsplitter.h> 57 #include <qscrollbar.h> 58 #include <qdialog.h> 59 #include <qevent.h> 60 #include <qtextedit.h> 61 #include <qsignalmapper.h> 62 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> 14 #include "../include/G4UIQt.hh" 15 #if !defined(Q_MOC_OUTPUT_REVISION) 16 #error "The header file 'G4UIQt.hh' doesn't include <QObject>." 17 #elif Q_MOC_OUTPUT_REVISION != 59 18 #error "This file was generated using the moc from 4.2.2. It" 19 #error "cannot be used with the include files from this version of Qt." 20 #error "(The moc has changed too much.)" 72 21 #endif 73 22 23 static const uint qt_meta_data_G4UIQt[] = { 74 24 25 // content: 26 1, // revision 27 0, // classname 28 0, 0, // classinfo 29 8, 10, // methods 30 0, 0, // properties 31 0, 0, // enums/sets 75 32 76 #include <stdlib.h> 33 // signals: signature, parameters, type, tag, flags 34 7, 26, 31, 31, 0x05, 77 35 78 // Pourquoi Static et non variables de classe ? 79 static G4bool exitSession = true; 80 static G4bool exitPause = true; 36 // slots: signature, parameters, type, tag, flags 37 32, 31, 31, 31, 0x08, 38 54, 31, 31, 31, 0x08, 39 79, 31, 31, 31, 0x08, 40 103, 31, 31, 31, 0x08, 41 126, 175, 31, 31, 0x08, 42 177, 31, 31, 31, 0x08, 43 196, 31, 31, 31, 0x08, 81 44 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) 45 0 // eod 46 }; 47 48 static const char qt_meta_stringdata_G4UIQt[] = { 49 "G4UIQt\0myClicked(QString)\0text\0\0" 50 "ClearButtonCallback()\0CommandEnteredCallback()\0" 51 "ButtonCallback(QString)\0HelpTreeClicCallback()\0" 52 "HelpTreeDoubleClicCallback(QTreeWidgetItem*,int)\0" 53 ",\0ShowHelpCallback()\0CommandHistoryCallback()\0" 54 }; 55 56 const QMetaObject G4UIQt::staticMetaObject = { 57 { &QObject::staticMetaObject, qt_meta_stringdata_G4UIQt, 58 qt_meta_data_G4UIQt, 0 } 59 }; 60 61 const QMetaObject *G4UIQt::metaObject() const 107 62 { 108 G4Qt* interactorManager = G4Qt::getInstance (); 109 G4UImanager* UI = G4UImanager::GetUIpointer(); 110 if(UI!=NULL) UI->SetSession(this); 111 112 fMainWindow = new QMainWindow(); 113 #if QT_VERSION < 0x040000 114 fMainWindow->setCaption( tr( "G4UI Session" )); 115 #else 116 fMainWindow->setWindowTitle( tr("G4UI Session") ); 117 #endif 118 fMainWindow->resize(800,600); 119 fMainWindow->move(QPoint(50,100)); 120 121 QSplitter *splitter = new QSplitter(Qt::Vertical); 122 fTextArea = new QTextEdit(); 123 QPushButton *clearButton = new QPushButton("clear",fMainWindow); 124 connect(clearButton, SIGNAL(clicked()), SLOT(ClearButtonCallback())); 125 126 #if QT_VERSION < 0x040000 127 fCommandHistoryArea = new QListView(); 128 fCommandHistoryArea->setSelectionMode(QListView::Single); 129 #else 130 fCommandHistoryArea = new QListWidget(); 131 fCommandHistoryArea->setSelectionMode(QAbstractItemView::SingleSelection); 132 #endif 133 connect(fCommandHistoryArea, SIGNAL(itemSelectionChanged()), SLOT(CommandHistoryCallback())); 134 fCommandHistoryArea->installEventFilter(this); 135 fCommandLabel = new QLabel("",fMainWindow); 136 137 fCommandArea = new QLineEdit(fMainWindow); 138 fCommandArea->installEventFilter(this); 139 #if QT_VERSION < 0x040000 140 fCommandArea->setActiveWindow(); 141 #else 142 fCommandArea->activateWindow(); 143 #endif 144 connect(fCommandArea, SIGNAL(returnPressed()), SLOT(CommandEnteredCallback())); 145 #if QT_VERSION < 0x040000 146 fCommandArea->setFocusPolicy ( QWidget::StrongFocus ); 147 fCommandArea->setFocus(); 148 #else 149 fCommandArea->setFocusPolicy ( Qt::StrongFocus ); 150 fCommandArea->setFocus(Qt::TabFocusReason); 151 #endif 152 fTextArea->setReadOnly(true); 153 154 155 // Set layouts 156 157 #if QT_VERSION < 0x040000 158 QWidget* topWidget = new QWidget(splitter); 159 QWidget* bottomWidget = new QWidget(splitter); 160 161 QVBoxLayout *layoutTop = new QVBoxLayout(topWidget); 162 QVBoxLayout *layoutBottom = new QVBoxLayout(bottomWidget); 163 #else 164 QWidget* topWidget = new QWidget(); 165 QWidget* bottomWidget = new QWidget(); 166 167 QVBoxLayout *layoutTop = new QVBoxLayout; 168 QVBoxLayout *layoutBottom = new QVBoxLayout; 169 #endif 170 171 172 173 layoutTop->addWidget(fTextArea); 174 layoutTop->addWidget(clearButton); 175 176 #if QT_VERSION >= 0x040000 177 topWidget->setLayout(layoutTop); 178 #endif 179 180 layoutBottom->addWidget(fCommandHistoryArea); 181 layoutBottom->addWidget(fCommandLabel); 182 layoutBottom->addWidget(fCommandArea); 183 #if QT_VERSION >= 0x040000 184 bottomWidget->setLayout(layoutBottom); 185 splitter->addWidget(topWidget); 186 splitter->addWidget(bottomWidget); 187 #endif 188 189 fMainWindow->setCentralWidget(splitter); 190 191 #if QT_VERSION < 0x040000 192 // Add a quit subMenu 193 QPopupMenu *fileMenu = new QPopupMenu( fMainWindow); 194 fileMenu->insertItem( "&Quitter", this, SLOT(close()), CTRL+Key_Q ); 195 fMainWindow->menuBar()->insertItem( QString("&File"), fileMenu ); 196 197 // Add a Help menu 198 QPopupMenu *helpMenu = new QPopupMenu( fMainWindow ); 199 helpMenu->insertItem( "&Show Help", this, SLOT(ShowHelpCallback()), CTRL+Key_H ); 200 fMainWindow->menuBar()->insertItem( QString("&Help"), helpMenu ); 201 202 #else 203 // Add a quit subMenu 204 QMenu *fileMenu = fMainWindow->menuBar()->addMenu("File"); 205 fileMenu->addAction("Quitter", fMainWindow, SLOT(close())); 206 207 // Add a Help menu 208 QMenu *helpMenu = fMainWindow->menuBar()->addMenu("Help"); 209 helpMenu->addAction("Show Help", this, SLOT(ShowHelpCallback())); 210 #endif 211 212 // Set the splitter size. The fTextArea sould be 2/3 on the fMainWindow 213 #if QT_VERSION < 0x040000 214 QValueList<int> vals = splitter->sizes(); 215 #else 216 QList<int> vals = splitter->sizes(); 217 #endif 218 if(vals.size()==2) { 219 vals[0] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*3/4; 220 vals[1] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*1/4; 221 splitter->setSizes(vals); 222 } 223 224 225 if(UI!=NULL) UI->SetCoutDestination(this); // TO KEEP 63 return &staticMetaObject; 226 64 } 227 65 228 229 230 G4UIQt::~G4UIQt( 231 ) 232 { 233 G4UImanager* UI = G4UImanager::GetUIpointer(); // TO KEEP 234 if(UI!=NULL) { // TO KEEP 235 UI->SetSession(NULL); // TO KEEP 236 UI->SetCoutDestination(NULL); // TO KEEP 237 } 238 239 if (fMainWindow!=NULL) 240 delete fMainWindow; 66 void *G4UIQt::qt_metacast(const char *_clname) 67 { 68 if (!_clname) return 0; 69 if (!strcmp(_clname, qt_meta_stringdata_G4UIQt)) 70 return static_cast<void*>(const_cast<G4UIQt*>(this)); 71 if (!strcmp(_clname, "G4VBasicShell")) 72 return static_cast<G4VBasicShell*>(const_cast<G4UIQt*>(this)); 73 if (!strcmp(_clname, "G4VInteractiveSession")) 74 return static_cast<G4VInteractiveSession*>(const_cast<G4UIQt*>(this)); 75 return QObject::qt_metacast(_clname); 241 76 } 242 77 243 244 245 /** Start the Qt main loop 246 */ 247 G4UIsession* G4UIQt::SessionStart ( 248 ) 78 int G4UIQt::qt_metacall(QMetaObject::Call _c, int _id, void **_a) 249 79 { 250 251 G4Qt* interactorManager = G4Qt::getInstance (); 252 fMainWindow->show(); 253 Prompt("session"); 254 exitSession = false; 255 256 257 printf("disable secondary loop\n"); 258 interactorManager->DisableSecondaryLoop (); // TO KEEP 259 ((QApplication*)interactorManager->GetMainInteractor())->exec(); 260 // on ne passe pas le dessous ? FIXME ???? 261 // je ne pense pas 13/06 262 263 // void* event; // TO KEEP 264 // while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP 265 // interactorManager->DispatchEvent(event); // TO KEEP 266 // if(exitSession==true) break; // TO KEEP 267 // } // TO KEEP 268 269 interactorManager->EnableSecondaryLoop (); 270 printf("enable secondary loop\n"); 271 return this; 80 _id = QObject::qt_metacall(_c, _id, _a); 81 if (_id < 0) 82 return _id; 83 if (_c == QMetaObject::InvokeMetaMethod) { 84 switch (_id) { 85 case 0: myClicked((*reinterpret_cast< const QString(*)>(_a[1]))); break; 86 case 1: ClearButtonCallback(); break; 87 case 2: CommandEnteredCallback(); break; 88 case 3: ButtonCallback((*reinterpret_cast< const QString(*)>(_a[1]))); break; 89 case 4: HelpTreeClicCallback(); break; 90 case 5: HelpTreeDoubleClicCallback((*reinterpret_cast< QTreeWidgetItem*(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break; 91 case 6: ShowHelpCallback(); break; 92 case 7: CommandHistoryCallback(); break; 93 } 94 _id -= 8; 95 } 96 return _id; 272 97 } 273 98 274 275 /** Display the prompt in the prompt area 276 @param aPrompt : string to display as the promt label 277 //FIXME : probablement inutile puisque le seul a afficher qq chose d'autre 278 que "session" est SecondaryLoop() 279 */ 280 void G4UIQt::Prompt ( 281 G4String aPrompt 282 ) 99 // SIGNAL 0 100 void G4UIQt::myClicked(const QString & _t1) 283 101 { 284 if (!aPrompt) return; 285 286 fCommandLabel->setText((char*)aPrompt.data()); 287 } 288 289 290 void G4UIQt::SessionTerminate ( 291 ) 292 { 293 G4Qt* interactorManager = G4Qt::getInstance (); 294 fMainWindow->close(); 295 ((QApplication*)interactorManager->GetMainInteractor())->exit(); 296 } 297 298 299 300 /** 301 Called by intercoms/src/G4UImanager.cc<br> 302 Called by visualization/management/src/G4VisCommands.cc with "EndOfEvent" argument<br> 303 It have to pause the session command terminal.<br> 304 Call SecondaryLoop to wait for exit event<br> 305 @param aState 306 @see : G4VisCommandReviewKeptEvents::SetNewValue 307 */ 308 void G4UIQt::PauseSessionStart ( 309 G4String aState 310 ) 311 { 312 if (!aState) return; 313 314 printf("G4UIQt::PauseSessionStart\n"); 315 if(aState=="G4_pause> ") { // TO KEEP 316 SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP 317 } // TO KEEP 318 319 if(aState=="EndOfEvent") { // TO KEEP 320 // Picking with feed back in event data Done here !!! 321 SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP 322 } // TO KEEP 323 } 324 325 326 327 /** 328 Begin the secondary loop 329 @param a_prompt : label to display as the prompt label 330 */ 331 void G4UIQt::SecondaryLoop ( 332 G4String aPrompt 333 ) 334 { 335 if (!aPrompt) return; 336 337 printf("G4UIQt::SecondaryLoop\n"); 338 G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ? 339 Prompt(aPrompt); // TO KEEP 340 exitPause = false; // TO KEEP 341 void* event; // TO KEEP 342 while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP 343 interactorManager->DispatchEvent(event); // TO KEEP 344 if(exitPause==true) break; // TO KEEP 345 } // TO KEEP 346 Prompt("session"); // TO KEEP 347 } 348 349 350 351 /** 352 Receive a cout from Geant4. We have to display it in the cout zone 353 @param aString : label to add in the display area 354 @return 0 355 */ 356 G4int G4UIQt::ReceiveG4cout ( 357 G4String aString 358 ) 359 { 360 if (!aString) return 0; 361 G4Qt* interactorManager = G4Qt::getInstance (); 362 if (!interactorManager) return 0; 363 364 // printf(" **************** G4 Cout : %s\n",(char*)aString.data()); 365 #if QT_VERSION < 0x040000 366 fTextArea->append(QString((char*)aString.data()).simplifyWhiteSpace()); 367 fTextArea->verticalScrollBar()->setValue(fTextArea->verticalScrollBar()->maxValue()); 368 #else 369 fTextArea->append(QString((char*)aString.data()).trimmed()); 370 fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum()); 371 #endif 372 interactorManager->FlushAndWaitExecution(); 373 return 0; 374 } 375 376 377 /** 378 Receive a cerr from Geant4. We have to display it in the cout zone 379 @param aString : label to add in the display area 380 @return 0 381 */ 382 G4int G4UIQt::ReceiveG4cerr ( 383 G4String aString 384 ) 385 { 386 if (!aString) return 0; 387 G4Qt* interactorManager = G4Qt::getInstance (); 388 if (!interactorManager) return 0; 389 390 #if QT_VERSION < 0x040000 391 QColor previousColor = fTextArea->color(); 392 fTextArea->setColor(Qt::red); 393 fTextArea->append(QString((char*)aString.data()).simplifyWhiteSpace()); 394 fTextArea->setColor(previousColor); 395 fTextArea->verticalScrollBar()->setValue(fTextArea->verticalScrollBar()->maxValue()); 396 #else 397 QColor previousColor = fTextArea->textColor(); 398 fTextArea->setTextColor(Qt::red); 399 fTextArea->append(QString((char*)aString.data()).trimmed()); 400 fTextArea->setTextColor(previousColor); 401 fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum()); 402 #endif 403 interactorManager->FlushAndWaitExecution(); 404 return 0; 405 } 406 407 408 409 /** 410 Add a new menu to the menu bar 411 @param aName name of menu 412 @param aLabel label to display 413 */ 414 void G4UIQt::AddMenu ( 415 const char* aName 416 ,const char* aLabel 417 ) 418 { 419 if (aName == NULL) return; 420 if (aLabel == NULL) return; 421 422 #if QT_VERSION < 0x040000 423 QPopupMenu *fileMenu = new QPopupMenu( fMainWindow); 424 fMainWindow->menuBar()->insertItem( aLabel, fileMenu ); 425 #else 426 QMenu *fileMenu = new QMenu(aLabel); 427 fMainWindow->menuBar()->insertMenu(fMainWindow->menuBar()->actions().last(),fileMenu); 428 #endif 429 430 AddInteractor (aName,(G4Interactor)fileMenu); 431 } 432 433 434 /** 435 Add a new button to a menu 436 @param aMenu : parent menu 437 @param aLabel : label to display 438 @param aCommand : command to execute as a callback 439 */ 440 void G4UIQt::AddButton ( 441 const char* aMenu 442 ,const char* aLabel 443 ,const char* aCommand 444 ) 445 { 446 if(aMenu==NULL) return; // TO KEEP 447 if(aLabel==NULL) return; // TO KEEP 448 if(aCommand==NULL) return; // TO KEEP 449 450 #if QT_VERSION < 0x040000 451 QPopupMenu *parent = (QPopupMenu*)GetInteractor(aMenu); 452 #else 453 QMenu *parent = (QMenu*)GetInteractor(aMenu); 454 #endif 455 456 if(parent==NULL) return; 457 458 QSignalMapper *signalMapper = new QSignalMapper(this); 459 #if QT_VERSION < 0x040000 460 QAction *action = new QAction(QString(aLabel),QKeySequence::QKeySequence (),signalMapper, SLOT(map())); 461 action->addTo(parent); 462 #else 463 QAction *action = parent->addAction(aLabel, signalMapper, SLOT(map())); 464 #endif 465 signalMapper->setMapping(action, QString(aCommand)); 466 connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&))); 467 } 468 469 470 471 472 /** 473 Open the help dialog in a separate window.<br> 474 This will be display as a tree widget.<br> 475 Implementation of <b>void G4VBasicShell::TerminalHelp(G4String newCommand)</b> 476 477 @param newCommand : open the tree widget item on this command if is set 478 */ 479 void G4UIQt::TerminalHelp( 480 G4String newCommand 481 ) 482 { 483 // Create the help dialog 484 if (!fHelpDialog) { 485 #if QT_VERSION < 0x040000 486 fHelpDialog = new QDialog(fMainWindow,0,FALSE,Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WStyle_MinMax ); 487 #else 488 fHelpDialog = new QDialog(fMainWindow,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint); 489 #endif 490 QSplitter *splitter = new QSplitter(Qt::Horizontal); 491 QPushButton *exitButton = new QPushButton("Exit",fMainWindow); 492 connect(exitButton, SIGNAL(clicked()), fHelpDialog,SLOT(close())); 493 494 // the help tree 495 G4UImanager* UI = G4UImanager::GetUIpointer(); 496 if(UI==NULL) return; 497 G4UIcommandTree * treeTop = UI->GetTree(); 498 499 // build widget 500 #if QT_VERSION < 0x040000 501 fHelpTreeWidget = new QListView(splitter); 502 fHelpTreeWidget->setSelectionMode(QListView::Single); 503 fHelpTreeWidget->addColumn("Command"); 504 fHelpTreeWidget->addColumn("Description"); 505 fHelpTreeWidget->hideColumn(1); 506 fHelpTreeWidget->header()->setResizeEnabled(FALSE,1); 507 // QList<QListViewItem *> items; 508 #else 509 fHelpTreeWidget = new QTreeWidget(); 510 fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection); 511 fHelpTreeWidget->setColumnCount(2); 512 fHelpTreeWidget->setColumnHidden(1,true); 513 QStringList labels; 514 labels << QString("Command") << QString("Description"); 515 fHelpTreeWidget->setHeaderLabels(labels); 516 // QList<QTreeWidgetItem *> items; 517 #endif 518 519 #if QT_VERSION < 0x040000 520 fHelpArea = new QTextEdit(splitter); 521 #else 522 fHelpArea = new QTextEdit(); 523 #endif 524 fHelpArea->setReadOnly(true); 525 526 G4int treeSize = treeTop->GetTreeEntry(); 527 #if QT_VERSION < 0x040000 528 QListViewItem * newItem; 529 #else 530 QTreeWidgetItem * newItem; 531 #endif 532 for (int a=0;a<treeSize;a++) { 533 // Creating new item 534 535 #if QT_VERSION < 0x040000 536 newItem = new QListViewItem(fHelpTreeWidget); 537 newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace()); 538 newItem->setText(1,QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).simplifyWhiteSpace()); 539 #else 540 //FIXME : Qt 4.2 541 // QStringList stringList; 542 // stringList << QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed() ; 543 // stringList << QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).trimmed() ; 544 // newItem = new QTreeWidgetItem(stringList); 545 // FIXME : Qt 4.0 546 newItem = new QTreeWidgetItem(fHelpTreeWidget); 547 newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed()); 548 newItem->setText(1,QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).trimmed()); 549 #endif 550 551 552 // look for childs 553 CreateChildTree(newItem,treeTop->GetTree(a+1)); 554 // items.append(newItem); 555 } 556 557 connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback())); 558 connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback(QTreeWidgetItem*,int))); 559 560 // Set layouts 561 562 #if QT_VERSION < 0x040000 563 QVBoxLayout *vLayout = new QVBoxLayout(fHelpDialog); 564 #else 565 QVBoxLayout *vLayout = new QVBoxLayout; 566 splitter->addWidget(fHelpTreeWidget); 567 splitter->addWidget(fHelpArea); 568 #endif 569 570 571 vLayout->addWidget(splitter); 572 vLayout->addWidget(exitButton); 573 #if QT_VERSION >= 0x040000 574 fHelpDialog->setLayout(vLayout); 575 #endif 576 577 } 578 579 // Look for the choosen command "newCommand" 580 size_t i = newCommand.index(" "); 581 G4String targetCom=""; 582 if( i != std::string::npos ) 583 { 584 G4String newValue = newCommand(i+1,newCommand.length()-(i+1)); 585 newValue.strip(G4String::both); 586 targetCom = ModifyToFullPathCommand( newValue ); 587 } 588 if (targetCom != "") { 589 #if QT_VERSION < 0x040000 590 QListViewItem* findItem = NULL; 591 QListViewItem* tmpItem = fHelpTreeWidget->firstChild(); 592 while (tmpItem != 0) { 593 if (!findItem) { 594 findItem = FindTreeItem(tmpItem,QString((char*)targetCom.data())); 595 } 596 tmpItem = tmpItem->nextSibling(); 597 } 598 #else 599 QTreeWidgetItem* findItem = NULL; 600 for (int a=0;a<fHelpTreeWidget->topLevelItemCount();a++) { 601 if (!findItem) { 602 findItem = FindTreeItem(fHelpTreeWidget->topLevelItem(a),QString((char*)targetCom.data())); 603 } 604 } 605 #endif 606 607 if (findItem) { 608 609 //collapsed open item 610 #if QT_VERSION < 0x040000 611 QList<QListViewItem *> selected; 612 #else 613 QList<QTreeWidgetItem *> selected; 614 #endif 615 selected = fHelpTreeWidget->selectedItems(); 616 if ( selected.count() != 0 ) { 617 #if QT_VERSION < 0x040000 618 QListViexItem * tmp =selected.at( 0 ); 619 #else 620 QTreeWidgetItem * tmp =selected.at( 0 ); 621 #endif 622 while ( tmp) { 623 tmp->setExpanded(false); 624 tmp = tmp->parent(); 625 } 626 } 627 628 // clear old selection 629 fHelpTreeWidget->clearSelection(); 630 631 // set new selection 632 findItem->setSelected(true); 633 634 // expand parent item 635 while ( findItem) { 636 findItem->setExpanded(true); 637 findItem = findItem->parent(); 638 } 639 640 // Call the update of the right textArea 641 HelpTreeClicCallback(); 642 } 643 } 644 fHelpDialog->setWindowTitle("Help on commands"); 645 fHelpDialog->resize(800,600); 646 fHelpDialog->move(QPoint(400,150)); 647 fHelpDialog->show(); 648 fHelpDialog->raise(); 649 fHelpDialog->activateWindow(); 650 } 651 652 653 654 /** Fill the Help Tree Widget 655 @param aParent : parent item to fill 656 @param aCommandTree : commandTree node associate with this part of the Tree 657 */ 658 #if QT_VERSION < 0x040000 659 void G4UIQt::CreateChildTree( 660 QListViewItem *aParent 661 ,G4UIcommandTree *aCommandTree 662 #else 663 void G4UIQt::CreateChildTree( 664 QTreeWidgetItem *aParent 665 ,G4UIcommandTree *aCommandTree 666 #endif 667 ) 668 { 669 if (aParent == NULL) return; 670 if (aCommandTree == NULL) return; 671 672 673 // Creating new item 674 QTreeWidgetItem * newItem; 675 676 // Get the Sub directories 677 for (int a=0;a<aCommandTree->GetTreeEntry();a++) { 678 679 QStringList stringList; 680 stringList << QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed() ; 681 stringList << QString((char*)(aCommandTree->GetTree(a+1)->GetTitle()).data()).trimmed() ; 682 newItem = new QTreeWidgetItem(stringList); 683 684 CreateChildTree(newItem,aCommandTree->GetTree(a+1)); 685 aParent->addChild(newItem); 686 } 687 688 689 690 // Get the Commands 691 692 for (int a=0;a<aCommandTree->GetCommandEntry();a++) { 693 694 QStringList stringList; 695 stringList << QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed() ; 696 stringList << QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed() ; 697 newItem = new QTreeWidgetItem(stringList); 698 699 aParent->addChild(newItem); 700 newItem->setExpanded(false); 701 } 702 } 703 704 705 /** Find a treeItemWidget in the help tree 706 @param aCommand item's String to look for 707 @return item if found, NULL if not 708 */ 709 QTreeWidgetItem* G4UIQt::FindTreeItem( 710 QTreeWidgetItem *aParent 711 ,const QString& aCommand 712 ) 713 { 714 if (aParent == NULL) return NULL; 715 716 if (aParent->text(0) == aCommand) 717 return aParent; 718 719 QTreeWidgetItem * tmp = NULL; 720 for (int a=0;a<aParent->childCount();a++) { 721 if (!tmp) 722 tmp = FindTreeItem(aParent->child(a),aCommand); 723 } 724 return tmp; 725 } 726 727 728 /** Build the command list parameters in a QString<br> 729 Reimplement partialy the G4UIparameter.cc 730 @param aCommand : command to list parameters 731 @see G4UIparameter::List() 732 @see G4UIcommand::List() 733 @return the command list parameters, or "" if nothing 734 */ 735 QString G4UIQt::GetCommandList ( 736 const G4UIcommand *aCommand 737 ) 738 { 739 740 QString txt =""; 741 if (aCommand == NULL) 742 return txt; 743 744 G4String commandPath = aCommand->GetCommandPath(); 745 G4String rangeString = aCommand->GetRange(); 746 G4int n_guidanceEntry = aCommand->GetGuidanceEntries(); 747 G4int n_parameterEntry = aCommand->GetParameterEntries(); 748 749 if ((commandPath == "") && 750 (rangeString == "") && 751 (n_guidanceEntry == 0) && 752 (n_parameterEntry == 0)) { 753 return txt; 754 } 755 756 if((commandPath.length()-1)!='/') { 757 txt += "Command " + QString((char*)(commandPath).data()) + "\n"; 758 } 759 txt += "Guidance :\n"; 760 761 for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) { 762 txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n"; 763 } 764 if( ! rangeString.isNull() ) { 765 txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n"; 766 } 767 if( n_parameterEntry > 0 ) { 768 G4UIparameter *param; 769 770 // Re-implementation of G4UIparameter.cc 771 772 for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) { 773 param = aCommand->GetParameter(i_thParameter); 774 txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n"; 775 if( ! param->GetParameterGuidance().isNull() ) 776 txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ; 777 txt += " Parameter type : " + QString(param->GetParameterType())+ "\n"; 778 if(param->IsOmittable()){ 779 txt += " Omittable : True\n"; 780 } else { 781 txt += " Omittable : False\n"; 782 } 783 if( param->GetCurrentAsDefault() ) { 784 txt += " Default value : taken from the current value\n"; 785 } else if( ! param->GetDefaultValue().isNull() ) { 786 txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n"; 787 } 788 if( ! param->GetParameterRange().isNull() ) { 789 txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n"; 790 } 791 if( ! param->GetParameterCandidates().isNull() ) { 792 txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n"; 793 } 794 } 795 } 796 return txt; 797 } 798 799 800 801 /** Implement G4VBasicShell vurtual function 802 */ 803 G4bool G4UIQt::GetHelpChoice( 804 G4int& aInt 805 ) 806 { 807 printf("G4UIQt::GetHelpChoice SHOULD NEVER GO HERE"); 808 return true; 809 } 810 811 812 /** Implement G4VBasicShell vurtual function 813 */ 814 void G4UIQt::ExitHelp( 815 ) 816 { 817 printf("G4UIQt::ExitHelp SHOULD NEVER GO HERE"); 818 } 819 820 821 /** Event filter method. Every event from QtApplication goes here.<br/> 822 We apply a filter only for the Up and Down Arrow press when the QLineEdit<br/> 823 is active. If this filter match, Up arrow we give the previous command<br/> 824 and Down arrow will give the next if exist.<br/> 825 @param obj Emitter of the event 826 @param event Kind of event 827 */ 828 bool G4UIQt::eventFilter( // Should stay with a minuscule eventFilter because of Qt 829 QObject *aObj 830 ,QEvent *aEvent 831 ) 832 { 833 if (aObj == NULL) return false; 834 if (aEvent == NULL) return false; 835 836 if (aObj == fCommandHistoryArea) { 837 if (aEvent->type() == QEvent::KeyPress) { 838 fCommandArea->setFocus(); 839 } 840 } 841 if (aObj == fCommandArea) { 842 if (aEvent->type() == QEvent::KeyPress) { 843 QKeyEvent *e = static_cast<QKeyEvent*>(aEvent); 844 if ((e->key() == (Qt::Key_Down)) || 845 (e->key() == (Qt::Key_PageDown)) || 846 (e->key() == (Qt::Key_Up)) || 847 (e->key() == (Qt::Key_PageUp))) { 848 int selection = fCommandHistoryArea->currentRow(); 849 if (fCommandHistoryArea->count()) { 850 if (selection == -1) { 851 selection = fCommandHistoryArea->count()-1; 852 } else { 853 if (e->key() == (Qt::Key_Down)) { 854 if (selection <(fCommandHistoryArea->count()-1)) 855 selection++; 856 } else if (e->key() == (Qt::Key_PageDown)) { 857 selection = fCommandHistoryArea->count()-1; 858 } else if (e->key() == (Qt::Key_Up)) { 859 if (selection >0) 860 selection --; 861 } else if (e->key() == (Qt::Key_PageUp)) { 862 selection = 0; 863 } 864 } 865 fCommandHistoryArea->clearSelection(); 866 fCommandHistoryArea->item(selection)->setSelected(true); 867 fCommandHistoryArea->setCurrentItem(fCommandHistoryArea->item(selection)); 868 } 869 } else if (e->key() == (Qt::Key_Tab)) { 870 #if QT_VERSION < 0x040000 871 G4String ss = Complete(fCommandArea->text().ascii()); 872 #else 873 G4String ss = Complete(fCommandArea->text().toStdString().c_str()); 874 #endif 875 fCommandArea->setText((char*)(ss.data())); 876 877 // do not pass by parent, it will disable widget tab focus ! 878 return true; 879 } 880 } 881 } 882 // pass the event on to the parent class 883 return QObject::eventFilter(aObj, aEvent); 884 } 885 886 887 888 889 /***************************************************************************/ 890 // 891 // SLOTS DEFINITIONS 892 // 893 /***************************************************************************/ 894 895 /** Called when user give "help" command. 896 */ 897 void G4UIQt::ShowHelpCallback ( 898 ) 899 { 900 TerminalHelp(""); 901 } 902 903 904 /** Called when user click on clear button. Clear the text Output area 905 */ 906 void G4UIQt::ClearButtonCallback ( 907 ) 908 { 909 fTextArea->clear(); 910 } 911 912 913 /** Callback call when "click on a menu entry.<br> 914 Send the associated command to geant4 915 */ 916 void G4UIQt::CommandEnteredCallback ( 917 ) 918 { 919 #if QT_VERSION < 0x040000 920 G4String command (fCommandArea->text().ascii()); 921 #else 922 G4String command (fCommandArea->text().toStdString().c_str()); 923 #endif 924 if (fCommandArea->text().trimmed() != "") { 925 fCommandHistoryArea->addItem(fCommandArea->text()); 926 fCommandHistoryArea->clearSelection(); 927 fCommandHistoryArea->setCurrentItem(NULL); 928 fCommandArea->setText(""); 929 930 G4Qt* interactorManager = G4Qt::getInstance (); 931 if (interactorManager) { 932 interactorManager->FlushAndWaitExecution(); 933 } 934 if (command(0,4) != "help") { 935 ApplyShellCommand (command,exitSession,exitPause); 936 } else { 937 TerminalHelp(command); 938 } 939 printf("after \n"); 940 if(exitSession==true) 941 SessionTerminate(); 942 } 943 } 944 945 946 /** Callback call when "enter" clicked on the command zone.<br> 947 Send the command to geant4 948 @param aCommand 949 */ 950 void G4UIQt::ButtonCallback ( 951 const QString& aCommand 952 ) 953 { 954 #if QT_VERSION < 0x040000 955 G4String ss = G4String(aCommand.ascii()); 956 #else 957 G4String ss = G4String(aCommand.toStdString().c_str()); 958 #endif 959 ApplyShellCommand(ss,exitSession,exitPause); 960 if(exitSession==true) 961 SessionTerminate(); 962 } 963 964 965 966 /** This callback is activated when user selected a item in the help tree 967 */ 968 void G4UIQt::HelpTreeClicCallback ( 969 ) 970 { 971 // printf("G4UIQt::HelpTreeClicCallback"); 972 QTreeWidgetItem* item = NULL; 973 if (!fHelpTreeWidget) 974 return ; 975 976 if (!fHelpArea) 977 return; 978 979 QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems(); 980 if (list.isEmpty()) 981 return; 982 item = list.first(); 983 if (!item) 984 return; 985 986 G4UImanager* UI = G4UImanager::GetUIpointer(); 987 if(UI==NULL) return; 988 G4UIcommandTree * treeTop = UI->GetTree(); 989 #if QT_VERSION < 0x040000 990 G4UIcommand* command = treeTop->FindPath(item->text (1).ascii()); 991 #else 992 G4UIcommand* command = treeTop->FindPath(item->text (1).toStdString().c_str()); 993 #endif 994 if (command) { 995 fHelpArea->setText(GetCommandList(command)); 996 } else { 997 // this is not a command, this is a sub directory 998 // We display the Title 999 #if QT_VERSION < 0x040000 1000 fHelpArea->setText(item->text (1).ascii()); 1001 #else 1002 fHelpArea->setText(item->text (1).toStdString().c_str()); 1003 #endif 1004 } 1005 } 1006 1007 /** This callback is activated when user double clic on a item in the help tree 1008 */ 1009 void G4UIQt::HelpTreeDoubleClicCallback ( 1010 QTreeWidgetItem* item 1011 ,int nb 1012 ) 1013 { 1014 printf("G4UIQt::HelpTreeDoubleClicCallback"); 1015 HelpTreeClicCallback(); 1016 fCommandArea->setText(item->text (1)); 1017 } 1018 1019 1020 /** Callback called when user select an old command in the command history<br> 1021 Give it to the command area. 1022 */ 1023 void G4UIQt::CommandHistoryCallback( 1024 ) 1025 { 1026 QListWidgetItem* item = NULL; 1027 if (!fCommandHistoryArea) 1028 return ; 1029 1030 1031 QList<QListWidgetItem *> list =fCommandHistoryArea->selectedItems(); 1032 if (list.isEmpty()) 1033 return; 1034 item = list.first(); 1035 if (!item) 1036 return; 1037 fCommandArea->setText(item->text()); 1038 102 void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) }; 103 QMetaObject::activate(this, &staticMetaObject, 0, _a); 1039 104 } 1040 105 1041 106 #endif 107 108 #endif
Note: See TracChangeset
for help on using the changeset viewer.