QCAD
Open Source 2D CAD
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RGraphicsView.h
Go to the documentation of this file.
1 
20 #ifndef RGRAPHICSVIEW_H
21 #define RGRAPHICSVIEW_H
22 
23 #include "core_global.h"
24 
25 #include <QKeyEvent>
26 #include <QCursor>
27 #include <QSwipeGesture>
28 #include <QPanGesture>
29 #include <QPinchGesture>
30 
31 #include "RExporter.h"
32 #include "RGrid.h"
33 #include "RNonCopyable.h"
34 #include "RTextLabel.h"
35 #include "RTerminateEvent.h"
36 
37 class RAction;
38 class RDocumentInterface;
39 class RGraphicsScene;
40 class RLine;
41 class RMouseEvent;
42 class RTabletEvent;
43 class RWheelEvent;
44 
45 #ifndef RDEFAULT_MIN1
46 #define RDEFAULT_MIN1 -1
47 #endif
48 
49 
59 public:
60  enum ColorMode {
63  BlackWhite
64  };
65 
66 public:
67  RGraphicsView(RGraphicsScene* scene = NULL);
68  virtual ~RGraphicsView();
69 
70  void setViewportNumber(int n);
71  int getViewportNumber() const {
72  return viewportNumber;
73  }
74 
75  void clearCaches();
76 
77  void setDisplayOnlyCurrentUcs(bool on);
78 
79  virtual void setScene(RGraphicsScene* scene, bool regen=true);
80  RGraphicsScene* getScene();
81  RDocument* getDocument() const;
83 
90  virtual RVector mapFromView(const RVector& v, double z=0.0) const = 0;
91 
95  virtual RVector mapToView(const RVector& v) const = 0;
96  virtual RBox mapToView(const RBox& box) const;
97 
102  virtual double mapDistanceFromView(double d) const = 0;
103 
108  virtual double mapDistanceToView(double d) const = 0;
109 
110  virtual QList<RVector> mapCornersFromView() const;
111 
112  virtual RBox getBox() const;
113  virtual RVector getMinimum() const;
114  virtual RVector getMaximum() const;
115 
116  virtual void handleTerminateEvent(RTerminateEvent& event);
117 
118  virtual void handleKeyPressEvent(QKeyEvent& event);
119  virtual void handleKeyReleaseEvent(QKeyEvent& event);
120  virtual void simulateMouseMoveEvent();
121  virtual void handleMouseMoveEvent(RMouseEvent& event);
122  virtual void handleMousePressEvent(RMouseEvent& event);
123  virtual void handleMouseReleaseEvent(RMouseEvent& event);
124  virtual void handleMouseDoubleClickEvent(RMouseEvent& event);
125  virtual void handleWheelEvent(RWheelEvent& event);
126  virtual void handleTabletEvent(RTabletEvent& event);
127  virtual void handleSwipeGestureEvent(QSwipeGesture& gesture);
128  virtual void handlePanGestureEvent(QPanGesture& gesture);
129  virtual void handlePinchGestureEvent(QPinchGesture& gesture);
130  virtual void giveFocus() = 0;
134  virtual bool hasFocus() = 0;
135  virtual void removeFocus() = 0;
136 
137  virtual void viewportChangeEvent();
138 
139  void saveViewport();
140  void restoreViewport();
141  void zoomIn();
142  void zoomOut();
143  void zoomIn(const RVector& center);
144  void zoomOut(const RVector& center);
145  virtual void zoom(const RVector& center, double factor);
146  virtual void zoomTo(const RBox& window, int margin = 0);
147  void zoomPrevious();
148  void autoZoom(int margin = RDEFAULT_MIN1, bool ignoreEmpty=false);
149  bool zoomToSelection();
150 
151  virtual void centerToPoint(const RVector& point);
152  virtual void centerToBox(const RBox& box);
153  virtual void pan(const RVector& delta, bool regen=true);
154  void startPan();
155 
156  double getFactor(bool includeStepFactor=true) const;
157  void setFactor(double f, bool regen=true);
158 
159  RVector getOffset(bool includeStepOffset=true) const;
160  void setOffset(const RVector& offset, bool regen=true);
161 
170  virtual void regenerate(bool force=false) = 0;
171 
179  virtual void repaintView() = 0;
180 
184  virtual int getWidth() const = 0;
185 
189  virtual int getHeight() const = 0;
190 
191  void setNavigationAction(RAction* action);
192 
197  return grid;
198  }
199 
205  void setGrid(RGrid* g) {
206  if (grid!=NULL) {
207  delete grid;
208  grid = NULL;
209  }
210  grid = g;
211  }
212 
213  void setGridVisible(bool on);
214  bool isGridVisible() const;
215 
216  virtual void paintGridPoint(const RVector& /*ucsPosition*/) {}
217  virtual void paintGridLine(const RLine& /*ucsPosition*/) {}
218 
219  virtual QCursor getCursor() { return QCursor(Qt::ArrowCursor); }
220  virtual void setCursor(Qt::CursorShape /*cursorShape*/) {}
221  virtual void setCursor(const QCursor& /*cursor*/) {}
222 
223  RVector getClosestReferencePoint(const RVector& screenPosition, int range);
224  RVector getClosestReferencePoint(REntity::Id entityId, const RVector& screenPosition);
225  REntity::Id getClosestEntity(const RVector& screenPosition, int range, int strictRange, bool includeLockedLayers=true);
226  //REntity::Id getClosestEntityInUcs(const RVector& screenPosition, int range);
227 
228  virtual void setBackgroundColor(const QColor& col);
229  QColor getBackgroundColor();
230 
231  int getMargin();
232  void setMargin(int m);
233 
234  void setPrinting(bool on);
235  bool isPrinting() const;
236  void setPrintPreview(bool on);
237  bool isPrintPreview() const;
238  void setPrintPointSize(const RVector& s);
239 
240  void setColorMode(RGraphicsView::ColorMode cm);
241  RGraphicsView::ColorMode getColorMode();
242 
243  void setHairlineMode(bool on);
244  bool getHairlineMode();
245 
246  QList<RTextLabel> getTextLabels();
247  void clearTextLabels();
248  void addTextLabel(const RTextLabel &textLabel);
249 
251  return lastKnownModelPosition;
252  }
253 
254  double getCurrentStepScaleFactor() const {
255  return currentStepScaleFactor;
256  }
257 
258  void setCurrentStepScaleFactor(double f) {
259  currentStepScaleFactor = f;
260  }
261 
263  return currentStepOffset;
264  }
265 
266  void setCurrentStepOffset(const RVector& s) {
267  currentStepOffset = s;
268  }
269 
271  textHeightThresholdOverride = v;
272  }
273 
275  return textHeightThresholdOverride;
276  }
277 
278  void updateTextHeightThreshold();
279 
280  bool isPathVisible(const RPainterPath& path) const;
281 
282  void setAntialiasing(bool val);
283  bool getAntialiasing() const;
284 
285 protected:
286  bool printing;
289 
292 
297 
302 
308 
314 
318  double factor;
319 
322 
328 
330 
332  int margin;
333 
338 
342 
346  QList<RTextLabel> textLabels;
347 
348 
351 
353 
355 
356  // grid display flag, cached:
357  mutable int gridVisible;
358 };
359 
363 
364 #endif