Salome HOME
ptv, do not send mouse release event just after mouse double click
[modules/gui.git] / src / GLViewer / GLViewer_ViewPort2d.h
1 // File:      GLViewer_ViewPort2d.h
2 // Created:   November, 2004
3 // Author:    OCC team
4 // Copyright (C) CEA 2004
5
6 #ifndef GLVIEWER_VIEWPORT2D_H
7 #define GLVIEWER_VIEWPORT2D_H
8
9 #ifdef WNT
10 #include <windows.h>
11 #endif
12
13 #include <GL/gl.h>
14 #include <GL/glu.h>
15
16 #include "GLViewer_ViewPort.h"
17 #include "GLViewer_Widget.h"
18 #include "GLViewer_Geom.h"
19
20 #include <qgl.h>
21 #include <qcolor.h>
22 #include <qwidget.h>
23 #include <qpaintdevice.h>
24
25 #ifdef WNT
26 #pragma warning( disable:4251 )
27 #endif
28
29 class GLViewer_Compass;
30 class GLViewer_Grid;
31 class GLViewer_Object;
32 class GLViewer_ViewFrame;
33
34 class QtxToolTip;
35 /*! 
36  * Class GLViewer_ViewPort
37  * 2D visualisation canvas of GLViewer
38  */
39 class GLViewer_ViewPort2d: public GLViewer_ViewPort
40 {
41   Q_OBJECT
42
43   //! Dragging states
44   enum vpDragState{ noDrag, initDrag, inDrag };
45
46 public:
47   GLViewer_ViewPort2d( QWidget* parent, GLViewer_ViewFrame* theViewFrame = NULL );
48   ~GLViewer_ViewPort2d();
49
50   //! On/off rectangular grid
51   void                   turnGrid( GLboolean on );
52   //! Returns rectangular grid
53   GLViewer_Grid*         getGrid() const { return myGrid; }
54   //! Returns grid color
55   void                   setGridColor( const QColor gridColor, const QColor axisColor );
56
57   //! Returns parent window
58   GLViewer_ViewFrame*    getViewFrame() const { return myViewFrame; }
59   //! Returns painted widget
60   GLViewer_Widget*       getGLWidget() const { return myGLWidget; }
61   virtual QPaintDevice*  getPaintDevice() { return myGLWidget; }
62
63   //! Sets background color
64   void                   setBackgroundColor( const QColor& color);
65   //! Returns background color
66   QColor                 backgroundColor() const;
67
68   //! Sets borders of scene
69   void                   setBorder( GLViewer_Rect* border ) { myBorder = border; }
70   //! Get current borders of scene
71   GLViewer_Rect*         getBorder() const { return myBorder; }
72   
73   //! Sets margin of borders
74   void                   setMargin( GLfloat margin ) { myMargin = margin; }
75   //! Returns margin of borders
76   GLfloat                getMargin() const { return myMargin; }
77
78   //! Returns width of view
79   int                    getWidth() const { return myWidth; }
80   //! Returns height of view
81   int                    getHeight() const { return myHeight; }
82
83   
84   //! Returns scale factors
85   void                   getScale( GLfloat& xSc, GLfloat& ySc ) const { xSc = myXScale; ySc = myYScale; }
86   //! returns offsets
87   void                   getPan( GLfloat& xPan, GLfloat& yPan ) const { xPan = myXPan; yPan = myYPan; }
88
89   //! Resize view
90   void                   initResize( int width, int height );
91   
92   //! Begins rotation
93   void                   startRotation( int, int );
94   //! Process rotation
95   void                   rotate( int, int );
96   //! Completes rotation
97   void                   endRotation();
98   
99   //! Checks of dragging process state
100   bool                   isDragProcess(){ return myIsDragProcess; }
101   
102   //! On/off compass
103   void                   turnCompass( GLboolean on );
104   //! Draws compass
105   void                   drawCompass();
106   
107   //! Returns unique ID of ViewPort
108   int                    getViewPortId(){ return myViewPortId; }
109   
110   //! Redefined method
111   virtual BlockStatus    currentBlock();
112   
113   //! Initializes before selecting by rect
114   void                   startSelectByRect( int x, int y );
115   //! Draw selecting rectandle
116   void                   drawSelectByRect( int x, int y );
117   //! Pass rect into selector and update
118   void                   finishSelectByRect();
119   
120   //! \warnign It is for ouv
121   bool                   startPulling( GLViewer_Pnt );
122   //! \warnign It is for ouv
123   void                   drawPulling( GLViewer_Pnt );
124   //! \warnign It is for ouv
125   void                   finishPulling();
126   //! \warnign It is for ouv
127   bool                   isPulling() const { return myIsPulling; }
128
129   //! Returns selection by rect
130   QRect                  selectionRect();
131   
132   //! Transforms window rect to global rect 
133   GLViewer_Rect          win2GLV( const QRect& ) const;
134   //! Transforms global rect to window rect
135   QRect                  GLV2win( const GLViewer_Rect& ) const;
136
137 signals:
138   //! Emits after any transformation
139   void                   vpUpdateValues();
140
141   void                   objectMoved();
142
143 protected:
144   void                   onDragObject( QMouseEvent* );
145     
146   virtual void           mouseMoveEvent( QMouseEvent *);
147   virtual void           mousePressEvent( QMouseEvent *);
148   virtual void           mouseReleaseEvent( QMouseEvent *);
149   virtual void           mouseDoubleClickEvent( QMouseEvent *);
150   
151   virtual void           paintEvent( QPaintEvent* );
152   virtual void           resizeEvent( QResizeEvent* );
153
154   //! Returns view to begin state
155   virtual void           reset();
156   //! Sets offset to view
157   virtual void           pan( int dx, int dy );
158   //! Sets view center in global coords
159   virtual void           setCenter( int x, int y );
160   //! Process zoming transformation with mouse tracking from ( x0, y0 ) to ( x1, y1 )
161   virtual void           zoom( int x0, int y0, int x1, int y1 );
162   //! Transforms view by certangle
163   virtual void           fitRect( const QRect& );
164   //! Transforms view by selection
165   virtual void           fitSelect();
166   //! Transform view by view borders ( if \param keepScale = true, zoom does not change )
167   virtual void           fitAll( bool keepScale = false, bool withZ = true );
168
169 protected slots:
170   //! Initializes drag process
171   void                   onStartDragObject();
172   //! Pastes object from clipboard
173   void                   onPasteObject();
174   //! Cuts object to clipboard
175   void                   onCutObject();
176   //! Copies object to clipboard
177   void                   onCopyObject();
178
179   //! Sets tool tip with \param text to \param theTextReg and on \param theViewReg whan mouse is on \param thePoint
180   void                   onMaybeTip( QPoint thePoint, QString& text, QFont& font, QRect& theTextReg, QRect& theViewReg );
181   
182 protected:
183   GLViewer_ViewFrame*    myViewFrame;
184   GLViewer_Widget*       myGLWidget;
185   GLViewer_Rect*         myBorder;
186   QColor                 myBackgroundColor;
187   
188   GLfloat                myMargin;
189   int                    myHeight;
190   int                    myWidth;
191   
192   GLfloat                myXScale;
193   GLfloat                myYScale;
194   GLfloat                myXOldScale;
195   GLfloat                myYOldScale;
196   GLfloat                myXPan;
197   GLfloat                myYPan;
198
199   GLViewer_Grid*         myGrid; 
200   GLViewer_Compass*      myCompass;
201
202   //dragging
203   int                    myIsDragProcess;
204   float*                 myCurDragPosX;
205   float*                 myCurDragPosY;
206   
207   //selection by rect
208   QPoint*                mypFirstPoint;
209   QPoint*                mypLastPoint;
210
211   //pulling
212   bool                   myIsPulling;
213   GLViewer_Object*       myPullingObject;
214     
215   int                    myViewPortId;
216
217   //GLViewer_ObjectTip*    myObjectTip;
218   QtxToolTip*            myObjectTip;
219   //! flag to block mouse release event just after mouse double-click
220   bool                   myIsMouseReleaseBlock;
221 };
222
223 #ifdef WNT
224 #pragma warning ( default:4251 )
225 #endif
226
227 #endif