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