]> Shamusworld >> Repos - architektonas/blob - src/base/rs_graphicview.h
Changed RS_Graphic to Drawing; this is less confusing as a drawing is
[architektonas] / src / base / rs_graphicview.h
1 #ifndef RS_GRAPHICVIEW_H
2 #define RS_GRAPHICVIEW_H
3
4 #include <stdarg.h>
5 #include <QtCore>
6 #include "rs.h"
7 #include "rs_blocklist.h"
8 #include "rs_color.h"
9 #include "rs_linetypepattern.h"
10 #include "rs_commandevent.h"
11 #include "rs_entitycontainer.h"
12
13 class RS_ActionInterface;
14 class RS_Grid;
15 class RS_EventHandler;
16 class RS_Preview;
17 class PaintInterface;
18
19 /**
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.
23  *
24  * Note that this is just an interface used as a slot to
25  * communicate with the qcadlib from a GUI level.
26  */
27 class RS_GraphicView
28 {
29 public:
30     RS_GraphicView();
31     virtual ~RS_GraphicView();
32
33         void cleanUp();
34
35     Drawing * getGraphic();
36     void setDrawingMode(RS2::DrawingMode m);
37     RS2::DrawingMode getDrawingMode();
38     void setDeleteMode(bool m);
39     bool getDeleteMode();
40
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
48       the widget. */
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();
56         /**
57          * Sets an external painter device.
58          */
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;
65     /**
66      * This virtual method must be overwritten and must return
67      *  the direct painter device for this widget
68      */
69     virtual PaintInterface * createDirectPainter() = 0;
70 //    virtual RS_Painter * createDirectPainter() = 0;
71     /**
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
75      * just do nothing.
76      */
77     virtual void destroyPainter() = 0;
78
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);
92     Vector getFactor();
93     void setOffset(int ox, int oy);
94     void setOffsetX(int ox);
95     void setOffsetY(int oy);
96     int getOffsetX();
97     int getOffsetY();
98     void centerOffsetX();
99     void centerOffsetY();
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);
104     int getBorderLeft();
105     int getBorderTop();
106     int getBorderRight();
107     int getBorderBottom();
108     void disableUpdate();
109     void enableUpdate();
110     bool isUpdateEnabled();
111     void freezeZoom(bool freeze);
112     bool isZoomFrozen();
113
114     void setDefaultAction(RS_ActionInterface * action);
115     RS_ActionInterface *  getDefaultAction();
116     void setCurrentAction(RS_ActionInterface * action);
117     RS_ActionInterface * getCurrentAction();
118
119     void killSelectActions();
120     void killAllActions();
121
122     /**
123      * Must be overwritten to emulate a mouse move event with
124      * the last known mouse position.
125      *
126      * @see mx, my
127      */
128     virtual void emulateMouseMoveEvent() = 0;
129
130     void back();
131     void enter();
132
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();
143
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();
160
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);
167
168     void simulateIt();
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);
174
175     virtual RS_LineTypePattern * getPattern(RS2::LineType t);
176
177     virtual void drawAbsoluteZero();
178     virtual void drawRelativeZero();
179     virtual void drawPaper();
180     virtual void drawGrid();
181     virtual void drawMetaGrid();
182     virtual void updateGrid();
183     RS_Grid * getGrid();
184         virtual void updateGridStatusWidget(const QString & /*text*/);
185
186     void setDefaultSnapMode(RS2::SnapMode sm);
187     RS2::SnapMode getDefaultSnapMode();
188     void setSnapRestriction(RS2::SnapRestriction sr);
189     RS2::SnapRestriction getSnapRestriction();
190     bool isGridOn();
191
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);
197
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);
204
205         void lockRelativeZero(bool lock);
206         bool isRelativeZeroLocked();
207         Vector getRelativeZero();
208         void setRelativeZero(const Vector & pos);
209         void moveRelativeZero(const Vector & pos);
210
211         RS_EventHandler * getEventHandler();
212         void setPrintPreview(bool pv);
213         bool isPrintPreview();
214         void setPrinting(bool p);
215         bool isPrinting();
216         bool isDraftMode();
217         void setSimulationSpeed(int s);
218         int getSimulationSpeed();
219         void setSimulationSmooth(bool s);
220         void setSimulationRapid(bool r);
221         bool getSimulationRapid();
222
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);
229
230 protected:
231     RS_EntityContainer * container;
232     RS_EventHandler * eventHandler;
233
234     int mx;   //!< Last known mouse cursor position
235     int my;   //!< Last known mouse cursor position
236
237 //    RS_Painter * painter;
238         PaintInterface * painter;
239     /** background color (any color) */
240     RS_Color background;
241     /** foreground color (black or white) */
242     RS_Color foreground;
243         /** grid color */
244     RS_Color gridColor;
245         /** meta grid color */
246         RS_Color metaGridColor;
247     /** selected color */
248     RS_Color selectedColor;
249     /** highlighted color */
250     RS_Color highlightedColor;
251     /** Grid */
252     RS_Grid * grid;
253     /**
254          * Current default snap mode for this graphic view. Used for new
255          * actions.
256          */
257     RS2::SnapMode defaultSnapMode;
258     /**
259          * Current default snap restriction for this graphic view. Used for new
260          * actions.
261          */
262     RS2::SnapRestriction defaultSnapRes;
263
264     RS2::DrawingMode drawingMode;
265
266         /**
267          * Delete mode. If true, all drawing actions will delete in background color
268          * instead.
269          */
270         bool deleteMode;
271         //! If true, the simulation is currectly running
272         bool simulationRunning;
273
274 private:
275     int updateEnabled;
276     bool zoomFrozen;
277     //bool gridVisible;
278         bool draftMode;
279
280     Vector factor;
281         int offsetX;
282     int offsetY;
283
284         Vector previousFactor;
285         int previousOffsetX;
286     int previousOffsetY;
287
288     int borderLeft;
289     int borderTop;
290     int borderRight;
291     int borderBottom;
292
293         Vector relativeZero;
294         bool relativeZeroLocked;
295         //! Print preview flag
296         bool printPreview;
297         //! Active when printing only:
298         bool printing;
299         //int drawRecursion;
300
301         //! Simulation speed in percentage
302         int simulationSpeed;
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;
309
310 protected:
311         // crap to make painting with update() possible
312         RS_Preview * previewEntity;
313         bool previewMode;
314         Vector previewOffset;
315         bool snapperDraw;
316         Vector snapSpot1;
317         Vector snapCoord1;
318         bool showCrosshairs1;
319 };
320
321 #endif