]> Shamusworld >> Repos - architektonas/blob - src/base/rs_graphicview.h
Removed more QC_ madness...
[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
61 // We're removing this crap...
62 #if 0
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;
66                 /**
67                  * This virtual method must be overwritten and must return
68                  *  the direct painter device for this widget
69                  */
70 //              virtual PaintInterface * 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 #endif
79
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);
93                 Vector getFactor();
94                 void setOffset(int ox, int oy);
95                 void setOffsetX(int ox);
96                 void setOffsetY(int oy);
97                 int getOffsetX();
98                 int getOffsetY();
99                 void centerOffsetX();
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);
105                 int getBorderLeft();
106                 int getBorderTop();
107                 int getBorderRight();
108                 int getBorderBottom();
109                 void disableUpdate();
110                 void enableUpdate();
111                 bool isUpdateEnabled();
112                 void freezeZoom(bool freeze);
113                 bool isZoomFrozen();
114
115                 void setDefaultAction(RS_ActionInterface * action);
116                 RS_ActionInterface *  getDefaultAction();
117                 void setCurrentAction(RS_ActionInterface * action);
118                 RS_ActionInterface * getCurrentAction();
119
120                 void killSelectActions();
121                 void killAllActions();
122
123                 /**
124                  * Must be overwritten to emulate a mouse move event with
125                  * the last known mouse position.
126                  *
127                  * @see mx, my
128                  */
129                 virtual void emulateMouseMoveEvent() = 0;
130
131                 void back();
132                 void enter();
133
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();
144
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();
161
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);
168
169                 void simulateIt();
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);
175
176                 virtual RS_LineTypePattern * getPattern(RS2::LineType t);
177
178                 virtual void drawAbsoluteZero();
179                 virtual void drawRelativeZero();
180                 virtual void drawPaper();
181                 virtual void drawGrid();
182                 virtual void drawMetaGrid();
183                 virtual void updateGrid();
184                 RS_Grid * getGrid();
185                 virtual void updateGridStatusWidget(const QString & /*text*/);
186
187                 void setDefaultSnapMode(RS2::SnapMode sm);
188                 RS2::SnapMode getDefaultSnapMode();
189                 void setSnapRestriction(RS2::SnapRestriction sr);
190                 RS2::SnapRestriction getSnapRestriction();
191                 bool isGridOn();
192
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);
198
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);
205
206                 void lockRelativeZero(bool lock);
207                 bool isRelativeZeroLocked();
208                 Vector getRelativeZero();
209                 void setRelativeZero(const Vector & pos);
210                 void moveRelativeZero(const Vector & pos);
211
212                 RS_EventHandler * getEventHandler();
213                 void setPrintPreview(bool pv);
214                 bool isPrintPreview();
215                 void setPrinting(bool p);
216                 bool isPrinting();
217                 bool isDraftMode();
218                 void setSimulationSpeed(int s);
219                 int getSimulationSpeed();
220                 void setSimulationSmooth(bool s);
221                 void setSimulationRapid(bool r);
222                 bool getSimulationRapid();
223
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);
230
231         protected:
232                 RS_EntityContainer * container;
233                 RS_EventHandler * eventHandler;
234
235                 int mx;   //!< Last known mouse cursor position
236                 int my;   //!< Last known mouse cursor position
237
238         //    RS_Painter * painter;
239                 PaintInterface * painter;
240                 /** background color (any color) */
241                 RS_Color background;
242                 /** foreground color (black or white) */
243                 RS_Color foreground;
244                 /** grid color */
245                 RS_Color gridColor;
246                 /** meta grid color */
247                 RS_Color metaGridColor;
248                 /** selected color */
249                 RS_Color selectedColor;
250                 /** highlighted color */
251                 RS_Color highlightedColor;
252                 /** Grid */
253                 RS_Grid * grid;
254                 /**
255                 * Current default snap mode for this graphic view. Used for new
256                 * actions.
257                 */
258                 RS2::SnapMode defaultSnapMode;
259                 /**
260                 * Current default snap restriction for this graphic view. Used for new
261                 * actions.
262                 */
263                 RS2::SnapRestriction defaultSnapRes;
264
265                 RS2::DrawingMode drawingMode;
266
267                 /**
268                 * Delete mode. If true, all drawing actions will delete in background color
269                 * instead.
270                 */
271                 bool deleteMode;
272                 //! If true, the simulation is currectly running
273                 bool simulationRunning;
274
275         private:
276                 int updateEnabled;
277                 bool zoomFrozen;
278                 //bool gridVisible;
279                 bool draftMode;
280
281                 Vector factor;
282                 int offsetX;
283                 int offsetY;
284
285                 Vector previousFactor;
286                 int previousOffsetX;
287                 int previousOffsetY;
288
289                 int borderLeft;
290                 int borderTop;
291                 int borderRight;
292                 int borderBottom;
293
294                 Vector relativeZero;
295                 bool relativeZeroLocked;
296                 //! Print preview flag
297                 bool printPreview;
298                 //! Active when printing only:
299                 bool printing;
300                 //int drawRecursion;
301
302                 //! Simulation speed in percentage
303                 int simulationSpeed;
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;
310
311         protected:
312                 // crap to make painting with update() possible
313                 RS_Preview * previewEntity;
314                 bool previewMode;
315                 Vector previewOffset;
316                 bool snapperDraw;
317                 Vector snapSpot1;
318                 Vector snapCoord1;
319                 bool showCrosshairs1;
320 };
321
322 #endif