Salome HOME
Merge branch 'master' of newgeom:newgeom
[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
178 protected:
179   virtual void resizeEvent(QResizeEvent* theEvent);
180
181   virtual void changeEvent(QEvent* theEvent);
182
183   virtual void enterEvent(QEvent* theEvent);
184   virtual void leaveEvent(QEvent* theEvent);
185
186   virtual bool eventFilter(QObject *theObj, QEvent *theEvent);
187
188 private slots:
189   void onClose();
190   void onMinimize();
191   void onMaximize();
192
193   void updateToolBar();
194 //  void repaintToolBar();
195
196 private:
197   enum WindowState
198   {
199     MinimizedState, MaximizedState, NormalState
200   };
201
202   bool processWindowControls(QObject *theObj, QEvent *theEvent);
203   bool processViewPort(QEvent *theEvent);
204
205   void vpMousePressEvent(QMouseEvent* theEvent);
206   void vpMouseReleaseEvent(QMouseEvent* theEvent);
207   void vpMouseMoveEvent(QMouseEvent* theEvent);
208
209   OperationType getButtonState(QMouseEvent* theEvent, XGUI::InteractionStyle theInteractionStyle);
210
211   void resetState();
212   void drawRect();
213   void endDrawRect();
214
215   bool transformRequested() const;
216   bool setTransformRequested(OperationType);
217
218   // Transformation is selected and already started
219   bool transformInProcess() const
220   {
221     return myEventStarted;
222   }
223   void setTransformInProcess(bool bOn)
224   {
225     myEventStarted = bOn;
226   }
227
228 private:
229   XGUI_Viewer* myViewer;
230
231   QLabel* myPicture;
232   ViewerLabel* myGripWgt;
233   XGUI_ViewPort* myViewPort;
234   ViewerToolbar* myViewBar;
235   ViewerToolbar* myWindowBar;
236   QAction* myMinimizeBtn;
237   QAction* myMaximizeBtn;
238
239   QIcon MinimizeIco;
240   QIcon MaximizeIco;
241   QIcon CloseIco;
242   QIcon RestoreIco;
243
244   bool myMoving;
245   QPoint myMousePnt;
246
247   WindowState myLastState;
248
249   int myStartX;
250   int myStartY;
251   int myCurrX;
252   int myCurrY;
253
254   XGUI::InteractionStyle myInteractionStyle;
255   OperationType myOperation;
256   XGUI::Mode2dType my2dMode;
257
258   int myCurSketch;
259   bool myDrawRect;          // set when a rect is used for selection or magnify 
260   bool myEnableDrawMode;
261   bool myRotationPointSelection;
262   bool myCursorIsHand;
263   bool myIsKeyFree;
264   bool myEventStarted;       // set when transformation is in process 
265   bool myClosable;
266
267   QCursor myCursor;
268
269   XGUI::RotationPointType myCurrPointType;
270   XGUI::RotationPointType myPrevPointType;
271
272   gp_Pnt mySelectedPoint;
273
274   XGUI_RectRubberBand* myRectBand; //!< selection rectangle rubber band
275
276   typedef QMap<OperationType, bool> MapOfTransformStatus;
277   MapOfTransformStatus myStatus;
278
279   double myCurScale;
280 };
281
282 //******************************************************
283 /*!
284   \class ViewerToolbar
285   \ingroup GUI
286   \brief Provides a toolbar widget with treansparent background over OCCT View window
287 */
288 class ViewerToolbar: public QToolBar
289 {
290 Q_OBJECT
291 public:
292   ViewerToolbar(QWidget* theParent, XGUI_ViewPort* thePort)
293       : QToolBar(theParent), myVPort(thePort)
294   {
295     setBackgroundRole(QPalette::NoRole);
296     setAttribute(Qt::WA_NoSystemBackground);
297     setAttribute(Qt::WA_PaintOnScreen);
298   }
299
300   void repaintBackground();
301
302 protected:
303   virtual void paintEvent(QPaintEvent* theEvent);
304
305 private:
306   XGUI_ViewPort* myVPort;
307 };
308
309 //******************************************************
310 /*!
311   \class ViewerToolbar
312   \ingroup GUI
313   \brief Provides a Label widget with treansparent background over OCCT View window
314 */
315 class ViewerLabel: public QLabel
316 {
317 Q_OBJECT
318 public:
319   ViewerLabel(QWidget* theParent, XGUI_ViewPort* thePort)
320       : QLabel(theParent), myVPort(thePort)
321   {
322     setAttribute(Qt::WA_NoSystemBackground);
323   }
324
325   void repaintBackground();
326
327 protected:
328   virtual void paintEvent(QPaintEvent* theEvent);
329
330 private:
331   XGUI_ViewPort* myVPort;
332 };
333
334 #endif