KoZoomHandler.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001-2005 David Faure <faure@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include "KoZoomHandler.h"
21#include <kdebug.h>
22#include <KoUnit.h> // for POINT_TO_INCH
23#include <KoGlobal.h>
24
25KoZoomHandler::KoZoomHandler()
26{
27 // Note that this calls the method below, not the derived one
28 setZoomAndResolution( 100, KoGlobal::dpiX(), KoGlobal::dpiY() );
29}
30
31void KoZoomHandler::setZoomAndResolution( int zoom, int dpiX, int dpiY )
32{
33 // m_resolution[XY] is in pixel per pt
34 m_resolutionX = POINT_TO_INCH( static_cast<double>(dpiX) );
35 m_resolutionY = POINT_TO_INCH( static_cast<double>(dpiY) );
36 setZoom( zoom );
37 /*kdDebug(32500) << "KoZoomHandler::setZoomAndResolution " << zoom << " " << dpiX << "," << dpiY
38 << " m_resolutionX=" << m_resolutionX
39 << " m_zoomedResolutionX=" << m_zoomedResolutionX
40 << " m_resolutionY=" << m_resolutionY
41 << " m_zoomedResolutionY=" << m_zoomedResolutionY << endl;*/
42}
43
44void KoZoomHandler::setResolution( double resolutionX, double resolutionY )
45{
46 m_zoom = 100;
47 m_resolutionX = resolutionX;
48 m_resolutionY = resolutionY;
49 m_zoomedResolutionX = resolutionX;
50 m_zoomedResolutionY = resolutionY;
51}
52
53void KoZoomHandler::setZoomedResolution( double zoomedResolutionX, double zoomedResolutionY )
54{
55 // m_zoom doesn't matter, it's only used in setZoom() to calculated the zoomed resolutions
56 // Here we know them. The whole point of this method is to allow a different zoom factor
57 // for X and for Y, as can be useful for e.g. fullscreen kpresenter presentations.
58 m_zoomedResolutionX = zoomedResolutionX;
59 m_zoomedResolutionY = zoomedResolutionY;
60}
61
62void KoZoomHandler::setZoom( int zoom )
63{
64 m_zoom = zoom;
65 if( m_zoom == 100 ) {
66 m_zoomedResolutionX = m_resolutionX;
67 m_zoomedResolutionY = m_resolutionY;
68 } else {
69 m_zoomedResolutionX = static_cast<double>(m_zoom) * m_resolutionX / 100.0;
70 m_zoomedResolutionY = static_cast<double>(m_zoom) * m_resolutionY / 100.0;
71 }
72}
virtual void setZoomedResolution(double zoomedResolutionX, double zoomedResolutionY)
Set the zoomed resolution for X and Y.
void setResolution(double resolutionX, double resolutionY)
Set a resolution for X and Y, when no zoom applies (e.g.
int zoom() const
virtual void setZoomAndResolution(int zoom, int dpiX, int dpiY)
Change the zoom factor to z (e.g.
double zoomedResolutionX() const
void setZoom(int zoom)
Change the zoom level, keeping the resolution unchanged.