1 // File : OCCViewer_ViewPort.h
2 // Created : Wed Mar 20 10:41:50 2002
3 // Author : Nicolas REJNERI
6 // Copyright : Open CASCADE 2002
10 #ifndef OCCViewer_ViewPort_H
11 #define OCCViewer_ViewPort_H
14 #include "QAD_Popup.h"
23 class QAD_EXPORT OCCViewer_ViewPort: public QWidget,
24 public QAD_PopupClientServer
32 static QCursor* defCursor;
33 static QCursor* handCursor;
34 static QCursor* panCursor;
35 static QCursor* zoomCursor;
36 static QCursor* rotCursor;
37 static QCursor* glPanCursor;
53 static void createCursors();
54 static void destroyCursors();
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);
69 /* Transformation selected but not started yet */
70 bool transformRequested() const { return ( myOperation != NOTHING ); }
71 void setTransformRequested ( OperationType op );
73 /* Transformation is selected and already started */
74 bool transformInProcess() const { return myEventStarted; }
75 void setTransformInProcess( bool bOn ) { myEventStarted = bOn; }
78 OCCViewer_ViewPort( QWidget* parent );
79 ~OCCViewer_ViewPort();
81 /* Draw mode management */
82 void enableDrawMode( bool bEnable );
83 bool enableDrawMode() const;
85 /* Cursors management */
86 void setDefaultCursorOn();
87 void setHandCursorOn();
88 void setPanCursorOn();
89 void setZoomCursorOn();
90 void setRotCursorOn();
91 void setGlPanCursorOn();
94 bool hasWindow() const;
96 void redrawPainters();
97 void update(int x, int y, int w, int h);
99 void setOriginalView( OCCViewer_ViewPort* view, const QRect& magnify );
100 OCCViewer_ViewPort* getOriginalView() const;
101 const QRect& getMagnifyRect() const;
102 const QRect& getSelectionRect() const;
104 /* View transformations */
105 virtual void activateZoom();
106 virtual void activatePanning();
107 virtual void activateRotation();
108 virtual void activateWindowFit();
109 virtual void activateGlobalPanning();
111 virtual void fitAll( bool withZ = true ) = 0;
112 virtual void reset() = 0;
114 virtual QColor backgroundColor() const;
115 virtual void setBackgroundColor( const QColor& color) = 0;
118 virtual void paintEvent(QPaintEvent *);
119 virtual void resizeEvent(QResizeEvent *);
121 virtual void mouseMoveEvent(QMouseEvent *);
122 virtual void mouseReleaseEvent(QMouseEvent *);
123 virtual void mousePressEvent(QMouseEvent *);
124 virtual void mouseDoubleClickEvent(QMouseEvent *);
126 virtual void keyPressEvent(QKeyEvent *);
127 virtual void keyReleaseEvent(QKeyEvent *);
129 virtual void focusInEvent(QFocusEvent *event);
130 virtual void focusOutEvent(QFocusEvent *event);
133 void vpTransformationStarted (OCCViewer_ViewPort::OperationType type);
134 void vpTransformationFinished (OCCViewer_ViewPort::OperationType type);
136 void vpMousePress (QMouseEvent*);
137 void vpMouseRelease (QMouseEvent*);
138 void vpMouseMove (QMouseEvent*);
139 void vpMouseDoubleClick (QMouseEvent*);
141 void vpKeyPress (QKeyEvent*);
142 void vpKeyRelease (QKeyEvent*);
144 void vpFocusOut (QFocusEvent*);
145 void vpFocusIn (QFocusEvent*);
147 void vpPaint (QPaintEvent*);
148 void vpDrawExternal (QPainter* painter);
151 virtual void onChangeBackgroundColor() = 0;
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;
165 OCCViewer_ViewPort* myOriginalViewport;
166 OperationType myOperation;
171 bool myDrawRect; /* set when a rect is used for selection or magnify */
173 /* Mouse coordinates */
181 bool myEnableDrawMode;
182 bool myEventStarted; /* set when transformation is in process */
183 bool myPaintersRedrawing; /* set to draw with external painters */