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;
82  RDocumentInterface* getDocumentInterface();
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);
133  virtual bool hasFocus() = 0;
134  virtual void removeFocus() = 0;
135 
136  virtual void viewportChangeEvent();
137 
138  void saveViewport();
139  void restoreViewport();
140  void zoomIn();
141  void zoomOut();
142  void zoomIn(const RVector& center);
143  void zoomOut(const RVector& center);
144  virtual void zoom(const RVector& center, double factor);
145  virtual void zoomTo(const RBox& window, int margin = 0);
146  void zoomPrevious();
147  void autoZoom(int margin = RDEFAULT_MIN1, bool ignoreEmpty=false);
148  bool zoomToSelection();
149 
150  virtual void centerToPoint(const RVector& point);
151  virtual void centerToBox(const RBox& box);
152  virtual void pan(const RVector& delta, bool regen=true);
153  void startPan();
154 
155  double getFactor(bool includeStepFactor=true) const;
156  void setFactor(double f, bool regen=true);
157 
158  RVector getOffset(bool includeStepOffset=true) const;
159  void setOffset(const RVector& offset, bool regen=true);
160 
169  virtual void regenerate(bool force=false) = 0;
170 
178  virtual void repaintView() = 0;
179 
183  virtual int getWidth() const = 0;
184 
188  virtual int getHeight() const = 0;
189 
190  void setNavigationAction(RAction* action);
191 
196  return grid;
197  }
198 
204  void setGrid(RGrid* g) {
205  if (grid!=NULL) {
206  delete grid;
207  grid = NULL;
208  }
209  grid = g;
210  }
211 
212  void setGridVisible(bool on);
213  bool isGridVisible() const;
214 
215  virtual void paintGridPoint(const RVector& /*ucsPosition*/) {}
216  virtual void paintGridLine(const RLine& /*ucsPosition*/) {}
217 
218  virtual QCursor getCursor() { return QCursor(Qt::ArrowCursor); }
219  virtual void setCursor(Qt::CursorShape /*cursorShape*/) {}
220  virtual void setCursor(const QCursor& /*cursor*/) {}
221 
222  RVector getClosestReferencePoint(const RVector& screenPosition, int range);
223  RVector getClosestReferencePoint(REntity::Id entityId, const RVector& screenPosition);
224  REntity::Id getClosestEntity(const RVector& screenPosition, int range, int strictRange, bool includeLockedLayers=true);
225  //REntity::Id getClosestEntityInUcs(const RVector& screenPosition, int range);
226 
227  virtual void setBackgroundColor(const QColor& col);
228  QColor getBackgroundColor();
229 
230  int getMargin();
231  void setMargin(int m);
232 
233  void setPrinting(bool on);
234  bool isPrinting() const;
235  void setPrintPreview(bool on);
236  bool isPrintPreview() const;
237  void setPrintPointSize(const RVector& s);
238 
239  void setColorMode(RGraphicsView::ColorMode cm);
240  RGraphicsView::ColorMode getColorMode();
241 
242  void setHairlineMode(bool on);
243  bool getHairlineMode();
244 
245  QList<RTextLabel> getTextLabels();
246  void clearTextLabels();
247  void addTextLabel(const RTextLabel &textLabel);
248 
250  return lastKnownModelPosition;
251  }
252 
253  double getCurrentStepScaleFactor() const {
254  return currentStepScaleFactor;
255  }
256 
257  void setCurrentStepScaleFactor(double f) {
258  currentStepScaleFactor = f;
259  }
260 
262  return currentStepOffset;
263  }
264 
265  void setCurrentStepOffset(const RVector& s) {
266  currentStepOffset = s;
267  }
268 
270  textHeightThresholdOverride = v;
271  }
272 
274  return textHeightThresholdOverride;
275  }
276 
277  void updateTextHeightThreshold();
278 
279  bool isPathVisible(const RPainterPath& path) const;
280 
281 protected:
282  bool printing;
285 
288 
293 
298 
304 
310 
314  double factor;
315 
318 
324 
326 
328  int margin;
329 
334 
338 
342  QList<RTextLabel> textLabels;
343 
344 
347 
349 
350  // grid display flag, cached:
351  mutable int gridVisible;
352 };
353 
357 
358 #endif