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