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() const;
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, double factor=1.2);
145  void zoomOut(const RVector& center, double factor=1.2);
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(int margin = RDEFAULT_MIN1);
151  bool zoomToEntities(const QSet<REntity::Id>& ids, int margin = RDEFAULT_MIN1);
152 
153  virtual void centerToPoint(const RVector& point);
154  virtual void centerToBox(const RBox& box);
155  virtual void pan(const RVector& delta, bool regen=true);
156  void startPan();
157 
158  double getFactor(bool includeStepFactor=true) const;
159  void setFactor(double f, bool regen=true);
160 
161  RVector getOffset(bool includeStepOffset=true) const;
162  void setOffset(const RVector& offset, bool regen=true);
163 
172  virtual void regenerate(bool force=false) = 0;
173  virtual void regenerate(QSet<REntity::Id>& affectedEntities) {
174  Q_UNUSED(affectedEntities)
175 
176  regenerate(true);
177  }
178 
186  virtual void repaintView() = 0;
187 
191  virtual int getWidth() const = 0;
192 
196  virtual int getHeight() const = 0;
197 
202  virtual int isActive() const {
203  return true;
204  }
205 
206  virtual bool getSignalsBlocked() const {
207  return false;
208  }
209  virtual void setSignalsBlocked(bool on) {
210  Q_UNUSED(on)
211  return;
212  }
213 
214  void setNavigationAction(RAction* action);
215 
220  return grid;
221  }
222 
228  void setGrid(RGrid* g) {
229  if (grid!=NULL) {
230  delete grid;
231  grid = NULL;
232  }
233  grid = g;
234  }
235 
236  void setGridVisible(bool on);
237  bool isGridVisible() const;
238 
239  virtual void paintGridPoint(const RVector& /*ucsPosition*/) {}
240  virtual void paintGridLine(const RLine& /*ucsPosition*/) {}
241 
242  virtual QCursor getCursor() { return QCursor(Qt::ArrowCursor); }
243  virtual void setCursor(Qt::CursorShape /*cursorShape*/) {}
244  virtual void setCursor(const QCursor& /*cursor*/) {}
245 
246  RRefPoint getClosestReferencePoint(const RVector& screenPosition, int range);
247  RRefPoint getClosestReferencePoint(REntity::Id entityId, const RVector& screenPosition);
248  REntity::Id getClosestEntity(const RVector& screenPosition, int range, int strictRange, bool includeLockedLayers=true, bool selectedOnly = false);
249  //REntity::Id getClosestEntityInUcs(const RVector& screenPosition, int range);
250 
251  virtual void setBackgroundColor(const QColor& col);
252  QColor getBackgroundColor();
253 
254  int getMargin();
255  void setMargin(int m);
256 
257  void setExporting(bool on);
258  bool isExporting() const;
259 
260  bool isPrintingOrExporting() const;
261 
262  void setPrinting(bool on);
263  bool isPrinting() const;
264  void setPrintPreview(bool on);
265  bool isPrintPreview() const;
266  void setPrintPointSize(const RVector& s);
267 
268  void setColorMode(RGraphicsView::ColorMode cm);
269  RGraphicsView::ColorMode getColorMode();
270 
271  void setHairlineMode(bool on);
272  bool getHairlineMode();
273 
274  void setHairlineMinimumMode(bool on);
275  bool getHairlineMinimumMode();
276 
277  QList<RTextLabel> getTextLabels();
278  void clearTextLabels();
279  void addTextLabel(const RTextLabel &textLabel);
280 
282  return lastKnownModelPosition;
283  }
284 
285  double getCurrentStepScaleFactor() const {
286  return currentStepScaleFactor;
287  }
288 
289  void setCurrentStepScaleFactor(double f) {
290  currentStepScaleFactor = f;
291  }
292 
294  return currentStepOffset;
295  }
296 
297  void setCurrentStepOffset(const RVector& s) {
298  currentStepOffset = s;
299  }
300 
302  textHeightThresholdOverride = v;
303  }
304 
306  return textHeightThresholdOverride;
307  }
308 
309  void updateTextHeightThreshold();
310 
311  bool isPathVisible(const RPainterPath& path) const;
312 
313  void setAntialiasing(bool val);
314  bool getAntialiasing() const;
315 
316  virtual double getDevicePixelRatio() const {
317  return 1.0;
318  }
319 
323  virtual bool isShared() const {
324  return false;
325  }
326 
331  virtual bool registerForFocus() const {
332  return false;
333  }
334 
335 protected:
336  bool exporting;
337  bool printing;
340 
344 
349 
354 
360 
366 
370  double factor;
371 
374 
380 
382 
384  int margin;
385 
390 
394 
398  QList<RTextLabel> textLabels;
399 
400 
403 
405 
407 
408  // grid display flag, cached:
409  mutable int gridVisible;
410 
411  //RVector mousePressScreenPosition;
412  //RVector mousePressModelPosition;
413 };
414 
417 Q_DECLARE_METATYPE(QList<RGraphicsView*>)
418 
419 #endif
RGraphicsView::previousOffset
RVector previousOffset
Definition: RGraphicsView.h:372
RGraphicsView::printing
bool printing
Definition: RGraphicsView.h:337
RGraphicsView::printPointSize
RVector printPointSize
Definition: RGraphicsView.h:339
RGraphicsView::getWidth
virtual int getWidth() const =0
RNonCopyable
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RNonCopyable.h:32
RGraphicsView::setCursor
virtual void setCursor(Qt::CursorShape)
Definition: RGraphicsView.h:243
RGraphicsView::currentStepOffset
RVector currentStepOffset
Definition: RGraphicsView.h:391
getDocument
void getDocument()
Returns the current RDocument or undefined.
Definition: simple.js:59
RGraphicsView::regenerate
virtual void regenerate(QSet< REntity::Id > &affectedEntities)
Definition: RGraphicsView.h:173
RGraphicsView::getLastKnownMousePosition
RVector getLastKnownMousePosition() const
Definition: RGraphicsView.h:281
RGraphicsView::isActive
virtual int isActive() const
Definition: RGraphicsView.h:202
RGraphicsView::getGrid
RGrid * getGrid()
Definition: RGraphicsView.h:219
RMouseEvent
A mouse event for a graphics scene.
Definition: RMouseEvent.h:42
RGraphicsView::paintGridPoint
virtual void paintGridPoint(const RVector &)
Definition: RGraphicsView.h:239
zoomTo
void zoomTo(void p1, void p2, void p3, void p4, void p5)
Zooms to the given entity.
Definition: simple_view.js:27
RRefPoint
Represents a reference point of an entity.
Definition: RRefPoint.h:18
RGraphicsView::giveFocus
virtual void giveFocus()=0
RGraphicsView::GrayScale
@ GrayScale
Definition: RGraphicsView.h:62
RGraphicsView::previousFactor
double previousFactor
Definition: RGraphicsView.h:373
RGraphicsView::viewportNumber
int viewportNumber
Definition: RGraphicsView.h:404
RGraphicsView::textLabels
QList< RTextLabel > textLabels
Internal list of text labels that were added to this view.
Definition: RGraphicsView.h:398
RGraphicsView::margin
int margin
Definition: RGraphicsView.h:384
RVector
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
RGraphicsView::FullColor
@ FullColor
Definition: RGraphicsView.h:61
RTerminateEvent
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RTerminateEvent.h:34
RGraphicsView::factor
double factor
Scale factor from model coordinates to view coordinates.
Definition: RGraphicsView.h:370
RGraphicsView::getSignalsBlocked
virtual bool getSignalsBlocked() const
Definition: RGraphicsView.h:206
RGraphicsView::removeFocus
virtual void removeFocus()=0
RTextLabel.h
RGraphicsView::clear
void clear()
Definition: RGraphicsView.h:75
RGraphicsView::repaintView
virtual void repaintView()=0
Repaints the view (widget, etc..).
RGraphicsView::hasFocus
virtual bool hasFocus()=0
RGraphicsView::paintGridLine
virtual void paintGridLine(const RLine &)
Definition: RGraphicsView.h:240
RGraphicsView::scene
RGraphicsScene * scene
The scene this view is attached to.
Definition: RGraphicsView.h:348
RTabletEvent
A tablet event for a graphics scene.
Definition: RTabletEvent.h:43
RLine
Low-level mathematical representation of a line.
Definition: RLine.h:41
RGraphicsView::displayOnlyCurrentUcs
bool displayOnlyCurrentUcs
True to only display entities within the horizontal slice that is defined by the current UCS.
Definition: RGraphicsView.h:379
RGraphicsView::hairlineMode
bool hairlineMode
Definition: RGraphicsView.h:342
RGraphicsView::currentStepScaleFactor
double currentStepScaleFactor
Current scale factor caused by a pinch gesture.
Definition: RGraphicsView.h:389
RGraphicsView::offset
RVector offset
Offset of the zero point from the lower left corner of the view in model coordinates.
Definition: RGraphicsView.h:365
RGraphicsView::textHeightThresholdOverride
int textHeightThresholdOverride
Definition: RGraphicsView.h:401
RGraphicsView::textHeightThreshold
int textHeightThreshold
Definition: RGraphicsView.h:402
RGraphicsView::antialiasing
bool antialiasing
Definition: RGraphicsView.h:406
RGraphicsView::getCursor
virtual QCursor getCursor()
Definition: RGraphicsView.h:242
RGraphicsView::regenerate
virtual void regenerate(bool force=false)=0
Regenerates the view to show the visible parts of the underlying scene.
RGraphicsView::getDevicePixelRatio
virtual double getDevicePixelRatio() const
Definition: RGraphicsView.h:316
RGraphicsView::setSignalsBlocked
virtual void setSignalsBlocked(bool on)
Definition: RGraphicsView.h:209
RNonCopyable.h
RGraphicsView::setCursor
virtual void setCursor(const QCursor &)
Definition: RGraphicsView.h:244
RGraphicsView
Graphics view.
Definition: RGraphicsView.h:58
RGraphicsView::mapDistanceFromView
virtual double mapDistanceFromView(double d) const =0
Maps the given view distance in pixels to a model distance.
RGraphicsView::getHeight
virtual int getHeight() const =0
getDocumentInterface
void getDocumentInterface()
Returns the current RDocumentInterface or undefined.
Definition: simple.js:80
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(RMath *)
RGraphicsView::grid
RGrid * grid
Grid that is currently displayed by this view or NULL.
Definition: RGraphicsView.h:353
RWheelEvent
A mouse wheel event for a graphics scene.
Definition: RWheelEvent.h:41
RAction
Abstract base class for all action classes.
Definition: RAction.h:62
RDEFAULT_MIN1
#define RDEFAULT_MIN1
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RExplodable.h:30
RObject::Id
int Id
Definition: RObject.h:66
RGraphicsView::mapToView
virtual RVector mapToView(const RVector &v) const =0
Maps the given model coordinate to a view coordinate in pixels.
RGraphicsView::getCurrentStepScaleFactor
double getCurrentStepScaleFactor() const
Definition: RGraphicsView.h:285
RGraphicsView::autoScalePatterns
bool autoScalePatterns
Definition: RGraphicsView.h:381
core_global.h
RGraphicsView::lastKnownModelPosition
RVector lastKnownModelPosition
Definition: RGraphicsView.h:392
RGraphicsView::lastKnownScreenPosition
RVector lastKnownScreenPosition
Definition: RGraphicsView.h:393
RTerminateEvent.h
RGraphicsView::navigationAction
RAction * navigationAction
The navigation action of this view or NULL if no navigation action has been set.
Definition: RGraphicsView.h:359
RPainterPath
Extended painter path with a z-level and a pen.
Definition: RPainterPath.h:46
RDocument
A graphics document contains and owns entities, layers, user coordinate systems, variables,...
Definition: RDocument.h:72
RGraphicsView::printPreview
bool printPreview
Definition: RGraphicsView.h:338
RGraphicsView::registerForFocus
virtual bool registerForFocus() const
Reimplementations may return true to register this view and allow it to be returned by RDocumentInter...
Definition: RGraphicsView.h:331
RExporter.h
autoZoom
void autoZoom()
Auto zoom.
Definition: simple_view.js:7
RGraphicsScene
Abstract base class for all graphics scenes.
Definition: RGraphicsScene.h:61
RTextLabel
Text label.
Definition: RTextLabel.h:42
RGrid
Abstract base class for grid implementations.
Definition: RGrid.h:39
RGraphicsView::isShared
virtual bool isShared() const
Reimplementations may return true to prevent this view from being deleted.
Definition: RGraphicsView.h:323
RGraphicsView::exporting
bool exporting
Definition: RGraphicsView.h:336
RGraphicsView::ColorMode
ColorMode
Definition: RGraphicsView.h:60
RGraphicsView::gridVisible
int gridVisible
Definition: RGraphicsView.h:409
RGraphicsView::backgroundColor
QColor backgroundColor
Definition: RGraphicsView.h:383
RGraphicsView::getTextHeightThresholdOverride
int getTextHeightThresholdOverride() const
Definition: RGraphicsView.h:305
RGraphicsView::getViewportNumber
int getViewportNumber() const
Definition: RGraphicsView.h:71
RGraphicsView::mapFromView
virtual RVector mapFromView(const RVector &v, double z=0.0) const =0
Maps the given view coordinate in pixels to a model coordinate.
RGraphicsView::colorMode
ColorMode colorMode
Definition: RGraphicsView.h:341
RGraphicsView::setCurrentStepOffset
void setCurrentStepOffset(const RVector &s)
Definition: RGraphicsView.h:297
RGraphicsView::setCurrentStepScaleFactor
void setCurrentStepScaleFactor(double f)
Definition: RGraphicsView.h:289
RBox
Represents a box e.g.
Definition: RBox.h:43
RGraphicsView::getCurrentStepOffset
RVector getCurrentStepOffset() const
Definition: RGraphicsView.h:293
RGraphicsView::hairlineMinimumMode
bool hairlineMinimumMode
Definition: RGraphicsView.h:343
RGraphicsView::setTextHeightThresholdOverride
void setTextHeightThresholdOverride(int v)
Definition: RGraphicsView.h:301
RGraphicsView::mapDistanceToView
virtual double mapDistanceToView(double d) const =0
Maps the given model distance to a screen distance in pixels.
RDocumentInterface
Interface for interaction between a graphics document and a user.
Definition: RDocumentInterface.h:85
RGrid.h
QCADCORE_EXPORT
#define QCADCORE_EXPORT
Definition: core_global.h:10
RGraphicsView::setGrid
void setGrid(RGrid *g)
Sets the current grid.
Definition: RGraphicsView.h:228