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) {
77  RGraphicsView::autoZoom(margin, ignoreEmpty);
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);
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 
270 protected:
271  double getPointSize(double pSize);
272  virtual void drawDot(QPainter* painter, QPointF pt);
273  virtual void drawPlus(QPainter* painter, QPointF pt, double pSize);
274  virtual void drawEx(QPainter* painter, QPointF pt, double pSize);
275  virtual void drawVBar(QPainter* painter, QPointF pt, double pSize);
276  virtual void drawCircle(QPainter* painter, QPointF pt, double pSize);
277  virtual void drawSquare(QPainter* painter, QPointF pt, double pSize);
278 
279  virtual void paintImage(QPainter* painter, RImageData& image);
280  virtual void paintOrigin(QPaintDevice& device);
281  virtual void paintReferencePoint(QPainter& painter, const RVector& pos, bool highlight);
282  virtual void paintErase(QPaintDevice& device, const QRect& rect = QRect());
283  virtual void paintGrid(QPaintDevice& device, const QRect& rect = QRect());
284  virtual void paintMetaGrid(QPaintDevice& device, const QRect& rect = QRect());
285  virtual void paintCursor(QPaintDevice& device);
286  virtual void paintRelativeZero(QPaintDevice& device);
287  virtual void paintDocument(const QRect& rect = QRect());
288  virtual void paintBackground(QPainter* painter, const QRect& rect = QRect());
289 
293  QPainter* initPainter(QPaintDevice& device, bool erase, bool screen = false, const QRect& rect = QRect());
294 
295  void invalidate(bool force=false);
296  void updateGraphicsBuffer();
297  void updateTransformation() const;
298 
299 protected:
302 
303 protected:
305  QMutex mutexSi;
306 
308  double currentScale;
309  QSize lastSize;
311  double lastFactor;
313  mutable QTransform transform;
314  QTransform previousView;
315 
316  QPainter* gridPainter;
318 
320  QSet<RObject::Id> selectedIds;
322 
326 
327 // int textHeightThresholdOverride;
328 // int textHeightThreshold;
329 
330  double drawingScale;
331 
332  QList<RPainterPath> backgroundDecoration;
333  //QTransform backgroundTransform;
337 };
338 
340 
341 #endif
QPainter * gridPainter
Definition: RGraphicsViewImage.h:316
void centerToBox(const RBox &box)
Centers the view on the given box.
Definition: RGraphicsViewImage.h:88
bool isSelected
Definition: RGraphicsViewImage.h:319
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:225
virtual void setBackgroundColor(const QColor &col)
Definition: RGraphicsView.cpp:845
QSet< RObject::Id > selectedIds
Definition: RGraphicsViewImage.h:320
RVector backgroundOffset
Definition: RGraphicsViewImage.h:335
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:324
void setFactor(double f, bool regen=true)
Definition: RGraphicsView.cpp:382
QSize lastSize
Definition: RGraphicsViewImage.h:309
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:895
void setMargin(int m)
Definition: RGraphicsViewImage.h:124
void setViewportNumber(int n)
Definition: RGraphicsView.cpp:84
int bgColorLightness
Definition: RGraphicsViewImage.h:321
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:686
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
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RImageData.h:41
QColor getBackgroundColor()
Definition: RGraphicsViewImage.h:120
Abstract base class for all graphics scenes.
Definition: RGraphicsScene.h:60
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:332
RGraphicsScene * getScene()
Definition: RGraphicsView.cpp:148
bool getHairlineMode()
Definition: RGraphicsViewImage.h:136
void autoZoom(int margin=RDEFAULT_MIN1, bool ignoreEmpty=false)
Definition: RGraphicsViewImage.h:76
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:280
double currentScale
Definition: RGraphicsViewImage.h:308
bool isPrinting() const
Definition: RGraphicsView.cpp:871
void setGridVisible(bool on)
Definition: RGraphicsViewImage.h:196
RDocument * getDocument()
Definition: RGraphicsViewImage.h:152
double backgroundFactor
Definition: RGraphicsViewImage.h:334
void setMargin(int m)
Definition: RGraphicsView.cpp:856
bool isPrinting() const
Definition: RGraphicsViewImage.h:164
double getFactor(bool includeStepFactor=true) const
Definition: RGraphicsView.cpp:337
RVector lastOffset
Definition: RGraphicsViewImage.h:310
QMutex mutexSi
Definition: RGraphicsViewImage.h:305
QImage graphicsBuffer
Definition: RGraphicsViewImage.h:300
virtual void emitUpdateSnapInfo(RSnap *snap, RSnapRestriction *restriction)
Definition: RGraphicsViewImage.h:247
void setTextHeightThresholdOverride(int v)
Definition: RGraphicsViewImage.h:184
int Id
Definition: RObject.h:53
Qt based 2d graphics scene.
Definition: RGraphicsSceneQt.h:56
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:436
bool getHairlineMode()
Definition: RGraphicsView.cpp:899
virtual void emitUpdateTextLabel(const RTextLabel &textLabel)
Definition: RGraphicsViewImage.h:251
void saveViewport()
Definition: RGraphicsView.cpp:124
void setTextHeightThresholdOverride(int v)
Definition: RGraphicsView.h:270
double drawingScale
Definition: RGraphicsViewImage.h:330
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
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:875
QImage graphicsBufferWithPreview
Definition: RGraphicsViewImage.h:301
virtual void centerToPoint(const RVector &point)
Centers the view on the given point.
Definition: RGraphicsView.cpp:424
void setPrinting(bool on)
Definition: RGraphicsViewImage.h:160
RVector getOffset(bool includeStepOffset=true) const
Definition: RGraphicsView.cpp:346
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:63
void setGrid(RGrid *g)
Sets the current grid.
Definition: RGraphicsView.h:205
virtual void giveFocus()
Definition: RGraphicsViewImage.h:208
int getTextHeightThresholdOverride() const
Definition: RGraphicsView.h:274
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:45
void setPrintPointSize(const RVector &s)
Definition: RGraphicsView.cpp:883
RDocument * getDocument() const
Definition: RGraphicsView.cpp:167
QTransform previousView
Definition: RGraphicsViewImage.h:314
void setOffset(const RVector &offset, bool regen=true)
Definition: RGraphicsView.cpp:355
QColor getBackgroundColor()
Definition: RGraphicsView.cpp:849
void setColorMode(RGraphicsView::ColorMode cm)
Definition: RGraphicsView.cpp:887
RDocumentInterface * getDocumentInterface()
Definition: RGraphicsView.cpp:179
bool doPaintOrigin
Definition: RGraphicsViewImage.h:317
virtual void paintGridLine(const RLine &)
Definition: RGraphicsView.h:217
Low-level mathematical representation of a line.
Definition: RLine.h:42
void autoZoom(int margin=RDEFAULT_MIN1, bool ignoreEmpty=false)
Definition: RGraphicsView.cpp:186
int getViewportNumber() const
Definition: RGraphicsView.h:71
void setAntialiasing(bool on)
Definition: RGraphicsViewImage.h:140
virtual void removeFocus()
Definition: RGraphicsViewImage.h:216
#define RDEFAULT_MIN1
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RExplodable.h:30
virtual void emitDecorateForeground(QPainter *painter)
Definition: RGraphicsViewImage.h:255
RBox clipBox
Definition: RGraphicsViewImage.h:336
bool isPrintPreview() const
Definition: RGraphicsView.cpp:879
void setPrinting(bool on)
Definition: RGraphicsView.cpp:867
void setAntialiasing(bool val)
Definition: RGraphicsView.cpp:950
bool colorCorrectionOverride
Definition: RGraphicsViewImage.h:323
int colorThreshold
Definition: RGraphicsViewImage.h:325
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:196
bool graphicsBufferNeedsUpdate
Definition: RGraphicsViewImage.h:312
void setPrintPointSize(const RVector &s)
Definition: RGraphicsViewImage.h:176
virtual void paintGridPoint(const RVector &)
Definition: RGraphicsView.h:216
RGraphicsScene * getScene()
Definition: RGraphicsViewImage.h:148
void setHairlineMode(bool on)
Definition: RGraphicsViewImage.h:132
virtual int getHeight() const =0
RGraphicsSceneQt * sceneQt
Definition: RGraphicsViewImage.h:307
virtual void setScene(RGraphicsScene *scene, bool regen=true)
Definition: RGraphicsView.cpp:138
virtual void simulateMouseMoveEvent()
Definition: RGraphicsView.cpp:537
virtual void repaintView()=0
Repaints the view (widget, etc..).
bool getColorCorrectionOverride() const
Definition: RGraphicsViewImage.h:265
virtual RBox getBox() const
Definition: RGraphicsView.cpp:463
int getViewportNumber() const
Definition: RGraphicsViewImage.h:64
double lastFactor
Definition: RGraphicsViewImage.h:311
bool panOptimization
Definition: RGraphicsViewImage.h:304
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:313
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:954
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
Graphics view.
Definition: RGraphicsView.h:58