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 #include <koffice_export.h>
00032 class KOTEXT_EXPORT 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 KOTEXT_EXPORT 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 
00102     double zoomFactorX() const { return m_zoomedResolutionX / m_resolutionX; }
00106     double zoomFactorY() const { return m_zoomedResolutionY / m_resolutionY; }
00107 
00108 
00115     void setResolution( double resolutionX, double resolutionY );
00116 
00122     virtual void setZoomedResolution( double zoomedResolutionX, double zoomedResolutionY );
00123 
00128     void setZoom( int zoom );
00129 
00134     int zoom() const { return m_zoom; }
00135 
00136     // Input: pt. Output: pixels. Resolution and zoom are applied.
00137     int zoomItX( double z ) const {
00138         return qRound( m_zoomedResolutionX * z );
00139     }
00140     int zoomItY( double z ) const {
00141         return qRound( m_zoomedResolutionY * z );
00142     }
00143 
00144     QPoint zoomPoint( const KoPoint & p ) const {
00145         return QPoint( zoomItX( p.x() ), zoomItY( p.y() ) );
00146     }
00147     QRect zoomRect( const KoRect & r ) const {
00148         QRect _r;
00149         _r.setCoords( zoomItX( r.left() ),  zoomItY( r.top() ),
00150                       zoomItX( r.right() ), zoomItY( r.bottom() ) );
00151         return _r;
00152     }
00163     QSize zoomSize( const KoSize & s ) const {
00164         return QSize( zoomItX( s.width() ), zoomItY( s.height() ) );
00165     }
00166 
00167     // Input: pixels. Output: pt.
00168     double unzoomItX( int x ) const {
00169         return static_cast<double>( x ) / m_zoomedResolutionX;
00170     }
00171     double unzoomItY( int y ) const {
00172         return static_cast<double>( y ) / m_zoomedResolutionY;
00173     }
00174     KoPoint unzoomPoint( const QPoint & p ) const {
00175         return KoPoint( unzoomItX( p.x() ), unzoomItY( p.y() ) );
00176     }
00177     KoRect unzoomRect( const QRect & r ) const {
00178         KoRect _r;
00179         _r.setCoords( unzoomItX( r.left() ),  unzoomItY( r.top() ),
00180                       unzoomItX( r.right() ), unzoomItY( r.bottom() ) );
00181         return _r;
00182     }
00183 
00184 
00186 
00188     int pixelToLayoutUnitX( int x ) const;
00189     int pixelToLayoutUnitY( int y ) const;
00190     QPoint pixelToLayoutUnit( const QPoint &p ) const
00191     { return QPoint( pixelToLayoutUnitX( p.x() ),
00192                      pixelToLayoutUnitY( p.y() ) ); }
00193     QRect pixelToLayoutUnit( const QRect &r ) const
00194     { return QRect( pixelToLayoutUnit( r.topLeft() ),
00195                     pixelToLayoutUnit( r.bottomRight() ) ); }
00196 
00198     int layoutUnitToPixelX( int lupix ) const;
00199     int layoutUnitToPixelY( int lupix ) const;
00200 
00203     int layoutUnitToPixelX( int x, int w ) const;
00206     int layoutUnitToPixelY( int y, int h ) const;
00207 
00208     QPoint layoutUnitToPixel( const QPoint &p ) const
00209     { return QPoint( layoutUnitToPixelX( p.x() ),
00210                      layoutUnitToPixelY( p.y() ) ); }
00211     QRect layoutUnitToPixel( const QRect &r ) const
00212     { return QRect( layoutUnitToPixel( r.topLeft() ),
00213                     layoutUnitToPixel( r.bottomRight() ) ); }
00214 
00218     int ptToPixelX( double pt ) const
00219     { return qRound( pt * m_resolutionX ); }
00220     int ptToPixelY( double pt ) const
00221     { return qRound( pt * m_resolutionY ); }
00222     QPoint ptToPixel( const KoPoint & p ) const {
00223         return QPoint( ptToPixelX( p.x() ), ptToPixelY( p.y() ) );
00224     }
00225     double pixelXToPt( int x ) const
00226     { return static_cast<double>(x) / m_resolutionX; }
00227     double pixelYToPt( int y ) const
00228     { return static_cast<double>(y) / m_resolutionY; }
00229     KoPoint pixelToPt( const QPoint& p ) const {
00230         return KoPoint( pixelXToPt( p.x() ), pixelYToPt( p.y() ) );
00231     }
00232 
00234     int ptToLayoutUnitPixX( double x_pt ) const
00235     { return ptToPixelX( ptToLayoutUnitPt( x_pt ) ); }
00236     int ptToLayoutUnitPixY( double y_pt ) const
00237     { return ptToPixelY( ptToLayoutUnitPt( y_pt ) ); }
00238     QPoint ptToLayoutUnitPix( const KoPoint & p ) const {
00239         return QPoint( ptToLayoutUnitPixX( p.x() ), ptToLayoutUnitPixY( p.y() ) );
00240     }
00241 
00246     double layoutUnitToFontSize( int luSize, bool /*forPrint*/ ) const;
00247 
00248     // Note: For converting fontsizes from/to layout units and zoom-independent
00249     // pt sizes (like the one the user sees, e.g. 12pt),
00250     // use ptToLayoutUnit and layoutUnitToPt, not layoutToFontSize.
00251 
00252 protected:
00253     int m_zoom;
00254     double m_resolutionX;
00255     double m_resolutionY;
00256     double m_zoomedResolutionX;
00257     double m_zoomedResolutionY;
00258 };
00259 
00260 #endif
KDE Logo
This file is part of the documentation for lib Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:40:14 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003