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