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