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 class XGUI_ViewWindow: public QFrame
24 {
25 Q_OBJECT
26 public:
27   enum OperationType
28   {
29     NOTHING,
30     PANVIEW,
31     ZOOMVIEW,
32     ROTATE,
33     PANGLOBAL,
34     WINDOWFIT,
35     FITALLVIEW,
36     RESETVIEW,
37     FRONTVIEW,
38     BACKVIEW,
39     TOPVIEW,
40     BOTTOMVIEW,
41     LEFTVIEW,
42     RIGHTVIEW,
43     CLOCKWISEVIEW,
44     ANTICLOCKWISEVIEW
45   };
46
47   XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType);
48
49   virtual ~XGUI_ViewWindow();
50
51   XGUI_ViewPort* viewPort() const
52   {
53     return myViewPort;
54   }
55
56   XGUI::InteractionStyle interactionStyle() const
57   {
58     return myInteractionStyle;
59   }
60
61   void setTransformEnabled(const OperationType, const bool);
62   bool transformEnabled(const OperationType) const;
63
64   XGUI_ViewBackground background() const;
65   void setBackground(const XGUI_ViewBackground& theBackground);
66
67   bool closable() const { return myClosable; }
68   void setClosable( const bool isClosable ) { myClosable = isClosable; }
69
70 signals:
71     void vpTransformationStarted(XGUI_ViewWindow::OperationType type);
72     void vpTransformationFinished(XGUI_ViewWindow::OperationType type);
73
74     void Show(QShowEvent *);
75     void Hide(QHideEvent *);
76     void maximized(XGUI_ViewWindow*, bool);
77     void returnedTo3d();
78
79     void tryClosing(XGUI_ViewWindow*);
80     void closed( QMdiSubWindow* );
81     void mousePressed(XGUI_ViewWindow*, QMouseEvent*);
82     void mouseReleased(XGUI_ViewWindow*, QMouseEvent*);
83     void mouseDoubleClicked(XGUI_ViewWindow*, QMouseEvent*);
84     void mouseMoving(XGUI_ViewWindow*, QMouseEvent*);
85     void keyPressed(XGUI_ViewWindow*, QKeyEvent*);
86     void keyReleased(XGUI_ViewWindow*, QKeyEvent*);
87     void contextMenuRequested(QContextMenuEvent *e);
88
89     void viewModified(XGUI_ViewWindow*);
90     void viewCloned( QMdiSubWindow* theView );
91
92 public slots:
93   void activateZoom();
94   void activateRotation();
95   void activatePanning();
96   void activateWindowFit();
97   void activateGlobalPanning();
98
99   void cloneView();
100   void dumpView();
101   void fitAll();
102
103   void frontView();
104   void backView();
105   void topView();
106   void bottomView();
107   void leftView();
108   void rightView();
109
110   void reset();
111
112
113 protected:
114   virtual void resizeEvent(QResizeEvent* theEvent);
115
116   virtual void changeEvent(QEvent* theEvent);
117
118   virtual void enterEvent(QEvent* theEvent);
119   virtual void leaveEvent(QEvent* theEvent);
120
121   virtual bool eventFilter(QObject *theObj, QEvent *theEvent);
122
123 private slots:
124   void onClose();
125   void onMinimize();
126   void onMaximize();
127
128   void updateToolBar();
129 //  void repaintToolBar();
130
131 private:
132   enum WindowState
133   {
134     MinimizedState, MaximizedState, NormalState
135   };
136
137   bool processWindowControls(QObject *theObj, QEvent *theEvent);
138   bool processViewPort(QEvent *theEvent);
139
140   void vpMousePressEvent(QMouseEvent* theEvent);
141   void vpMouseReleaseEvent(QMouseEvent* theEvent);
142   void vpMouseMoveEvent(QMouseEvent* theEvent);
143
144   OperationType getButtonState(QMouseEvent* theEvent, XGUI::InteractionStyle theInteractionStyle);
145
146   void resetState();
147   void drawRect();
148   void endDrawRect();
149
150   bool transformRequested() const;
151   bool setTransformRequested(OperationType);
152
153   // Transformation is selected and already started
154   bool transformInProcess() const
155   {
156     return myEventStarted;
157   }
158   void setTransformInProcess(bool bOn)
159   {
160     myEventStarted = bOn;
161   }
162
163 private:
164   XGUI_Viewer* myViewer;
165
166   QLabel* myPicture;
167   ViewerLabel* myGripWgt;
168   XGUI_ViewPort* myViewPort;
169   ViewerToolbar* myViewBar;
170   ViewerToolbar* myWindowBar;
171   QAction* myMinimizeBtn;
172   QAction* myMaximizeBtn;
173
174   QIcon MinimizeIco;
175   QIcon MaximizeIco;
176   QIcon CloseIco;
177   QIcon RestoreIco;
178
179   bool myMoving;
180   QPoint myMousePnt;
181
182   WindowState myLastState;
183
184   int myStartX;
185   int myStartY;
186   int myCurrX;
187   int myCurrY;
188
189   XGUI::InteractionStyle myInteractionStyle;
190   OperationType myOperation;
191   XGUI::Mode2dType my2dMode;
192
193   int myCurSketch;
194   bool myDrawRect;          // set when a rect is used for selection or magnify 
195   bool myEnableDrawMode;
196   bool myRotationPointSelection;
197   bool myCursorIsHand;
198   bool myIsKeyFree;
199   bool myEventStarted;       // set when transformation is in process 
200   bool myClosable;
201
202   QCursor myCursor;
203
204   XGUI::RotationPointType myCurrPointType;
205   XGUI::RotationPointType myPrevPointType;
206
207   gp_Pnt mySelectedPoint;
208
209   XGUI_RectRubberBand* myRectBand; //!< selection rectangle rubber band
210
211   typedef QMap<OperationType, bool> MapOfTransformStatus;
212   MapOfTransformStatus myStatus;
213
214   double myCurScale;
215 };
216
217 //******************************************************
218 class ViewerToolbar: public QToolBar
219 {
220 Q_OBJECT
221 public:
222   ViewerToolbar(QWidget* theParent, XGUI_ViewPort* thePort)
223       : QToolBar(theParent), myVPort(thePort)
224   {
225     setBackgroundRole(QPalette::NoRole);
226     setAttribute(Qt::WA_NoSystemBackground);
227     setAttribute(Qt::WA_PaintOnScreen);
228   }
229
230   void repaintBackground();
231
232 protected:
233   virtual void paintEvent(QPaintEvent* theEvent);
234
235 private:
236   XGUI_ViewPort* myVPort;
237 };
238
239 //******************************************************
240 class ViewerLabel: public QLabel
241 {
242 Q_OBJECT
243 public:
244   ViewerLabel(QWidget* theParent, XGUI_ViewPort* thePort)
245       : QLabel(theParent), myVPort(thePort)
246   {
247     setAttribute(Qt::WA_NoSystemBackground);
248   }
249
250   void repaintBackground();
251
252 protected:
253   virtual void paintEvent(QPaintEvent* theEvent);
254
255 private:
256   XGUI_ViewPort* myVPort;
257 };
258
259 #endif