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  // TODO: these methods are not found in RGraphicsViewQt, due to the
58  // multiple inheritance of RGraphicsViewQt (QWidget and RGraphicsViewImage)
59  // unless they are re-declared here again:
60  void setViewportNumber(int n) {
62  }
63 
64  int getViewportNumber() const {
66  }
67 
68  void setNavigationAction(RAction* action) {
70  }
71 
72  RBox getBox() const {
73  return RGraphicsView::getBox();
74  }
75 
76  void autoZoom(int margin = RDEFAULT_MIN1, bool ignoreEmpty=false, bool ignoreLineweight=false) {
77  RGraphicsView::autoZoom(margin, ignoreEmpty, ignoreLineweight);
78  }
79 
80  void zoomTo(const RBox &window, int margin = 0) {
81  RGraphicsView::zoomTo(window, margin);
82  }
83 
84  void zoom(const RVector& center, double factor) {
85  RGraphicsView::zoom(center, factor);
86  }
87 
88  void centerToBox(const RBox& box) {
90  }
91 
92  void centerToPoint(const RVector& point) {
94  }
95 
96  void setGrid(RGrid* grid) {
98  }
99 
101  return RGraphicsView::getGrid();
102  }
103 
104  double getFactor(bool includeStepFactor=true) const {
105  return RGraphicsView::getFactor(includeStepFactor);
106  }
107 
108  void setFactor(double f, bool regen=true) {
109  RGraphicsView::setFactor(f, regen);
110  }
111 
112  RVector getOffset(bool includeStepOffset=true) const {
113  return RGraphicsView::getOffset(includeStepOffset);
114  }
115 
116  void setOffset(const RVector& offset, bool regen=true) {
117  RGraphicsView::setOffset(offset, regen);
118  }
119 
122  }
123 
124  void setMargin(int m) {
126  }
127 
130  }
131 
132  void setHairlineMode(bool on) {
134  }
135 
138  }
139 
140  void setAntialiasing(bool on) {
142  }
143 
144  bool getAntialiasing() const {
146  }
147 
149  return RGraphicsView::getScene();
150  }
151 
154  }
155 
158  }
159 
160  void setPrinting(bool on) {
162  }
163 
164  bool isPrinting() const {
165  return RGraphicsView::isPrinting();
166  }
167 
168  void setPrintPreview(bool on) {
170  }
171 
172  bool isPrintPreview() const {
174  }
175 
176  void setPrintPointSize(const RVector& s) {
178  }
179 
180  virtual void simulateMouseMoveEvent() {
182  }
183 
186  }
187 
190  }
191 
192  bool isGridVisible() const {
194  }
195 
196  void setGridVisible(bool on) {
198  }
199 
200  virtual void setScene(RGraphicsSceneQt* scene, bool regen=true);
201 
202  virtual void setBackgroundColor(const QColor& col);
203 
204  virtual void regenerate(bool force=false);
205  virtual void repaintView();
206  virtual void updateImage();
207 
208  virtual void giveFocus() {
209  return;
210  }
211 
212  virtual bool hasFocus() {
213  return true;
214  }
215 
216  virtual void removeFocus() {
217  return;
218  }
219 
220  void saveViewport();
221  void restoreViewport();
222 
223  virtual RVector mapFromView(const RVector& v, double z=0.0) const;
224  virtual RVector mapToView(const RVector& v) const;
225  virtual double mapDistanceFromView(double d) const;
226  virtual double mapDistanceToView(double d) const;
227 
228  virtual int getWidth() const;
229  virtual int getHeight() const;
230  void resizeImage(int w, int h);
231 
232  virtual void paintGridPoint(const RVector& ucsPosition);
233  virtual void paintGridLine(const RLine& ucsPosition);
234  //virtual void paintCursorLine(const RLine& ucsPosition);
235 
236  void setPaintOrigin(bool val);
237 
238  void setPanOptimization(bool on);
239  bool getPanOptimization();
240 
241  virtual void paintEntities(QPainter* painter, const RBox& queryBox);
242  virtual void paintEntity(QPainter* painter, REntity::Id id, bool preview = false);
243 
244  QImage getBuffer() const;
245  QTransform getTransform() const;
246 
247  virtual void emitUpdateSnapInfo(RSnap* snap, RSnapRestriction* restriction) {
248  Q_UNUSED(snap)
249  Q_UNUSED(restriction)
250  }
251  virtual void emitUpdateTextLabel(const RTextLabel& textLabel) {
252  Q_UNUSED(textLabel)
253  }
254  virtual void emitDecorateBackground(QPainter* painter) { Q_UNUSED(painter) }
255  virtual void emitDecorateForeground(QPainter* painter) { Q_UNUSED(painter) }
256 
257  void clearBackground();
258  void addToBackground(const RPainterPath& path);
259  void setBackgroundTransform(double bgFactor, const RVector& bgOffset);
260 
262  colorCorrectionOverride = on;
263  }
264 
266  return colorCorrectionOverride;
267  }
268 
269  void setMinimumLineweight(double lw) {
270  minimumLineweight = lw;
271  }
272 
273  void setPaintOffset(const RVector& offset) {
274  paintOffset = offset;
275  }
276 
278  return paintOffset;
279  }
280 
281  bool isAlphaEnabled() const {
282  return alphaEnabled;
283  }
284 
285  void setAlphaEnabled(bool on) {
286  alphaEnabled = on;
287  }
288 
289 protected:
290  QList<RPainterPath> getTextLayoutsPainterPaths(const RTextBasedData& text, const QList<RTextLayout>& textLayouts);
291  void applyMinimumLineweight(QPen& pen);
292  void applyColorCorrection(QPen& pen);
293  void applyColorCorrection(QBrush& brush);
294  void applyColorMode(QPen& pen);
295  void applyColorMode(QBrush& brush);
296  double getPointSize(double pSize);
297  virtual void drawDot(QPainter* painter, QPointF pt);
298  virtual void drawPlus(QPainter* painter, QPointF pt, double pSize);
299  virtual void drawEx(QPainter* painter, QPointF pt, double pSize);
300  virtual void drawVBar(QPainter* painter, QPointF pt, double pSize);
301  virtual void drawCircle(QPainter* painter, QPointF pt, double pSize);
302  virtual void drawSquare(QPainter* painter, QPointF pt, double pSize);
303 
304  virtual void paintImage(QPainter* painter, RImageData& image);
305  virtual void paintText(QPainter* painter, RTextBasedData& text);
306  virtual void paintOrigin(QPaintDevice& device);
307  virtual void paintReferencePoint(QPainter& painter, const RRefPoint& pos, bool highlight);
308  virtual void paintErase(QPaintDevice& device, const QRect& rect = QRect());
309  virtual void paintGrid(QPaintDevice& device, const QRect& rect = QRect());
310  virtual void paintMetaGrid(QPaintDevice& device, const QRect& rect = QRect());
311  virtual void paintCursor(QPaintDevice& device);
312  virtual void paintRelativeZero(QPaintDevice& device);
313  virtual void paintDocument(const QRect& rect = QRect());
314  virtual void paintBackground(QPainter* painter, const QRect& rect = QRect());
315 
319  QPainter* initPainter(QPaintDevice& device, bool erase, bool screen = false, const QRect& rect = QRect());
320 
321  void invalidate(bool force=false);
322  void updateGraphicsBuffer();
323  void updateTransformation() const;
324 
325 protected:
328 
329 protected:
331  QMutex mutexSi;
332 
334  double currentScale;
335  QSize lastSize;
337  double lastFactor;
339  mutable QTransform transform;
340  QTransform previousView;
341 
342  QPainter* gridPainter;
344 
346  QSet<RObject::Id> selectedIds;
348 
352 
354 
355 // int textHeightThresholdOverride;
356 // int textHeightThreshold;
357 
358  double drawingScale;
359 
360  QList<RPainterPath> backgroundDecoration;
361  //QTransform backgroundTransform;
367 };
368 
370 
371 #endif
QPainter * gridPainter
Definition: RGraphicsViewImage.h:342
void centerToBox(const RBox &box)
Centers the view on the given box.
Definition: RGraphicsViewImage.h:88
bool isSelected
Definition: RGraphicsViewImage.h:345
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:365
bool alphaEnabled
Definition: RGraphicsViewImage.h:366
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:874
RVector offset
Offset of the zero point from the lower left corner of the view in model coordinates.
Definition: RGraphicsView.h:337
QSet< RObject::Id > selectedIds
Definition: RGraphicsViewImage.h:346
RVector backgroundOffset
Definition: RGraphicsViewImage.h:363
void centerToPoint(const RVector &point)
Centers the view on the given point.
Definition: RGraphicsViewImage.h:92
Abstract base class for all grid and object snap implementations.
Definition: RSnap.h:44
bool colorCorrection
Definition: RGraphicsViewImage.h:350
void setFactor(double f, bool regen=true)
Definition: RGraphicsView.cpp:397
QSize lastSize
Definition: RGraphicsViewImage.h:335
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
bool getAntialiasing() const
Definition: RGraphicsViewImage.h:144
void setHairlineMode(bool on)
Definition: RGraphicsView.cpp:924
void setMargin(int m)
Definition: RGraphicsViewImage.h:124
void setViewportNumber(int n)
Definition: RGraphicsView.cpp:84
int bgColorLightness
Definition: RGraphicsViewImage.h:347
void setPrintPreview(bool on)
Definition: RGraphicsViewImage.h:168
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:212
#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:721
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:84
bool isPrintPreview() const
Definition: RGraphicsViewImage.h:172
Represents a reference point of an entity.
Definition: RRefPoint.h:18
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RImageData.h:41
QColor getBackgroundColor()
Definition: RGraphicsViewImage.h:120
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:261
QList< RPainterPath > backgroundDecoration
Definition: RGraphicsViewImage.h:360
RGraphicsScene * getScene()
Definition: RGraphicsView.cpp:148
bool getHairlineMode()
Definition: RGraphicsViewImage.h:136
void setAlphaEnabled(bool on)
Definition: RGraphicsViewImage.h:285
RDocumentInterface * getDocumentInterface()
Definition: RGraphicsViewImage.h:156
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:334
bool isPrinting() const
Definition: RGraphicsView.cpp:900
void setGridVisible(bool on)
Definition: RGraphicsViewImage.h:196
RDocument * getDocument()
Definition: RGraphicsViewImage.h:152
double backgroundFactor
Definition: RGraphicsViewImage.h:362
void setMargin(int m)
Definition: RGraphicsView.cpp:885
bool isPrinting() const
Definition: RGraphicsViewImage.h:164
double getFactor(bool includeStepFactor=true) const
Definition: RGraphicsView.cpp:344
RVector lastOffset
Definition: RGraphicsViewImage.h:336
QMutex mutexSi
Definition: RGraphicsViewImage.h:331
QImage graphicsBuffer
Definition: RGraphicsViewImage.h:326
virtual void emitUpdateSnapInfo(RSnap *snap, RSnapRestriction *restriction)
Definition: RGraphicsViewImage.h:247
void setTextHeightThresholdOverride(int v)
Definition: RGraphicsViewImage.h:184
int Id
Definition: RObject.h:57
Qt based 2d graphics scene.
Definition: RGraphicsSceneQt.h:62
int getTextHeightThresholdOverride() const
Definition: RGraphicsViewImage.h:188
RGrid * getGrid()
Definition: RGraphicsViewImage.h:100
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:76
bool getHairlineMode()
Definition: RGraphicsView.cpp:928
virtual void emitUpdateTextLabel(const RTextLabel &textLabel)
Definition: RGraphicsViewImage.h:251
void saveViewport()
Definition: RGraphicsView.cpp:124
void setTextHeightThresholdOverride(int v)
Definition: RGraphicsView.h:283
double drawingScale
Definition: RGraphicsViewImage.h:358
virtual int getWidth() const =0
void setFactor(double f, bool regen=true)
Definition: RGraphicsViewImage.h:108
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:43
virtual void simulateMouseMoveEvent()
Definition: RGraphicsViewImage.h:180
void setViewportNumber(int n)
Definition: RGraphicsViewImage.h:60
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:904
QImage graphicsBufferWithPreview
Definition: RGraphicsViewImage.h:327
virtual void centerToPoint(const RVector &point)
Centers the view on the given point.
Definition: RGraphicsView.cpp:447
void setPrinting(bool on)
Definition: RGraphicsViewImage.h:160
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:116
void setNavigationAction(RAction *action)
Definition: RGraphicsViewImage.h:68
virtual void emitDecorateBackground(QPainter *painter)
Definition: RGraphicsViewImage.h:254
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
virtual void giveFocus()
Definition: RGraphicsViewImage.h:208
int getTextHeightThresholdOverride() const
Definition: RGraphicsView.h:287
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:80
Q_DECLARE_METATYPE(RMath *)
RBox getBox() const
Definition: RGraphicsViewImage.h:72
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:912
RDocument * getDocument() const
Definition: RGraphicsView.cpp:167
QTransform previousView
Definition: RGraphicsViewImage.h:340
void setOffset(const RVector &offset, bool regen=true)
Definition: RGraphicsView.cpp:362
QColor getBackgroundColor()
Definition: RGraphicsView.cpp:878
void setColorMode(RGraphicsView::ColorMode cm)
Definition: RGraphicsView.cpp:916
RDocumentInterface * getDocumentInterface()
Definition: RGraphicsView.cpp:179
bool doPaintOrigin
Definition: RGraphicsViewImage.h:343
virtual void paintGridLine(const RLine &)
Definition: RGraphicsView.h:230
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:140
virtual void removeFocus()
Definition: RGraphicsViewImage.h:216
RVector getPaintOffset() const
Definition: RGraphicsViewImage.h:277
#define RDEFAULT_MIN1
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RExplodable.h:30
virtual void emitDecorateForeground(QPainter *painter)
Definition: RGraphicsViewImage.h:255
RBox clipBox
Definition: RGraphicsViewImage.h:364
bool isPrintPreview() const
Definition: RGraphicsView.cpp:908
void setPrinting(bool on)
Definition: RGraphicsView.cpp:896
void setAntialiasing(bool val)
Definition: RGraphicsView.cpp:979
bool colorCorrectionOverride
Definition: RGraphicsViewImage.h:349
int colorThreshold
Definition: RGraphicsViewImage.h:351
Abstract base class for grid implementations.
Definition: RGrid.h:39
void setGrid(RGrid *grid)
Definition: RGraphicsViewImage.h:96
Interface for interaction between a graphics document and a user.
Definition: RDocumentInterface.h:82
RGrid * getGrid()
Definition: RGraphicsView.h:209
bool graphicsBufferNeedsUpdate
Definition: RGraphicsViewImage.h:338
void setPrintPointSize(const RVector &s)
Definition: RGraphicsViewImage.h:176
virtual void paintGridPoint(const RVector &)
Definition: RGraphicsView.h:229
RGraphicsScene * getScene()
Definition: RGraphicsViewImage.h:148
void setHairlineMode(bool on)
Definition: RGraphicsViewImage.h:132
virtual int getHeight() const =0
RGraphicsSceneQt * sceneQt
Definition: RGraphicsViewImage.h:333
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:265
void setMinimumLineweight(double lw)
Definition: RGraphicsViewImage.h:269
virtual RBox getBox() const
Definition: RGraphicsView.cpp:486
int getViewportNumber() const
Definition: RGraphicsViewImage.h:64
double lastFactor
Definition: RGraphicsViewImage.h:337
bool panOptimization
Definition: RGraphicsViewImage.h:330
RVector getOffset(bool includeStepOffset=true) const
Definition: RGraphicsViewImage.h:112
double getFactor(bool includeStepFactor=true) const
Definition: RGraphicsViewImage.h:104
bool isGridVisible() const
Definition: RGraphicsViewImage.h:192
QTransform transform
Definition: RGraphicsViewImage.h:339
void setPaintOffset(const RVector &offset)
Definition: RGraphicsViewImage.h:273
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:128
bool getAntialiasing() const
Definition: RGraphicsView.cpp:983
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:353
Graphics view.
Definition: RGraphicsView.h:58
bool isAlphaEnabled() const
Definition: RGraphicsViewImage.h:281