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