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

#include <KoZoomHandler.h>

+ Inheritance diagram for KoZoomHandler:

Public Member Functions

QPointF documentToView (const QPointF &documentPoint) const override
 
QRectF documentToView (const QRectF &documentRect) const override
 
QSizeF documentToView (const QSizeF &documentSize) const override
 
qreal documentToViewX (qreal documentX) const override
 
qreal documentToViewY (qreal documentY) const override
 
 KoZoomHandler ()
 
qreal resolutionX () const
 
qreal resolutionY () const
 
void setDpi (int dpiX, int dpiY)
 
void setResolution (qreal resolutionX, qreal resolutionY)
 
void setZoom (qreal zoom) override
 
virtual void setZoomedResolution (qreal zoomedResolutionX, qreal zoomedResolutionY)
 
void setZoomMarginSize (int size)
 
void setZoomMode (KoZoomMode::Mode zoomMode)
 
qreal unzoomItX (qreal x) const
 
qreal unzoomItY (qreal y) const
 
QPointF viewToDocument (const QPointF &viewPoint) const override
 
QRectF viewToDocument (const QRectF &viewRect) const override
 
QSizeF viewToDocument (const QSizeF &viewSize) const override
 
qreal viewToDocumentX (qreal viewX) const override
 
qreal viewToDocumentY (qreal viewY) const override
 
qreal zoom () const
 
virtual void zoom (qreal *zoomX, qreal *zoomY) const
 
void zoom (qreal *zoomX, qreal *zoomY) const override
 
qreal zoomedResolutionX () const
 
qreal zoomedResolutionY () const
 
qreal zoomFactorX () const
 
qreal zoomFactorY () const
 
int zoomInPercent () const
 
qreal zoomItX (qreal z) const
 
qreal zoomItY (qreal z) const
 
int zoomMarginSize () const
 
KoZoomMode::Mode zoomMode () const
 
 ~KoZoomHandler () override
 
- Public Member Functions inherited from KoViewConverter
QTransform documentToView () 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.
 
QTransform viewToDocument () const
 
virtual QTransform viewToWidget () const
 
virtual QTransform widgetToView () const
 
qreal zoom () const
 
virtual ~KoViewConverter ()
 

Protected Attributes

qreal m_resolutionX
 
qreal m_resolutionY
 
qreal m_zoomedResolutionX
 
qreal m_zoomedResolutionY
 
int m_zoomMarginSize
 
KoZoomMode::Mode m_zoomMode
 

Detailed Description

This class handles the zooming and DPI stuff (conversions between postscript pt values and pixels). If the internal data of your document does not work with postscript points (for instance raster image pixels), you need to some additional converting yourself.

An instance of KoZoomHandler operates at a given zoom and resolution so there is usually one instance of KoZoomHandler per view.

Definition at line 24 of file KoZoomHandler.h.

Constructor & Destructor Documentation

◆ KoZoomHandler()

KoZoomHandler::KoZoomHandler ( )

Definition at line 15 of file KoZoomHandler.cpp.

18 , m_resolutionX(0)
19 , m_resolutionY(0)
23{
24 setZoom(1.0);
26 // Use 72 dpi as a placeholder. KisView will immediately update the
27 // screen resolution correctly after this, using the values initialized
28 // by KisZoomManager::updateScreenResolution().
29 setDpi(72, 72);
30}
qreal m_zoomedResolutionX
void setZoom(qreal zoom) override
void setZoomMode(KoZoomMode::Mode zoomMode)
KoZoomMode::Mode m_zoomMode
void setDpi(int dpiX, int dpiY)
qreal m_zoomedResolutionY
@ ZOOM_CONSTANT
zoom x %
Definition KoZoomMode.h:24

References setDpi(), setZoom(), setZoomMode(), and KoZoomMode::ZOOM_CONSTANT.

◆ ~KoZoomHandler()

KoZoomHandler::~KoZoomHandler ( )
override

Definition at line 32 of file KoZoomHandler.cpp.

33{
34}

Member Function Documentation

◆ documentToView() [1/3]

QPointF KoZoomHandler::documentToView ( const QPointF & documentPoint) const
overridevirtual

Convert a coordinate in pt to pixels.

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

Reimplemented from KoViewConverter.

