1 // File: GLViewer_ViewPort2d.h
2 // Created: November, 2004
4 // Copyright (C) CEA 2004
6 #ifndef GLVIEWER_VIEWPORT2D_H
7 #define GLVIEWER_VIEWPORT2D_H
16 #include "GLViewer_ViewPort.h"
17 #include "GLViewer_Widget.h"
18 #include "GLViewer_Geom.h"
23 #include <qpaintdevice.h>
26 #pragma warning( disable:4251 )
29 class GLViewer_Compass;
31 class GLViewer_Object;
32 class GLViewer_ViewFrame;
36 * Class GLViewer_ViewPort
37 * 2D visualisation canvas of GLViewer
39 class GLViewer_ViewPort2d: public GLViewer_ViewPort
44 enum vpDragState{ noDrag, initDrag, inDrag };
47 GLViewer_ViewPort2d( QWidget* parent, GLViewer_ViewFrame* theViewFrame = NULL );
48 ~GLViewer_ViewPort2d();
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 );
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; }
63 //! Sets background color
64 void setBackgroundColor( const QColor& color);
65 //! Returns background color
66 QColor backgroundColor() const;
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; }
73 //! Sets margin of borders
74 void setMargin( GLfloat margin ) { myMargin = margin; }
75 //! Returns margin of borders
76 GLfloat getMargin() const { return myMargin; }
78 //! Returns width of view
79 int getWidth() const { return myWidth; }
80 //! Returns height of view
81 int getHeight() const { return myHeight; }
84 //! Returns scale factors
85 void getScale( GLfloat& xSc, GLfloat& ySc ) const { xSc = myXScale; ySc = myYScale; }
87 void getPan( GLfloat& xPan, GLfloat& yPan ) const { xPan = myXPan; yPan = myYPan; }
90 void initResize( int width, int height );
93 void startRotation( int, int );
95 void rotate( int, int );
96 //! Completes rotation
99 //! Checks of dragging process state
100 bool isDragProcess(){ return myIsDragProcess; }
103 void turnCompass( GLboolean on );
107 //! Returns unique ID of ViewPort
108 int getViewPortId(){ return myViewPortId; }
111 virtual BlockStatus currentBlock();
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();
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; }
129 //! Returns selection by rect
130 QRect selectionRect();
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;
138 //! Emits after any transformation
139 void vpUpdateValues();
144 void onDragObject( QMouseEvent* );
146 virtual void mouseMoveEvent( QMouseEvent *);
147 virtual void mousePressEvent( QMouseEvent *);
148 virtual void mouseReleaseEvent( QMouseEvent *);
149 virtual void mouseDoubleClickEvent( QMouseEvent *);
151 virtual void paintEvent( QPaintEvent* );
152 virtual void resizeEvent( QResizeEvent* );
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 );
170 //! Initializes drag process
171 void onStartDragObject();
172 //! Pastes object from clipboard
173 void onPasteObject();
174 //! Cuts object to clipboard
176 //! Copies object to clipboard
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 );
183 GLViewer_ViewFrame* myViewFrame;
184 GLViewer_Widget* myGLWidget;
185 GLViewer_Rect* myBorder;
186 QColor myBackgroundColor;
199 GLViewer_Grid* myGrid;
200 GLViewer_Compass* myCompass;
204 float* myCurDragPosX;
205 float* myCurDragPosY;
208 QPoint* mypFirstPoint;
209 QPoint* mypLastPoint;
213 GLViewer_Object* myPullingObject;
217 //GLViewer_ObjectTip* myObjectTip;
218 QtxToolTip* myObjectTip;
219 //! flag to block mouse release event just after mouse double-click
220 bool myIsMouseReleaseBlock;
224 #pragma warning ( default:4251 )