QCAD
Open Source 2D CAD
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 clear() {}
76  void clearCaches();
77 
78  void setDisplayOnlyCurrentUcs(bool on);
79 
80  virtual void setScene(RGraphicsScene* scene, bool regen=true);
81  RGraphicsScene* getScene();
82  RDocument* getDocument() const;
84 
91  virtual RVector mapFromView(const RVector& v, double z=0.0) const = 0;
92 
96  virtual RVector mapToView(const RVector& v) const = 0;
97  virtual RBox mapToView(const RBox& box) const;
98 
103  virtual double mapDistanceFromView(double d) const = 0;
104 
109  virtual double mapDistanceToView(double d) const = 0;
110 
111  virtual QList<RVector> mapCornersFromView() const;
112 
113  virtual RBox getBox() const;
114  virtual RVector getMinimum() const;
115  virtual RVector getMaximum() const;
116 
117  virtual void handleTerminateEvent(RTerminateEvent& event);
118 
119  virtual void handleKeyPressEvent(QKeyEvent& event);
120  virtual void handleKeyReleaseEvent(QKeyEvent& event);
121  virtual void simulateMouseMoveEvent();
122  virtual void handleMouseMoveEvent(RMouseEvent& event);
123  virtual void handleMousePressEvent(RMouseEvent& event);
124  virtual void handleMouseReleaseEvent(RMouseEvent& event);
125  virtual void handleMouseDoubleClickEvent(RMouseEvent& event);
126  virtual void handleWheelEvent(RWheelEvent& event);
127  virtual void handleTabletEvent(RTabletEvent& event);
128  virtual void handleSwipeGestureEvent(QSwipeGesture& gesture);
129  virtual void handlePanGestureEvent(QPanGesture& gesture);
130  virtual void handlePinchGestureEvent(QPinchGesture& gesture);
131  virtual void giveFocus() = 0;
135  virtual bool hasFocus() = 0;
136  virtual void removeFocus() = 0;
137 
138  virtual void viewportChangeEvent();
139 
140  void saveViewport();
141  void restoreViewport();
142  void zoomIn();
143  void zoomOut();
144  void zoomIn(const RVector& center);
145  void zoomOut(const RVector& center);
146  virtual void zoom(const RVector& center, double factor);
147  virtual void zoomTo(const RBox& window, int margin = 0);
148  void zoomPrevious();
149  void autoZoom(int margin = RDEFAULT_MIN1, bool ignoreEmpty=false, bool ignoreLineweight=false);
150  bool zoomToSelection();
151 
152  virtual void centerToPoint(const RVector& point);
153  virtual void centerToBox(const RBox& box);
154  virtual void pan(const RVector& delta, bool regen=true);
155  void startPan();
156 
157  double getFactor(bool includeStepFactor=true) const;
158  void setFactor(double f, bool regen=true);
159 
160  RVector getOffset(bool includeStepOffset=true) const;
161  void setOffset(const RVector& offset, bool regen=true);
162 
171  virtual void regenerate(bool force=false) = 0;
172  virtual void regenerate(QSet<REntity::Id>& affectedEntities) {
173  Q_UNUSED(affectedEntities)
174 
175  regenerate(true);
176  }
177 
185  virtual void repaintView() = 0;
186 
190  virtual int getWidth() const = 0;
191 
195  virtual int getHeight() const = 0;
196 
201  virtual int isActive() const {
202  return true;
203  }
204 
205  virtual bool getSignalsBlocked() const {
206  return false;
207  }
208  virtual void setSignalsBlocked(bool on) {
209  Q_UNUSED(on)
210  return;
211  }
212 
213  void setNavigationAction(RAction* action);
214 
219  return grid;
220  }
221 
227  void setGrid(RGrid* g) {
228  if (grid!=NULL) {
229  delete grid;
230  grid = NULL;
231  }
232  grid = g;
233  }
234 
235  void setGridVisible(bool on);
236  bool isGridVisible() const;
237 
238  virtual void paintGridPoint(const RVector& /*ucsPosition*/) {}
239  virtual void paintGridLine(const RLine& /*ucsPosition*/) {}
240 
241  virtual QCursor getCursor() { return QCursor(Qt::ArrowCursor); }
242  virtual void setCursor(Qt::CursorShape /*cursorShape*/) {}
243  virtual void setCursor(const QCursor& /*cursor*/) {}
244 
245  RRefPoint getClosestReferencePoint(const RVector& screenPosition, int range);
246  RRefPoint getClosestReferencePoint(REntity::Id entityId, const RVector& screenPosition);
247  REntity::Id getClosestEntity(const RVector& screenPosition, int range, int strictRange, bool includeLockedLayers=true, bool selectedOnly = false);
248  //REntity::Id getClosestEntityInUcs(const RVector& screenPosition, int range);
249 
250  virtual void setBackgroundColor(const QColor& col);
251  QColor getBackgroundColor();
252 
253  int getMargin();
254  void setMargin(int m);
255 
256  void setPrinting(bool on);
257  bool isPrinting() const;
258  void setPrintPreview(bool on);
259  bool isPrintPreview() const;
260  void setPrintPointSize(const RVector& s);
261 
262  void setColorMode(RGraphicsView::ColorMode cm);
263  RGraphicsView::ColorMode getColorMode();
264 
265  void setHairlineMode(bool on);
266  bool getHairlineMode();
267 
268  QList<RTextLabel> getTextLabels();
269  void clearTextLabels();
270  void addTextLabel(const RTextLabel &textLabel);
271 
273  return lastKnownModelPosition;
274  }
275 
276  double getCurrentStepScaleFactor() const {
277  return currentStepScaleFactor;
278  }
279 
280  void setCurrentStepScaleFactor(double f) {
281  currentStepScaleFactor = f;
282  }
283 
285  return currentStepOffset;
286  }
287 
288  void setCurrentStepOffset(const RVector& s) {
289  currentStepOffset = s;
290  }
291 
293  textHeightThresholdOverride = v;
294  }
295 
297  return textHeightThresholdOverride;
298  }
299 
300  void updateTextHeightThreshold();
301 
302  bool isPathVisible(const RPainterPath& path) const;
303 
304  void setAntialiasing(bool val);
305  bool getAntialiasing() const;
306 
307  virtual double getDevicePixelRatio() const {
308  return 1.0;
309  }
310 
314  virtual bool isShared() const {
315  return false;
316  }
317 
322  virtual bool registerForFocus() const {
323  return false;
324  }
325 
326 protected:
327  bool printing;
330 
333 
338 
343 
349 
355 
359  double factor;
360 
363 
369 
371 
373  int margin;
374 
379 
383 
387  QList<RTextLabel> textLabels;
388 
389 
392 
394 
396 
397  // grid display flag, cached:
398  mutable int gridVisible;
399 
400  //RVector mousePressScreenPosition;
401  //RVector mousePressModelPosition;
402 };
403 
407 
408 #endif
Represents a box e.g.
Definition: RBox.h:43
bool displayOnlyCurrentUcs
True to only display entities within the horizontal slice that is defined by the current UCS...
Definition: RGraphicsView.h:368
RVector offset
Offset of the zero point from the lower left corner of the view in model coordinates.
Definition: RGraphicsView.h:354
bool autoScalePatterns
Definition: RGraphicsView.h:370
virtual void setSignalsBlocked(bool on)
Definition: RGraphicsView.h:208
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
RVector getCurrentStepOffset() const
Definition: RGraphicsView.h:284
A tablet event for a graphics scene.
Definition: RTabletEvent.h:43
virtual double getDevicePixelRatio() const
Definition: RGraphicsView.h:307
virtual void setCursor(const QCursor &)
Definition: RGraphicsView.h:243
Text label.
Definition: RTextLabel.h:42
RVector lastKnownModelPosition
Definition: RGraphicsView.h:381
Represents a reference point of an entity.
Definition: RRefPoint.h:18
Abstract base class for all graphics scenes.
Definition: RGraphicsScene.h:61
RGrid * grid
Grid that is currently displayed by this view or NULL.
Definition: RGraphicsView.h:342
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RNonCopyable.h:32
Definition: RGraphicsView.h:61
ColorMode colorMode
Definition: RGraphicsView.h:331
#define QCADCORE_EXPORT
Definition: core_global.h:10
int Id
Definition: RObject.h:57
bool printPreview
Definition: RGraphicsView.h:328
QColor backgroundColor
Definition: RGraphicsView.h:372
void setCurrentStepScaleFactor(double f)
Definition: RGraphicsView.h:280
RVector previousOffset
Definition: RGraphicsView.h:361
virtual bool registerForFocus() const
Reimplementations may return true to register this view and allow it to be returned by RDocumentInter...
Definition: RGraphicsView.h:322
double getCurrentStepScaleFactor() const
Definition: RGraphicsView.h:276
void setTextHeightThresholdOverride(int v)
Definition: RGraphicsView.h:292
RVector getLastKnownMousePosition() const
Definition: RGraphicsView.h:272
int gridVisible
Definition: RGraphicsView.h:398
void setCurrentStepOffset(const RVector &s)
Definition: RGraphicsView.h:288
ColorMode
Definition: RGraphicsView.h:60
Abstract base class for all action classes.
Definition: RAction.h:62
A graphics document contains and owns entities, layers, user coordinate systems, variables, block definitions, etc.
Definition: RDocument.h:67
void setGrid(RGrid *g)
Sets the current grid.
Definition: RGraphicsView.h:227
int getTextHeightThresholdOverride() const
Definition: RGraphicsView.h:296
Q_DECLARE_METATYPE(RMath *)
bool printing
Definition: RGraphicsView.h:327
QList< RTextLabel > textLabels
Internal list of text labels that were added to this view.
Definition: RGraphicsView.h:387
virtual bool getSignalsBlocked() const
Definition: RGraphicsView.h:205
Extended painter path with a z-level and a pen.
Definition: RPainterPath.h:46
A mouse event for a graphics scene.
Definition: RMouseEvent.h:42
void getDocument()
Returns the current RDocument or undefined.
Definition: simple.js:21
RVector currentStepOffset
Definition: RGraphicsView.h:380
virtual bool isShared() const
Reimplementations may return true to prevent this view from being deleted.
Definition: RGraphicsView.h:314
RVector printPointSize
Definition: RGraphicsView.h:329
int margin
Definition: RGraphicsView.h:373
virtual void paintGridLine(const RLine &)
Definition: RGraphicsView.h:239
Definition: RGraphicsView.h:62
Low-level mathematical representation of a line.
Definition: RLine.h:41
virtual void setCursor(Qt::CursorShape)
Definition: RGraphicsView.h:242
int getViewportNumber() const
Definition: RGraphicsView.h:71
#define RDEFAULT_MIN1
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RExplodable.h:30
int textHeightThreshold
Definition: RGraphicsView.h:391
double previousFactor
Definition: RGraphicsView.h:362
virtual void regenerate(QSet< REntity::Id > &affectedEntities)
Definition: RGraphicsView.h:172
void getDocumentInterface()
Returns the current RDocumentInterface or undefined.
Definition: simple.js:67
int viewportNumber
Definition: RGraphicsView.h:393
Abstract base class for grid implementations.
Definition: RGrid.h:39
Interface for interaction between a graphics document and a user.
Definition: RDocumentInterface.h:84
RGraphicsScene * scene
The scene this view is attached to.
Definition: RGraphicsView.h:337
RGrid * getGrid()
Definition: RGraphicsView.h:218
virtual void paintGridPoint(const RVector &)
Definition: RGraphicsView.h:238
void clear()
Definition: RGraphicsView.h:75
bool hairlineMode
Definition: RGraphicsView.h:332
void autoZoom()
Auto zoom.
Definition: simple_view.js:27
double factor
Scale factor from model coordinates to view coordinates.
Definition: RGraphicsView.h:359
virtual int isActive() const
Definition: RGraphicsView.h:201
double currentStepScaleFactor
Current scale factor caused by a pinch gesture.
Definition: RGraphicsView.h:378
int textHeightThresholdOverride
Definition: RGraphicsView.h:390
RVector lastKnownScreenPosition
Definition: RGraphicsView.h:382
bool antialiasing
Definition: RGraphicsView.h:395
virtual QCursor getCursor()
Definition: RGraphicsView.h:241
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RTerminateEvent.h:34
void zoomTo(void p1, void p2, void p3, void p4, void p5)
Zooms to the given entity.
Definition: simple_view.js:21
A mouse wheel event for a graphics scene.
Definition: RWheelEvent.h:41
RAction * navigationAction
The navigation action of this view or NULL if no navigation action has been set.
Definition: RGraphicsView.h:348
Graphics view.
Definition: RGraphicsView.h:58