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