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