Warning, file /office/calligra/libs/widgets/KoZoomHandler.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 Copyright (C) 2001-2005 David Faure <faure@kde.org> 0003 Copyright (C) 2006, 2009 Thomas Zander <zander@kde.org> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #ifndef KOZOOMHANDLER_H 0022 #define KOZOOMHANDLER_H 0023 0024 #include "kowidgets_export.h" 0025 #include <KoZoomMode.h> 0026 #include <KoViewConverter.h> 0027 0028 /** 0029 * This class handles the zooming and DPI stuff (conversions between 0030 * postscript pt values and pixels). If the internal data of your 0031 * document does not work with postscript points (for instance raster 0032 * image pixels), you need to some additional converting yourself. 0033 * 0034 * An instance of KoZoomHandler operates at a given zoom and resolution 0035 * so there is usually one instance of KoZoomHandler per view. 0036 */ 0037 class KOWIDGETS_EXPORT KoZoomHandler : public KoViewConverter 0038 { 0039 public: 0040 0041 KoZoomHandler(); 0042 ~KoZoomHandler() override = default; 0043 0044 /** 0045 * @return the conversion factor between document and view, that 0046 * includes the zoom and also the DPI setting. 0047 */ 0048 inline qreal zoomedResolutionX() const { return m_zoomedResolutionX; } 0049 0050 /** 0051 * @return the conversion factor between document and view, that 0052 * includes the zoom and also the DPI setting. 0053 */ 0054 inline qreal zoomedResolutionY() const { return m_zoomedResolutionY; } 0055 0056 inline qreal resolutionX() const { return m_resolutionX; } 0057 inline qreal resolutionY() const { return m_resolutionY; } 0058 0059 /** 0060 * Zoom factor for X. Equivalent to zoomedResolutionX()/resolutionX() 0061 */ 0062 inline qreal zoomFactorX() const { return m_zoomedResolutionX / m_resolutionX; } 0063 0064 /** 0065 * Zoom factor for Y. Equivalent to zoomedResolutionY()/resolutionY() 0066 */ 0067 inline qreal zoomFactorY() const { return m_zoomedResolutionY / m_resolutionY; } 0068 0069 0070 /** 0071 * Set resolution expressed in dots-per-inch 0072 */ 0073 void setDpi(int dpiX, int dpiY); 0074 0075 /** 0076 * Set a resolution for X and Y of the output device. 0077 * The zoom factor is not changed. 0078 * 0079 * This number should be the result of: 0080 * POINT_TO_INCH(static_cast<qreal>(DOTS_PER_INCH)) 0081 */ 0082 void setResolution(qreal resolutionX, qreal resolutionY); 0083 0084 /** 0085 * Set the resolution for X and Y to the display values reported by KGlobal. 0086 * The zoom factor is not changed. 0087 */ 0088 void setResolutionToStandard( ); 0089 0090 /** 0091 * Set the zoomed resolution for X and Y. 0092 * Compared to the setZoom... methods, this allows to set a different 0093 * zoom factor for X and for Y. 0094 */ 0095 virtual void setZoomedResolution(qreal zoomedResolutionX, qreal zoomedResolutionY); 0096 0097 /** 0098 * Change the zoom level, keeping the resolution unchanged. 0099 * @param zoom the zoom factor (e.g. 1.0 for 100%) 0100 */ 0101 void setZoom(qreal zoom) override; 0102 0103 /** 0104 * Change the zoom mode 0105 * @param zoomMode the zoom mode. 0106 */ 0107 inline void setZoomMode(KoZoomMode::Mode zoomMode) { m_zoomMode = zoomMode; } 0108 /** 0109 * @return the global zoom factor (e.g. 100 for 100%). 0110 * Only use this to display to the user, don't use in calculations 0111 */ 0112 inline int zoomInPercent() const { return qRound(KoViewConverter::zoom() * 100); } 0113 /** 0114 * @return the global zoom mode (e.g. KoZoomMode::ZOOM_WIDTH). 0115 * use this to determine how to zoom 0116 */ 0117 KoZoomMode::Mode zoomMode() const { return m_zoomMode; } 0118 0119 // Input: pt. Output: pixels. Resolution and zoom are applied. 0120 0121 inline qreal zoomItX(qreal z) const 0122 { 0123 return m_zoomedResolutionX * z; 0124 } 0125 0126 inline qreal zoomItY(qreal z) const 0127 { 0128 return m_zoomedResolutionY * z ; 0129 } 0130 0131 // Input: pixels. Output: pt. 0132 inline qreal unzoomItX(qreal x) const 0133 { 0134 return x / m_zoomedResolutionX; 0135 } 0136 0137 inline qreal unzoomItY(qreal y) const 0138 { 0139 return y / m_zoomedResolutionY; 0140 } 0141 0142 // KoViewConverter-interface methods 0143 0144 /** 0145 * Convert a coordinate in pt to pixels. 0146 * @param documentPoint the point in the document coordinate system of a KoShape. 0147 */ 0148 QPointF documentToView(const QPointF &documentPoint) const override; 0149 0150 /** 0151 * Convert a coordinate in pixels to pt. 0152 * @param viewPoint the point in the coordinate system of the widget, or window. 0153 */ 0154 QPointF viewToDocument(const QPointF &viewPoint) const override; 0155 0156 /** 0157 * Convert a rectangle in pt to pixels. 0158 * @param documentRect the rect in the document coordinate system of a KoShape. 0159 */ 0160 QRectF documentToView(const QRectF &documentRect) const override; 0161 0162 /** 0163 * Convert a rectangle in pixels to pt. 0164 * @param viewRect the rect in the coordinate system of the widget, or window. 0165 */ 0166 QRectF viewToDocument(const QRectF &viewRect) const override; 0167 0168 /** 0169 * Convert a size in pt to pixels. 0170 * @param documentSize the size in pt. 0171 * @return the size in pixels. 0172 */ 0173 QSizeF documentToView(const QSizeF &documentSize) const override; 0174 0175 /** 0176 * Convert a size in pixels to pt. 0177 * @param viewSize the size in pixels. 0178 * @return the size in pt. 0179 */ 0180 QSizeF viewToDocument(const QSizeF &viewSize) const override; 0181 0182 /** 0183 * Convert a single x coordinate in pt to pixels. 0184 * @param documentX the x coordinate in pt. 0185 * @return the x coordinate in pixels. 0186 */ 0187 qreal documentToViewX(qreal documentX) const override; 0188 0189 /** 0190 * Convert a single y coordinate in pt to pixels. 0191 * @param documentY the y coordinate in pt. 0192 * @return the y coordinate in pixels. 0193 */ 0194 qreal documentToViewY(qreal documentY) const override; 0195 0196 /** 0197 * Convert a single x coordinate in pixels to pt. 0198 * @param viewX the x coordinate in pixels. 0199 * @return the x coordinate in pt. 0200 */ 0201 qreal viewToDocumentX(qreal viewX) const override; 0202 0203 /** 0204 * Convert a single y coordinate in pixels to pt. 0205 * @param viewY the y coordinate in pixels. 0206 * @return the y coordinate in pt. 0207 */ 0208 qreal viewToDocumentY(qreal viewY) const override; 0209 0210 /** 0211 * Get the zoom levels of the individual x and y axis. Copy them to the pointer parameters. 0212 * @param zoomX a pointer to a qreal which will be modified to set the horizontal zoom. 0213 * @param zoomY a pointer to a qreal which will be modified to set the vertical zoom. 0214 */ 0215 void zoom(qreal *zoomX, qreal *zoomY) const override; 0216 0217 using KoViewConverter::zoom; 0218 0219 protected: 0220 0221 KoZoomMode::Mode m_zoomMode; 0222 0223 qreal m_resolutionX; 0224 qreal m_resolutionY; 0225 qreal m_zoomedResolutionX; 0226 qreal m_zoomedResolutionY; 0227 }; 0228 0229 #endif