1 #ifndef __GRAPHICVIEW_H__
2 #define __GRAPHICVIEW_H__
10 class ActionInterface;
15 class EntityContainer;
18 class LineTypePattern;
29 Drawing * GetDrawing();
30 void setDrawingMode(RS2::DrawingMode m);
31 RS2::DrawingMode getDrawingMode();
32 void setDeleteMode(bool m);
35 /** This virtual method must be overwritten to return
36 the width of the widget the graphic is shown in */
37 virtual int getWidth() = 0;
38 /** This virtual method must be overwritten to return
39 the height of the widget the graphic is shown in */
40 virtual int getHeight() = 0;
41 /** This virtual method must be overwritten to redraw
43 virtual void redraw() = 0;
45 /** This virtual method must be overwritten and is then
46 called whenever the view changed */
47 virtual void adjustOffsetControls();
48 /** This virtual method must be overwritten and is then
49 called whenever the view changed */
50 virtual void adjustZoomControls();
52 virtual void setBackground(const Color & bg);
53 Color getBackground();
54 Color getForeground();
55 void setGridColor(const Color & c);
56 void setMetaGridColor(const Color & c);
57 void setSelectedColor(const Color & c);
58 void setHighlightedColor(const Color & c);
59 virtual void setMouseCursor(RS2::CursorType /*c*/);
60 void setContainer(EntityContainer * container);
61 EntityContainer * getContainer();
62 void setFactor(double f);
63 void setFactorX(double f);
64 void setFactorY(double f);
66 void setOffset(int ox, int oy);
67 void setOffsetX(int ox);
68 void setOffsetY(int oy);
73 void centerX(double x);
74 void centerY(double y);
75 virtual void updateView();
76 void setBorders(int left, int top, int right, int bottom);
80 int getBorderBottom();
83 bool isUpdateEnabled();
84 void freezeZoom(bool freeze);
87 void setDefaultAction(ActionInterface * action);
88 ActionInterface * getDefaultAction();
89 void setCurrentAction(ActionInterface * action);
90 ActionInterface * getCurrentAction();
92 void killSelectActions();
93 void killAllActions();
96 * Must be overridden to emulate a mouse move event with the last known
101 virtual void emulateMouseMoveEvent() = 0;
106 void _mousePressEvent(QMouseEvent * e);
107 void _mouseReleaseEvent(QMouseEvent * e);
108 void _mouseMoveEvent(QMouseEvent * e);
109 void _mouseLeaveEvent();
110 void _mouseEnterEvent();
111 void _keyPressEvent(QKeyEvent * e);
112 void _keyReleaseEvent(QKeyEvent * e);
113 void commandEvent(CommandEvent * e);
114 void enableCoordinateInput();
115 void disableCoordinateInput();
117 virtual void zoomIn(double f = 1.5, const Vector & center = Vector(false));
118 virtual void zoomInX(double f = 1.5);
119 virtual void zoomInY(double f = 1.5);
120 virtual void zoomOut(double f = 1.5, const Vector & center = Vector(false));
121 virtual void zoomOutX(double f = 1.5);
122 virtual void zoomOutY(double f = 1.5);
123 virtual void zoomAuto(bool axis = true, bool keepAspectRatio = true);
124 virtual void zoomAutoY(bool axis = true);
125 virtual void zoomPrevious();
126 virtual void saveView();
127 virtual void restoreView();
128 virtual void zoomWindow(Vector v1, Vector v2, bool keepAspectRatio = true);
129 //virtual void zoomPan(Vector v1);
130 virtual void zoomPan(int dx, int dy);
131 virtual void zoomScroll(RS2::Direction direction);
132 virtual void zoomPage();
134 virtual void drawWindow(Vector v1, Vector v2);
135 virtual void drawIt();
136 virtual void drawEntity(Entity * e, double patternOffset = 0.0, bool db = false);
137 virtual void drawEntityPlain(Entity * e, double patternOffset = 0.0);
138 virtual void setPenForEntity(Entity * e);
141 void simulateEntity(Entity * e, const Pen & pen);
142 void drawLineSmooth(const Vector & p1, const Vector & p2, const Pen & pen);
143 void drawArcSmooth(const Vector & center, double radius,
144 double a1, double a2, bool rev, const Pen & pen);
145 void simulationDelay(bool step = false);
147 virtual LineTypePattern * getPattern(RS2::LineType t);
149 virtual void drawAbsoluteZero();
150 virtual void drawRelativeZero();
151 virtual void drawPaper();
152 virtual void drawGrid();
153 virtual void drawMetaGrid();
154 virtual void updateGrid();
156 virtual void updateGridStatusWidget(const QString & /*text*/);
158 void setDefaultSnapMode(RS2::SnapMode sm);
159 RS2::SnapMode getDefaultSnapMode();
160 void setSnapRestriction(RS2::SnapRestriction sr);
161 RS2::SnapRestriction getSnapRestriction();
165 What to do about this shiatsu? This stuff is used in the snapper rendering
166 code... Maybe move all the snapper rendering back into this class???
167 Seems to make sense, though it kinda blows encapsulation. But it's already
168 blown by the snapper class having to use these functions in the first place!
172 The snapper as a separate class makes sense, since it has several functions
173 for finding various snapping points. But what about rendering???
175 Having this class derive from that one *might* make sense... *Maybe*. Not sure.
178 Vector toGui(Vector v);
179 double toGuiX(double x, bool * visible = NULL);
180 double toGuiY(double y);
181 double toGuiDX(double d);
182 double toGuiDY(double d);
184 Vector toGraph(Vector v);
185 Vector toGraph(int x, int y);
186 double toGraphX(int x);
187 double toGraphY(int y);
188 double toGraphDX(int d);
189 double toGraphDY(int d);
191 void lockRelativeZero(bool lock);
192 bool isRelativeZeroLocked();
193 Vector getRelativeZero();
194 void setRelativeZero(const Vector & pos);
195 void moveRelativeZero(const Vector & pos);
197 EventHandler * getEventHandler();
198 void setPrintPreview(bool pv);
199 bool isPrintPreview();
200 void setPrinting(bool p);
203 void setSimulationSpeed(int s);
204 int getSimulationSpeed();
205 void setSimulationSmooth(bool s);
206 void setSimulationRapid(bool r);
207 bool getSimulationRapid();
209 Entity * CatchEntity(const Vector &, RS2::ResolveLevel level = RS2::ResolveNone);
210 Entity * CatchEntity(QMouseEvent *, RS2::ResolveLevel level = RS2::ResolveNone);
211 Entity * GetSnapperEntity(void);
212 Vector SnapPoint(QMouseEvent *);
213 Vector SnapGrid(Vector);
214 void DrawSnapper(PaintInterface *);
215 void SetSnapperVisible(bool visibility = true);
216 bool SnapperVisible(void);
219 EntityContainer * container;
220 EventHandler * eventHandler;
221 int mx; //!< Last known mouse cursor position
222 int my; //!< Last known mouse cursor position
223 PaintInterface * painter;
224 Color background; //! background color (any color)
225 Color foreground; //! foreground color (black or white)
226 Color gridColor; //! grid color
227 Color metaGridColor; //! meta grid color
228 Color selectedColor; //! selected color
229 Color highlightedColor; //! highlighted color
230 Grid * grid; //! Grid
232 * Current default snap mode for this graphic view. Used for new
235 RS2::SnapMode defaultSnapMode;
237 * Current default snap restriction for this graphic view. Used for new
240 RS2::SnapRestriction defaultSnapRes;
241 RS2::DrawingMode drawingMode;
243 * Delete mode. If true, all drawing actions will delete in background color
247 bool simulationRunning; //! If true, the simulation is currectly running
248 double snapDistance; //! Manually set snap distance
249 Entity * snapEntity; //! Entity to snap to (if any)
252 bool snapperVisible; //! Snapper visibility
254 bool showCrosshairs; //! Snapper crosshair visibility
263 Vector previousFactor;
271 bool relativeZeroLocked;
272 bool printPreview; //! Print preview flag
273 bool printing; //! Active when printing only:
274 int simulationSpeed; //! Simulation speed in percentage
275 bool simulationSmooth; //! If true, the entity is drawn slowly (pixel by pixel).
276 bool simulationRapid; //! If true, the way between entities is also shown.
277 Vector simulationLast; //! Last position (for rapid move)
280 // We use this here instead of deriving ActionInterface from it because
281 // this makes more sense.
290 QScrollBar * hScrollBar; //! Horizontal scrollbar.
291 QScrollBar * vScrollBar; //! Vertical scrollbar.
292 QLabel * gridStatus; //! Label for grid spacing.
293 QCursor * curCad; //! CAD mouse cursor
294 QCursor * curDel; //! Delete mouse cursor
295 QCursor * curSelect; //! Select mouse cursor
296 QCursor * curMagnifier; //! Magnifying glass mouse cursor
297 QCursor * curHand; //! Hand mouse cursor
299 //QC was merged with QG
302 #endif // __GRAPHICVIEW_H__
305 class QG_GraphicView: public QWidget, public RS_GraphicView
310 QG_GraphicView(QWidget * parent = 0, const char * name = 0, Qt::WindowFlags f = 0);
311 virtual ~QG_GraphicView();
313 virtual int getWidth();
314 virtual int getHeight();
315 virtual void redraw();
316 virtual void adjustOffsetControls();
317 virtual void adjustZoomControls();
318 virtual void setBackground(const Color & bg);
319 virtual void setMouseCursor(RS2::CursorType c);
320 virtual void updateGridStatusWidget(const QString & text);
323 virtual void emulateMouseMoveEvent();
324 virtual void mousePressEvent(QMouseEvent * e);
325 virtual void mouseReleaseEvent(QMouseEvent * e);
326 virtual void mouseMoveEvent(QMouseEvent * e);
327 virtual void tabletEvent(QTabletEvent * e);
328 virtual void leaveEvent(QEvent *);
329 virtual void enterEvent(QEvent *);
330 virtual void focusInEvent(QFocusEvent *);
331 virtual void focusOutEvent(QFocusEvent *);
332 virtual void wheelEvent(QWheelEvent * e);
333 virtual void keyPressEvent(QKeyEvent * e);
334 virtual void keyReleaseEvent(QKeyEvent * e);
336 void paintEvent(QPaintEvent *);
337 virtual void resizeEvent(QResizeEvent * e);
340 void slotHScrolled(int value);
341 void slotVScrolled(int value);