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