Definition at line 92 of file KoZoomHandler.cpp.

93{
94 return QPointF( zoomItX( documentPoint.x() ),
95 zoomItY( documentPoint.y() ));
96}
qreal zoomItX(qreal z) const
qreal zoomItY(qreal z) const

References zoomItX(), and zoomItY().

◆ documentToView() [2/3]

QRectF KoZoomHandler::documentToView ( const QRectF & documentRect) const
overridevirtual

Convert a rectangle in pt to pixels.

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

Reimplemented from KoViewConverter.

Definition at line 104 of file KoZoomHandler.cpp.

105{
106 QRectF r (zoomItX( documentRect.x() ),
107 zoomItY( documentRect.y() ),
108 zoomItX( documentRect.width() ),
109 zoomItY( documentRect.height() ) );
110 return r;
111}

References zoomItX(), and zoomItY().

◆ documentToView() [3/3]

QSizeF KoZoomHandler::documentToView ( const QSizeF & documentSize) const
overridevirtual

Convert a size in pt to pixels.

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

Reimplemented from KoViewConverter.

Definition at line 122 of file KoZoomHandler.cpp.

123{
124 return QSizeF( zoomItX( documentSize.width() ),
125 zoomItY( documentSize.height() ) );
126}

References zoomItX(), and zoomItY().

◆ documentToViewX()

qreal KoZoomHandler::documentToViewX ( qreal documentX) const
overridevirtual

Convert a single x coordinate in pt to pixels.

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

Reimplemented from KoViewConverter.

Definition at line 134 of file KoZoomHandler.cpp.

135{
136 return zoomItX( documentX );
137}

References zoomItX().

◆ documentToViewY()

qreal KoZoomHandler::documentToViewY ( qreal documentY) const
overridevirtual

Convert a single y coordinate in pt to pixels.

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

Reimplemented from KoViewConverter.

Definition at line 139 of file KoZoomHandler.cpp.

140{
141 return zoomItY( documentY );
142}

References zoomItY().

◆ resolutionX()

qreal KoZoomHandler::resolutionX ( ) const
inline

Definition at line 43 of file KoZoomHandler.h.

43{ return m_resolutionX; }

◆ resolutionY()

qreal KoZoomHandler::resolutionY ( ) const
inline

Definition at line 44 of file KoZoomHandler.h.

44{ return m_resolutionY; }

◆ setDpi()

void KoZoomHandler::setDpi ( int dpiX,
int dpiY )

Set resolution expressed in dots-per-inch

Definition at line 36 of file KoZoomHandler.cpp.

37{
38 setResolution(POINT_TO_INCH(static_cast<qreal>(dpiX)),
39 POINT_TO_INCH(static_cast<qreal>(dpiY)));
40}
constexpr qreal POINT_TO_INCH(qreal px)
Definition KoUnit.h:37
void setResolution(qreal resolutionX, qreal resolutionY)

References POINT_TO_INCH(), and setResolution().

◆ setResolution()

void KoZoomHandler::setResolution ( qreal resolutionX,
qreal resolutionY )

Set a resolution for X and Y of the output device. The zoom factor is not changed.

This number should be the result of: POINT_TO_INCH(static_cast<qreal>(DOTS_PER_INCH))

Definition at line 42 of file KoZoomHandler.cpp.

43{
44
47
49 m_resolutionX = 1;
51 m_resolutionY = 1;
52
55}
qreal resolutionX() const
qreal zoom() const
qreal resolutionY() const
static bool qFuzzyCompare(half p1, half p2)

References m_resolutionX, m_resolutionY, m_zoomedResolutionX, m_zoomedResolutionY, qFuzzyCompare(), resolutionX(), resolutionY(), and zoom().

◆ setZoom()

void KoZoomHandler::setZoom ( qreal zoom)
overridevirtual

Change the zoom level, keeping the resolution unchanged.

Parameters
zoomthe zoom factor (e.g. 1.0 for 100%)

Reimplemented from KoViewConverter.

Definition at line 66 of file KoZoomHandler.cpp.

67{
68 if (qFuzzyCompare(zoom, qreal(1.0))) {
69 zoom = 1.0;
70 }
71
73 if( zoom == 1.0 ) {
76 } else {
79 }
80}
virtual void setZoom(qreal zoom)

