[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 | // |
---|
[1255] | 27 | // $Id: G4UIQt.cc,v 1.37 2010/05/20 07:01:03 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> |
---|
[1261] | 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 ! |
---|
[1262] | 641 | #if QT_VERSION >= 0x040000 |
---|
| 642 | #if QT_VERSION >= 0x040200 |
---|
| 643 | fTabWidget->setVisible(true); |
---|
| 644 | #else |
---|
[1265] | 645 | fTabWidget->show(); |
---|
[1262] | 646 | #endif |
---|
| 647 | #else |
---|
[1265] | 648 | fTabWidget->show(); |
---|
[1262] | 649 | #endif |
---|
[1243] | 650 | |
---|
| 651 | // This will send a paintEvent to OGL Viewers |
---|
[1236] | 652 | fTabWidget->setTabSelected(); |
---|
| 653 | |
---|
[1263] | 654 | #if QT_VERSION < 0x040000 |
---|
| 655 | QApplication::sendPostedEvents () ; |
---|
| 656 | #else |
---|
[1252] | 657 | QCoreApplication::sendPostedEvents () ; |
---|
[1263] | 658 | #endif |
---|
[1252] | 659 | |
---|
[1236] | 660 | #ifdef G4DEBUG_INTERFACES_BASIC |
---|
| 661 | printf("G4UIQt::UpdateTabWidget END\n"); |
---|
| 662 | #endif |
---|
[1158] | 663 | } |
---|
| 664 | |
---|
| 665 | |
---|
[1223] | 666 | /** Send resize event to all tabs |
---|
| 667 | */ |
---|
| 668 | void G4UIQt::ResizeTabWidget( QResizeEvent* e) { |
---|
| 669 | for (int a=0;a<fTabWidget->count() ;a++) { |
---|
| 670 | #ifdef G4DEBUG_INTERFACES_BASIC |
---|
| 671 | printf("G4UIQt::ResizeTabWidget +++++++++++++++++++++++++++++++++++++++\n"); |
---|
| 672 | #endif |
---|
[1265] | 673 | #if QT_VERSION < 0x040000 |
---|
| 674 | fTabWidget->page(a)->resize(e->size()); |
---|
| 675 | #else |
---|
[1223] | 676 | fTabWidget->widget(a)->resize(e->size()); |
---|
[1265] | 677 | #endif |
---|
[1223] | 678 | } |
---|
| 679 | } |
---|
[1163] | 680 | |
---|
[1223] | 681 | |
---|
[607] | 682 | /** Start the Qt main loop |
---|
| 683 | */ |
---|
| 684 | G4UIsession* G4UIQt::SessionStart ( |
---|
| 685 | ) |
---|
| 686 | { |
---|
[1232] | 687 | #ifdef G4DEBUG_INTERFACES_BASIC |
---|
| 688 | printf("G4UIQt::G4UIQt SessionStart\n"); |
---|
| 689 | #endif |
---|
[607] | 690 | |
---|
| 691 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
| 692 | |
---|
[1232] | 693 | Prompt("Session :"); |
---|
| 694 | exitSession = false; |
---|
| 695 | |
---|
[1265] | 696 | #if QT_VERSION >= 0x040000 |
---|
[1266] | 697 | #if QT_VERSION >= 0x040200 |
---|
[1243] | 698 | fTabWidget->setVisible(true); |
---|
[1266] | 699 | fEmptyViewerTabLabel->setVisible(true); |
---|
| 700 | #else |
---|
[1265] | 701 | fTabWidget->show(); |
---|
[1266] | 702 | fEmptyViewerTabLabel->show(); |
---|
| 703 | #endif |
---|
[1265] | 704 | #else |
---|
| 705 | fTabWidget->show(); |
---|
[1266] | 706 | fEmptyViewerTabLabel->show(); |
---|
[1265] | 707 | #endif |
---|
| 708 | |
---|
[1243] | 709 | |
---|
[1156] | 710 | #if QT_VERSION >= 0x040000 |
---|
[1266] | 711 | #if QT_VERSION >= 0x040200 |
---|
[1156] | 712 | fMainWindow->setVisible(true); |
---|
[1266] | 713 | #else |
---|
[607] | 714 | fMainWindow->show(); |
---|
[1266] | 715 | #endif |
---|
[1156] | 716 | #else |
---|
| 717 | fMainWindow->show(); |
---|
| 718 | #endif |
---|
[607] | 719 | |
---|
[1263] | 720 | #if QT_VERSION < 0x040000 |
---|
| 721 | QApplication::sendPostedEvents () ; |
---|
| 722 | #else |
---|
[1243] | 723 | QCoreApplication::sendPostedEvents () ; |
---|
[1263] | 724 | #endif |
---|
[1243] | 725 | |
---|
[1232] | 726 | #ifdef G4DEBUG_INTERFACES_BASIC |
---|
| 727 | printf("G4UIQt::G4UIQt SessionStart2\n"); |
---|
| 728 | #endif |
---|
[607] | 729 | interactorManager->DisableSecondaryLoop (); // TO KEEP |
---|
[610] | 730 | if ((QApplication*)interactorManager->GetMainInteractor()) |
---|
| 731 | ((QApplication*)interactorManager->GetMainInteractor())->exec(); |
---|
[850] | 732 | |
---|
| 733 | // on ne passe pas le dessous ? FIXME ???? |
---|
| 734 | // je ne pense pas 13/06 |
---|
| 735 | |
---|
| 736 | // void* event; // TO KEEP |
---|
| 737 | // while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
| 738 | // interactorManager->DispatchEvent(event); // TO KEEP |
---|
| 739 | // if(exitSession==true) break; // TO KEEP |
---|
| 740 | // } // TO KEEP |
---|
| 741 | |
---|
[607] | 742 | interactorManager->EnableSecondaryLoop (); |
---|
| 743 | return this; |
---|
| 744 | } |
---|
| 745 | |
---|
| 746 | |
---|
| 747 | /** Display the prompt in the prompt area |
---|
| 748 | @param aPrompt : string to display as the promt label |
---|
[850] | 749 | //FIXME : probablement inutile puisque le seul a afficher qq chose d'autre |
---|
| 750 | que "session" est SecondaryLoop() |
---|
[607] | 751 | */ |
---|
| 752 | void G4UIQt::Prompt ( |
---|
| 753 | G4String aPrompt |
---|
| 754 | ) |
---|
| 755 | { |
---|
| 756 | if (!aPrompt) return; |
---|
| 757 | |
---|
| 758 | fCommandLabel->setText((char*)aPrompt.data()); |
---|
| 759 | } |
---|
| 760 | |
---|
| 761 | |
---|
[922] | 762 | |
---|
[607] | 763 | void G4UIQt::SessionTerminate ( |
---|
| 764 | ) |
---|
| 765 | { |
---|
| 766 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
| 767 | fMainWindow->close(); |
---|
| 768 | ((QApplication*)interactorManager->GetMainInteractor())->exit(); |
---|
| 769 | } |
---|
| 770 | |
---|
| 771 | |
---|
| 772 | |
---|
| 773 | /** |
---|
| 774 | Called by intercoms/src/G4UImanager.cc<br> |
---|
| 775 | Called by visualization/management/src/G4VisCommands.cc with "EndOfEvent" argument<br> |
---|
| 776 | It have to pause the session command terminal.<br> |
---|
| 777 | Call SecondaryLoop to wait for exit event<br> |
---|
| 778 | @param aState |
---|
| 779 | @see : G4VisCommandReviewKeptEvents::SetNewValue |
---|
| 780 | */ |
---|
| 781 | void G4UIQt::PauseSessionStart ( |
---|
| 782 | G4String aState |
---|
| 783 | ) |
---|
| 784 | { |
---|
| 785 | if (!aState) return; |
---|
| 786 | |
---|
| 787 | if(aState=="G4_pause> ") { // TO KEEP |
---|
| 788 | SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP |
---|
| 789 | } // TO KEEP |
---|
| 790 | |
---|
| 791 | if(aState=="EndOfEvent") { // TO KEEP |
---|
| 792 | // Picking with feed back in event data Done here !!! |
---|
| 793 | SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP |
---|
| 794 | } // TO KEEP |
---|
| 795 | } |
---|
| 796 | |
---|
| 797 | |
---|
| 798 | |
---|
| 799 | /** |
---|
| 800 | Begin the secondary loop |
---|
| 801 | @param a_prompt : label to display as the prompt label |
---|
| 802 | */ |
---|
| 803 | void G4UIQt::SecondaryLoop ( |
---|
| 804 | G4String aPrompt |
---|
| 805 | ) |
---|
| 806 | { |
---|
| 807 | if (!aPrompt) return; |
---|
| 808 | |
---|
| 809 | G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ? |
---|
| 810 | Prompt(aPrompt); // TO KEEP |
---|
| 811 | exitPause = false; // TO KEEP |
---|
| 812 | void* event; // TO KEEP |
---|
| 813 | while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
| 814 | interactorManager->DispatchEvent(event); // TO KEEP |
---|
| 815 | if(exitPause==true) break; // TO KEEP |
---|
| 816 | } // TO KEEP |
---|
[1223] | 817 | Prompt("Session :"); // TO KEEP |
---|
[607] | 818 | } |
---|
| 819 | |
---|
| 820 | |
---|
| 821 | |
---|
| 822 | /** |
---|
| 823 | Receive a cout from Geant4. We have to display it in the cout zone |
---|
| 824 | @param aString : label to add in the display area |
---|
| 825 | @return 0 |
---|
| 826 | */ |
---|
| 827 | G4int G4UIQt::ReceiveG4cout ( |
---|
| 828 | G4String aString |
---|
[1224] | 829 | ) |
---|
[607] | 830 | { |
---|
| 831 | if (!aString) return 0; |
---|
| 832 | |
---|
[1224] | 833 | QStringList newStr; |
---|
| 834 | |
---|
| 835 | // Add to stringList |
---|
[607] | 836 | #if QT_VERSION < 0x040000 |
---|
[1224] | 837 | newStr = QStringList(QString((char*)aString.data()).simplifyWhiteSpace()); |
---|
[607] | 838 | #else |
---|
[1224] | 839 | newStr = QStringList(QString((char*)aString.data()).trimmed()); |
---|
[607] | 840 | #endif |
---|
[1224] | 841 | fG4cout += newStr; |
---|
| 842 | |
---|
[1265] | 843 | #if QT_VERSION >= 0x040000 |
---|
[1224] | 844 | QStringList result = newStr.filter(fCoutFilter->text()); |
---|
[1265] | 845 | #else |
---|
[1266] | 846 | //L. Garnier : in qt3 filter will does nothing |
---|
| 847 | QStringList result = ""; |
---|
[1265] | 848 | #endif |
---|
[1224] | 849 | |
---|
| 850 | if (result.join("\n").isEmpty()) { |
---|
| 851 | return 0; |
---|
| 852 | } |
---|
| 853 | fCoutTBTextArea->append(result.join("\n")); |
---|
| 854 | fCoutTBTextArea->repaint(); |
---|
| 855 | |
---|
| 856 | #if QT_VERSION < 0x040000 |
---|
| 857 | fCoutTBTextArea->verticalScrollBar()->setValue(fCoutTBTextArea->verticalScrollBar()->maxValue()); |
---|
| 858 | #else |
---|
| 859 | fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum()); |
---|
| 860 | #endif |
---|
| 861 | |
---|
[607] | 862 | return 0; |
---|
| 863 | } |
---|
| 864 | |
---|
| 865 | |
---|
| 866 | /** |
---|
| 867 | Receive a cerr from Geant4. We have to display it in the cout zone |
---|
| 868 | @param aString : label to add in the display area |
---|
| 869 | @return 0 |
---|
| 870 | */ |
---|
| 871 | G4int G4UIQt::ReceiveG4cerr ( |
---|
| 872 | G4String aString |
---|
| 873 | ) |
---|
| 874 | { |
---|
| 875 | if (!aString) return 0; |
---|
| 876 | |
---|
[1224] | 877 | QStringList newStr; |
---|
| 878 | |
---|
| 879 | // Add to stringList |
---|
[607] | 880 | #if QT_VERSION < 0x040000 |
---|
[1224] | 881 | newStr = QStringList(QString((char*)aString.data()).simplifyWhiteSpace()); |
---|
[607] | 882 | #else |
---|
[1224] | 883 | newStr = QStringList(QString((char*)aString.data()).trimmed()); |
---|
[607] | 884 | #endif |
---|
[1224] | 885 | fG4cout += newStr; |
---|
| 886 | |
---|
[1266] | 887 | #if QT_VERSION < 0x040000 |
---|
| 888 | //L. Garnier : in qt3 filter will does nothing |
---|
| 889 | QStringList result = ""; |
---|
| 890 | #else |
---|
| 891 | QStringList result = newStr.filter(fCoutFilter->text()); |
---|
| 892 | #endif |
---|
[1224] | 893 | |
---|
| 894 | #if QT_VERSION < 0x040000 |
---|
| 895 | QColor previousColor = fCoutTBTextArea->color(); |
---|
| 896 | fCoutTBTextArea->setColor(Qt::red); |
---|
| 897 | fCoutTBTextArea->append(result.join("\n")); |
---|
| 898 | fCoutTBTextArea->setColor(previousColor); |
---|
| 899 | fCoutTBTextArea->verticalScrollBar()->setValue(fCoutTBTextArea->verticalScrollBar()->maxValue()); |
---|
| 900 | #else |
---|
| 901 | QColor previousColor = fCoutTBTextArea->textColor(); |
---|
| 902 | fCoutTBTextArea->setTextColor(Qt::red); |
---|
| 903 | fCoutTBTextArea->append(result.join("\n")); |
---|
| 904 | fCoutTBTextArea->setTextColor(previousColor); |
---|
| 905 | fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum()); |
---|
| 906 | #endif |
---|
| 907 | fCoutTBTextArea->repaint(); |
---|
[607] | 908 | return 0; |
---|
| 909 | } |
---|
| 910 | |
---|
| 911 | |
---|
| 912 | |
---|
| 913 | /** |
---|
| 914 | Add a new menu to the menu bar |
---|
| 915 | @param aName name of menu |
---|
| 916 | @param aLabel label to display |
---|
| 917 | */ |
---|
| 918 | void G4UIQt::AddMenu ( |
---|
| 919 | const char* aName |
---|
| 920 | ,const char* aLabel |
---|
| 921 | ) |
---|
| 922 | { |
---|
| 923 | if (aName == NULL) return; |
---|
| 924 | if (aLabel == NULL) return; |
---|
| 925 | |
---|
| 926 | #if QT_VERSION < 0x040000 |
---|
| 927 | QPopupMenu *fileMenu = new QPopupMenu( fMainWindow); |
---|
| 928 | fMainWindow->menuBar()->insertItem( aLabel, fileMenu ); |
---|
| 929 | #else |
---|
| 930 | QMenu *fileMenu = new QMenu(aLabel); |
---|
| 931 | fMainWindow->menuBar()->insertMenu(fMainWindow->menuBar()->actions().last(),fileMenu); |
---|
| 932 | #endif |
---|
| 933 | |
---|
| 934 | AddInteractor (aName,(G4Interactor)fileMenu); |
---|
| 935 | } |
---|
| 936 | |
---|
| 937 | |
---|
| 938 | /** |
---|
| 939 | Add a new button to a menu |
---|
| 940 | @param aMenu : parent menu |
---|
| 941 | @param aLabel : label to display |
---|
| 942 | @param aCommand : command to execute as a callback |
---|
| 943 | */ |
---|
| 944 | void G4UIQt::AddButton ( |
---|
| 945 | const char* aMenu |
---|
| 946 | ,const char* aLabel |
---|
| 947 | ,const char* aCommand |
---|
| 948 | ) |
---|
| 949 | { |
---|
| 950 | if(aMenu==NULL) return; // TO KEEP |
---|
| 951 | if(aLabel==NULL) return; // TO KEEP |
---|
| 952 | if(aCommand==NULL) return; // TO KEEP |
---|
| 953 | |
---|
| 954 | #if QT_VERSION < 0x040000 |
---|
| 955 | QPopupMenu *parent = (QPopupMenu*)GetInteractor(aMenu); |
---|
| 956 | #else |
---|
| 957 | QMenu *parent = (QMenu*)GetInteractor(aMenu); |
---|
| 958 | #endif |
---|
| 959 | |
---|
| 960 | if(parent==NULL) return; |
---|
| 961 | |
---|
| 962 | QSignalMapper *signalMapper = new QSignalMapper(this); |
---|
[617] | 963 | #if QT_VERSION < 0x030200 |
---|
[1248] | 964 | QAction *action = new QAction(QString(aLabel),QString(aLabel),QKeySequence(),signalMapper, SLOT(map())); |
---|
[620] | 965 | action->addTo(parent); |
---|
| 966 | connect(action,SIGNAL(activated()),signalMapper,SLOT(map())); |
---|
| 967 | |
---|
| 968 | #elif QT_VERSION < 0x040000 |
---|
[1248] | 969 | QAction *action = new QAction(QString(aLabel),QKeySequence(),signalMapper, SLOT(map())); |
---|
[607] | 970 | action->addTo(parent); |
---|
[624] | 971 | connect(action,SIGNAL(activated()),signalMapper,SLOT(map())); |
---|
[620] | 972 | |
---|
[607] | 973 | #else |
---|
| 974 | QAction *action = parent->addAction(aLabel, signalMapper, SLOT(map())); |
---|
[620] | 975 | |
---|
[607] | 976 | #endif |
---|
[620] | 977 | connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&))); |
---|
[607] | 978 | signalMapper->setMapping(action, QString(aCommand)); |
---|
| 979 | } |
---|
| 980 | |
---|
| 981 | |
---|
| 982 | |
---|
| 983 | |
---|
[695] | 984 | void G4UIQt::ActivateCommand( |
---|
| 985 | G4String newCommand |
---|
| 986 | ) |
---|
| 987 | { |
---|
[697] | 988 | if (!fHelpTreeWidget) { |
---|
| 989 | return; |
---|
| 990 | } |
---|
[607] | 991 | // Look for the choosen command "newCommand" |
---|
| 992 | size_t i = newCommand.index(" "); |
---|
[1226] | 993 | G4String targetCom =""; |
---|
[607] | 994 | if( i != std::string::npos ) |
---|
| 995 | { |
---|
| 996 | G4String newValue = newCommand(i+1,newCommand.length()-(i+1)); |
---|
| 997 | newValue.strip(G4String::both); |
---|
| 998 | targetCom = ModifyToFullPathCommand( newValue ); |
---|
| 999 | } |
---|
[1226] | 1000 | #ifdef G4DEBUG_INTERFACES_BASIC |
---|
[1248] | 1001 | printf("G4UIQt::ActivateCommand found : %s \n",targetCom.data()); |
---|
[1226] | 1002 | #endif |
---|
[607] | 1003 | if (targetCom != "") { |
---|
[1226] | 1004 | OpenHelpTreeOnCommand(targetCom.data()); |
---|
| 1005 | } |
---|
[607] | 1006 | |
---|
[1266] | 1007 | #if QT_VERSION < 0x040000 |
---|
| 1008 | fToolBox->setCurrentItem(fHelpTBWidget); |
---|
| 1009 | #else |
---|
[1223] | 1010 | fToolBox->setCurrentWidget(fHelpTBWidget); |
---|
[1266] | 1011 | #endif |
---|
[607] | 1012 | } |
---|
| 1013 | |
---|
[697] | 1014 | |
---|
| 1015 | |
---|
| 1016 | /** |
---|
| 1017 | Create the help tree widget |
---|
| 1018 | @param parent : parent of tree widget |
---|
| 1019 | @return the widget containing the tree or NULL if it could not have beeen created |
---|
| 1020 | */ |
---|
| 1021 | |
---|
[1248] | 1022 | void G4UIQt::InitHelpTree() |
---|
| 1023 | { |
---|
| 1024 | |
---|
| 1025 | if (! fHelpTreeWidget ) { |
---|
[697] | 1026 | #if QT_VERSION < 0x040000 |
---|
[1266] | 1027 | fHelpTreeWidget = new QListView(fHelpVSplitter); |
---|
[697] | 1028 | #else |
---|
[1248] | 1029 | fHelpTreeWidget = new QTreeWidget(); |
---|
[697] | 1030 | #endif |
---|
[1248] | 1031 | } |
---|
[697] | 1032 | |
---|
[1252] | 1033 | |
---|
[697] | 1034 | // build widget |
---|
| 1035 | #if QT_VERSION < 0x040000 |
---|
| 1036 | fHelpTreeWidget->setSelectionMode(QListView::Single); |
---|
| 1037 | fHelpTreeWidget->setRootIsDecorated(true); |
---|
| 1038 | fHelpTreeWidget->addColumn("Command"); |
---|
| 1039 | fHelpTreeWidget->header()->setResizeEnabled(FALSE,1); |
---|
| 1040 | #else |
---|
| 1041 | fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection); |
---|
| 1042 | QStringList labels; |
---|
[700] | 1043 | labels << QString("Command"); |
---|
[697] | 1044 | fHelpTreeWidget->setHeaderLabels(labels); |
---|
| 1045 | #endif |
---|
| 1046 | |
---|
[1248] | 1047 | |
---|
| 1048 | #if QT_VERSION < 0x040000 |
---|
| 1049 | connect(fHelpTreeWidget, SIGNAL(selectionChanged ()),this, SLOT(HelpTreeClicCallback())); |
---|
| 1050 | connect(fHelpTreeWidget, SIGNAL(doubleClicked (QListViewItem*)),this, SLOT(HelpTreeDoubleClicCallback())); |
---|
| 1051 | #else |
---|
| 1052 | connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback())); |
---|
| 1053 | connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback())); |
---|
| 1054 | #endif |
---|
| 1055 | |
---|
| 1056 | } |
---|
| 1057 | /** |
---|
| 1058 | Create the help tree widget |
---|
| 1059 | @param parent : parent of tree widget |
---|
| 1060 | @return the widget containing the tree or NULL if it could not have beeen created |
---|
| 1061 | */ |
---|
| 1062 | |
---|
| 1063 | void G4UIQt::FillHelpTree() |
---|
| 1064 | { |
---|
| 1065 | if (! fHelpTreeWidget ) { |
---|
| 1066 | InitHelpTree(); |
---|
| 1067 | } |
---|
[1250] | 1068 | |
---|
[1248] | 1069 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
| 1070 | if(UI==NULL) return; |
---|
| 1071 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
| 1072 | |
---|
[697] | 1073 | G4int treeSize = treeTop->GetTreeEntry(); |
---|
| 1074 | #if QT_VERSION < 0x040000 |
---|
[1250] | 1075 | QListViewItem * newItem = NULL; |
---|
[697] | 1076 | #else |
---|
[1250] | 1077 | QTreeWidgetItem * newItem = NULL; |
---|
[697] | 1078 | #endif |
---|
[1250] | 1079 | QString commandText = ""; |
---|
[697] | 1080 | for (int a=0;a<treeSize;a++) { |
---|
| 1081 | // Creating new item |
---|
[1251] | 1082 | newItem = NULL; |
---|
[697] | 1083 | |
---|
| 1084 | #if QT_VERSION < 0x040000 |
---|
[1250] | 1085 | commandText = QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace(); |
---|
[697] | 1086 | #else |
---|
[1250] | 1087 | commandText = QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed(); |
---|
[697] | 1088 | #endif |
---|
| 1089 | |
---|
[1250] | 1090 | // if already exist, don't create it ! |
---|
| 1091 | #if QT_VERSION < 0x040000 |
---|
[1252] | 1092 | QListViewItem* tmpAddItem = fHelpTreeWidget->firstChild(); |
---|
| 1093 | while (tmpAddItem != 0) { |
---|
[1250] | 1094 | if (!newItem) { |
---|
[1252] | 1095 | newItem = FindTreeItem(tmpAddItem,commandText); |
---|
[1250] | 1096 | } |
---|
[1252] | 1097 | tmpAddItem = tmpAddItem->nextSibling(); |
---|
[1250] | 1098 | } |
---|
| 1099 | #else |
---|
[1251] | 1100 | for (int b=0;b<fHelpTreeWidget->topLevelItemCount();b++) { |
---|
[1250] | 1101 | if (!newItem) |
---|
| 1102 | newItem = FindTreeItem(fHelpTreeWidget->topLevelItem(b),commandText); |
---|
| 1103 | } |
---|
| 1104 | #endif |
---|
[697] | 1105 | |
---|
[1250] | 1106 | if (newItem == NULL) { |
---|
| 1107 | |
---|
| 1108 | #if QT_VERSION < 0x040000 |
---|
| 1109 | newItem = new QListViewItem(fHelpTreeWidget); |
---|
| 1110 | #else |
---|
| 1111 | newItem = new QTreeWidgetItem(fHelpTreeWidget); |
---|
| 1112 | #endif |
---|
| 1113 | newItem->setText(0,GetShortCommandPath(commandText)); |
---|
| 1114 | } |
---|
| 1115 | |
---|
[697] | 1116 | // look for childs |
---|
| 1117 | CreateChildTree(newItem,treeTop->GetTree(a+1)); |
---|
| 1118 | } |
---|
[1252] | 1119 | |
---|
[697] | 1120 | } |
---|
| 1121 | |
---|
| 1122 | |
---|
| 1123 | |
---|
[607] | 1124 | /** Fill the Help Tree Widget |
---|
| 1125 | @param aParent : parent item to fill |
---|
| 1126 | @param aCommandTree : commandTree node associate with this part of the Tree |
---|
| 1127 | */ |
---|
| 1128 | #if QT_VERSION < 0x040000 |
---|
| 1129 | void G4UIQt::CreateChildTree( |
---|
| 1130 | QListViewItem *aParent |
---|
| 1131 | ,G4UIcommandTree *aCommandTree |
---|
| 1132 | #else |
---|
| 1133 | void G4UIQt::CreateChildTree( |
---|
| 1134 | QTreeWidgetItem *aParent |
---|
| 1135 | ,G4UIcommandTree *aCommandTree |
---|
| 1136 | #endif |
---|
| 1137 | ) |
---|
| 1138 | { |
---|
| 1139 | if (aParent == NULL) return; |
---|
| 1140 | if (aCommandTree == NULL) return; |
---|
| 1141 | |
---|
| 1142 | |
---|
| 1143 | // Creating new item |
---|
| 1144 | #if QT_VERSION < 0x040000 |
---|
| 1145 | QListViewItem * newItem; |
---|
| 1146 | #else |
---|
| 1147 | QTreeWidgetItem * newItem; |
---|
| 1148 | #endif |
---|
| 1149 | |
---|
[1250] | 1150 | QString commandText = ""; |
---|
[607] | 1151 | // Get the Sub directories |
---|
| 1152 | for (int a=0;a<aCommandTree->GetTreeEntry();a++) { |
---|
| 1153 | |
---|
| 1154 | #if QT_VERSION < 0x040000 |
---|
[1250] | 1155 | commandText = QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace(); |
---|
| 1156 | #else |
---|
| 1157 | commandText = QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed(); |
---|
| 1158 | #endif |
---|
| 1159 | |
---|
| 1160 | // if already exist, don't create it ! |
---|
| 1161 | newItem = FindTreeItem(aParent,commandText); |
---|
| 1162 | if (newItem == NULL) { |
---|
| 1163 | #if QT_VERSION < 0x040000 |
---|
[607] | 1164 | newItem = new QListViewItem(aParent); |
---|
| 1165 | #else |
---|
[1250] | 1166 | newItem = new QTreeWidgetItem(aParent); |
---|
[607] | 1167 | #endif |
---|
[1250] | 1168 | newItem->setText(0,GetShortCommandPath(commandText)); |
---|
| 1169 | } |
---|
[607] | 1170 | CreateChildTree(newItem,aCommandTree->GetTree(a+1)); |
---|
| 1171 | } |
---|
| 1172 | |
---|
| 1173 | |
---|
| 1174 | |
---|
| 1175 | // Get the Commands |
---|
| 1176 | |
---|
| 1177 | for (int a=0;a<aCommandTree->GetCommandEntry();a++) { |
---|
| 1178 | |
---|
| 1179 | QStringList stringList; |
---|
| 1180 | #if QT_VERSION < 0x040000 |
---|
[1251] | 1181 | commandText = QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).simplifyWhiteSpace(); |
---|
| 1182 | #else |
---|
| 1183 | commandText = QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed(); |
---|
| 1184 | #endif |
---|
[607] | 1185 | |
---|
[1251] | 1186 | // if already exist, don't create it ! |
---|
| 1187 | newItem = FindTreeItem(aParent,commandText); |
---|
| 1188 | if (newItem == NULL) { |
---|
| 1189 | #if QT_VERSION < 0x040000 |
---|
| 1190 | newItem = new QListViewItem(aParent); |
---|
| 1191 | newItem->setText(0,GetShortCommandPath(commandText)); |
---|
| 1192 | newItem->setOpen(false); |
---|
| 1193 | |
---|
[607] | 1194 | #else |
---|
[1251] | 1195 | newItem = new QTreeWidgetItem(aParent); |
---|
| 1196 | newItem->setText(0,GetShortCommandPath(commandText)); |
---|
[607] | 1197 | #if QT_VERSION < 0x040202 |
---|
[1251] | 1198 | fHelpTreeWidget->setItemExpanded(newItem,false); |
---|
[607] | 1199 | #else |
---|
[1251] | 1200 | newItem->setExpanded(false); |
---|
[607] | 1201 | #endif |
---|
| 1202 | #endif |
---|
[1251] | 1203 | } |
---|
[607] | 1204 | } |
---|
| 1205 | } |
---|
| 1206 | |
---|
[1248] | 1207 | |
---|
[607] | 1208 | /** Find a treeItemWidget in the help tree |
---|
| 1209 | @param aCommand item's String to look for |
---|
| 1210 | @return item if found, NULL if not |
---|
| 1211 | */ |
---|
| 1212 | #if QT_VERSION < 0x040000 |
---|
| 1213 | QListViewItem* G4UIQt::FindTreeItem( |
---|
| 1214 | QListViewItem *aParent |
---|
| 1215 | #else |
---|
| 1216 | QTreeWidgetItem* G4UIQt::FindTreeItem( |
---|
| 1217 | QTreeWidgetItem *aParent |
---|
| 1218 | #endif |
---|
| 1219 | ,const QString& aCommand |
---|
| 1220 | ) |
---|
| 1221 | { |
---|
| 1222 | if (aParent == NULL) return NULL; |
---|
| 1223 | |
---|
[1251] | 1224 | // Suppress last "/" |
---|
| 1225 | QString myCommand = aCommand; |
---|
| 1226 | |
---|
[1266] | 1227 | #if QT_VERSION < 0x040000 |
---|
[1267] | 1228 | if (myCommand.findRev("/") == ((int)myCommand.length()-1)) { |
---|
[1266] | 1229 | myCommand = myCommand.left(myCommand.length()-1); |
---|
| 1230 | #else |
---|
[1251] | 1231 | if (myCommand.lastIndexOf("/") == (myCommand.size()-1)) { |
---|
| 1232 | myCommand = myCommand.left(myCommand.size()-1); |
---|
[1266] | 1233 | #endif |
---|
[1251] | 1234 | } |
---|
| 1235 | |
---|
| 1236 | if (GetLongCommandPath(aParent) == myCommand) |
---|
[607] | 1237 | return aParent; |
---|
| 1238 | |
---|
| 1239 | #if QT_VERSION < 0x040000 |
---|
| 1240 | QListViewItem * tmp = NULL; |
---|
| 1241 | QListViewItem* tmpItem = aParent->firstChild(); |
---|
| 1242 | while (tmpItem != 0) { |
---|
| 1243 | if (!tmp) |
---|
[1251] | 1244 | tmp = FindTreeItem(tmpItem,myCommand); |
---|
[607] | 1245 | tmpItem = tmpItem->nextSibling(); |
---|
| 1246 | } |
---|
| 1247 | #else |
---|
| 1248 | QTreeWidgetItem * tmp = NULL; |
---|
| 1249 | for (int a=0;a<aParent->childCount();a++) { |
---|
| 1250 | if (!tmp) |
---|
[1251] | 1251 | tmp = FindTreeItem(aParent->child(a),myCommand); |
---|
[607] | 1252 | } |
---|
| 1253 | #endif |
---|
| 1254 | return tmp; |
---|
| 1255 | } |
---|
| 1256 | |
---|
| 1257 | |
---|
[1158] | 1258 | |
---|
[607] | 1259 | /** Build the command list parameters in a QString<br> |
---|
| 1260 | Reimplement partialy the G4UIparameter.cc |
---|
| 1261 | @param aCommand : command to list parameters |
---|
| 1262 | @see G4UIparameter::List() |
---|
| 1263 | @see G4UIcommand::List() |
---|
| 1264 | @return the command list parameters, or "" if nothing |
---|
| 1265 | */ |
---|
| 1266 | QString G4UIQt::GetCommandList ( |
---|
| 1267 | const G4UIcommand *aCommand |
---|
| 1268 | ) |
---|
| 1269 | { |
---|
| 1270 | |
---|
| 1271 | QString txt =""; |
---|
| 1272 | if (aCommand == NULL) |
---|
| 1273 | return txt; |
---|
| 1274 | |
---|
| 1275 | G4String commandPath = aCommand->GetCommandPath(); |
---|
| 1276 | G4String rangeString = aCommand->GetRange(); |
---|
| 1277 | G4int n_guidanceEntry = aCommand->GetGuidanceEntries(); |
---|
| 1278 | G4int n_parameterEntry = aCommand->GetParameterEntries(); |
---|
| 1279 | |
---|
| 1280 | if ((commandPath == "") && |
---|
| 1281 | (rangeString == "") && |
---|
| 1282 | (n_guidanceEntry == 0) && |
---|
| 1283 | (n_parameterEntry == 0)) { |
---|
| 1284 | return txt; |
---|
| 1285 | } |
---|
| 1286 | |
---|
| 1287 | if((commandPath.length()-1)!='/') { |
---|
| 1288 | txt += "Command " + QString((char*)(commandPath).data()) + "\n"; |
---|
| 1289 | } |
---|
| 1290 | txt += "Guidance :\n"; |
---|
| 1291 | |
---|
| 1292 | for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) { |
---|
| 1293 | txt += QString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n"; |
---|
| 1294 | } |
---|
| 1295 | if( ! rangeString.isNull() ) { |
---|
| 1296 | txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n"; |
---|
| 1297 | } |
---|
| 1298 | if( n_parameterEntry > 0 ) { |
---|
| 1299 | G4UIparameter *param; |
---|
| 1300 | |
---|
| 1301 | // Re-implementation of G4UIparameter.cc |
---|
| 1302 | |
---|
| 1303 | for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) { |
---|
| 1304 | param = aCommand->GetParameter(i_thParameter); |
---|
| 1305 | txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n"; |
---|
| 1306 | if( ! param->GetParameterGuidance().isNull() ) |
---|
| 1307 | txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ; |
---|
| 1308 | txt += " Parameter type : " + QString(QChar(param->GetParameterType())) + "\n"; |
---|
| 1309 | if(param->IsOmittable()){ |
---|
| 1310 | txt += " Omittable : True\n"; |
---|
| 1311 | } else { |
---|
| 1312 | txt += " Omittable : False\n"; |
---|
| 1313 | } |
---|
| 1314 | if( param->GetCurrentAsDefault() ) { |
---|
| 1315 | txt += " Default value : taken from the current value\n"; |
---|
| 1316 | } else if( ! param->GetDefaultValue().isNull() ) { |
---|
| 1317 | txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n"; |
---|
| 1318 | } |
---|
| 1319 | if( ! param->GetParameterRange().isNull() ) { |
---|
| 1320 | txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n"; |
---|
| 1321 | } |
---|
| 1322 | if( ! param->GetParameterCandidates().isNull() ) { |
---|
| 1323 | txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n"; |
---|
| 1324 | } |
---|
| 1325 | } |
---|
| 1326 | } |
---|
| 1327 | return txt; |
---|
| 1328 | } |
---|
| 1329 | |
---|
| 1330 | |
---|
| 1331 | |
---|
| 1332 | /** Implement G4VBasicShell vurtual function |
---|
| 1333 | */ |
---|
| 1334 | G4bool G4UIQt::GetHelpChoice( |
---|
[1033] | 1335 | G4int& |
---|
[607] | 1336 | ) |
---|
| 1337 | { |
---|
[1118] | 1338 | #ifdef G4DEBUG_INTERFACES_BASIC |
---|
[607] | 1339 | printf("G4UIQt::GetHelpChoice SHOULD NEVER GO HERE"); |
---|
[608] | 1340 | #endif |
---|
[607] | 1341 | return true; |
---|
| 1342 | } |
---|
| 1343 | |
---|
| 1344 | |
---|
| 1345 | /** Event filter method. Every event from QtApplication goes here.<br/> |
---|
| 1346 | We apply a filter only for the Up and Down Arrow press when the QLineEdit<br/> |
---|
| 1347 | is active. If this filter match, Up arrow we give the previous command<br/> |
---|
| 1348 | and Down arrow will give the next if exist.<br/> |
---|
| 1349 | @param obj Emitter of the event |
---|
| 1350 | @param event Kind of event |
---|
| 1351 | */ |
---|
| 1352 | bool G4UIQt::eventFilter( // Should stay with a minuscule eventFilter because of Qt |
---|
| 1353 | QObject *aObj |
---|
| 1354 | ,QEvent *aEvent |
---|
| 1355 | ) |
---|
| 1356 | { |
---|
[1223] | 1357 | bool moveCommandCursor = false; |
---|
[607] | 1358 | if (aObj == NULL) return false; |
---|
| 1359 | if (aEvent == NULL) return false; |
---|
| 1360 | |
---|
[1224] | 1361 | if (aObj == fHistoryTBTableList) { |
---|
[607] | 1362 | if (aEvent->type() == QEvent::KeyPress) { |
---|
| 1363 | fCommandArea->setFocus(); |
---|
| 1364 | } |
---|
| 1365 | } |
---|
| 1366 | if (aObj == fCommandArea) { |
---|
| 1367 | if (aEvent->type() == QEvent::KeyPress) { |
---|
| 1368 | QKeyEvent *e = static_cast<QKeyEvent*>(aEvent); |
---|
| 1369 | if ((e->key() == (Qt::Key_Down)) || |
---|
| 1370 | (e->key() == (Qt::Key_PageDown)) || |
---|
| 1371 | (e->key() == (Qt::Key_Up)) || |
---|
| 1372 | (e->key() == (Qt::Key_PageUp))) { |
---|
| 1373 | #if QT_VERSION < 0x040000 |
---|
| 1374 | // count rows... |
---|
[1224] | 1375 | QListViewItem* tmpItem = fHistoryTBTableList->firstChild(); |
---|
[607] | 1376 | int selection = -1; |
---|
| 1377 | int index = 0; |
---|
| 1378 | while (tmpItem != 0) { |
---|
[1224] | 1379 | if (tmpItem == fHistoryTBTableList->selectedItem()) { |
---|
[607] | 1380 | selection = index; |
---|
| 1381 | } |
---|
| 1382 | index ++; |
---|
| 1383 | tmpItem = tmpItem->nextSibling(); |
---|
| 1384 | } |
---|
[1224] | 1385 | if (fHistoryTBTableList->childCount()) { |
---|
[607] | 1386 | if (selection == -1) { |
---|
[1224] | 1387 | selection = fHistoryTBTableList->childCount()-1; |
---|
[607] | 1388 | } else { |
---|
| 1389 | if (e->key() == (Qt::Key_Down)) { |
---|
[1224] | 1390 | if (selection <(fHistoryTBTableList->childCount()-1)) |
---|
[607] | 1391 | selection++; |
---|
| 1392 | } else if (e->key() == (Qt::Key_PageDown)) { |
---|
[1224] | 1393 | selection = fHistoryTBTableList->childCount()-1; |
---|
[607] | 1394 | #else |
---|
[1224] | 1395 | int selection = fHistoryTBTableList->currentRow(); |
---|
| 1396 | if (fHistoryTBTableList->count()) { |
---|
[607] | 1397 | if (selection == -1) { |
---|
[1224] | 1398 | selection = fHistoryTBTableList->count()-1; |
---|
[607] | 1399 | } else { |
---|
| 1400 | if (e->key() == (Qt::Key_Down)) { |
---|
[1224] | 1401 | if (selection <(fHistoryTBTableList->count()-1)) |
---|
[607] | 1402 | selection++; |
---|
| 1403 | } else if (e->key() == (Qt::Key_PageDown)) { |
---|
[1224] | 1404 | selection = fHistoryTBTableList->count()-1; |
---|
[607] | 1405 | #endif |
---|
| 1406 | } else if (e->key() == (Qt::Key_Up)) { |
---|
| 1407 | if (selection >0) |
---|
| 1408 | selection --; |
---|
| 1409 | } else if (e->key() == (Qt::Key_PageUp)) { |
---|
| 1410 | selection = 0; |
---|
| 1411 | } |
---|
| 1412 | } |
---|
[1224] | 1413 | fHistoryTBTableList->clearSelection(); |
---|
[607] | 1414 | #if QT_VERSION < 0x040000 |
---|
[1224] | 1415 | QListViewItem* tmpItem = fHistoryTBTableList->firstChild(); |
---|
[607] | 1416 | int index = 0; |
---|
| 1417 | while (tmpItem != 0) { |
---|
| 1418 | if (index == selection) { |
---|
| 1419 | tmpItem->setSelected(true); |
---|
[1224] | 1420 | fHistoryTBTableList->setCurrentItem(tmpItem); |
---|
[607] | 1421 | } |
---|
| 1422 | index ++; |
---|
| 1423 | tmpItem = tmpItem->nextSibling(); |
---|
| 1424 | } |
---|
| 1425 | #else |
---|
| 1426 | #if QT_VERSION < 0x040202 |
---|
[1224] | 1427 | fHistoryTBTableList->setItemSelected(fHistoryTBTableList->item(selection),true); |
---|
[607] | 1428 | #else |
---|
[1224] | 1429 | fHistoryTBTableList->item(selection)->setSelected(true); |
---|
[607] | 1430 | #endif |
---|
[1224] | 1431 | fHistoryTBTableList->setCurrentItem(fHistoryTBTableList->item(selection)); |
---|
[607] | 1432 | #endif |
---|
| 1433 | } |
---|
[1223] | 1434 | moveCommandCursor = true; |
---|
[607] | 1435 | } else if (e->key() == (Qt::Key_Tab)) { |
---|
| 1436 | #if QT_VERSION < 0x040000 |
---|
| 1437 | G4String ss = Complete(fCommandArea->text().ascii()); |
---|
| 1438 | #else |
---|
| 1439 | G4String ss = Complete(fCommandArea->text().toStdString().c_str()); |
---|
| 1440 | #endif |
---|
| 1441 | fCommandArea->setText((char*)(ss.data())); |
---|
| 1442 | |
---|
| 1443 | // do not pass by parent, it will disable widget tab focus ! |
---|
| 1444 | return true; |
---|
[1183] | 1445 | #if QT_VERSION >= 0x040000 |
---|
[1184] | 1446 | // L.Garnier : MetaModifier is CTRL for MAC, but I don't want to put a MAC |
---|
| 1447 | // specific #ifdef |
---|
| 1448 | } else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_A)) { |
---|
| 1449 | fCommandArea->home(false); |
---|
| 1450 | return true; |
---|
| 1451 | } else if (((e->modifiers () == Qt::ControlModifier) || (e->modifiers () == Qt::MetaModifier)) && (e->key() == Qt::Key_E)) { |
---|
| 1452 | fCommandArea->end(false); |
---|
| 1453 | return true; |
---|
[1177] | 1454 | #endif |
---|
[607] | 1455 | } |
---|
| 1456 | } |
---|
| 1457 | } |
---|
[1223] | 1458 | bool res= false; |
---|
| 1459 | // change cursor position if needed |
---|
| 1460 | if (moveCommandCursor == true) { |
---|
| 1461 | #ifdef G4DEBUG_INTERFACES_BASIC |
---|
| 1462 | printf("G4UIQt::eventFilter setCursor Position\n"); |
---|
| 1463 | #endif |
---|
| 1464 | fCommandArea->setCursorPosition ( fCommandArea->text().length() ); |
---|
| 1465 | fCommandArea->setCursorPosition (4); |
---|
| 1466 | } else { |
---|
| 1467 | // pass the event on to the parent class |
---|
| 1468 | res = QObject::eventFilter(aObj, aEvent); |
---|
| 1469 | } |
---|
| 1470 | return res; |
---|
[607] | 1471 | } |
---|
| 1472 | |
---|
| 1473 | |
---|
| 1474 | |
---|
| 1475 | |
---|
| 1476 | /***************************************************************************/ |
---|
| 1477 | // |
---|
| 1478 | // SLOTS DEFINITIONS |
---|
| 1479 | // |
---|
| 1480 | /***************************************************************************/ |
---|
| 1481 | |
---|
| 1482 | /** Called when user give "help" command. |
---|
| 1483 | */ |
---|
| 1484 | void G4UIQt::ShowHelpCallback ( |
---|
| 1485 | ) |
---|
| 1486 | { |
---|
| 1487 | TerminalHelp(""); |
---|
| 1488 | } |
---|
| 1489 | |
---|
| 1490 | |
---|
| 1491 | /** Called when user click on clear button. Clear the text Output area |
---|
| 1492 | */ |
---|
| 1493 | void G4UIQt::ClearButtonCallback ( |
---|
| 1494 | ) |
---|
| 1495 | { |
---|
[1224] | 1496 | fCoutTBTextArea->clear(); |
---|
| 1497 | fG4cout.clear(); |
---|
[607] | 1498 | } |
---|
| 1499 | |
---|
[608] | 1500 | /** Called when user exit session |
---|
| 1501 | */ |
---|
| 1502 | void G4UIQt::ExitSession ( |
---|
| 1503 | ) |
---|
| 1504 | { |
---|
| 1505 | SessionTerminate(); |
---|
| 1506 | } |
---|
[607] | 1507 | |
---|
[1224] | 1508 | void G4UIQt::ExitHelp( |
---|
| 1509 | ) |
---|
| 1510 | { |
---|
| 1511 | } |
---|
[608] | 1512 | |
---|
[607] | 1513 | /** Callback call when "click on a menu entry.<br> |
---|
| 1514 | Send the associated command to geant4 |
---|
| 1515 | */ |
---|
| 1516 | void G4UIQt::CommandEnteredCallback ( |
---|
| 1517 | ) |
---|
| 1518 | { |
---|
| 1519 | #if QT_VERSION < 0x040000 |
---|
| 1520 | G4String command (fCommandArea->text().ascii()); |
---|
| 1521 | if (fCommandArea->text().simplifyWhiteSpace() != "") { |
---|
| 1522 | |
---|
[1224] | 1523 | QListViewItem *newItem = new QListViewItem(fHistoryTBTableList); |
---|
[607] | 1524 | newItem->setText(0,fCommandArea->text()); |
---|
[1224] | 1525 | fHistoryTBTableList->insertItem(newItem); |
---|
[620] | 1526 | // now we have to arrange |
---|
[1224] | 1527 | QListViewItem *temp= fHistoryTBTableList->lastItem(); |
---|
| 1528 | for (int i=0; i<fHistoryTBTableList->childCount()-1;i++) { |
---|
| 1529 | fHistoryTBTableList->takeItem(temp); |
---|
| 1530 | fHistoryTBTableList->insertItem(temp); |
---|
| 1531 | temp= fHistoryTBTableList->lastItem(); |
---|
[620] | 1532 | } |
---|
[607] | 1533 | #else |
---|
| 1534 | G4String command (fCommandArea->text().toStdString().c_str()); |
---|
| 1535 | if (fCommandArea->text().trimmed() != "") { |
---|
[1224] | 1536 | fHistoryTBTableList->addItem(fCommandArea->text()); |
---|
[607] | 1537 | #endif |
---|
[1224] | 1538 | fHistoryTBTableList->clearSelection(); |
---|
| 1539 | fHistoryTBTableList->setCurrentItem(NULL); |
---|
[607] | 1540 | fCommandArea->setText(""); |
---|
| 1541 | |
---|
| 1542 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
| 1543 | if (interactorManager) { |
---|
| 1544 | interactorManager->FlushAndWaitExecution(); |
---|
| 1545 | } |
---|
| 1546 | if (command(0,4) != "help") { |
---|
| 1547 | ApplyShellCommand (command,exitSession,exitPause); |
---|
| 1548 | } else { |
---|
[1223] | 1549 | ActivateCommand(command); |
---|
[607] | 1550 | } |
---|
[1248] | 1551 | // Rebuild help tree |
---|
| 1552 | FillHelpTree(); |
---|
| 1553 | |
---|
[607] | 1554 | if(exitSession==true) |
---|
| 1555 | SessionTerminate(); |
---|
| 1556 | } |
---|
| 1557 | } |
---|
| 1558 | |
---|
| 1559 | |
---|
| 1560 | /** Callback call when "enter" clicked on the command zone.<br> |
---|
| 1561 | Send the command to geant4 |
---|
| 1562 | @param aCommand |
---|
| 1563 | */ |
---|
| 1564 | void G4UIQt::ButtonCallback ( |
---|
| 1565 | const QString& aCommand |
---|
| 1566 | ) |
---|
| 1567 | { |
---|
| 1568 | #if QT_VERSION < 0x040000 |
---|
| 1569 | G4String ss = G4String(aCommand.ascii()); |
---|
| 1570 | #else |
---|
| 1571 | G4String ss = G4String(aCommand.toStdString().c_str()); |
---|
| 1572 | #endif |
---|
| 1573 | ApplyShellCommand(ss,exitSession,exitPause); |
---|
[1248] | 1574 | |
---|
| 1575 | // Rebuild help tree |
---|
| 1576 | FillHelpTree(); |
---|
| 1577 | |
---|
[607] | 1578 | if(exitSession==true) |
---|
| 1579 | SessionTerminate(); |
---|
| 1580 | } |
---|
| 1581 | |
---|
| 1582 | |
---|
| 1583 | |
---|
| 1584 | /** This callback is activated when user selected a item in the help tree |
---|
| 1585 | */ |
---|
| 1586 | void G4UIQt::HelpTreeClicCallback ( |
---|
| 1587 | ) |
---|
| 1588 | { |
---|
| 1589 | #if QT_VERSION < 0x040000 |
---|
| 1590 | QListViewItem* item = NULL; |
---|
| 1591 | #else |
---|
| 1592 | QTreeWidgetItem* item = NULL; |
---|
| 1593 | #endif |
---|
| 1594 | if (!fHelpTreeWidget) |
---|
| 1595 | return ; |
---|
| 1596 | |
---|
| 1597 | if (!fHelpArea) |
---|
| 1598 | return; |
---|
| 1599 | |
---|
| 1600 | #if QT_VERSION < 0x040000 |
---|
| 1601 | item =fHelpTreeWidget->selectedItem(); |
---|
| 1602 | #else |
---|
| 1603 | QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems(); |
---|
| 1604 | if (list.isEmpty()) |
---|
| 1605 | return; |
---|
| 1606 | item = list.first(); |
---|
| 1607 | #endif |
---|
| 1608 | if (!item) |
---|
| 1609 | return; |
---|
| 1610 | |
---|
| 1611 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
| 1612 | if(UI==NULL) return; |
---|
| 1613 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
[699] | 1614 | |
---|
[1266] | 1615 | #if QT_VERSION < 0x040000 |
---|
| 1616 | std::string itemText = GetLongCommandPath(item).ascii(); |
---|
| 1617 | #else |
---|
[1249] | 1618 | std::string itemText = GetLongCommandPath(item).toStdString(); |
---|
[1266] | 1619 | #endif |
---|
[1249] | 1620 | |
---|
[699] | 1621 | G4UIcommand* command = treeTop->FindPath(itemText.c_str()); |
---|
| 1622 | |
---|
[607] | 1623 | if (command) { |
---|
| 1624 | #if QT_VERSION >= 0x040000 |
---|
| 1625 | #if QT_VERSION < 0x040200 |
---|
| 1626 | fHelpArea->clear(); |
---|
| 1627 | fHelpArea->append(GetCommandList(command)); |
---|
| 1628 | #else |
---|
| 1629 | fHelpArea->setText(GetCommandList(command)); |
---|
| 1630 | #endif |
---|
| 1631 | #else |
---|
| 1632 | fHelpArea->setText(GetCommandList(command)); |
---|
| 1633 | #endif |
---|
[699] | 1634 | } else { // this is a command |
---|
| 1635 | G4UIcommandTree* path = treeTop->FindCommandTree(itemText.c_str()); |
---|
| 1636 | if ( path) { |
---|
| 1637 | // this is not a command, this is a sub directory |
---|
| 1638 | // We display the Title |
---|
[607] | 1639 | #if QT_VERSION >= 0x040000 |
---|
| 1640 | #if QT_VERSION < 0x040200 |
---|
[699] | 1641 | fHelpArea->clear(); |
---|
| 1642 | fHelpArea->append(path->GetTitle().data()); |
---|
[607] | 1643 | #else |
---|
[699] | 1644 | fHelpArea->setText(path->GetTitle().data()); |
---|
[607] | 1645 | #endif |
---|
| 1646 | #else |
---|
[699] | 1647 | fHelpArea->setText(path->GetTitle().data()); |
---|
[607] | 1648 | #endif |
---|
[699] | 1649 | } |
---|
[607] | 1650 | } |
---|
| 1651 | } |
---|
[699] | 1652 | |
---|
[607] | 1653 | /** This callback is activated when user double clic on a item in the help tree |
---|
| 1654 | */ |
---|
| 1655 | void G4UIQt::HelpTreeDoubleClicCallback ( |
---|
[648] | 1656 | ) |
---|
| 1657 | { |
---|
| 1658 | HelpTreeClicCallback(); |
---|
| 1659 | |
---|
[607] | 1660 | #if QT_VERSION < 0x040000 |
---|
[648] | 1661 | QListViewItem* item = NULL; |
---|
[607] | 1662 | #else |
---|
[648] | 1663 | QTreeWidgetItem* item = NULL; |
---|
[607] | 1664 | #endif |
---|
[648] | 1665 | if (!fHelpTreeWidget) |
---|
| 1666 | return ; |
---|
| 1667 | |
---|
| 1668 | if (!fHelpArea) |
---|
| 1669 | return; |
---|
| 1670 | |
---|
| 1671 | #if QT_VERSION < 0x040000 |
---|
| 1672 | item =fHelpTreeWidget->selectedItem(); |
---|
| 1673 | #else |
---|
| 1674 | QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems(); |
---|
| 1675 | if (list.isEmpty()) |
---|
| 1676 | return; |
---|
| 1677 | item = list.first(); |
---|
| 1678 | #endif |
---|
| 1679 | if (!item) |
---|
| 1680 | return; |
---|
| 1681 | |
---|
[683] | 1682 | fCommandArea->clear(); |
---|
[1249] | 1683 | fCommandArea->setText(GetLongCommandPath(item)); |
---|
[607] | 1684 | } |
---|
| 1685 | |
---|
| 1686 | |
---|
| 1687 | /** Callback called when user select an old command in the command history<br> |
---|
| 1688 | Give it to the command area. |
---|
| 1689 | */ |
---|
| 1690 | void G4UIQt::CommandHistoryCallback( |
---|
| 1691 | ) |
---|
| 1692 | { |
---|
| 1693 | #if QT_VERSION < 0x040000 |
---|
| 1694 | QListViewItem* item = NULL; |
---|
| 1695 | #else |
---|
| 1696 | QListWidgetItem* item = NULL; |
---|
| 1697 | #endif |
---|
[1224] | 1698 | if (!fHistoryTBTableList) |
---|
[607] | 1699 | return ; |
---|
[632] | 1700 | |
---|
[607] | 1701 | |
---|
| 1702 | #if QT_VERSION < 0x040000 |
---|
[1224] | 1703 | item =fHistoryTBTableList->selectedItem(); |
---|
[607] | 1704 | #else |
---|
[1224] | 1705 | QList<QListWidgetItem *> list =fHistoryTBTableList->selectedItems(); |
---|
[607] | 1706 | if (list.isEmpty()) |
---|
| 1707 | return; |
---|
| 1708 | item = list.first(); |
---|
| 1709 | #endif |
---|
| 1710 | if (!item) |
---|
| 1711 | return; |
---|
| 1712 | #if QT_VERSION < 0x040000 |
---|
| 1713 | fCommandArea->setText(item->text(0)); |
---|
| 1714 | #else |
---|
| 1715 | fCommandArea->setText(item->text()); |
---|
| 1716 | #endif |
---|
[1223] | 1717 | #ifdef G4DEBUG_INTERFACES_BASIC |
---|
| 1718 | printf("G4UIQt::CommandHistoryCallback change text\n"); |
---|
| 1719 | #endif |
---|
[607] | 1720 | } |
---|
| 1721 | |
---|
[697] | 1722 | |
---|
[1224] | 1723 | void G4UIQt::CoutFilterCallback( |
---|
| 1724 | const QString & text) { |
---|
| 1725 | |
---|
[1266] | 1726 | #if QT_VERSION < 0x040000 |
---|
| 1727 | QStringList result = ""; |
---|
| 1728 | #else |
---|
| 1729 | QStringList result = fG4cout.filter(text); |
---|
[1224] | 1730 | #endif |
---|
| 1731 | |
---|
| 1732 | fCoutTBTextArea->setText(result.join("\n")); |
---|
| 1733 | fCoutTBTextArea->repaint(); |
---|
| 1734 | #if QT_VERSION < 0x040000 |
---|
| 1735 | fCoutTBTextArea->verticalScrollBar()->setValue(fCoutTBTextArea->verticalScrollBar()->maxValue()); |
---|
| 1736 | #else |
---|
| 1737 | fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum()); |
---|
| 1738 | #endif |
---|
| 1739 | |
---|
| 1740 | } |
---|
| 1741 | |
---|
[695] | 1742 | /** Callback called when user give a new string to look for<br> |
---|
[697] | 1743 | Display a list of matching commands descriptions. If no string is set, |
---|
| 1744 | will display the complete help tree |
---|
[695] | 1745 | */ |
---|
[1226] | 1746 | void G4UIQt::LookForHelpStringCallback( |
---|
[695] | 1747 | ) |
---|
| 1748 | { |
---|
[1239] | 1749 | QString searchText = fHelpLine->text(); |
---|
[1226] | 1750 | |
---|
[698] | 1751 | #if QT_VERSION < 0x040200 |
---|
| 1752 | fHelpArea->clear(); |
---|
| 1753 | #else |
---|
| 1754 | fHelpArea->setText(""); |
---|
| 1755 | #endif |
---|
[1226] | 1756 | if (searchText =="") { |
---|
[697] | 1757 | // clear old help tree |
---|
| 1758 | fHelpTreeWidget->clear(); |
---|
[791] | 1759 | #if QT_VERSION < 0x040000 |
---|
[719] | 1760 | fHelpTreeWidget->removeColumn(1); |
---|
| 1761 | fHelpTreeWidget->removeColumn(0); |
---|
| 1762 | #endif |
---|
[1248] | 1763 | |
---|
| 1764 | FillHelpTree(); |
---|
| 1765 | |
---|
[697] | 1766 | return; |
---|
[1226] | 1767 | } else { |
---|
| 1768 | OpenHelpTreeOnCommand(searchText); |
---|
[697] | 1769 | } |
---|
[1226] | 1770 | } |
---|
[697] | 1771 | |
---|
[1226] | 1772 | |
---|
| 1773 | void G4UIQt::OpenHelpTreeOnCommand( |
---|
| 1774 | const QString & searchText |
---|
| 1775 | ) |
---|
| 1776 | { |
---|
| 1777 | |
---|
[695] | 1778 | // the help tree |
---|
| 1779 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
| 1780 | if(UI==NULL) return; |
---|
| 1781 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
| 1782 | |
---|
| 1783 | G4int treeSize = treeTop->GetTreeEntry(); |
---|
[697] | 1784 | |
---|
| 1785 | // clear old help tree |
---|
| 1786 | fHelpTreeWidget->clear(); |
---|
[793] | 1787 | #if QT_VERSION < 0x040000 |
---|
[719] | 1788 | fHelpTreeWidget->removeColumn(1); |
---|
| 1789 | fHelpTreeWidget->removeColumn(0); |
---|
| 1790 | #endif |
---|
[697] | 1791 | |
---|
| 1792 | // look for new items |
---|
| 1793 | |
---|
[695] | 1794 | int tmp = 0; |
---|
[719] | 1795 | #if QT_VERSION < 0x040000 |
---|
| 1796 | int multFactor = 1000; // factor special for having double keys in Qt3 |
---|
| 1797 | int doubleKeyAdd = 0; // decay for doubleKeys in Qt3 |
---|
| 1798 | #endif |
---|
| 1799 | |
---|
[697] | 1800 | QMap<int,QString> commandResultMap; |
---|
| 1801 | QMap<int,QString> commandChildResultMap; |
---|
| 1802 | |
---|
[695] | 1803 | for (int a=0;a<treeSize;a++) { |
---|
| 1804 | G4UIcommand* command = treeTop->FindPath(treeTop->GetTree(a+1)->GetPathName().data()); |
---|
[719] | 1805 | #if QT_VERSION > 0x040000 |
---|
[1226] | 1806 | tmp = GetCommandList (command).count(searchText,Qt::CaseInsensitive); |
---|
[719] | 1807 | #else |
---|
[1226] | 1808 | tmp = GetCommandList (command).contains(searchText,false); |
---|
[719] | 1809 | #endif |
---|
[695] | 1810 | if (tmp >0) { |
---|
[719] | 1811 | #if QT_VERSION > 0x040000 |
---|
[697] | 1812 | commandResultMap.insertMulti(tmp,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data())); |
---|
[719] | 1813 | #else // tricky thing for Qt3... |
---|
| 1814 | doubleKeyAdd = 0; |
---|
| 1815 | while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) { |
---|
| 1816 | doubleKeyAdd ++; |
---|
| 1817 | } |
---|
| 1818 | commandResultMap.insert( tmp*multFactor+doubleKeyAdd,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()) ); |
---|
[695] | 1819 | #endif |
---|
| 1820 | } |
---|
| 1821 | // look for childs |
---|
[1226] | 1822 | commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a+1),searchText); |
---|
[697] | 1823 | // insert new childs |
---|
| 1824 | if (!commandChildResultMap.empty()) { |
---|
[719] | 1825 | #if QT_VERSION > 0x040000 |
---|
[697] | 1826 | QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin(); |
---|
| 1827 | while (i != commandChildResultMap.constEnd()) { |
---|
| 1828 | commandResultMap.insertMulti(i.key(),i.value()); |
---|
[719] | 1829 | #else // tricky thing for Qt3... |
---|
| 1830 | QMap<int,QString>::const_iterator i = commandChildResultMap.begin(); |
---|
| 1831 | while (i != commandChildResultMap.end()) { |
---|
| 1832 | doubleKeyAdd = 0; |
---|
| 1833 | while (commandResultMap.find( i.key()*multFactor+doubleKeyAdd) != commandResultMap.end()) { |
---|
| 1834 | doubleKeyAdd ++; |
---|
| 1835 | } |
---|
| 1836 | commandResultMap.insert(i.key()*multFactor+doubleKeyAdd,i.data()); |
---|
| 1837 | #endif |
---|
[697] | 1838 | i++; |
---|
| 1839 | } |
---|
| 1840 | commandChildResultMap.clear(); |
---|
| 1841 | } |
---|
[695] | 1842 | } |
---|
[697] | 1843 | |
---|
| 1844 | // build new help tree |
---|
| 1845 | #if QT_VERSION < 0x040000 |
---|
| 1846 | fHelpTreeWidget->setSelectionMode(QListView::Single); |
---|
| 1847 | fHelpTreeWidget->setRootIsDecorated(true); |
---|
| 1848 | fHelpTreeWidget->addColumn("Command"); |
---|
| 1849 | fHelpTreeWidget->addColumn("Match"); |
---|
| 1850 | // fHelpTreeWidget->header()->setResizeEnabled(FALSE,1); |
---|
| 1851 | #else |
---|
| 1852 | fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection); |
---|
[700] | 1853 | fHelpTreeWidget->setColumnCount(2); |
---|
[697] | 1854 | QStringList labels; |
---|
[700] | 1855 | labels << QString("Command") << QString("Match"); |
---|
[697] | 1856 | fHelpTreeWidget->setHeaderLabels(labels); |
---|
| 1857 | #endif |
---|
| 1858 | |
---|
| 1859 | if (commandResultMap.empty()) { |
---|
| 1860 | #if QT_VERSION < 0x040200 |
---|
| 1861 | fHelpArea->clear(); |
---|
| 1862 | fHelpArea->append("No match found"); |
---|
| 1863 | #else |
---|
| 1864 | fHelpArea->setText("No match found"); |
---|
| 1865 | #endif |
---|
| 1866 | return; |
---|
| 1867 | } |
---|
| 1868 | |
---|
[719] | 1869 | #if QT_VERSION > 0x040000 |
---|
[697] | 1870 | QMap<int,QString>::const_iterator i = commandResultMap.constEnd(); |
---|
[719] | 1871 | #else |
---|
| 1872 | QMap<int,QString>::const_iterator i = commandResultMap.end(); |
---|
| 1873 | #endif |
---|
[697] | 1874 | i--; |
---|
| 1875 | // 10 maximum progress values |
---|
| 1876 | float multValue = 10.0/(float)(i.key()); |
---|
| 1877 | QString progressChar = "|"; |
---|
| 1878 | QString progressStr = "|"; |
---|
| 1879 | |
---|
| 1880 | #if QT_VERSION < 0x040000 |
---|
| 1881 | QListViewItem * newItem; |
---|
| 1882 | #else |
---|
| 1883 | QTreeWidgetItem * newItem; |
---|
| 1884 | #endif |
---|
| 1885 | bool end = false; |
---|
| 1886 | while (!end) { |
---|
[719] | 1887 | #if QT_VERSION > 0x040000 |
---|
[697] | 1888 | if (i == commandResultMap.constBegin()) { |
---|
[719] | 1889 | #else |
---|
| 1890 | if (i == commandResultMap.begin()) { |
---|
| 1891 | #endif |
---|
[697] | 1892 | end = true; |
---|
| 1893 | } |
---|
| 1894 | for(int a=0;a<int(i.key()*multValue);a++) { |
---|
| 1895 | progressStr += progressChar; |
---|
| 1896 | } |
---|
| 1897 | #if QT_VERSION < 0x040000 |
---|
| 1898 | newItem = new QListViewItem(fHelpTreeWidget); |
---|
[719] | 1899 | newItem->setText(0,i.data().simplifyWhiteSpace()); |
---|
[697] | 1900 | #else |
---|
| 1901 | newItem = new QTreeWidgetItem(fHelpTreeWidget); |
---|
| 1902 | newItem->setText(0,i.value().trimmed()); |
---|
[719] | 1903 | #endif |
---|
[700] | 1904 | newItem->setText(1,progressStr); |
---|
[697] | 1905 | |
---|
| 1906 | #if QT_VERSION >= 0x040200 |
---|
[700] | 1907 | newItem->setForeground ( 1, QBrush(Qt::blue) ); |
---|
[697] | 1908 | #endif |
---|
| 1909 | progressStr = "|"; |
---|
| 1910 | i--; |
---|
| 1911 | } |
---|
| 1912 | // FIXME : to be checked on Qt3 |
---|
| 1913 | #if QT_VERSION < 0x040000 |
---|
[700] | 1914 | fHelpTreeWidget->setColumnWidthMode (1,QListView::Maximum); |
---|
[719] | 1915 | fHelpTreeWidget->setSorting(1,false); |
---|
[697] | 1916 | #else |
---|
| 1917 | fHelpTreeWidget->resizeColumnToContents (0); |
---|
[719] | 1918 | fHelpTreeWidget->sortItems(1,Qt::DescendingOrder); |
---|
[700] | 1919 | // fHelpTreeWidget->setColumnWidth(1,10);//resizeColumnToContents (1); |
---|
[697] | 1920 | #endif |
---|
[695] | 1921 | } |
---|
| 1922 | |
---|
[697] | 1923 | |
---|
| 1924 | |
---|
| 1925 | |
---|
| 1926 | QMap<int,QString> G4UIQt::LookForHelpStringInChildTree( |
---|
[695] | 1927 | G4UIcommandTree *aCommandTree |
---|
[697] | 1928 | ,const QString & text |
---|
| 1929 | ) |
---|
[695] | 1930 | { |
---|
[697] | 1931 | QMap<int,QString> commandResultMap; |
---|
| 1932 | if (aCommandTree == NULL) return commandResultMap; |
---|
| 1933 | |
---|
[719] | 1934 | #if QT_VERSION < 0x040000 |
---|
| 1935 | int multFactor = 1000; // factor special for having double keys in Qt3 |
---|
| 1936 | int doubleKeyAdd = 0; // decay for doubleKeys in Qt3 |
---|
| 1937 | #endif |
---|
| 1938 | |
---|
[695] | 1939 | // Get the Sub directories |
---|
| 1940 | int tmp = 0; |
---|
[697] | 1941 | QMap<int,QString> commandChildResultMap; |
---|
| 1942 | |
---|
[695] | 1943 | for (int a=0;a<aCommandTree->GetTreeEntry();a++) { |
---|
| 1944 | const G4UIcommand* command = aCommandTree->GetGuidance(); |
---|
[719] | 1945 | #if QT_VERSION > 0x040000 |
---|
[695] | 1946 | tmp = GetCommandList (command).count(text,Qt::CaseInsensitive); |
---|
[719] | 1947 | #else |
---|
| 1948 | tmp = GetCommandList (command).contains(text,false); |
---|
| 1949 | #endif |
---|
[695] | 1950 | if (tmp >0) { |
---|
[719] | 1951 | #if QT_VERSION > 0x040000 |
---|
[697] | 1952 | commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data())); |
---|
[719] | 1953 | #else // tricky thing for Qt3... |
---|
| 1954 | doubleKeyAdd = 0; |
---|
| 1955 | while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) { |
---|
| 1956 | doubleKeyAdd ++; |
---|
| 1957 | } |
---|
| 1958 | commandResultMap.insert(tmp*multFactor+doubleKeyAdd,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data())); |
---|
| 1959 | #endif |
---|
[695] | 1960 | } |
---|
| 1961 | // look for childs |
---|
[697] | 1962 | commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text); |
---|
| 1963 | |
---|
| 1964 | if (!commandChildResultMap.empty()) { |
---|
| 1965 | // insert new childs |
---|
[719] | 1966 | #if QT_VERSION > 0x040000 |
---|
[697] | 1967 | QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin(); |
---|
| 1968 | while (i != commandChildResultMap.constEnd()) { |
---|
| 1969 | commandResultMap.insertMulti(i.key(),i.value()); |
---|
[719] | 1970 | #else // tricky thing for Qt3... |
---|
| 1971 | QMap<int,QString>::const_iterator i = commandChildResultMap.begin(); |
---|
| 1972 | while (i != commandChildResultMap.end()) { |
---|
| 1973 | doubleKeyAdd = 0; |
---|
| 1974 | while (commandResultMap.find( i.key()*multFactor+doubleKeyAdd) != commandResultMap.end()) { |
---|
| 1975 | doubleKeyAdd ++; |
---|
| 1976 | } |
---|
| 1977 | commandResultMap.insert(i.key()*multFactor+doubleKeyAdd,i.data()); |
---|
| 1978 | #endif |
---|
[697] | 1979 | i++; |
---|
| 1980 | } |
---|
| 1981 | commandChildResultMap.clear(); |
---|
| 1982 | } |
---|
[695] | 1983 | } |
---|
| 1984 | // Get the Commands |
---|
[697] | 1985 | |
---|
[695] | 1986 | for (int a=0;a<aCommandTree->GetCommandEntry();a++) { |
---|
| 1987 | const G4UIcommand* command = aCommandTree->GetCommand(a+1); |
---|
[719] | 1988 | #if QT_VERSION > 0x040000 |
---|
| 1989 | tmp = GetCommandList (command).count(text,Qt::CaseInsensitive); |
---|
| 1990 | #else |
---|
| 1991 | tmp = GetCommandList (command).contains(text,false); |
---|
[695] | 1992 | #endif |
---|
| 1993 | if (tmp >0) { |
---|
[719] | 1994 | #if QT_VERSION > 0x040000 |
---|
[697] | 1995 | commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data())); |
---|
[719] | 1996 | #else // tricky thing for Qt3... |
---|
| 1997 | doubleKeyAdd = 0; |
---|
| 1998 | while (commandResultMap.find( tmp*multFactor+doubleKeyAdd) != commandResultMap.end()) { |
---|
| 1999 | doubleKeyAdd ++; |
---|
| 2000 | } |
---|
| 2001 | commandResultMap.insert(tmp*multFactor+doubleKeyAdd,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data())); |
---|
| 2002 | #endif |
---|
[695] | 2003 | } |
---|
| 2004 | |
---|
| 2005 | } |
---|
[697] | 2006 | return commandResultMap; |
---|
[695] | 2007 | } |
---|
[1232] | 2008 | |
---|
[1236] | 2009 | |
---|
[1249] | 2010 | QString G4UIQt::GetShortCommandPath( |
---|
| 2011 | QString commandPath |
---|
| 2012 | ) |
---|
| 2013 | { |
---|
[1267] | 2014 | #if QT_VERSION < 0x040000 |
---|
[1268] | 2015 | if (commandPath.find("/") == 0) { |
---|
[1267] | 2016 | commandPath = commandPath.right(commandPath.length()-1); |
---|
| 2017 | #else |
---|
[1268] | 2018 | if (commandPath.indexOf("/") == 0) { |
---|
[1249] | 2019 | commandPath = commandPath.right(commandPath.size()-1); |
---|
[1267] | 2020 | #endif |
---|
[1249] | 2021 | } |
---|
[1236] | 2022 | |
---|
[1267] | 2023 | #if QT_VERSION < 0x040000 |
---|
| 2024 | commandPath = commandPath.right(commandPath.length()-commandPath.findRev("/",-2)-1); |
---|
| 2025 | #else |
---|
[1249] | 2026 | commandPath = commandPath.right(commandPath.size()-commandPath.lastIndexOf("/",-2)-1); |
---|
[1267] | 2027 | #endif |
---|
[1249] | 2028 | |
---|
[1267] | 2029 | #if QT_VERSION < 0x040000 |
---|
| 2030 | if (commandPath.findRev("/") == ((int)commandPath.length()-1)) { |
---|
| 2031 | commandPath = commandPath.left(commandPath.length()-1); |
---|
| 2032 | } |
---|
| 2033 | #else |
---|
[1249] | 2034 | if (commandPath.lastIndexOf("/") == (commandPath.size()-1)) { |
---|
| 2035 | commandPath = commandPath.left(commandPath.size()-1); |
---|
[1267] | 2036 | } |
---|
| 2037 | #endif |
---|
[1249] | 2038 | |
---|
| 2039 | return commandPath; |
---|
| 2040 | } |
---|
| 2041 | |
---|
| 2042 | |
---|
| 2043 | QString G4UIQt::GetLongCommandPath( |
---|
| 2044 | #if QT_VERSION < 0x040000 |
---|
| 2045 | QListViewItem* item |
---|
| 2046 | #else |
---|
| 2047 | QTreeWidgetItem* item |
---|
| 2048 | #endif |
---|
| 2049 | ) |
---|
| 2050 | { |
---|
| 2051 | if (item == NULL) return ""; |
---|
| 2052 | |
---|
| 2053 | // rebuild path: |
---|
| 2054 | QString itemText = ""; |
---|
| 2055 | itemText = item->text(0); |
---|
| 2056 | |
---|
| 2057 | while (item->parent() != NULL) { |
---|
| 2058 | itemText = item->parent()->text(0)+"/"+itemText; |
---|
| 2059 | item = item->parent(); |
---|
| 2060 | } |
---|
| 2061 | itemText = "/"+itemText; |
---|
| 2062 | |
---|
| 2063 | return itemText; |
---|
| 2064 | } |
---|
| 2065 | |
---|
[1236] | 2066 | G4QTabWidget::G4QTabWidget( |
---|
| 2067 | QSplitter*& split |
---|
| 2068 | ):QTabWidget(split) |
---|
[1252] | 2069 | ,tabSelected(false) |
---|
| 2070 | ,lastCreated(-1) |
---|
[1236] | 2071 | { |
---|
| 2072 | } |
---|
| 2073 | |
---|
| 2074 | G4QTabWidget::G4QTabWidget( |
---|
| 2075 | ):QTabWidget() |
---|
[1252] | 2076 | ,tabSelected(false) |
---|
| 2077 | ,lastCreated(-1) |
---|
[1236] | 2078 | { |
---|
| 2079 | } |
---|
| 2080 | |
---|
| 2081 | |
---|
[1239] | 2082 | |
---|
| 2083 | void G4UIQt::TabCloseCallback(int a){ |
---|
[1267] | 2084 | #if QT_VERSION < 0x040000 |
---|
[1268] | 2085 | QWidget* temp = fTabWidget->page(a); |
---|
| 2086 | fTabWidget->removePage (a); |
---|
[1267] | 2087 | #else |
---|
[1239] | 2088 | QWidget* temp = fTabWidget->widget(a); |
---|
| 2089 | fTabWidget->removeTab (a); |
---|
[1267] | 2090 | #endif |
---|
| 2091 | |
---|
[1239] | 2092 | delete temp; |
---|
[1236] | 2093 | |
---|
[1239] | 2094 | if (fTabWidget->count() == 0) { |
---|
| 2095 | #if QT_VERSION < 0x040000 |
---|
[1267] | 2096 | fEmptyViewerTabLabel->setParent(fMyVSplitter); |
---|
[1239] | 2097 | fTabWidget->reparent(0,0,QPoint(0,0)); |
---|
| 2098 | #else |
---|
[1267] | 2099 | fMyVSplitter->addWidget(fEmptyViewerTabLabel); |
---|
[1239] | 2100 | fTabWidget->setParent(0); |
---|
| 2101 | #endif |
---|
| 2102 | } |
---|
| 2103 | } |
---|
| 2104 | |
---|
| 2105 | |
---|
[1248] | 2106 | void G4UIQt::ToolBoxActivated(int a){ |
---|
| 2107 | |
---|
[1267] | 2108 | #if QT_VERSION < 0x040000 |
---|
[1268] | 2109 | if (fToolBox->page(a) == fHelpTBWidget) { |
---|
[1267] | 2110 | #else |
---|
[1248] | 2111 | if (fToolBox->widget(a) == fHelpTBWidget) { |
---|
[1267] | 2112 | #endif |
---|
[1248] | 2113 | // Rebuild the help tree |
---|
| 2114 | FillHelpTree(); |
---|
| 2115 | } |
---|
[1239] | 2116 | } |
---|
| 2117 | |
---|
[1236] | 2118 | void G4QTabWidget::paintEvent( |
---|
| 2119 | QPaintEvent * event |
---|
| 2120 | ) |
---|
| 2121 | { |
---|
| 2122 | |
---|
[1267] | 2123 | #if QT_VERSION < 0x040000 |
---|
[1268] | 2124 | if (currentPage()) { |
---|
[1267] | 2125 | #else |
---|
[1236] | 2126 | if (currentWidget()) { |
---|
[1267] | 2127 | #endif |
---|
| 2128 | |
---|
[1236] | 2129 | if ( isTabSelected()) { |
---|
[1239] | 2130 | |
---|
[1263] | 2131 | #if QT_VERSION < 0x040000 |
---|
[1268] | 2132 | QApplication::sendPostedEvents () ; |
---|
[1263] | 2133 | #else |
---|
[1268] | 2134 | QCoreApplication::sendPostedEvents () ; |
---|
[1263] | 2135 | #endif |
---|
| 2136 | |
---|
[1236] | 2137 | #ifdef G4DEBUG_INTERFACES_BASIC |
---|
| 2138 | printf("G4QTabWidget::paintEvent OK\n"); |
---|
| 2139 | #endif |
---|
[1252] | 2140 | #if QT_VERSION < 0x040000 |
---|
| 2141 | QString text = label (currentPageIndex()); |
---|
| 2142 | #else |
---|
[1236] | 2143 | QString text = tabText (currentIndex()); |
---|
[1252] | 2144 | #endif |
---|
| 2145 | |
---|
| 2146 | if (lastCreated == -1) { |
---|
| 2147 | QString paramSelect = QString("/vis/viewer/select ")+text; |
---|
| 2148 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
| 2149 | if(UI != NULL) { |
---|
[1266] | 2150 | #if QT_VERSION < 0x040000 |
---|
[1267] | 2151 | UI->ApplyCommand(paramSelect.ascii()); |
---|
[1266] | 2152 | #else |
---|
[1252] | 2153 | UI->ApplyCommand(paramSelect.toStdString().c_str()); |
---|
[1266] | 2154 | #endif |
---|
[1252] | 2155 | } |
---|
| 2156 | } else { |
---|
| 2157 | lastCreated = -1; |
---|
[1236] | 2158 | } |
---|
[1237] | 2159 | unselectTab(); |
---|
[1236] | 2160 | repaint(); |
---|
| 2161 | } |
---|
| 2162 | } |
---|
| 2163 | } |
---|
| 2164 | |
---|
| 2165 | #endif |
---|