lib

KoZoomHandler.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001-2005 David Faure <faure@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "KoZoomHandler.h"
00021 #include <kdebug.h>
00022 #include <KoUnit.h> // for POINT_TO_INCH
00023 #include <KoGlobal.h>
00024 
00025 KoZoomHandler::KoZoomHandler()
00026 {
00027     // Note that this calls the method below, not the derived one
00028     setZoomAndResolution( 100, KoGlobal::dpiX(), KoGlobal::dpiY() );
00029 }
00030 
00031 void KoZoomHandler::setZoomAndResolution( int zoom, int dpiX, int dpiY )
00032 {
00033     // m_resolution[XY] is in pixel per pt
00034     m_resolutionX = POINT_TO_INCH( static_cast<double>(dpiX) );
00035     m_resolutionY = POINT_TO_INCH( static_cast<double>(dpiY) );
00036     setZoom( zoom );
00037     /*kdDebug(32500) << "KoZoomHandler::setZoomAndResolution " << zoom << " " << dpiX << "," << dpiY
00038               << " m_resolutionX=" << m_resolutionX
00039               << " m_zoomedResolutionX=" << m_zoomedResolutionX
00040               << " m_resolutionY=" << m_resolutionY
00041               << " m_zoomedResolutionY=" << m_zoomedResolutionY << endl;*/
00042 }
00043 
00044 void KoZoomHandler::setResolution( double resolutionX, double resolutionY )
00045 {
00046     m_zoom = 100;
00047     m_resolutionX = resolutionX;
00048     m_resolutionY = resolutionY;
00049     m_zoomedResolutionX = resolutionX;
00050     m_zoomedResolutionY = resolutionY;
00051 }
00052 
00053 void KoZoomHandler::setZoomedResolution( double zoomedResolutionX, double zoomedResolutionY )
00054 {
00055     // m_zoom doesn't matter, it's only used in setZoom() to calculated the zoomed resolutions
00056     // Here we know them. The whole point of this method is to allow a different zoom factor
00057     // for X and for Y, as can be useful for e.g. fullscreen kpresenter presentations.
00058     m_zoomedResolutionX = zoomedResolutionX;
00059     m_zoomedResolutionY = zoomedResolutionY;
00060 }
00061 
00062 void KoZoomHandler::setZoom( int zoom )
00063 {
00064     m_zoom = zoom;
00065     if( m_zoom == 100 ) {
00066         m_zoomedResolutionX = m_resolutionX;
00067         m_zoomedResolutionY = m_resolutionY;
00068     } else {
00069         m_zoomedResolutionX = static_cast<double>(m_zoom) * m_resolutionX / 100.0;
00070         m_zoomedResolutionY = static_cast<double>(m_zoom) * m_resolutionY / 100.0;
00071     }
00072 }
KDE Home | KDE Accessibility Home | Description of Access Keys