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