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