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