]> Shamusworld >> Repos - architektonas/blob - src/mainapp/graphicview.h
6e2ec159156379b4b7a8ff0afb81335eb5c98036
[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 ActionInterface;
12 class RS_CommandEvent;
13 class Drawing;
14 class PaintInterface;
15 class RS_Entity;
16 class RS_EntityContainer;
17 class RS_EventHandler;
18 class RS_Grid;
19 class RS_LineTypePattern;
20 class RS_Pen;
21
22 class GraphicView
23 {
24         public:
25                 GraphicView();
26                 ~GraphicView();
27
28                 void cleanUp();
29
30                 Drawing * getGraphic();
31                 void setDrawingMode(RS2::DrawingMode m);
32                 RS2::DrawingMode getDrawingMode();
33                 void setDeleteMode(bool m);
34                 bool getDeleteMode();
35
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
43                 the widget. */
44                 virtual void redraw() = 0;
45
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();
52
53                 virtual void setBackground(const RS_Color & bg);
54                 RS_Color getBackground();
55                 RS_Color getForeground();
56                 void setGridColor(const RS_Color & c);
57                 void setMetaGridColor(const RS_Color & c);
58                 void setSelectedColor(const RS_Color & c);
59                 void setHighlightedColor(const RS_Color & c);
60                 virtual void setMouseCursor(RS2::CursorType /*c*/);
61                 void setContainer(RS_EntityContainer * container);
62                 RS_EntityContainer * getContainer();
63                 void setFactor(double f);
64                 void setFactorX(double f);
65                 void setFactorY(double f);
66                 Vector getFactor();
67                 void setOffset(int ox, int oy);
68                 void setOffsetX(int ox);
69                 void setOffsetY(int oy);
70                 int getOffsetX();
71                 int getOffsetY();
72                 void centerOffsetX();
73                 void centerOffsetY();
74                 void centerX(double x);
75                 void centerY(double y);
76                 virtual void updateView();
77                 void setBorders(int left, int top, int right, int bottom);
78                 int getBorderLeft();
79                 int getBorderTop();
80                 int getBorderRight();
81                 int getBorderBottom();
82                 void disableUpdate();
83                 void enableUpdate();
84                 bool isUpdateEnabled();
85                 void freezeZoom(bool freeze);
86                 bool isZoomFrozen();
87
88                 void setDefaultAction(ActionInterface * action);
89                 ActionInterface *  getDefaultAction();
90                 void setCurrentAction(ActionInterface * action);
91                 ActionInterface * getCurrentAction();
92
93                 void killSelectActions();
94                 void killAllActions();
95
96                 /**
97                  * Must be overwritten to emulate a mouse move event with
98                  * the last known mouse position.
99                  *
100                  * @see mx, my
101                  */
102                 virtual void emulateMouseMoveEvent() = 0;
103
104                 void back();
105                 void enter();
106
107                 void mousePressEvent(QMouseEvent * e);
108                 void mouseReleaseEvent(QMouseEvent * e);
109                 void mouseMoveEvent(QMouseEvent * e);
110                 void mouseLeaveEvent();
111                 void mouseEnterEvent();
112                 void keyPressEvent(QKeyEvent * e);
113                 void keyReleaseEvent(QKeyEvent * e);
114                 void commandEvent(RS_CommandEvent * e);
115                 void enableCoordinateInput();
116                 void disableCoordinateInput();
117
118                 virtual void zoomIn(double f = 1.5, const Vector & center = Vector(false));
119                 virtual void zoomInX(double f = 1.5);
120                 virtual void zoomInY(double f = 1.5);
121                 virtual void zoomOut(double f = 1.5, const Vector & center = Vector(false));
122                 virtual void zoomOutX(double f = 1.5);
123                 virtual void zoomOutY(double f = 1.5);
124                 virtual void zoomAuto(bool axis = true, bool keepAspectRatio = true);
125                 virtual void zoomAutoY(bool axis = true);
126                 virtual void zoomPrevious();
127                 virtual void saveView();
128                 virtual void restoreView();
129                 virtual void zoomWindow(Vector v1, Vector v2, bool keepAspectRatio = true);
130                 //virtual void zoomPan(Vector v1);
131                 virtual void zoomPan(int dx, int dy);
132                 virtual void zoomScroll(RS2::Direction direction);
133                 virtual void zoomPage();
134
135                 virtual void drawWindow(Vector v1, Vector v2);
136                 virtual void drawIt();
137                 virtual void deleteEntity(RS_Entity * e);
138                 virtual void drawEntity(RS_Entity * e, double patternOffset = 0.0, bool db = false);
139                 virtual void drawEntityPlain(RS_Entity * e, double patternOffset = 0.0);
140                 virtual void setPenForEntity(RS_Entity * e);
141
142                 void simulateIt();
143                 void simulateEntity(RS_Entity * e, const RS_Pen & pen);
144                 void drawLineSmooth(const Vector & p1, const Vector & p2, const RS_Pen & pen);
145                 void drawArcSmooth(const Vector & center, double radius,
146                         double a1, double a2, bool rev, const RS_Pen & pen);
147                 void simulationDelay(bool step = false);
148
149                 virtual RS_LineTypePattern * getPattern(RS2::LineType t);
150
151                 virtual void drawAbsoluteZero();
152                 virtual void drawRelativeZero();
153                 virtual void drawPaper();
154                 virtual void drawGrid();
155                 virtual void drawMetaGrid();
156                 virtual void updateGrid();
157                 RS_Grid * getGrid();
158                 virtual void updateGridStatusWidget(const QString & /*text*/);
159
160                 void setDefaultSnapMode(RS2::SnapMode sm);
161                 RS2::SnapMode getDefaultSnapMode();
162                 void setSnapRestriction(RS2::SnapRestriction sr);
163                 RS2::SnapRestriction getSnapRestriction();
164                 bool isGridOn();
165
166                 Vector toGui(Vector v);
167                 double toGuiX(double x, bool * visible = NULL);
168                 double toGuiY(double y);
169                 double toGuiDX(double d);
170                 double toGuiDY(double d);
171
172                 Vector toGraph(Vector v);
173                 Vector toGraph(int x, int y);
174                 double toGraphX(int x);
175                 double toGraphY(int y);
176                 double toGraphDX(int d);
177                 double toGraphDY(int d);
178
179                 void lockRelativeZero(bool lock);
180                 bool isRelativeZeroLocked();
181                 Vector getRelativeZero();
182                 void setRelativeZero(const Vector & pos);
183                 void moveRelativeZero(const Vector & pos);
184
185                 RS_EventHandler * getEventHandler();
186                 void setPrintPreview(bool pv);
187                 bool isPrintPreview();
188                 void setPrinting(bool p);
189                 bool isPrinting();
190                 bool isDraftMode();
191                 void setSimulationSpeed(int s);
192                 int getSimulationSpeed();
193                 void setSimulationSmooth(bool s);
194                 void setSimulationRapid(bool r);
195                 bool getSimulationRapid();
196
197         protected:
198                 RS_EntityContainer * container;
199                 RS_EventHandler * eventHandler;
200
201                 int mx;   //!< Last known mouse cursor position
202                 int my;   //!< Last known mouse cursor position
203
204                 PaintInterface * painter;
205                 /** background color (any color) */
206                 RS_Color background;
207                 /** foreground color (black or white) */
208                 RS_Color foreground;
209                 /** grid color */
210                 RS_Color gridColor;
211                 /** meta grid color */
212                 RS_Color metaGridColor;
213                 /** selected color */
214                 RS_Color selectedColor;
215                 /** highlighted color */
216                 RS_Color highlightedColor;
217                 /** Grid */
218                 RS_Grid * grid;
219                 /**
220                 * Current default snap mode for this graphic view. Used for new
221                 * actions.
222                 */
223                 RS2::SnapMode defaultSnapMode;
224                 /**
225                 * Current default snap restriction for this graphic view. Used for new
226                 * actions.
227                 */
228                 RS2::SnapRestriction defaultSnapRes;
229
230                 RS2::DrawingMode drawingMode;
231
232                 /**
233                 * Delete mode. If true, all drawing actions will delete in background color
234                 * instead.
235                 */
236                 bool deleteMode;
237                 //! If true, the simulation is currectly running
238                 bool simulationRunning;
239
240         private:
241                 int updateEnabled;
242                 bool zoomFrozen;
243                 bool draftMode;
244
245                 Vector factor;
246                 int offsetX;
247                 int offsetY;
248
249                 Vector previousFactor;
250                 int previousOffsetX;
251                 int previousOffsetY;
252
253                 int borderLeft;
254                 int borderTop;
255                 int borderRight;
256                 int borderBottom;
257
258                 Vector relativeZero;
259                 bool relativeZeroLocked;
260                 //! Print preview flag
261                 bool printPreview;
262                 //! Active when printing only:
263                 bool printing;
264
265                 //! Simulation speed in percentage
266                 int simulationSpeed;
267                 //! If true, the entity is drawn slowly (pixel by pixel).
268                 bool simulationSmooth;
269                 //! If true, the way between entities is also shown.
270                 bool simulationRapid;
271                 //! Last position (for rapid move)
272                 Vector simulationLast;
273
274         public://for now
275                 // We use this here instead of deriving ActionInterface from it because
276                 // this makes more sense.
277                 RS_Snapper snapper;
278                 RS_Preview preview;
279
280 //QG
281         protected:
282                 int lastWidth;
283                 int lastHeight;
284                 //! Horizontal scrollbar.
285                 QScrollBar * hScrollBar;
286                 //! Vertical scrollbar.
287                 QScrollBar * vScrollBar;
288                 //! Label for grid spacing.
289                 QLabel * gridStatus;
290                 //! CAD mouse cursor
291                 QCursor * curCad;
292                 //! Delete mouse cursor
293                 QCursor * curDel;
294                 //! Select mouse cursor
295                 QCursor * curSelect;
296                 //! Magnifying glass mouse cursor
297                 QCursor * curMagnifier;
298                 //! Hand mouse cursor
299                 QCursor * curHand;
300
301 //QC was merged with QG
302 };
303
304 #endif  // __GRAPHICVIEW_H__
305
306 #if 0
307 class QG_GraphicView: public QWidget, public RS_GraphicView
308 {
309         Q_OBJECT
310
311         public:
312                 QG_GraphicView(QWidget * parent = 0, const char * name = 0, Qt::WindowFlags f = 0);
313                 virtual ~QG_GraphicView();
314
315                 virtual int getWidth();
316                 virtual int getHeight();
317                 virtual void redraw();
318                 virtual void adjustOffsetControls();
319                 virtual void adjustZoomControls();
320                 virtual void setBackground(const RS_Color & bg);
321                 virtual void setMouseCursor(RS2::CursorType c);
322                 virtual void updateGridStatusWidget(const QString & text);
323
324         protected:
325                 virtual void emulateMouseMoveEvent();
326                 virtual void mousePressEvent(QMouseEvent * e);
327                 virtual void mouseReleaseEvent(QMouseEvent * e);
328                 virtual void mouseMoveEvent(QMouseEvent * e);
329                 virtual void tabletEvent(QTabletEvent * e);
330                 virtual void leaveEvent(QEvent *);
331                 virtual void enterEvent(QEvent *);
332                 virtual void focusInEvent(QFocusEvent *);
333                 virtual void focusOutEvent(QFocusEvent *);
334                 virtual void wheelEvent(QWheelEvent * e);
335                 virtual void keyPressEvent(QKeyEvent * e);
336                 virtual void keyReleaseEvent(QKeyEvent * e);
337
338                 void paintEvent(QPaintEvent *);
339                 virtual void resizeEvent(QResizeEvent * e);
340
341         private slots:
342                 void slotHScrolled(int value);
343                 void slotVScrolled(int value);
344 };
345 #endif