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