References m_resolutionX, m_resolutionY, m_zoomedResolutionX, m_zoomedResolutionY, qFuzzyCompare(), KoViewConverter::setZoom(), and zoom().

◆ setZoomedResolution()

void KoZoomHandler::setZoomedResolution ( qreal zoomedResolutionX,
qreal zoomedResolutionY )
virtual

Set the zoomed resolution for X and Y. Compared to the setZoom... methods, this allows to set a different zoom factor for X and for Y.

Definition at line 57 of file KoZoomHandler.cpp.

58{
59 // zoom() doesn't matter, it's only used in setZoom() to calculated the zoomed resolutions
60 // Here we know them. The whole point of this method is to allow a different zoom factor
61 // for X and for Y, as can be useful for e.g. fullscreen kpresenter presentations.
64}
qreal zoomedResolutionY() const
qreal zoomedResolutionX() const

References m_zoomedResolutionX, m_zoomedResolutionY, zoomedResolutionX(), and zoomedResolutionY().

◆ setZoomMarginSize()

void KoZoomHandler::setZoomMarginSize ( int size)

Definition at line 82 of file KoZoomHandler.cpp.

83{
85}
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References m_zoomMarginSize.

◆ setZoomMode()

void KoZoomHandler::setZoomMode ( KoZoomMode::Mode zoomMode)
inline

Change the zoom mode

Parameters
zoomModethe zoom mode.

Definition at line 88 of file KoZoomHandler.h.

KoZoomMode::Mode zoomMode() const

◆ unzoomItX()

qreal KoZoomHandler::unzoomItX ( qreal x) const
inline

Definition at line 113 of file KoZoomHandler.h.

◆ unzoomItY()

qreal KoZoomHandler::unzoomItY ( qreal y) const
inline

Definition at line 118 of file KoZoomHandler.h.

◆ viewToDocument() [1/3]

QPointF KoZoomHandler::viewToDocument ( const QPointF & viewPoint) const
overridevirtual

Convert a coordinate in pixels to pt.

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

Reimplemented from KoViewConverter.

Definition at line 98 of file KoZoomHandler.cpp.

99{
100 return QPointF( unzoomItX( viewPoint.x() ),
101 unzoomItY( viewPoint.y() ) );
102}
qreal unzoomItY(qreal y) const
qreal unzoomItX(qreal x) const

References unzoomItX(), and unzoomItY().

◆ viewToDocument() [2/3]

QRectF KoZoomHandler::viewToDocument ( const QRectF & viewRect) const
overridevirtual

Convert a rectangle in pixels to pt.

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

Reimplemented from KoViewConverter.

Definition at line 113 of file KoZoomHandler.cpp.

114{
115 QRectF r ( unzoomItX( viewRect.x() ),
116 unzoomItY( viewRect.y()),
117 unzoomItX( viewRect.width() ),
118 unzoomItY( viewRect.height() ) );
119 return r;
120}

References unzoomItX(), and unzoomItY().

◆ viewToDocument() [3/3]

QSizeF KoZoomHandler::viewToDocument ( const QSizeF & viewSize) const
overridevirtual

Convert a size in pixels to pt.

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

Reimplemented from KoViewConverter.

Definition at line 128 of file KoZoomHandler.cpp.

129{
130 return QSizeF( unzoomItX( viewSize.width() ),
131 unzoomItY( viewSize.height() ) );
132}

References unzoomItX(), and unzoomItY().

◆ viewToDocumentX()

qreal KoZoomHandler::viewToDocumentX ( qreal viewX) const
overridevirtual

Convert a single x coordinate in pixels to pt.

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

Reimplemented from KoViewConverter.

Definition at line 144 of file KoZoomHandler.cpp.

145{
146 return unzoomItX( viewX );
147}

References unzoomItX().

◆ viewToDocumentY()

qreal KoZoomHandler::viewToDocumentY ( qreal viewY) const
overridevirtual

Convert a single y coordinate in pixels to pt.

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

Reimplemented from KoViewConverter.

Definition at line 149 of file KoZoomHandler.cpp.

150{
151 return unzoomItY( viewY );
152}

References unzoomItY().

◆ zoom() [1/3]

qreal KoViewConverter::zoom ( ) const

