]> Shamusworld >> Repos - architektonas/blob - src/mainapp/graphicview.h
96e16260a9f4156bc34f15bda47de4db4ec075ce
[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 "vector.h"
8
9 class Drawing;
10 class PaintInterface;
11 class RS_EntityContainer;
12 class RS_ActionInterface;
13 class RS_Entity;
14 class RS_LineTypePattern;
15 class RS_CommandEvent;
16 class Vector;
17 class RS_Preview;
18 class RS_Grid;
19 class RS_Pen;
20 class RS_EventHandler;
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                  * Sets an external painter device.
54                  */
55                 virtual void setPainter(PaintInterface * p);
56
57                 virtual void setBackground(const RS_Color & bg);
58                 RS_Color getBackground();
59                 RS_Color getForeground();
60                 void setGridColor(const RS_Color & c);
61                 void setMetaGridColor(const RS_Color & c);
62                 void setSelectedColor(const RS_Color & c);
63                 void setHighlightedColor(const RS_Color & c);
64                 virtual void setMouseCursor(RS2::CursorType /*c*/);
65                 void setContainer(RS_EntityContainer * container);
66                 RS_EntityContainer * getContainer();
67                 void setFactor(double f);
68                 void setFactorX(double f);
69                 void setFactorY(double f);
70                 Vector getFactor();
71                 void setOffset(int ox, int oy);
72                 void setOffsetX(int ox);
73                 void setOffsetY(int oy);
74                 int getOffsetX();
75                 int getOffsetY();
76                 void centerOffsetX();
77                 void centerOffsetY();
78                 void centerX(double x);
79                 void centerY(double y);
80                 virtual void updateView();
81                 void setBorders(int left, int top, int right, int bottom);
82                 int getBorderLeft();
83                 int getBorderTop();
84                 int getBorderRight();
85                 int getBorderBottom();
86                 void disableUpdate();
87                 void enableUpdate();
88                 bool isUpdateEnabled();
89                 void freezeZoom(bool freeze);
90                 bool isZoomFrozen();
91
92                 void setDefaultAction(RS_ActionInterface * action);
93                 RS_ActionInterface *  getDefaultAction();
94                 void setCurrentAction(RS_ActionInterface * action);
95                 RS_ActionInterface * getCurrentAction();
96
97                 void killSelectActions();
98                 void killAllActions();
99
100                 /**
101                  * Must be overwritten to emulate a mouse move event with
102                  * the last known mouse position.
103                  *
104                  * @see mx, my
105                  */
106                 virtual void emulateMouseMoveEvent() = 0;
107
108                 void back();
109                 void enter();
110
111                 void mousePressEvent(QMouseEvent * e);
112                 void mouseReleaseEvent(QMouseEvent * e);
113                 void mouseMoveEvent(QMouseEvent * e);
114                 void mouseLeaveEvent();
115                 void mouseEnterEvent();
116                 void keyPressEvent(QKeyEvent * e);
117                 void keyReleaseEvent(QKeyEvent * e);
118                 void commandEvent(RS_CommandEvent * e);
119                 void enableCoordinateInput();
120                 void disableCoordinateInput();
121
122                 virtual void zoomIn(double f = 1.5, const Vector & center = Vector(false));
123                 virtual void zoomInX(double f = 1.5);
124                 virtual void zoomInY(double f = 1.5);
125                 virtual void zoomOut(double f = 1.5, const Vector & center = Vector(false));
126                 virtual void zoomOutX(double f = 1.5);
127                 virtual void zoomOutY(double f = 1.5);
128                 virtual void zoomAuto(bool axis = true, bool keepAspectRatio = true);
129                 virtual void zoomAutoY(bool axis = true);
130                 virtual void zoomPrevious();
131                 virtual void saveView();
132                 virtual void restoreView();
133                 virtual void zoomWindow(Vector v1, Vector v2, bool keepAspectRatio = true);
134                 //virtual void zoomPan(Vector v1);
135                 virtual void zoomPan(int dx, int dy);
136                 virtual void zoomScroll(RS2::Direction direction);
137                 virtual void zoomPage();
138
139                 virtual void drawWindow(Vector v1, Vector v2);
140                 virtual void drawIt();
141                 virtual void deleteEntity(RS_Entity * e);
142                 virtual void drawEntity(RS_Entity * e, double patternOffset = 0.0, bool db = false);
143                 virtual void drawEntityPlain(RS_Entity * e, double patternOffset = 0.0);
144                 virtual void setPenForEntity(RS_Entity * e);
145
146                 void simulateIt();
147                 void simulateEntity(RS_Entity * e, const RS_Pen & pen);
148                 void drawLineSmooth(const Vector & p1, const Vector & p2, const RS_Pen & pen);
149                 void drawArcSmooth(const Vector & center, double radius,
150                         double a1, double a2, bool rev, const RS_Pen & pen);
151                 void simulationDelay(bool step = false);
152
153                 virtual RS_LineTypePattern * getPattern(RS2::LineType t);
154
155                 virtual void drawAbsoluteZero();
156                 virtual void drawRelativeZero();
157                 virtual void drawPaper();
158                 virtual void drawGrid();
159                 virtual void drawMetaGrid();
160                 virtual void updateGrid();
161                 RS_Grid * getGrid();
162                 virtual void updateGridStatusWidget(const QString & /*text*/);
163
164                 void setDefaultSnapMode(RS2::SnapMode sm);
165                 RS2::SnapMode getDefaultSnapMode();
166                 void setSnapRestriction(RS2::SnapRestriction sr);
167                 RS2::SnapRestriction getSnapRestriction();
168                 bool isGridOn();
169
170                 Vector toGui(Vector v);
171                 double toGuiX(double x, bool * visible = NULL);
172                 double toGuiY(double y);
173                 double toGuiDX(double d);
174                 double toGuiDY(double d);
175
176                 Vector toGraph(Vector v);
177                 Vector toGraph(int x, int y);
178                 double toGraphX(int x);
179                 double toGraphY(int y);
180                 double toGraphDX(int d);
181                 double toGraphDY(int d);
182
183                 void lockRelativeZero(bool lock);
184                 bool isRelativeZeroLocked();
185                 Vector getRelativeZero();
186                 void setRelativeZero(const Vector & pos);
187                 void moveRelativeZero(const Vector & pos);
188
189                 RS_EventHandler * getEventHandler();
190                 void setPrintPreview(bool pv);
191                 bool isPrintPreview();
192                 void setPrinting(bool p);
193                 bool isPrinting();
194                 bool isDraftMode();
195                 void setSimulationSpeed(int s);
196                 int getSimulationSpeed();
197                 void setSimulationSmooth(bool s);
198                 void setSimulationRapid(bool r);
199                 bool getSimulationRapid();
200
201                 //this is here because of crappy braindead infrastructure
202                 void SetPreviewMode(bool mode = true);
203                 void SetPreviewEntity(RS_Preview *);
204                 void SetPreviewOffset(Vector);
205                 void SetSnapperDraw(bool);
206                 void SetSnapperVars(Vector snapSpot, Vector snapCoord, bool showCrosshairs);
207
208         protected:
209                 RS_EntityContainer * container;
210                 RS_EventHandler * eventHandler;
211
212                 int mx;   //!< Last known mouse cursor position
213                 int my;   //!< Last known mouse cursor position
214
215                 PaintInterface * painter;
216                 /** background color (any color) */
217                 RS_Color background;
218                 /** foreground color (black or white) */
219                 RS_Color foreground;
220                 /** grid color */
221                 RS_Color gridColor;
222                 /** meta grid color */
223                 RS_Color metaGridColor;
224                 /** selected color */
225                 RS_Color selectedColor;
226                 /** highlighted color */
227                 RS_Color highlightedColor;
228                 /** Grid */
229                 RS_Grid * grid;
230                 /**
231                 * Current default snap mode for this graphic view. Used for new
232                 * actions.
233                 */
234                 RS2::SnapMode defaultSnapMode;
235                 /**
236                 * Current default snap restriction for this graphic view. Used for new
237                 * actions.
238                 */
239                 RS2::SnapRestriction defaultSnapRes;
240
241                 RS2::DrawingMode drawingMode;
242
243                 /**
244                 * Delete mode. If true, all drawing actions will delete in background color
245                 * instead.
246                 */
247                 bool deleteMode;
248                 //! If true, the simulation is currectly running
249                 bool simulationRunning;
250
251         private:
252                 int updateEnabled;
253                 bool zoomFrozen;
254                 bool draftMode;
255
256                 Vector factor;
257                 int offsetX;
258                 int offsetY;
259
260                 Vector previousFactor;
261                 int previousOffsetX;
262                 int previousOffsetY;
263
264                 int borderLeft;
265                 int borderTop;
266                 int borderRight;
267                 int borderBottom;
268
269                 Vector relativeZero;
270                 bool relativeZeroLocked;
271                 //! Print preview flag
272                 bool printPreview;
273                 //! Active when printing only:
274                 bool printing;
275
276                 //! Simulation speed in percentage
277                 int simulationSpeed;
278                 //! If true, the entity is drawn slowly (pixel by pixel).
279                 bool simulationSmooth;
280                 //! If true, the way between entities is also shown.
281                 bool simulationRapid;
282                 //! Last position (for rapid move)
283                 Vector simulationLast;
284
285         protected:
286                 // crap to make painting with update() possible
287                 RS_Preview * previewEntity;
288                 bool previewMode;
289                 Vector previewOffset;
290                 bool snapperDraw;
291                 Vector snapSpot1;
292                 Vector snapCoord1;
293                 bool showCrosshairs1;
294
295 //QG
296
297
298 //QC
299 };
300
301 #endif  // __GRAPHICVIEW_H__
302
303 #if 0
304 class QG_GraphicView: public QWidget, public RS_GraphicView, //public Q3FilePreview,
305         public RS_LayerListListener, public RS_BlockListListener
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 RS_Painter * createPainter();
319 //              virtual RS_Painter * createDirectPainter();
320 #warning "!!! Need to scrub out all instances of createPainter and createDirectPainter !!!"
321 //              virtual PaintInterface * createPainter();
322 //              virtual PaintInterface * createDirectPainter();
323 //              virtual void destroyPainter();
324                 virtual void setBackground(const RS_Color & bg);
325                 virtual void setMouseCursor(RS2::CursorType c);
326                 virtual void updateGridStatusWidget(const QString & text);
327
328                 // Methods from RS_LayerListListener Interface:
329                 virtual void layerEdited(RS_Layer *);
330                 virtual void layerRemoved(RS_Layer *);
331                 virtual void layerToggled(RS_Layer *);
332
333         protected:
334                 virtual void emulateMouseMoveEvent();
335                 virtual void mousePressEvent(QMouseEvent * e);
336                 virtual void mouseReleaseEvent(QMouseEvent * e);
337                 virtual void mouseMoveEvent(QMouseEvent * e);
338                 virtual void tabletEvent(QTabletEvent * e);
339                 virtual void leaveEvent(QEvent *);
340                 virtual void enterEvent(QEvent *);
341                 virtual void focusInEvent(QFocusEvent *);
342                 virtual void focusOutEvent(QFocusEvent *);
343                 virtual void wheelEvent(QWheelEvent * e);
344                 virtual void keyPressEvent(QKeyEvent * e);
345                 virtual void keyReleaseEvent(QKeyEvent * e);
346
347                 void paintEvent(QPaintEvent *);
348                 virtual void resizeEvent(QResizeEvent * e);
349
350 #warning "!!! File preview needs porting to Qt4 !!!"
351 //              void previewUrl(const Q3Url &u);
352
353         private slots:
354                 void slotHScrolled(int value);
355                 void slotVScrolled(int value);
356
357         private:
358 #warning "!!! Double buffering is not necessary anymore !!!"
359                 //! Buffer for double-buffering
360                 QPixmap * buffer;
361 //              int refCount;
362
363         protected:
364                 int lastWidth;
365                 int lastHeight;
366                 //! Horizontal scrollbar.
367                 QG_ScrollBar * hScrollBar;
368                 //! Vertical scrollbar.
369                 QG_ScrollBar * vScrollBar;
370                 //! Layout used to fit in the view and the scrollbars.
371                 QGridLayout * layout;
372                 //! Label for grid spacing.
373                 QLabel * gridStatus;
374                 //! CAD mouse cursor
375                 QCursor * curCad;
376                 //! Delete mouse cursor
377                 QCursor * curDel;
378                 //! Select mouse cursor
379                 QCursor * curSelect;
380                 //! Magnifying glass mouse cursor
381                 QCursor * curMagnifier;
382                 //! Hand mouse cursor
383                 QCursor * curHand;
384 };
385 #endif
386
387 #if 0
388 class QC_GraphicView: public QG_GraphicView
389 {
390         public:
391                 QC_GraphicView(RS_Document * doc, QWidget * parent = 0);
392                 virtual ~QC_GraphicView();
393
394                 virtual void drawIt();
395
396         private:
397                 //RS_Document* document;
398 };
399 #endif