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