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 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, bool ignoreLineweight=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  virtual void regenerate(QSet<REntity::Id>& affectedEntities) {
172  Q_UNUSED(affectedEntities)
173 
174  regenerate(true);
175  }
176 
184  virtual void repaintView() = 0;
185 
189  virtual int getWidth() const = 0;
190 
194  virtual int getHeight() const = 0;
195 
196  virtual bool getSignalsBlocked() const {
197  return false;
198  }
199  virtual void setSignalsBlocked(bool on) {
200  Q_UNUSED(on)
201  return;
202  }
203 
204  void setNavigationAction(RAction* action);
205 
210  return grid;
211  }
212 
218  void setGrid(RGrid* g) {
219  if (grid!=NULL) {
220  delete grid;
221  grid = NULL;
222  }
223  grid = g;
224  }
225 
226  void setGridVisible(bool on);
227  bool isGridVisible() const;
228 
229  virtual void paintGridPoint(const RVector& /*ucsPosition*/) {}
230  virtual void paintGridLine(const RLine& /*ucsPosition*/) {}
231 
232  virtual QCursor getCursor() { return QCursor(Qt::ArrowCursor); }
233  virtual void setCursor(Qt::CursorShape /*cursorShape*/) {}
234  virtual void setCursor(const QCursor& /*cursor*/) {}
235 
236  RRefPoint getClosestReferencePoint(const RVector& screenPosition, int range);
237  RRefPoint getClosestReferencePoint(REntity::Id entityId, const RVector& screenPosition);
238  REntity::Id getClosestEntity(const RVector& screenPosition, int range, int strictRange, bool includeLockedLayers=true, bool selectedOnly = false);
239  //REntity::Id getClosestEntityInUcs(const RVector& screenPosition, int range);
240 
241  virtual void setBackgroundColor(const QColor& col);
242  QColor getBackgroundColor();
243 
244  int getMargin();
245  void setMargin(int m);
246 
247  void setPrinting(bool on);
248  bool isPrinting() const;
249  void setPrintPreview(bool on);
250  bool isPrintPreview() const;
251  void setPrintPointSize(const RVector& s);
252 
253  void setColorMode(RGraphicsView::ColorMode cm);
254  RGraphicsView::ColorMode getColorMode();
255 
256  void setHairlineMode(bool on);
257  bool getHairlineMode();
258 
259  QList<RTextLabel> getTextLabels();
260  void clearTextLabels();
261  void addTextLabel(const RTextLabel &textLabel);
262 
264  return lastKnownModelPosition;
265  }
266 
267  double getCurrentStepScaleFactor() const {
268  return currentStepScaleFactor;
269  }
270 
271  void setCurrentStepScaleFactor(double f) {
272  currentStepScaleFactor = f;
273  }
274 
276  return currentStepOffset;
277  }
278 
279  void setCurrentStepOffset(const RVector& s) {
280  currentStepOffset = s;
281  }
282 
284  textHeightThresholdOverride = v;
285  }
286 
288  return textHeightThresholdOverride;
289  }
290 
291  void updateTextHeightThreshold();
292 
293  bool isPathVisible(const RPainterPath& path) const;
294 
295  void setAntialiasing(bool val);
296  bool getAntialiasing() const;
297 
298  virtual double getDevicePixelRatio() const {
299  return 1.0;
300  }
301 
305  virtual bool isShared() const {
306  return false;
307  }
308 
309 protected:
310  bool printing;
313 
316 
321 
326 
332 
338 
342  double factor;
343 
346 
352 
354 
356  int margin;
357 
362 
366 
370  QList<RTextLabel> textLabels;
371 
372 
375 
377 
379 
380  // grid display flag, cached:
381  mutable int gridVisible;
382 
383  //RVector mousePressScreenPosition;
384  //RVector mousePressModelPosition;
385 };
386 
390 
391 #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:351
RVector offset
Offset of the zero point from the lower left corner of the view in model coordinates.
Definition: RGraphicsView.h:337
bool autoScalePatterns
Definition: RGraphicsView.h:353
virtual void setSignalsBlocked(bool on)
Definition: RGraphicsView.h:199
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
RVector getCurrentStepOffset() const
Definition: RGraphicsView.h:275
A tablet event for a graphics scene.
Definition: RTabletEvent.h:43
virtual double getDevicePixelRatio() const
Definition: RGraphicsView.h:298
virtual void setCursor(const QCursor &)
Definition: RGraphicsView.h:234
Text label.
Definition: RTextLabel.h:42
RVector lastKnownModelPosition
Definition: RGraphicsView.h:364
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:325
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RNonCopyable.h:32
Definition: RGraphicsView.h:61
ColorMode colorMode
Definition: RGraphicsView.h:314
#define QCADCORE_EXPORT
Definition: core_global.h:10
int Id
Definition: RObject.h:57
void getDocument()
Definition: simple.js:61
bool printPreview
Definition: RGraphicsView.h:311
QColor backgroundColor
Definition: RGraphicsView.h:355
void setCurrentStepScaleFactor(double f)
Definition: RGraphicsView.h:271
RVector previousOffset
Definition: RGraphicsView.h:344
double getCurrentStepScaleFactor() const
Definition: RGraphicsView.h:267
void setTextHeightThresholdOverride(int v)
Definition: RGraphicsView.h:283
RVector getLastKnownMousePosition() const
Definition: RGraphicsView.h:263
int gridVisible
Definition: RGraphicsView.h:381
void setCurrentStepOffset(const RVector &s)
Definition: RGraphicsView.h:279
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:218
int getTextHeightThresholdOverride() const
Definition: RGraphicsView.h:287
Q_DECLARE_METATYPE(RMath *)
bool printing
Definition: RGraphicsView.h:310
QList< RTextLabel > textLabels
Internal list of text labels that were added to this view.
Definition: RGraphicsView.h:370
virtual bool getSignalsBlocked() const
Definition: RGraphicsView.h:196
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
RVector currentStepOffset
Definition: RGraphicsView.h:363
virtual bool isShared() const
Reimplementations may return true to prevent this view from being deleted.
Definition: RGraphicsView.h:305
RVector printPointSize
Definition: RGraphicsView.h:312
int margin
Definition: RGraphicsView.h:356
virtual void paintGridLine(const RLine &)
Definition: RGraphicsView.h:230
Definition: RGraphicsView.h:62
Low-level mathematical representation of a line.
Definition: RLine.h:41
virtual void setCursor(Qt::CursorShape)
Definition: RGraphicsView.h:233
int getViewportNumber() const
Definition: RGraphicsView.h:71
#define RDEFAULT_MIN1
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RExplodable.h:30
int textHeightThreshold
Definition: RGraphicsView.h:374
double previousFactor
Definition: RGraphicsView.h:345
virtual void regenerate(QSet< REntity::Id > &affectedEntities)
Definition: RGraphicsView.h:171
void getDocumentInterface()
Returns the current RDocumentInterface or undefined.
Definition: simple.js:79
int viewportNumber
Definition: RGraphicsView.h:376
Abstract base class for grid implementations.
Definition: RGrid.h:39
Interface for interaction between a graphics document and a user.
Definition: RDocumentInterface.h:82
RGraphicsScene * scene
The scene this view is attached to.
Definition: RGraphicsView.h:320
RGrid * getGrid()
Definition: RGraphicsView.h:209
virtual void paintGridPoint(const RVector &)
Definition: RGraphicsView.h:229
bool hairlineMode
Definition: RGraphicsView.h:315
void autoZoom()
Auto zoom.
Definition: simple_view.js:27
double factor
Scale factor from model coordinates to view coordinates.
Definition: RGraphicsView.h:342
double currentStepScaleFactor
Current scale factor caused by a pinch gesture.
Definition: RGraphicsView.h:361
int textHeightThresholdOverride
Definition: RGraphicsView.h:373
RVector lastKnownScreenPosition
Definition: RGraphicsView.h:365
bool antialiasing
Definition: RGraphicsView.h:378
virtual QCursor getCursor()
Definition: RGraphicsView.h:232
Copyright (c) 2011-2016 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:331
Graphics view.
Definition: RGraphicsView.h:58