]> Shamusworld >> Repos - architektonas/blob - src/mainapp/graphicview.h
cb684c060aef93b3f75ed173c92a1f2134c1dff6
[architektonas] / src / mainapp / graphicview.h
1 #ifndef __GRAPHICVIEW_H__
2 #define __GRAPHICVIEW_H__
3
4 #include <QtGui>
5 #include "enums.h"
6 #include "color.h"
7 #include "preview.h"
8 #include "snapper.h"
9 #include "vector.h"
10
11 class ActionInterface;
12 class CommandEvent;
13 class Drawing;
14 class PaintInterface;
15 class Entity;
16 class EntityContainer;
17 class EventHandler;
18 class Grid;
19 class LineTypePattern;
20 class 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 Color & bg);
54                 Color getBackground();
55                 Color getForeground();
56                 void setGridColor(const Color & c);
57                 void setMetaGridColor(const Color & c);
58                 void setSelectedColor(const Color & c);
59                 void setHighlightedColor(const Color & c);
60                 virtual void setMouseCursor(RS2::CursorType /*c*/);
61                 void setContainer(EntityContainer * container);
62                 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(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 drawEntity(Entity * e, double patternOffset = 0.0, bool db = false);
138                 virtual void drawEntityPlain(Entity * e, double patternOffset = 0.0);
139                 virtual void setPenForEntity(Entity * e);
140
141                 void simulateIt();
142                 void simulateEntity(Entity * e, const Pen & pen);
143                 void drawLineSmooth(const Vector & p1, const Vector & p2, const Pen & pen);
144                 void drawArcSmooth(const Vector & center, double radius,
145                         double a1, double a2, bool rev, const Pen & pen);
146                 void simulationDelay(bool step = false);
147
148                 virtual LineTypePattern * getPattern(RS2::LineType t);
149
150                 virtual void drawAbsoluteZero();
151                 virtual void drawRelativeZero();
152                 virtual void drawPaper();
153                 virtual void drawGrid();
154                 virtual void drawMetaGrid();
155                 virtual void updateGrid();
156                 Grid * getGrid();
157                 virtual void updateGridStatusWidget(const QString & /*text*/);
158
159                 void setDefaultSnapMode(RS2::SnapMode sm);
160                 RS2::SnapMode getDefaultSnapMode();
161                 void setSnapRestriction(RS2::SnapRestriction sr);
162                 RS2::SnapRestriction getSnapRestriction();
163                 bool isGridOn();
164
165 /*
166 What to do about this shiatsu? This stuff is used in the snapper rendering
167 code... Maybe move all the snapper rendering back into this class???
168 Seems to make sense, though it kinda blows encapsulation. But it's already
169 blown by the snapper class having to use these functions in the first place!
170
171 How to fix???
172
173 The snapper as a separate class makes sense, since it has several functions
174 for finding various snapping points. But what about rendering???
175
176 Having this class derive from that one *might* make sense... *Maybe*. Not sure.
177
178 */
179                 Vector toGui(Vector v);
180                 double toGuiX(double x, bool * visible = NULL);
181                 double toGuiY(double y);
182                 double toGuiDX(double d);
183                 double toGuiDY(double d);
184
185                 Vector toGraph(Vector v);
186                 Vector toGraph(int x, int y);
187                 double toGraphX(int x);
188                 double toGraphY(int y);
189                 double toGraphDX(int d);
190                 double toGraphDY(int d);
191
192                 void lockRelativeZero(bool lock);
193                 bool isRelativeZeroLocked();
194                 Vector getRelativeZero();
195                 void setRelativeZero(const Vector & pos);
196                 void moveRelativeZero(const Vector & pos);
197
198                 EventHandler * getEventHandler();
199                 void setPrintPreview(bool pv);
200                 bool isPrintPreview();
201                 void setPrinting(bool p);
202                 bool isPrinting();
203                 bool isDraftMode();
204                 void setSimulationSpeed(int s);
205                 int getSimulationSpeed();
206                 void setSimulationSmooth(bool s);
207                 void setSimulationRapid(bool r);
208                 bool getSimulationRapid();
209
210                 Entity * CatchEntity(const Vector &, RS2::ResolveLevel level = RS2::ResolveNone);
211                 Entity * CatchEntity(QMouseEvent *, RS2::ResolveLevel level = RS2::ResolveNone);
212                 Entity * GetSnapperEntity(void);
213                 Vector SnapPoint(QMouseEvent *);
214                 Vector SnapGrid(Vector);
215                 void DrawSnapper(PaintInterface *);
216                 void SetSnapperVisible(bool visibility = true);
217                 bool SnapperVisible(void);
218
219         protected:
220                 EntityContainer * container;
221                 EventHandler * eventHandler;
222                 int mx;                                                         //!< Last known mouse cursor position
223                 int my;                                                         //!< Last known mouse cursor position
224                 PaintInterface * painter;
225                 Color background;                                       //! background color (any color)
226                 Color foreground;                                       //! foreground color (black or white)
227                 Color gridColor;                                        //! grid color
228                 Color metaGridColor;                            //! meta grid color
229                 Color selectedColor;                            //! selected color
230                 Color highlightedColor;                         //! highlighted color
231                 Grid * grid;                                            //! Grid
232                 /**
233                  * Current default snap mode for this graphic view. Used for new
234                  * actions.
235                  */
236                 RS2::SnapMode defaultSnapMode;
237                 /**
238                  * Current default snap restriction for this graphic view. Used for new
239                  * actions.
240                  */
241                 RS2::SnapRestriction defaultSnapRes;
242                 RS2::DrawingMode drawingMode;
243                 /**
244                  * Delete mode. If true, all drawing actions will delete in background color
245                  * instead.
246                  */
247                 bool deleteMode;
248                 bool simulationRunning;                         //! If true, the simulation is currectly running
249                 double snapDistance;                            //! Manually set snap distance
250                 Entity * snapEntity;                            //! Entity to snap to (if any)
251                 Vector snapSpot;
252                 Vector snapCoord;
253                 bool snapperVisible;                            //! Snapper visibility
254                 int snapRange;
255                 bool showCrosshairs;                            //! Snapper crosshair visibility
256
257         private:
258                 int updateEnabled;
259                 bool zoomFrozen;
260                 bool draftMode;
261                 Vector factor;
262                 int offsetX;
263                 int offsetY;
264                 Vector previousFactor;
265                 int previousOffsetX;
266                 int previousOffsetY;
267                 int borderLeft;
268                 int borderTop;
269                 int borderRight;
270                 int borderBottom;
271                 Vector relativeZero;
272                 bool relativeZeroLocked;
273                 bool printPreview;                              //! Print preview flag
274                 bool printing;                                  //! Active when printing only:
275                 int simulationSpeed;                    //! Simulation speed in percentage
276                 bool simulationSmooth;                  //! If true, the entity is drawn slowly (pixel by pixel).
277                 bool simulationRapid;                   //! If true, the way between entities is also shown.
278                 Vector simulationLast;                  //! Last position (for rapid move)
279
280         public://for now
281                 // We use this here instead of deriving ActionInterface from it because
282                 // this makes more sense.
283 //              Snapper snapper;
284 //yer next
285                 Preview preview;
286
287 //QG
288         protected:
289                 int lastWidth;
290                 int lastHeight;
291                 QScrollBar * hScrollBar;                        //! Horizontal scrollbar.
292                 QScrollBar * vScrollBar;                        //! Vertical scrollbar.
293                 QLabel * gridStatus;                            //! Label for grid spacing.
294                 QCursor * curCad;                                       //! CAD mouse cursor
295                 QCursor * curDel;                                       //! Delete mouse cursor
296                 QCursor * curSelect;                            //! Select mouse cursor
297                 QCursor * curMagnifier;                         //! Magnifying glass mouse cursor
298                 QCursor * curHand;                                      //! Hand mouse cursor
299
300 //QC was merged with QG
301 };
302
303 #endif  // __GRAPHICVIEW_H__
304
305 #if 0
306 class QG_GraphicView: public QWidget, public RS_GraphicView
307 {
308         Q_OBJECT
309
310         public:
311                 QG_GraphicView(QWidget * parent = 0, const char * name = 0, Qt::WindowFlags f = 0);
312                 virtual ~QG_GraphicView();
313
314                 virtual int getWidth();
315                 virtual int getHeight();
316                 virtual void redraw();
317                 virtual void adjustOffsetControls();
318                 virtual void adjustZoomControls();
319                 virtual void setBackground(const Color & bg);
320                 virtual void setMouseCursor(RS2::CursorType c);
321                 virtual void updateGridStatusWidget(const QString & text);
322
323         protected:
324                 virtual void emulateMouseMoveEvent();
325                 virtual void mousePressEvent(QMouseEvent * e);
326                 virtual void mouseReleaseEvent(QMouseEvent * e);
327                 virtual void mouseMoveEvent(QMouseEvent * e);
328                 virtual void tabletEvent(QTabletEvent * e);
329                 virtual void leaveEvent(QEvent *);
330                 virtual void enterEvent(QEvent *);
331                 virtual void focusInEvent(QFocusEvent *);
332                 virtual void focusOutEvent(QFocusEvent *);
333                 virtual void wheelEvent(QWheelEvent * e);
334                 virtual void keyPressEvent(QKeyEvent * e);
335                 virtual void keyReleaseEvent(QKeyEvent * e);
336
337                 void paintEvent(QPaintEvent *);
338                 virtual void resizeEvent(QResizeEvent * e);
339
340         private slots:
341                 void slotHScrolled(int value);
342                 void slotVScrolled(int value);
343 };
344 #endif