1 #ifndef __GRAPHICVIEW_H__
2 #define __GRAPHICVIEW_H__
7 #include "rs_preview.h"
8 #include "rs_snapper.h"
13 class RS_EntityContainer;
14 class RS_ActionInterface;
16 class RS_LineTypePattern;
17 class RS_CommandEvent;
22 class RS_EventHandler;
32 Drawing * getGraphic();
33 void setDrawingMode(RS2::DrawingMode m);
34 RS2::DrawingMode getDrawingMode();
35 void setDeleteMode(bool m);
38 /** This virtual method must be overwritten to return
39 the width of the widget the graphic is shown in */
40 virtual int getWidth() = 0;
41 /** This virtual method must be overwritten to return
42 the height of the widget the graphic is shown in */
43 virtual int getHeight() = 0;
44 /** This virtual method must be overwritten to redraw
46 virtual void redraw() = 0;
48 /** This virtual method must be overwritten and is then
49 called whenever the view changed */
50 virtual void adjustOffsetControls();
51 /** This virtual method must be overwritten and is then
52 called whenever the view changed */
53 virtual void adjustZoomControls();
55 virtual void setBackground(const RS_Color & bg);
56 RS_Color getBackground();
57 RS_Color getForeground();
58 void setGridColor(const RS_Color & c);
59 void setMetaGridColor(const RS_Color & c);
60 void setSelectedColor(const RS_Color & c);
61 void setHighlightedColor(const RS_Color & c);
62 virtual void setMouseCursor(RS2::CursorType /*c*/);
63 void setContainer(RS_EntityContainer * container);
64 RS_EntityContainer * getContainer();
65 void setFactor(double f);
66 void setFactorX(double f);
67 void setFactorY(double f);
69 void setOffset(int ox, int oy);
70 void setOffsetX(int ox);
71 void setOffsetY(int oy);
76 void centerX(double x);
77 void centerY(double y);
78 virtual void updateView();
79 void setBorders(int left, int top, int right, int bottom);
83 int getBorderBottom();
86 bool isUpdateEnabled();
87 void freezeZoom(bool freeze);
90 void setDefaultAction(RS_ActionInterface * action);
91 RS_ActionInterface * getDefaultAction();
92 void setCurrentAction(RS_ActionInterface * action);
93 RS_ActionInterface * getCurrentAction();
95 void killSelectActions();
96 void killAllActions();
99 * Must be overwritten to emulate a mouse move event with
100 * the last known mouse position.
104 virtual void emulateMouseMoveEvent() = 0;
109 void mousePressEvent(QMouseEvent * e);
110 void mouseReleaseEvent(QMouseEvent * e);
111 void mouseMoveEvent(QMouseEvent * e);
112 void mouseLeaveEvent();
113 void mouseEnterEvent();
114 void keyPressEvent(QKeyEvent * e);
115 void keyReleaseEvent(QKeyEvent * e);
116 void commandEvent(RS_CommandEvent * e);
117 void enableCoordinateInput();
118 void disableCoordinateInput();
120 virtual void zoomIn(double f = 1.5, const Vector & center = Vector(false));
121 virtual void zoomInX(double f = 1.5);
122 virtual void zoomInY(double f = 1.5);
123 virtual void zoomOut(double f = 1.5, const Vector & center = Vector(false));
124 virtual void zoomOutX(double f = 1.5);
125 virtual void zoomOutY(double f = 1.5);
126 virtual void zoomAuto(bool axis = true, bool keepAspectRatio = true);
127 virtual void zoomAutoY(bool axis = true);
128 virtual void zoomPrevious();
129 virtual void saveView();
130 virtual void restoreView();
131 virtual void zoomWindow(Vector v1, Vector v2, bool keepAspectRatio = true);
132 //virtual void zoomPan(Vector v1);
133 virtual void zoomPan(int dx, int dy);
134 virtual void zoomScroll(RS2::Direction direction);
135 virtual void zoomPage();
137 virtual void drawWindow(Vector v1, Vector v2);
138 virtual void drawIt();
139 virtual void deleteEntity(RS_Entity * e);
140 virtual void drawEntity(RS_Entity * e, double patternOffset = 0.0, bool db = false);
141 virtual void drawEntityPlain(RS_Entity * e, double patternOffset = 0.0);
142 virtual void setPenForEntity(RS_Entity * e);
145 void simulateEntity(RS_Entity * e, const RS_Pen & pen);
146 void drawLineSmooth(const Vector & p1, const Vector & p2, const RS_Pen & pen);
147 void drawArcSmooth(const Vector & center, double radius,
148 double a1, double a2, bool rev, const RS_Pen & pen);
149 void simulationDelay(bool step = false);
151 virtual RS_LineTypePattern * getPattern(RS2::LineType t);
153 virtual void drawAbsoluteZero();
154 virtual void drawRelativeZero();
155 virtual void drawPaper();
156 virtual void drawGrid();
157 virtual void drawMetaGrid();
158 virtual void updateGrid();
160 virtual void updateGridStatusWidget(const QString & /*text*/);
162 void setDefaultSnapMode(RS2::SnapMode sm);
163 RS2::SnapMode getDefaultSnapMode();
164 void setSnapRestriction(RS2::SnapRestriction sr);
165 RS2::SnapRestriction getSnapRestriction();
168 Vector toGui(Vector v);
169 double toGuiX(double x, bool * visible = NULL);
170 double toGuiY(double y);
171 double toGuiDX(double d);
172 double toGuiDY(double d);
174 Vector toGraph(Vector v);
175 Vector toGraph(int x, int y);
176 double toGraphX(int x);
177 double toGraphY(int y);
178 double toGraphDX(int d);
179 double toGraphDY(int d);
181 void lockRelativeZero(bool lock);
182 bool isRelativeZeroLocked();
183 Vector getRelativeZero();
184 void setRelativeZero(const Vector & pos);
185 void moveRelativeZero(const Vector & pos);
187 RS_EventHandler * getEventHandler();
188 void setPrintPreview(bool pv);
189 bool isPrintPreview();
190 void setPrinting(bool p);
193 void setSimulationSpeed(int s);
194 int getSimulationSpeed();
195 void setSimulationSmooth(bool s);
196 void setSimulationRapid(bool r);
197 bool getSimulationRapid();
199 //this is here because of crappy braindead infrastructure
200 void SetPreviewMode(bool mode = true);
201 void SetPreviewEntity(RS_Preview *);
202 void SetPreviewOffset(Vector);
203 //We can remove this now...
204 // void SetSnapperDraw(bool);
205 // void SetSnapperVars(Vector snapSpot, Vector snapCoord, bool showCrosshairs);
208 RS_EntityContainer * container;
209 RS_EventHandler * eventHandler;
211 int mx; //!< Last known mouse cursor position
212 int my; //!< Last known mouse cursor position
214 PaintInterface * painter;
215 /** background color (any color) */
217 /** foreground color (black or white) */
221 /** meta grid color */
222 RS_Color metaGridColor;
223 /** selected color */
224 RS_Color selectedColor;
225 /** highlighted color */
226 RS_Color highlightedColor;
230 * Current default snap mode for this graphic view. Used for new
233 RS2::SnapMode defaultSnapMode;
235 * Current default snap restriction for this graphic view. Used for new
238 RS2::SnapRestriction defaultSnapRes;
240 RS2::DrawingMode drawingMode;
243 * Delete mode. If true, all drawing actions will delete in background color
247 //! If true, the simulation is currectly running
248 bool simulationRunning;
259 Vector previousFactor;
269 bool relativeZeroLocked;
270 //! Print preview flag
272 //! Active when printing only:
275 //! Simulation speed in percentage
277 //! If true, the entity is drawn slowly (pixel by pixel).
278 bool simulationSmooth;
279 //! If true, the way between entities is also shown.
280 bool simulationRapid;
281 //! Last position (for rapid move)
282 Vector simulationLast;
285 // We use this here instead of deriving ActionInterface from it because
286 // this makes more sense.
291 // crap to make painting with update() possible
292 RS_Preview * previewEntity;
294 Vector previewOffset;
297 // Vector snapCoord1;
298 // bool showCrosshairs1;
304 //! Horizontal scrollbar.
305 QScrollBar * hScrollBar;
306 //! Vertical scrollbar.
307 QScrollBar * vScrollBar;
308 // //! Layout used to fit in the view and the scrollbars.
309 // QGridLayout * layout;
310 //! Label for grid spacing.
314 //! Delete mouse cursor
316 //! Select mouse cursor
318 //! Magnifying glass mouse cursor
319 QCursor * curMagnifier;
320 //! Hand mouse cursor
326 #endif // __GRAPHICVIEW_H__
329 class QG_GraphicView: public QWidget, public RS_GraphicView
334 QG_GraphicView(QWidget * parent = 0, const char * name = 0, Qt::WindowFlags f = 0);
335 virtual ~QG_GraphicView();
337 virtual int getWidth();
338 virtual int getHeight();
339 virtual void redraw();
340 virtual void adjustOffsetControls();
341 virtual void adjustZoomControls();
342 virtual void setBackground(const RS_Color & bg);
343 virtual void setMouseCursor(RS2::CursorType c);
344 virtual void updateGridStatusWidget(const QString & text);
347 virtual void emulateMouseMoveEvent();
348 virtual void mousePressEvent(QMouseEvent * e);
349 virtual void mouseReleaseEvent(QMouseEvent * e);
350 virtual void mouseMoveEvent(QMouseEvent * e);
351 virtual void tabletEvent(QTabletEvent * e);
352 virtual void leaveEvent(QEvent *);
353 virtual void enterEvent(QEvent *);
354 virtual void focusInEvent(QFocusEvent *);
355 virtual void focusOutEvent(QFocusEvent *);
356 virtual void wheelEvent(QWheelEvent * e);
357 virtual void keyPressEvent(QKeyEvent * e);
358 virtual void keyReleaseEvent(QKeyEvent * e);
360 void paintEvent(QPaintEvent *);
361 virtual void resizeEvent(QResizeEvent * e);
364 void slotHScrolled(int value);
365 void slotVScrolled(int value);