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