Krita Source Code Documentation
Loading...
Searching...
No Matches
KoViewConverter Class Reference

#include <KoViewConverter.h>

+ Inheritance diagram for KoViewConverter:

Public Member Functions

QTransform documentToView () const
 
virtual QPointF documentToView (const QPointF &documentPoint) const
 
virtual QRectF documentToView (const QRectF &documentRect) const
 
virtual QSizeF documentToView (const QSizeF &documentSize) const
 
virtual qreal documentToViewX (qreal documentX) const
 
virtual qreal documentToViewY (qreal documentY) const
 
 KoViewConverter ()
 
virtual KoViewTransformStillPoint makeDocStillPoint (const QPointF &docPoint) const
 Creates a still point that links the docPoint of the image (in document pixels!) to the corresponding point on the screen (in the canvas widget).
 
virtual KoViewTransformStillPoint makeWidgetStillPoint (const QPointF &viewPoint) const
 Creates a still point that links the viewPoint of the widget to the corresponding point of the image.
 
virtual void setZoom (qreal zoom)
 
QTransform viewToDocument () const
 
virtual QPointF viewToDocument (const QPointF &viewPoint) const
 
virtual QRectF viewToDocument (const QRectF &viewRect) const
 
virtual QSizeF viewToDocument (const QSizeF &viewSize) const
 
virtual qreal viewToDocumentX (qreal viewX) const
 
virtual qreal viewToDocumentY (qreal viewY) const
 
virtual QTransform viewToWidget () const
 
virtual QTransform widgetToView () const
 
qreal zoom () const
 
virtual void zoom (qreal *zoomX, qreal *zoomY) const
 
virtual ~KoViewConverter ()
 

Private Attributes

qreal m_zoomLevel
 

Detailed Description

The interface for view conversions.

All KoShape based objects are using a postscript-point (pt) based measurement system which requires a conversion to view coordinates (in pixel sizes) at the moment we are painting, and a conversion to the normalized coordinate system if we receive mouse events so we can figure out which KoShape object was touched.

The zoom level is expressed on a scale of 0.0 to 1.0 to infinite, where 1.0 is 100%

Definition at line 31 of file KoViewConverter.h.

Constructor & Destructor Documentation

◆ KoViewConverter()

KoViewConverter::KoViewConverter ( )

Definition at line 13 of file KoViewConverter.cpp.

14 : m_zoomLevel(1.0)
15{
16}

◆ ~KoViewConverter()

virtual KoViewConverter::~KoViewConverter ( )
inlinevirtual

Definition at line 35 of file KoViewConverter.h.

35{}

Member Function Documentation

◆ documentToView() [1/4]

QTransform KoViewConverter::documentToView ( ) const

Definition at line 111 of file KoViewConverter.cpp.

112{
113 qreal zoomX, zoomY;
114 zoom(&zoomX, &zoomY);
115 return QTransform::fromScale(zoomX, zoomY);
116}
qreal zoom() const

References zoom().

◆ documentToView() [2/4]

QPointF KoViewConverter::documentToView ( const QPointF & documentPoint) const
virtual

Convert a coordinate in pt to pixels.

Parameters
documentPointthe point in the document coordinate system of a KoShape.

Reimplemented in KoZoomHandler.

Definition at line 18 of file KoViewConverter.cpp.

19{
21 return documentPoint;
22 return QPointF(documentToViewX(documentPoint.x()), documentToViewY(documentPoint.y()));
23}
virtual qreal documentToViewY(qreal documentY) const
virtual qreal documentToViewX(qreal documentX) const
static bool qFuzzyCompare(half p1, half p2)

References documentToViewX(), documentToViewY(), m_zoomLevel, and qFuzzyCompare().

◆ documentToView() [3/4]

QRectF KoViewConverter::documentToView ( const QRectF & documentRect) const
virtual

Convert a rectangle in pt to pixels.

Parameters
documentRectthe rect in the document coordinate system of a KoShape.

Reimplemented in KoZoomHandler.

Definition at line 32 of file KoViewConverter.cpp.

33{
35 return documentRect;
36 return QRectF(documentToView(documentRect.topLeft()), documentToView(documentRect.size()));
37}
QTransform documentToView() const

