]> SALOME platform Git repositories - modules/kernel.git/blob - src/OCCViewer/OCCViewer_ViewPort.h
Salome HOME
Initialisation de la base KERNEL avec la version operationnelle de KERNEL_SRC issue...
[modules/kernel.git] / src / OCCViewer / OCCViewer_ViewPort.h
1 //  File      : OCCViewer_ViewPort.h
2 //  Created   : Wed Mar 20 10:41:50 2002
3 //  Author    : Nicolas REJNERI
4 //  Project   : SALOME
5 //  Module    : OCCViewer
6 //  Copyright : Open CASCADE 2002
7 //  $Header$
8
9
10 #ifndef OCCViewer_ViewPort_H
11 #define OCCViewer_ViewPort_H
12
13 #include "QAD.h"
14 #include "QAD_Popup.h"
15
16 // QT Includes
17 #include <qrect.h>
18 #include <qcolor.h>
19 #include <qwidget.h>
20 #include <qcursor.h>
21 #include <qpainter.h>
22
23 class QAD_EXPORT OCCViewer_ViewPort: public QWidget, 
24   public QAD_PopupClientServer
25 {
26   Q_OBJECT
27
28   /* Objects counter */
29   static int            nCounter;                               
30         
31   /* Cursors */
32   static QCursor*       defCursor;
33   static QCursor*       handCursor;
34   static QCursor*       panCursor;
35   static QCursor*       zoomCursor;
36   static QCursor*       rotCursor;
37   static QCursor*       glPanCursor;
38
39   void  initialize();
40   void  cleanup();
41
42 public:
43   enum OperationType    {
44     NOTHING,
45     PANVIEW,
46     ZOOMVIEW,
47     ROTATE,
48     PANGLOBAL,
49     WINDOWFIT
50   };
51
52 protected:
53   static void createCursors();
54   static void destroyCursors();
55   
56   static const QCursor* getDefaultCursor() { return defCursor; }
57   static void setDefaultCursor(const QCursor& newCursor);
58   static const QCursor* getHandCursor() { return handCursor; }
59   static void setHandCursor(const QCursor& newCursor);
60   static const QCursor* getPanCursor() { return panCursor; }
61   static void setPanCursor(const QCursor& newCursor);
62   static const QCursor* getZoomCursor() { return zoomCursor; }
63   static void setZoomCursor(const QCursor& newCursor);
64   static const QCursor* getRotCursor() { return rotCursor; }
65   static void setRotCursor(const QCursor& newCursor);
66   static const QCursor* getGlPanCursor() { return rotCursor; }
67   static void setGlPanCursor(const QCursor& newCursor);
68   
69   /* Transformation selected but not started yet */
70   bool          transformRequested() const { return ( myOperation != NOTHING ); }
71   void          setTransformRequested ( OperationType op );
72
73   /* Transformation is selected and already started */
74   bool          transformInProcess() const { return myEventStarted; }
75   void          setTransformInProcess( bool bOn ) { myEventStarted = bOn; }
76
77 public:
78   OCCViewer_ViewPort( QWidget* parent );
79   ~OCCViewer_ViewPort();
80   
81   /* Draw mode management */
82   void          enableDrawMode( bool bEnable );
83   bool          enableDrawMode() const;
84
85   /* Cursors management */
86   void          setDefaultCursorOn();
87   void          setHandCursorOn();
88   void          setPanCursorOn();
89   void          setZoomCursorOn();
90   void          setRotCursorOn();
91   void          setGlPanCursorOn();
92
93   void          resetState();
94   bool          hasWindow() const;
95   void          windowChanged();
96   void          redrawPainters();
97   void          update(int x, int y, int w, int h);
98   
99   void                setOriginalView( OCCViewer_ViewPort* view, const QRect& magnify );
100   OCCViewer_ViewPort* getOriginalView() const;
101   const QRect&        getMagnifyRect() const;
102   const QRect&        getSelectionRect() const;
103
104   /* View transformations */
105   virtual void    activateZoom();       
106   virtual void    activatePanning();
107   virtual void    activateRotation();
108   virtual void    activateWindowFit();
109   virtual void    activateGlobalPanning();      
110   
111   virtual void    fitAll( bool withZ = true ) = 0;
112   virtual void    reset() = 0;
113   
114   virtual QColor  backgroundColor() const;
115   virtual void    setBackgroundColor( const QColor& color) = 0;
116
117 protected: 
118   virtual void    paintEvent(QPaintEvent *);
119   virtual void    resizeEvent(QResizeEvent *);
120   
121   virtual void    mouseMoveEvent(QMouseEvent *);
122   virtual void    mouseReleaseEvent(QMouseEvent *);
123   virtual void    mousePressEvent(QMouseEvent *);
124   virtual void    mouseDoubleClickEvent(QMouseEvent *); 
125
126   virtual void    keyPressEvent(QKeyEvent *);
127   virtual void    keyReleaseEvent(QKeyEvent *);
128
129   virtual void    focusInEvent(QFocusEvent *event);
130   virtual void    focusOutEvent(QFocusEvent *event);
131
132 signals:
133   void            vpTransformationStarted (OCCViewer_ViewPort::OperationType type);
134   void            vpTransformationFinished (OCCViewer_ViewPort::OperationType type);
135   
136   void            vpMousePress (QMouseEvent*);
137   void            vpMouseRelease (QMouseEvent*);
138   void            vpMouseMove (QMouseEvent*);
139   void            vpMouseDoubleClick (QMouseEvent*);
140   
141   void            vpKeyPress (QKeyEvent*);
142   void            vpKeyRelease (QKeyEvent*);
143   
144   void            vpFocusOut (QFocusEvent*);
145   void            vpFocusIn (QFocusEvent*);
146   
147   void            vpPaint (QPaintEvent*);
148   void            vpDrawExternal (QPainter* painter);
149
150 protected slots:
151  virtual void   onChangeBackgroundColor() = 0;
152
153 protected:    
154  virtual bool   setWindow() = 0;
155  virtual void   windowResize() = 0;     
156  virtual void   pan(int dx, int dy) = 0;        
157  virtual void   setCenter(int x, int y) = 0;
158  virtual void   fitWindow( const QRect& rect) = 0;
159  virtual void   zoom(int x0, int y0, int x, int y) = 0; 
160  virtual void   startRotation(int x0, int y0) = 0;
161  virtual void   rotate(int x, int y) = 0;
162  virtual void   endRotation() = 0;
163         
164 protected:
165  OCCViewer_ViewPort*    myOriginalViewport;
166  OperationType          myOperation;
167  QCursor                myCursor;
168  
169  QRect                  myMagnifyRect;
170  QRect                  myRect;                         
171  bool                   myDrawRect;  /* set when a rect is used for selection or magnify */
172         
173  /* Mouse coordinates */
174  int                    myStartX;       
175  int                    myStartY;
176  int                    myCurrX;
177  int                    myCurrY;
178
179  bool                   myHasWindow;
180  bool                   myCursorIsHand;                 
181  bool                   myEnableDrawMode;
182  bool                   myEventStarted;       /* set when transformation is in process */
183  bool                   myPaintersRedrawing;  /* set to draw with external painters */
184 };
185
186 #endif
187