lib Library API Documentation

kozoomhandler.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 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., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #ifndef kozoomhandler_h
00021 #define kozoomhandler_h
00022 
00023 #include <koRect.h>
00024 
00032 class KoTextZoomHandler
00033 {
00034 public:
00035     KoTextZoomHandler() {}
00036     virtual ~KoTextZoomHandler() {}
00037 
00040     static void setPtToLayoutUnitFactor( int factor ) { m_layoutUnitFactor = factor; }
00041 
00044     static double ptToLayoutUnitPt( double pt )
00045     { return pt * static_cast<double>( m_layoutUnitFactor ); }
00047     static int ptToLayoutUnitPt( int ptSize )
00048     { return ptSize * m_layoutUnitFactor; }
00049 
00050     static KoPoint ptToLayoutUnitPt( const KoPoint &p )
00051     { return KoPoint( ptToLayoutUnitPt( p.x() ),
00052                       ptToLayoutUnitPt( p.y() ) ); }
00053     static KoRect ptToLayoutUnitPt( const KoRect &r )
00054     { return KoRect( ptToLayoutUnitPt( r.topLeft() ),
00055                      ptToLayoutUnitPt( r.bottomRight() ) ); }
00056 
00057     static double layoutUnitPtToPt( double lupt )
00058     { return lupt / static_cast<double>( m_layoutUnitFactor ); }
00059     static KoPoint layoutUnitPtToPt( const KoPoint& p )
00060     { return KoPoint( layoutUnitPtToPt( p.x() ),
00061                       layoutUnitPtToPt( p.y() ) ); }
00062 
00063 protected:
00065     static int m_layoutUnitFactor;
00066 };
00067 
00073 class KoZoomHandler : public KoTextZoomHandler
00074 {
00075 public:
00076     KoZoomHandler();
00077     virtual ~KoZoomHandler() {}
00078 
00086     virtual void setZoomAndResolution( int zoom, int dpiX, int dpiY );
00087 
00093     double zoomedResolutionX() const { return m_zoomedResolutionX; }
00094     double zoomedResolutionY() const { return m_zoomedResolutionY; }
00095 
00096     double resolutionX() const { return m_resolutionX; }
00097     double resolutionY() const { return m_resolutionY; }
00098 
00099 
00105     virtual void setResolution( double resolutionX, double resolutionY );
00106 
00107 
00108     int zoom() const { return m_zoom; }
00109 
00110     // Input: pt. Output: pixels. Resolution and zoom are applied.
00111     int zoomItX( double z ) const {
00112         return qRound( m_zoomedResolutionX * z );
00113     }
00114     int zoomItY( double z ) const {
00115         return qRound( m_zoomedResolutionY * z );
00116     }
00117 
00118     QPoint zoomPoint( const KoPoint & p ) const {
00119         return QPoint( zoomItX( p.x() ), zoomItY( p.y() ) );
00120     }
00121     QRect zoomRect( const KoRect & r ) const {
00122         QRect _r;
00123         _r.setCoords( zoomItX( r.left() ),  zoomItY( r.top() ),
00124                       zoomItX( r.right() ), zoomItY( r.bottom() ) );
00125         return _r;
00126     }
00137     QSize zoomSize( const KoSize & s ) const {
00138         return QSize( zoomItX( s.width() ), zoomItY( s.height() ) );
00139     }
00140 
00141     // Input: pixels. Output: pt.
00142     double unzoomItX( int x ) const {
00143         return static_cast<double>( x ) / m_zoomedResolutionX;
00144     }
00145     double unzoomItY( int y ) const {
00146         return static_cast<double>( y ) / m_zoomedResolutionY;
00147     }
00148     KoPoint unzoomPoint( const QPoint & p ) const {
00149         return KoPoint( unzoomItX( p.x() ), unzoomItY( p.y() ) );
00150     }
00151     KoRect unzoomRect( const QRect & r ) const {
00152         KoRect _r;
00153         _r.setCoords( unzoomItX( r.left() ),  unzoomItY( r.top() ),
00154                       unzoomItX( r.right() ), unzoomItY( r.bottom() ) );
00155         return _r;
00156     }
00157 
00158 
00160 
00162     int pixelToLayoutUnitX( int x ) const
00163       // No need to apply the resolution here.
00164     { return qRound( static_cast<double>( x * m_layoutUnitFactor * 100 ) / static_cast<double>(m_zoom) ); }
00165     int pixelToLayoutUnitY( int y ) const
00166       // Same as pixelToLayoutUnitX nowadays
00167     { return qRound( static_cast<double>( y * m_layoutUnitFactor * 100 ) / static_cast<double>(m_zoom) ); }
00168     QPoint pixelToLayoutUnit( const QPoint &p ) const
00169     { return QPoint( pixelToLayoutUnitX( p.x() ),
00170                      pixelToLayoutUnitY( p.y() ) ); }
00171     QRect pixelToLayoutUnit( const QRect &r ) const
00172     { return QRect( pixelToLayoutUnit( r.topLeft() ),
00173                     pixelToLayoutUnit( r.bottomRight() ) ); }
00174 
00176     int layoutUnitToPixelX( int lupix ) const
00177       // No need to apply the resolution here.
00178       // qRound replaced with a truncation, too many problems (e.g. bottom of parags)
00179     { return int( static_cast<double>( lupix * m_zoom ) / static_cast<double>( m_layoutUnitFactor * 100 ) ); }
00180     int layoutUnitToPixelY( int lupix ) const
00181       // Same as layoutUnitToPixelX nowadays
00182     { return layoutUnitToPixelX( lupix ); }
00183 
00186     int layoutUnitToPixelX( int x, int w ) const;
00189     int layoutUnitToPixelY( int y, int h ) const;
00190 
00191     QPoint layoutUnitToPixel( const QPoint &p ) const
00192     { return QPoint( layoutUnitToPixelX( p.x() ),
00193                      layoutUnitToPixelY( p.y() ) ); }
00194     QRect layoutUnitToPixel( const QRect &r ) const
00195     { return QRect( layoutUnitToPixel( r.topLeft() ),
00196                     layoutUnitToPixel( r.bottomRight() ) ); }
00197 
00201     int ptToPixelX( double pt ) const
00202     { return qRound( pt * m_resolutionX ); }
00203     int ptToPixelY( double pt ) const
00204     { return qRound( pt * m_resolutionY ); }
00205     QPoint ptToPixel( const KoPoint & p ) const {
00206         return QPoint( ptToPixelX( p.x() ), ptToPixelY( p.y() ) );
00207     }
00208     double pixelXToPt( int x ) const
00209     { return static_cast<double>(x) / m_resolutionX; }
00210     double pixelYToPt( int y ) const
00211     { return static_cast<double>(y) / m_resolutionY; }
00212     KoPoint pixelToPt( const QPoint& p ) const {
00213         return KoPoint( pixelXToPt( p.x() ), pixelYToPt( p.y() ) );
00214     }
00215 
00217     int ptToLayoutUnitPixX( double x_pt ) const
00218     { return ptToPixelX( ptToLayoutUnitPt( x_pt ) ); }
00219     int ptToLayoutUnitPixY( double y_pt ) const
00220     { return ptToPixelY( ptToLayoutUnitPt( y_pt ) ); }
00221     QPoint ptToLayoutUnitPix( const KoPoint & p ) const {
00222         return QPoint( ptToLayoutUnitPixX( p.x() ), ptToLayoutUnitPixY( p.y() ) );
00223     }
00224 
00229     double layoutUnitToFontSize( int luSize, bool /*forPrint*/ ) const;
00230 
00231     // Note: For converting fontsizes from/to layout units and zoom-independent
00232     // pt sizes (like the one the user sees, e.g. 12pt),
00233     // use ptToLayoutUnit and layoutUnitToPt, not layoutToFontSize.
00234 
00235 protected:
00236     int m_zoom;
00237     double m_resolutionX;
00238     double m_resolutionY;
00239     double m_zoomedResolutionX;
00240     double m_zoomedResolutionY;
00241 };
00242 
00243 #endif
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Mar 20 14:25:28 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003