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