libs/flake
KoZoomHandler.h
Go to the documentation of this file.00001 /* This file is part of the KDE project 00002 Copyright (C) 2001-2005 David Faure <faure@kde.org> 00003 Copyright (C) 2006, 2009 Thomas Zander <zander@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #ifndef KOZOOMHANDLER_H 00022 #define KOZOOMHANDLER_H 00023 00024 #include "flake_export.h" 00025 #include <KoZoomMode.h> 00026 #include <KoViewConverter.h> 00027 00028 00039 class FLAKE_EXPORT KoZoomHandler : public KoViewConverter 00040 { 00041 public: 00042 00043 KoZoomHandler(); 00044 virtual ~KoZoomHandler(); 00045 00053 virtual void setZoomAndResolution(int zoom, int dpiX, int dpiY); 00054 00059 inline qreal zoomedResolutionX() const { return m_zoomedResolutionX; } 00060 00065 inline qreal zoomedResolutionY() const { return m_zoomedResolutionY; } 00066 00067 inline qreal resolutionX() const { return m_resolutionX; } 00068 inline qreal resolutionY() const { return m_resolutionY; } 00069 00073 inline qreal zoomFactorX() const { return m_zoomedResolutionX / m_resolutionX; } 00074 00078 inline qreal zoomFactorY() const { return m_zoomedResolutionY / m_resolutionY; } 00079 00086 void setResolution(qreal resolutionX, qreal resolutionY); 00087 00092 void setResolutionToStandard( ); 00093 00099 virtual void setZoomedResolution(qreal zoomedResolutionX, qreal zoomedResolutionY); 00100 00105 void setZoom(qreal zoom); 00106 00107 inline qreal zoom() const { return m_zoom; } 00108 00113 inline void setZoomMode(KoZoomMode::Mode zoomMode) { m_zoomMode = zoomMode; } 00118 inline int zoomInPercent() const { return qRound(m_zoom * 100); } 00123 KoZoomMode::Mode zoomMode() const { return m_zoomMode; } 00124 00125 // Input: pt. Output: pixels. Resolution and zoom are applied. 00126 00127 inline qreal zoomItX(qreal z) const 00128 { 00129 return m_zoomedResolutionX * z; 00130 } 00131 00132 inline qreal zoomItY(qreal z) const 00133 { 00134 return m_zoomedResolutionY * z ; 00135 } 00136 00137 // Input: pixels. Output: pt. 00138 inline qreal unzoomItX(qreal x) const 00139 { 00140 return x / m_zoomedResolutionX; 00141 } 00142 00143 inline qreal unzoomItY(qreal y) const 00144 { 00145 return y / m_zoomedResolutionY; 00146 } 00147 00148 // KoViewConverter-interface methods 00149 00154 virtual QPointF documentToView(const QPointF &documentPoint) const; 00155 00160 virtual QPointF viewToDocument(const QPointF &viewPoint) const; 00161 00166 virtual QRectF documentToView(const QRectF &documentRect) const; 00167 00172 virtual QRectF viewToDocument(const QRectF &viewRect) const; 00173 00179 virtual QSizeF documentToView(const QSizeF &documentSize) const; 00180 00186 virtual QSizeF viewToDocument(const QSizeF &viewSize) const; 00187 00193 virtual qreal documentToViewX(qreal documentX) const; 00194 00200 virtual qreal documentToViewY(qreal documentY) const; 00201 00207 virtual qreal viewToDocumentX(qreal viewX) const; 00208 00214 virtual qreal viewToDocumentY(qreal viewY) const; 00215 00221 virtual void zoom(qreal *zoomX, qreal *zoomY) const; 00222 00223 protected: 00224 qreal m_zoom; 00225 KoZoomMode::Mode m_zoomMode; 00226 00227 qreal m_resolutionX; 00228 qreal m_resolutionY; 00229 qreal m_zoomedResolutionX; 00230 qreal m_zoomedResolutionY; 00231 }; 00232 00233 #endif
