Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4UIQt.hh
Go to the documentation of this file.
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//
28#ifndef G4UIQt_h
29#define G4UIQt_h
30
31#include <map>
32
33#include "G4VBasicShell.hh"
35
36#include <qobject.h>
37#include <qmap.h>
38#include <qstringlist.h>
39#include <qtabwidget.h>
40#include <qdockwidget.h>
41#include <qdialog.h>
42
43class QMainWindow;
44class QLineEdit;
45class G4UIsession;
46class QListWidget;
47class QTreeWidget;
48class QTreeWidgetItem;
49class QTextEdit;
50class QTextBrowser;
51class QLabel;
52class QResizeEvent;
53class QTabWidget;
54class QStringList;
55class QSplitter;
56class QToolBar;
57class QTableWidget;
58class QPixmap;
59class QComboBox;
60class QCompleter;
61class QtGlobal;
62class QStandardItemModel;
63class QToolButton;
64
65// Class description :
66//
67// G4UIQt : class to handle a Qt interactive session.
68// G4UIQt is the Qt version of G4UIterminal.
69//
70// A command box is at disposal for entering/recalling Geant4 commands.
71// A menubar could be customized through the AddMenu, AddButton, AddIcon methods.
72// Note that there are corresponding Geant4 commands to add a
73// menus in the menubar and add buttons in a menu.
74// Ex :
75// /gui/addMenu test Test
76// /gui/addButton test Init /run/initialize
77// /gui/addButton test "Set gun" "/control/execute gun.g4m"
78// /gui/addButton test "Run one event" "/run/beamOn 1"
79//
80// Command completion, by typing "tab" key, is available on the
81// command line.
82//
83// Class description - end :
84
85class G4QTabWidget : public QTabWidget {
86public :
88 G4QTabWidget(QWidget* aParent, G4int sizeX, G4int sizeY);
89 void paintEvent ( QPaintEvent * event );
90 inline void setTabSelected(G4bool a) { fTabSelected = a; };
91 inline void setLastTabCreated(G4int a) { fLastCreated = a; };
92 inline bool isTabSelected() { return fTabSelected; };
97 inline void setPreferredSize(QSize s) {
98 fPreferedSizeX = s.width() + 6; // tab label height + margin left+right
99 fPreferedSizeY = s.height() + 58; // margin left+right
100 }
101 inline QSize sizeHint () const {
102 return QSize(fPreferedSizeX, fPreferedSizeY);
103 }
104};
105
107 public :
108 G4UIOutputString(QString text,G4String thread = "",G4String outputstream= "info");
109 inline QString GetOutputList() { return " all info warning error ";};
110 QString fText;
112 G4String fOutputStream; // Error, Warning, Info
113};
114
115
116class G4UIDockWidget : public QDockWidget {
117public:
118 G4UIDockWidget(QString txt);
119 void closeEvent(QCloseEvent *);
120};
121
122
123class G4UIQt : public QObject, public G4VBasicShell, public G4VInteractiveSession {
124 Q_OBJECT
125
126public: // With description
127 G4UIQt(G4int,char**);
128 // (argv, argc) or (0, NULL) had to be given.
130 // To enter interactive X loop ; waiting/executing command,...
131 void AddMenu(const char*,const char*);
132 // To add a pulldown menu in the menu bar.
133 // First argument is the name of the menu.
134 // Second argument is the label of the cascade button.
135 // Ex : AddMenu("my_menu","My menu")
136 void AddButton(const char*,const char*,const char*);
137 // To add a push button in a pulldown menu.
138 // First argument is the name of the menu.
139 // Second argument is the label of the button.
140 // Third argument is the Geant4 command executed when the button is fired.
141 // Ex : AddButton("my_menu","Run","/run/beamOn 1");
142 void AddIcon(const char* userLabel, const char* iconFile, const char* command, const char* file_name="");
143 // To add a icon in the toolbar
144 // First argument is the label of the icon.
145 // Second argument is the selected icon type (open save move rotate pick zoom_in zoom_out wireframe solid hidden_line_removal hidden_line_and_surface_removal perspective ortho user_icon).
146 // Third argument is the Geant4 command executed when the button is fired.
147 // Fourth argument is the path to the icon file if "user_icon" selected
148 // Ex : AddButton("change background color","../background.xpm"," /vis/viewer/set/background");
149 void OutputStyle (const char*,const char*,const char*);
150 // Specify an output style
151 // First argument destination (cout cerr warnings errors all)
152 // Second argument is the style (fixed proportional)
153 // Third argument highlights commands if "highlight" (and if /control/verbose > 0)
154
155 void NativeMenu(G4bool aVal);
156 // Enable/Disable the native Menu Bar in Qt
157
158 void ClearMenu();
159 // Clear Menu Bar, remove all actions
160
161 void DefaultIcons(G4bool aVal);
162 // Enable/Disable the default icon ToolBar in Qt
163
164 G4bool AddTabWidget(QWidget*,QString);
165 // To add a tab for vis openGL Qt driver
166
167 inline QTabWidget* GetViewerTabWidget() {
168 return fViewerTabWidget;
169 };
170
171 QWidget* GetSceneTreeWidget();
172 // Get the scene tree component
173
174 QWidget* GetViewerPropertiesWidget();
175 // Get the Viewer Properties Widget
176
177 QWidget* GetPickInfosWidget();
178 // Get the Pick Widget
179
181
183 return fMoveSelected;
184 };
186 return fRotateSelected;
187 };
189 return fPickSelected;
190 };
192 return fZoomInSelected;
193 };
195 return fZoomOutSelected;
196 };
197
198 void SetIconMoveSelected();
200 void SetIconPickSelected();
204 void SetIconHLRSelected();
209
210 inline QMainWindow * GetMainWindow() {
211 return fMainWindow;
212 };
213 // Return the main window
214
215 inline QPixmap* getSearchIcon() { return fSearchIcon;};
216 // return the "search" icon pixmap
217 inline QPixmap* getClearIcon() { return fClearIcon;};
218 // return the "clear" icon pixmap
219
220 void SetStartPage(const std::string&);
221 // Set the text on the first page of the viewer. If "", will take the last value as default
222 // Note: Qt Rich text format could be used, see link for example :
223 // https://qt-project.org/doc/qt-4.8/richtext-html-subset.html#table-cell-attributes
224
225 inline QWidget* GetCoutWidget() {
226 return fCoutDockWidget->widget();
227 };
228 // Return the G4cout widget with filters
229
231 return fCoutDockWidget;
232 };
233 // Return the cout dockable widget as a QDockWidget
234
236 return fUIDockWidget;
237 };
238 // Return the UserInterface widget (including scene tree, help and History widgets)
239
240 inline QTabWidget* GetUITabWidget() {
241 return fUITabWidget;
242 }
243 // return the viewer widget including all viewers
244
245 inline QWidget* GetHistoryWidget() {
246 return fHistoryTBWidget;
247 }
248 // return the history widget
249
250 inline QWidget* GetHelpWidget() {
251 return fHelpTBWidget;
252 }
253 // return the help widget
254
255 G4bool AddViewerTab(QWidget* w, std::string title);
256 // Add a new tab in the viewer, could be used to add your own component
257
258 G4bool AddViewerTabFromFile(std::string fileName, std::string title);
259 // Add a new tab in the viewer containing the content of the file in a QLabel
260
261public:
262 ~G4UIQt();
263 void Prompt(G4String);
264 void SessionTerminate();
265 virtual void PauseSessionStart(const G4String&);
266 virtual G4int ReceiveG4cout(const G4String&);
267 virtual G4int ReceiveG4cerr(const G4String&);
268 // G4String GetCommand(Widget);
269
270private:
271 void SecondaryLoop(G4String); // a VIRER
272 void CreateHelpWidget();
273 void InitHelpTreeAndVisParametersWidget();
274 void FillHelpTree();
275 void UpdateCommandCompleter();
276 void CreateIcons();
277 virtual void ExitHelp() const;
278 void SetDefaultIconsToolbar();
279
280 void CreateHelpTree(QTreeWidgetItem*,G4UIcommandTree*);
281 QTreeWidgetItem* FindTreeItem(QTreeWidgetItem *,const QString&);
282
283 QString GetCommandList(const G4UIcommand*);
284 void updateHelpArea(const G4UIcommand*);
285 virtual G4bool GetHelpChoice(G4int&);// have to be implemeted because we heritate from G4VBasicShell
286 bool eventFilter(QObject*,QEvent*);
287 void ActivateCommand(G4String);
288#if QT_VERSION < 0x050F00
289 QMap<G4int,QString> LookForHelpStringInChildTree(G4UIcommandTree *,const QString&);
290#else
291 QMultiMap<G4int,QString> LookForHelpStringInChildTree(G4UIcommandTree *,const QString&);
292#endif
293 QWidget* CreateVisParametersTBWidget();
294 QWidget* CreateHelpTBWidget();
295 G4UIDockWidget* CreateCoutTBWidget();
296 QWidget* CreateHistoryTBWidget();
297 G4UIDockWidget* CreateUITabWidget();
298 QWidget* CreateSceneTreeWidget();
299 void CreateViewerWidget();
300 void OpenHelpTreeOnCommand(const QString &);
301 QString GetShortCommandPath(QString);
302 QString GetLongCommandPath(QTreeWidgetItem*);
303 G4bool IsGUICommand(const G4UIcommand*);
304 G4bool CreateVisCommandGroupAndToolBox(G4UIcommand*, QWidget*, G4int, G4bool isDialog);
305 G4bool CreateCommandWidget(G4UIcommand* command, QWidget* parent, G4bool isDialog);
306 void CreateViewerPropertiesDialog();
307 void CreatePickInfosDialog();
308#ifdef G4MULTITHREADED
309 void UpdateCoutThreadFilter();
310#endif
311 void FilterAllOutputTextArea();
312 QString FilterOutput(const G4UIOutputString&,const QString&,const QString&);
313 G4String GetThreadPrefix();
314 G4bool CheckG4EnvironmentVariable(char* txt, char* version);
315 QStandardItemModel* CreateCompleterModel(G4String aCmd);
316 void CreateEmptyViewerPropertiesWidget();
317 void CreateEmptyPickInfosWidget();
318private:
319
320 QMainWindow * fMainWindow;
321 QLabel *fCommandLabel;
322 QLineEdit * fCommandArea;
323 QTextEdit *fCoutTBTextArea;
324 QTabWidget* fUITabWidget;
325 std::vector <G4UIOutputString> fG4OutputString;
326 QLineEdit * fCoutFilter;
327 QCompleter* fCompleter;
328 G4bool fDefaultIcons;
329
330 QListWidget *fHistoryTBTableList;
331 QTreeWidget *fHelpTreeWidget;
332 QWidget* fHelpTBWidget;
333 QWidget* fHistoryTBWidget;
334 G4UIDockWidget* fCoutDockWidget;
335 G4UIDockWidget* fUIDockWidget;
336 QWidget* fSceneTreeWidget;
337 QWidget* fViewerPropertiesWidget;
338 QWidget* fPickInfosWidget;
339 QLineEdit* fHelpLine;
340 G4QTabWidget* fViewerTabWidget;
341 QString fCoutText;
342 QTextBrowser *fStartPage;
343 QSplitter * fHelpVSplitter;
344 QTextEdit* fParameterHelpLabel;
345 QTableWidget* fParameterHelpTable;
346
347 QToolBar *fToolbarApp;
348 QToolBar *fToolbarUser;
349 QString fStringSeparator;
350 G4String fLastErrMessage;
351 QString fLastOpenPath;
352 QToolButton* fViewModePopupButton;
353 QToolButton* fSurfaceModePopupButton;
354
355 QPixmap* fSearchIcon;
356 QPixmap* fClearIcon;
357 QPixmap* fSaveIcon;
358 QPixmap* fOpenIcon;
359 QPixmap* fMoveIcon;
360 QPixmap* fRotateIcon;
361 QPixmap* fPickIcon;
362 QPixmap* fZoomInIcon;
363 QPixmap* fZoomOutIcon;
364 QPixmap* fWireframeIcon;
365 QPixmap* fSolidIcon;
366 QPixmap* fHiddenLineRemovalIcon;
367 QPixmap* fHiddenLineAndSurfaceRemovalIcon;
368 QPixmap* fPerspectiveIcon;
369 QPixmap* fOrthoIcon;
370 QPixmap* fCommandIcon;
371 QPixmap* fDirIcon;
372 QPixmap* fRunIcon;
373 QPixmap* fParamIcon;
374 QPixmap* fPickTargetIcon;
375 QPixmap* fExitIcon;
376
377#ifdef G4MULTITHREADED
378 QComboBox* fThreadsFilterComboBox;
379#endif
380 std::string fDefaultViewerFirstPageHTMLText;
381
382 QDialog* fViewerPropertiesDialog;
383 QDialog* fPickInfosDialog;
384 QString fLastCompleteCommand;
385 G4bool fMoveSelected;
386 G4bool fRotateSelected;
387 G4bool fPickSelected;
388 G4bool fZoomInSelected;
389 G4bool fZoomOutSelected;
390 struct G4UIQtStyle {
391 G4bool fixed, highlight;
392 };
393 std::map<G4String,G4UIQtStyle> fOutputStyles;
394
395private Q_SLOTS :
396 void ExitSession();
397 void ClearButtonCallback();
398 void SaveOutputCallback();
399 void CommandEnteredCallback();
400 void CommandEditedCallback(const QString & text);
401 void ButtonCallback(const QString&);
402 void HelpTreeClicCallback();
403 void HelpTreeDoubleClicCallback();
404 void ShowHelpCallback();
405 void CommandHistoryCallback();
406 void LookForHelpStringCallback();
407 void UpdateTabWidget(G4int);
408 void ResizeTabWidget( QResizeEvent* );
409 void CoutFilterCallback(const QString&);
410 void ThreadComboBoxCallback(G4int);
411 void TabCloseCallback(G4int);
412 void ToolBoxActivated(G4int);
413 void VisParameterCallback(QWidget*);
414 void ChangeColorCallback(QWidget*);
415 void ChangeCursorAction(const QString&);
416 void ChangeSurfaceStyle(const QString&);
417 void OpenIconCallback(const QString&);
418 void SaveIconCallback(const QString&);
419 void ViewerPropertiesIconCallback(G4int);
420 void ChangePerspectiveOrtho(const QString&);
421};
422
423#endif
424
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
void setLastTabCreated(G4int a)
Definition: G4UIQt.hh:91
void setTabSelected(G4bool a)
Definition: G4UIQt.hh:90
QSize sizeHint() const
Definition: G4UIQt.hh:101
G4int fLastCreated
Definition: G4UIQt.hh:94
void setPreferredSize(QSize s)
Definition: G4UIQt.hh:97
G4int fPreferedSizeX
Definition: G4UIQt.hh:95
void paintEvent(QPaintEvent *event)
Definition: G4UIQt.cc:5190
G4int fPreferedSizeY
Definition: G4UIQt.hh:96
bool isTabSelected()
Definition: G4UIQt.hh:92
G4bool fTabSelected
Definition: G4UIQt.hh:93
void closeEvent(QCloseEvent *)
Definition: G4UIQt.cc:5226
G4String fOutputStream
Definition: G4UIQt.hh:112
QString fText
Definition: G4UIQt.hh:110
G4String fThread
Definition: G4UIQt.hh:111
QString GetOutputList()
Definition: G4UIQt.hh:109
G4bool IsSplitterReleased()
QMainWindow * GetMainWindow()
Definition: G4UIQt.hh:210
void SetIconPickSelected()
Definition: G4UIQt.cc:4868
G4bool AddTabWidget(QWidget *, QString)
Definition: G4UIQt.cc:1860
QWidget * GetViewerPropertiesWidget()
Definition: G4UIQt.cc:1788
void SetIconOrthoSelected()
Definition: G4UIQt.cc:5081
void SetStartPage(const std::string &)
Definition: G4UIQt.cc:1917
QWidget * GetCoutWidget()
Definition: G4UIQt.hh:225
G4bool IsIconRotateSelected()
Definition: G4UIQt.hh:185
G4bool IsIconZoomInSelected()
Definition: G4UIQt.hh:191
G4bool AddViewerTabFromFile(std::string fileName, std::string title)
Definition: G4UIQt.cc:1827
virtual void PauseSessionStart(const G4String &)
Definition: G4UIQt.cc:2050
G4bool IsIconMoveSelected()
Definition: G4UIQt.hh:182
void SetIconZoomInSelected()
Definition: G4UIQt.cc:4899
QPixmap * getSearchIcon()
Definition: G4UIQt.hh:215
G4bool IsIconZoomOutSelected()
Definition: G4UIQt.hh:194
QWidget * GetSceneTreeWidget()
Definition: G4UIQt.cc:1780
G4UIDockWidget * GetUserInterfaceWidget()
Definition: G4UIQt.hh:235
void SetIconZoomOutSelected()
Definition: G4UIQt.cc:4930
G4UIDockWidget * GetCoutDockWidget()
Definition: G4UIQt.hh:230
void SetIconHLRSelected()
Definition: G4UIQt.cc:5009
void SetIconPerspectiveSelected()
Definition: G4UIQt.cc:5059
QPixmap * getClearIcon()
Definition: G4UIQt.hh:217
virtual G4int ReceiveG4cout(const G4String &)
Definition: G4UIQt.cc:2102
QTabWidget * GetViewerTabWidget()
Definition: G4UIQt.hh:167
virtual G4int ReceiveG4cerr(const G4String &)
Definition: G4UIQt.cc:2195
G4UIsession * SessionStart()
Definition: G4UIQt.cc:1967
QWidget * GetPickInfosWidget()
Definition: G4UIQt.cc:1799
void SetIconSolidSelected()
Definition: G4UIQt.cc:4961
void DefaultIcons(G4bool aVal)
Definition: G4UIQt.cc:289
QWidget * GetHelpWidget()
Definition: G4UIQt.hh:250
void NativeMenu(G4bool aVal)
Definition: G4UIQt.cc:2686
void SetIconRotateSelected()
Definition: G4UIQt.cc:4842
void SessionTerminate()
Definition: G4UIQt.cc:2032
void AddButton(const char *, const char *, const char *)
Definition: G4UIQt.cc:2354
G4bool IsIconPickSelected()
Definition: G4UIQt.hh:188
~G4UIQt()
Definition: G4UIQt.cc:274
QTabWidget * GetUITabWidget()
Definition: G4UIQt.hh:240
void ClearMenu()
Definition: G4UIQt.cc:2695
void AddMenu(const char *, const char *)
Definition: G4UIQt.cc:2333
void AddIcon(const char *userLabel, const char *iconFile, const char *command, const char *file_name="")
Definition: G4UIQt.cc:2429
void Prompt(G4String)
Definition: G4UIQt.cc:2021
void SetIconWireframeSelected()
Definition: G4UIQt.cc:4985
void SetIconMoveSelected()
Definition: G4UIQt.cc:4816
G4bool AddViewerTab(QWidget *w, std::string title)
Definition: G4UIQt.cc:1811
void SetIconHLHSRSelected()
Definition: G4UIQt.cc:5034
void OutputStyle(const char *, const char *, const char *)
Definition: G4UIQt.cc:2667
QWidget * GetHistoryWidget()
Definition: G4UIQt.hh:245