Return the current zoom level. 1.0 is 100%.

Definition at line 118 of file KoViewConverter.cpp.

97{
98 return m_zoomLevel;
99}

◆ zoom() [2/3]

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 from KoViewConverter.

Definition at line 108 of file KoViewConverter.cpp.

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

References KoViewConverter::documentToView(), and KoViewConverter::viewToWidget().

◆ zoom() [3/3]

void KoZoomHandler::zoom ( qreal * zoomX,
qreal * zoomY ) const
overridevirtual

Get the zoom levels of the individual x and y axis. Copy them to the pointer parameters.

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

Reimplemented from KoViewConverter.

Definition at line 154 of file KoZoomHandler.cpp.

155{
156 *zoomX = zoomItX(100.0) / 100.0;
157 *zoomY = zoomItY(100.0) / 100.0;
158}

References zoomItX(), and zoomItY().

◆ zoomedResolutionX()

qreal KoZoomHandler::zoomedResolutionX ( ) const
inline
Returns
the conversion factor between document and view, that includes the zoom and also the DPI setting.

Definition at line 35 of file KoZoomHandler.h.

35{ return m_zoomedResolutionX; }

◆ zoomedResolutionY()

qreal KoZoomHandler::zoomedResolutionY ( ) const
inline
Returns
the conversion factor between document and view, that includes the zoom and also the DPI setting.

Definition at line 41 of file KoZoomHandler.h.

41{ return m_zoomedResolutionY; }

◆ zoomFactorX()

qreal KoZoomHandler::zoomFactorX ( ) const
inline

Zoom factor for X. Equivalent to zoomedResolutionX()/resolutionX()

Definition at line 49 of file KoZoomHandler.h.

◆ zoomFactorY()

qreal KoZoomHandler::zoomFactorY ( ) const
inline

Zoom factor for Y. Equivalent to zoomedResolutionY()/resolutionY()

Definition at line 54 of file KoZoomHandler.h.

◆ zoomInPercent()

int KoZoomHandler::zoomInPercent ( ) const
inline
Returns
the global zoom factor (e.g. 100 for 100%). Only use this to display to the user, don't use in calculations

Definition at line 93 of file KoZoomHandler.h.

93{ return qRound(KoViewConverter::zoom() * 100); }
qreal zoom() const

References KoViewConverter::zoom().

◆ zoomItX()

qreal KoZoomHandler::zoomItX ( qreal z) const
inline

Definition at line 102 of file KoZoomHandler.h.

103 {
104 return m_zoomedResolutionX * z;
105 }

◆ zoomItY()

qreal KoZoomHandler::zoomItY ( qreal z) const
inline

Definition at line 107 of file KoZoomHandler.h.

108 {
109 return m_zoomedResolutionY * z ;
110 }

◆ zoomMarginSize()

int KoZoomHandler::zoomMarginSize ( ) const

Definition at line 87 of file KoZoomHandler.cpp.

88{
89 return m_zoomMarginSize;
90}

References m_zoomMarginSize.

◆ zoomMode()

KoZoomMode::Mode KoZoomHandler::zoomMode ( ) const
inline
Returns
the global zoom mode (e.g. KoZoomMode::ZOOM_WIDTH). use this to determine how to zoom

Definition at line 98 of file KoZoomHandler.h.

98{ return m_zoomMode; }

Member Data Documentation

◆ m_resolutionX

qreal KoZoomHandler::m_resolutionX
protected

Definition at line 208 of file KoZoomHandler.h.

◆ m_resolutionY

qreal KoZoomHandler::m_resolutionY
protected

Definition at line 209 of file KoZoomHandler.h.

◆ m_zoomedResolutionX

qreal KoZoomHandler::m_zoomedResolutionX
protected

Definition at line 210 of file KoZoomHandler.h.

◆ m_zoomedResolutionY

qreal KoZoomHandler::m_zoomedResolutionY
protected

Definition at line 211 of file KoZoomHandler.h.

◆ m_zoomMarginSize

int KoZoomHandler::m_zoomMarginSize
protected

Definition at line 213 of file KoZoomHandler.h.

◆ m_zoomMode

KoZoomMode::Mode KoZoomHandler::m_zoomMode
protected

Definition at line 206 of file KoZoomHandler.h.


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