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