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);
61 // We're removing this crap...
63 /** This virtual method must be overwritten and must return
64 the painter device for the buffer of this widget */
65 // virtual PaintInterface * createPainter() = 0;
67 * This virtual method must be overwritten and must return
68 * the direct painter device for this widget
70 // virtual PaintInterface * 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;
80 virtual void setBackground(const RS_Color & bg);
81 RS_Color getBackground();
82 RS_Color getForeground();
83 void setGridColor(const RS_Color & c);
84 void setMetaGridColor(const RS_Color & c);
85 void setSelectedColor(const RS_Color & c);
86 void setHighlightedColor(const RS_Color & c);
87 virtual void setMouseCursor(RS2::CursorType /*c*/);
88 void setContainer(RS_EntityContainer * container);
89 RS_EntityContainer * getContainer();
90 void setFactor(double f);
91 void setFactorX(double f);
92 void setFactorY(double f);
94 void setOffset(int ox, int oy);
95 void setOffsetX(int ox);
96 void setOffsetY(int oy);
100 void centerOffsetY();
101 void centerX(double x);
102 void centerY(double y);
103 virtual void updateView();
104 void setBorders(int left, int top, int right, int bottom);
107 int getBorderRight();
108 int getBorderBottom();
109 void disableUpdate();
111 bool isUpdateEnabled();
112 void freezeZoom(bool freeze);
115 void setDefaultAction(RS_ActionInterface * action);
116 RS_ActionInterface * getDefaultAction();
117 void setCurrentAction(RS_ActionInterface * action);
118 RS_ActionInterface * getCurrentAction();
120 void killSelectActions();
121 void killAllActions();
124 * Must be overwritten to emulate a mouse move event with
125 * the last known mouse position.
129 virtual void emulateMouseMoveEvent() = 0;
134 void mousePressEvent(QMouseEvent * e);
135 void mouseReleaseEvent(QMouseEvent * e);
136 void mouseMoveEvent(QMouseEvent * e);
137 void mouseLeaveEvent();
138 void mouseEnterEvent();
139 void keyPressEvent(QKeyEvent * e);
140 void keyReleaseEvent(QKeyEvent * e);
141 void commandEvent(RS_CommandEvent * e);
142 void enableCoordinateInput();
143 void disableCoordinateInput();
145 virtual void zoomIn(double f = 1.5, const Vector & center = Vector(false));
146 virtual void zoomInX(double f = 1.5);
147 virtual void zoomInY(double f = 1.5);
148 virtual void zoomOut(double f = 1.5, const Vector & center = Vector(false));
149 virtual void zoomOutX(double f = 1.5);
150 virtual void zoomOutY(double f = 1.5);
151 virtual void zoomAuto(bool axis = true, bool keepAspectRatio = true);
152 virtual void zoomAutoY(bool axis = true);
153 virtual void zoomPrevious();
154 virtual void saveView();
155 virtual void restoreView();
156 virtual void zoomWindow(Vector v1, Vector v2, bool keepAspectRatio = true);
157 //virtual void zoomPan(Vector v1);
158 virtual void zoomPan(int dx, int dy);
159 virtual void zoomScroll(RS2::Direction direction);
160 virtual void zoomPage();
162 virtual void drawWindow(Vector v1, Vector v2);
163 virtual void drawIt();
164 virtual void deleteEntity(RS_Entity * e);
165 virtual void drawEntity(RS_Entity * e, double patternOffset = 0.0, bool db = false);
166 virtual void drawEntityPlain(RS_Entity * e, double patternOffset = 0.0);
167 virtual void setPenForEntity(RS_Entity * e);
170 void simulateEntity(RS_Entity * e, const RS_Pen & pen);
171 void drawLineSmooth(const Vector & p1, const Vector & p2, const RS_Pen & pen);
172 void drawArcSmooth(const Vector & center, double radius,
173 double a1, double a2, bool rev, const RS_Pen & pen);
174 void simulationDelay(bool step = false);
176 virtual RS_LineTypePattern * getPattern(RS2::LineType t);
178 virtual void drawAbsoluteZero();
179 virtual void drawRelativeZero();
180 virtual void drawPaper();
181 virtual void drawGrid();
182 virtual void drawMetaGrid();
183 virtual void updateGrid();
185 virtual void updateGridStatusWidget(const QString & /*text*/);
187 void setDefaultSnapMode(RS2::SnapMode sm);
188 RS2::SnapMode getDefaultSnapMode();
189 void setSnapRestriction(RS2::SnapRestriction sr);
190 RS2::SnapRestriction getSnapRestriction();
193 Vector toGui(Vector v);
194 double toGuiX(double x, bool * visible = NULL);
195 double toGuiY(double y);
196 double toGuiDX(double d);
197 double toGuiDY(double d);
199 Vector toGraph(Vector v);
200 Vector toGraph(int x, int y);
201 double toGraphX(int x);
202 double toGraphY(int y);
203 double toGraphDX(int d);
204 double toGraphDY(int d);
206 void lockRelativeZero(bool lock);
207 bool isRelativeZeroLocked();
208 Vector getRelativeZero();
209 void setRelativeZero(const Vector & pos);
210 void moveRelativeZero(const Vector & pos);
212 RS_EventHandler * getEventHandler();
213 void setPrintPreview(bool pv);
214 bool isPrintPreview();
215 void setPrinting(bool p);
218 void setSimulationSpeed(int s);
219 int getSimulationSpeed();
220 void setSimulationSmooth(bool s);
221 void setSimulationRapid(bool r);
222 bool getSimulationRapid();
224 //this is here because of crappy braindead infrastructure
225 void SetPreviewMode(bool mode = true);
226 void SetPreviewEntity(RS_Preview *);
227 void SetPreviewOffset(Vector);
228 void SetSnapperDraw(bool);
229 void SetSnapperVars(Vector snapSpot, Vector snapCoord, bool showCrosshairs);
232 RS_EntityContainer * container;
233 RS_EventHandler * eventHandler;
235 int mx; //!< Last known mouse cursor position
236 int my; //!< Last known mouse cursor position
238 // RS_Painter * painter;
239 PaintInterface * painter;
240 /** background color (any color) */
242 /** foreground color (black or white) */
246 /** meta grid color */
247 RS_Color metaGridColor;
248 /** selected color */
249 RS_Color selectedColor;
250 /** highlighted color */
251 RS_Color highlightedColor;
255 * Current default snap mode for this graphic view. Used for new
258 RS2::SnapMode defaultSnapMode;
260 * Current default snap restriction for this graphic view. Used for new
263 RS2::SnapRestriction defaultSnapRes;
265 RS2::DrawingMode drawingMode;
268 * Delete mode. If true, all drawing actions will delete in background color
272 //! If true, the simulation is currectly running
273 bool simulationRunning;
285 Vector previousFactor;
295 bool relativeZeroLocked;
296 //! Print preview flag
298 //! Active when printing only:
302 //! Simulation speed in percentage
304 //! If true, the entity is drawn slowly (pixel by pixel).
305 bool simulationSmooth;
306 //! If true, the way between entities is also shown.
307 bool simulationRapid;
308 //! Last position (for rapid move)
309 Vector simulationLast;
312 // crap to make painting with update() possible
313 RS_Preview * previewEntity;
315 Vector previewOffset;
319 bool showCrosshairs1;