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