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