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