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);
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 
179  virtual void repaintView() = 0;
180 
184  virtual int getWidth() const = 0;
185 
189  virtual int getHeight() const = 0;
190 
191  void setNavigationAction(RAction* action);
192 
197  return grid;
198  }
199 
205  void setGrid(RGrid* g) {
206  if (grid!=NULL) {
207  delete grid;
208  grid = NULL;
209  }
210  grid = g;
211  }
212 
213  void setGridVisible(bool on);
214  bool isGridVisible() const;
215 
216  virtual void paintGridPoint(const RVector& /*ucsPosition*/) {}
217  virtual void paintGridLine(const RLine& /*ucsPosition*/) {}
218 
219  virtual QCursor getCursor() { return QCursor(Qt::ArrowCursor); }
220  virtual void setCursor(Qt::CursorShape /*cursorShape*/) {}
221  virtual void setCursor(const QCursor& /*cursor*/) {}
222 
223  RVector getClosestReferencePoint(const RVector& screenPosition, int range);
224  RVector getClosestReferencePoint(REntity::Id entityId, const RVector& screenPosition);
225  REntity::Id getClosestEntity(const RVector& screenPosition, int range, int strictRange, bool includeLockedLayers=true);
226  //REntity::Id getClosestEntityInUcs(const RVector& screenPosition, int range);
227 
228  virtual void setBackgroundColor(const QColor& col);
229  QColor getBackgroundColor();
230 
231  int getMargin();
232  void setMargin(int m);
233 
234  void setPrinting(bool on);
235  bool isPrinting() const;
236  void setPrintPreview(bool on);
237  bool isPrintPreview() const;
238  void setPrintPointSize(const RVector& s);
239 
240  void setColorMode(RGraphicsView::ColorMode cm);
241  RGraphicsView::ColorMode getColorMode();
242 
243  void setHairlineMode(bool on);
244  bool getHairlineMode();
245 
246  QList<RTextLabel> getTextLabels();
247  void clearTextLabels();
248  void addTextLabel(const RTextLabel &textLabel);
249 
251  return lastKnownModelPosition;
252  }
253 
254  double getCurrentStepScaleFactor() const {
255  return currentStepScaleFactor;
256  }
257 
258  void setCurrentStepScaleFactor(double f) {
259  currentStepScaleFactor = f;
260  }
261 
263  return currentStepOffset;
264  }
265 
266  void setCurrentStepOffset(const RVector& s) {
267  currentStepOffset = s;
268  }
269 
271  textHeightThresholdOverride = v;
272  }
273 
275  return textHeightThresholdOverride;
276  }
277 
278  void updateTextHeightThreshold();
279 
280  bool isPathVisible(const RPainterPath& path) const;
281 
282  void setAntialiasing(bool val);
283  bool getAntialiasing() const;
284 
285  virtual double getDevicePixelRatio() const {
286  return 1.0;
287  }
288 
289 protected:
290  bool printing;
293 
296 
301 
306 
312 
318 
322  double factor;
323 
326 
332 
334 
336  int margin;
337 
342 
346 
350  QList<RTextLabel> textLabels;
351 
352 
355 
357 
359 
360  // grid display flag, cached:
361  mutable int gridVisible;
362 };
363 
367 
368 #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:331
RVector offset
Offset of the zero point from the lower left corner of the view in model coordinates.
Definition: RGraphicsView.h:317
bool autoScalePatterns
Definition: RGraphicsView.h:333
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
RVector getCurrentStepOffset() const
Definition: RGraphicsView.h:262
A tablet event for a graphics scene.
Definition: RTabletEvent.h:43
virtual double getDevicePixelRatio() const
Definition: RGraphicsView.h:285
virtual void setCursor(const QCursor &)
Definition: RGraphicsView.h:221
Text label.
Definition: RTextLabel.h:42
RVector lastKnownModelPosition
Definition: RGraphicsView.h:344
Abstract base class for all graphics scenes.
Definition: RGraphicsScene.h:60
RGrid * grid
Grid that is currently displayed by this view or NULL.
Definition: RGraphicsView.h:305
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RNonCopyable.h:32
Definition: RGraphicsView.h:61
ColorMode colorMode
Definition: RGraphicsView.h:294
#define QCADCORE_EXPORT
Definition: core_global.h:10
int Id
Definition: RObject.h:53
void getDocument()
Definition: simple.js:19
bool printPreview
Definition: RGraphicsView.h:291
QColor backgroundColor
Definition: RGraphicsView.h:335
void setCurrentStepScaleFactor(double f)
Definition: RGraphicsView.h:258
RVector previousOffset
Definition: RGraphicsView.h:324
double getCurrentStepScaleFactor() const
Definition: RGraphicsView.h:254
void setTextHeightThresholdOverride(int v)
Definition: RGraphicsView.h:270
RVector getLastKnownMousePosition() const
Definition: RGraphicsView.h:250
int gridVisible
Definition: RGraphicsView.h:361
void setCurrentStepOffset(const RVector &s)
Definition: RGraphicsView.h:266
ColorMode
Definition: RGraphicsView.h:60
Abstract base class for all action classes.
Definition: RAction.h:62
#define RDEFAULT_MIN1
Definition: RGraphicsView.h:46
A graphics document contains and owns entities, layers, user coordinate systems, variables, block definitions, etc.
Definition: RDocument.h:63
void setGrid(RGrid *g)
Sets the current grid.
Definition: RGraphicsView.h:205
int getTextHeightThresholdOverride() const
Definition: RGraphicsView.h:274
Q_DECLARE_METATYPE(RMath *)
bool printing
Definition: RGraphicsView.h:290
void getDocumentInterface()
Definition: simple.js:21
QList< RTextLabel > textLabels
Internal list of text labels that were added to this view.
Definition: RGraphicsView.h:350
Extended painter path with a z-level and a pen.
Definition: RPainterPath.h:45
A mouse event for a graphics scene.
Definition: RMouseEvent.h:42
RVector currentStepOffset
Definition: RGraphicsView.h:343
RVector printPointSize
Definition: RGraphicsView.h:292
int margin
Definition: RGraphicsView.h:336
virtual void paintGridLine(const RLine &)
Definition: RGraphicsView.h:217
Definition: RGraphicsView.h:62
Low-level mathematical representation of a line.
Definition: RLine.h:42
virtual void setCursor(Qt::CursorShape)
Definition: RGraphicsView.h:220
int getViewportNumber() const
Definition: RGraphicsView.h:71
int textHeightThreshold
Definition: RGraphicsView.h:354
double previousFactor
Definition: RGraphicsView.h:325
int viewportNumber
Definition: RGraphicsView.h:356
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:300
RGrid * getGrid()
Definition: RGraphicsView.h:196
virtual void paintGridPoint(const RVector &)
Definition: RGraphicsView.h:216
bool hairlineMode
Definition: RGraphicsView.h:295
double factor
Scale factor from model coordinates to view coordinates.
Definition: RGraphicsView.h:322
double currentStepScaleFactor
Current scale factor caused by a pinch gesture.
Definition: RGraphicsView.h:341
int textHeightThresholdOverride
Definition: RGraphicsView.h:353
RVector lastKnownScreenPosition
Definition: RGraphicsView.h:345
bool antialiasing
Definition: RGraphicsView.h:358
virtual QCursor getCursor()
Definition: RGraphicsView.h:219
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RTerminateEvent.h:34
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:311
Graphics view.
Definition: RGraphicsView.h:58