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