References documentToView(), m_zoomLevel, and qFuzzyCompare().

◆ documentToView() [4/4]

QSizeF KoViewConverter::documentToView ( const QSizeF & documentSize) const
virtual

Convert a size in pt to pixels.

Parameters
documentSizethe size in pt.
Returns
the size in pixels.

Reimplemented in KoZoomHandler.

Definition at line 46 of file KoViewConverter.cpp.

47{
49 return documentSize;
50 return QSizeF(documentToViewX(documentSize.width()), documentToViewY(documentSize.height()));
51}

References documentToViewX(), documentToViewY(), m_zoomLevel, and qFuzzyCompare().

◆ documentToViewX()

qreal KoViewConverter::documentToViewX ( qreal documentX) const
virtual

Convert a single x coordinate in pt to pixels.

Parameters
documentXthe x coordinate in pt.
Returns
the x coordinate in pixels.

Reimplemented in KisImageViewConverter, and KoZoomHandler.

Definition at line 66 of file KoViewConverter.cpp.

67{
68 return documentX * m_zoomLevel;
69}

References m_zoomLevel.

◆ documentToViewY()

qreal KoViewConverter::documentToViewY ( qreal documentY) const
virtual

Convert a single y coordinate in pt to pixels.

Parameters
documentYthe y coordinate in pt.
Returns
the y coordinate in pixels.

Reimplemented in KisImageViewConverter, and KoZoomHandler.

Definition at line 71 of file KoViewConverter.cpp.

72{
73 return documentY * m_zoomLevel;
74}

References m_zoomLevel.

◆ makeDocStillPoint()

KoViewTransformStillPoint KoViewConverter::makeDocStillPoint ( const QPointF & docPoint) const
virtual

Creates a still point that links the docPoint of the image (in document pixels!) to the corresponding point on the screen (in the canvas widget).

The link is "baked" in KoViewTransformStillPoint object, hence intermediate transformations will not affect it.

Reimplemented in KisCoordinatesConverter.

Reimplemented in KisCoordinatesConverter.

Definition at line 106 of file KoViewConverter.cpp.

107{
108 return {docPoint, viewToWidget().map(documentToView(docPoint))};
109}
virtual QTransform viewToWidget() const

◆ makeWidgetStillPoint()

KoViewTransformStillPoint KoViewConverter::makeWidgetStillPoint ( const QPointF & viewPoint) const
virtual

Creates a still point that links the viewPoint of the widget to the corresponding point of the image.

The link is "baked" in KoViewTransformStillPoint object, hence intermediate transformations will not affect it.

Reimplemented in KisCoordinatesConverter.

Reimplemented in KisCoordinatesConverter.

Definition at line 101 of file KoViewConverter.cpp.

102{
103 return { viewToDocument(widgetToView().map(viewPoint)), viewPoint };
104}
QTransform viewToDocument() const
virtual QTransform widgetToView() const

References viewToDocument(), and widgetToView().

◆ setZoom()

void KoViewConverter::setZoom ( qreal zoom)
virtual

Set the zoom level. 1.0 is 100%.

Reimplemented in KisCoordinatesConverter, and KoZoomHandler.

Definition at line 88 of file KoViewConverter.cpp.

89{
90 if (qFuzzyCompare(zoom, qreal(0.0)) || qFuzzyCompare(zoom, qreal(1.0))) {
91 zoom = 1;
92 }
94}

References m_zoomLevel, qFuzzyCompare(), and zoom().

◆ viewToDocument() [1/4]

QTransform KoViewConverter::viewToDocument ( ) const

Definition at line 118 of file KoViewConverter.cpp.

119{
120 qreal zoomX, zoomY;
121 zoom(&zoomX, &zoomY);
122 return QTransform::fromScale(1.0 / zoomX, 1.0 / zoomY);
123}

References zoom().

◆ viewToDocument() [2/4]

QPointF KoViewConverter::viewToDocument ( const QPointF & viewPoint) const
virtual

Convert a coordinate in pixels to pt.

Parameters
viewPointthe point in the coordinate system of the widget, or window.

Reimplemented in KoZoomHandler.

Definition at line 25 of file KoViewConverter.cpp.

26{
28 return viewPoint;
29 return QPointF(viewToDocumentX(viewPoint.x()), viewToDocumentY(viewPoint.y()));
30}
virtual qreal viewToDocumentY(qreal viewY) const
virtual qreal viewToDocumentX(qreal viewX) const

References m_zoomLevel, qFuzzyCompare(), viewToDocumentX(), and viewToDocumentY().

◆ viewToDocument() [3/4]

QRectF KoViewConverter::viewToDocument ( const QRectF & viewRect) const
virtual

Convert a rectangle in pixels to pt.

Parameters
viewRectthe rect in the coordinate system of the widget, or window.

Reimplemented in KoZoomHandler.

Definition at line 39 of file KoViewConverter.cpp.

40{
42 return viewRect;
43 return QRectF(viewToDocument(viewRect.topLeft()), viewToDocument(viewRect.size()));
44}

References m_zoomLevel, qFuzzyCompare(), and viewToDocument().

◆ viewToDocument() [4/4]

QSizeF KoViewConverter::viewToDocument ( const QSizeF & viewSize) const
virtual

Convert a size in pixels to pt.

Parameters
viewSizethe size in pixels.
Returns
the size in pt.

Reimplemented in KoZoomHandler.

Definition at line 53 of file KoViewConverter.cpp.

54{
56 return viewSize;
57 return QSizeF(viewToDocumentX(viewSize.width()), viewToDocumentY(viewSize.height()));
58}

References m_zoomLevel, qFuzzyCompare(), viewToDocumentX(), and viewToDocumentY().

◆ viewToDocumentX()

qreal KoViewConverter::viewToDocumentX ( qreal viewX) const
virtual

Convert a single x coordinate in pixels to pt.

Parameters
viewXthe x coordinate in pixels.
Returns
the x coordinate in pt.

Reimplemented in KisImageViewConverter, and KoZoomHandler.

Definition at line 76 of file KoViewConverter.cpp.

77{
78 return viewX / m_zoomLevel;
79}

References m_zoomLevel.

◆ viewToDocumentY()

qreal KoViewConverter::viewToDocumentY ( qreal viewY) const
virtual

Convert a single y coordinate in pixels to pt.

Parameters
viewYthe y coordinate in pixels.
Returns
the y coordinate in pt.

Reimplemented in KisImageViewConverter, and KoZoomHandler.

Definition at line 81 of file KoViewConverter.cpp.

82{
83 return viewY / m_zoomLevel;
84}

References m_zoomLevel.

◆ viewToWidget()

QTransform KoViewConverter::viewToWidget ( ) const
virtual

Reimplemented in KisCoordinatesConverter.

Definition at line 125 of file KoViewConverter.cpp.

126{
127 return QTransform();
128}

◆ widgetToView()

QTransform KoViewConverter::widgetToView ( ) const
virtual

Reimplemented in KisCoordinatesConverter.

Definition at line 130 of file KoViewConverter.cpp.

131{
132 return QTransform();
133}

◆ zoom() [1/2]

qreal KoViewConverter::zoom ( ) const

Return the current zoom level. 1.0 is 100%.

Definition at line 96 of file KoViewConverter.cpp.

97{
98 return m_zoomLevel;
99}

References m_zoomLevel.

◆ zoom() [2/2]

void KoViewConverter::zoom ( qreal * zoomX,
qreal * zoomY ) const
virtual

Retrieve the zoom levels of the individual x and y axes.

Parameters
zoomXa pointer to a qreal which will be modified to the horizontal zoom.
zoomYa pointer to a qreal which will be modified to the vertical zoom.

Reimplemented in KoZoomHandler, KisImageViewConverter, and KoZoomHandler.

Definition at line 60 of file KoViewConverter.cpp.

61{
62 *zoomX = m_zoomLevel;
63 *zoomY = m_zoomLevel;
64}

References m_zoomLevel.

Member Data Documentation

◆ m_zoomLevel

qreal KoViewConverter::m_zoomLevel
private

Definition at line 150 of file KoViewConverter.h.


The documentation for this class was generated from the following files: