Salome HOME
9553fcf24c49de9f5b572429540ff2cc028f430b
[modules/gui.git] / src / GLViewer / GLViewer_ViewPort.h
1 // File:      GLViewer_ViewPort.h
2 // Created:   November, 2004
3 // Author:    OCC team
4 // Copyright (C) CEA 2004
5
6 /***************************************************************************
7 **  Class:   GLViewer_ViewPort
8 **  Descr:   Visualisation canvas of GLViewer
9 **  Created: UI team, 05.09.04
10 ****************************************************************************/
11 #ifndef GLVIEWER_VIEWPORT_H
12 #define GLVIEWER_VIEWPORT_H
13
14 #include "GLViewer.h"
15
16 #include <qlist.h>
17 #include <qcolor.h>
18 #include <qaction.h>
19 #include <qwidget.h>
20
21 #include <Aspect_Window.hxx>
22
23 class QRect;
24 class QCursor;
25 class QPainter;
26 class GLViewer_ViewSketcher;
27 class GLViewer_ViewTransformer;
28
29 #ifdef WNT
30 #pragma warning( disable:4251 )
31 #endif
32
33 enum BlockStatus
34 {
35     BS_NoBlock          = 0x0000,
36     BS_Highlighting     = 0x0001,
37     BS_Selection        = 0x0002,
38     BS_Dragging         = 0x0004
39 };
40
41 /*! 
42  * Class GLViewer_ViewPort
43  * Visualisation canvas of GLViewer
44  */
45 class GLVIEWER_API GLViewer_ViewPort: public QWidget
46 {
47     Q_OBJECT
48     friend class GLViewer_ViewSketcher;
49     friend class GLViewer_ViewTransformer;
50
51 public:
52     GLViewer_ViewPort( QWidget* parent );
53     ~GLViewer_ViewPort();
54
55 public:
56     //! Activates/deactivates sketching
57     void                             setSketchingEnabled( bool );
58     //! Checks active status of sketcher
59     bool                             isSketchingEnabled() const;
60     //! Activates/deactivates transformer
61     void                             setTransformEnabled( bool );
62     //! Checks active status of transformer
63     bool                             isTransformEnabled() const;
64
65     //! Returns background color
66     virtual QColor                   backgroundColor() const;
67     //! Sets background color
68     virtual void                     setBackgroundColor( const QColor& );
69
70     //! Redraw external pa inters
71     void                             redrawPainters();
72
73     //! Updates view
74     virtual void                     onUpdate();
75
76     //! Returns blocking status for current started operations
77     virtual BlockStatus              currentBlock(){ return BS_NoBlock; }
78
79 protected:
80     enum ViewType { Type2D, Type3D };
81     void                             selectVisualId( ViewType );
82
83     virtual QPaintDevice*            getPaintDevice() { return this; }
84     virtual void                     contextMenuEvent( QContextMenuEvent * e );
85
86 //! STATICS
87     static void                      createCursors();
88     static void                      destroyCursors();
89     static QCursor*                  getHandCursor() { return handCursor; }
90     static void                      setHandCursor( const QCursor& newCursor );
91     static QCursor*                  getPanCursor() { return panCursor; }
92     static void                      setPanCursor( const QCursor& newCursor );
93     static QCursor*                  getPanglCursor() { return panglCursor; }
94     static void                      setPanglCursor( const QCursor& newCursor );
95     static QCursor*                  getZoomCursor() { return zoomCursor; }
96     static void                      setZoomCursor( const QCursor& newCursor );
97
98 public://ouv
99     static QCursor*                  getDefaultCursor() { return defCursor; }
100     static void                      setDefaultCursor( const QCursor& newCursor );
101     static QCursor*                  getRotCursor() { return rotCursor; }
102     static void                      setRotCursor( const QCursor& newCursor );
103     static QCursor*                  getSketchCursor() { return sketchCursor; }
104     static void                      setSketchCursor( const QCursor& newCursor );
105
106 protected:
107 //! EVENTS
108     virtual void                     paintEvent( QPaintEvent *);
109     virtual void                     mouseMoveEvent( QMouseEvent *);
110     virtual void                     mouseReleaseEvent( QMouseEvent *);
111     virtual void                     mousePressEvent( QMouseEvent *);
112     virtual void                     mouseDoubleClickEvent( QMouseEvent *);
113     virtual void                     keyPressEvent( QKeyEvent *);
114     virtual void                     keyReleaseEvent( QKeyEvent *);
115     virtual void                     wheelEvent( QWheelEvent *);
116
117 //! TO BE REDEFINED
118     virtual void                     reset() = 0;
119     virtual void                     pan( int, int ) = 0;
120     virtual void                     setCenter( int, int ) = 0;    
121     virtual void                     zoom( int, int, int, int ) = 0;
122     virtual void                     fitRect( const QRect& ) = 0;
123     virtual void                     fitSelect() = 0;
124     virtual void                     fitAll( bool keepScale = false, bool withZ = true ) = 0;
125
126 protected slots:
127     virtual void                     onChangeBgColor();
128
129 signals:
130     void                             vpKeyEvent( QKeyEvent* );
131     void                             vpMouseEvent( QMouseEvent* );
132     void                             vpWheelEvent( QWheelEvent* );
133     void                             vpDrawExternal( QPainter* );
134
135     void                             contextMenuRequested( QContextMenuEvent* );
136
137 private:
138     void                             initialize();
139     void                             cleanup();
140
141 protected:
142     //Handle(Aspect_Window)            myWindow;
143     bool                             myEnableSketching;
144     bool                             myEnableTransform;
145     bool                             myPaintersRedrawing;   /* set to draw externally */
146     //QList<QAction>                   myPopupActions;
147
148 private:
149     static int                       nCounter;              /* objects counter */
150     static QCursor*                  defCursor;
151     static QCursor*                  panglCursor;
152     static QCursor*                  handCursor;
153     static QCursor*                  panCursor;
154     static QCursor*                  zoomCursor;
155     static QCursor*                  rotCursor;
156     static QCursor*                  sketchCursor;
157 };
158
159 #ifdef WNT
160 #pragma warning ( default:4251 )
161 #endif
162
163 #endif