QCAD
Open Source 2D CAD
RGraphicsViewImage.h
Go to the documentation of this file.
1 
20 #ifndef RGRAPHICSVIEWIMAGE_H
21 #define RGRAPHICSVIEWIMAGE_H
22 
23 #include "gui_global.h"
24 
25 #include <QtCore>
26 #include <QPinchGesture>
27 
28 #include "RGraphicsView.h"
29 #include "RPainterPath.h"
30 
31 class RAction;
32 class RDocument;
33 class RDocumentInterface;
34 class RGraphicsSceneQt;
35 class RLine;
36 class RSnap;
37 class RSnapRestriction;
38 
39 
40 
52 
53 public:
55  virtual ~RGraphicsViewImage();
56 
57  void clear();
58 
59  // TODO: these methods are not found in RGraphicsViewQt, due to the
60  // multiple inheritance of RGraphicsViewQt (QWidget and RGraphicsViewImage)
61  // unless they are re-declared here again:
62  void setViewportNumber(int n) {
64  }
65 
66  int getViewportNumber() const {
68  }
69 
70  void setNavigationAction(RAction* action) {
72  }
73 
74  RBox getBox() const {
75  return RGraphicsView::getBox();
76  }
77 
78  void autoZoom(int margin = RDEFAULT_MIN1, bool ignoreEmpty=false, bool ignoreLineweight=false) {
79  RGraphicsView::autoZoom(margin, ignoreEmpty, ignoreLineweight);
80  }
81 
82  void zoomTo(const RBox &window, int margin = 0) {
83  RGraphicsView::zoomTo(window, margin);
84  }
85 
86  void zoom(const RVector& center, double factor) {
87  RGraphicsView::zoom(center, factor);
88  }
89 
90  void centerToBox(const RBox& box) {
92  }
93 
94  void centerToPoint(const RVector& point) {
96  }
97 
98  void setGrid(RGrid* grid) {
100  }
101 
103  return RGraphicsView::getGrid();
104  }
105 
106  double getFactor(bool includeStepFactor=true) const {
107  return RGraphicsView::getFactor(includeStepFactor);
108  }
109 
110  void setFactor(double f, bool regen=true) {
111  RGraphicsView::setFactor(f, regen);
112  }
113 
114  RVector getOffset(bool includeStepOffset=true) const {
115  return RGraphicsView::getOffset(includeStepOffset);
116  }
117 
118  void setOffset(const RVector& offset, bool regen=true) {
119  RGraphicsView::setOffset(offset, regen);
120  }
121 
124  }
125 
126  void setMargin(int m) {
128  }
129 
132  }
133 
134  void setHairlineMode(bool on) {
136  }
137 
140  }
141 
142  void setAntialiasing(bool on) {
144  }
145 
146  bool getAntialiasing() const {
148  }
149 
151  return RGraphicsView::getScene();
152  }
153 
156  }
157 
160  }
161 
162  void setPrinting(bool on) {
164  }
165 
166  bool isPrinting() const {
167  return RGraphicsView::isPrinting();
168  }
169 
170  void setPrintPreview(bool on) {
172  }
173 
174  bool isPrintPreview() const {
176  }
177 
178  void setPrintPointSize(const RVector& s) {
180  }
181 
182  virtual void simulateMouseMoveEvent() {
184  }
185 
188  }
189 
192  }
193 
194  bool isGridVisible() const {
196  }
197 
198  void setGridVisible(bool on) {
200  }
201 
202  virtual void setScene(RGraphicsSceneQt* scene, bool regen=true);
203 
204  virtual void setBackgroundColor(const QColor& col);
205 
206  virtual void regenerate(bool force=false);
207  virtual void repaintView();
208  virtual void updateImage();
209 
210  virtual void giveFocus() {
211  return;
212  }
213 
214  virtual bool hasFocus() {
215  return true;
216  }
217 
218  virtual void removeFocus() {
219  return;
220  }
221 
222  void saveViewport();
223  void restoreViewport();
224 
225  virtual RVector mapFromView(const RVector& v, double z=0.0) const;
226  virtual RVector mapToView(const RVector& v) const;
227  virtual double mapDistanceFromView(double d) const;
228  virtual double mapDistanceToView(double d) const;
229 
230  virtual int getWidth() const;
231  virtual int getHeight() const;
232  void resizeImage(int w, int h);
233 
234  virtual void paintGridPoint(const RVector& ucsPosition);
235  virtual void paintGridLine(const RLine& ucsPosition);
236  //virtual void paintCursorLine(const RLine& ucsPosition);
237 
238  void setPaintOrigin(bool val);
239 
240  void setPanOptimization(bool on);
241  bool getPanOptimization();
242 
243  virtual void paintEntities(QPainter* painter, const RBox& queryBox);
244  virtual void paintEntity(QPainter* painter, REntity::Id id, bool preview = false);
245 
246  QImage getBuffer() const;
247  QTransform getTransform() const;
248 
249  virtual void emitUpdateSnapInfo(RSnap* snap, RSnapRestriction* restriction) {
250  Q_UNUSED(snap)
251  Q_UNUSED(restriction)
252  }
253  virtual void emitUpdateTextLabel(const RTextLabel& textLabel) {
254  Q_UNUSED(textLabel)
255  }
256  virtual void emitDecorateBackground(QPainter* painter) { Q_UNUSED(painter) }
257  virtual void emitDecorateForeground(QPainter* painter) { Q_UNUSED(painter) }
258 
259  void clearBackground();
260  void addToBackground(const RPainterPath& path);
261  void setBackgroundTransform(double bgFactor, const RVector& bgOffset);
262 
264  colorCorrectionOverride = on;
265  }
266 
268  return colorCorrectionOverride;
269  }
270 
271  void setMinimumLineweight(double lw) {
272  minimumLineweight = lw;
273  }
274 
275  void setPaintOffset(const RVector& offset) {
276  paintOffset = offset;
277  }
278 
280  return paintOffset;
281  }
282 
283  bool isAlphaEnabled() const {
284  return alphaEnabled;
285  }
286 
287  void setAlphaEnabled(bool on) {
288  alphaEnabled = on;
289  }
290 
291 protected:
292  QList<RPainterPath> getTextLayoutsPainterPaths(const RTextBasedData& text, const QList<RTextLayout>& textLayouts);
293  void applyMinimumLineweight(QPen& pen);
294  void applyColorCorrection(QPen& pen);
295  void applyColorCorrection(QBrush& brush);
296  void applyColorMode(QPen& pen);
297  void applyColorMode(QBrush& brush);
298  double getPointSize(double pSize);
299  virtual void drawDot(QPainter* painter, QPointF pt);
300  virtual void drawPlus(QPainter* painter, QPointF pt, double pSize);
301  virtual void drawEx(QPainter* painter, QPointF pt, double pSize);
302  virtual void drawVBar(QPainter* painter, QPointF pt, double pSize);
303  virtual void drawCircle(QPainter* painter, QPointF pt, double pSize);
304  virtual void drawSquare(QPainter* painter, QPointF pt, double pSize);
305 
306  virtual void paintImage(QPainter* painter, RImageData& image);
307  virtual void paintText(QPainter* painter, RTextBasedData& text);
308  virtual void paintOrigin(QPaintDevice& device);
309  virtual void paintReferencePoint(QPainter& painter, const RRefPoint& pos, bool highlight);
310  virtual void paintErase(QPaintDevice& device, const QRect& rect = QRect());
311  virtual void paintGrid(QPaintDevice& device, const QRect& rect = QRect());
312  virtual void paintMetaGrid(QPaintDevice& device, const QRect& rect = QRect());
313  virtual void paintCursor(QPaintDevice& device);
314  virtual void paintRelativeZero(QPaintDevice& device);
315  virtual void paintDocument(const QRect& rect = QRect());
316  virtual void paintBackground(QPainter* painter, const QRect& rect = QRect());
317 
321  QPainter* initPainter(QPaintDevice& device, bool erase, bool screen = false, const QRect& rect = QRect());
322 
323  void invalidate(bool force=false);
324  void updateGraphicsBuffer();
325  void updateTransformation() const;
326 
327 protected:
330 
331 protected:
333  QMutex mutexSi;
334 
336  double currentScale;
337  QSize lastSize;
339  double lastFactor;
341  mutable QTransform transform;
342  QTransform previousView;
343 
344  QPainter* gridPainter;
346 
348  QSet<RObject::Id> selectedIds;
350 
354 
356 
357 // int textHeightThresholdOverride;
358 // int textHeightThreshold;
359 
360  double drawingScale;
361 
362  QList<RPainterPath> backgroundDecoration;
363  //QTransform backgroundTransform;
369 };
370 
372 
373 #endif
QPainter * gridPainter
Definition: RGraphicsViewImage.h:344
void centerToBox(const RBox &box)
Centers the view on the given box.
Definition: RGraphicsViewImage.h:90
bool isSelected
Definition: RGraphicsViewImage.h:347
Represents a box e.g.
Definition: RBox.h:43
virtual void zoom(const RVector &center, double factor)
Zooms in / out by the given factor towards / from the given center in scene coordinates.
Definition: RGraphicsView.cpp:228
RVector paintOffset
Definition: RGraphicsViewImage.h:367
bool alphaEnabled
Definition: RGraphicsViewImage.h:368
void autoZoom(int margin=RDEFAULT_MIN1, bool ignoreEmpty=false, bool ignoreLineweight=false)
Definition: RGraphicsView.cpp:186
virtual void setBackgroundColor(const QColor &col)
Definition: RGraphicsView.cpp:876
RVector offset
Offset of the zero point from the lower left corner of the view in model coordinates.
Definition: RGraphicsView.h:354
QSet< RObject::Id > selectedIds
Definition: RGraphicsViewImage.h:348
RVector backgroundOffset
Definition: RGraphicsViewImage.h:365
void centerToPoint(const RVector &point)
Centers the view on the given point.
Definition: RGraphicsViewImage.h:94
Abstract base class for all grid and object snap implementations.
Definition: RSnap.h:44
bool colorCorrection
Definition: RGraphicsViewImage.h:352
void setFactor(double f, bool regen=true)
Definition: RGraphicsView.cpp:397
QSize lastSize
Definition: RGraphicsViewImage.h:337
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
bool getAntialiasing() const
Definition: RGraphicsViewImage.h:146
void setHairlineMode(bool on)
Definition: RGraphicsView.cpp:926
void setMargin(int m)
Definition: RGraphicsViewImage.h:126
void setViewportNumber(int n)
Definition: RGraphicsView.cpp:84
int bgColorLightness
Definition: RGraphicsViewImage.h:349
void setPrintPreview(bool on)
Definition: RGraphicsViewImage.h:170
virtual double mapDistanceFromView(double d) const =0
Maps the given view distance in pixels to a model distance.
bool isGridVisible() const
Definition: RGraphicsView.cpp:106
Text label.
Definition: RTextLabel.h:42
virtual bool hasFocus()
Definition: RGraphicsViewImage.h:214
#define QCADGUI_EXPORT
Definition: gui_global.h:10
void setNavigationAction(RAction *action)
Sets an action object that is typically used to handle all navigation interaction (zooming...
Definition: RGraphicsView.cpp:723
void zoom(const RVector &center, double factor)
Zooms in / out by the given factor towards / from the given center in scene coordinates.
Definition: RGraphicsViewImage.h:86
bool isPrintPreview() const
Definition: RGraphicsViewImage.h:174
Represents a reference point of an entity.
Definition: RRefPoint.h:18
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RImageData.h:41
QColor getBackgroundColor()
Definition: RGraphicsViewImage.h:122
Abstract base class for all graphics scenes.
Definition: RGraphicsScene.h:61
Abstract base class for all snap restriction implementations.
Definition: RSnapRestriction.h:37
void setColorCorrectionOverride(bool on)
Definition: RGraphicsViewImage.h:263
QList< RPainterPath > backgroundDecoration
Definition: RGraphicsViewImage.h:362
RGraphicsScene * getScene()
Definition: RGraphicsView.cpp:148
bool getHairlineMode()
Definition: RGraphicsViewImage.h:138
void setAlphaEnabled(bool on)
Definition: RGraphicsViewImage.h:287
RDocumentInterface * getDocumentInterface()
Definition: RGraphicsViewImage.h:158
virtual void zoomTo(const RBox &window, int margin=0)
Zooms the view in a way that the given window is visible and fills the view.
Definition: RGraphicsView.cpp:283
double currentScale
Definition: RGraphicsViewImage.h:336
bool isPrinting() const
Definition: RGraphicsView.cpp:902
void setGridVisible(bool on)
Definition: RGraphicsViewImage.h:198
RDocument * getDocument()
Definition: RGraphicsViewImage.h:154
double backgroundFactor
Definition: RGraphicsViewImage.h:364
void setMargin(int m)
Definition: RGraphicsView.cpp:887
bool isPrinting() const
Definition: RGraphicsViewImage.h:166
double getFactor(bool includeStepFactor=true) const
Definition: RGraphicsView.cpp:344
RVector lastOffset
Definition: RGraphicsViewImage.h:338
QMutex mutexSi
Definition: RGraphicsViewImage.h:333
QImage graphicsBuffer
Definition: RGraphicsViewImage.h:328
virtual void emitUpdateSnapInfo(RSnap *snap, RSnapRestriction *restriction)
Definition: RGraphicsViewImage.h:249
void setTextHeightThresholdOverride(int v)
Definition: RGraphicsViewImage.h:186
int Id
Definition: RObject.h:57
Qt based 2d graphics scene.
Definition: RGraphicsSceneQt.h:62
int getTextHeightThresholdOverride() const
Definition: RGraphicsViewImage.h:190
RGrid * getGrid()
Definition: RGraphicsViewImage.h:102
virtual RVector mapFromView(const RVector &v, double z=0.0) const =0
Maps the given view coordinate in pixels to a model coordinate.
virtual void centerToBox(const RBox &box)
Centers the view on the given box.
Definition: RGraphicsView.cpp:459
void autoZoom(int margin=RDEFAULT_MIN1, bool ignoreEmpty=false, bool ignoreLineweight=false)
Definition: RGraphicsViewImage.h:78
bool getHairlineMode()
Definition: RGraphicsView.cpp:930
virtual void emitUpdateTextLabel(const RTextLabel &textLabel)
Definition: RGraphicsViewImage.h:253
void saveViewport()
Definition: RGraphicsView.cpp:124
void setTextHeightThresholdOverride(int v)
Definition: RGraphicsView.h:292
double drawingScale
Definition: RGraphicsViewImage.h:360
virtual int getWidth() const =0
void setFactor(double f, bool regen=true)
Definition: RGraphicsViewImage.h:110
void setGridVisible(bool on)
Definition: RGraphicsView.cpp:91
ColorMode
Definition: RGraphicsView.h:60
Stores and manages all data that defines the geometry and appearance of a text based entity (text...
Definition: RTextBasedData.h:44
virtual void simulateMouseMoveEvent()
Definition: RGraphicsViewImage.h:182
void setViewportNumber(int n)
Definition: RGraphicsViewImage.h:62
virtual double mapDistanceToView(double d) const =0
Maps the given model distance to a screen distance in pixels.
void setPrintPreview(bool on)
Definition: RGraphicsView.cpp:906
QImage graphicsBufferWithPreview
Definition: RGraphicsViewImage.h:329
virtual void centerToPoint(const RVector &point)
Centers the view on the given point.
Definition: RGraphicsView.cpp:447
void setPrinting(bool on)
Definition: RGraphicsViewImage.h:162
RVector getOffset(bool includeStepOffset=true) const
Definition: RGraphicsView.cpp:353
Abstract base class for all action classes.
Definition: RAction.h:62
void setOffset(const RVector &offset, bool regen=true)
Definition: RGraphicsViewImage.h:118
void setNavigationAction(RAction *action)
Definition: RGraphicsViewImage.h:70
virtual void emitDecorateBackground(QPainter *painter)
Definition: RGraphicsViewImage.h:256
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
virtual void giveFocus()
Definition: RGraphicsViewImage.h:210
int getTextHeightThresholdOverride() const
Definition: RGraphicsView.h:296
void zoomTo(const RBox &window, int margin=0)
Zooms the view in a way that the given window is visible and fills the view.
Definition: RGraphicsViewImage.h:82
Q_DECLARE_METATYPE(RMath *)
RBox getBox() const
Definition: RGraphicsViewImage.h:74
void restoreViewport()
Definition: RGraphicsView.cpp:129
Extended painter path with a z-level and a pen.
Definition: RPainterPath.h:46
void setPrintPointSize(const RVector &s)
Definition: RGraphicsView.cpp:914
RDocument * getDocument() const
Definition: RGraphicsView.cpp:167
QTransform previousView
Definition: RGraphicsViewImage.h:342
void setOffset(const RVector &offset, bool regen=true)
Definition: RGraphicsView.cpp:362
QColor getBackgroundColor()
Definition: RGraphicsView.cpp:880
void setColorMode(RGraphicsView::ColorMode cm)
Definition: RGraphicsView.cpp:918
RDocumentInterface * getDocumentInterface()
Definition: RGraphicsView.cpp:179
bool doPaintOrigin
Definition: RGraphicsViewImage.h:345
virtual void paintGridLine(const RLine &)
Definition: RGraphicsView.h:239
Low-level mathematical representation of a line.
Definition: RLine.h:41
int getViewportNumber() const
Definition: RGraphicsView.h:71
void setAntialiasing(bool on)
Definition: RGraphicsViewImage.h:142
virtual void removeFocus()
Definition: RGraphicsViewImage.h:218
RVector getPaintOffset() const
Definition: RGraphicsViewImage.h:279
#define RDEFAULT_MIN1
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RExplodable.h:30
virtual void emitDecorateForeground(QPainter *painter)
Definition: RGraphicsViewImage.h:257
RBox clipBox
Definition: RGraphicsViewImage.h:366
bool isPrintPreview() const
Definition: RGraphicsView.cpp:910
void setPrinting(bool on)
Definition: RGraphicsView.cpp:898
void setAntialiasing(bool val)
Definition: RGraphicsView.cpp:981
bool colorCorrectionOverride
Definition: RGraphicsViewImage.h:351
int colorThreshold
Definition: RGraphicsViewImage.h:353
Abstract base class for grid implementations.
Definition: RGrid.h:39
void setGrid(RGrid *grid)
Definition: RGraphicsViewImage.h:98
Interface for interaction between a graphics document and a user.
Definition: RDocumentInterface.h:83
RGrid * getGrid()
Definition: RGraphicsView.h:218
bool graphicsBufferNeedsUpdate
Definition: RGraphicsViewImage.h:340
void setPrintPointSize(const RVector &s)
Definition: RGraphicsViewImage.h:178
virtual void paintGridPoint(const RVector &)
Definition: RGraphicsView.h:238
RGraphicsScene * getScene()
Definition: RGraphicsViewImage.h:150
void setHairlineMode(bool on)
Definition: RGraphicsViewImage.h:134
virtual int getHeight() const =0
void clear()
Definition: RGraphicsView.h:75
RGraphicsSceneQt * sceneQt
Definition: RGraphicsViewImage.h:335
virtual void setScene(RGraphicsScene *scene, bool regen=true)
Definition: RGraphicsView.cpp:138
virtual void simulateMouseMoveEvent()
Definition: RGraphicsView.cpp:560
virtual void repaintView()=0
Repaints the view (widget, etc..).
bool getColorCorrectionOverride() const
Definition: RGraphicsViewImage.h:267
void setMinimumLineweight(double lw)
Definition: RGraphicsViewImage.h:271
virtual RBox getBox() const
Definition: RGraphicsView.cpp:486
int getViewportNumber() const
Definition: RGraphicsViewImage.h:66
double lastFactor
Definition: RGraphicsViewImage.h:339
bool panOptimization
Definition: RGraphicsViewImage.h:332
RVector getOffset(bool includeStepOffset=true) const
Definition: RGraphicsViewImage.h:114
double getFactor(bool includeStepFactor=true) const
Definition: RGraphicsViewImage.h:106
bool isGridVisible() const
Definition: RGraphicsViewImage.h:194
QTransform transform
Definition: RGraphicsViewImage.h:341
void setPaintOffset(const RVector &offset)
Definition: RGraphicsViewImage.h:275
virtual void regenerate(bool force=false)=0
Regenerates the view to show the visible parts of the underlying scene.
void setColorMode(RGraphicsView::ColorMode cm)
Definition: RGraphicsViewImage.h:130
bool getAntialiasing() const
Definition: RGraphicsView.cpp:985
virtual RVector mapToView(const RVector &v) const =0
Maps the given model coordinate to a view coordinate in pixels.
QImage based 2d graphics view.
Definition: RGraphicsViewImage.h:51
double minimumLineweight
Definition: RGraphicsViewImage.h:355
Graphics view.
Definition: RGraphicsView.h:58
bool isAlphaEnabled() const
Definition: RGraphicsViewImage.h:283