| 1 | // TODO !
|
|---|
| 2 |
|
|---|
| 3 | //
|
|---|
| 4 | // ********************************************************************
|
|---|
| 5 | // * License and Disclaimer *
|
|---|
| 6 | // * *
|
|---|
| 7 | // * The Geant4 software is copyright of the Copyright Holders of *
|
|---|
| 8 | // * the Geant4 Collaboration. It is provided under the terms and *
|
|---|
| 9 | // * conditions of the Geant4 Software License, included in the file *
|
|---|
| 10 | // * LICENSE and available at http://cern.ch/geant4/license . These *
|
|---|
| 11 | // * include a list of copyright holders. *
|
|---|
| 12 | // * *
|
|---|
| 13 | // * Neither the authors of this software system, nor their employing *
|
|---|
| 14 | // * institutes,nor the agencies providing financial support for this *
|
|---|
| 15 | // * work make any representation or warranty, express or implied, *
|
|---|
| 16 | // * regarding this software system or assume any liability for its *
|
|---|
| 17 | // * use. Please see the license in the file LICENSE and URL above *
|
|---|
| 18 | // * for the full disclaimer and the limitation of liability. *
|
|---|
| 19 | // * *
|
|---|
| 20 | // * This code implementation is the result of the scientific and *
|
|---|
| 21 | // * technical work of the GEANT4 collaboration. *
|
|---|
| 22 | // * By using, copying, modifying or distributing the software (or *
|
|---|
| 23 | // * any work based on the software) you agree to acknowledge its *
|
|---|
| 24 | // * use in resulting scientific publications, and indicate your *
|
|---|
| 25 | // * acceptance of all terms of the Geant4 Software license. *
|
|---|
| 26 | // ********************************************************************
|
|---|
| 27 | //
|
|---|
| 28 | //
|
|---|
| 29 | // $Id: G4UIQt.cc,v 1.14 2007/05/29 11:09:49 $
|
|---|
| 30 | // GEANT4 tag $Name: geant4-08-01 $
|
|---|
| 31 | //
|
|---|
| 32 | // L. Garnier
|
|---|
| 33 |
|
|---|
| 34 | //#define DEBUG
|
|---|
| 35 |
|
|---|
| 36 | #ifdef G4UI_BUILD_QT_SESSION
|
|---|
| 37 |
|
|---|
| 38 | #include "G4Types.hh"
|
|---|
| 39 |
|
|---|
| 40 | #include <string.h>
|
|---|
| 41 |
|
|---|
| 42 | #include "G4UIQt.hh"
|
|---|
| 43 | #include "G4UImanager.hh"
|
|---|
| 44 | #include "G4StateManager.hh"
|
|---|
| 45 | #include "G4UIcommandTree.hh"
|
|---|
| 46 | #include "G4UIcommandStatus.hh"
|
|---|
| 47 |
|
|---|
| 48 | #include "G4Qt.hh"
|
|---|
| 49 |
|
|---|
| 50 | #include <QtGui/qapplication.h>
|
|---|
| 51 | #include <QtGui/qwidget.h>
|
|---|
| 52 | #include <QtGui/qmenu.h>
|
|---|
| 53 | #include <QtGui/qmenubar.h>
|
|---|
| 54 | #include <QtGui/qboxlayout.h>
|
|---|
| 55 | #include <QtGui/qpushbutton.h>
|
|---|
| 56 | #include <QtGui/qlabel.h>
|
|---|
| 57 | #include <QtGui/qsplitter.h>
|
|---|
| 58 | #include <QtGui/qscrollbar.h>
|
|---|
| 59 | #include <QtGui/qdialog.h>
|
|---|
| 60 | #include <QtGui/qevent.h>
|
|---|
| 61 |
|
|---|
| 62 | #include <stdlib.h>
|
|---|
| 63 |
|
|---|
| 64 | // Pourquoi Static et non variables de classe ?
|
|---|
| 65 | static G4bool exitSession = true;
|
|---|
| 66 | static G4bool exitPause = true;
|
|---|
| 67 | /***************************************************************************/
|
|---|
| 68 | /**
|
|---|
| 69 | Build a Qt window with a menubar, output area and promt area
|
|---|
| 70 | +-----------------------+
|
|---|
| 71 | |exit menu| |
|
|---|
| 72 | | |
|
|---|
| 73 | | +-------------------+ |
|
|---|
| 74 | | | | |
|
|---|
| 75 | | | Output area | |
|
|---|
| 76 | | | | |
|
|---|
| 77 | | +-------------------+ |
|
|---|
| 78 | | | clear | |
|
|---|
| 79 | | +-------------------+ |
|
|---|
| 80 | | | promt history | |
|
|---|
| 81 | | +-------------------+ |
|
|---|
| 82 | | +-------------------+ |
|
|---|
| 83 | | |> promt area | |
|
|---|
| 84 | | +-------------------+ |
|
|---|
| 85 | +-----------------------+
|
|---|
| 86 | */
|
|---|
| 87 |
|
|---|
| 88 | G4UIQt::G4UIQt (
|
|---|
| 89 | int argc,
|
|---|
| 90 | char** argv
|
|---|
| 91 | )
|
|---|
| 92 | :fHelpDialog(NULL)
|
|---|
| 93 |
|
|---|
| 94 | /***************************************************************************/
|
|---|
| 95 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 96 | {
|
|---|
| 97 | G4Qt* interactorManager = G4Qt::getInstance ();
|
|---|
| 98 | G4UImanager* UI = G4UImanager::GetUIpointer();
|
|---|
| 99 | if(UI!=NULL) UI->SetSession(this);
|
|---|
| 100 |
|
|---|
| 101 | fMainWindow = new QMainWindow();
|
|---|
| 102 | fMainWindow->setWindowTitle( "G4UI Session" );
|
|---|
| 103 | fMainWindow->resize(800,600);
|
|---|
| 104 | fMainWindow->move(QPoint(300,100));
|
|---|
| 105 |
|
|---|
| 106 | QSplitter *splitter = new QSplitter(Qt::Vertical);
|
|---|
| 107 | fTextArea = new QTextEdit();
|
|---|
| 108 | QPushButton *clearButton = new QPushButton("clear");
|
|---|
| 109 | connect(clearButton, SIGNAL(clicked()), SLOT(clearButtonCallback()));
|
|---|
| 110 |
|
|---|
| 111 | fCommandHistoryArea = new QListWidget();
|
|---|
| 112 | fCommandHistoryArea->setSelectionMode(QAbstractItemView::SingleSelection);
|
|---|
| 113 | connect(fCommandHistoryArea, SIGNAL(itemSelectionChanged()), SLOT(commandHistoryCallback()));
|
|---|
| 114 | fCommandLabel = new QLabel();
|
|---|
| 115 |
|
|---|
| 116 | fCommandArea = new QLineEdit();
|
|---|
| 117 | fCommandArea->installEventFilter(this);
|
|---|
| 118 | fCommandArea->activateWindow();
|
|---|
| 119 | connect(fCommandArea, SIGNAL(returnPressed()), SLOT(commandEnteredCallback()));
|
|---|
| 120 | fCommandArea->setFocusPolicy ( Qt::StrongFocus );
|
|---|
| 121 | fCommandArea->setFocus(Qt::TabFocusReason);
|
|---|
| 122 | fTextArea->setReadOnly(true);
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 | // Set layouts
|
|---|
| 126 | QVBoxLayout *layoutSplitter = new QVBoxLayout;
|
|---|
| 127 |
|
|---|
| 128 | QWidget* topWidget = new QWidget();
|
|---|
| 129 | QVBoxLayout *layoutTop = new QVBoxLayout;
|
|---|
| 130 |
|
|---|
| 131 | QWidget* bottomWidget = new QWidget();
|
|---|
| 132 | QVBoxLayout *layoutBottom = new QVBoxLayout;
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 | layoutTop->addWidget(fTextArea);
|
|---|
| 136 | layoutTop->addWidget(clearButton);
|
|---|
| 137 | topWidget->setLayout(layoutTop);
|
|---|
| 138 |
|
|---|
| 139 | layoutBottom->addWidget(fCommandHistoryArea);
|
|---|
| 140 | layoutBottom->addWidget(fCommandLabel);
|
|---|
| 141 | layoutBottom->addWidget(fCommandArea);
|
|---|
| 142 | bottomWidget->setLayout(layoutBottom);
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 | layoutSplitter->addWidget(topWidget);
|
|---|
| 146 | layoutSplitter->addWidget(bottomWidget);
|
|---|
| 147 | splitter->setLayout(layoutSplitter);
|
|---|
| 148 |
|
|---|
| 149 | fMainWindow->setCentralWidget(splitter);
|
|---|
| 150 |
|
|---|
| 151 | // Add a quit subMenu
|
|---|
| 152 | QMenu *fileMenu = fMainWindow->menuBar()->addMenu("File");
|
|---|
| 153 | fileMenu->addAction("Quitter", fMainWindow, SLOT(close()));
|
|---|
| 154 |
|
|---|
| 155 | // Add a Help menu
|
|---|
| 156 | QMenu *helpMenu = fMainWindow->menuBar()->addMenu("Help");
|
|---|
| 157 | helpMenu->addAction("Show Help", this, SLOT(showHelpCallback()));
|
|---|
| 158 |
|
|---|
| 159 | // Set the splitter size. The fTextArea sould be 2/3 on the fMainWindow
|
|---|
| 160 | QList<int> vals = splitter->sizes();
|
|---|
| 161 | if(vals.size()==2) {
|
|---|
| 162 | vals[0] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*3/4;
|
|---|
| 163 | vals[1] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*1/4;
|
|---|
| 164 | splitter->setSizes(vals);
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 | if(UI!=NULL) UI->SetCoutDestination(this); // TO KEEP
|
|---|
| 169 | }
|
|---|
| 170 | /***************************************************************************/
|
|---|
| 171 | G4UIQt::~G4UIQt(
|
|---|
| 172 | )
|
|---|
| 173 | /***************************************************************************/
|
|---|
| 174 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 175 | {
|
|---|
| 176 | G4UImanager* UI = G4UImanager::GetUIpointer(); // TO KEEP
|
|---|
| 177 | if(UI!=NULL) { // TO KEEP
|
|---|
| 178 | UI->SetSession(NULL); // TO KEEP
|
|---|
| 179 | UI->SetCoutDestination(NULL); // TO KEEP
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 | if (fMainWindow!=NULL)
|
|---|
| 184 | delete fMainWindow;
|
|---|
| 185 | }
|
|---|
| 186 | /***************************************************************************/
|
|---|
| 187 | /*
|
|---|
| 188 | Start the Qt main loop
|
|---|
| 189 | */
|
|---|
| 190 | G4UIsession* G4UIQt::SessionStart (
|
|---|
| 191 | )
|
|---|
| 192 | /***************************************************************************/
|
|---|
| 193 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 194 | {
|
|---|
| 195 |
|
|---|
| 196 | G4Qt* interactorManager = G4Qt::getInstance ();
|
|---|
| 197 | fMainWindow->show();
|
|---|
| 198 | Prompt("session");
|
|---|
| 199 | exitSession = false;
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 | printf("disable secondary loop\n");
|
|---|
| 203 | interactorManager->DisableSecondaryLoop (); // TO KEEP
|
|---|
| 204 | ((QApplication*)interactorManager->GetMainInteractor())->exec();
|
|---|
| 205 | // on ne passe pas le dessous ? FIXME ????
|
|---|
| 206 | // je ne pense pas 13/06
|
|---|
| 207 |
|
|---|
| 208 | // void* event; // TO KEEP
|
|---|
| 209 | // while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP
|
|---|
| 210 | // interactorManager->DispatchEvent(event); // TO KEEP
|
|---|
| 211 | // if(exitSession==true) break; // TO KEEP
|
|---|
| 212 | // } // TO KEEP
|
|---|
| 213 |
|
|---|
| 214 | interactorManager->EnableSecondaryLoop ();
|
|---|
| 215 | printf("enable secondary loop\n");
|
|---|
| 216 | return this;
|
|---|
| 217 | }
|
|---|
| 218 | /***************************************************************************/
|
|---|
| 219 |
|
|---|
| 220 | /**
|
|---|
| 221 | Display the prompt in the prompt area
|
|---|
| 222 | */
|
|---|
| 223 | void G4UIQt::Prompt (
|
|---|
| 224 | G4String aPrompt
|
|---|
| 225 | )
|
|---|
| 226 | /***************************************************************************/
|
|---|
| 227 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 228 | {
|
|---|
| 229 | fCommandLabel->setText((char*)aPrompt.data());
|
|---|
| 230 | }
|
|---|
| 231 | /***************************************************************************/
|
|---|
| 232 | void G4UIQt::SessionTerminate (
|
|---|
| 233 | )
|
|---|
| 234 | /***************************************************************************/
|
|---|
| 235 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 236 | {
|
|---|
| 237 | G4Qt* interactorManager = G4Qt::getInstance ();
|
|---|
| 238 | fMainWindow->close();
|
|---|
| 239 | ((QApplication*)interactorManager->GetMainInteractor())->exit();
|
|---|
| 240 | }
|
|---|
| 241 | /***************************************************************************/
|
|---|
| 242 | void G4UIQt::PauseSessionStart (
|
|---|
| 243 | G4String a_state
|
|---|
| 244 | )
|
|---|
| 245 | /***************************************************************************/
|
|---|
| 246 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 247 | {
|
|---|
| 248 | printf("G4UIQt::PauseSessionStart\n");
|
|---|
| 249 | if(a_state=="G4_pause> ") { // TO KEEP
|
|---|
| 250 | SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP
|
|---|
| 251 | } // TO KEEP
|
|---|
| 252 |
|
|---|
| 253 | if(a_state=="EndOfEvent") { // TO KEEP
|
|---|
| 254 | // Picking with feed back in event data Done here !!!
|
|---|
| 255 | SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP
|
|---|
| 256 | } // TO KEEP
|
|---|
| 257 | }
|
|---|
| 258 | /***************************************************************************/
|
|---|
| 259 | void G4UIQt::SecondaryLoop (
|
|---|
| 260 | G4String a_prompt
|
|---|
| 261 | )
|
|---|
| 262 | /***************************************************************************/
|
|---|
| 263 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 264 | {
|
|---|
| 265 | printf("G4UIQt::SecondaryLoop\n");
|
|---|
| 266 | G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ?
|
|---|
| 267 | Prompt(a_prompt); // TO KEEP
|
|---|
| 268 | exitPause = false; // TO KEEP
|
|---|
| 269 | void* event; // TO KEEP
|
|---|
| 270 | while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP
|
|---|
| 271 | interactorManager->DispatchEvent(event); // TO KEEP
|
|---|
| 272 | if(exitPause==true) break; // TO KEEP
|
|---|
| 273 | } // TO KEEP
|
|---|
| 274 | Prompt("session"); // TO KEEP
|
|---|
| 275 | }
|
|---|
| 276 | /***************************************************************************/
|
|---|
| 277 | /**
|
|---|
| 278 | Receive a cout from Geant4. We have to display it in the cout zone
|
|---|
| 279 | */
|
|---|
| 280 | G4int G4UIQt::ReceiveG4cout (
|
|---|
| 281 | G4String a_string
|
|---|
| 282 | )
|
|---|
| 283 | /***************************************************************************/
|
|---|
| 284 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 285 | {
|
|---|
| 286 | fTextArea->append(QString((char*)a_string.data()).trimmed());
|
|---|
| 287 | fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum());
|
|---|
| 288 | return 0;
|
|---|
| 289 | }
|
|---|
| 290 | /***************************************************************************/
|
|---|
| 291 | /**
|
|---|
| 292 | Receive a cerr from Geant4. We have to display it in the cout zone
|
|---|
| 293 | */
|
|---|
| 294 | G4int G4UIQt::ReceiveG4cerr (
|
|---|
| 295 | G4String a_string
|
|---|
| 296 | )
|
|---|
| 297 | /***************************************************************************/
|
|---|
| 298 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 299 | {
|
|---|
| 300 | QColor previousColor = fTextArea->textColor();
|
|---|
| 301 | fTextArea->setTextColor(Qt::red);
|
|---|
| 302 | fTextArea->append(QString((char*)a_string.data()).trimmed());
|
|---|
| 303 | fTextArea->setTextColor(previousColor);
|
|---|
| 304 | fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum());
|
|---|
| 305 | return 0;
|
|---|
| 306 | }
|
|---|
| 307 |
|
|---|
| 308 | /***************************************************************************/
|
|---|
| 309 | void G4UIQt::AddMenu (
|
|---|
| 310 | const char* a_name
|
|---|
| 311 | ,const char* a_label
|
|---|
| 312 | )
|
|---|
| 313 | /***************************************************************************/
|
|---|
| 314 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 315 | {
|
|---|
| 316 | printf("G4UIQt::AddMenu %s %s\n",a_name,a_label);
|
|---|
| 317 |
|
|---|
| 318 | // QMenu *fileMenu = fMainWindow->menuBar()->addMenu(a_label);
|
|---|
| 319 | QMenu *fileMenu = new QMenu(a_label);
|
|---|
| 320 | fMainWindow->menuBar()->insertMenu(fMainWindow->menuBar()->actions().last(),fileMenu);
|
|---|
| 321 | AddInteractor (a_name,(G4Interactor)fileMenu);
|
|---|
| 322 | }
|
|---|
| 323 | /***************************************************************************/
|
|---|
| 324 | void G4UIQt::AddButton (
|
|---|
| 325 | const char* a_menu
|
|---|
| 326 | ,const char* a_label
|
|---|
| 327 | ,const char* a_command
|
|---|
| 328 | )
|
|---|
| 329 | /***************************************************************************/
|
|---|
| 330 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 331 | {
|
|---|
| 332 | if(a_menu==NULL) return; // TO KEEP
|
|---|
| 333 | if(a_label==NULL) return; // TO KEEP
|
|---|
| 334 | if(a_command==NULL) return; // TO KEEP
|
|---|
| 335 | QMenu *parent = (QMenu*)GetInteractor(a_menu);
|
|---|
| 336 | if(parent==NULL) return;
|
|---|
| 337 |
|
|---|
| 338 | signalMapper = new QSignalMapper(this);
|
|---|
| 339 | QAction *action = parent->addAction(a_label, signalMapper, SLOT(map()));
|
|---|
| 340 | signalMapper->setMapping(action, QString(a_command));
|
|---|
| 341 | connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(buttonCallback(const QString&)));
|
|---|
| 342 | }
|
|---|
| 343 |
|
|---|
| 344 |
|
|---|
| 345 |
|
|---|
| 346 |
|
|---|
| 347 | /**
|
|---|
| 348 | Open the help dialog in a separate window.
|
|---|
| 349 | This will be display as a tree widget
|
|---|
| 350 | Implementation of <b>void G4VBasicShell::TerminalHelp(G4String newCommand)</b>
|
|---|
| 351 |
|
|---|
| 352 | @param newCommand : open the tree widget item on this command if is set
|
|---|
| 353 | */
|
|---|
| 354 | void G4UIQt::TerminalHelp(G4String newCommand)
|
|---|
| 355 | {
|
|---|
| 356 |
|
|---|
| 357 |
|
|---|
| 358 | if (!fHelpDialog) {
|
|---|
| 359 | fHelpDialog = new QDialog;
|
|---|
| 360 |
|
|---|
| 361 | QSplitter *splitter = new QSplitter(Qt::Horizontal);
|
|---|
| 362 | fHelpArea = new QTextEdit();
|
|---|
| 363 | QPushButton *exitButton = new QPushButton("Exit");
|
|---|
| 364 | connect(exitButton, SIGNAL(clicked()), fHelpDialog,SLOT(close()));
|
|---|
| 365 | fHelpArea->setReadOnly(true);
|
|---|
| 366 |
|
|---|
| 367 | // the help tree
|
|---|
| 368 | G4UImanager* UI = G4UImanager::GetUIpointer();
|
|---|
| 369 | if(UI==NULL) return;
|
|---|
| 370 | G4UIcommandTree * treeTop = UI->GetTree();
|
|---|
| 371 |
|
|---|
| 372 | // build widget
|
|---|
| 373 | fHelpTreeWidget = new QTreeWidget();
|
|---|
| 374 | fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
|
|---|
| 375 | fHelpTreeWidget->setColumnCount(2);
|
|---|
| 376 | fHelpTreeWidget->setColumnHidden(1,true);
|
|---|
| 377 | QStringList labels;
|
|---|
| 378 | labels << QString("Command") << QString("Description");
|
|---|
| 379 | fHelpTreeWidget->setHeaderLabels(labels);
|
|---|
| 380 |
|
|---|
| 381 | QList<QTreeWidgetItem *> items;
|
|---|
| 382 | G4int treeSize = treeTop->GetTreeEntry();
|
|---|
| 383 | QTreeWidgetItem * newItem;
|
|---|
| 384 | for (int a=0;a<treeSize;a++) {
|
|---|
| 385 | // Creating new item
|
|---|
| 386 | QStringList stringList;
|
|---|
| 387 | stringList << QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed() ;
|
|---|
| 388 | stringList << QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).trimmed() ;
|
|---|
| 389 |
|
|---|
| 390 | newItem = new QTreeWidgetItem(stringList);
|
|---|
| 391 |
|
|---|
| 392 | // look for childs
|
|---|
| 393 | CreateChildTree(newItem,treeTop->GetTree(a+1));
|
|---|
| 394 | items.append(newItem);
|
|---|
| 395 | }
|
|---|
| 396 | fHelpTreeWidget->insertTopLevelItems(0, items);
|
|---|
| 397 |
|
|---|
| 398 | //connecting callback
|
|---|
| 399 | // QSignalMapper signalMapper = new QSignalMapper(this);
|
|---|
| 400 |
|
|---|
| 401 | connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(helpTreeCallback()));
|
|---|
| 402 |
|
|---|
| 403 | // Set layouts
|
|---|
| 404 | QHBoxLayout *splitterLayout = new QHBoxLayout;
|
|---|
| 405 |
|
|---|
| 406 | QVBoxLayout *vLayout = new QVBoxLayout;
|
|---|
| 407 |
|
|---|
| 408 | splitterLayout->addWidget(fHelpTreeWidget);
|
|---|
| 409 | splitterLayout->addWidget(fHelpArea);
|
|---|
| 410 | splitter->setLayout(splitterLayout);
|
|---|
| 411 |
|
|---|
| 412 | vLayout->addWidget(splitter);
|
|---|
| 413 | vLayout->addWidget(exitButton);
|
|---|
| 414 | fHelpDialog->setLayout(vLayout);
|
|---|
| 415 |
|
|---|
| 416 | }
|
|---|
| 417 |
|
|---|
| 418 | // Look for the choosen command "newCommand"
|
|---|
| 419 | size_t i = newCommand.index(" ");
|
|---|
| 420 | G4String targetCom="";
|
|---|
| 421 | if( i != std::string::npos )
|
|---|
| 422 | {
|
|---|
| 423 | G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
|
|---|
| 424 | newValue.strip(G4String::both);
|
|---|
| 425 | targetCom = ModifyToFullPathCommand( newValue );
|
|---|
| 426 | printf("test : av:%s-- ap:%s--\n",((char*)newValue.data()),((char*)targetCom.data()));
|
|---|
| 427 | }
|
|---|
| 428 | if (targetCom != "") {
|
|---|
| 429 | QList<QTreeWidgetItem *> list = fHelpTreeWidget->findItems(QString(((char*)targetCom.data())),Qt::MatchFixedString,0);
|
|---|
| 430 | for (int a=0;a<13;a++) {
|
|---|
| 431 | printf("verif.... =%s= +%s+\n",fHelpTreeWidget->topLevelItem(a)->text(0).toStdString().c_str(),((char*)targetCom.data()));
|
|---|
| 432 | }
|
|---|
| 433 |
|
|---|
| 434 | if (!list.isEmpty()) {
|
|---|
| 435 | if (list.first()->childCount() >0)
|
|---|
| 436 | list.first()->setExpanded(true);
|
|---|
| 437 |
|
|---|
| 438 | //collapsed open item
|
|---|
| 439 | QList<QTreeWidgetItem *> selected;
|
|---|
| 440 | selected = fHelpTreeWidget->selectedItems();
|
|---|
| 441 | if ( selected.count() != 0 ) {
|
|---|
| 442 | fHelpTreeWidget->collapseItem (selected.at( 0 ) );
|
|---|
| 443 | }
|
|---|
| 444 |
|
|---|
| 445 | // clear old selection
|
|---|
| 446 | fHelpTreeWidget->clearSelection();
|
|---|
| 447 | list.first()->setSelected(true);
|
|---|
| 448 |
|
|---|
| 449 | // Call the update of the right textArea
|
|---|
| 450 | helpTreeCallback();
|
|---|
| 451 | }
|
|---|
| 452 | }
|
|---|
| 453 | fHelpDialog->setWindowTitle("Help on commands");
|
|---|
| 454 | fHelpDialog->resize(800,600);
|
|---|
| 455 | fHelpDialog->move(QPoint(400,150));
|
|---|
| 456 | fHelpDialog->show();
|
|---|
| 457 | fHelpDialog->raise();
|
|---|
| 458 | fHelpDialog->activateWindow();
|
|---|
| 459 | }
|
|---|
| 460 |
|
|---|
| 461 |
|
|---|
| 462 |
|
|---|
| 463 | void G4UIQt::CreateChildTree(QTreeWidgetItem *a_parent,G4UIcommandTree *a_commandTree) {
|
|---|
| 464 |
|
|---|
| 465 | // Creating new item
|
|---|
| 466 | QTreeWidgetItem * newItem;
|
|---|
| 467 |
|
|---|
| 468 |
|
|---|
| 469 | // Get the Sub directories
|
|---|
| 470 | for (int a=0;a<a_commandTree->GetTreeEntry();a++) {
|
|---|
| 471 |
|
|---|
| 472 | QStringList stringList;
|
|---|
| 473 | stringList << QString((char*)(a_commandTree->GetTree(a+1)->GetPathName()).data()).trimmed() ;
|
|---|
| 474 | stringList << QString((char*)(a_commandTree->GetTree(a+1)->GetTitle()).data()).trimmed() ;
|
|---|
| 475 | newItem = new QTreeWidgetItem(stringList);
|
|---|
| 476 |
|
|---|
| 477 | CreateChildTree(newItem,a_commandTree->GetTree(a+1));
|
|---|
| 478 | a_parent->addChild(newItem);
|
|---|
| 479 | }
|
|---|
| 480 |
|
|---|
| 481 |
|
|---|
| 482 |
|
|---|
| 483 | // Get the Commands
|
|---|
| 484 |
|
|---|
| 485 | for (int a=0;a<a_commandTree->GetCommandEntry();a++) {
|
|---|
| 486 |
|
|---|
| 487 | QStringList stringList;
|
|---|
| 488 | stringList << QString((char*)(a_commandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed() ;
|
|---|
| 489 | stringList << QString((char*)(a_commandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed() ;
|
|---|
| 490 | newItem = new QTreeWidgetItem(stringList);
|
|---|
| 491 |
|
|---|
| 492 | a_parent->addChild(newItem);
|
|---|
| 493 | newItem->setExpanded(false);
|
|---|
| 494 | }
|
|---|
| 495 | }
|
|---|
| 496 |
|
|---|
| 497 |
|
|---|
| 498 | /**
|
|---|
| 499 | This fonction return the command list parameters in a QString
|
|---|
| 500 |
|
|---|
| 501 | */
|
|---|
| 502 | /***************************************************************************/
|
|---|
| 503 | QString G4UIQt::GetCommandList (
|
|---|
| 504 | G4UIcommand *a_command
|
|---|
| 505 | )
|
|---|
| 506 | /***************************************************************************/
|
|---|
| 507 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 508 | {
|
|---|
| 509 |
|
|---|
| 510 | QString txt;
|
|---|
| 511 | G4String commandPath = a_command->GetCommandPath();
|
|---|
| 512 | G4String rangeString = a_command->GetRange();
|
|---|
| 513 |
|
|---|
| 514 | if((commandPath.length()-1)!='/')
|
|---|
| 515 | {
|
|---|
| 516 | txt += "Command " + QString((char*)(commandPath).data()) + "\n";
|
|---|
| 517 | }
|
|---|
| 518 | txt += "Guidance :\n";
|
|---|
| 519 | G4int n_guidanceEntry = a_command->GetGuidanceEntries();
|
|---|
| 520 |
|
|---|
| 521 | for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ )
|
|---|
| 522 | { txt += QString((char*)(a_command->GetGuidanceLine(i_thGuidance)).data()) + "\n"; }
|
|---|
| 523 | if( ! rangeString.isNull() )
|
|---|
| 524 | { txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n"; }
|
|---|
| 525 | G4int n_parameterEntry = a_command->GetParameterEntries();
|
|---|
| 526 | if( n_parameterEntry > 0 )
|
|---|
| 527 | {
|
|---|
| 528 | G4UIparameter *param;
|
|---|
| 529 |
|
|---|
| 530 | // Re-implementation of G4UIparameter.cc
|
|---|
| 531 |
|
|---|
| 532 | for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ )
|
|---|
| 533 | { param = a_command->GetParameter(i_thParameter);
|
|---|
| 534 | txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
|
|---|
| 535 | if( ! param->GetParameterGuidance().isNull() )
|
|---|
| 536 | txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
|
|---|
| 537 | txt += " Parameter type : " + QString(param->GetParameterType())+ "\n";
|
|---|
| 538 | if(param->IsOmittable())
|
|---|
| 539 | { txt += " Omittable : True\n"; }
|
|---|
| 540 | else
|
|---|
| 541 | { txt += " Omittable : False\n"; }
|
|---|
| 542 | if( param->GetCurrentAsDefault() )
|
|---|
| 543 | { txt += " Default value : taken from the current value\n"; }
|
|---|
| 544 | else if( ! param->GetDefaultValue().isNull() )
|
|---|
| 545 | { txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n"; }
|
|---|
| 546 | if( ! param->GetParameterRange().isNull() )
|
|---|
| 547 | txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
|
|---|
| 548 | if( ! param->GetParameterCandidates().isNull() )
|
|---|
| 549 | txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
|
|---|
| 550 | }
|
|---|
| 551 | }
|
|---|
| 552 | return txt;
|
|---|
| 553 | }
|
|---|
| 554 |
|
|---|
| 555 |
|
|---|
| 556 |
|
|---|
| 557 | /***************************************************************************/
|
|---|
| 558 | void G4UIQt::expandHelpItem (
|
|---|
| 559 | QTreeWidgetItem *a_parent
|
|---|
| 560 | ,G4UIcommand* a_expandCommand
|
|---|
| 561 | )
|
|---|
| 562 | /***************************************************************************/
|
|---|
| 563 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 564 | {
|
|---|
| 565 | }
|
|---|
| 566 |
|
|---|
| 567 | /***************************************************************************/
|
|---|
| 568 | G4bool G4UIQt::GetHelpChoice(
|
|---|
| 569 | G4int& aInt
|
|---|
| 570 | )
|
|---|
| 571 | /***************************************************************************/
|
|---|
| 572 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 573 | {
|
|---|
| 574 | printf("G4UIQt::GetHelpChoice SHOULD NEVER GO HERE");
|
|---|
| 575 | return true;
|
|---|
| 576 | }
|
|---|
| 577 |
|
|---|
| 578 | /***************************************************************************/
|
|---|
| 579 | void G4UIQt::ExitHelp(
|
|---|
| 580 | )
|
|---|
| 581 | /***************************************************************************/
|
|---|
| 582 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 583 | {
|
|---|
| 584 | printf("G4UIQt::ExitHelp SHOULD NEVER GO HERE");
|
|---|
| 585 | }
|
|---|
| 586 |
|
|---|
| 587 |
|
|---|
| 588 | /**
|
|---|
| 589 | Event filter method. Every event from QtApplication goes here.
|
|---|
| 590 | We apply a filter only for the Up and Down Arrow press when the QLineEdit
|
|---|
| 591 | is active. If this filter match, Up arrow we give the previous command
|
|---|
| 592 | and Down arrow will give the next if exist.
|
|---|
| 593 | @param obj Emitter of the event
|
|---|
| 594 | @param event Kind of event
|
|---|
| 595 | */
|
|---|
| 596 | /***************************************************************************/
|
|---|
| 597 | bool G4UIQt::eventFilter(
|
|---|
| 598 | QObject *obj
|
|---|
| 599 | ,QEvent *event
|
|---|
| 600 | )
|
|---|
| 601 | /***************************************************************************/
|
|---|
| 602 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 603 | {
|
|---|
| 604 | if (obj == fCommandArea) {
|
|---|
| 605 | if (event->type() == QEvent::KeyPress) {
|
|---|
| 606 | QKeyEvent *e = static_cast<QKeyEvent*>(event);
|
|---|
| 607 | if ((e->key() == (Qt::Key_Down)) ||
|
|---|
| 608 | (e->key() == (Qt::Key_PageDown)) ||
|
|---|
| 609 | (e->key() == (Qt::Key_Up)) ||
|
|---|
| 610 | (e->key() == (Qt::Key_PageUp))) {
|
|---|
| 611 | int selection = fCommandHistoryArea->currentRow();
|
|---|
| 612 | printf("-selection : %d\n",selection);
|
|---|
| 613 | if (fCommandHistoryArea->count()) {
|
|---|
| 614 | if (selection == -1) {
|
|---|
| 615 | selection = fCommandHistoryArea->count()-1;
|
|---|
| 616 | }
|
|---|
| 617 | printf("selection : %d\n",selection);
|
|---|
| 618 | if (e->key() == (Qt::Key_Down)) {
|
|---|
| 619 | printf("****************KEY PRESSED DOWN*****%d <= %d\n",selection,fCommandHistoryArea->count());
|
|---|
| 620 | if (selection <(fCommandHistoryArea->count()-1))
|
|---|
| 621 | selection++;
|
|---|
| 622 | } else if (e->key() == (Qt::Key_PageDown)) {
|
|---|
| 623 | selection = fCommandHistoryArea->count()-1;
|
|---|
| 624 | printf("****************KEY PRESSED PAGE DOWN*****\n");
|
|---|
| 625 | } else if (e->key() == (Qt::Key_Up)) {
|
|---|
| 626 | if (selection >0)
|
|---|
| 627 | selection --;
|
|---|
| 628 | printf("****************KEY PRESSED UP*****\n");
|
|---|
| 629 | } else if (e->key() == (Qt::Key_PageUp)) {
|
|---|
| 630 | selection = 0;
|
|---|
| 631 | printf("****************KEY PRESSED PAGE UP*****\n");
|
|---|
| 632 | }
|
|---|
| 633 | fCommandHistoryArea->clearSelection();
|
|---|
| 634 | fCommandHistoryArea->item(selection)->setSelected(true);
|
|---|
| 635 | }
|
|---|
| 636 | }
|
|---|
| 637 | }
|
|---|
| 638 | }
|
|---|
| 639 |
|
|---|
| 640 | // pass the event on to the parent class
|
|---|
| 641 | return QObject::eventFilter(obj, event);
|
|---|
| 642 | }
|
|---|
| 643 |
|
|---|
| 644 |
|
|---|
| 645 |
|
|---|
| 646 |
|
|---|
| 647 | /***************************************************************************/
|
|---|
| 648 | //
|
|---|
| 649 | // SLOTS DEFINITIONS
|
|---|
| 650 | //
|
|---|
| 651 | /***************************************************************************/
|
|---|
| 652 |
|
|---|
| 653 | /***************************************************************************/
|
|---|
| 654 | void G4UIQt::showHelpCallback (
|
|---|
| 655 | )
|
|---|
| 656 | /***************************************************************************/
|
|---|
| 657 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 658 | {
|
|---|
| 659 | TerminalHelp("");
|
|---|
| 660 | }
|
|---|
| 661 |
|
|---|
| 662 | /***************************************************************************/
|
|---|
| 663 | void G4UIQt::clearButtonCallback (
|
|---|
| 664 | )
|
|---|
| 665 | /***************************************************************************/
|
|---|
| 666 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 667 | {
|
|---|
| 668 | fTextArea->clear();
|
|---|
| 669 | }
|
|---|
| 670 |
|
|---|
| 671 |
|
|---|
| 672 | /**
|
|---|
| 673 | Callback call when "click on a menu entry.
|
|---|
| 674 | Send the associated command to geant4
|
|---|
| 675 | */
|
|---|
| 676 | void G4UIQt::commandEnteredCallback (
|
|---|
| 677 | )
|
|---|
| 678 | /***************************************************************************/
|
|---|
| 679 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 680 | {
|
|---|
| 681 | printf ("debug : callback\n");
|
|---|
| 682 | G4String command (fCommandArea->text().toStdString().c_str());
|
|---|
| 683 | if (fCommandArea->text().toStdString().c_str() != "") {
|
|---|
| 684 | fCommandHistoryArea->addItem(fCommandArea->text());
|
|---|
| 685 |
|
|---|
| 686 | if (command(0,4) != "help") {
|
|---|
| 687 | ApplyShellCommand (command,exitSession,exitPause);
|
|---|
| 688 | } else {
|
|---|
| 689 | printf ("terminal help\n");
|
|---|
| 690 | TerminalHelp(command);
|
|---|
| 691 | }
|
|---|
| 692 | if(exitSession==true)
|
|---|
| 693 | SessionTerminate();
|
|---|
| 694 | }
|
|---|
| 695 | fCommandArea->setText("");
|
|---|
| 696 | }
|
|---|
| 697 |
|
|---|
| 698 | /**
|
|---|
| 699 | Callback call when "enter" clicked on the command zone.
|
|---|
| 700 | Send the command to geant4
|
|---|
| 701 | */
|
|---|
| 702 | void G4UIQt::buttonCallback (
|
|---|
| 703 | const QString& a_command
|
|---|
| 704 | )
|
|---|
| 705 | /***************************************************************************/
|
|---|
| 706 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 707 | {
|
|---|
| 708 | G4String ss = G4String(a_command.toStdString().c_str());
|
|---|
| 709 | printf ("debug : execute:\n-%s- %d %d \n",ss.data(),exitSession,exitPause);
|
|---|
| 710 | ApplyShellCommand(ss,exitSession,exitPause);
|
|---|
| 711 | if(exitSession==true)
|
|---|
| 712 | SessionTerminate();
|
|---|
| 713 | }
|
|---|
| 714 | /**
|
|---|
| 715 | This callback is activated when user selected a item in the help tree
|
|---|
| 716 | */
|
|---|
| 717 | void G4UIQt::helpTreeCallback (
|
|---|
| 718 | )
|
|---|
| 719 | /***************************************************************************/
|
|---|
| 720 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 721 | {
|
|---|
| 722 | // G4bool GetHelpChoice(G4int&);
|
|---|
| 723 | QTreeWidgetItem* item = NULL;
|
|---|
| 724 | if (!fHelpTreeWidget)
|
|---|
| 725 | return ;
|
|---|
| 726 |
|
|---|
| 727 | if (!fHelpArea)
|
|---|
| 728 | return;
|
|---|
| 729 |
|
|---|
| 730 | QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
|
|---|
| 731 | if (list.isEmpty())
|
|---|
| 732 | return;
|
|---|
| 733 | item = list.first();
|
|---|
| 734 | if (!item)
|
|---|
| 735 | return;
|
|---|
| 736 |
|
|---|
| 737 | G4UImanager* UI = G4UImanager::GetUIpointer();
|
|---|
| 738 | if(UI==NULL) return;
|
|---|
| 739 | G4UIcommandTree * treeTop = UI->GetTree();
|
|---|
| 740 | G4UIcommand* command = treeTop->FindPath(item->text (1).toStdString().c_str());
|
|---|
| 741 | if (command) {
|
|---|
| 742 | fHelpArea->setText(GetCommandList(command));
|
|---|
| 743 | } else {
|
|---|
| 744 | // this is not a command, this is a sub directory
|
|---|
| 745 | // We display the Title
|
|---|
| 746 | fHelpArea->setText(item->text (1).toStdString().c_str());
|
|---|
| 747 | }
|
|---|
| 748 | }
|
|---|
| 749 |
|
|---|
| 750 |
|
|---|
| 751 |
|
|---|
| 752 | void G4UIQt::commandHistoryCallback(
|
|---|
| 753 | )
|
|---|
| 754 | /***************************************************************************/
|
|---|
| 755 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 756 | {
|
|---|
| 757 | // G4bool GetHelpChoice(G4int&);
|
|---|
| 758 | QListWidgetItem* item = NULL;
|
|---|
| 759 | if (!fCommandHistoryArea)
|
|---|
| 760 | return ;
|
|---|
| 761 |
|
|---|
| 762 |
|
|---|
| 763 | QList<QListWidgetItem *> list =fCommandHistoryArea->selectedItems();
|
|---|
| 764 | if (list.isEmpty())
|
|---|
| 765 | return;
|
|---|
| 766 | item = list.first();
|
|---|
| 767 | if (!item)
|
|---|
| 768 | return;
|
|---|
| 769 | fCommandArea->setText(item->text());
|
|---|
| 770 |
|
|---|
| 771 | }
|
|---|
| 772 |
|
|---|
| 773 | #endif
|
|---|