F:/KPlato/koffice/libs/kofficeui/KoZoomHandler.cpp

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2001-2005 David Faure <faure@kde.org>
00003    Copyright (C) 2006 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 #include "KoZoomHandler.h"
00022 #include <kdebug.h>
00023 #include <KoUnit.h> // for POINT_TO_INCH
00024 #include <KoGlobal.h>
00025 
00026 KoZoomHandler::KoZoomHandler() : KoViewConverter()
00027 {
00028     // Note that this calls the method below, not the derived one
00029     setZoomAndResolution( 100, KoGlobal::dpiX(), KoGlobal::dpiY() );
00030     setZoomMode( KoZoomMode::ZOOM_CONSTANT );
00031 }
00032 
00033 void KoZoomHandler::setZoomAndResolution( int zoom, int dpiX, int dpiY )
00034 {
00035     // m_resolution[XY] is in pixel per pt
00036     m_resolutionX = POINT_TO_INCH( static_cast<double>(dpiX) );
00037     m_resolutionY = POINT_TO_INCH( static_cast<double>(dpiY) );
00038     setZoom( zoom / 100.0 );
00039     /*kDebug(32500) << "KoZoomHandler::setZoomAndResolution " << zoom << " " << dpiX << "," << dpiY
00040               << " m_resolutionX=" << m_resolutionX
00041               << " m_zoomedResolutionX=" << m_zoomedResolutionX
00042               << " m_resolutionY=" << m_resolutionY
00043               << " m_zoomedResolutionY=" << m_zoomedResolutionY << endl;*/
00044 }
00045 
00046 void KoZoomHandler::setResolution( double resolutionX, double resolutionY )
00047 {
00048     m_zoom = 1.0;
00049     m_resolutionX = resolutionX;
00050     m_resolutionY = resolutionY;
00051     m_zoomedResolutionX = resolutionX;
00052     m_zoomedResolutionY = resolutionY;
00053 }
00054 
00055 void KoZoomHandler::setZoomedResolution( double zoomedResolutionX, double zoomedResolutionY )
00056 {
00057     // m_zoom doesn't matter, it's only used in setZoom() to calculated the zoomed resolutions
00058     // Here we know them. The whole point of this method is to allow a different zoom factor
00059     // for X and for Y, as can be useful for e.g. fullscreen kpresenter presentations.
00060     m_zoomedResolutionX = zoomedResolutionX;
00061     m_zoomedResolutionY = zoomedResolutionY;
00062 }
00063 
00064 void KoZoomHandler::setZoom( double zoom )
00065 {
00066     m_zoom = zoom;
00067     if( m_zoom == 1.0 ) {
00068         m_zoomedResolutionX = m_resolutionX;
00069         m_zoomedResolutionY = m_resolutionY;
00070     } else {
00071         m_zoomedResolutionX = m_zoom * m_resolutionX;
00072         m_zoomedResolutionY = m_zoom * m_resolutionY;
00073     }
00074 }
00075 
00076 void KoZoomHandler::setZoom( int zoom )
00077 {
00078     setZoom(zoom / 100.0);
00079 }
00080 
00081 QPointF KoZoomHandler::documentToView( const QPointF &documentPoint )  const{
00082     return QPointF( zoomItX( documentPoint.x() ), zoomItY( documentPoint.y() ) );
00083 }
00084 
00085 QPointF KoZoomHandler::viewToDocument( const QPointF &viewPoint )  const{
00086     return QPointF( unzoomItX( viewPoint.x() ), unzoomItY( viewPoint.y() ) );
00087 }
00088 
00089 QRectF KoZoomHandler::documentToView( const QRectF &documentRect )  const{
00090     QRectF r;
00091     r.setCoords( zoomItX( documentRect.left() ),  zoomItY( documentRect.top() ),
00092                   zoomItX( documentRect.right() ), zoomItY( documentRect.bottom() ) );
00093     return r;
00094 }
00095 
00096 QRectF KoZoomHandler::viewToDocument( const QRectF &viewRect )  const{
00097     QRectF r;
00098     r.setCoords( unzoomItX( viewRect.left() ),  unzoomItY( viewRect.top() ),
00099                   unzoomItX( viewRect.right() ), unzoomItY( viewRect.bottom() ) );
00100     return r;
00101 }
00102 
00103 double KoZoomHandler::documentToViewX( double documentX ) const
00104 {
00105     return zoomItX( documentX );
00106 }
00107 
00108 double KoZoomHandler::documentToViewY( double documentY ) const
00109 {
00110     return zoomItY( documentY );
00111 }
00112 
00113 double KoZoomHandler::viewToDocumentX( double viewX ) const
00114 {
00115     return unzoomItX( viewX );
00116 }
00117 
00118 double KoZoomHandler::viewToDocumentY( double viewY ) const
00119 {
00120     return unzoomItY( viewY );
00121 }
00122 
00123 void KoZoomHandler::zoom(double *zoomX, double *zoomY) const {
00124     *zoomX = zoomItX(100.0) / 100.0;
00125     *zoomY = zoomItY(100.0) / 100.0;
00126 }

Généré le Wed Nov 22 23:41:05 2006 pour KPlato par  doxygen 1.5.1-p1