QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
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 <QMutex>
26#include <QTransform>
27
29#include "RGraphicsView.h"
30#include "RPainterPath.h"
31
32class RAction;
33class RColor;
34class RBox;
35class RDocument;
37class RGraphicsScene;
40class RGraphicsViewQt;
42class RGrid;
43class RImageData;
44class RLine;
45class RMouseEvent;
46class RObject;
47class RPainterPath;
48class RRefPoint;
49class RShape;
50class RSnap;
52class RTabletEvent;
53class RTerminateEvent;
54class RTextBasedData;
55class RTextLabel;
56class RTextLayout;
57class RTransform;
58class RVector;
59class RWheelEvent;
60
69class QCADGUI_EXPORT RGraphicsViewImage : public QObject, public RGraphicsView {
70 Q_OBJECT
71
72public:
73 RGraphicsViewImage(QObject* parent=NULL);
74 virtual ~RGraphicsViewImage();
75
76 int getNumThreads() const {
77 return numThreads;
78 }
79 void setNumThreads(int n);
80
81 void clear();
82
83 virtual void setCursor(Qt::CursorShape cursorShape);
84 virtual void setCursor(const QCursor& cursor);
85
86 virtual QCursor getCursor();
87
88 // TODO: these methods are not found in RGraphicsViewQt, due to the
89 // multiple inheritance of RGraphicsViewQt (QWidget and RGraphicsViewImage)
90 // unless they are re-declared here again:
91// void setViewportNumber(int n) {
92// RGraphicsView::setViewportNumber(n);
93// }
94
95// int getViewportNumber() const {
96// return RGraphicsView::getViewportNumber();
97// }
98
99// void setNavigationAction(RAction* action) {
100// RGraphicsView::setNavigationAction(action);
101// }
102
103// RBox getBox() const {
104// return RGraphicsView::getBox();
105// }
106
107// void autoZoom(int margin = RDEFAULT_MIN1, bool ignoreEmpty=false, bool ignoreLineweight=false) {
108// RGraphicsView::autoZoom(margin, ignoreEmpty, ignoreLineweight);
109// }
110
111// void zoomTo(const RBox &window, int margin = 0) {
112// RGraphicsView::zoomTo(window, margin);
113// }
114
115// void zoom(const RVector& center, double factor) {
116// RGraphicsView::zoom(center, factor);
117// }
118
119// void pan(const RVector& delta, bool regen=true) {
120// RGraphicsView::pan(delta, regen);
121// }
122
123// void centerToBox(const RBox& box) {
124// RGraphicsView::centerToBox(box);
125// }
126
127// void centerToPoint(const RVector& point) {
128// RGraphicsView::centerToPoint(point);
129// }
130
131// void setGrid(RGrid* grid) {
132// RGraphicsView::setGrid(grid);
133// }
134
135// RGrid* getGrid() {
136// return RGraphicsView::getGrid();
137// }
138
139// double getFactor(bool includeStepFactor=true) const {
140// return RGraphicsView::getFactor(includeStepFactor);
141// }
142
143// void setFactor(double f, bool regen=true) {
144// RGraphicsView::setFactor(f, regen);
145// }
146
147// RVector getOffset(bool includeStepOffset=true) const {
148// return RGraphicsView::getOffset(includeStepOffset);
149// }
150
151// void setOffset(const RVector& offset, bool regen=true) {
152// RGraphicsView::setOffset(offset, regen);
153// }
154
155// QColor getBackgroundColor() {
156// return RGraphicsView::getBackgroundColor();
157// }
158
159// void setMargin(int m) {
160// RGraphicsView::setMargin(m);
161// }
162
163// void setColorMode(RGraphicsView::ColorMode cm) {
164// RGraphicsView::setColorMode(cm);
165// }
166
167// void setHairlineMode(bool on) {
168// RGraphicsView::setHairlineMode(on);
169// }
170
171// bool getHairlineMode() {
172// return RGraphicsView::getHairlineMode();
173// }
174
175// void setHairlineMinimumMode(bool on) {
176// RGraphicsView::setHairlineMinimumMode(on);
177// }
178
179// bool getHairlineMinimumMode() {
180// return RGraphicsView::getHairlineMinimumMode();
181// }
182
183// void setAntialiasing(bool on) {
184// RGraphicsView::setAntialiasing(on);
185// }
186
187// bool getAntialiasing() const {
188// return RGraphicsView::getAntialiasing();
189// }
190
191// RGraphicsScene* getScene() const {
192// return RGraphicsView::getScene();
193// }
194
195// RDocument* getDocument() const {
196// return RGraphicsView::getDocument();
197// }
198
199// RDocumentInterface* getDocumentInterface() const {
200// return RGraphicsView::getDocumentInterface();
201// }
202
203// void setExporting(bool on) {
204// RGraphicsView::setExporting(on);
205// }
206
207// bool isExporting() const {
208// return RGraphicsView::isExporting();
209// }
210
211// bool isPrintingOrExporting() const {
212// return RGraphicsView::isPrintingOrExporting();
213// }
214
215// void setPrinting(bool on) {
216// RGraphicsView::setPrinting(on);
217// }
218
219// bool isPrinting() const {
220// return RGraphicsView::isPrinting();
221// }
222
223// void setPrintPreview(bool on) {
224// RGraphicsView::setPrintPreview(on);
225// }
226
227// bool isPrintPreview() const {
228// return RGraphicsView::isPrintPreview();
229// }
230
231// void setPrintPointSize(const RVector& s) {
232// RGraphicsView::setPrintPointSize(s);
233// }
234
235 virtual void simulateMouseMoveEvent();
236
237// void setTextHeightThresholdOverride(int v) {
238// RGraphicsView::setTextHeightThresholdOverride(v);
239// }
240
241// int getTextHeightThresholdOverride() const {
242// return RGraphicsView::getTextHeightThresholdOverride();
243// }
244
245// bool isGridVisible() const {
246// return RGraphicsView::isGridVisible();
247// }
248
249// void setGridVisible(bool on) {
250// RGraphicsView::setGridVisible(on);
251// }
252
253 virtual void setScene(RGraphicsSceneQt* scene, bool regen=true);
254
255 virtual void setBackgroundColor(const QColor& col);
256
257 virtual void regenerate(bool force=false);
258 virtual void repaintView();
259 virtual void updateImage();
260
261 virtual void giveFocus();
262 virtual bool hasFocus();
263 virtual void removeFocus();
264
265 void saveViewport();
266 void restoreViewport();
267
268 virtual RVector mapFromView(const RVector& v, double z=0.0) const;
269 virtual RVector mapToView(const RVector& v) const;
270 virtual double mapDistanceFromView(double d) const;
271 virtual double mapDistanceToView(double d) const;
272
273 virtual int getWidth() const;
274 virtual int getHeight() const;
275 virtual void resizeImage(int w, int h);
276
277 virtual void paintGridPoint(const RVector& ucsPosition);
278 virtual void paintGridLine(const RLine& ucsPosition);
279 virtual void paintCursorLine(const RLine& ucsPosition);
280
281 void setPaintOrigin(bool val);
282
283 void setPanOptimization(bool on);
284 bool getPanOptimization();
285
286 virtual void paintEntities(QPainter* painter, const RBox& queryBox);
287 void paintEntitiesMulti(const RBox& queryBox);
288 //void paintEntitiesThread(int threadId, const QList<RObject::Id>& list, int start, int end);
289 //void paintDrawablesThread(int threadId, const QList<RGraphicsSceneDrawable>& list, int start, int end);
290
291 virtual void paintEntityThread(RGraphicsViewWorker* worker, RObject::Id id, bool preview = false);
292 virtual void paintDrawableThread(RGraphicsViewWorker* worker, RGraphicsSceneDrawable& drawable, const RBox& clipRectangle, bool preview = false);
293
294 virtual void paintOverlay();
295
296 QImage getBuffer() const;
297 QTransform getTransform() const;
298
299 void clearBackground();
300 void addToBackground(const RGraphicsSceneDrawable& drawable);
301 void setBackgroundTransform(double bgFactor, const RVector& bgOffset);
302
303 void clearOverlay(int overlayId);
304 void clearOverlay(int overlayId, RObject::Id objectId);
305 void addToOverlay(int overlayId, RObject::Id objectId, const RGraphicsSceneDrawable& drawable);
306
308 colorCorrectionOverride = (int)on;
309 }
310
312 return (colorCorrectionOverride!=0);
313 }
314
315 void setMinimumLineweight(double lw) {
316 minimumLineweight = lw;
317 }
318
319 double getMinimumLineweight() const {
320 return minimumLineweight;
321 }
322
323 void setMaximumLineweight(double lw) {
324 maximumLineweight = lw;
325 }
326
327 double getMaximumLineweight() const {
328 return maximumLineweight;
329 }
330
331 void setPaintOffset(const RVector& offset) {
332 paintOffset = offset;
333 }
334
336 return paintOffset;
337 }
338
339 bool isAlphaEnabled() const {
340 return alphaEnabled;
341 }
342
343 void setAlphaEnabled(bool on) {
344 alphaEnabled = on;
345 }
346
347 double getDrawingScale() const {
348 return drawingScale;
349 }
350 void setDrawingScale(double s) {
351 drawingScale = s;
352 }
353
355 return graphicsBufferWithPreview;
356 }
357
361
363 lastKnownScreenPosition = p;
364 }
365
367 lastKnownModelPosition = p;
368 }
369
370 virtual bool isShared() const {
371 // never delete image view:
372 // owned by creator
373 return true;
374 }
375
376 virtual bool registerForFocus() const {
377 return true;
378 }
379
380 virtual void viewportChangeEvent();
381
382 virtual void emitUpdateSnapInfo(RSnap* snap, RSnapRestriction* restriction);
383 virtual void emitUpdateTextLabel(const RTextLabel& textLabel);
384
385 virtual double getDevicePixelRatio() const;
386
387 virtual void paintImage(RGraphicsViewWorker* worker, const RImageData& image, bool workingSet = true);
388 virtual void paintText(RGraphicsViewWorker* worker, const RTextBasedData& text, bool workingSet = true);
389
390protected:
391 QList<RPainterPath> getTextLayoutsPainterPaths(const RTextBasedData& text, const QList<RTextLayout>& textLayouts);
392 void applyMinimumLineweight(QPen& pen);
393 void applyColorCorrection(QPen& pen);
394 void applyColorCorrection(QBrush& brush);
395 void applyColorMode(QPen& pen);
396 void applyColorMode(QBrush& brush);
397 double getPointSize(double pSize);
398 virtual void drawDot(RGraphicsViewWorker* worker, QPointF pt);
399 virtual void drawPlus(RGraphicsViewWorker* worker, QPointF pt, double pSize);
400 virtual void drawEx(RGraphicsViewWorker* worker, QPointF pt, double pSize);
401 virtual void drawVBar(RGraphicsViewWorker* worker, QPointF pt, double pSize);
402 virtual void drawCircle(RGraphicsViewWorker* worker, QPointF pt, double pSize);
403 virtual void drawSquare(RGraphicsViewWorker* worker, QPointF pt, double pSize);
404
405 virtual void paintOrigin(RGraphicsViewWorker* worker);
406 virtual void paintReferencePoint(RGraphicsViewWorker* worker, const RRefPoint& pos, bool highlight);
407 virtual void paintErase(RGraphicsViewWorker* worker, const QRect& rect = QRect());
408 virtual void paintGrid(RGraphicsViewWorker* worker, const QRect& rect = QRect());
409 virtual void paintMetaGrid(RGraphicsViewWorker* worker, const QRect& rect = QRect());
410 virtual void paintCursor(RGraphicsViewWorker* worker);
411 virtual void paintRelativeZero(RGraphicsViewWorker* worker);
412 virtual void paintDocument(const QRect& rect = QRect());
413 virtual void paintBackground(RGraphicsViewWorker* worker, const QRect& rect = QRect());
414
415 virtual void endPaint() const;
416 virtual void setBrush(const QBrush& brush) const;
417 virtual void setPen(const QPen& pen) const;
418 virtual void drawLine(const QLineF& line) const;
419
423 void initPainter(QPaintDevice& device, bool erase, bool screen = false, const QRect& rect = QRect());
424
425 void invalidate(bool force=false);
426 virtual void initWorkers();
427 virtual RGraphicsViewWorker* initWorker(int threadId);
428 void updateTransformation() const;
429
430signals:
432 void updateSnapInfo(RGraphicsViewWorker* worker, RSnap* snap, RSnapRestriction* restriction);
433 void updateTextLabel(RGraphicsViewWorker* worker, const RTextLabel& textLabel);
434
435protected:
436 //QList<QImage> graphicsBufferThread;
437 //QList<QPainter*> painterThread;
438
439 // graphics buffer with current drawing rendered into it, without preview:
441 // graphics buffer with current drawing rendered into it, with preview:
443
445
446protected:
448 QMutex mutexSi;
449
452 QSize lastSize;
456 mutable QTransform transform;
457 QTransform previousView;
458
459 QPainter* painter;
461
463 QSet<RObject::Id> selectedIds;
465
470
473
474// int textHeightThresholdOverride;
475// int textHeightThreshold;
476
478
479 QList<RGraphicsSceneDrawable> backgroundDecoration;
480 //QTransform backgroundTransform;
483
485
487 //QList<QStack<RTransform> > entityTransformThread;
490
492
494
495 QList<RGraphicsViewWorker*> workers;
497};
498
500
501#endif
Q_DECLARE_METATYPE(RMath *)
Definition RDebug.h:38
Abstract base class for all action classes.
Definition RAction.h:57
Represents a box e.g.
Definition RBox.h:46
Color.
Definition RColor.h:43
A graphics document contains and owns entities, layers, user coordinate systems, variables,...
Definition RDocument.h:78
Interface for interaction between a graphics document and a user.
Definition RDocumentInterface.h:97
Definition RGraphicsSceneDrawable.h:37
Abstract base class for all graphics scenes.
Definition RGraphicsScene.h:64
Qt based 2d graphics scene.
Definition RGraphicsSceneQt.h:68
Graphics view.
Definition RGraphicsView.h:67
virtual double mapDistanceFromView(double d) const =0
Maps the given view distance in pixels to a model distance.
virtual double getDevicePixelRatio() const
Definition RGraphicsView.h:324
virtual void setScene(RGraphicsScene *scene, bool regen=true)
Definition RGraphicsView.cpp:164
virtual void setCursor(Qt::CursorShape)
Definition RGraphicsView.h:243
RVector offset
Offset of the zero point from the lower left corner of the view in model coordinates.
Definition RGraphicsView.h:381
virtual void paintCursorLine(const RLine &)
Definition RGraphicsView.h:240
void restoreViewport()
Definition RGraphicsView.cpp:155
virtual RVector mapToView(const RVector &v) const =0
Maps the given model coordinate to a view coordinate in pixels.
virtual bool hasFocus()=0
virtual int getHeight() const =0
virtual void repaintView()=0
Repaints the view (widget, etc..).
virtual void removeFocus()=0
virtual double mapDistanceToView(double d) const =0
Maps the given model distance to a screen distance in pixels.
virtual int getWidth() const =0
virtual void paintGridPoint(const RVector &)
Definition RGraphicsView.h:238
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 regenerate(bool force=false)=0
Regenerates the view to show the visible parts of the underlying scene.
virtual void setBackgroundColor(const QColor &col)
Definition RGraphicsView.cpp:934
RVector lastKnownScreenPosition
Definition RGraphicsView.h:409
virtual QCursor getCursor()
Definition RGraphicsView.h:242
virtual void viewportChangeEvent()
Definition RGraphicsView.cpp:143
void saveViewport()
Definition RGraphicsView.cpp:150
virtual void simulateMouseMoveEvent()
Definition RGraphicsView.cpp:614
void clear()
Definition RGraphicsView.h:84
virtual void paintGridLine(const RLine &)
Definition RGraphicsView.h:239
virtual void giveFocus()=0
QImage based 2d graphics view.
Definition RGraphicsViewImage.h:69
double lastFactor
Definition RGraphicsViewImage.h:454
QImage graphicsBufferWithPreview
Definition RGraphicsViewImage.h:442
RGraphicsViewWorker * decorationWorker
Definition RGraphicsViewImage.h:496
RVector lastOffset
Definition RGraphicsViewImage.h:453
QString lastScaleString
Definition RGraphicsViewImage.h:491
bool panOptimization
Definition RGraphicsViewImage.h:447
bool getColorCorrectionOverride() const
Definition RGraphicsViewImage.h:311
bool colorCorrectionDisableForPrinting
Definition RGraphicsViewImage.h:468
RVector getPaintOffset() const
Definition RGraphicsViewImage.h:335
bool showOnlyPlottable
Definition RGraphicsViewImage.h:493
QTransform previousView
Definition RGraphicsViewImage.h:457
bool doPaintOrigin
Definition RGraphicsViewImage.h:460
void setMaximumLineweight(double lw)
Definition RGraphicsViewImage.h:323
double getMaximumLineweight() const
Definition RGraphicsViewImage.h:327
void setLastKnownScreenPosition(const RVector &p)
Definition RGraphicsViewImage.h:362
int colorThreshold
Definition RGraphicsViewImage.h:469
virtual bool registerForFocus() const
Reimplementations may return true to register this view and allow it to be returned by RDocumentInter...
Definition RGraphicsViewImage.h:376
double maximumLineweight
Definition RGraphicsViewImage.h:472
double minimumLineweight
Definition RGraphicsViewImage.h:471
QList< RGraphicsSceneDrawable > backgroundDecoration
Definition RGraphicsViewImage.h:479
int colorCorrectionOverride
Definition RGraphicsViewImage.h:466
QSet< RObject::Id > selectedIds
Definition RGraphicsViewImage.h:463
int bgColorLightness
Definition RGraphicsViewImage.h:464
QPainter * painter
Definition RGraphicsViewImage.h:459
RVector backgroundOffset
Definition RGraphicsViewImage.h:482
int getNumThreads() const
Definition RGraphicsViewImage.h:76
double backgroundFactor
Definition RGraphicsViewImage.h:481
RVector getLastKnownScreenPosition() const
Definition RGraphicsViewImage.h:358
QTransform transform
Definition RGraphicsViewImage.h:456
void setAlphaEnabled(bool on)
Definition RGraphicsViewImage.h:343
virtual bool isShared() const
Reimplementations may return true to prevent this view from being deleted.
Definition RGraphicsViewImage.h:370
double drawingScale
Definition RGraphicsViewImage.h:477
void updateSnapInfo(RGraphicsViewWorker *worker, RSnap *snap, RSnapRestriction *restriction)
bool alphaEnabled
Definition RGraphicsViewImage.h:489
void setMinimumLineweight(double lw)
Definition RGraphicsViewImage.h:315
QImage graphicsBuffer
Definition RGraphicsViewImage.h:440
bool isAlphaEnabled() const
Definition RGraphicsViewImage.h:339
RBox clipBox
Definition RGraphicsViewImage.h:486
bool isSelected
Definition RGraphicsViewImage.h:462
double currentScale
Definition RGraphicsViewImage.h:451
void setLastKnownModelPosition(const RVector &p)
Definition RGraphicsViewImage.h:366
RVector paintOffset
Definition RGraphicsViewImage.h:488
void updateTextLabel(RGraphicsViewWorker *worker, const RTextLabel &textLabel)
double getDrawingScale() const
Definition RGraphicsViewImage.h:347
bool graphicsBufferNeedsUpdate
Definition RGraphicsViewImage.h:455
QSize lastSize
Definition RGraphicsViewImage.h:452
void setDrawingScale(double s)
Definition RGraphicsViewImage.h:350
int numThreads
Definition RGraphicsViewImage.h:444
void setPaintOffset(const RVector &offset)
Definition RGraphicsViewImage.h:331
QMap< int, QMap< RObject::Id, QList< RGraphicsSceneDrawable > > > overlayDrawables
Definition RGraphicsViewImage.h:484
void setColorCorrectionOverride(bool on)
Definition RGraphicsViewImage.h:307
QImage getGraphicsBufferWithPreview() const
Definition RGraphicsViewImage.h:354
QList< RGraphicsViewWorker * > workers
Definition RGraphicsViewImage.h:495
bool colorCorrection
Definition RGraphicsViewImage.h:467
QMutex mutexSi
Definition RGraphicsViewImage.h:448
RGraphicsSceneQt * sceneQt
Definition RGraphicsViewImage.h:450
double getMinimumLineweight() const
Definition RGraphicsViewImage.h:319
QWidget based 2d graphics view.
Definition RGraphicsViewQt.h:44
Thread worker that draws a part of a document.
Definition RGraphicsViewWorker.h:44
Abstract base class for grid implementations.
Definition RGrid.h:41
Stores and manages all data that defines the geometry and appearance of a raster image entity.
Definition RImageData.h:41
Low-level mathematical representation of a line.
Definition RLine.h:41
A mouse event for a graphics scene.
Definition RMouseEvent.h:42
Abstract base class for all objects.
Definition RObject.h:64
int Id
Definition RObject.h:69
Extended painter path with a z-level and a pen.
Definition RPainterPath.h:48
Represents a reference point of an entity.
Definition RRefPoint.h:18
Interface for geometrical shape classes.
Definition RShape.h:72
Abstract base class for all grid and object snap implementations.
Definition RSnap.h:43
Abstract base class for all snap restriction implementations.
Definition RSnapRestriction.h:37
A tablet event for a graphics scene.
Definition RTabletEvent.h:43
Copyright (c) 2011-2018 by Andrew Mustun.
Definition RTerminateEvent.h:34
Stores and manages all data that defines the geometry and appearance of a text based entity (text,...
Definition RTextBasedData.h:68
Text label.
Definition RTextLabel.h:44
Copyright (c) 2011-2018 by Andrew Mustun.
Definition RTextLayout.h:37
Copyright (c) 2011-2020 by Andrew Mustun.
Definition RTransform.h:37
Represents a 3d vector (x/y/z).
Definition RVector.h:47
A mouse wheel event for a graphics scene.
Definition RWheelEvent.h:41
#define QCADGUI_EXPORT
Definition gui_global.h:10
char s
Definition opennurbs_string.cpp:32
#define NULL
Definition opennurbs_system.h:256