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