1 #ifndef RS_GRAPHICVIEW_H
2 #define RS_GRAPHICVIEW_H
7 #include "rs_blocklist.h"
9 #include "rs_linetypepattern.h"
10 #include "rs_commandevent.h"
11 #include "rs_entitycontainer.h"
13 class RS_ActionInterface;
15 class RS_EventHandler;
20 * This class is a common GUI interface for the graphic viewer
21 * widget which has to be implementet by real GUI classes such
22 * as the Qt graphical view.
24 * Note that this is just an interface used as a slot to
25 * communicate with the qcadlib from a GUI level.
31 virtual ~RS_GraphicView();
35 Drawing * getGraphic();
36 void setDrawingMode(RS2::DrawingMode m);
37 RS2::DrawingMode getDrawingMode();
38 void setDeleteMode(bool m);
41 /** This virtual method must be overwritten to return
42 the width of the widget the graphic is shown in */
43 virtual int getWidth() = 0;
44 /** This virtual method must be overwritten to return
45 the height of the widget the graphic is shown in */
46 virtual int getHeight() = 0;
47 /** This virtual method must be overwritten to redraw
49 virtual void redraw() = 0;
50 /** This virtual method must be overwritten and is then
51 called whenever the view changed */
52 virtual void adjustOffsetControls();
53 /** This virtual method must be overwritten and is then
54 called whenever the view changed */
55 virtual void adjustZoomControls();
57 * Sets an external painter device.
59 virtual void setPainter(PaintInterface * p);
60 // virtual void setPainter(RS_Painter * p);
61 /** This virtual method must be overwritten and must return
62 the painter device for the buffer of this widget */
63 virtual PaintInterface * createPainter() = 0;
64 // virtual RS_Painter * createPainter() = 0;
66 * This virtual method must be overwritten and must return
67 * the direct painter device for this widget
69 virtual PaintInterface * createDirectPainter() = 0;
70 // virtual RS_Painter * createDirectPainter() = 0;
72 * This virtual method must be overwritten and must destroy
73 * the painter device and point 'painter' to NULL. If the painter
74 * is static during the whole life of the application, it might
77 virtual void destroyPainter() = 0;
79 virtual void setBackground(const RS_Color & bg);
80 RS_Color getBackground();
81 RS_Color getForeground();
82 void setGridColor(const RS_Color & c);
83 void setMetaGridColor(const RS_Color & c);
84 void setSelectedColor(const RS_Color & c);
85 void setHighlightedColor(const RS_Color & c);
86 virtual void setMouseCursor(RS2::CursorType /*c*/);
87 void setContainer(RS_EntityContainer * container);
88 RS_EntityContainer * getContainer();
89 void setFactor(double f);
90 void setFactorX(double f);
91 void setFactorY(double f);
93 void setOffset(int ox, int oy);
94 void setOffsetX(int ox);
95 void setOffsetY(int oy);
100 void centerX(double x);
101 void centerY(double y);
102 virtual void updateView();
103 void setBorders(int left, int top, int right, int bottom);
106 int getBorderRight();
107 int getBorderBottom();
108 void disableUpdate();
110 bool isUpdateEnabled();
111 void freezeZoom(bool freeze);
114 void setDefaultAction(RS_ActionInterface * action);
115 RS_ActionInterface * getDefaultAction();
116 void setCurrentAction(RS_ActionInterface * action);
117 RS_ActionInterface * getCurrentAction();
119 void killSelectActions();
120 void killAllActions();
123 * Must be overwritten to emulate a mouse move event with
124 * the last known mouse position.
128 virtual void emulateMouseMoveEvent() = 0;
133 void mousePressEvent(QMouseEvent * e);
134 void mouseReleaseEvent(QMouseEvent * e);
135 void mouseMoveEvent(QMouseEvent * e);
136 void mouseLeaveEvent();
137 void mouseEnterEvent();
138 void keyPressEvent(QKeyEvent * e);
139 void keyReleaseEvent(QKeyEvent * e);
140 void commandEvent(RS_CommandEvent * e);
141 void enableCoordinateInput();
142 void disableCoordinateInput();
144 virtual void zoomIn(double f = 1.5, const Vector & center = Vector(false));
145 virtual void zoomInX(double f = 1.5);
146 virtual void zoomInY(double f = 1.5);
147 virtual void zoomOut(double f = 1.5, const Vector & center = Vector(false));
148 virtual void zoomOutX(double f = 1.5);
149 virtual void zoomOutY(double f = 1.5);
150 virtual void zoomAuto(bool axis = true, bool keepAspectRatio = true);
151 virtual void zoomAutoY(bool axis = true);
152 virtual void zoomPrevious();
153 virtual void saveView();
154 virtual void restoreView();
155 virtual void zoomWindow(Vector v1, Vector v2, bool keepAspectRatio = true);
156 //virtual void zoomPan(Vector v1);
157 virtual void zoomPan(int dx, int dy);
158 virtual void zoomScroll(RS2::Direction direction);
159 virtual void zoomPage();
161 virtual void drawWindow(Vector v1, Vector v2);
162 virtual void drawIt();
163 virtual void deleteEntity(RS_Entity * e);
164 virtual void drawEntity(RS_Entity * e, double patternOffset = 0.0, bool db = false);
165 virtual void drawEntityPlain(RS_Entity * e, double patternOffset = 0.0);
166 virtual void setPenForEntity(RS_Entity * e);
169 void simulateEntity(RS_Entity * e, const RS_Pen & pen);
170 void drawLineSmooth(const Vector & p1, const Vector & p2, const RS_Pen & pen);
171 void drawArcSmooth(const Vector & center, double radius,
172 double a1, double a2, bool rev, const RS_Pen & pen);
173 void simulationDelay(bool step = false);
175 virtual RS_LineTypePattern * getPattern(RS2::LineType t);
177 virtual void drawAbsoluteZero();
178 virtual void drawRelativeZero();
179 virtual void drawPaper();
180 virtual void drawGrid();
181 virtual void drawMetaGrid();
182 virtual void updateGrid();
184 virtual void updateGridStatusWidget(const QString & /*text*/);
186 void setDefaultSnapMode(RS2::SnapMode sm);
187 RS2::SnapMode getDefaultSnapMode();
188 void setSnapRestriction(RS2::SnapRestriction sr);
189 RS2::SnapRestriction getSnapRestriction();
192 Vector toGui(Vector v);
193 double toGuiX(double x, bool * visible = NULL);
194 double toGuiY(double y);
195 double toGuiDX(double d);
196 double toGuiDY(double d);
198 Vector toGraph(Vector v);
199 Vector toGraph(int x, int y);
200 double toGraphX(int x);
201 double toGraphY(int y);
202 double toGraphDX(int d);
203 double toGraphDY(int d);
205 void lockRelativeZero(bool lock);
206 bool isRelativeZeroLocked();
207 Vector getRelativeZero();
208 void setRelativeZero(const Vector & pos);
209 void moveRelativeZero(const Vector & pos);
211 RS_EventHandler * getEventHandler();
212 void setPrintPreview(bool pv);
213 bool isPrintPreview();
214 void setPrinting(bool p);
217 void setSimulationSpeed(int s);
218 int getSimulationSpeed();
219 void setSimulationSmooth(bool s);
220 void setSimulationRapid(bool r);
221 bool getSimulationRapid();
223 //this is here because of crappy braindead infrastructure
224 void SetPreviewMode(bool mode = true);
225 void SetPreviewEntity(RS_Preview *);
226 void SetPreviewOffset(Vector);
227 void SetSnapperDraw(bool);
228 void SetSnapperVars(Vector snapSpot, Vector snapCoord, bool showCrosshairs);
231 RS_EntityContainer * container;
232 RS_EventHandler * eventHandler;
234 int mx; //!< Last known mouse cursor position
235 int my; //!< Last known mouse cursor position
237 // RS_Painter * painter;
238 PaintInterface * painter;
239 /** background color (any color) */
241 /** foreground color (black or white) */
245 /** meta grid color */
246 RS_Color metaGridColor;
247 /** selected color */
248 RS_Color selectedColor;
249 /** highlighted color */
250 RS_Color highlightedColor;
254 * Current default snap mode for this graphic view. Used for new
257 RS2::SnapMode defaultSnapMode;
259 * Current default snap restriction for this graphic view. Used for new
262 RS2::SnapRestriction defaultSnapRes;
264 RS2::DrawingMode drawingMode;
267 * Delete mode. If true, all drawing actions will delete in background color
271 //! If true, the simulation is currectly running
272 bool simulationRunning;
284 Vector previousFactor;
294 bool relativeZeroLocked;
295 //! Print preview flag
297 //! Active when printing only:
301 //! Simulation speed in percentage
303 //! If true, the entity is drawn slowly (pixel by pixel).
304 bool simulationSmooth;
305 //! If true, the way between entities is also shown.
306 bool simulationRapid;
307 //! Last position (for rapid move)
308 Vector simulationLast;
311 // crap to make painting with update() possible
312 RS_Preview * previewEntity;
314 Vector previewOffset;
318 bool showCrosshairs1;