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