| 1 | //
|
|---|
| 2 | // ********************************************************************
|
|---|
| 3 | // * License and Disclaimer *
|
|---|
| 4 | // * *
|
|---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of *
|
|---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and *
|
|---|
| 7 | // * conditions of the Geant4 Software License, included in the file *
|
|---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These *
|
|---|
| 9 | // * include a list of copyright holders. *
|
|---|
| 10 | // * *
|
|---|
| 11 | // * Neither the authors of this software system, nor their employing *
|
|---|
| 12 | // * institutes,nor the agencies providing financial support for this *
|
|---|
| 13 | // * work make any representation or warranty, express or implied, *
|
|---|
| 14 | // * regarding this software system or assume any liability for its *
|
|---|
| 15 | // * use. Please see the license in the file LICENSE and URL above *
|
|---|
| 16 | // * for the full disclaimer and the limitation of liability. *
|
|---|
| 17 | // * *
|
|---|
| 18 | // * This code implementation is the result of the scientific and *
|
|---|
| 19 | // * technical work of the GEANT4 collaboration. *
|
|---|
| 20 | // * By using, copying, modifying or distributing the software (or *
|
|---|
| 21 | // * any work based on the software) you agree to acknowledge its *
|
|---|
| 22 | // * use in resulting scientific publications, and indicate your *
|
|---|
| 23 | // * acceptance of all terms of the Geant4 Software license. *
|
|---|
| 24 | // ********************************************************************
|
|---|
| 25 | //
|
|---|
| 26 | //
|
|---|
| 27 | // $Id: G4UIQt.cc,v 1.37 2010/05/20 07:01:03 lgarnier Exp $
|
|---|
| 28 | // GEANT4 tag $Name: $
|
|---|
| 29 | //
|
|---|
| 30 | // L. Garnier
|
|---|
| 31 |
|
|---|
| 32 | #ifdef G4UI_BUILD_QT_SESSION
|
|---|
| 33 |
|
|---|
| 34 | #include "G4Types.hh"
|
|---|
| 35 |
|
|---|
| 36 | #include <string.h>
|
|---|
| 37 |
|
|---|
| 38 | #include "G4UIQt.hh"
|
|---|
| 39 | #include "G4UImanager.hh"
|
|---|
| 40 | #include "G4StateManager.hh"
|
|---|
| 41 | #include "G4UIcommandTree.hh"
|
|---|
| 42 | #include "G4UIcommandStatus.hh"
|
|---|
| 43 |
|
|---|
| 44 | #include "G4Qt.hh"
|
|---|
| 45 |
|
|---|
| 46 | #include <qapplication.h>
|
|---|
| 47 | #include <qlineedit.h>
|
|---|
| 48 | #include <qwidget.h>
|
|---|
| 49 | #include <qmenubar.h>
|
|---|
| 50 | #include <qlayout.h>
|
|---|
| 51 | #include <qpushbutton.h>
|
|---|
| 52 | #include <qlabel.h>
|
|---|
| 53 | #include <qtoolbox.h>
|
|---|
| 54 | #include <qsplitter.h>
|
|---|
| 55 | #include <qscrollbar.h>
|
|---|
| 56 | #include <qdialog.h>
|
|---|
| 57 | #include <qevent.h>
|
|---|
| 58 | #include <qtextedit.h>
|
|---|
| 59 | #include <qsignalmapper.h>
|
|---|
| 60 | #include <qtabwidget.h>
|
|---|
| 61 | #include <qtabbar.h>
|
|---|
| 62 | #include <qstringlist.h>
|
|---|
| 63 |
|
|---|
| 64 | #include <qmainwindow.h>
|
|---|
| 65 | #if QT_VERSION >= 0x040000
|
|---|
| 66 | #include <qmenu.h>
|
|---|
| 67 | #include <qlistwidget.h>
|
|---|
| 68 | #include <qtreewidget.h>
|
|---|
| 69 | #include <QResizeEvent>
|
|---|
| 70 | #else
|
|---|
| 71 | #include <qaction.h>
|
|---|
| 72 | #include <qheader.h>
|
|---|
| 73 | #include <qlistview.h>
|
|---|
| 74 | #include <qpopupmenu.h>
|
|---|
| 75 | #include <qwidgetlist.h>
|
|---|
| 76 | #endif
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 | #include <stdlib.h>
|
|---|
| 81 |
|
|---|
| 82 | // Pourquoi Static et non variables de classe ?
|
|---|
| 83 | static G4bool exitSession = true;
|
|---|
| 84 | static G4bool exitPause = true;
|
|---|
| 85 |
|
|---|
| 86 | /** Build a Qt window with a menubar, output area and promt area<br>
|
|---|
| 87 | <pre>
|
|---|
| 88 | +-----------------------+
|
|---|
| 89 | |exit menu| |
|
|---|
| 90 | | |
|
|---|
| 91 | | +-------------------+ |
|
|---|
| 92 | | | | |
|
|---|
| 93 | | | Output area | |
|
|---|
| 94 | | | | |
|
|---|
| 95 | | +-------------------+ |
|
|---|
| 96 | | | clear | |
|
|---|
| 97 | | +-------------------+ |
|
|---|
| 98 | | | promt history | |
|
|---|
| 99 | | +-------------------+ |
|
|---|
| 100 | | +-------------------+ |
|
|---|
| 101 | | |> promt area | |
|
|---|
| 102 | | +-------------------+ |
|
|---|
| 103 | +-----------------------+
|
|---|
| 104 | </pre>
|
|---|
| 105 | */
|
|---|
| 106 | G4UIQt::G4UIQt (
|
|---|
| 107 | int argc
|
|---|
| 108 | ,char** argv
|
|---|
| 109 | )
|
|---|
| 110 | :fG4cout("")
|
|---|
| 111 | ,fHelpTreeWidget(NULL)
|
|---|
| 112 | ,fHelpTBWidget(NULL)
|
|---|
| 113 | ,fHistoryTBWidget(NULL)
|
|---|
| 114 | ,fCoutTBWidget(NULL)
|
|---|
| 115 | ,fVisParametersTBWidget(NULL)
|
|---|
| 116 | ,fViewComponentsTBWidget(NULL)
|
|---|
| 117 | ,fTabWidget(NULL)
|
|---|
| 118 | ,fCoutText("Output")
|
|---|
| 119 | {
|
|---|
| 120 |
|
|---|
| 121 | G4Qt* interactorManager = G4Qt::getInstance (argc,argv,(char*)"Qt");
|
|---|
| 122 | if (!(QApplication*)interactorManager->GetMainInteractor()) {
|
|---|
| 123 | G4cout << "G4UIQt : Unable to init Qt. Aborted" << G4endl;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | G4UImanager* UI = G4UImanager::GetUIpointer();
|
|---|
| 127 | if(UI!=NULL) UI->SetSession(this);
|
|---|
| 128 | if(UI!=NULL) UI->SetG4UIWindow(this);
|
|---|
| 129 |
|
|---|
| 130 | // Check if already define in external app QMainWindow
|
|---|
| 131 | bool found = false;
|
|---|
| 132 | #if QT_VERSION < 0x040000
|
|---|
| 133 | // theses lines does nothing exept this one "GLWindow = new QDialog(0..."
|
|---|
| 134 | // but if I comment them, it doesn't work...
|
|---|
| 135 | QWidgetList *list = QApplication::allWidgets();
|
|---|
| 136 | QWidgetListIt it( *list ); // iterate over the widgets
|
|---|
| 137 | QWidget * widget;
|
|---|
| 138 | while ( (widget=it.current()) != 0 ) { // for each widget...
|
|---|
| 139 | ++it;
|
|---|
| 140 | if ((found== false) && (widget->inherits("QMainWindow"))) {
|
|---|
| 141 | found = true;
|
|---|
| 142 | }
|
|---|
| 143 | }
|
|---|
| 144 | delete list; // delete the list, not the widgets
|
|---|
| 145 | #else
|
|---|
| 146 | foreach (QWidget *widget, QApplication::allWidgets()) {
|
|---|
| 147 | if ((found== false) && (widget->inherits("QMainWindow"))) {
|
|---|
| 148 | found = true;
|
|---|
| 149 | }
|
|---|
| 150 | }
|
|---|
| 151 | #endif
|
|---|
| 152 |
|
|---|
| 153 | if (found) {
|
|---|
| 154 | G4cout << "G4UIQt : Found an external App with a QMainWindow already defined. Aborted" << G4endl;
|
|---|
| 155 | return ;
|
|---|
| 156 | }
|
|---|
| 157 | fMainWindow = new QMainWindow();
|
|---|
| 158 |
|
|---|
| 159 | #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 160 | printf("G4UIQt::Initialise after main window creation +++++++++++\n");
|
|---|
| 161 | #endif
|
|---|
| 162 |
|
|---|
| 163 | QWidget *mainWidget = new QWidget(fMainWindow);
|
|---|
| 164 | #if QT_VERSION < 0x040000
|
|---|
| 165 | fMyVSplitter = new QSplitter(Qt::Horizontal,fMainWindow);
|
|---|
| 166 | fToolBox = new QToolBox(fMyVSplitter);
|
|---|
| 167 | #else
|
|---|
| 168 | fMyVSplitter = new QSplitter(Qt::Horizontal,fMainWindow);
|
|---|
| 169 | fToolBox = new QToolBox();
|
|---|
| 170 | #endif
|
|---|
| 171 |
|
|---|
| 172 | // Set layouts
|
|---|
| 173 |
|
|---|
| 174 | // Add a empty tabwidget
|
|---|
| 175 | fTabWidget = new G4QTabWidget(fMyVSplitter);
|
|---|
| 176 | #if QT_VERSION >= 0x040500
|
|---|
| 177 | fTabWidget->setTabsClosable (true);
|
|---|
| 178 | #endif
|
|---|
| 179 |
|
|---|
| 180 | #if QT_VERSION >= 0x040200
|
|---|
| 181 | fTabWidget->setUsesScrollButtons (true);
|
|---|
| 182 | #endif
|
|---|
| 183 |
|
|---|
| 184 | QWidget* commandLineWidget = new QWidget(mainWidget);
|
|---|
| 185 | #if QT_VERSION < 0x040000
|
|---|
| 186 | QVBoxLayout *layoutCommandLine = new QVBoxLayout(commandLineWidget);
|
|---|
| 187 | #else
|
|---|
| 188 | QVBoxLayout *layoutCommandLine = new QVBoxLayout();
|
|---|
| 189 | #endif
|
|---|
| 190 |
|
|---|
| 191 | // fill them
|
|---|
| 192 |
|
|---|
| 193 | fCommandLabel = new QLabel("",commandLineWidget);
|
|---|
| 194 |
|
|---|
| 195 | fCommandArea = new QLineEdit(commandLineWidget);
|
|---|
| 196 | fCommandArea->installEventFilter(this);
|
|---|
| 197 | #if QT_VERSION < 0x040000
|
|---|
| 198 | fCommandArea->setActiveWindow();
|
|---|
| 199 | #else
|
|---|
| 200 | fCommandArea->activateWindow();
|
|---|
| 201 | #endif
|
|---|
| 202 |
|
|---|
| 203 | #if QT_VERSION < 0x040000
|
|---|
| 204 | fCommandArea->setFocusPolicy ( QWidget::StrongFocus );
|
|---|
| 205 | fCommandArea->setFocus();
|
|---|
| 206 | #else
|
|---|
| 207 | fCommandArea->setFocusPolicy ( Qt::StrongFocus );
|
|---|
| 208 | fCommandArea->setFocus(Qt::TabFocusReason);
|
|---|
| 209 | #endif
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 | layoutCommandLine->addWidget(fCommandLabel);
|
|---|
| 214 | layoutCommandLine->addWidget(fCommandArea);
|
|---|
| 215 | #if QT_VERSION >= 0x040000
|
|---|
| 216 | QVBoxLayout *mainLayout = new QVBoxLayout();
|
|---|
| 217 | #else
|
|---|
| 218 | QVBoxLayout *mainLayout = new QVBoxLayout(mainWidget);
|
|---|
| 219 | #endif
|
|---|
| 220 |
|
|---|
| 221 | fHelpTBWidget = new QWidget(fToolBox);
|
|---|
| 222 | fHistoryTBWidget = new QWidget(fToolBox);
|
|---|
| 223 | fCoutTBWidget = new QWidget(fToolBox);
|
|---|
| 224 | fVisParametersTBWidget = new QWidget(fToolBox);
|
|---|
| 225 | fViewComponentsTBWidget = new QWidget(fToolBox);
|
|---|
| 226 |
|
|---|
| 227 | CreateVisParametersTBWidget();
|
|---|
| 228 | CreateViewComponentsTBWidget();
|
|---|
| 229 | CreateHelpTBWidget();
|
|---|
| 230 | CreateCoutTBWidget();
|
|---|
| 231 | CreateHistoryTBWidget();
|
|---|
| 232 |
|
|---|
| 233 | // the splitter
|
|---|
| 234 | // fToolBox->addItem(fVisParametersTBWidget,"Vis parameters");
|
|---|
| 235 | // fToolBox->addItem(fViewComponentsTBWidget,"Viewer components");
|
|---|
| 236 | fToolBox->addItem(fHelpTBWidget,"Help");
|
|---|
| 237 | fToolBox->addItem(fCoutTBWidget,"Cout");
|
|---|
| 238 | fToolBox->addItem(fHistoryTBWidget,"History");
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 | fToolBox->setSizePolicy (QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed));
|
|---|
| 243 | fTabWidget->setSizePolicy (QSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum));
|
|---|
| 244 |
|
|---|
| 245 | QSizePolicy policy = fTabWidget->sizePolicy();
|
|---|
| 246 | #if QT_VERSION < 0x040000
|
|---|
| 247 | policy.setHorStretch(1);
|
|---|
| 248 | policy.setVerStretch(1);
|
|---|
| 249 | #else
|
|---|
| 250 | policy.setHorizontalStretch(1);
|
|---|
| 251 | policy.setVerticalStretch(1);
|
|---|
| 252 | #endif
|
|---|
| 253 | fTabWidget->setSizePolicy(policy);
|
|---|
| 254 |
|
|---|
| 255 | fEmptyViewerTabLabel = new QLabel(QString(" If you want to have a Viewer, please use /vis/open commands. "));
|
|---|
| 256 |
|
|---|
| 257 | // Only at creation. Will be set visible when sessionStart();
|
|---|
| 258 | #if QT_VERSION >= 0x040000
|
|---|
| 259 | #if QT_VERSION >= 0x040200
|
|---|
| 260 | fTabWidget->setVisible(false);
|
|---|
| 261 | fEmptyViewerTabLabel->setVisible(false);
|
|---|
| 262 | #else
|
|---|
| 263 | fTabWidget->hide();
|
|---|
| 264 | fEmptyViewerTabLabel->hide();
|
|---|
| 265 | #endif
|
|---|
| 266 | #else
|
|---|
| 267 | fTabWidget->hide();
|
|---|
| 268 | fEmptyViewerTabLabel->hide();
|
|---|
| 269 | #endif
|
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 | // fMyVSplitter->addWidget(fTabWidget);
|
|---|
| 273 |
|
|---|
| 274 | // unset parent fot TabWidget
|
|---|
| 275 | #if QT_VERSION < 0x040000
|
|---|
| 276 | fTabWidget->reparent(0,0,QPoint(0,0));
|
|---|
| 277 | #else
|
|---|
| 278 | fMyVSplitter->addWidget(fToolBox);
|
|---|
| 279 | fMyVSplitter->addWidget(fEmptyViewerTabLabel);
|
|---|
| 280 | fTabWidget->setParent(0);
|
|---|
| 281 | #endif
|
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 | #if QT_VERSION >= 0x040000
|
|---|
| 285 | commandLineWidget->setLayout(layoutCommandLine);
|
|---|
| 286 | #endif
|
|---|
| 287 | commandLineWidget->setSizePolicy (QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
|
|---|
| 288 | mainLayout->addWidget(fMyVSplitter,1);
|
|---|
| 289 | mainLayout->addWidget(commandLineWidget);
|
|---|
| 290 |
|
|---|
| 291 | #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 292 | printf("G4UIQt::G4UIQt :: 5\n");
|
|---|
| 293 | #endif
|
|---|
| 294 |
|
|---|
| 295 | #if QT_VERSION >= 0x040000
|
|---|
| 296 | mainWidget->setLayout(mainLayout);
|
|---|
| 297 | #endif
|
|---|
| 298 |
|
|---|
| 299 | fMainWindow->setCentralWidget(mainWidget);
|
|---|
| 300 |
|
|---|
| 301 | #if QT_VERSION < 0x040000
|
|---|
| 302 |
|
|---|
| 303 | // Add a quit subMenu
|
|---|
| 304 | QPopupMenu *fileMenu = new QPopupMenu( fMainWindow);
|
|---|
| 305 | fileMenu->insertItem( "&Quit", this, SLOT(ExitSession()), CTRL+Key_Q );
|
|---|
| 306 | fMainWindow->menuBar()->insertItem( QString("&File"), fileMenu );
|
|---|
| 307 |
|
|---|
| 308 | #else
|
|---|
| 309 |
|
|---|
| 310 | // Add a quit subMenu
|
|---|
| 311 | QMenu *fileMenu = fMainWindow->menuBar()->addMenu("File");
|
|---|
| 312 | fileMenu->addAction("Quit", this, SLOT(ExitSession()));
|
|---|
| 313 |
|
|---|
| 314 | #endif
|
|---|
| 315 |
|
|---|
| 316 | AddInteractor ("file",(G4Interactor)fileMenu);
|
|---|
| 317 | #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 318 | printf("G4UIQt::G4UIQt :: 6\n");
|
|---|
| 319 | #endif
|
|---|
| 320 |
|
|---|
| 321 | // Connect signal
|
|---|
| 322 | connect(fCommandArea, SIGNAL(returnPressed()), SLOT(CommandEnteredCallback()));
|
|---|
| 323 | connect(fTabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(TabCloseCallback(int)));
|
|---|
| 324 | connect(fTabWidget, SIGNAL(currentChanged ( int ) ), SLOT(UpdateTabWidget(int)));
|
|---|
| 325 | connect(fToolBox, SIGNAL(currentChanged(int)), SLOT(ToolBoxActivated(int)));
|
|---|
| 326 |
|
|---|
| 327 | if(UI!=NULL) UI->SetCoutDestination(this); // TO KEEP
|
|---|
| 328 |
|
|---|
| 329 | #if QT_VERSION < 0x040000
|
|---|
| 330 | fMainWindow->setCaption( tr( "G4UI Session" ));
|
|---|
| 331 | fMainWindow->resize(900,600);
|
|---|
| 332 | fMainWindow->move(50,100);
|
|---|
| 333 | #else
|
|---|
| 334 | fMainWindow->setWindowTitle( tr("G4UI Session") );
|
|---|
| 335 | fMainWindow->resize(900,600);
|
|---|
| 336 | fMainWindow->move(QPoint(50,100));
|
|---|
| 337 | #endif
|
|---|
| 338 |
|
|---|
| 339 | // Set visible
|
|---|
| 340 | #if QT_VERSION >= 0x040000
|
|---|
| 341 | #if QT_VERSION >= 0x040200
|
|---|
| 342 | fMainWindow->setVisible(true);
|
|---|
| 343 | #else
|
|---|
| 344 | fMainWindow->show();
|
|---|
| 345 | #endif
|
|---|
| 346 | #else
|
|---|
| 347 | fMainWindow->show();
|
|---|
| 348 | #endif
|
|---|
| 349 |
|
|---|
| 350 | #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 351 | printf("G4UIQt::G4UIQt END\n");
|
|---|
| 352 | #endif
|
|---|
| 353 | }
|
|---|
| 354 |
|
|---|
| 355 |
|
|---|
| 356 |
|
|---|
| 357 | G4UIQt::~G4UIQt(
|
|---|
| 358 | )
|
|---|
| 359 | {
|
|---|
| 360 | #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 361 | printf("G4UIQt::~G4UIQt Delete\n");
|
|---|
| 362 | #endif
|
|---|
| 363 | G4UImanager* UI = G4UImanager::GetUIpointer(); // TO KEEP
|
|---|
| 364 | if(UI!=NULL) { // TO KEEP
|
|---|
| 365 | UI->SetSession(NULL); // TO KEEP
|
|---|
| 366 | UI->SetG4UIWindow(NULL);
|
|---|
| 367 | UI->SetCoutDestination(NULL); // TO KEEP
|
|---|
| 368 | }
|
|---|
| 369 |
|
|---|
| 370 | if (fMainWindow!=NULL) {
|
|---|
| 371 | #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 372 | printf("G4UIQt::~G4UIQt DELETE fMainWindow\n");
|
|---|
| 373 | #endif
|
|---|
| 374 | delete fMainWindow;
|
|---|
| 375 | }
|
|---|
| 376 | }
|
|---|
| 377 |
|
|---|
| 378 | /** Create the History ToolBox Widget
|
|---|
| 379 | */
|
|---|
| 380 | void G4UIQt::CreateHistoryTBWidget(
|
|---|
| 381 | )
|
|---|
| 382 | {
|
|---|
| 383 |
|
|---|
| 384 | #if QT_VERSION < 0x040000
|
|---|
| 385 | QVBoxLayout *layoutHistoryTB = new QVBoxLayout(fHistoryTBWidget);
|
|---|
| 386 |
|
|---|
| 387 | fHistoryTBTableList = new QListView(fHistoryTBWidget);
|
|---|
| 388 | fHistoryTBTableList->setSorting (-1, FALSE);
|
|---|
| 389 | fHistoryTBTableList->setSelectionMode(QListView::Single);
|
|---|
| 390 | fHistoryTBTableList->addColumn("");
|
|---|
| 391 | fHistoryTBTableList->header()->hide();
|
|---|
| 392 | connect(fHistoryTBTableList, SIGNAL(selectionChanged()), SLOT(CommandHistoryCallback()));
|
|---|
| 393 | #else
|
|---|
| 394 | QVBoxLayout *layoutHistoryTB = new QVBoxLayout();
|
|---|
| 395 | fHistoryTBTableList = new QListWidget();
|
|---|
| 396 | fHistoryTBTableList->setSelectionMode(QAbstractItemView::SingleSelection);
|
|---|
| 397 | connect(fHistoryTBTableList, SIGNAL(itemSelectionChanged()), SLOT(CommandHistoryCallback()));
|
|---|
| 398 | #endif
|
|---|
| 399 | fHistoryTBTableList->installEventFilter(this);
|
|---|
| 400 |
|
|---|
| 401 | layoutHistoryTB->addWidget(fHistoryTBTableList);
|
|---|
| 402 |
|
|---|
| 403 | #if QT_VERSION >= 0x040000
|
|---|
| 404 | fHistoryTBWidget->setLayout(layoutHistoryTB);
|
|---|
| 405 | #endif
|
|---|
| 406 | }
|
|---|
| 407 |
|
|---|
| 408 | /** Create the Help ToolBox Widget
|
|---|
| 409 | */
|
|---|
| 410 | void G4UIQt::CreateHelpTBWidget(
|
|---|
| 411 | )
|
|---|
| 412 | {
|
|---|
| 413 |
|
|---|
| 414 |
|
|---|
| 415 | #if QT_VERSION < 0x040000
|
|---|
| 416 | QWidget *helpWidget = new QWidget(fHelpTBWidget);
|
|---|
| 417 | QHBoxLayout *helpLayout = new QHBoxLayout(helpWidget);
|
|---|
| 418 | QVBoxLayout *vLayout = new QVBoxLayout(fHelpTBWidget);
|
|---|
| 419 | fHelpVSplitter = new QSplitter(Qt::Horizontal,fHelpTBWidget);
|
|---|
| 420 | #else
|
|---|
| 421 | QWidget *helpWidget = new QWidget();
|
|---|
| 422 | QHBoxLayout *helpLayout = new QHBoxLayout();
|
|---|
| 423 | QVBoxLayout *vLayout = new QVBoxLayout();
|
|---|
| 424 | fHelpVSplitter = new QSplitter(Qt::Horizontal);
|
|---|
| 425 | #endif
|
|---|
| 426 | fHelpLine = new QLineEdit(fHelpTBWidget);
|
|---|
| 427 | helpLayout->addWidget(new QLabel("Search :",helpWidget));
|
|---|
| 428 | helpLayout->addWidget(fHelpLine);
|
|---|
| 429 | #if QT_VERSION < 0x040000
|
|---|
| 430 | connect( fHelpLine, SIGNAL( returnPressed () ), this, SLOT( LookForHelpStringCallback() ) );
|
|---|
| 431 | #else
|
|---|
| 432 | connect( fHelpLine, SIGNAL( editingFinished () ), this, SLOT( LookForHelpStringCallback() ) );
|
|---|
| 433 | #endif
|
|---|
| 434 |
|
|---|
| 435 | // Create Help tree
|
|---|
| 436 | FillHelpTree();
|
|---|
| 437 |
|
|---|
| 438 | fHelpArea = new QTextEdit(fHelpVSplitter);
|
|---|
| 439 | fHelpArea->setReadOnly(true);
|
|---|
| 440 |
|
|---|
| 441 | // Set layouts
|
|---|
| 442 |
|
|---|
| 443 | #if QT_VERSION >= 0x040000
|
|---|
| 444 | if (fHelpTreeWidget) {
|
|---|
| 445 | fHelpVSplitter->addWidget(fHelpTreeWidget);
|
|---|
| 446 | }
|
|---|
| 447 | fHelpVSplitter->addWidget(fHelpArea);
|
|---|
| 448 | #endif
|
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 | #if QT_VERSION >= 0x040000
|
|---|
| 452 | vLayout->addWidget(helpWidget);
|
|---|
| 453 | vLayout->addWidget(fHelpVSplitter,1);
|
|---|
| 454 | #endif
|
|---|
| 455 |
|
|---|
| 456 | fHelpTBWidget->setMinimumSize(50,50);
|
|---|
| 457 | fHelpTBWidget->setSizePolicy (QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
|
|---|
| 458 | // set the splitter size
|
|---|
| 459 | #if QT_VERSION >= 0x040000
|
|---|
| 460 | QList<int> list;
|
|---|
| 461 | #else
|
|---|
| 462 | QValueList<int> list;
|
|---|
| 463 | #endif
|
|---|
| 464 | list.append( 50 );
|
|---|
| 465 | list.append( 50 );
|
|---|
| 466 | fHelpVSplitter->setSizes(list);
|
|---|
| 467 |
|
|---|
| 468 | #if QT_VERSION >= 0x040000
|
|---|
| 469 | helpWidget->setLayout(helpLayout);
|
|---|
| 470 | fHelpTBWidget->setLayout(vLayout);
|
|---|
| 471 | #endif
|
|---|
| 472 | }
|
|---|
| 473 |
|
|---|
| 474 |
|
|---|
| 475 | /** Create the Cout ToolBox Widget
|
|---|
| 476 | */
|
|---|
| 477 | void G4UIQt::CreateCoutTBWidget(
|
|---|
| 478 | )
|
|---|
| 479 | {
|
|---|
| 480 | #if QT_VERSION >= 0x040000
|
|---|
| 481 | QVBoxLayout *layoutCoutTB = new QVBoxLayout();
|
|---|
| 482 | #else
|
|---|
| 483 | QVBoxLayout *layoutCoutTB = new QVBoxLayout(fCoutTBWidget);
|
|---|
| 484 | #endif
|
|---|
| 485 |
|
|---|
| 486 | fCoutTBTextArea = new QTextEdit(fCoutTBWidget);
|
|---|
| 487 | fCoutFilter = new QLineEdit(fCoutTBWidget);
|
|---|
| 488 | QLabel* coutFilterLabel = new QLabel("Filter : ",fCoutTBWidget);
|
|---|
| 489 |
|
|---|
| 490 | QPushButton *coutTBClearButton = new QPushButton("clear",fCoutTBWidget);
|
|---|
| 491 | connect(coutTBClearButton, SIGNAL(clicked()), SLOT(ClearButtonCallback()));
|
|---|
| 492 | connect(fCoutFilter, SIGNAL(textEdited ( const QString &)), SLOT(CoutFilterCallback( const QString &)));
|
|---|
| 493 |
|
|---|
| 494 | fCoutTBTextArea->setReadOnly(true);
|
|---|
| 495 |
|
|---|
| 496 | QWidget* coutButtonWidget = new QWidget(fCoutTBWidget);
|
|---|
| 497 | QHBoxLayout* layoutCoutTBButtons = new QHBoxLayout(coutButtonWidget);
|
|---|
| 498 | layoutCoutTBButtons->addWidget(coutTBClearButton);
|
|---|
| 499 | layoutCoutTBButtons->addWidget(coutFilterLabel);
|
|---|
| 500 | layoutCoutTBButtons->addWidget(fCoutFilter);
|
|---|
| 501 |
|
|---|
| 502 | layoutCoutTB->addWidget(fCoutTBTextArea);
|
|---|
| 503 | layoutCoutTB->addWidget(coutButtonWidget);
|
|---|
| 504 |
|
|---|
| 505 | #if QT_VERSION >= 0x040000
|
|---|
| 506 | fCoutTBWidget->setLayout(layoutCoutTB);
|
|---|
| 507 | #endif
|
|---|
| 508 | }
|
|---|
| 509 |
|
|---|
| 510 |
|
|---|
| 511 | /** Create the VisParameters ToolBox Widget
|
|---|
| 512 | */
|
|---|
| 513 | void G4UIQt::CreateVisParametersTBWidget(
|
|---|
| 514 | )
|
|---|
| 515 | {
|
|---|
| 516 | }
|
|---|
| 517 |
|
|---|
| 518 |
|
|---|
| 519 | /** Create the ViewComponents ToolBox Widget
|
|---|
| 520 | */
|
|---|
| 521 | void G4UIQt::CreateViewComponentsTBWidget(
|
|---|
| 522 | )
|
|---|
| 523 | {
|
|---|
| 524 | }
|
|---|
| 525 |
|
|---|
| 526 |
|
|---|
| 527 | /** Add a new tab widget.
|
|---|
| 528 | Create the tab if it was not done
|
|---|
| 529 | */
|
|---|
| 530 | bool G4UIQt::AddTabWidget(
|
|---|
| 531 | QWidget* aWidget
|
|---|
| 532 | ,QString name
|
|---|
| 533 | ,int sizeX
|
|---|
| 534 | ,int sizeY
|
|---|
| 535 | )
|
|---|
| 536 | {
|
|---|
| 537 | #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 538 | printf("G4UIQt::AddTabWidget %d %d\n",sizeX, sizeY);
|
|---|
| 539 | #endif
|
|---|
| 540 | if (!aWidget) {
|
|---|
| 541 | return false;
|
|---|
| 542 | }
|
|---|
| 543 |
|
|---|
| 544 | // Remove QLabel
|
|---|
| 545 | if ( fMyVSplitter->indexOf(fEmptyViewerTabLabel) != -1) {
|
|---|
| 546 | #if QT_VERSION < 0x040000
|
|---|
| 547 | fEmptyViewerTabLabel->reparent(0,0,QPoint(0,0));
|
|---|
| 548 | #else
|
|---|
| 549 | fEmptyViewerTabLabel->setParent(0);
|
|---|
| 550 | #endif
|
|---|
| 551 | fMyVSplitter->addWidget(fTabWidget);
|
|---|
| 552 | #if QT_VERSION < 0x040000
|
|---|
| 553 | aWidget->reparent(fTabWidget,0,QPoint(0,0));
|
|---|
| 554 | #else
|
|---|
| 555 | aWidget->setParent(fTabWidget);
|
|---|
| 556 | #endif
|
|---|
| 557 | }
|
|---|
| 558 |
|
|---|
| 559 |
|
|---|
| 560 |
|
|---|
| 561 | #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 562 | printf("G4UIQt::AddTabWidget ADD %d %d + %d %d---------------------------------------------------\n",sizeX, sizeY,sizeX-fTabWidget->width(),sizeY-fTabWidget->height());
|
|---|
| 563 | #endif
|
|---|
| 564 |
|
|---|
| 565 | #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 566 | printf("G4UIQt::AddTabWidget resize VVVVVVVVVVVG4UIQt G4UIQt G4UIQt G4UIQt G4UIQt G4UIQt G4UIQt G4UIQt \n");
|
|---|
| 567 | printf("G4UIQt::AddTabWidget resize 22222222222 W---:%d + sx:%d -fwx:%d H---:%d + sy:%d -fwy:%d TabW:%d TabH:%d G4UIQt G4UIQt aWX:%d aWY:%d\n",fMainWindow->width(),sizeX,fTabWidget->width(),fMainWindow->height(),sizeY,fTabWidget->height(),fTabWidget->width(),fTabWidget->height(),aWidget->size().height(),aWidget->size().width());
|
|---|
| 568 | #endif
|
|---|
| 569 |
|
|---|
| 570 | fMainWindow->resize(fMainWindow->width()+sizeX-fTabWidget->width(),fMainWindow->height()+sizeY-fTabWidget->height());
|
|---|
| 571 |
|
|---|
| 572 | // Problems with resize. The widgets are not realy drawn at this step,
|
|---|
| 573 | // then we have to force them on order to check the size
|
|---|
| 574 |
|
|---|
| 575 | fTabWidget->insertTab(fTabWidget->count(),aWidget,name);
|
|---|
| 576 |
|
|---|
| 577 | // if (fTabWidget->count() == 1) {
|
|---|
| 578 | // connect(fTabWidget, SIGNAL(currentChanged ( int ) ), SLOT(UpdateTabWidget(int)));
|
|---|
| 579 | // connect(fTabWidget, SIGNAL(resizeEvent ( QResizeEvent* ) ), SLOT(ResizeTabWidget( QResizeEvent*)));
|
|---|
| 580 | // }
|
|---|
| 581 |
|
|---|
| 582 | fTabWidget->setCurrentIndex(fTabWidget->count()-1);
|
|---|
| 583 | // UpdateTabWidget(fTabWidget->count()-1);
|
|---|
| 584 | // Set visible
|
|---|
| 585 | #if QT_VERSION >= 0x040000
|
|---|
| 586 | #if QT_VERSION >= 0x040200
|
|---|
| 587 | fTabWidget->setLastTabCreated(fTabWidget->currentIndex());
|
|---|
| 588 | fMainWindow->setVisible(true);
|
|---|
| 589 | #else
|
|---|
| 590 | fTabWidget->setLastTabCreated(fTabWidget->currentIndex());
|
|---|
| 591 | fMainWindow->show();
|
|---|
| 592 | #endif
|
|---|
| 593 | #else
|
|---|
| 594 | fTabWidget->setLastTabCreated(fTabWidget->currentPageIndex());
|
|---|
| 595 | fMainWindow->show();
|
|---|
| 596 | #endif
|
|---|
| 597 |
|
|---|
| 598 |
|
|---|
| 599 |
|
|---|
| 600 | // // // Check size
|
|---|
| 601 | // // int offX = (sizeX-aWidget->size().width());
|
|---|
| 602 | // // int offY = (sizeY-aWidget->size().height());
|
|---|
| 603 |
|
|---|
| 604 | // // #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 605 | // // printf("G4UIQt::AddTabWidget resize AFTER FIRST W:%d + sx:%d -fwx:%d H:%d + sy:%d -fwy:%d TabW:%d TabH:%d G4UIQt G4UIQt offX:%d offY:%d aWX:%d aWY:%d\n",fMainWindow->width(),sizeX,fTabWidget->width(),fMainWindow->height(),sizeY,fTabWidget->height(),fTabWidget->width(),fTabWidget->height(),offX,offY,aWidget->size().height(),aWidget->size().width());
|
|---|
| 606 | // // #endif
|
|---|
| 607 |
|
|---|
| 608 | // // // and correct if necessairy
|
|---|
| 609 | // // if ((offX != 0) ||(offY != 0)) {
|
|---|
| 610 | // // fMainWindow->resize(fMainWindow->width()+offX,fMainWindow->height()+offY);
|
|---|
| 611 | // // // Re-Set visible
|
|---|
| 612 | // // #if QT_VERSION >= 0x040000
|
|---|
| 613 | // // #if QT_VERSION >= 0x040200
|
|---|
| 614 | // // fMainWindow->setVisible(true);
|
|---|
| 615 | // // #else
|
|---|
| 616 | // // fMainWindow->show();
|
|---|
| 617 | // // #endif
|
|---|
| 618 | // // #else
|
|---|
| 619 | // // fMainWindow->show();
|
|---|
| 620 | // // #endif
|
|---|
| 621 | // // }
|
|---|
| 622 |
|
|---|
| 623 | // // #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 624 | // // printf("G4UIQt::AddTabWidget resize ^^^^^^^^^^^^ W:%d + sx:%d -fwx:%d H:%d + sy:%d -fwy:%d TabW:%d TabH:%d G4UIQt G4UIQt offX:%d offY:%d aWX:%d aWY:%d\n",fMainWindow->width(),sizeX,fTabWidget->width(),fMainWindow->height(),sizeY,fTabWidget->height(),fTabWidget->width(),fTabWidget->height(),offX,offY,aWidget->size().height(),aWidget->size().width());
|
|---|
| 625 | // // #endif
|
|---|
| 626 | // // #endif
|
|---|
| 627 |
|
|---|
| 628 | fTabWidget->setVisible(true);
|
|---|
| 629 |
|
|---|
| 630 | return true;
|
|---|
| 631 | }
|
|---|
| 632 |
|
|---|
| 633 |
|
|---|
| 634 | void G4UIQt::UpdateTabWidget(int tabNumber) {
|
|---|
| 635 | #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 636 | printf("G4UIQt::UpdateTabWidget %d\n",tabNumber);
|
|---|
| 637 | #endif
|
|---|
| 638 | if ( fTabWidget == NULL) {
|
|---|
| 639 | fTabWidget = new G4QTabWidget;
|
|---|
| 640 | }
|
|---|
| 641 |
|
|---|
| 642 |
|
|---|
| 643 | #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 644 | printf("G4UIQt::UpdateTabWidget CALL REPAINT tabGL\n");
|
|---|
| 645 | #endif
|
|---|
| 646 |
|
|---|
| 647 | fTabWidget->setCurrentIndex(tabNumber);
|
|---|
| 648 |
|
|---|
| 649 | // Send this signal to unblock graphic updates !
|
|---|
| 650 | fTabWidget->setVisible(true);
|
|---|
| 651 |
|
|---|
| 652 | // This will send a paintEvent to OGL Viewers
|
|---|
| 653 | fTabWidget->setTabSelected();
|
|---|
| 654 |
|
|---|
| 655 | QCoreApplication::sendPostedEvents () ;
|
|---|
| 656 |
|
|---|
| 657 | #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 658 | printf("G4UIQt::UpdateTabWidget END\n");
|
|---|
| 659 | #endif
|
|---|
| 660 | }
|
|---|
| 661 |
|
|---|
| 662 |
|
|---|
| 663 | /** Send resize event to all tabs
|
|---|
| 664 | */
|
|---|
| 665 | void G4UIQt::ResizeTabWidget( QResizeEvent* e) {
|
|---|
| 666 | for (int a=0;a<fTabWidget->count() ;a++) {
|
|---|
| 667 | #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 668 | printf("G4UIQt::ResizeTabWidget +++++++++++++++++++++++++++++++++++++++\n");
|
|---|
| 669 | #endif
|
|---|
| 670 | fTabWidget->widget(a)->resize(e->size());
|
|---|
| 671 | }
|
|---|
| 672 | }
|
|---|
| 673 |
|
|---|
| 674 |
|
|---|
| 675 | /** Start the Qt main loop
|
|---|
| 676 | */
|
|---|
| 677 | G4UIsession* G4UIQt::SessionStart (
|
|---|
| 678 | )
|
|---|
| 679 | {
|
|---|
| 680 | #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 681 | printf("G4UIQt::G4UIQt SessionStart\n");
|
|---|
| 682 | #endif
|
|---|
| 683 |
|
|---|
| 684 | G4Qt* interactorManager = G4Qt::getInstance ();
|
|---|
| 685 |
|
|---|
| 686 | Prompt("Session :");
|
|---|
| 687 | exitSession = false;
|
|---|
| 688 |
|
|---|
| 689 | fTabWidget->setVisible(true);
|
|---|
| 690 | fEmptyViewerTabLabel->setVisible(true);
|
|---|
| 691 |
|
|---|
| 692 | #if QT_VERSION >= 0x040000
|
|---|
| 693 | #if QT_VERSION >= 0x040200
|
|---|
| 694 | fMainWindow->setVisible(true);
|
|---|
| 695 | #else
|
|---|
| 696 | fMainWindow->show();
|
|---|
| 697 | #endif
|
|---|
| 698 | #else
|
|---|
| 699 | fMainWindow->show();
|
|---|
| 700 | #endif
|
|---|
| 701 |
|
|---|
| 702 | QCoreApplication::sendPostedEvents () ;
|
|---|
| 703 |
|
|---|
| 704 | #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 705 | printf("G4UIQt::G4UIQt SessionStart2\n");
|
|---|
| 706 | #endif
|
|---|
| 707 | interactorManager->DisableSecondaryLoop (); // TO KEEP
|
|---|
| 708 | if ((QApplication*)interactorManager->GetMainInteractor())
|
|---|
| 709 | ((QApplication*)interactorManager->GetMainInteractor())->exec();
|
|---|
| 710 |
|
|---|
| 711 | // on ne passe pas le dessous ? FIXME ????
|
|---|
| 712 | // je ne pense pas 13/06
|
|---|
| 713 |
|
|---|
| 714 | // void* event; // TO KEEP
|
|---|
| 715 | // while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP
|
|---|
| 716 | // interactorManager->DispatchEvent(event); // TO KEEP
|
|---|
| 717 | // if(exitSession==true) break; // TO KEEP
|
|---|
| 718 | // } // TO KEEP
|
|---|
| 719 |
|
|---|
| 720 | interactorManager->EnableSecondaryLoop ();
|
|---|
| 721 | return this;
|
|---|
| 722 | }
|
|---|
| 723 |
|
|---|
| 724 |
|
|---|
| 725 | /** Display the prompt in the prompt area
|
|---|
| 726 | @param aPrompt : string to display as the promt label
|
|---|
| 727 | //FIXME : probablement inutile puisque le seul a afficher qq chose d'autre
|
|---|
| 728 | que "session" est SecondaryLoop()
|
|---|
| 729 | */
|
|---|
| 730 | void G4UIQt::Prompt (
|
|---|
| 731 | G4String aPrompt
|
|---|
| 732 | )
|
|---|
| 733 | {
|
|---|
| 734 | if (!aPrompt) return;
|
|---|
| 735 |
|
|---|
| 736 | fCommandLabel->setText((char*)aPrompt.data());
|
|---|
| 737 | }
|
|---|
| 738 |
|
|---|
| 739 |
|
|---|
| 740 |
|
|---|
| 741 | void G4UIQt::SessionTerminate (
|
|---|
| 742 | )
|
|---|
| 743 | {
|
|---|
| 744 | G4Qt* interactorManager = G4Qt::getInstance ();
|
|---|
| 745 | fMainWindow->close();
|
|---|
| 746 | ((QApplication*)interactorManager->GetMainInteractor())->exit();
|
|---|
| 747 | }
|
|---|
| 748 |
|
|---|
| 749 |
|
|---|
| 750 |
|
|---|
| 751 | /**
|
|---|
| 752 | Called by intercoms/src/G4UImanager.cc<br>
|
|---|
| 753 | Called by visualization/management/src/G4VisCommands.cc with "EndOfEvent" argument<br>
|
|---|
| 754 | It have to pause the session command terminal.<br>
|
|---|
| 755 | Call SecondaryLoop to wait for exit event<br>
|
|---|
| 756 | @param aState
|
|---|
| 757 | @see : G4VisCommandReviewKeptEvents::SetNewValue
|
|---|
| 758 | */
|
|---|
| 759 | void G4UIQt::PauseSessionStart (
|
|---|
| 760 | G4String aState
|
|---|
| 761 | )
|
|---|
| 762 | {
|
|---|
| 763 | if (!aState) return;
|
|---|
| 764 |
|
|---|
| 765 | if(aState=="G4_pause> ") { // TO KEEP
|
|---|
| 766 | SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP
|
|---|
| 767 | } // TO KEEP
|
|---|
| 768 |
|
|---|
| 769 | if(aState=="EndOfEvent") { // TO KEEP
|
|---|
| 770 | // Picking with feed back in event data Done here !!!
|
|---|
| 771 | SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP
|
|---|
| 772 | } // TO KEEP
|
|---|
| 773 | }
|
|---|
| 774 |
|
|---|
| 775 |
|
|---|
| 776 |
|
|---|
| 777 | /**
|
|---|
| 778 | Begin the secondary loop
|
|---|
| 779 | @param a_prompt : label to display as the prompt label
|
|---|
| 780 | */
|
|---|
| 781 | void G4UIQt::SecondaryLoop (
|
|---|
| 782 | G4String aPrompt
|
|---|
| 783 | )
|
|---|
| 784 | {
|
|---|
| 785 | if (!aPrompt) return;
|
|---|
| 786 |
|
|---|
| 787 | G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ?
|
|---|
| 788 | Prompt(aPrompt); // TO KEEP
|
|---|
| 789 | exitPause = false; // TO KEEP
|
|---|
| 790 | void* event; // TO KEEP
|
|---|
| 791 | while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP
|
|---|
| 792 | interactorManager->DispatchEvent(event); // TO KEEP
|
|---|
| 793 | if(exitPause==true) break; // TO KEEP
|
|---|
| 794 | } // TO KEEP
|
|---|
| 795 | Prompt("Session :"); // TO KEEP
|
|---|
| 796 | }
|
|---|
| 797 |
|
|---|
| 798 |
|
|---|
| 799 |
|
|---|
| 800 | /**
|
|---|
| 801 | Receive a cout from Geant4. We have to display it in the cout zone
|
|---|
| 802 | @param aString : label to add in the display area
|
|---|
| 803 | @return 0
|
|---|
| 804 | */
|
|---|
| 805 | G4int G4UIQt::ReceiveG4cout (
|
|---|
| 806 | G4String aString
|
|---|
| 807 | )
|
|---|
| 808 | {
|
|---|
| 809 | if (!aString) return 0;
|
|---|
| 810 |
|
|---|
| 811 | QStringList newStr;
|
|---|
| 812 |
|
|---|
| 813 | // Add to stringList
|
|---|
| 814 | #if QT_VERSION < 0x040000
|
|---|
| 815 | newStr = QStringList(QString((char*)aString.data()).simplifyWhiteSpace());
|
|---|
| 816 | #else
|
|---|
| 817 | newStr = QStringList(QString((char*)aString.data()).trimmed());
|
|---|
| 818 | #endif
|
|---|
| 819 | fG4cout += newStr;
|
|---|
| 820 |
|
|---|
| 821 | QStringList result = newStr.filter(fCoutFilter->text());
|
|---|
| 822 |
|
|---|
| 823 | if (result.join("\n").isEmpty()) {
|
|---|
| 824 | return 0;
|
|---|
| 825 | }
|
|---|
| 826 | fCoutTBTextArea->append(result.join("\n"));
|
|---|
| 827 | fCoutTBTextArea->repaint();
|
|---|
| 828 |
|
|---|
| 829 | #if QT_VERSION < 0x040000
|
|---|
| 830 | fCoutTBTextArea->verticalScrollBar()->setValue(fCoutTBTextArea->verticalScrollBar()->maxValue());
|
|---|
| 831 | #else
|
|---|
| 832 | fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
|
|---|
| 833 | #endif
|
|---|
| 834 |
|
|---|
| 835 | return 0;
|
|---|
| 836 | }
|
|---|
| 837 |
|
|---|
| 838 |
|
|---|
| 839 | /**
|
|---|
| 840 | Receive a cerr from Geant4. We have to display it in the cout zone
|
|---|
| 841 | @param aString : label to add in the display area
|
|---|
| 842 | @return 0
|
|---|
| 843 | */
|
|---|
| 844 | G4int G4UIQt::ReceiveG4cerr (
|
|---|
| 845 | G4String aString
|
|---|
| 846 | )
|
|---|
| 847 | {
|
|---|
| 848 | if (!aString) return 0;
|
|---|
| 849 |
|
|---|
| 850 | QStringList newStr;
|
|---|
| 851 |
|
|---|
| 852 | // Add to stringList
|
|---|
| 853 | #if QT_VERSION < 0x040000
|
|---|
| 854 | newStr = QStringList(QString((char*)aString.data()).simplifyWhiteSpace());
|
|---|
| 855 | #else
|
|---|
| 856 | newStr = QStringList(QString((char*)aString.data()).trimmed());
|
|---|
| 857 | #endif
|
|---|
| 858 | fG4cout += newStr;
|
|---|
| 859 |
|
|---|
| 860 | QStringList result = newStr.filter(fCoutFilter->text());
|
|---|
| 861 |
|
|---|
| 862 | #if QT_VERSION < 0x040000
|
|---|
| 863 | QColor previousColor = fCoutTBTextArea->color();
|
|---|
| 864 | fCoutTBTextArea->setColor(Qt::red);
|
|---|
| 865 | fCoutTBTextArea->append(result.join("\n"));
|
|---|
| 866 | fCoutTBTextArea->setColor(previousColor);
|
|---|
| 867 | fCoutTBTextArea->verticalScrollBar()->setValue(fCoutTBTextArea->verticalScrollBar()->maxValue());
|
|---|
| 868 | #else
|
|---|
| 869 | QColor previousColor = fCoutTBTextArea->textColor();
|
|---|
| 870 | fCoutTBTextArea->setTextColor(Qt::red);
|
|---|
| 871 | fCoutTBTextArea->append(result.join("\n"));
|
|---|
| 872 | fCoutTBTextArea->setTextColor(previousColor);
|
|---|
| 873 | fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
|
|---|
| 874 | #endif
|
|---|
| 875 | fCoutTBTextArea->repaint();
|
|---|
| 876 | return 0;
|
|---|
| 877 | }
|
|---|
| 878 |
|
|---|
| 879 |
|
|---|
| 880 |
|
|---|
| 881 | /**
|
|---|
| 882 | Add a new menu to the menu bar
|
|---|
| 883 | @param aName name of menu
|
|---|
| 884 | @param aLabel label to display
|
|---|
| 885 | */
|
|---|
| 886 | void G4UIQt::AddMenu (
|
|---|
| 887 | const char* aName
|
|---|
| 888 | ,const char* aLabel
|
|---|
| 889 | )
|
|---|
| 890 | {
|
|---|
| 891 | if (aName == NULL) return;
|
|---|
| 892 | if (aLabel == NULL) return;
|
|---|
| 893 |
|
|---|
| 894 | #if QT_VERSION < 0x040000
|
|---|
| 895 | QPopupMenu *fileMenu = new QPopupMenu( fMainWindow);
|
|---|
| 896 | fMainWindow->menuBar()->insertItem( aLabel, fileMenu );
|
|---|
| 897 | #else
|
|---|
| 898 | QMenu *fileMenu = new QMenu(aLabel);
|
|---|
| 899 | fMainWindow->menuBar()->insertMenu(fMainWindow->menuBar()->actions().last(),fileMenu);
|
|---|
| 900 | #endif
|
|---|
| 901 |
|
|---|
| 902 | AddInteractor (aName,(G4Interactor)fileMenu);
|
|---|
| 903 | }
|
|---|
| 904 |
|
|---|
| 905 |
|
|---|
| 906 | /**
|
|---|
| 907 | Add a new button to a menu
|
|---|
| 908 | @param aMenu : parent menu
|
|---|
| 909 | @param aLabel : label to display
|
|---|
| 910 | @param aCommand : command to execute as a callback
|
|---|
| 911 | */
|
|---|
| 912 | void G4UIQt::AddButton (
|
|---|
| 913 | const char* aMenu
|
|---|
| 914 | ,const char* aLabel
|
|---|
| 915 | ,const char* aCommand
|
|---|
| 916 | )
|
|---|
| 917 | {
|
|---|
| 918 | if(aMenu==NULL) return; // TO KEEP
|
|---|
| 919 | if(aLabel==NULL) return; // TO KEEP
|
|---|
| 920 | if(aCommand==NULL) return; // TO KEEP
|
|---|
| 921 |
|
|---|
| 922 | #if QT_VERSION < 0x040000
|
|---|
| 923 | QPopupMenu *parent = (QPopupMenu*)GetInteractor(aMenu);
|
|---|
| 924 | #else
|
|---|
| 925 | QMenu *parent = (QMenu*)GetInteractor(aMenu);
|
|---|
| 926 | #endif
|
|---|
| 927 |
|
|---|
| 928 | if(parent==NULL) return;
|
|---|
| 929 |
|
|---|
| 930 | QSignalMapper *signalMapper = new QSignalMapper(this);
|
|---|
| 931 | #if QT_VERSION < 0x030200
|
|---|
| 932 | QAction *action = new QAction(QString(aLabel),QString(aLabel),QKeySequence(),signalMapper, SLOT(map()));
|
|---|
| 933 | action->addTo(parent);
|
|---|
| 934 | connect(action,SIGNAL(activated()),signalMapper,SLOT(map()));
|
|---|
| 935 |
|
|---|
| 936 | #elif QT_VERSION < 0x040000
|
|---|
| 937 | QAction *action = new QAction(QString(aLabel),QKeySequence(),signalMapper, SLOT(map()));
|
|---|
| 938 | action->addTo(parent);
|
|---|
| 939 | connect(action,SIGNAL(activated()),signalMapper,SLOT(map()));
|
|---|
| 940 |
|
|---|
| 941 | #else
|
|---|
| 942 | QAction *action = parent->addAction(aLabel, signalMapper, SLOT(map()));
|
|---|
| 943 |
|
|---|
| 944 | #endif
|
|---|
| 945 | connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&)));
|
|---|
| 946 | signalMapper->setMapping(action, QString(aCommand));
|
|---|
| 947 | }
|
|---|
| 948 |
|
|---|
| 949 |
|
|---|
| 950 |
|
|---|
| 951 |
|
|---|
| 952 | void G4UIQt::ActivateCommand(
|
|---|
| 953 | G4String newCommand
|
|---|
| 954 | )
|
|---|
| 955 | {
|
|---|
| 956 | if (!fHelpTreeWidget) {
|
|---|
| 957 | return;
|
|---|
| 958 | }
|
|---|
| 959 | // Look for the choosen command "newCommand"
|
|---|
| 960 | size_t i = newCommand.index(" ");
|
|---|
| 961 | G4String targetCom ="";
|
|---|
| 962 | if( i != std::string::npos )
|
|---|
| 963 | {
|
|---|
| 964 | G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
|
|---|
| 965 | newValue.strip(G4String::both);
|
|---|
| 966 | targetCom = ModifyToFullPathCommand( newValue );
|
|---|
| 967 | }
|
|---|
| 968 | #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 969 | printf("G4UIQt::ActivateCommand found : %s \n",targetCom.data());
|
|---|
| 970 | #endif
|
|---|
| 971 | if (targetCom != "") {
|
|---|
| 972 | OpenHelpTreeOnCommand(targetCom.data());
|
|---|
| 973 | }
|
|---|
| 974 |
|
|---|
| 975 | fToolBox->setCurrentWidget(fHelpTBWidget);
|
|---|
| 976 | }
|
|---|
| 977 |
|
|---|
| 978 |
|
|---|
| 979 |
|
|---|
| 980 | /**
|
|---|
| 981 | Create the help tree widget
|
|---|
| 982 | @param parent : parent of tree widget
|
|---|
| 983 | @return the widget containing the tree or NULL if it could not have beeen created
|
|---|
| 984 | */
|
|---|
| 985 |
|
|---|
| 986 | void G4UIQt::InitHelpTree()
|
|---|
| 987 | {
|
|---|
| 988 |
|
|---|
| 989 | if (! fHelpTreeWidget ) {
|
|---|
| 990 | #if QT_VERSION < 0x040000
|
|---|
| 991 | fHelpTreeWidget = new QListView(splitter);
|
|---|
| 992 | #else
|
|---|
| 993 | fHelpTreeWidget = new QTreeWidget();
|
|---|
| 994 | #endif
|
|---|
| 995 | }
|
|---|
| 996 |
|
|---|
| 997 |
|
|---|
| 998 | // build widget
|
|---|
| 999 | #if QT_VERSION < 0x040000
|
|---|
| 1000 | fHelpTreeWidget->setSelectionMode(QListView::Single);
|
|---|
| 1001 | fHelpTreeWidget->setRootIsDecorated(true);
|
|---|
| 1002 | fHelpTreeWidget->addColumn("Command");
|
|---|
| 1003 | fHelpTreeWidget->header()->setResizeEnabled(FALSE,1);
|
|---|
| 1004 | #else
|
|---|
| 1005 | fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
|
|---|
| 1006 | QStringList labels;
|
|---|
| 1007 | labels << QString("Command");
|
|---|
| 1008 | fHelpTreeWidget->setHeaderLabels(labels);
|
|---|
| 1009 | #endif
|
|---|
| 1010 |
|
|---|
| 1011 |
|
|---|
| 1012 | #if QT_VERSION < 0x040000
|
|---|
| 1013 | connect(fHelpTreeWidget, SIGNAL(selectionChanged ()),this, SLOT(HelpTreeClicCallback()));
|
|---|
| 1014 | connect(fHelpTreeWidget, SIGNAL(doubleClicked (QListViewItem*)),this, SLOT(HelpTreeDoubleClicCallback()));
|
|---|
| 1015 | #else
|
|---|
| 1016 | connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback()));
|
|---|
| 1017 | connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback()));
|
|---|
| 1018 | #endif
|
|---|
| 1019 |
|
|---|
| 1020 | }
|
|---|
| 1021 | /**
|
|---|
| 1022 | Create the help tree widget
|
|---|
| 1023 | @param parent : parent of tree widget
|
|---|
| 1024 | @return the widget containing the tree or NULL if it could not have beeen created
|
|---|
| 1025 | */
|
|---|
| 1026 |
|
|---|
| 1027 | void G4UIQt::FillHelpTree()
|
|---|
| 1028 | {
|
|---|
| 1029 | if (! fHelpTreeWidget ) {
|
|---|
| 1030 | InitHelpTree();
|
|---|
| 1031 | }
|
|---|
| 1032 |
|
|---|
| 1033 | G4UImanager* UI = G4UImanager::GetUIpointer();
|
|---|
| 1034 | if(UI==NULL) return;
|
|---|
| 1035 | G4UIcommandTree * treeTop = UI->GetTree();
|
|---|
| 1036 |
|
|---|
| 1037 | G4int treeSize = treeTop->GetTreeEntry();
|
|---|
| 1038 | #if QT_VERSION < 0x040000
|
|---|
| 1039 | QListViewItem * newItem = NULL;
|
|---|
| 1040 | #else
|
|---|
| 1041 | QTreeWidgetItem * newItem = NULL;
|
|---|
| 1042 | #endif
|
|---|
| 1043 | QString commandText = "";
|
|---|
| 1044 | for (int a=0;a<treeSize;a++) {
|
|---|
| 1045 | // Creating new item
|
|---|
| 1046 | newItem = NULL;
|
|---|
| 1047 |
|
|---|
| 1048 | #if QT_VERSION < 0x040000
|
|---|
| 1049 | commandText = QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace();
|
|---|
| 1050 | #else
|
|---|
| 1051 | commandText = QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed();
|
|---|
| 1052 | #endif
|
|---|
| 1053 |
|
|---|
| 1054 | // if already exist, don't create it !
|
|---|
| 1055 | #if QT_VERSION < 0x040000
|
|---|
| 1056 | QListViewItem* tmpAddItem = fHelpTreeWidget->firstChild();
|
|---|
| 1057 | while (tmpAddItem != 0) {
|
|---|
| 1058 | if (!newItem) {
|
|---|
| 1059 | newItem = FindTreeItem(tmpAddItem,commandText);
|
|---|
| 1060 | }
|
|---|
| 1061 | tmpAddItem = tmpAddItem->nextSibling();
|
|---|
| 1062 | }
|
|---|
| 1063 | #else
|
|---|
| 1064 | for (int b=0;b<fHelpTreeWidget->topLevelItemCount();b++) {
|
|---|
| 1065 | if (!newItem)
|
|---|
| 1066 | newItem = FindTreeItem(fHelpTreeWidget->topLevelItem(b),commandText);
|
|---|
| 1067 | }
|
|---|
| 1068 | #endif
|
|---|
| 1069 |
|
|---|
| 1070 | if (newItem == NULL) {
|
|---|
| 1071 |
|
|---|
| 1072 | #if QT_VERSION < 0x040000
|
|---|
| 1073 | newItem = new QListViewItem(fHelpTreeWidget);
|
|---|
| 1074 | #else
|
|---|
| 1075 | newItem = new QTreeWidgetItem(fHelpTreeWidget);
|
|---|
| 1076 | #endif
|
|---|
| 1077 | newItem->setText(0,GetShortCommandPath(commandText));
|
|---|
| 1078 | }
|
|---|
| 1079 |
|
|---|
| 1080 | // look for childs
|
|---|
| 1081 | CreateChildTree(newItem,treeTop->GetTree(a+1));
|
|---|
| 1082 | }
|
|---|
| 1083 |
|
|---|
| 1084 | }
|
|---|
| 1085 |
|
|---|
| 1086 |
|
|---|
| 1087 |
|
|---|
| 1088 | /** Fill the Help Tree Widget
|
|---|
| 1089 | @param aParent : parent item to fill
|
|---|
| 1090 | @param aCommandTree : commandTree node associate with this part of the Tree
|
|---|
| 1091 | */
|
|---|
| 1092 | #if QT_VERSION < 0x040000
|
|---|
| 1093 | void G4UIQt::CreateChildTree(
|
|---|
| 1094 | QListViewItem *aParent
|
|---|
| 1095 | ,G4UIcommandTree *aCommandTree
|
|---|
| 1096 | #else
|
|---|
| 1097 | void G4UIQt::CreateChildTree(
|
|---|
| 1098 | QTreeWidgetItem *aParent
|
|---|
| 1099 | ,G4UIcommandTree *aCommandTree
|
|---|
| 1100 | #endif
|
|---|
| 1101 | )
|
|---|
| 1102 | {
|
|---|
| 1103 | if (aParent == NULL) return;
|
|---|
| 1104 | if (aCommandTree == NULL) return;
|
|---|
| 1105 |
|
|---|
| 1106 |
|
|---|
| 1107 | // Creating new item
|
|---|
| 1108 | #if QT_VERSION < 0x040000
|
|---|
| 1109 | QListViewItem * newItem;
|
|---|
| 1110 | #else
|
|---|
| 1111 | QTreeWidgetItem * newItem;
|
|---|
| 1112 | #endif
|
|---|
| 1113 |
|
|---|
| 1114 | QString commandText = "";
|
|---|
| 1115 | // Get the Sub directories
|
|---|
| 1116 | for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
|
|---|
| 1117 |
|
|---|
| 1118 | #if QT_VERSION < 0x040000
|
|---|
| 1119 | commandText = QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace();
|
|---|
| 1120 | #else
|
|---|
| 1121 | commandText = QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed();
|
|---|
| 1122 | #endif
|
|---|
| 1123 |
|
|---|
| 1124 | // if already exist, don't create it !
|
|---|
| 1125 | newItem = FindTreeItem(aParent,commandText);
|
|---|
| 1126 | if (newItem == NULL) {
|
|---|
| 1127 | #if QT_VERSION < 0x040000
|
|---|
| 1128 | newItem = new QListViewItem(aParent);
|
|---|
| 1129 | #else
|
|---|
| 1130 | newItem = new QTreeWidgetItem(aParent);
|
|---|
| 1131 | #endif
|
|---|
| 1132 | newItem->setText(0,GetShortCommandPath(commandText));
|
|---|
| 1133 | }
|
|---|
| 1134 | CreateChildTree(newItem,aCommandTree->GetTree(a+1));
|
|---|
| 1135 | }
|
|---|
| 1136 |
|
|---|
| 1137 |
|
|---|
| 1138 |
|
|---|
| 1139 | // Get the Commands
|
|---|
| 1140 |
|
|---|
| 1141 | for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
|
|---|
| 1142 |
|
|---|
| 1143 | QStringList stringList;
|
|---|
| 1144 | #if QT_VERSION < 0x040000
|
|---|
| 1145 | commandText = QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).simplifyWhiteSpace();
|
|---|
| 1146 | #else
|
|---|
| 1147 | commandText = QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed();
|
|---|
| 1148 | #endif
|
|---|
| 1149 |
|
|---|
| 1150 | // if already exist, don't create it !
|
|---|
| 1151 | newItem = FindTreeItem(aParent,commandText);
|
|---|
| 1152 | if (newItem == NULL) {
|
|---|
| 1153 | #if QT_VERSION < 0x040000
|
|---|
| 1154 | newItem = new QListViewItem(aParent);
|
|---|
| 1155 | newItem->setText(0,GetShortCommandPath(commandText));
|
|---|
| 1156 | newItem->setOpen(false);
|
|---|
| 1157 |
|
|---|
| 1158 | #else
|
|---|
| 1159 | newItem = new QTreeWidgetItem(aParent);
|
|---|
| 1160 | newItem->setText(0,GetShortCommandPath(commandText));
|
|---|
| 1161 | #if QT_VERSION < 0x040202
|
|---|
| 1162 | fHelpTreeWidget->setItemExpanded(newItem,false);
|
|---|
| 1163 | #else
|
|---|
| 1164 | newItem->setExpanded(false);
|
|---|
| 1165 | #endif
|
|---|
| 1166 | #endif
|
|---|
| 1167 | }
|
|---|
| 1168 | }
|
|---|
| 1169 | }
|
|---|
| 1170 |
|
|---|
| 1171 |
|
|---|
| 1172 | /** Find a treeItemWidget in the help tree
|
|---|
| 1173 | @param aCommand item's String to look for
|
|---|
| 1174 | @return item if found, NULL if not
|
|---|
| 1175 | */
|
|---|
| 1176 | #if QT_VERSION < 0x040000
|
|---|
| 1177 | QListViewItem* G4UIQt::FindTreeItem(
|
|---|
| 1178 | QListViewItem *aParent
|
|---|
| 1179 | #else
|
|---|
| 1180 | QTreeWidgetItem* G4UIQt::FindTreeItem(
|
|---|
| 1181 | QTreeWidgetItem *aParent
|
|---|
| 1182 | #endif
|
|---|
| 1183 | ,const QString& aCommand
|
|---|
| 1184 | )
|
|---|
| 1185 | {
|
|---|
| 1186 | if (aParent == NULL) return NULL;
|
|---|
| 1187 |
|
|---|
| 1188 | // Suppress last "/"
|
|---|
| 1189 | QString myCommand = aCommand;
|
|---|
| 1190 |
|
|---|
| 1191 | if (myCommand.lastIndexOf("/") == (myCommand.size()-1)) {
|
|---|
| 1192 | myCommand = myCommand.left(myCommand.size()-1);
|
|---|
| 1193 | }
|
|---|
| 1194 |
|
|---|
| 1195 | if (GetLongCommandPath(aParent) == myCommand)
|
|---|
| 1196 | return aParent;
|
|---|
| 1197 |
|
|---|
| 1198 | #if QT_VERSION < 0x040000
|
|---|
| 1199 | QListViewItem * tmp = NULL;
|
|---|
| 1200 | QListViewItem* tmpItem = aParent->firstChild();
|
|---|
| 1201 | while (tmpItem != 0) {
|
|---|
| 1202 | if (!tmp)
|
|---|
| 1203 | tmp = FindTreeItem(tmpItem,myCommand);
|
|---|
| 1204 | tmpItem = tmpItem->nextSibling();
|
|---|
| 1205 | }
|
|---|
| 1206 | #else
|
|---|
| 1207 | QTreeWidgetItem * tmp = NULL;
|
|---|
| 1208 | for (int a=0;a<aParent->childCount();a++) {
|
|---|
| 1209 | if (!tmp)
|
|---|
| 1210 | tmp = FindTreeItem(aParent->child(a),myCommand);
|
|---|
| 1211 | }
|
|---|
| 1212 | #endif
|
|---|
| 1213 | return tmp;
|
|---|
| 1214 | }
|
|---|
| 1215 |
|
|---|
| 1216 |
|
|---|
| 1217 |
|
|---|
| 1218 | /** Build the command list parameters in a QString<br>
|
|---|
| 1219 | Reimplement partialy the G4UIparameter.cc
|
|---|
| 1220 | @param aCommand : command to list parameters
|
|---|
| 1221 | @see G4UIparameter::List()
|
|---|
| 1222 | @see G4UIcommand::List()
|
|---|
| 1223 | @return the command list parameters, or "" if nothing
|
|---|
| 1224 | */
|
|---|
| 1225 | QString G4UIQt::GetCommandList (
|
|---|
| 1226 | const G4UIcommand *aCommand
|
|---|
| 1227 | )
|
|---|
| 1228 | {
|
|---|
| 1229 |
|
|---|
| 1230 | QString txt ="";
|
|---|
| 1231 | if (aCommand == NULL)
|
|---|
| 1232 | return txt;
|
|---|
| 1233 |
|
|---|
| 1234 | G4String commandPath = aCommand->GetCommandPath();
|
|---|
| 1235 | G4String rangeString = aCommand->GetRange();
|
|---|
| 1236 | G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
|
|---|
| 1237 | G4int n_parameterEntry = aCommand->GetParameterEntries();
|
|---|
| 1238 |
|
|---|
| 1239 | if ((commandPath == "") &&
|
|---|
| 1240 | (rangeString == "") &&
|
|---|
| 1241 | (n_guidanceEntry == 0) &&
|
|---|
| 1242 | (n_parameterEntry == 0)) {
|
|---|
| 1243 | return txt;
|
|---|
| 1244 | }
|
|---|
| 1245 |
|
|---|
| 1246 | if((commandPath.length()-1)!='/') {
|
|---|
| 1247 | txt += "Command " + QString((char*)(commandPath).data()) + "\n";
|
|---|
| 1248 | }
|
|---|
| 1249 | txt += "Guidance :\n";
|
|---|
| 1250 |
|
|---|
| 1251 | for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
|
|---|
| 1252 | txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
|
|---|
| 1253 | }
|
|---|
| 1254 | if( ! rangeString.isNull() ) {
|
|---|
| 1255 | txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n";
|
|---|
| 1256 | }
|
|---|
| 1257 | if( n_parameterEntry > 0 ) {
|
|---|
| 1258 | G4UIparameter *param;
|
|---|
| 1259 |
|
|---|
| 1260 | // Re-implementation of G4UIparameter.cc
|
|---|
| 1261 |
|
|---|
| 1262 | for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
|
|---|
| 1263 | param = aCommand->GetParameter(i_thParameter);
|
|---|
| 1264 | txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
|
|---|
| 1265 | if( ! param->GetParameterGuidance().isNull() )
|
|---|
| 1266 | txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
|
|---|
| 1267 | txt += " Parameter type : " + QString(QChar(param->GetParameterType())) + "\n";
|
|---|
| 1268 | if(param->IsOmittable()){
|
|---|
| 1269 | txt += " Omittable : True\n";
|
|---|
| 1270 | } else {
|
|---|
| 1271 | txt += " Omittable : False\n";
|
|---|
| 1272 | }
|
|---|
| 1273 | if( param->GetCurrentAsDefault() ) {
|
|---|
| 1274 | txt += " Default value : taken from the current value\n";
|
|---|
| 1275 | } else if( ! param->GetDefaultValue().isNull() ) {
|
|---|
| 1276 | txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n";
|
|---|
| 1277 | }
|
|---|
| 1278 | if( ! param->GetParameterRange().isNull() ) {
|
|---|
| 1279 | txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
|
|---|
| 1280 | }
|
|---|
| 1281 | if( ! param->GetParameterCandidates().isNull() ) {
|
|---|
| 1282 | txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
|
|---|
| 1283 | }
|
|---|
| 1284 | }
|
|---|
| 1285 | }
|
|---|
| 1286 | return txt;
|
|---|
| 1287 | }
|
|---|
| 1288 |
|
|---|
| 1289 |
|
|---|
| 1290 |
|
|---|
| 1291 | /** Implement G4VBasicShell vurtual function
|
|---|
| 1292 | */
|
|---|
| 1293 | G4bool G4UIQt::GetHelpChoice(
|
|---|
| 1294 | G4int&
|
|---|
| 1295 | )
|
|---|
| 1296 | {
|
|---|
| 1297 | #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 1298 | printf("G4UIQt::GetHelpChoice SHOULD NEVER GO HERE");
|
|---|
| 1299 | #endif
|
|---|
| 1300 | return true;
|
|---|
| 1301 | }
|
|---|
| 1302 |
|
|---|
| 1303 |
|
|---|
| 1304 | /** Event filter method. Every event from QtApplication goes here.<br/>
|
|---|
| 1305 | We apply a filter only for the Up and Down Arrow press when the QLineEdit<br/>
|
|---|
| 1306 | is active. If this filter match, Up arrow we give the previous command<br/>
|
|---|
| 1307 | and Down arrow will give the next if exist.<br/>
|
|---|
| 1308 | @param obj Emitter of the event
|
|---|
| 1309 | @param event Kind of event
|
|---|
| 1310 | */
|
|---|
| 1311 | bool G4UIQt::eventFilter( // Should stay with a minuscule eventFilter because of Qt
|
|---|
| 1312 | QObject *aObj
|
|---|
| 1313 | ,QEvent *aEvent
|
|---|
| 1314 | )
|
|---|
| 1315 | {
|
|---|
| 1316 | bool moveCommandCursor = false;
|
|---|
| 1317 | if (aObj == NULL) return false;
|
|---|
| 1318 | if (aEvent == NULL) return false;
|
|---|
| 1319 |
|
|---|
| 1320 | if (aObj == fHistoryTBTableList) {
|
|---|
| 1321 | if (aEvent->type() == QEvent::KeyPress) {
|
|---|
| 1322 | fCommandArea->setFocus();
|
|---|
| 1323 | }
|
|---|
| 1324 | }
|
|---|
| 1325 | if (aObj == fCommandArea) {
|
|---|
| 1326 | if (aEvent->type() == QEvent::KeyPress) {
|
|---|
| 1327 | QKeyEvent *e = static_cast<QKeyEvent*>(aEvent);
|
|---|
| 1328 | if ((e->key() == (Qt::Key_Down)) ||
|
|---|
| 1329 | (e->key() == (Qt::Key_PageDown)) ||
|
|---|
| 1330 | (e->key() == (Qt::Key_Up)) ||
|
|---|
| 1331 | (e->key() == (Qt::Key_PageUp))) {
|
|---|
| 1332 | #if QT_VERSION < 0x040000
|
|---|
| 1333 | // count rows...
|
|---|
| 1334 | QListViewItem* tmpItem = fHistoryTBTableList->firstChild();
|
|---|
| 1335 | int selection = -1;
|
|---|
| 1336 | int index = 0;
|
|---|
| 1337 | while (tmpItem != 0) {
|
|---|
| 1338 | if (tmpItem == fHistoryTBTableList->selectedItem()) {
|
|---|
| 1339 | selection = index;
|
|---|
| 1340 | }
|
|---|
| 1341 | index ++;
|
|---|
| 1342 | tmpItem = tmpItem->nextSibling();
|
|---|
| 1343 | }
|
|---|
| 1344 | if (fHistoryTBTableList->childCount()) {
|
|---|
| 1345 | if (selection == -1) {
|
|---|
| 1346 | selection = fHistoryTBTableList->childCount()-1;
|
|---|
| 1347 | } else {
|
|---|
| 1348 | if (e->key() == (Qt::Key_Down)) {
|
|---|
| 1349 | if (selection <(fHistoryTBTableList->childCount()-1))
|
|---|
| 1350 | selection++;
|
|---|
| 1351 | } else if (e->key() == (Qt::Key_PageDown)) {
|
|---|
| 1352 | selection = fHistoryTBTableList->childCount()-1;
|
|---|
| 1353 | #else
|
|---|
| 1354 | int selection = fHistoryTBTableList->currentRow();
|
|---|
| 1355 | if (fHistoryTBTableList->count()) {
|
|---|
| 1356 | if (selection == -1) {
|
|---|
| 1357 | selection = fHistoryTBTableList->count()-1;
|
|---|
| 1358 | } else {
|
|---|
| 1359 | if (e->key() == (Qt::Key_Down)) {
|
|---|
| 1360 | if (selection <(fHistoryTBTableList->count()-1))
|
|---|
| 1361 | selection++;
|
|---|
| 1362 | } else if (e->key() == (Qt::Key_PageDown)) {
|
|---|
| 1363 | selection = fHistoryTBTableList->count()-1;
|
|---|
| 1364 | #endif
|
|---|
| 1365 | } else if (e->key() == (Qt::Key_Up)) {
|
|---|
| 1366 | if (selection >0)
|
|---|
| 1367 | selection --;
|
|---|
| 1368 | } else if (e->key() == (Qt::Key_PageUp)) {
|
|---|
| 1369 | selection = 0;
|
|---|
| 1370 | }
|
|---|
| 1371 | }
|
|---|
| 1372 | fHistoryTBTableList->clearSelection();
|
|---|
| 1373 | #if QT_VERSION < 0x040000
|
|---|
| 1374 | QListViewItem* tmpItem = fHistoryTBTableList->firstChild();
|
|---|
| 1375 | int index = 0;
|
|---|
| 1376 | while (tmpItem != 0) {
|
|---|
| 1377 | if (index == selection) {
|
|---|
| 1378 | tmpItem->setSelected(true);
|
|---|
| 1379 | fHistoryTBTableList->setCurrentItem(tmpItem);
|
|---|
| 1380 | }
|
|---|
| 1381 | index ++;
|
|---|
| 1382 | tmpItem = tmpItem->nextSibling();
|
|---|
| 1383 | }
|
|---|
| 1384 | #else
|
|---|
| 1385 | #if QT_VERSION < 0x040202
|
|---|
| 1386 | fHistoryTBTableList->setItemSelected(fHistoryTBTableList->item(selection),true);
|
|---|
| 1387 | #else
|
|---|
| 1388 | fHistoryTBTableList->item(selection)->setSelected(true);
|
|---|
| 1389 | #endif
|
|---|
| 1390 | fHistoryTBTableList->setCurrentItem(fHistoryTBTableList->item(selection));
|
|---|
| 1391 | #endif
|
|---|
| 1392 | }
|
|---|
| 1393 | moveCommandCursor = true;
|
|---|
| 1394 | } else if (e->key() == (Qt::Key_Tab)) {
|
|---|
| 1395 | #if QT_VERSION < 0x040000
|
|---|
| 1396 | G4String ss = Complete(fCommandArea->text().ascii());
|
|---|
| 1397 | #else
|
|---|
| 1398 | G4String ss = Complete(fCommandArea->text().toStdString().c_str());
|
|---|
| 1399 | #endif
|
|---|
| 1400 | fCommandArea->setText((char*)(ss.data()));
|
|---|
| 1401 |
|
|---|
| 1402 | // do not pass by parent, it will disable widget tab focus !
|
|---|
| 1403 | return true;
|
|---|
| 1404 | #if QT_VERSION >= 0x040000
|
|---|
| 1405 | // L.Garnier : MetaModifier is CTRL for MAC, but I don't want to put a MAC
|
|---|
| 1406 | // specific #ifdef
|
|---|
| 1407 | } else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_A)) {
|
|---|
| 1408 | fCommandArea->home(false);
|
|---|
| 1409 | return true;
|
|---|
| 1410 | } else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_E)) {
|
|---|
| 1411 | fCommandArea->end(false);
|
|---|
| 1412 | return true;
|
|---|
| 1413 | #endif
|
|---|
| 1414 | }
|
|---|
| 1415 | }
|
|---|
| 1416 | }
|
|---|
| 1417 | bool res= false;
|
|---|
| 1418 | // change cursor position if needed
|
|---|
| 1419 | if (moveCommandCursor == true) {
|
|---|
| 1420 | #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 1421 | printf("G4UIQt::eventFilter setCursor Position\n");
|
|---|
| 1422 | #endif
|
|---|
| 1423 | fCommandArea->setCursorPosition ( fCommandArea->text().length() );
|
|---|
| 1424 | fCommandArea->setCursorPosition (4);
|
|---|
| 1425 | } else {
|
|---|
| 1426 | // pass the event on to the parent class
|
|---|
| 1427 | res = QObject::eventFilter(aObj, aEvent);
|
|---|
| 1428 | }
|
|---|
| 1429 | return res;
|
|---|
| 1430 | }
|
|---|
| 1431 |
|
|---|
| 1432 |
|
|---|
| 1433 |
|
|---|
| 1434 |
|
|---|
| 1435 | /***************************************************************************/
|
|---|
| 1436 | //
|
|---|
| 1437 | // SLOTS DEFINITIONS
|
|---|
| 1438 | //
|
|---|
| 1439 | /***************************************************************************/
|
|---|
| 1440 |
|
|---|
| 1441 | /** Called when user give "help" command.
|
|---|
| 1442 | */
|
|---|
| 1443 | void G4UIQt::ShowHelpCallback (
|
|---|
| 1444 | )
|
|---|
| 1445 | {
|
|---|
| 1446 | TerminalHelp("");
|
|---|
| 1447 | }
|
|---|
| 1448 |
|
|---|
| 1449 |
|
|---|
| 1450 | /** Called when user click on clear button. Clear the text Output area
|
|---|
| 1451 | */
|
|---|
| 1452 | void G4UIQt::ClearButtonCallback (
|
|---|
| 1453 | )
|
|---|
| 1454 | {
|
|---|
| 1455 | fCoutTBTextArea->clear();
|
|---|
| 1456 | fG4cout.clear();
|
|---|
| 1457 | }
|
|---|
| 1458 |
|
|---|
| 1459 | /** Called when user exit session
|
|---|
| 1460 | */
|
|---|
| 1461 | void G4UIQt::ExitSession (
|
|---|
| 1462 | )
|
|---|
| 1463 | {
|
|---|
| 1464 | SessionTerminate();
|
|---|
| 1465 | }
|
|---|
| 1466 |
|
|---|
| 1467 | void G4UIQt::ExitHelp(
|
|---|
| 1468 | )
|
|---|
| 1469 | {
|
|---|
| 1470 | }
|
|---|
| 1471 |
|
|---|
| 1472 | /** Callback call when "click on a menu entry.<br>
|
|---|
| 1473 | Send the associated command to geant4
|
|---|
| 1474 | */
|
|---|
| 1475 | void G4UIQt::CommandEnteredCallback (
|
|---|
| 1476 | )
|
|---|
| 1477 | {
|
|---|
| 1478 | #if QT_VERSION < 0x040000
|
|---|
| 1479 | G4String command (fCommandArea->text().ascii());
|
|---|
| 1480 | if (fCommandArea->text().simplifyWhiteSpace() != "") {
|
|---|
| 1481 |
|
|---|
| 1482 | QListViewItem *newItem = new QListViewItem(fHistoryTBTableList);
|
|---|
| 1483 | newItem->setText(0,fCommandArea->text());
|
|---|
| 1484 | fHistoryTBTableList->insertItem(newItem);
|
|---|
| 1485 | // now we have to arrange
|
|---|
| 1486 | QListViewItem *temp= fHistoryTBTableList->lastItem();
|
|---|
| 1487 | for (int i=0; i<fHistoryTBTableList->childCount()-1;i++) {
|
|---|
| 1488 | fHistoryTBTableList->takeItem(temp);
|
|---|
| 1489 | fHistoryTBTableList->insertItem(temp);
|
|---|
| 1490 | temp= fHistoryTBTableList->lastItem();
|
|---|
| 1491 | }
|
|---|
| 1492 | #else
|
|---|
| 1493 | G4String command (fCommandArea->text().toStdString().c_str());
|
|---|
| 1494 | if (fCommandArea->text().trimmed() != "") {
|
|---|
| 1495 | fHistoryTBTableList->addItem(fCommandArea->text());
|
|---|
| 1496 | #endif
|
|---|
| 1497 | fHistoryTBTableList->clearSelection();
|
|---|
| 1498 | fHistoryTBTableList->setCurrentItem(NULL);
|
|---|
| 1499 | fCommandArea->setText("");
|
|---|
| 1500 |
|
|---|
| 1501 | G4Qt* interactorManager = G4Qt::getInstance ();
|
|---|
| 1502 | if (interactorManager) {
|
|---|
| 1503 | interactorManager->FlushAndWaitExecution();
|
|---|
| 1504 | }
|
|---|
| 1505 | if (command(0,4) != "help") {
|
|---|
| 1506 | ApplyShellCommand (command,exitSession,exitPause);
|
|---|
| 1507 | } else {
|
|---|
| 1508 | ActivateCommand(command);
|
|---|
| 1509 | }
|
|---|
| 1510 | // Rebuild help tree
|
|---|
| 1511 | FillHelpTree();
|
|---|
| 1512 |
|
|---|
| 1513 | if(exitSession==true)
|
|---|
| 1514 | SessionTerminate();
|
|---|
| 1515 | }
|
|---|
| 1516 | }
|
|---|
| 1517 |
|
|---|
| 1518 |
|
|---|
| 1519 | /** Callback call when "enter" clicked on the command zone.<br>
|
|---|
| 1520 | Send the command to geant4
|
|---|
| 1521 | @param aCommand
|
|---|
| 1522 | */
|
|---|
| 1523 | void G4UIQt::ButtonCallback (
|
|---|
| 1524 | const QString& aCommand
|
|---|
| 1525 | )
|
|---|
| 1526 | {
|
|---|
| 1527 | #if QT_VERSION < 0x040000
|
|---|
| 1528 | G4String ss = G4String(aCommand.ascii());
|
|---|
| 1529 | #else
|
|---|
| 1530 | G4String ss = G4String(aCommand.toStdString().c_str());
|
|---|
| 1531 | #endif
|
|---|
| 1532 | ApplyShellCommand(ss,exitSession,exitPause);
|
|---|
| 1533 |
|
|---|
| 1534 | // Rebuild help tree
|
|---|
| 1535 | FillHelpTree();
|
|---|
| 1536 |
|
|---|
| 1537 | if(exitSession==true)
|
|---|
| 1538 | SessionTerminate();
|
|---|
| 1539 | }
|
|---|
| 1540 |
|
|---|
| 1541 |
|
|---|
| 1542 |
|
|---|
| 1543 | /** This callback is activated when user selected a item in the help tree
|
|---|
| 1544 | */
|
|---|
| 1545 | void G4UIQt::HelpTreeClicCallback (
|
|---|
| 1546 | )
|
|---|
| 1547 | {
|
|---|
| 1548 | #if QT_VERSION < 0x040000
|
|---|
| 1549 | QListViewItem* item = NULL;
|
|---|
| 1550 | #else
|
|---|
| 1551 | QTreeWidgetItem* item = NULL;
|
|---|
| 1552 | #endif
|
|---|
| 1553 | if (!fHelpTreeWidget)
|
|---|
| 1554 | return ;
|
|---|
| 1555 |
|
|---|
| 1556 | if (!fHelpArea)
|
|---|
| 1557 | return;
|
|---|
| 1558 |
|
|---|
| 1559 | #if QT_VERSION < 0x040000
|
|---|
| 1560 | item =fHelpTreeWidget->selectedItem();
|
|---|
| 1561 | #else
|
|---|
| 1562 | QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
|
|---|
| 1563 | if (list.isEmpty())
|
|---|
| 1564 | return;
|
|---|
| 1565 | item = list.first();
|
|---|
| 1566 | #endif
|
|---|
| 1567 | if (!item)
|
|---|
| 1568 | return;
|
|---|
| 1569 |
|
|---|
| 1570 | G4UImanager* UI = G4UImanager::GetUIpointer();
|
|---|
| 1571 | if(UI==NULL) return;
|
|---|
| 1572 | G4UIcommandTree * treeTop = UI->GetTree();
|
|---|
| 1573 |
|
|---|
| 1574 | std::string itemText = GetLongCommandPath(item).toStdString();
|
|---|
| 1575 |
|
|---|
| 1576 | G4UIcommand* command = treeTop->FindPath(itemText.c_str());
|
|---|
| 1577 |
|
|---|
| 1578 | if (command) {
|
|---|
| 1579 | #if QT_VERSION >= 0x040000
|
|---|
| 1580 | #if QT_VERSION < 0x040200
|
|---|
| 1581 | fHelpArea->clear();
|
|---|
| 1582 | fHelpArea->append(GetCommandList(command));
|
|---|
| 1583 | #else
|
|---|
| 1584 | fHelpArea->setText(GetCommandList(command));
|
|---|
| 1585 | #endif
|
|---|
| 1586 | #else
|
|---|
| 1587 | fHelpArea->setText(GetCommandList(command));
|
|---|
| 1588 | #endif
|
|---|
| 1589 | } else { // this is a command
|
|---|
| 1590 | G4UIcommandTree* path = treeTop->FindCommandTree(itemText.c_str());
|
|---|
| 1591 | if ( path) {
|
|---|
| 1592 | // this is not a command, this is a sub directory
|
|---|
| 1593 | // We display the Title
|
|---|
| 1594 | #if QT_VERSION >= 0x040000
|
|---|
| 1595 | #if QT_VERSION < 0x040200
|
|---|
| 1596 | fHelpArea->clear();
|
|---|
| 1597 | fHelpArea->append(path->GetTitle().data());
|
|---|
| 1598 | #else
|
|---|
| 1599 | fHelpArea->setText(path->GetTitle().data());
|
|---|
| 1600 | #endif
|
|---|
| 1601 | #else
|
|---|
| 1602 | fHelpArea->setText(path->GetTitle().data());
|
|---|
| 1603 | #endif
|
|---|
| 1604 | }
|
|---|
| 1605 | }
|
|---|
| 1606 | }
|
|---|
| 1607 |
|
|---|
| 1608 | /** This callback is activated when user double clic on a item in the help tree
|
|---|
| 1609 | */
|
|---|
| 1610 | void G4UIQt::HelpTreeDoubleClicCallback (
|
|---|
| 1611 | )
|
|---|
| 1612 | {
|
|---|
| 1613 | HelpTreeClicCallback();
|
|---|
| 1614 |
|
|---|
| 1615 | #if QT_VERSION < 0x040000
|
|---|
| 1616 | QListViewItem* item = NULL;
|
|---|
| 1617 | #else
|
|---|
| 1618 | QTreeWidgetItem* item = NULL;
|
|---|
| 1619 | #endif
|
|---|
| 1620 | if (!fHelpTreeWidget)
|
|---|
| 1621 | return ;
|
|---|
| 1622 |
|
|---|
| 1623 | if (!fHelpArea)
|
|---|
| 1624 | return;
|
|---|
| 1625 |
|
|---|
| 1626 | #if QT_VERSION < 0x040000
|
|---|
| 1627 | item =fHelpTreeWidget->selectedItem();
|
|---|
| 1628 | #else
|
|---|
| 1629 | QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems();
|
|---|
| 1630 | if (list.isEmpty())
|
|---|
| 1631 | return;
|
|---|
| 1632 | item = list.first();
|
|---|
| 1633 | #endif
|
|---|
| 1634 | if (!item)
|
|---|
| 1635 | return;
|
|---|
| 1636 |
|
|---|
| 1637 | fCommandArea->clear();
|
|---|
| 1638 | fCommandArea->setText(GetLongCommandPath(item));
|
|---|
| 1639 | }
|
|---|
| 1640 |
|
|---|
| 1641 |
|
|---|
| 1642 | /** Callback called when user select an old command in the command history<br>
|
|---|
| 1643 | Give it to the command area.
|
|---|
| 1644 | */
|
|---|
| 1645 | void G4UIQt::CommandHistoryCallback(
|
|---|
| 1646 | )
|
|---|
| 1647 | {
|
|---|
| 1648 | #if QT_VERSION < 0x040000
|
|---|
| 1649 | QListViewItem* item = NULL;
|
|---|
| 1650 | #else
|
|---|
| 1651 | QListWidgetItem* item = NULL;
|
|---|
| 1652 | #endif
|
|---|
| 1653 | if (!fHistoryTBTableList)
|
|---|
| 1654 | return ;
|
|---|
| 1655 |
|
|---|
| 1656 |
|
|---|
| 1657 | #if QT_VERSION < 0x040000
|
|---|
| 1658 | item =fHistoryTBTableList->selectedItem();
|
|---|
| 1659 | #else
|
|---|
| 1660 | QList<QListWidgetItem *> list =fHistoryTBTableList->selectedItems();
|
|---|
| 1661 | if (list.isEmpty())
|
|---|
| 1662 | return;
|
|---|
| 1663 | item = list.first();
|
|---|
| 1664 | #endif
|
|---|
| 1665 | if (!item)
|
|---|
| 1666 | return;
|
|---|
| 1667 | #if QT_VERSION < 0x040000
|
|---|
| 1668 | fCommandArea->setText(item->text(0));
|
|---|
| 1669 | #else
|
|---|
| 1670 | fCommandArea->setText(item->text());
|
|---|
| 1671 | #endif
|
|---|
| 1672 | #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 1673 | printf("G4UIQt::CommandHistoryCallback change text\n");
|
|---|
| 1674 | #endif
|
|---|
| 1675 | }
|
|---|
| 1676 |
|
|---|
| 1677 |
|
|---|
| 1678 | void G4UIQt::CoutFilterCallback(
|
|---|
| 1679 | const QString & text) {
|
|---|
| 1680 |
|
|---|
| 1681 | #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 1682 | printf("G4UIQt::CoutFilterCallback : %s\n",text.toStdString().c_str());
|
|---|
| 1683 | #endif
|
|---|
| 1684 |
|
|---|
| 1685 | QStringList result = fG4cout.filter(text);
|
|---|
| 1686 |
|
|---|
| 1687 | fCoutTBTextArea->setText(result.join("\n"));
|
|---|
| 1688 | fCoutTBTextArea->repaint();
|
|---|
| 1689 | #if QT_VERSION < 0x040000
|
|---|
| 1690 | fCoutTBTextArea->verticalScrollBar()->setValue(fCoutTBTextArea->verticalScrollBar()->maxValue());
|
|---|
| 1691 | #else
|
|---|
| 1692 | fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
|
|---|
| 1693 | #endif
|
|---|
| 1694 | #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 1695 | printf("G4UIQt::CoutFilterCallback textSize:%d resSize:%d \n",fG4cout.join("").size(),result.join("").size());
|
|---|
| 1696 | #endif
|
|---|
| 1697 |
|
|---|
| 1698 | }
|
|---|
| 1699 |
|
|---|
| 1700 | /** Callback called when user give a new string to look for<br>
|
|---|
| 1701 | Display a list of matching commands descriptions. If no string is set,
|
|---|
| 1702 | will display the complete help tree
|
|---|
| 1703 | */
|
|---|
| 1704 | void G4UIQt::LookForHelpStringCallback(
|
|---|
| 1705 | )
|
|---|
| 1706 | {
|
|---|
| 1707 | QString searchText = fHelpLine->text();
|
|---|
| 1708 |
|
|---|
| 1709 | #if QT_VERSION < 0x040200
|
|---|
| 1710 | fHelpArea->clear();
|
|---|
| 1711 | #else
|
|---|
| 1712 | fHelpArea->setText("");
|
|---|
| 1713 | #endif
|
|---|
| 1714 | if (searchText =="") {
|
|---|
| 1715 | // clear old help tree
|
|---|
| 1716 | fHelpTreeWidget->clear();
|
|---|
| 1717 | #if QT_VERSION < 0x040000
|
|---|
| 1718 | fHelpTreeWidget->removeColumn(1);
|
|---|
| 1719 | fHelpTreeWidget->removeColumn(0);
|
|---|
| 1720 | #endif
|
|---|
| 1721 |
|
|---|
| 1722 | FillHelpTree();
|
|---|
| 1723 |
|
|---|
| 1724 | return;
|
|---|
| 1725 | } else {
|
|---|
| 1726 | OpenHelpTreeOnCommand(searchText);
|
|---|
| 1727 | }
|
|---|
| 1728 | }
|
|---|
| 1729 |
|
|---|
| 1730 |
|
|---|
| 1731 | void G4UIQt::OpenHelpTreeOnCommand(
|
|---|
| 1732 | const QString & searchText
|
|---|
| 1733 | )
|
|---|
| 1734 | {
|
|---|
| 1735 |
|
|---|
| 1736 | // the help tree
|
|---|
| 1737 | G4UImanager* UI = G4UImanager::GetUIpointer();
|
|---|
| 1738 | if(UI==NULL) return;
|
|---|
| 1739 | G4UIcommandTree * treeTop = UI->GetTree();
|
|---|
| 1740 |
|
|---|
| 1741 | G4int treeSize = treeTop->GetTreeEntry();
|
|---|
| 1742 |
|
|---|
| 1743 | // clear old help tree
|
|---|
| 1744 | fHelpTreeWidget->clear();
|
|---|
| 1745 | #if QT_VERSION < 0x040000
|
|---|
| 1746 | fHelpTreeWidget->removeColumn(1);
|
|---|
| 1747 | fHelpTreeWidget->removeColumn(0);
|
|---|
| 1748 | #endif
|
|---|
| 1749 |
|
|---|
| 1750 | // look for new items
|
|---|
| 1751 |
|
|---|
| 1752 | int tmp = 0;
|
|---|
| 1753 | #if QT_VERSION < 0x040000
|
|---|
| 1754 | int multFactor = 1000; // factor special for having double keys in Qt3
|
|---|
| 1755 | int doubleKeyAdd = 0; // decay for doubleKeys in Qt3
|
|---|
| 1756 | #endif
|
|---|
| 1757 |
|
|---|
| 1758 | QMap<int,QString> commandResultMap;
|
|---|
| 1759 | QMap<int,QString> commandChildResultMap;
|
|---|
| 1760 |
|
|---|
| 1761 | for (int a=0;a<treeSize;a++) {
|
|---|
| 1762 | G4UIcommand* command = treeTop->FindPath(treeTop->GetTree(a+1)->GetPathName().data());
|
|---|
| 1763 | #if QT_VERSION > 0x040000
|
|---|
| 1764 | tmp = GetCommandList (command).count(searchText,Qt::CaseInsensitive);
|
|---|
| 1765 | #else
|
|---|
| 1766 | tmp = GetCommandList (command).contains(searchText,false);
|
|---|
| 1767 | #endif
|
|---|
| 1768 | if (tmp >0) {
|
|---|
| 1769 | #if QT_VERSION > 0x040000
|
|---|
| 1770 | commandResultMap.insertMulti(tmp,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()));
|
|---|
| 1771 | #else // tricky thing for Qt3...
|
|---|
| 1772 | doubleKeyAdd = 0;
|
|---|
| 1773 | while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) {
|
|---|
| 1774 | doubleKeyAdd ++;
|
|---|
| 1775 | }
|
|---|
| 1776 | commandResultMap.insert( tmp*multFactor+doubleKeyAdd,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()) );
|
|---|
| 1777 | #endif
|
|---|
| 1778 | }
|
|---|
| 1779 | // look for childs
|
|---|
| 1780 | commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a+1),searchText);
|
|---|
| 1781 | // insert new childs
|
|---|
| 1782 | if (!commandChildResultMap.empty()) {
|
|---|
| 1783 | #if QT_VERSION > 0x040000
|
|---|
| 1784 | QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
|
|---|
| 1785 | while (i != commandChildResultMap.constEnd()) {
|
|---|
| 1786 | commandResultMap.insertMulti(i.key(),i.value());
|
|---|
| 1787 | #else // tricky thing for Qt3...
|
|---|
| 1788 | QMap<int,QString>::const_iterator i = commandChildResultMap.begin();
|
|---|
| 1789 | while (i != commandChildResultMap.end()) {
|
|---|
| 1790 | doubleKeyAdd = 0;
|
|---|
| 1791 | while (commandResultMap.find( i.key()*multFactor+doubleKeyAdd) != commandResultMap.end()) {
|
|---|
| 1792 | doubleKeyAdd ++;
|
|---|
| 1793 | }
|
|---|
| 1794 | commandResultMap.insert(i.key()*multFactor+doubleKeyAdd,i.data());
|
|---|
| 1795 | #endif
|
|---|
| 1796 | i++;
|
|---|
| 1797 | }
|
|---|
| 1798 | commandChildResultMap.clear();
|
|---|
| 1799 | }
|
|---|
| 1800 | }
|
|---|
| 1801 |
|
|---|
| 1802 | // build new help tree
|
|---|
| 1803 | #if QT_VERSION < 0x040000
|
|---|
| 1804 | fHelpTreeWidget->setSelectionMode(QListView::Single);
|
|---|
| 1805 | fHelpTreeWidget->setRootIsDecorated(true);
|
|---|
| 1806 | fHelpTreeWidget->addColumn("Command");
|
|---|
| 1807 | fHelpTreeWidget->addColumn("Match");
|
|---|
| 1808 | // fHelpTreeWidget->header()->setResizeEnabled(FALSE,1);
|
|---|
| 1809 | #else
|
|---|
| 1810 | fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
|
|---|
| 1811 | fHelpTreeWidget->setColumnCount(2);
|
|---|
| 1812 | QStringList labels;
|
|---|
| 1813 | labels << QString("Command") << QString("Match");
|
|---|
| 1814 | fHelpTreeWidget->setHeaderLabels(labels);
|
|---|
| 1815 | #endif
|
|---|
| 1816 |
|
|---|
| 1817 | if (commandResultMap.empty()) {
|
|---|
| 1818 | #if QT_VERSION < 0x040200
|
|---|
| 1819 | fHelpArea->clear();
|
|---|
| 1820 | fHelpArea->append("No match found");
|
|---|
| 1821 | #else
|
|---|
| 1822 | fHelpArea->setText("No match found");
|
|---|
| 1823 | #endif
|
|---|
| 1824 | return;
|
|---|
| 1825 | }
|
|---|
| 1826 |
|
|---|
| 1827 | #if QT_VERSION > 0x040000
|
|---|
| 1828 | QMap<int,QString>::const_iterator i = commandResultMap.constEnd();
|
|---|
| 1829 | #else
|
|---|
| 1830 | QMap<int,QString>::const_iterator i = commandResultMap.end();
|
|---|
| 1831 | #endif
|
|---|
| 1832 | i--;
|
|---|
| 1833 | // 10 maximum progress values
|
|---|
| 1834 | float multValue = 10.0/(float)(i.key());
|
|---|
| 1835 | QString progressChar = "|";
|
|---|
| 1836 | QString progressStr = "|";
|
|---|
| 1837 |
|
|---|
| 1838 | #if QT_VERSION < 0x040000
|
|---|
| 1839 | QListViewItem * newItem;
|
|---|
| 1840 | #else
|
|---|
| 1841 | QTreeWidgetItem * newItem;
|
|---|
| 1842 | #endif
|
|---|
| 1843 | bool end = false;
|
|---|
| 1844 | while (!end) {
|
|---|
| 1845 | #if QT_VERSION > 0x040000
|
|---|
| 1846 | if (i == commandResultMap.constBegin()) {
|
|---|
| 1847 | #else
|
|---|
| 1848 | if (i == commandResultMap.begin()) {
|
|---|
| 1849 | #endif
|
|---|
| 1850 | end = true;
|
|---|
| 1851 | }
|
|---|
| 1852 | for(int a=0;a<int(i.key()*multValue);a++) {
|
|---|
| 1853 | progressStr += progressChar;
|
|---|
| 1854 | }
|
|---|
| 1855 | #if QT_VERSION < 0x040000
|
|---|
| 1856 | newItem = new QListViewItem(fHelpTreeWidget);
|
|---|
| 1857 | newItem->setText(0,i.data().simplifyWhiteSpace());
|
|---|
| 1858 | #else
|
|---|
| 1859 | newItem = new QTreeWidgetItem(fHelpTreeWidget);
|
|---|
| 1860 | newItem->setText(0,i.value().trimmed());
|
|---|
| 1861 | #endif
|
|---|
| 1862 | newItem->setText(1,progressStr);
|
|---|
| 1863 |
|
|---|
| 1864 | #if QT_VERSION >= 0x040200
|
|---|
| 1865 | newItem->setForeground ( 1, QBrush(Qt::blue) );
|
|---|
| 1866 | #endif
|
|---|
| 1867 | progressStr = "|";
|
|---|
| 1868 | i--;
|
|---|
| 1869 | }
|
|---|
| 1870 | // FIXME : to be checked on Qt3
|
|---|
| 1871 | #if QT_VERSION < 0x040000
|
|---|
| 1872 | fHelpTreeWidget->setColumnWidthMode (1,QListView::Maximum);
|
|---|
| 1873 | fHelpTreeWidget->setSorting(1,false);
|
|---|
| 1874 | #else
|
|---|
| 1875 | fHelpTreeWidget->resizeColumnToContents (0);
|
|---|
| 1876 | fHelpTreeWidget->sortItems(1,Qt::DescendingOrder);
|
|---|
| 1877 | // fHelpTreeWidget->setColumnWidth(1,10);//resizeColumnToContents (1);
|
|---|
| 1878 | #endif
|
|---|
| 1879 | }
|
|---|
| 1880 |
|
|---|
| 1881 |
|
|---|
| 1882 |
|
|---|
| 1883 |
|
|---|
| 1884 | QMap<int,QString> G4UIQt::LookForHelpStringInChildTree(
|
|---|
| 1885 | G4UIcommandTree *aCommandTree
|
|---|
| 1886 | ,const QString & text
|
|---|
| 1887 | )
|
|---|
| 1888 | {
|
|---|
| 1889 | QMap<int,QString> commandResultMap;
|
|---|
| 1890 | if (aCommandTree == NULL) return commandResultMap;
|
|---|
| 1891 |
|
|---|
| 1892 | #if QT_VERSION < 0x040000
|
|---|
| 1893 | int multFactor = 1000; // factor special for having double keys in Qt3
|
|---|
| 1894 | int doubleKeyAdd = 0; // decay for doubleKeys in Qt3
|
|---|
| 1895 | #endif
|
|---|
| 1896 |
|
|---|
| 1897 | // Get the Sub directories
|
|---|
| 1898 | int tmp = 0;
|
|---|
| 1899 | QMap<int,QString> commandChildResultMap;
|
|---|
| 1900 |
|
|---|
| 1901 | for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
|
|---|
| 1902 | const G4UIcommand* command = aCommandTree->GetGuidance();
|
|---|
| 1903 | #if QT_VERSION > 0x040000
|
|---|
| 1904 | tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
|
|---|
| 1905 | #else
|
|---|
| 1906 | tmp = GetCommandList (command).contains(text,false);
|
|---|
| 1907 | #endif
|
|---|
| 1908 | if (tmp >0) {
|
|---|
| 1909 | #if QT_VERSION > 0x040000
|
|---|
| 1910 | commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()));
|
|---|
| 1911 | #else // tricky thing for Qt3...
|
|---|
| 1912 | doubleKeyAdd = 0;
|
|---|
| 1913 | while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) {
|
|---|
| 1914 | doubleKeyAdd ++;
|
|---|
| 1915 | }
|
|---|
| 1916 | commandResultMap.insert(tmp*multFactor+doubleKeyAdd,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()));
|
|---|
| 1917 | #endif
|
|---|
| 1918 | }
|
|---|
| 1919 | // look for childs
|
|---|
| 1920 | commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text);
|
|---|
| 1921 |
|
|---|
| 1922 | if (!commandChildResultMap.empty()) {
|
|---|
| 1923 | // insert new childs
|
|---|
| 1924 | #if QT_VERSION > 0x040000
|
|---|
| 1925 | QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
|
|---|
| 1926 | while (i != commandChildResultMap.constEnd()) {
|
|---|
| 1927 | commandResultMap.insertMulti(i.key(),i.value());
|
|---|
| 1928 | #else // tricky thing for Qt3...
|
|---|
| 1929 | QMap<int,QString>::const_iterator i = commandChildResultMap.begin();
|
|---|
| 1930 | while (i != commandChildResultMap.end()) {
|
|---|
| 1931 | doubleKeyAdd = 0;
|
|---|
| 1932 | while (commandResultMap.find( i.key()*multFactor+doubleKeyAdd) != commandResultMap.end()) {
|
|---|
| 1933 | doubleKeyAdd ++;
|
|---|
| 1934 | }
|
|---|
| 1935 | commandResultMap.insert(i.key()*multFactor+doubleKeyAdd,i.data());
|
|---|
| 1936 | #endif
|
|---|
| 1937 | i++;
|
|---|
| 1938 | }
|
|---|
| 1939 | commandChildResultMap.clear();
|
|---|
| 1940 | }
|
|---|
| 1941 | }
|
|---|
| 1942 | // Get the Commands
|
|---|
| 1943 |
|
|---|
| 1944 | for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
|
|---|
| 1945 | const G4UIcommand* command = aCommandTree->GetCommand(a+1);
|
|---|
| 1946 | #if QT_VERSION > 0x040000
|
|---|
| 1947 | tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
|
|---|
| 1948 | #else
|
|---|
| 1949 | tmp = GetCommandList (command).contains(text,false);
|
|---|
| 1950 | #endif
|
|---|
| 1951 | if (tmp >0) {
|
|---|
| 1952 | #if QT_VERSION > 0x040000
|
|---|
| 1953 | commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()));
|
|---|
| 1954 | #else // tricky thing for Qt3...
|
|---|
| 1955 | doubleKeyAdd = 0;
|
|---|
| 1956 | while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) {
|
|---|
| 1957 | doubleKeyAdd ++;
|
|---|
| 1958 | }
|
|---|
| 1959 | commandResultMap.insert(tmp*multFactor+doubleKeyAdd,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()));
|
|---|
| 1960 | #endif
|
|---|
| 1961 | }
|
|---|
| 1962 |
|
|---|
| 1963 | }
|
|---|
| 1964 | return commandResultMap;
|
|---|
| 1965 | }
|
|---|
| 1966 |
|
|---|
| 1967 |
|
|---|
| 1968 | QString G4UIQt::GetShortCommandPath(
|
|---|
| 1969 | QString commandPath
|
|---|
| 1970 | )
|
|---|
| 1971 | {
|
|---|
| 1972 | if (commandPath.indexOf("/") == 0) {
|
|---|
| 1973 | commandPath = commandPath.right(commandPath.size()-1);
|
|---|
| 1974 | }
|
|---|
| 1975 |
|
|---|
| 1976 | commandPath = commandPath.right(commandPath.size()-commandPath.lastIndexOf("/",-2)-1);
|
|---|
| 1977 |
|
|---|
| 1978 | if (commandPath.lastIndexOf("/") == (commandPath.size()-1)) {
|
|---|
| 1979 | commandPath = commandPath.left(commandPath.size()-1);
|
|---|
| 1980 | }
|
|---|
| 1981 |
|
|---|
| 1982 | return commandPath;
|
|---|
| 1983 | }
|
|---|
| 1984 |
|
|---|
| 1985 |
|
|---|
| 1986 | QString G4UIQt::GetLongCommandPath(
|
|---|
| 1987 | #if QT_VERSION < 0x040000
|
|---|
| 1988 | QListViewItem* item
|
|---|
| 1989 | #else
|
|---|
| 1990 | QTreeWidgetItem* item
|
|---|
| 1991 | #endif
|
|---|
| 1992 | )
|
|---|
| 1993 | {
|
|---|
| 1994 | if (item == NULL) return "";
|
|---|
| 1995 |
|
|---|
| 1996 | // rebuild path:
|
|---|
| 1997 | QString itemText = "";
|
|---|
| 1998 | itemText = item->text(0);
|
|---|
| 1999 |
|
|---|
| 2000 | while (item->parent() != NULL) {
|
|---|
| 2001 | itemText = item->parent()->text(0)+"/"+itemText;
|
|---|
| 2002 | item = item->parent();
|
|---|
| 2003 | }
|
|---|
| 2004 | itemText = "/"+itemText;
|
|---|
| 2005 |
|
|---|
| 2006 | return itemText;
|
|---|
| 2007 | }
|
|---|
| 2008 |
|
|---|
| 2009 | G4QTabWidget::G4QTabWidget(
|
|---|
| 2010 | QSplitter*& split
|
|---|
| 2011 | ):QTabWidget(split)
|
|---|
| 2012 | ,tabSelected(false)
|
|---|
| 2013 | ,lastCreated(-1)
|
|---|
| 2014 | {
|
|---|
| 2015 | }
|
|---|
| 2016 |
|
|---|
| 2017 | G4QTabWidget::G4QTabWidget(
|
|---|
| 2018 | ):QTabWidget()
|
|---|
| 2019 | ,tabSelected(false)
|
|---|
| 2020 | ,lastCreated(-1)
|
|---|
| 2021 | {
|
|---|
| 2022 | }
|
|---|
| 2023 |
|
|---|
| 2024 |
|
|---|
| 2025 |
|
|---|
| 2026 | void G4UIQt::TabCloseCallback(int a){
|
|---|
| 2027 | QWidget* temp = fTabWidget->widget(a);
|
|---|
| 2028 | fTabWidget->removeTab (a);
|
|---|
| 2029 | delete temp;
|
|---|
| 2030 |
|
|---|
| 2031 | if (fTabWidget->count() == 0) {
|
|---|
| 2032 | fMyVSplitter->addWidget(fEmptyViewerTabLabel);
|
|---|
| 2033 | #if QT_VERSION < 0x040000
|
|---|
| 2034 | fTabWidget->reparent(0,0,QPoint(0,0));
|
|---|
| 2035 | #else
|
|---|
| 2036 | fTabWidget->setParent(0);
|
|---|
| 2037 | #endif
|
|---|
| 2038 | }
|
|---|
| 2039 | }
|
|---|
| 2040 |
|
|---|
| 2041 |
|
|---|
| 2042 | void G4UIQt::ToolBoxActivated(int a){
|
|---|
| 2043 |
|
|---|
| 2044 | if (fToolBox->widget(a) == fHelpTBWidget) {
|
|---|
| 2045 | // Rebuild the help tree
|
|---|
| 2046 | FillHelpTree();
|
|---|
| 2047 | }
|
|---|
| 2048 | }
|
|---|
| 2049 |
|
|---|
| 2050 | void G4QTabWidget::paintEvent(
|
|---|
| 2051 | QPaintEvent * event
|
|---|
| 2052 | )
|
|---|
| 2053 | {
|
|---|
| 2054 |
|
|---|
| 2055 | if (currentWidget()) {
|
|---|
| 2056 | #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 2057 | printf("G4QTabWidget::paintEvent repaint type : %d -- rect %d %d region:%d %d page : %d %d ________________________ i= %d\n", event->type(),event->rect().height(),event->rect().width(),event->region().boundingRect().width(),event->region().boundingRect().height(),currentWidget()->width(),currentWidget()->height(),currentIndex());
|
|---|
| 2058 | #endif
|
|---|
| 2059 | if ( isTabSelected()) {
|
|---|
| 2060 |
|
|---|
| 2061 | QCoreApplication::sendPostedEvents () ;
|
|---|
| 2062 | #ifdef G4DEBUG_INTERFACES_BASIC
|
|---|
| 2063 | printf("G4QTabWidget::paintEvent OK\n");
|
|---|
| 2064 | #endif
|
|---|
| 2065 | #if QT_VERSION < 0x040000
|
|---|
| 2066 | QString text = label (currentPageIndex());
|
|---|
| 2067 | #else
|
|---|
| 2068 | QString text = tabText (currentIndex());
|
|---|
| 2069 | #endif
|
|---|
| 2070 |
|
|---|
| 2071 | if (lastCreated == -1) {
|
|---|
| 2072 | QString paramSelect = QString("/vis/viewer/select ")+text;
|
|---|
| 2073 | G4UImanager* UI = G4UImanager::GetUIpointer();
|
|---|
| 2074 | if(UI != NULL) {
|
|---|
| 2075 | UI->ApplyCommand(paramSelect.toStdString().c_str());
|
|---|
| 2076 | }
|
|---|
| 2077 | } else {
|
|---|
| 2078 | lastCreated = -1;
|
|---|
| 2079 | }
|
|---|
| 2080 | unselectTab();
|
|---|
| 2081 | repaint();
|
|---|
| 2082 | }
|
|---|
| 2083 | }
|
|---|
| 2084 | }
|
|---|
| 2085 |
|
|---|
| 2086 | #endif
|
|---|