]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_ViewWindow.h
Salome HOME
Make XGUI as a shared library
[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 signals:
91   //! Emited whien view transformation operation is started
92   void vpTransformationStarted(XGUI_ViewWindow::OperationType type);
93
94   //! Emited whien view transformation operation is finished
95   void vpTransformationFinished(XGUI_ViewWindow::OperationType type);
96
97   //void Show(QShowEvent *);
98   //void Hide(QHideEvent *);
99   //void maximized(XGUI_ViewWindow*, bool);
100   //void returnedTo3d();
101
102   //! Emited before the window closing
103   void tryClosing(XGUI_ViewWindow*);
104
105   //! Emited when window is closing
106   void closed( QMdiSubWindow* );
107
108   //! Emited on mouse press in view port
109   void mousePressed(XGUI_ViewWindow*, QMouseEvent*);
110
111   //! Emited on mouse release in view port
112   void mouseReleased(XGUI_ViewWindow*, QMouseEvent*);
113
114   //! Emited on mouse double click in view port
115   void mouseDoubleClicked(XGUI_ViewWindow*, QMouseEvent*);
116
117   //! Emited on mouse moving in view port
118   void mouseMoving(XGUI_ViewWindow*, QMouseEvent*);
119  
120   //! Emited on key press in view port
121   void keyPressed(XGUI_ViewWindow*, QKeyEvent*);
122  
123   //! Emited on key release in view port
124   void keyReleased(XGUI_ViewWindow*, QKeyEvent*);
125  
126   //! Emited on context menu request in view port
127   void contextMenuRequested(QContextMenuEvent *e);
128
129   //void viewModified(XGUI_ViewWindow*);
130   void viewCloned( QMdiSubWindow* theView );
131
132 public slots:
133   //! Start zooming operation
134   void activateZoom();
135
136   //! Start rotation operation
137   void activateRotation();
138
139   //! Start panning operation
140   void activatePanning();
141
142   //! Start window fit operation
143   void activateWindowFit();
144
145   //! Start global panning operation
146   void activateGlobalPanning();
147
148   //! Clone the view window preserving a view point of the current view
149   void cloneView();
150
151   //! Dump the view window into external file (*.bmp *.png *.jpg *.jpeg *.eps *.ps)
152   void dumpView();
153
154   //! Fit all command
155   void fitAll();
156
157   //! Set front view
158   void frontView();
159
160   //! Set back view
161   void backView();
162
163   //! Set top view
164   void topView();
165
166   //! Set bottom view
167   void bottomView();
168
169   //! Set left view
170   void leftView();
171
172   //! Set right view
173   void rightView();
174
175   //! Reset point of view
176   void reset();
177
178   void windowActivated();
179
180   void windowDeactivated();
181
182 protected:
183   virtual void resizeEvent(QResizeEvent* theEvent);
184
185   virtual void changeEvent(QEvent* theEvent);
186
187   //virtual void enterEvent(QEvent* theEvent);
188   //virtual void leaveEvent(QEvent* theEvent);
189
190   virtual bool eventFilter(QObject *theObj, QEvent *theEvent);
191
192 private slots:
193   void onClose();
194   void onMinimize();
195   void onMaximize();
196
197   void updateToolBar();
198 //  void repaintToolBar();
199
200 private:
201   enum WindowState
202   {
203     MinimizedState,
204     MaximizedState,
205     WindowNormalState
206   };
207
208   bool processWindowControls(QObject *theObj, QEvent *theEvent);
209   bool processViewPort(QEvent *theEvent);
210
211   void vpMousePressEvent(QMouseEvent* theEvent);
212   void vpMouseReleaseEvent(QMouseEvent* theEvent);
213   void vpMouseMoveEvent(QMouseEvent* theEvent);
214
215   OperationType getButtonState(QMouseEvent* theEvent, XGUI::InteractionStyle theInteractionStyle);
216
217   void resetState();
218   void drawRect();
219   void endDrawRect();
220
221   bool transformRequested() const;
222   bool setTransformRequested(OperationType);
223
224   // Transformation is selected and already started
225   bool transformInProcess() const
226   {
227     return myEventStarted;
228   }
229   void setTransformInProcess(bool bOn)
230   {
231     myEventStarted = bOn;
232   }
233
234 private:
235   XGUI_Viewer* myViewer;
236
237   QLabel* myPicture;
238   ViewerLabel* myGripWgt;
239   XGUI_ViewPort* myViewPort;
240   ViewerToolbar* myViewBar;
241   ViewerToolbar* myWindowBar;
242   QAction* myMinimizeBtn;
243   QAction* myMaximizeBtn;
244
245   QIcon MinimizeIco;
246   QIcon MaximizeIco;
247   QIcon CloseIco;
248   QIcon RestoreIco;
249
250   bool myMoving;
251   QPoint myMousePnt;
252
253   WindowState myLastState;
254
255   int myStartX;
256   int myStartY;
257   int myCurrX;
258   int myCurrY;
259
260   XGUI::InteractionStyle myInteractionStyle;
261   OperationType myOperation;
262   XGUI::Mode2dType my2dMode;
263
264   int myCurSketch;
265   bool myDrawRect;          // set when a rect is used for selection or magnify 
266   bool myEnableDrawMode;
267   bool myRotationPointSelection;
268   bool myCursorIsHand;
269   bool myIsKeyFree;
270   bool myEventStarted;       // set when transformation is in process 
271   bool myClosable;
272
273   QCursor myCursor;
274
275   XGUI::RotationPointType myCurrPointType;
276   XGUI::RotationPointType myPrevPointType;
277
278   gp_Pnt mySelectedPoint;
279
280   XGUI_RectRubberBand* myRectBand; //!< selection rectangle rubber band
281
282   typedef QMap<OperationType, bool> MapOfTransformStatus;
283   MapOfTransformStatus myStatus;
284
285   double myCurScale;
286 };
287
288 //******************************************************
289 /*!
290   \class ViewerToolbar
291   \ingroup GUI
292   \brief Provides a toolbar widget with treansparent background over OCCT View window
293 */
294 class ViewerToolbar: public QToolBar
295 {
296 Q_OBJECT
297 public:
298   ViewerToolbar(QWidget* theParent, XGUI_ViewPort* thePort)
299       : QToolBar(theParent), myVPort(thePort)
300   {
301     setBackgroundRole(QPalette::NoRole);
302     setAttribute(Qt::WA_NoSystemBackground);
303     setAttribute(Qt::WA_PaintOnScreen);
304   }
305
306 protected:
307   virtual void paintEvent(QPaintEvent* theEvent);
308
309 private:
310   XGUI_ViewPort* myVPort;
311 };
312
313 //******************************************************
314 /*!
315   \class ViewerToolbar
316   \ingroup GUI
317   \brief Provides a Label widget with treansparent background over OCCT View window
318 */
319 class ViewerLabel: public QLabel
320 {
321 Q_OBJECT
322 public:
323   ViewerLabel(QWidget* theParent, XGUI_ViewPort* thePort)
324       : QLabel(theParent), myVPort(thePort)
325   {
326     setAttribute(Qt::WA_NoSystemBackground);
327   }
328
329   void repaintBackground();
330
331 protected:
332   virtual void paintEvent(QPaintEvent* theEvent);
333
334 private:
335   XGUI_ViewPort* myVPort;
336 };
337
338 #endif