1 #ifndef __GRAPHICVIEW_H__
2 #define __GRAPHICVIEW_H__
11 class RS_EntityContainer;
12 class RS_ActionInterface;
14 class RS_LineTypePattern;
15 class RS_CommandEvent;
20 class RS_EventHandler;
30 Drawing * getGraphic();
31 void setDrawingMode(RS2::DrawingMode m);
32 RS2::DrawingMode getDrawingMode();
33 void setDeleteMode(bool m);
36 /** This virtual method must be overwritten to return
37 the width of the widget the graphic is shown in */
38 virtual int getWidth() = 0;
39 /** This virtual method must be overwritten to return
40 the height of the widget the graphic is shown in */
41 virtual int getHeight() = 0;
42 /** This virtual method must be overwritten to redraw
44 virtual void redraw() = 0;
46 /** This virtual method must be overwritten and is then
47 called whenever the view changed */
48 virtual void adjustOffsetControls();
49 /** This virtual method must be overwritten and is then
50 called whenever the view changed */
51 virtual void adjustZoomControls();
53 * Sets an external painter device.
55 virtual void setPainter(PaintInterface * p);
57 virtual void setBackground(const RS_Color & bg);
58 RS_Color getBackground();
59 RS_Color getForeground();
60 void setGridColor(const RS_Color & c);
61 void setMetaGridColor(const RS_Color & c);
62 void setSelectedColor(const RS_Color & c);
63 void setHighlightedColor(const RS_Color & c);
64 virtual void setMouseCursor(RS2::CursorType /*c*/);
65 void setContainer(RS_EntityContainer * container);
66 RS_EntityContainer * getContainer();
67 void setFactor(double f);
68 void setFactorX(double f);
69 void setFactorY(double f);
71 void setOffset(int ox, int oy);
72 void setOffsetX(int ox);
73 void setOffsetY(int oy);
78 void centerX(double x);
79 void centerY(double y);
80 virtual void updateView();
81 void setBorders(int left, int top, int right, int bottom);
85 int getBorderBottom();
88 bool isUpdateEnabled();
89 void freezeZoom(bool freeze);
92 void setDefaultAction(RS_ActionInterface * action);
93 RS_ActionInterface * getDefaultAction();
94 void setCurrentAction(RS_ActionInterface * action);
95 RS_ActionInterface * getCurrentAction();
97 void killSelectActions();
98 void killAllActions();
101 * Must be overwritten to emulate a mouse move event with
102 * the last known mouse position.
106 virtual void emulateMouseMoveEvent() = 0;
111 void mousePressEvent(QMouseEvent * e);
112 void mouseReleaseEvent(QMouseEvent * e);
113 void mouseMoveEvent(QMouseEvent * e);
114 void mouseLeaveEvent();
115 void mouseEnterEvent();
116 void keyPressEvent(QKeyEvent * e);
117 void keyReleaseEvent(QKeyEvent * e);
118 void commandEvent(RS_CommandEvent * e);
119 void enableCoordinateInput();
120 void disableCoordinateInput();
122 virtual void zoomIn(double f = 1.5, const Vector & center = Vector(false));
123 virtual void zoomInX(double f = 1.5);
124 virtual void zoomInY(double f = 1.5);
125 virtual void zoomOut(double f = 1.5, const Vector & center = Vector(false));
126 virtual void zoomOutX(double f = 1.5);
127 virtual void zoomOutY(double f = 1.5);
128 virtual void zoomAuto(bool axis = true, bool keepAspectRatio = true);
129 virtual void zoomAutoY(bool axis = true);
130 virtual void zoomPrevious();
131 virtual void saveView();
132 virtual void restoreView();
133 virtual void zoomWindow(Vector v1, Vector v2, bool keepAspectRatio = true);
134 //virtual void zoomPan(Vector v1);
135 virtual void zoomPan(int dx, int dy);
136 virtual void zoomScroll(RS2::Direction direction);
137 virtual void zoomPage();
139 virtual void drawWindow(Vector v1, Vector v2);
140 virtual void drawIt();
141 virtual void deleteEntity(RS_Entity * e);
142 virtual void drawEntity(RS_Entity * e, double patternOffset = 0.0, bool db = false);
143 virtual void drawEntityPlain(RS_Entity * e, double patternOffset = 0.0);
144 virtual void setPenForEntity(RS_Entity * e);
147 void simulateEntity(RS_Entity * e, const RS_Pen & pen);
148 void drawLineSmooth(const Vector & p1, const Vector & p2, const RS_Pen & pen);
149 void drawArcSmooth(const Vector & center, double radius,
150 double a1, double a2, bool rev, const RS_Pen & pen);
151 void simulationDelay(bool step = false);
153 virtual RS_LineTypePattern * getPattern(RS2::LineType t);
155 virtual void drawAbsoluteZero();
156 virtual void drawRelativeZero();
157 virtual void drawPaper();
158 virtual void drawGrid();
159 virtual void drawMetaGrid();
160 virtual void updateGrid();
162 virtual void updateGridStatusWidget(const QString & /*text*/);
164 void setDefaultSnapMode(RS2::SnapMode sm);
165 RS2::SnapMode getDefaultSnapMode();
166 void setSnapRestriction(RS2::SnapRestriction sr);
167 RS2::SnapRestriction getSnapRestriction();
170 Vector toGui(Vector v);
171 double toGuiX(double x, bool * visible = NULL);
172 double toGuiY(double y);
173 double toGuiDX(double d);
174 double toGuiDY(double d);
176 Vector toGraph(Vector v);
177 Vector toGraph(int x, int y);
178 double toGraphX(int x);
179 double toGraphY(int y);
180 double toGraphDX(int d);
181 double toGraphDY(int d);
183 void lockRelativeZero(bool lock);
184 bool isRelativeZeroLocked();
185 Vector getRelativeZero();
186 void setRelativeZero(const Vector & pos);
187 void moveRelativeZero(const Vector & pos);
189 RS_EventHandler * getEventHandler();
190 void setPrintPreview(bool pv);
191 bool isPrintPreview();
192 void setPrinting(bool p);
195 void setSimulationSpeed(int s);
196 int getSimulationSpeed();
197 void setSimulationSmooth(bool s);
198 void setSimulationRapid(bool r);
199 bool getSimulationRapid();
201 //this is here because of crappy braindead infrastructure
202 void SetPreviewMode(bool mode = true);
203 void SetPreviewEntity(RS_Preview *);
204 void SetPreviewOffset(Vector);
205 void SetSnapperDraw(bool);
206 void SetSnapperVars(Vector snapSpot, Vector snapCoord, bool showCrosshairs);
209 RS_EntityContainer * container;
210 RS_EventHandler * eventHandler;
212 int mx; //!< Last known mouse cursor position
213 int my; //!< Last known mouse cursor position
215 PaintInterface * painter;
216 /** background color (any color) */
218 /** foreground color (black or white) */
222 /** meta grid color */
223 RS_Color metaGridColor;
224 /** selected color */
225 RS_Color selectedColor;
226 /** highlighted color */
227 RS_Color highlightedColor;
231 * Current default snap mode for this graphic view. Used for new
234 RS2::SnapMode defaultSnapMode;
236 * Current default snap restriction for this graphic view. Used for new
239 RS2::SnapRestriction defaultSnapRes;
241 RS2::DrawingMode drawingMode;
244 * Delete mode. If true, all drawing actions will delete in background color
248 //! If true, the simulation is currectly running
249 bool simulationRunning;
260 Vector previousFactor;
270 bool relativeZeroLocked;
271 //! Print preview flag
273 //! Active when printing only:
276 //! Simulation speed in percentage
278 //! If true, the entity is drawn slowly (pixel by pixel).
279 bool simulationSmooth;
280 //! If true, the way between entities is also shown.
281 bool simulationRapid;
282 //! Last position (for rapid move)
283 Vector simulationLast;
286 // crap to make painting with update() possible
287 RS_Preview * previewEntity;
289 Vector previewOffset;
293 bool showCrosshairs1;
301 #endif // __GRAPHICVIEW_H__
304 class QG_GraphicView: public QWidget, public RS_GraphicView, //public Q3FilePreview,
305 public RS_LayerListListener, public RS_BlockListListener
310 QG_GraphicView(QWidget * parent = 0, const char * name = 0, Qt::WindowFlags f = 0);
311 virtual ~QG_GraphicView();
313 virtual int getWidth();
314 virtual int getHeight();
315 virtual void redraw();
316 virtual void adjustOffsetControls();
317 virtual void adjustZoomControls();
318 // virtual RS_Painter * createPainter();
319 // virtual RS_Painter * createDirectPainter();
320 #warning "!!! Need to scrub out all instances of createPainter and createDirectPainter !!!"
321 // virtual PaintInterface * createPainter();
322 // virtual PaintInterface * createDirectPainter();
323 // virtual void destroyPainter();
324 virtual void setBackground(const RS_Color & bg);
325 virtual void setMouseCursor(RS2::CursorType c);
326 virtual void updateGridStatusWidget(const QString & text);
328 // Methods from RS_LayerListListener Interface:
329 virtual void layerEdited(RS_Layer *);
330 virtual void layerRemoved(RS_Layer *);
331 virtual void layerToggled(RS_Layer *);
334 virtual void emulateMouseMoveEvent();
335 virtual void mousePressEvent(QMouseEvent * e);
336 virtual void mouseReleaseEvent(QMouseEvent * e);
337 virtual void mouseMoveEvent(QMouseEvent * e);
338 virtual void tabletEvent(QTabletEvent * e);
339 virtual void leaveEvent(QEvent *);
340 virtual void enterEvent(QEvent *);
341 virtual void focusInEvent(QFocusEvent *);
342 virtual void focusOutEvent(QFocusEvent *);
343 virtual void wheelEvent(QWheelEvent * e);
344 virtual void keyPressEvent(QKeyEvent * e);
345 virtual void keyReleaseEvent(QKeyEvent * e);
347 void paintEvent(QPaintEvent *);
348 virtual void resizeEvent(QResizeEvent * e);
350 #warning "!!! File preview needs porting to Qt4 !!!"
351 // void previewUrl(const Q3Url &u);
354 void slotHScrolled(int value);
355 void slotVScrolled(int value);
358 #warning "!!! Double buffering is not necessary anymore !!!"
359 //! Buffer for double-buffering
366 //! Horizontal scrollbar.
367 QG_ScrollBar * hScrollBar;
368 //! Vertical scrollbar.
369 QG_ScrollBar * vScrollBar;
370 //! Layout used to fit in the view and the scrollbars.
371 QGridLayout * layout;
372 //! Label for grid spacing.
376 //! Delete mouse cursor
378 //! Select mouse cursor
380 //! Magnifying glass mouse cursor
381 QCursor * curMagnifier;
382 //! Hand mouse cursor
388 class QC_GraphicView: public QG_GraphicView
391 QC_GraphicView(RS_Document * doc, QWidget * parent = 0);
392 virtual ~QC_GraphicView();
394 virtual void drawIt();
397 //RS_Document* document;