Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 // $Id: G4UIQt.hh 76743 2013-11-14 15:48:22Z gcosmo $
28 //
29 #ifndef G4UIQt_h
30 #define G4UIQt_h
31 
32 #if defined(G4UI_BUILD_QT_SESSION) || defined(G4UI_USE_QT)
33 
34 #include <map>
35 
36 #include "G4VBasicShell.hh"
37 #include "G4VInteractiveSession.hh"
38 
39 #include <qobject.h>
40 #include <qmap.h>
41 #include <qstringlist.h>
42 #include <qtabwidget.h>
43 
44 class QMainWindow;
45 class QLineEdit;
46 class G4UIsession;
47 class QListWidget;
48 class QTreeWidget;
49 class QTreeWidgetItem;
50 class QTextEdit;
51 class QLabel;
52 class QResizeEvent;
53 class QTabWidget;
54 class QStringList;
55 class QSplitter;
56 class QToolBar;
57 
58 // Class description :
59 //
60 // G4UIQt : class to handle a Qt interactive session.
61 // G4UIQt is the Qt version of G4UIterminal.
62 //
63 // A command box is at disposal for entering/recalling Geant4 commands.
64 // A menubar could be customized through the AddMenu, AddButton, AddIcon methods.
65 // Note that there are corresponding Geant4 commands to add a
66 // menus in the menubar and add buttons in a menu.
67 // Ex :
68 // /gui/addMenu test Test
69 // /gui/addButton test Init /run/initialize
70 // /gui/addButton test "Set gun" "/control/execute gun.g4m"
71 // /gui/addButton test "Run one event" "/run/beamOn 1"
72 //
73 // Command completion, by typing "tab" key, is available on the
74 // command line.
75 //
76 // Class description - end :
77 
78 class G4QTabWidget : public QTabWidget {
79 public :
80  G4QTabWidget();
81  G4QTabWidget(QWidget* aParent, int sizeX, int sizeY);
82  void paintEvent ( QPaintEvent * event );
83  inline void setTabSelected(bool a) { fTabSelected = a; };
84  inline void setLastTabCreated(int a) { fLastCreated = a; };
85  inline bool isTabSelected() { return fTabSelected; };
86  bool fTabSelected;
87  int fLastCreated;
88  int fPreferedSizeX;
89  int fPreferedSizeY;
90  inline void setPreferredSize(QSize s) {
91  fPreferedSizeX = s.width() + 6; // tab label height + margin left+right
92  fPreferedSizeY = s.height() + 58; // margin left+right
93  }
94  inline QSize sizeHint () const {
95  return QSize(fPreferedSizeX, fPreferedSizeY);
96  }
97 };
98 
99 class G4UIQt : public QObject, public G4VBasicShell, public G4VInteractiveSession {
100  Q_OBJECT
101 
102 public: // With description
103  G4UIQt(int,char**);
104  // (argv, argc) or (0, NULL) had to be given.
106  // To enter interactive X loop ; waiting/executing command,...
107  void AddMenu(const char*,const char*);
108  // To add a pulldown menu in the menu bar.
109  // First argument is the name of the menu.
110  // Second argument is the label of the cascade button.
111  // Ex : AddMenu("my_menu","My menu")
112  void AddButton(const char*,const char*,const char*);
113  // To add a push button in a pulldown menu.
114  // First argument is the name of the menu.
115  // Second argument is the label of the button.
116  // Third argument is the Geant4 command executed when the button is fired.
117  // Ex : AddButton("my_menu","Run","/run/beamOn 1");
118  void AddIcon(const char* userLabel, const char* iconFile, const char* command, const char* file_name="");
119  // To add a icon in the toolbar
120  // First argument is the label of the icon.
121  // 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).
122  // Third argument is the Geant4 command executed when the button is fired.
123  // Fourth argument is the path to the icon file if "user_icon" selected
124  // Ex : AddButton("change background color","../background.xpm"," /vis/viewer/set/background");
125 
126  bool AddTabWidget(QWidget*,QString,int,int);
127  // To add a tab for vis openGL Qt driver
128 
129  QTabWidget* GetSceneTreeComponentsTBWidget();
130  // Get the viewComponent
131 
132  bool IsSplitterReleased();
133 
134  inline bool IsIconMoveSelected() {
135  return fMoveSelected;
136  };
137  inline bool IsIconRotateSelected() {
138  return fRotateSelected;
139  };
140  inline bool IsIconPickSelected() {
141  return fPickSelected;
142  };
143  inline bool IsIconZoomInSelected() {
144  return fZoomInSelected;
145  };
146  inline bool IsIconZoomOutSelected() {
147  return fZoomOutSelected;
148  };
149 
150  void SetIconMoveSelected();
151  void SetIconRotateSelected();
152  void SetIconPickSelected();
153  void SetIconZoomInSelected();
154  void SetIconZoomOutSelected();
155  void SetIconHLHSRSelected();
156  void SetIconHLRSelected();
157  void SetIconSolidSelected();
158  void SetIconWireframeSelected();
159  void SetIconPerspectiveSelected();
160  void SetIconOrthoSelected();
161 
162  inline QMainWindow * GetMainWindow() {
163  return fMainWindow;
164  };
165 
166 public:
167  ~G4UIQt();
168  void Prompt(G4String);
169  void SessionTerminate();
170  virtual void PauseSessionStart(const G4String&);
171  virtual G4int ReceiveG4cout(const G4String&);
172  virtual G4int ReceiveG4cerr(const G4String&);
173  // G4String GetCommand(Widget);
174 
175 private:
176  void SecondaryLoop(G4String); // a VIRER
177  void CreateHelpWidget();
178  void InitHelpTreeAndVisParametersWidget();
179  void FillHelpTree();
180  virtual void ExitHelp() const;
181 
182  void CreateHelpTree(QTreeWidgetItem*,G4UIcommandTree*);
183  QTreeWidgetItem* FindTreeItem(QTreeWidgetItem *,const QString&);
184 
185  QString GetCommandList(const G4UIcommand*);
186 
187  virtual G4bool GetHelpChoice(G4int&);// have to be implemeted because we heritate from G4VBasicShell
188  bool eventFilter(QObject*,QEvent*);
189  void ActivateCommand(G4String);
190  QMap<int,QString> LookForHelpStringInChildTree(G4UIcommandTree *,const QString&);
191 
192  QWidget* CreateVisParametersTBWidget();
193  QWidget* CreateHelpTBWidget();
194  QWidget* CreateCoutTBWidget();
195  QWidget* CreateHistoryTBWidget();
196  QWidget* CreateUITabWidget();
197  QWidget* CreateSceneTreeComponentsTBWidget();
198  QWidget* CreateRightSplitterWidget();
199  QWidget* CreateLeftSplitterWidget();
200  void OpenHelpTreeOnCommand(const QString &);
201  QString GetShortCommandPath(QString);
202  QString GetLongCommandPath(QTreeWidgetItem*);
203  G4bool IsGUICommand(const G4UIcommand*);
204  bool CreateVisCommandGroupAndToolBox(G4UIcommand*, QWidget*, int, bool isDialog);
205  bool CreateCommandWidget(G4UIcommand* command, QWidget* parent, bool isDialog);
206 
207 private:
208 
209  QMainWindow * fMainWindow;
210  QLabel *fCommandLabel;
211  QLineEdit * fCommandArea;
212  QTextEdit *fCoutTBTextArea;
213  QTextEdit *fHelpArea;
214  QTabWidget* fUITabWidget;
215  QStringList fG4cout;
216  QLineEdit * fCoutFilter;
217 
218  QListWidget *fHistoryTBTableList;
219  QTreeWidget *fHelpTreeWidget;
220  QWidget* fHelpTBWidget;
221  QWidget* fHistoryTBWidget;
222  QWidget* fCoutTBWidget;
223  QTabWidget* fSceneTreeComponentsTBWidget;
224  QLineEdit* fHelpLine;
225  G4QTabWidget* fViewerTabWidget;
226  QString fCoutText;
227  QLabel *fEmptyViewerTabLabel;
228  QSplitter * fMainSplitterWidget;
229  QSplitter* fRightSplitterWidget;
230  QWidget* fLeftSplitterWidget;
231  QSplitter * fHelpVSplitter;
232  QWidget* fViewerTabHandleWidget;
233 
234  QToolBar *fToolbarApp;
235  QToolBar *fToolbarUser;
236  QString fStringSeparator;
237  G4String fLastErrMessage;
238  QString fLastOpenPath;
239 
240  bool fMoveSelected;
241  bool fRotateSelected;
242  bool fPickSelected;
243  bool fZoomInSelected;
244  bool fZoomOutSelected;
245 
246 private Q_SLOTS :
247  void ExitSession();
248  void ClearButtonCallback();
249  void CommandEnteredCallback();
250  void CommandEditedCallback(const QString & text);
251  void ButtonCallback(const QString&);
252  void HelpTreeClicCallback();
253  void HelpTreeDoubleClicCallback();
254  void ShowHelpCallback();
255  void CommandHistoryCallback();
256  void LookForHelpStringCallback();
257  void UpdateTabWidget(int);
258  void ResizeTabWidget( QResizeEvent* );
259  void CoutFilterCallback(const QString&);
260  void TabCloseCallback(int);
261  void ToolBoxActivated(int);
262  void VisParameterCallback(QWidget*);
263  void ChangeColorCallback(QWidget*);
264  void ChangeCursorStyle(const QString&);
265  void ChangeSurfaceStyle(const QString&);
266  void OpenIconCallback(const QString&);
267  void SaveIconCallback(const QString&);
268  void ChangePerspectiveOrtho(const QString&);
269 };
270 
271 #endif
272 
273 #endif
274 
virtual G4bool GetHelpChoice(G4int &)=0
virtual void ExitHelp() const =0
const XML_Char * s
virtual G4int ReceiveG4cout(const G4String &coutString)
Definition: G4UIsession.cc:42
virtual void AddMenu(const char *, const char *)
int G4int
Definition: G4Types.hh:78
virtual void PauseSessionStart(const G4String &Prompt)=0
bool G4bool
Definition: G4Types.hh:79
virtual G4UIsession * SessionStart()=0
virtual void AddButton(const char *, const char *, const char *)
virtual G4int ReceiveG4cerr(const G4String &cerrString)
Definition: G4UIsession.cc:48
virtual void AddIcon(const char *, const char *, const char *, const char *)