1
/* This file is part of the KDE project
2
Copyright (C) 2001-2005 David Faure <faure@kde.org>
3
Copyright (C) 2006, 2009 Thomas Zander <zander@kde.org>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
Boston, MA 02110-1301, USA.
21
#ifndef KOZOOMHANDLER_H
22
#define KOZOOMHANDLER_H
24
#include "flake_export.h"
25
#include <KoZoomMode.h>
26
#include <KoViewConverter.h>
30
* This class handles the zooming and DPI stuff (conversions between
31
* postscript pt values and pixels). If the internal data of your
32
* document does not work with postscript points (for instance raster
33
* image pixels), you need to some additional converting yourself.
35
* An instance of KoZoomHandler operates at a given zoom (see
36
* setZoomAndResolution() and setZoom()) so there is usually one
37
* instance of KoZoomHandler per view.
39
class FLAKE_EXPORT KoZoomHandler : public KoViewConverter
44
virtual ~KoZoomHandler();
47
* Change the zoom factor to @p zoom (e.g. 150 for 150%)
48
* and/or change the resolution of the output device, given in DPI.
49
* This is done on startup and when zooming.
50
* The same call combines both so that all the updating done behind
51
* the scenes is done only once, even if both zoom and DPI must be changed.
53
virtual void setZoomAndResolution(int zoom, int dpiX, int dpiY);
56
* @return the conversion factor between document and view, that
57
* includes the zoom and also the DPI setting.
59
inline qreal zoomedResolutionX() const { return m_zoomedResolutionX; }
62
* @return the conversion factor between document and view, that
63
* includes the zoom and also the DPI setting.
65
inline qreal zoomedResolutionY() const { return m_zoomedResolutionY; }
67
inline qreal resolutionX() const { return m_resolutionX; }
68
inline qreal resolutionY() const { return m_resolutionY; }
71
* Zoom factor for X. Equivalent to zoomedResolutionX()/resolutionX()
73
inline qreal zoomFactorX() const { return m_zoomedResolutionX / m_resolutionX; }
76
* Zoom factor for Y. Equivalent to zoomedResolutionY()/resolutionY()
78
inline qreal zoomFactorY() const { return m_zoomedResolutionY / m_resolutionY; }
81
* Set a resolution for X and Y of the output device.
82
* The zoom factor is not changed.
84
* XXX: Is this also in dots per inch?
86
void setResolution(qreal resolutionX, qreal resolutionY);
89
* Set the resolution for X and Y to the display values reported by KGlobal.
90
* The zoom factor is not changed.
92
void setResolutionToStandard( );
95
* Set the zoomed resolution for X and Y.
96
* Compared to the setZoom... methods, this allows to set a different
97
* zoom factor for X and for Y.
99
virtual void setZoomedResolution(qreal zoomedResolutionX, qreal zoomedResolutionY);
102
* Change the zoom level, keeping the resolution unchanged.
103
* @param zoom the zoom factor (e.g. 1.0 for 100%)
105
void setZoom(qreal zoom);
107
inline qreal zoom() const { return m_zoom; }
110
* Change the zoom mode
111
* @param zoomMode the zoom mode.
113
inline void setZoomMode(KoZoomMode::Mode zoomMode) { m_zoomMode = zoomMode; }
115
* @return the global zoom factor (e.g. 100 for 100%).
116
* Only use this to display to the user, don't use in calculations
118
inline int zoomInPercent() const { return qRound(m_zoom * 100); }
120
* @return the global zoom mode (e.g. KoZoomMode::ZOOM_WIDTH).
121
* use this to determine how to zoom
123
KoZoomMode::Mode zoomMode() const { return m_zoomMode; }
125
// Input: pt. Output: pixels. Resolution and zoom are applied.
127
inline qreal zoomItX(qreal z) const
129
return m_zoomedResolutionX * z;
132
inline qreal zoomItY(qreal z) const
134
return m_zoomedResolutionY * z ;
137
// Input: pixels. Output: pt.
138
inline qreal unzoomItX(qreal x) const
140
return x / m_zoomedResolutionX;
143
inline qreal unzoomItY(qreal y) const
145
return y / m_zoomedResolutionY;
148
// KoViewConverter-interface methods
151
* Convert a coordinate in pt to pixels.
152
* @param documentPoint the point in the document coordinate system of a KoShape.
154
virtual QPointF documentToView(const QPointF &documentPoint) const;
157
* Convert a coordinate in pixels to pt.
158
* @param viewPoint the point in the coordinate system of the widget, or window.
160
virtual QPointF viewToDocument(const QPointF &viewPoint) const;
163
* Convert a rectangle in pt to pixels.
164
* @param documentRect the rect in the document coordinate system of a KoShape.
166
virtual QRectF documentToView(const QRectF &documentRect) const;
169
* Convert a rectangle in pixels to pt.
170
* @param viewRect the rect in the coordinate system of the widget, or window.
172
virtual QRectF viewToDocument(const QRectF &viewRect) const;
175
* Convert a size in pt to pixels.
176
* @param documentSize the size in pt.
177
* @return the size in pixels.
179
virtual QSizeF documentToView(const QSizeF &documentSize) const;
182
* Convert a size in pixels to pt.
183
* @param viewSize the size in pixels.
184
* @return the size in pt.
186
virtual QSizeF viewToDocument(const QSizeF &viewSize) const;
189
* Convert a single x coordinate in pt to pixels.
190
* @param documentX the x coordinate in pt.
191
* @return the x coordinate in pixels.
193
virtual qreal documentToViewX(qreal documentX) const;
196
* Convert a single y coordinate in pt to pixels.
197
* @param documentY the y coordinate in pt.
198
* @return the y coordinate in pixels.
200
virtual qreal documentToViewY(qreal documentY) const;
203
* Convert a single x coordinate in pixels to pt.
204
* @param viewX the x coordinate in pixels.
205
* @return the x coordinate in pt.
207
virtual qreal viewToDocumentX(qreal viewX) const;
210
* Convert a single y coordinate in pixels to pt.
211
* @param viewY the y coordinate in pixels.
212
* @return the y coordinate in pt.
214
virtual qreal viewToDocumentY(qreal viewY) const;
217
* Get the zoom levels of the individual x and y axis. Copy them to the pointer parameters.
218
* @param zoomX a pointer to a qreal which will be modified to set the horizontal zoom.
219
* @param zoomY a pointer to a qreal which will be modified to set the vertical zoom.
221
virtual void zoom(qreal *zoomX, qreal *zoomY) const;
225
KoZoomMode::Mode m_zoomMode;
229
qreal m_zoomedResolutionX;
230
qreal m_zoomedResolutionY;