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