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