Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/gui.git] / src / GLViewer / GLViewer_ViewPort.h
1 //  Copyright (C) 2005 OPEN CASCADE
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 //  Author : OPEN CASCADE
20 //
21
22 // File:      GLViewer_ViewPort.h
23 // Created:   November, 2004
24
25 #ifndef GLVIEWER_VIEWPORT_H
26 #define GLVIEWER_VIEWPORT_H
27
28 #include "GLViewer.h"
29
30 #include <qlist.h>
31 #include <qcolor.h>
32 #include <qaction.h>
33 #include <qwidget.h>
34
35 #include <Aspect_Window.hxx>
36
37 class QRect;
38 class QCursor;
39 class QPainter;
40 class GLViewer_ViewSketcher;
41 class GLViewer_ViewTransformer;
42
43 #ifdef WNT
44 #pragma warning( disable:4251 )
45 #endif
46
47 enum BlockStatus
48 {
49     BS_NoBlock          = 0x0000,
50     BS_Highlighting     = 0x0001,
51     BS_Selection        = 0x0002,
52     BS_Dragging         = 0x0004
53 };
54
55 /*!
56   \class GLViewer_ViewPort
57   Visualisation canvas of GLViewer
58 */
59 class GLVIEWER_API GLViewer_ViewPort: public QWidget
60 {
61     Q_OBJECT
62     friend class GLViewer_ViewSketcher;
63     friend class GLViewer_ViewTransformer;
64
65 public:
66     GLViewer_ViewPort( QWidget* parent );
67     ~GLViewer_ViewPort();
68
69 public:
70     //! Activates/deactivates sketching
71     void                             setSketchingEnabled( bool );
72     //! Checks active status of sketcher
73     bool                             isSketchingEnabled() const;
74     //! Activates/deactivates transformer
75     void                             setTransformEnabled( bool );
76     //! Checks active status of transformer
77     bool                             isTransformEnabled() const;
78
79     //! Returns background color
80     virtual QColor                   backgroundColor() const;
81     //! Sets background color
82     virtual void                     setBackgroundColor( const QColor& );
83
84     //! Redraw external pa inters
85     void                             redrawPainters();
86
87     //! Updates view
88     virtual void                     onUpdate();
89
90     //! Returns blocking status for current started operations
91     virtual BlockStatus              currentBlock(){ return BS_NoBlock; }
92
93 protected:
94     enum ViewType { Type2D, Type3D };
95     void                             selectVisualId( ViewType );
96
97     virtual QPaintDevice*            getPaintDevice() { return this; }
98     virtual void                     contextMenuEvent( QContextMenuEvent * e );
99
100 //! STATICS
101     static void                      createCursors();
102     static void                      destroyCursors();
103     static QCursor*                  getHandCursor() { return handCursor; }
104     static void                      setHandCursor( const QCursor& newCursor );
105     static QCursor*                  getPanCursor() { return panCursor; }
106     static void                      setPanCursor( const QCursor& newCursor );
107     static QCursor*                  getPanglCursor() { return panglCursor; }
108     static void                      setPanglCursor( const QCursor& newCursor );
109     static QCursor*                  getZoomCursor() { return zoomCursor; }
110     static void                      setZoomCursor( const QCursor& newCursor );
111
112 public://ouv
113     static QCursor*                  getDefaultCursor() { return defCursor; }
114     static void                      setDefaultCursor( const QCursor& newCursor );
115     static QCursor*                  getRotCursor() { return rotCursor; }
116     static void                      setRotCursor( const QCursor& newCursor );
117     static QCursor*                  getSketchCursor() { return sketchCursor; }
118     static void                      setSketchCursor( const QCursor& newCursor );
119
120 protected:
121 //! EVENTS
122     virtual void                     paintEvent( QPaintEvent *);
123     virtual void                     mouseMoveEvent( QMouseEvent *);
124     virtual void                     mouseReleaseEvent( QMouseEvent *);
125     virtual void                     mousePressEvent( QMouseEvent *);
126     virtual void                     mouseDoubleClickEvent( QMouseEvent *);
127     virtual void                     keyPressEvent( QKeyEvent *);
128     virtual void                     keyReleaseEvent( QKeyEvent *);
129     virtual void                     wheelEvent( QWheelEvent *);
130
131 //! TO BE REDEFINED
132     virtual void                     reset() = 0;
133     virtual void                     pan( int, int ) = 0;
134     virtual void                     setCenter( int, int ) = 0;    
135     virtual void                     zoom( int, int, int, int ) = 0;
136     virtual void                     fitRect( const QRect& ) = 0;
137     virtual void                     fitSelect() = 0;
138     virtual void                     fitAll( bool keepScale = false, bool withZ = true ) = 0;
139
140 protected slots:
141     virtual void                     onChangeBgColor();
142
143 signals:
144     void                             vpKeyEvent( QKeyEvent* );
145     void                             vpMouseEvent( QMouseEvent* );
146     void                             vpWheelEvent( QWheelEvent* );
147     void                             vpDrawExternal( QPainter* );
148
149     void                             contextMenuRequested( QContextMenuEvent* );
150
151 private:
152     void                             initialize();
153     void                             cleanup();
154
155 protected:
156     //Handle(Aspect_Window)            myWindow;
157     bool                             myEnableSketching;
158     bool                             myEnableTransform;
159     bool                             myPaintersRedrawing;   /* set to draw externally */
160     //QList<QAction>                   myPopupActions;
161
162 private:
163     static int                       nCounter;              /* objects counter */
164     static QCursor*                  defCursor;
165     static QCursor*                  panglCursor;
166     static QCursor*                  handCursor;
167     static QCursor*                  panCursor;
168     static QCursor*                  zoomCursor;
169     static QCursor*                  rotCursor;
170     static QCursor*                  sketchCursor;
171 };
172
173 #ifdef WNT
174 #pragma warning ( default:4251 )
175 #endif
176
177 #endif