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,v 1.23 2010/06/10 15:37:13 lgarnier Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-04-beta-01 $ |
---|
29 | // |
---|
30 | #ifndef G4UIQt_h |
---|
31 | #define G4UIQt_h |
---|
32 | |
---|
33 | #if defined(G4UI_BUILD_QT_SESSION) || defined(G4UI_USE_QT) |
---|
34 | |
---|
35 | #include <map> |
---|
36 | |
---|
37 | #include "G4VBasicShell.hh" |
---|
38 | #include "G4VInteractiveSession.hh" |
---|
39 | |
---|
40 | #include <qobject.h> |
---|
41 | #include <qmap.h> |
---|
42 | #include <qstringlist.h> |
---|
43 | #include <qtabwidget.h> |
---|
44 | |
---|
45 | class QMainWindow; |
---|
46 | class QLineEdit; |
---|
47 | class G4UIsession; |
---|
48 | #if QT_VERSION < 0x040000 |
---|
49 | class QListView; |
---|
50 | class QListViewItem; |
---|
51 | #else |
---|
52 | class QListWidget; |
---|
53 | class QTreeWidget; |
---|
54 | class QTreeWidgetItem; |
---|
55 | #endif |
---|
56 | class QTextEdit; |
---|
57 | class QLabel; |
---|
58 | class QResizeEvent; |
---|
59 | class QToolBox; |
---|
60 | class QStringList; |
---|
61 | class QSplitter; |
---|
62 | |
---|
63 | // Class description : |
---|
64 | // |
---|
65 | // G4UIQt : class to handle a Qt interactive session. |
---|
66 | // G4UIQt is the Qt version of G4UIterminal. |
---|
67 | // |
---|
68 | // A command box is at disposal for entering/recalling Geant4 commands. |
---|
69 | // A menubar could be customized through the AddMenu, AddButton methods. |
---|
70 | // Note that there are corresponding Geant4 commands to add a |
---|
71 | // menus in the menubar and add buttons in a menu. |
---|
72 | // Ex : |
---|
73 | // /gui/addMenu test Test |
---|
74 | // /gui/addButton test Init /run/initialize |
---|
75 | // /gui/addButton test "Set gun" "/control/execute gun.g4m" |
---|
76 | // /gui/addButton test "Run one event" "/run/beamOn 1" |
---|
77 | // |
---|
78 | // Command completion, by typing "tab" key, is available on the |
---|
79 | // command line. |
---|
80 | // |
---|
81 | // Class description - end : |
---|
82 | |
---|
83 | class G4QTabWidget : public QTabWidget { |
---|
84 | public : |
---|
85 | G4QTabWidget(); |
---|
86 | G4QTabWidget(QSplitter*&); |
---|
87 | void paintEvent ( QPaintEvent * event ); |
---|
88 | inline void setTabSelected(bool a) { tabSelected = a; }; |
---|
89 | inline void setLastTabCreated(int a) { lastCreated = a; }; |
---|
90 | inline bool isTabSelected() { return tabSelected; }; |
---|
91 | bool tabSelected; |
---|
92 | int lastCreated; |
---|
93 | }; |
---|
94 | |
---|
95 | class G4UIQt : public QObject, public G4VBasicShell, public G4VInteractiveSession { |
---|
96 | Q_OBJECT |
---|
97 | |
---|
98 | public: // With description |
---|
99 | G4UIQt(int,char**); |
---|
100 | // (argv, argc) or (0, NULL) had to be given. |
---|
101 | G4UIsession* SessionStart(); |
---|
102 | // To enter interactive X loop ; waiting/executing command,... |
---|
103 | void AddMenu(const char*,const char*); |
---|
104 | // To add a pulldown menu in the menu bar. |
---|
105 | // First argument is the name of the menu. |
---|
106 | // Second argument is the label of the cascade button. |
---|
107 | // Ex : AddMenu("my_menu","My menu") |
---|
108 | void AddButton(const char*,const char*,const char*); |
---|
109 | // To add a push button in a pulldown menu. |
---|
110 | // First argument is the name of the menu. |
---|
111 | // Second argument is the label of the button. |
---|
112 | // Third argument is the Geant4 command executed when the button is fired. |
---|
113 | // Ex : AddButton("my_menu","Run","/run/beamOn 1"); |
---|
114 | |
---|
115 | bool AddTabWidget(QWidget*,QString,int,int); |
---|
116 | // To add a tab for vis openGL Qt driver |
---|
117 | |
---|
118 | bool IsSplitterReleased(); |
---|
119 | |
---|
120 | public: |
---|
121 | ~G4UIQt(); |
---|
122 | void Prompt(G4String); |
---|
123 | void SessionTerminate(); |
---|
124 | void PauseSessionStart(G4String); |
---|
125 | G4int ReceiveG4cout(G4String); |
---|
126 | G4int ReceiveG4cerr(G4String); |
---|
127 | // G4String GetCommand(Widget); |
---|
128 | |
---|
129 | private: |
---|
130 | void SecondaryLoop(G4String); // a VIRER |
---|
131 | void CreateHelpWidget(); |
---|
132 | void InitHelpTree(); |
---|
133 | void FillHelpTree(); |
---|
134 | void ExitHelp(); |
---|
135 | |
---|
136 | #if QT_VERSION < 0x040000 |
---|
137 | void CreateChildTree(QListViewItem*,G4UIcommandTree*); |
---|
138 | QListViewItem* FindTreeItem(QListViewItem *,const QString&); |
---|
139 | #else |
---|
140 | void CreateChildTree(QTreeWidgetItem*,G4UIcommandTree*); |
---|
141 | QTreeWidgetItem* FindTreeItem(QTreeWidgetItem *,const QString&); |
---|
142 | #endif |
---|
143 | |
---|
144 | QString GetCommandList(const G4UIcommand*); |
---|
145 | |
---|
146 | G4bool GetHelpChoice(G4int&) ;// have to be implemeted because we heritate from G4VBasicShell |
---|
147 | bool eventFilter(QObject*,QEvent*); |
---|
148 | void ActivateCommand(G4String); |
---|
149 | QMap<int,QString> LookForHelpStringInChildTree(G4UIcommandTree *,const QString&); |
---|
150 | |
---|
151 | void CreateVisParametersTBWidget(); |
---|
152 | void CreateViewComponentsTBWidget(); |
---|
153 | void CreateHelpTBWidget(); |
---|
154 | void CreateCoutTBWidget(); |
---|
155 | void CreateHistoryTBWidget(); |
---|
156 | void OpenHelpTreeOnCommand(const QString &); |
---|
157 | QString GetShortCommandPath(QString); |
---|
158 | #if QT_VERSION < 0x040000 |
---|
159 | QString GetLongCommandPath(QListViewItem*); |
---|
160 | #else |
---|
161 | QString GetLongCommandPath(QTreeWidgetItem*); |
---|
162 | #endif |
---|
163 | |
---|
164 | private: |
---|
165 | |
---|
166 | // Widget form,shell,command,menuBar,text; |
---|
167 | // std::map<QAction*,G4String, std::less<QAction*> > commands; |
---|
168 | // static void commandEnteredCallback(Widget,XtPointer,XtPointer); |
---|
169 | // static void keyHandler(Widget,XtPointer,XEvent*,Boolean*); |
---|
170 | QMainWindow * fMainWindow; |
---|
171 | QLabel *fCommandLabel; |
---|
172 | QLineEdit * fCommandArea; |
---|
173 | QTextEdit *fCoutTBTextArea; |
---|
174 | QTextEdit *fHelpArea; |
---|
175 | QToolBox* fToolBox; |
---|
176 | QStringList fG4cout; |
---|
177 | QLineEdit * fCoutFilter; |
---|
178 | |
---|
179 | #if QT_VERSION < 0x040000 |
---|
180 | QListView *fHistoryTBTableList; |
---|
181 | QListView *fHelpTreeWidget; |
---|
182 | #else |
---|
183 | QListWidget *fHistoryTBTableList; |
---|
184 | QTreeWidget *fHelpTreeWidget; |
---|
185 | #endif |
---|
186 | QWidget* fHelpTBWidget; |
---|
187 | QWidget* fHistoryTBWidget; |
---|
188 | QWidget* fCoutTBWidget; |
---|
189 | QWidget* fVisParametersTBWidget; |
---|
190 | QWidget* fViewComponentsTBWidget; |
---|
191 | QLineEdit* fHelpLine; |
---|
192 | G4QTabWidget* fTabWidget; |
---|
193 | QString fCoutText; |
---|
194 | QLabel *fEmptyViewerTabLabel; |
---|
195 | QSplitter * fMyVSplitter; |
---|
196 | QSplitter * fHelpVSplitter; |
---|
197 | int fLastQTabSizeX; |
---|
198 | int fLastQTabSizeY; |
---|
199 | |
---|
200 | private slots : |
---|
201 | void ExitSession(); |
---|
202 | void ClearButtonCallback(); |
---|
203 | void CommandEnteredCallback(); |
---|
204 | void ButtonCallback(const QString&); |
---|
205 | void HelpTreeClicCallback(); |
---|
206 | void HelpTreeDoubleClicCallback(); |
---|
207 | void ShowHelpCallback(); |
---|
208 | void CommandHistoryCallback(); |
---|
209 | void LookForHelpStringCallback(); |
---|
210 | void UpdateTabWidget(int); |
---|
211 | void ResizeTabWidget( QResizeEvent* ); |
---|
212 | void CoutFilterCallback(const QString&); |
---|
213 | void TabCloseCallback(int); |
---|
214 | void ToolBoxActivated(int); |
---|
215 | }; |
---|
216 | |
---|
217 | #endif |
---|
218 | |
---|
219 | #endif |
---|
220 | |
---|