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;
31 Drawing * getGraphic();
32 void setDrawingMode(RS2::DrawingMode m);
33 RS2::DrawingMode getDrawingMode();
34 void setDeleteMode(bool m);
37 /** This virtual method must be overwritten to return
38 the width of the widget the graphic is shown in */
39 virtual int getWidth() = 0;
40 /** This virtual method must be overwritten to return
41 the height of the widget the graphic is shown in */
42 virtual int getHeight() = 0;
43 /** This virtual method must be overwritten to redraw
45 virtual void redraw() = 0;
47 /** This virtual method must be overwritten and is then
48 called whenever the view changed */
49 virtual void adjustOffsetControls();
50 /** This virtual method must be overwritten and is then
51 called whenever the view changed */
52 virtual void adjustZoomControls();
54 * Sets an external painter device.
56 virtual void setPainter(PaintInterface * p);
58 virtual void setBackground(const RS_Color & bg);
59 RS_Color getBackground();
60 RS_Color getForeground();
61 void setGridColor(const RS_Color & c);
62 void setMetaGridColor(const RS_Color & c);
63 void setSelectedColor(const RS_Color & c);
64 void setHighlightedColor(const RS_Color & c);
65 virtual void setMouseCursor(RS2::CursorType /*c*/);
66 void setContainer(RS_EntityContainer * container);
67 RS_EntityContainer * getContainer();
68 void setFactor(double f);
69 void setFactorX(double f);
70 void setFactorY(double f);
72 void setOffset(int ox, int oy);
73 void setOffsetX(int ox);
74 void setOffsetY(int oy);
79 void centerX(double x);
80 void centerY(double y);
81 virtual void updateView();
82 void setBorders(int left, int top, int right, int bottom);
86 int getBorderBottom();
89 bool isUpdateEnabled();
90 void freezeZoom(bool freeze);
93 void setDefaultAction(RS_ActionInterface * action);
94 RS_ActionInterface * getDefaultAction();
95 void setCurrentAction(RS_ActionInterface * action);
96 RS_ActionInterface * getCurrentAction();
98 void killSelectActions();
99 void killAllActions();
102 * Must be overwritten to emulate a mouse move event with
103 * the last known mouse position.
107 virtual void emulateMouseMoveEvent() = 0;
112 void mousePressEvent(QMouseEvent * e);
113 void mouseReleaseEvent(QMouseEvent * e);
114 void mouseMoveEvent(QMouseEvent * e);
115 void mouseLeaveEvent();
116 void mouseEnterEvent();
117 void keyPressEvent(QKeyEvent * e);
118 void keyReleaseEvent(QKeyEvent * e);
119 void commandEvent(RS_CommandEvent * e);
120 void enableCoordinateInput();
121 void disableCoordinateInput();
123 virtual void zoomIn(double f = 1.5, const Vector & center = Vector(false));
124 virtual void zoomInX(double f = 1.5);
125 virtual void zoomInY(double f = 1.5);
126 virtual void zoomOut(double f = 1.5, const Vector & center = Vector(false));
127 virtual void zoomOutX(double f = 1.5);
128 virtual void zoomOutY(double f = 1.5);
129 virtual void zoomAuto(bool axis = true, bool keepAspectRatio = true);
130 virtual void zoomAutoY(bool axis = true);
131 virtual void zoomPrevious();
132 virtual void saveView();
133 virtual void restoreView();
134 virtual void zoomWindow(Vector v1, Vector v2, bool keepAspectRatio = true);
135 //virtual void zoomPan(Vector v1);
136 virtual void zoomPan(int dx, int dy);
137 virtual void zoomScroll(RS2::Direction direction);
138 virtual void zoomPage();
140 virtual void drawWindow(Vector v1, Vector v2);
141 virtual void drawIt();
142 virtual void deleteEntity(RS_Entity * e);
143 virtual void drawEntity(RS_Entity * e, double patternOffset = 0.0, bool db = false);
144 virtual void drawEntityPlain(RS_Entity * e, double patternOffset = 0.0);
145 virtual void setPenForEntity(RS_Entity * e);
148 void simulateEntity(RS_Entity * e, const RS_Pen & pen);
149 void drawLineSmooth(const Vector & p1, const Vector & p2, const RS_Pen & pen);
150 void drawArcSmooth(const Vector & center, double radius,
151 double a1, double a2, bool rev, const RS_Pen & pen);
152 void simulationDelay(bool step = false);
154 virtual RS_LineTypePattern * getPattern(RS2::LineType t);
156 virtual void drawAbsoluteZero();
157 virtual void drawRelativeZero();
158 virtual void drawPaper();
159 virtual void drawGrid();
160 virtual void drawMetaGrid();
161 virtual void updateGrid();
163 virtual void updateGridStatusWidget(const QString & /*text*/);
165 void setDefaultSnapMode(RS2::SnapMode sm);
166 RS2::SnapMode getDefaultSnapMode();
167 void setSnapRestriction(RS2::SnapRestriction sr);
168 RS2::SnapRestriction getSnapRestriction();
171 Vector toGui(Vector v);
172 double toGuiX(double x, bool * visible = NULL);
173 double toGuiY(double y);
174 double toGuiDX(double d);
175 double toGuiDY(double d);
177 Vector toGraph(Vector v);
178 Vector toGraph(int x, int y);
179 double toGraphX(int x);
180 double toGraphY(int y);
181 double toGraphDX(int d);
182 double toGraphDY(int d);
184 void lockRelativeZero(bool lock);
185 bool isRelativeZeroLocked();
186 Vector getRelativeZero();
187 void setRelativeZero(const Vector & pos);
188 void moveRelativeZero(const Vector & pos);
190 RS_EventHandler * getEventHandler();
191 void setPrintPreview(bool pv);
192 bool isPrintPreview();
193 void setPrinting(bool p);
196 void setSimulationSpeed(int s);
197 int getSimulationSpeed();
198 void setSimulationSmooth(bool s);
199 void setSimulationRapid(bool r);
200 bool getSimulationRapid();
202 //this is here because of crappy braindead infrastructure
203 void SetPreviewMode(bool mode = true);
204 void SetPreviewEntity(RS_Preview *);
205 void SetPreviewOffset(Vector);
206 void SetSnapperDraw(bool);
207 void SetSnapperVars(Vector snapSpot, Vector snapCoord, bool showCrosshairs);
210 RS_EntityContainer * container;
211 RS_EventHandler * eventHandler;
213 int mx; //!< Last known mouse cursor position
214 int my; //!< Last known mouse cursor position
216 PaintInterface * painter;
217 /** background color (any color) */
219 /** foreground color (black or white) */
223 /** meta grid color */
224 RS_Color metaGridColor;
225 /** selected color */
226 RS_Color selectedColor;
227 /** highlighted color */
228 RS_Color highlightedColor;
232 * Current default snap mode for this graphic view. Used for new
235 RS2::SnapMode defaultSnapMode;
237 * Current default snap restriction for this graphic view. Used for new
240 RS2::SnapRestriction defaultSnapRes;
242 RS2::DrawingMode drawingMode;
245 * Delete mode. If true, all drawing actions will delete in background color
249 //! If true, the simulation is currectly running
250 bool simulationRunning;
261 Vector previousFactor;
271 bool relativeZeroLocked;
272 //! Print preview flag
274 //! Active when printing only:
277 //! Simulation speed in percentage
279 //! If true, the entity is drawn slowly (pixel by pixel).
280 bool simulationSmooth;
281 //! If true, the way between entities is also shown.
282 bool simulationRapid;
283 //! Last position (for rapid move)
284 Vector simulationLast;
287 // crap to make painting with update() possible
288 RS_Preview * previewEntity;
290 Vector previewOffset;
294 bool showCrosshairs1;
300 //! Horizontal scrollbar.
301 QG_ScrollBar * hScrollBar;
302 //! Vertical scrollbar.
303 QG_ScrollBar * vScrollBar;
304 //! Layout used to fit in the view and the scrollbars.
305 QGridLayout * layout;
306 //! Label for grid spacing.
310 //! Delete mouse cursor
312 //! Select mouse cursor
314 //! Magnifying glass mouse cursor
315 QCursor * curMagnifier;
316 //! Hand mouse cursor
322 #endif // __GRAPHICVIEW_H__
325 class QG_GraphicView: public QWidget, public RS_GraphicView, //public Q3FilePreview,
326 public RS_LayerListListener, public RS_BlockListListener
331 QG_GraphicView(QWidget * parent = 0, const char * name = 0, Qt::WindowFlags f = 0);
332 virtual ~QG_GraphicView();
334 virtual int getWidth();
335 virtual int getHeight();
336 virtual void redraw();
337 virtual void adjustOffsetControls();
338 virtual void adjustZoomControls();
339 // virtual RS_Painter * createPainter();
340 // virtual RS_Painter * createDirectPainter();
341 #warning "!!! Need to scrub out all instances of createPainter and createDirectPainter !!!"
342 // virtual PaintInterface * createPainter();
343 // virtual PaintInterface * createDirectPainter();
344 // virtual void destroyPainter();
345 virtual void setBackground(const RS_Color & bg);
346 virtual void setMouseCursor(RS2::CursorType c);
347 virtual void updateGridStatusWidget(const QString & text);
349 // Methods from RS_LayerListListener Interface:
350 virtual void layerEdited(RS_Layer *);
351 virtual void layerRemoved(RS_Layer *);
352 virtual void layerToggled(RS_Layer *);
355 virtual void emulateMouseMoveEvent();
356 virtual void mousePressEvent(QMouseEvent * e);
357 virtual void mouseReleaseEvent(QMouseEvent * e);
358 virtual void mouseMoveEvent(QMouseEvent * e);
359 virtual void tabletEvent(QTabletEvent * e);
360 virtual void leaveEvent(QEvent *);
361 virtual void enterEvent(QEvent *);
362 virtual void focusInEvent(QFocusEvent *);
363 virtual void focusOutEvent(QFocusEvent *);
364 virtual void wheelEvent(QWheelEvent * e);
365 virtual void keyPressEvent(QKeyEvent * e);
366 virtual void keyReleaseEvent(QKeyEvent * e);
368 void paintEvent(QPaintEvent *);
369 virtual void resizeEvent(QResizeEvent * e);
371 #warning "!!! File preview needs porting to Qt4 !!!"
372 // void previewUrl(const Q3Url &u);
375 void slotHScrolled(int value);
376 void slotVScrolled(int value);
379 #warning "!!! Double buffering is not necessary anymore !!!"
380 //! Buffer for double-buffering
387 //! Horizontal scrollbar.
388 QG_ScrollBar * hScrollBar;
389 //! Vertical scrollbar.
390 QG_ScrollBar * vScrollBar;
391 //! Layout used to fit in the view and the scrollbars.
392 QGridLayout * layout;
393 //! Label for grid spacing.
397 //! Delete mouse cursor
399 //! Select mouse cursor
401 //! Magnifying glass mouse cursor
402 QCursor * curMagnifier;
403 //! Hand mouse cursor
409 class QC_GraphicView: public QG_GraphicView
412 QC_GraphicView(RS_Document * doc, QWidget * parent = 0);
413 virtual ~QC_GraphicView();
415 virtual void drawIt();