]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_ViewWindow.h
Salome HOME
Issue #24
[modules/shaper.git] / src / XGUI / XGUI_ViewWindow.h
1 #ifndef XGUI_ViewWindow_H
2 #define XGUI_ViewWindow_H
3
4 #include "XGUI_Constants.h"
5 #include "XGUI_ViewBackground.h"
6
7 #include <QFrame>
8 #include <QIcon>
9 #include <QToolBar>
10 #include <QLabel>
11 #include <QMap>
12
13 #include <V3d_View.hxx>
14 #include <V3d_Viewer.hxx>
15
16 class XGUI_ViewPort;
17 class XGUI_Viewer;
18 class ViewerToolbar;
19 class ViewerLabel;
20 class XGUI_RectRubberBand;
21 class QMdiSubWindow;
22
23 /*!
24   \class XGUI_ViewWindow
25   \ingroup GUI
26   \brief Implements a one view window of 3d viewer object.
27   It contains a view port object (drawing area) and toolbars for view camera and window management.
28   Also it managements events in view port
29 */
30 class XGUI_ViewWindow: public QFrame
31 {
32 Q_OBJECT
33 public:
34   //! Types of viewer operations
35   enum OperationType
36   {
37     NOTHING,
38     PANVIEW,
39     ZOOMVIEW,
40     ROTATE,
41     PANGLOBAL,
42     WINDOWFIT,
43     FITALLVIEW,
44     RESETVIEW,
45     FRONTVIEW,
46     BACKVIEW,
47     TOPVIEW,
48     BOTTOMVIEW,
49     LEFTVIEW,
50     RIGHTVIEW,
51     CLOCKWISEVIEW,
52     ANTICLOCKWISEVIEW
53   };
54
55   XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType);
56
57   virtual ~XGUI_ViewWindow();
58
59   //! Returns view port object
60   XGUI_ViewPort* viewPort() const
61   {
62     return myViewPort;
63   }
64
65   //! Retrurns current interaction style
66   XGUI::InteractionStyle interactionStyle() const
67   {
68     return myInteractionStyle;
69   }
70
71   //! Disable or enable given operation type
72   void setTransformEnabled(const OperationType, const bool);
73
74   //! Returns true if the given operation type is enabled
75   bool transformEnabled(const OperationType) const;
76
77   //! Returns View background object
78   XGUI_ViewBackground background() const;
79
80   //! Sets View background object
81   void setBackground(const XGUI_ViewBackground& theBackground);
82
83   //! Returns true if the current view window can be closed
84   bool closable() const { return myClosable; }
85
86   //! Sets the current view window closable or not
87   void setClosable( const bool isClosable ) { myClosable = isClosable; }
88
89 signals:
90   //! Emited whien view transformation operation is started
91   void vpTransformationStarted(XGUI_ViewWindow::OperationType type);
92
93   //! Emited whien view transformation operation is finished
94   void vpTransformationFinished(XGUI_ViewWindow::OperationType type);
95
96   //void Show(QShowEvent *);
97   //void Hide(QHideEvent *);
98   //void maximized(XGUI_ViewWindow*, bool);
99   //void returnedTo3d();
100
101   //! Emited before the window closing
102   void tryClosing(XGUI_ViewWindow*);
103
104   //! Emited when window is closing
105   void closed( QMdiSubWindow* );
106
107   //! Emited on mouse press in view port
108   void mousePressed(XGUI_ViewWindow*, QMouseEvent*);
109
110   //! Emited on mouse release in view port
111   void mouseReleased(XGUI_ViewWindow*, QMouseEvent*);
112
113   //! Emited on mouse double click in view port
114   void mouseDoubleClicked(XGUI_ViewWindow*, QMouseEvent*);
115
116   //! Emited on mouse moving in view port
117   void mouseMoving(XGUI_ViewWindow*, QMouseEvent*);
118  
119   //! Emited on key press in view port
120   void keyPressed(XGUI_ViewWindow*, QKeyEvent*);
121  
122   //! Emited on key release in view port
123   void keyReleased(XGUI_ViewWindow*, QKeyEvent*);
124  
125   //! Emited on context menu request in view port
126   void contextMenuRequested(QContextMenuEvent *e);
127
128   //void viewModified(XGUI_ViewWindow*);
129   void viewCloned( QMdiSubWindow* theView );
130
131 public slots:
132   //! Start zooming operation
133   void activateZoom();
134
135   //! Start rotation operation
136   void activateRotation();
137
138   //! Start panning operation
139   void activatePanning();
140
141   //! Start window fit operation
142   void activateWindowFit();
143
144   //! Start global panning operation
145   void activateGlobalPanning();
146
147   //! Clone the view window preserving a view point of the current view
148   void cloneView();
149
150   //! Dump the view window into external file (*.bmp *.png *.jpg *.jpeg *.eps *.ps)
151   void dumpView();
152
153   //! Fit all command
154   void fitAll();
155
156   //! Set front view
157   void frontView();
158
159   //! Set back view
160   void backView();
161
162   //! Set top view
163   void topView();
164
165   //! Set bottom view
166   void bottomView();
167
168   //! Set left view
169   void leftView();
170
171   //! Set right view
172   void rightView();
173
174   //! Reset point of view
175   void reset();
176
177   void windowActivated();
178
179   void windowDeactivated();
180
181 protected:
182   virtual void resizeEvent(QResizeEvent* theEvent);
183
184   virtual void changeEvent(QEvent* theEvent);
185
186   //virtual void enterEvent(QEvent* theEvent);
187   //virtual void leaveEvent(QEvent* theEvent);
188
189   virtual bool eventFilter(QObject *theObj, QEvent *theEvent);
190
191 private slots:
192   void onClose();
193   void onMinimize();
194   void onMaximize();
195
196   void updateToolBar();
197 //  void repaintToolBar();
198
199 private:
200   enum WindowState
201   {
202     MinimizedState,
203     MaximizedState,
204     WindowNormalState
205   };
206
207   bool processWindowControls(QObject *theObj, QEvent *theEvent);
208   bool processViewPort(QEvent *theEvent);
209
210   void vpMousePressEvent(QMouseEvent* theEvent);
211   void vpMouseReleaseEvent(QMouseEvent* theEvent);
212   void vpMouseMoveEvent(QMouseEvent* theEvent);
213
214   OperationType getButtonState(QMouseEvent* theEvent, XGUI::InteractionStyle theInteractionStyle);
215
216   void resetState();
217   void drawRect();
218   void endDrawRect();
219
220   bool transformRequested() const;
221   bool setTransformRequested(OperationType);
222
223   // Transformation is selected and already started
224   bool transformInProcess() const
225   {
226     return myEventStarted;
227   }
228   void setTransformInProcess(bool bOn)
229   {
230     myEventStarted = bOn;
231   }
232
233 private:
234   XGUI_Viewer* myViewer;
235
236   QLabel* myPicture;
237   ViewerLabel* myGripWgt;
238   XGUI_ViewPort* myViewPort;
239   ViewerToolbar* myViewBar;
240   ViewerToolbar* myWindowBar;
241   QAction* myMinimizeBtn;
242   QAction* myMaximizeBtn;
243
244   QIcon MinimizeIco;
245   QIcon MaximizeIco;
246   QIcon CloseIco;
247   QIcon RestoreIco;
248
249   bool myMoving;
250   QPoint myMousePnt;
251
252   WindowState myLastState;
253
254   int myStartX;
255   int myStartY;
256   int myCurrX;
257   int myCurrY;
258
259   XGUI::InteractionStyle myInteractionStyle;
260   OperationType myOperation;
261   XGUI::Mode2dType my2dMode;
262
263   int myCurSketch;
264   bool myDrawRect;          // set when a rect is used for selection or magnify 
265   bool myEnableDrawMode;
266   bool myRotationPointSelection;
267   bool myCursorIsHand;
268   bool myIsKeyFree;
269   bool myEventStarted;       // set when transformation is in process 
270   bool myClosable;
271
272   QCursor myCursor;
273
274   XGUI::RotationPointType myCurrPointType;
275   XGUI::RotationPointType myPrevPointType;
276
277   gp_Pnt mySelectedPoint;
278
279   XGUI_RectRubberBand* myRectBand; //!< selection rectangle rubber band
280
281   typedef QMap<OperationType, bool> MapOfTransformStatus;
282   MapOfTransformStatus myStatus;
283
284   double myCurScale;
285 };
286
287 //******************************************************
288 /*!
289   \class ViewerToolbar
290   \ingroup GUI
291   \brief Provides a toolbar widget with treansparent background over OCCT View window
292 */
293 class ViewerToolbar: public QToolBar
294 {
295 Q_OBJECT
296 public:
297   ViewerToolbar(QWidget* theParent, XGUI_ViewPort* thePort)
298       : QToolBar(theParent), myVPort(thePort)
299   {
300     setBackgroundRole(QPalette::NoRole);
301     setAttribute(Qt::WA_NoSystemBackground);
302     setAttribute(Qt::WA_PaintOnScreen);
303   }
304
305 protected:
306   virtual void paintEvent(QPaintEvent* theEvent);
307
308 private:
309   XGUI_ViewPort* myVPort;
310 };
311
312 //******************************************************
313 /*!
314   \class ViewerToolbar
315   \ingroup GUI
316   \brief Provides a Label widget with treansparent background over OCCT View window
317 */
318 class ViewerLabel: public QLabel
319 {
320 Q_OBJECT
321 public:
322   ViewerLabel(QWidget* theParent, XGUI_ViewPort* thePort)
323       : QLabel(theParent), myVPort(thePort)
324   {
325     setAttribute(Qt::WA_NoSystemBackground);
326   }
327
328   void repaintBackground();
329
330 protected:
331   virtual void paintEvent(QPaintEvent* theEvent);
332
333 private:
334   XGUI_ViewPort* myVPort;
335 };
336
337 #endif