QCAD Application Framework
CAD Application Development and Automation.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RGraphicsView.h
Go to the documentation of this file.
1 #ifndef RGRAPHICSVIEW_H
2 #define RGRAPHICSVIEW_H
3 
4 #include <QKeyEvent>
5 #include <QCursor>
6 #include <QSwipeGesture>
7 #include <QPanGesture>
8 #include <QPinchGesture>
9 
10 #include "RExporter.h"
11 #include "RGrid.h"
12 #include "RNonCopyable.h"
13 #include "RTextLabel.h"
14 #include "RTerminateEvent.h"
15 
16 class RAction;
17 class RDocumentInterface;
18 class RGraphicsScene;
19 class RLine;
20 class RMouseEvent;
21 class RTabletEvent;
22 class RWheelEvent;
23 
24 #ifndef RDEFAULT_MIN1
25 #define RDEFAULT_MIN1 -1
26 #endif
27 
28 
38 public:
39  enum ColorMode {
43  };
44 
45 public:
47  virtual ~RGraphicsView();
48 
49  void setDisplayOnlyCurrentUcs(bool on);
50 
51  virtual void setScene(RGraphicsScene* scene, bool regen=true);
53  RDocument* getDocument() const;
55 
62  virtual RVector mapFromView(const RVector& v, double z=0.0) const = 0;
63 
67  virtual RVector mapToView(const RVector& v) const = 0;
68  virtual RBox mapToView(const RBox& box) const;
69 
74  virtual double mapDistanceFromView(double d) const = 0;
75 
80  virtual double mapDistanceToView(double d) const = 0;
81 
82  virtual QList<RVector> mapCornersFromView() const;
83 
84  virtual RBox getBox() const;
85  virtual RVector getMinimum() const;
86  virtual RVector getMaximum() const;
87 
88  virtual void handleTerminateEvent(RTerminateEvent& event);
89 
90  virtual void handleKeyPressEvent(QKeyEvent& event);
91  virtual void handleKeyReleaseEvent(QKeyEvent& event);
92  virtual void simulateMouseMoveEvent();
93  virtual void handleMouseMoveEvent(RMouseEvent& event);
94  virtual void handleMousePressEvent(RMouseEvent& event);
95  virtual void handleMouseReleaseEvent(RMouseEvent& event);
96  virtual void handleMouseDoubleClickEvent(RMouseEvent& event);
97  virtual void handleWheelEvent(RWheelEvent& event);
98  virtual void handleTabletEvent(RTabletEvent& event);
99  virtual void handleSwipeGestureEvent(QSwipeGesture& gesture);
100  virtual void handlePanGestureEvent(QPanGesture& gesture);
101  virtual void handlePinchGestureEvent(QPinchGesture& gesture);
105  virtual bool hasFocus() = 0;
106  virtual void removeFocus() = 0;
107 
108  virtual void viewportChangeEvent();
109 
110  void saveViewport();
111  void restoreViewport();
112  void zoomIn();
113  void zoomOut();
114  void zoomIn(const RVector& center);
115  void zoomOut(const RVector& center);
116  virtual void zoom(const RVector& center, double factor);
117  virtual void zoomTo(const RBox& window, int margin = 0);
118  void zoomPrevious();
119  void autoZoom(int margin = RDEFAULT_MIN1);
120  bool zoomToSelection();
121 
122  virtual void pan(const RVector& delta);
123  void startPan();
124 
125  double getFactor(bool includeStepFactor=true) const;
126  void setFactor(double f, bool regen=true);
127 
128  RVector getOffset(bool includeStepOffset=true) const;
129  void setOffset(const RVector& offset, bool regen=true);
130 
139  virtual void regenerate(bool force=false) = 0;
140 
148  virtual void repaintView() = 0;
149 
153  virtual int getWidth() const = 0;
154 
158  virtual int getHeight() const = 0;
159 
160  void setNavigationAction(RAction* action);
161 
166  return grid;
167  }
168 
174  void setGrid(RGrid* g) {
175  if (grid!=NULL) {
176  delete grid;
177  grid = NULL;
178  }
179  grid = g;
180  }
181 
182  void setGridVisible(bool on) {
183  gridVisible = on;
184  }
185 
186  bool isGridVisible() const {
187  return gridVisible;
188  }
189 
190  void setDraftMode(bool on);
191  bool getDraftMode() const {
192  return draftMode;
193  }
194 
195  virtual void paintGridPoint(const RVector& /*ucsPosition*/) {}
196  virtual void paintMetaGridLine(const RLine& /*ucsPosition*/) {}
197 
198  virtual QCursor getCursor() { return QCursor(Qt::ArrowCursor); }
199  virtual void setCursor(Qt::CursorShape /*cursorShape*/) {}
200  virtual void setCursor(const QCursor& /*cursor*/) {}
201 
202  RVector getClosestReferencePoint(const RVector& screenPosition, int range);
203  RVector getClosestReferencePoint(REntity::Id entityId, const RVector& screenPosition);
204  REntity::Id getClosestEntity(const RVector& screenPosition, int range, bool includeLockedLayers=true);
205  //REntity::Id getClosestEntityInUcs(const RVector& screenPosition, int range);
206 
207  virtual void setBackgroundColor(const QColor& col);
208  QColor getBackgroundColor();
209 
210  int getMargin();
211  void setMargin(int m);
212 
213  void setPrinting(bool on);
214  bool isPrinting() const;
215  void setPrintPreview(bool on);
216  bool isPrintPreview() const;
217  void setPrintPointSize(const RVector& s);
218 
221 
222  QList<RTextLabel> getTextLabels();
223  void clearTextLabels();
224  void addTextLabel(const RTextLabel &textLabel);
225 
227  return lastKnownModelPosition;
228  }
229 
230  double getCurrentStepScaleFactor() const {
231  return currentStepScaleFactor;
232  }
233 
234  void setCurrentStepScaleFactor(double f) {
236  }
237 
239  return currentStepOffset;
240  }
241 
242  void setCurrentStepOffset(const RVector& s) {
243  currentStepOffset = s;
244  }
245 
246 protected:
247  virtual void centerTo(const RBox& box);
248 
249 protected:
250  bool printing;
253 
255 
260 
265 
271 
277 
281  double factor;
282 
285 
291 
293 
295  int margin;
296 
301 
305 
309  QList<RTextLabel> textLabels;
310 
312  bool draftMode;
313 
314  // for simulation: 0.0...1.0:
315  //int maxEntities;
316  //REntity::Id nextEntityId;
317 };
318 
322 
323 #endif