lib

KoZoomHandler.h

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 #ifndef kozoomhandler_h
00021 #define kozoomhandler_h
00022 
00023 #include <KoRect.h>
00024 #include <koffice_export.h>
00025 #include <KoZoomMode.h>
00026 
00032 class KOFFICEUI_EXPORT KoZoomHandler
00033 {
00034 public:
00035     KoZoomHandler();
00036     virtual ~KoZoomHandler() {}
00037 
00045     virtual void setZoomAndResolution( int zoom, int dpiX, int dpiY );
00046 
00052     double zoomedResolutionX() const { return m_zoomedResolutionX; }
00053     double zoomedResolutionY() const { return m_zoomedResolutionY; }
00054 
00055     double resolutionX() const { return m_resolutionX; }
00056     double resolutionY() const { return m_resolutionY; }
00057 
00061     double zoomFactorX() const { return m_zoomedResolutionX / m_resolutionX; }
00065     double zoomFactorY() const { return m_zoomedResolutionY / m_resolutionY; }
00066 
00067 
00074     void setResolution( double resolutionX, double resolutionY );
00075 
00081     virtual void setZoomedResolution( double zoomedResolutionX, double zoomedResolutionY );
00082 
00087     void setZoom( int zoom );
00092     void setZoomMode( KoZoomMode::Mode zoomMode ) { m_zoomMode = zoomMode; }
00097     int zoom() const { return m_zoom; }
00102     KoZoomMode::Mode zoomMode() const { return m_zoomMode; }
00103     
00104     // Input: pt. Output: pixels. Resolution and zoom are applied.
00105     int zoomItX( double z ) const {
00106         return qRound( m_zoomedResolutionX * z );
00107     }
00108     int zoomItY( double z ) const {
00109         return qRound( m_zoomedResolutionY * z );
00110     }
00111 
00112     QPoint zoomPoint( const KoPoint & p ) const {
00113         return QPoint( zoomItX( p.x() ), zoomItY( p.y() ) );
00114     }
00115     QRect zoomRect( const KoRect & r ) const {
00116         QRect _r;
00117         _r.setCoords( zoomItX( r.left() ),  zoomItY( r.top() ),
00118                       zoomItX( r.right() ), zoomItY( r.bottom() ) );
00119         return _r;
00120     }
00131     QSize zoomSize( const KoSize & s ) const {
00132         return QSize( zoomItX( s.width() ), zoomItY( s.height() ) );
00133     }
00134 
00135     // Input: pixels. Output: pt.
00136     double unzoomItX( int x ) const {
00137         return static_cast<double>( x ) / m_zoomedResolutionX;
00138     }
00139     double unzoomItY( int y ) const {
00140         return static_cast<double>( y ) / m_zoomedResolutionY;
00141     }
00142     KoPoint unzoomPoint( const QPoint & p ) const {
00143         return KoPoint( unzoomItX( p.x() ), unzoomItY( p.y() ) );
00144     }
00145     KoRect unzoomRect( const QRect & r ) const {
00146         KoRect _r;
00147         _r.setCoords( unzoomItX( r.left() ),  unzoomItY( r.top() ),
00148                       unzoomItX( r.right() ), unzoomItY( r.bottom() ) );
00149         return _r;
00150     }
00151 
00152 
00153 protected:
00154     int m_zoom;
00155     KoZoomMode::Mode m_zoomMode;
00156     
00157     double m_resolutionX;
00158     double m_resolutionY;
00159     double m_zoomedResolutionX;
00160     double m_zoomedResolutionY;
00161 };
00162 
00163 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys