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