]> Shamusworld >> Repos - architektonas/blob - src/mainapp/graphicview.h
Fixed preview rendering for ActionDrawLine...
[architektonas] / src / mainapp / graphicview.h
1 #ifndef __GRAPHICVIEW_H__
2 #define __GRAPHICVIEW_H__
3
4 #include <QtGui>
5 #include "rs.h"
6 #include "rs_color.h"
7 #include "rs_preview.h"
8 #include "rs_snapper.h"
9 #include "vector.h"
10
11 class Drawing;
12 class PaintInterface;
13 class RS_EntityContainer;
14 class RS_ActionInterface;
15 class RS_Entity;
16 class RS_LineTypePattern;
17 class RS_CommandEvent;
18 class Vector;
19 class RS_Preview;
20 class RS_Grid;
21 class RS_Pen;
22 class RS_EventHandler;
23
24 class GraphicView
25 {
26         public:
27                 GraphicView();
28                 ~GraphicView();
29
30                 void cleanUp();
31
32                 Drawing * getGraphic();
33                 void setDrawingMode(RS2::DrawingMode m);
34                 RS2::DrawingMode getDrawingMode();
35                 void setDeleteMode(bool m);
36                 bool getDeleteMode();
37
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
45                 the widget. */
46                 virtual void redraw() = 0;
47
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();
54
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);
68                 Vector getFactor();
69                 void setOffset(int ox, int oy);
70                 void setOffsetX(int ox);
71                 void setOffsetY(int oy);
72                 int getOffsetX();
73                 int getOffsetY();
74                 void centerOffsetX();
75                 void centerOffsetY();
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);
80                 int getBorderLeft();
81                 int getBorderTop();
82                 int getBorderRight();
83                 int getBorderBottom();
84                 void disableUpdate();
85                 void enableUpdate();
86                 bool isUpdateEnabled();
87                 void freezeZoom(bool freeze);
88                 bool isZoomFrozen();
89
90                 void setDefaultAction(RS_ActionInterface * action);
91                 RS_ActionInterface *  getDefaultAction();
92                 void setCurrentAction(RS_ActionInterface * action);
93                 RS_ActionInterface * getCurrentAction();
94
95                 void killSelectActions();
96                 void killAllActions();
97
98                 /**
99                  * Must be overwritten to emulate a mouse move event with
100                  * the last known mouse position.
101                  *
102                  * @see mx, my
103                  */
104                 virtual void emulateMouseMoveEvent() = 0;
105
106                 void back();
107                 void enter();
108
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();
119
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();
136
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);
143
144                 void simulateIt();
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);
150
151                 virtual RS_LineTypePattern * getPattern(RS2::LineType t);
152
153                 virtual void drawAbsoluteZero();
154                 virtual void drawRelativeZero();
155                 virtual void drawPaper();
156                 virtual void drawGrid();
157                 virtual void drawMetaGrid();
158                 virtual void updateGrid();
159                 RS_Grid * getGrid();
160                 virtual void updateGridStatusWidget(const QString & /*text*/);
161
162                 void setDefaultSnapMode(RS2::SnapMode sm);
163                 RS2::SnapMode getDefaultSnapMode();
164                 void setSnapRestriction(RS2::SnapRestriction sr);
165                 RS2::SnapRestriction getSnapRestriction();
166                 bool isGridOn();
167
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);
173
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);
180
181                 void lockRelativeZero(bool lock);
182                 bool isRelativeZeroLocked();
183                 Vector getRelativeZero();
184                 void setRelativeZero(const Vector & pos);
185                 void moveRelativeZero(const Vector & pos);
186
187                 RS_EventHandler * getEventHandler();
188                 void setPrintPreview(bool pv);
189                 bool isPrintPreview();
190                 void setPrinting(bool p);
191                 bool isPrinting();
192                 bool isDraftMode();
193                 void setSimulationSpeed(int s);
194                 int getSimulationSpeed();
195                 void setSimulationSmooth(bool s);
196                 void setSimulationRapid(bool r);
197                 bool getSimulationRapid();
198
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);
206
207         protected:
208                 RS_EntityContainer * container;
209                 RS_EventHandler * eventHandler;
210
211                 int mx;   //!< Last known mouse cursor position
212                 int my;   //!< Last known mouse cursor position
213
214                 PaintInterface * painter;
215                 /** background color (any color) */
216                 RS_Color background;
217                 /** foreground color (black or white) */
218                 RS_Color foreground;
219                 /** grid color */
220                 RS_Color gridColor;
221                 /** meta grid color */
222                 RS_Color metaGridColor;
223                 /** selected color */
224                 RS_Color selectedColor;
225                 /** highlighted color */
226                 RS_Color highlightedColor;
227                 /** Grid */
228                 RS_Grid * grid;
229                 /**
230                 * Current default snap mode for this graphic view. Used for new
231                 * actions.
232                 */
233                 RS2::SnapMode defaultSnapMode;
234                 /**
235                 * Current default snap restriction for this graphic view. Used for new
236                 * actions.
237                 */
238                 RS2::SnapRestriction defaultSnapRes;
239
240                 RS2::DrawingMode drawingMode;
241
242                 /**
243                 * Delete mode. If true, all drawing actions will delete in background color
244                 * instead.
245                 */
246                 bool deleteMode;
247                 //! If true, the simulation is currectly running
248                 bool simulationRunning;
249
250         private:
251                 int updateEnabled;
252                 bool zoomFrozen;
253                 bool draftMode;
254
255                 Vector factor;
256                 int offsetX;
257                 int offsetY;
258
259                 Vector previousFactor;
260                 int previousOffsetX;
261                 int previousOffsetY;
262
263                 int borderLeft;
264                 int borderTop;
265                 int borderRight;
266                 int borderBottom;
267
268                 Vector relativeZero;
269                 bool relativeZeroLocked;
270                 //! Print preview flag
271                 bool printPreview;
272                 //! Active when printing only:
273                 bool printing;
274
275                 //! Simulation speed in percentage
276                 int simulationSpeed;
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;
283
284         public://for now
285                 // We use this here instead of deriving ActionInterface from it because
286                 // this makes more sense.
287                 RS_Snapper snapper;
288                 RS_Preview preview;
289
290         protected:
291                 // crap to make painting with update() possible
292                 RS_Preview * previewEntity;
293                 bool previewMode;
294                 Vector previewOffset;
295 //              bool snapperDraw;
296 //              Vector snapSpot1;
297 //              Vector snapCoord1;
298 //              bool showCrosshairs1;
299
300 //QG
301         protected:
302                 int lastWidth;
303                 int lastHeight;
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.
311                 QLabel * gridStatus;
312                 //! CAD mouse cursor
313                 QCursor * curCad;
314                 //! Delete mouse cursor
315                 QCursor * curDel;
316                 //! Select mouse cursor
317                 QCursor * curSelect;
318                 //! Magnifying glass mouse cursor
319                 QCursor * curMagnifier;
320                 //! Hand mouse cursor
321                 QCursor * curHand;
322
323 //QC
324 };
325
326 #endif  // __GRAPHICVIEW_H__
327
328 #if 0
329 class QG_GraphicView: public QWidget, public RS_GraphicView
330 {
331         Q_OBJECT
332
333         public:
334                 QG_GraphicView(QWidget * parent = 0, const char * name = 0, Qt::WindowFlags f = 0);
335                 virtual ~QG_GraphicView();
336
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);
345
346         protected:
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);
359
360                 void paintEvent(QPaintEvent *);
361                 virtual void resizeEvent(QResizeEvent * e);
362
363         private slots:
364                 void slotHScrolled(int value);
365                 void slotVScrolled(int value);
366 };
367 #endif