F:/KPlato/koffice/libs/kotext/KoTextZoomHandler.h

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 
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 kotextzoomhandler_h
00021 #define kotextzoomhandler_h
00022 
00023 #include <KoZoomHandler.h>
00024 
00028 class KOTEXT_EXPORT KoTextZoomHandler : public KoZoomHandler
00029 {
00030 public:
00031     KoTextZoomHandler() {}
00032     virtual ~KoTextZoomHandler() {}
00033 
00035 
00037     int pixelToLayoutUnitX( int x ) const;
00038     int pixelToLayoutUnitY( int y ) const;
00039     QPoint pixelToLayoutUnit( const QPoint &p ) const
00040     { return QPoint( pixelToLayoutUnitX( p.x() ),
00041                      pixelToLayoutUnitY( p.y() ) ); }
00042     QRect pixelToLayoutUnit( const QRect &r ) const
00043     { return QRect( pixelToLayoutUnit( r.topLeft() ),
00044                     pixelToLayoutUnit( r.bottomRight() ) ); }
00045 
00047     int layoutUnitToPixelX( int lupix ) const;
00048     int layoutUnitToPixelY( int lupix ) const;
00049 
00052     int layoutUnitToPixelX( int x, int w ) const;
00055     int layoutUnitToPixelY( int y, int h ) const;
00056 
00057     QPoint layoutUnitToPixel( const QPoint &p ) const
00058     { return QPoint( layoutUnitToPixelX( p.x() ),
00059                      layoutUnitToPixelY( p.y() ) ); }
00060     QRect layoutUnitToPixel( const QRect &r ) const
00061     { return QRect( layoutUnitToPixel( r.topLeft() ),
00062                     layoutUnitToPixel( r.bottomRight() ) ); }
00063 
00067     int ptToPixelX( double pt ) const
00068     { return qRound( pt * m_resolutionX ); }
00069     int ptToPixelY( double pt ) const
00070     { return qRound( pt * m_resolutionY ); }
00071     QPoint ptToPixel( const KoPoint & p ) const {
00072         return QPoint( ptToPixelX( p.x() ), ptToPixelY( p.y() ) );
00073     }
00074     double pixelXToPt( int x ) const
00075     { return static_cast<double>(x) / m_resolutionX; }
00076     double pixelYToPt( int y ) const
00077     { return static_cast<double>(y) / m_resolutionY; }
00078     KoPoint pixelToPt( const QPoint& p ) const {
00079         return KoPoint( pixelXToPt( p.x() ), pixelYToPt( p.y() ) );
00080     }
00081 
00083     int ptToLayoutUnitPixX( double x_pt ) const
00084     { return ptToPixelX( ptToLayoutUnitPt( x_pt ) ); }
00085     int ptToLayoutUnitPixY( double y_pt ) const
00086     { return ptToPixelY( ptToLayoutUnitPt( y_pt ) ); }
00087     QPoint ptToLayoutUnitPix( const KoPoint & p ) const {
00088         return QPoint( ptToLayoutUnitPixX( p.x() ), ptToLayoutUnitPixY( p.y() ) );
00089     }
00090 
00095     double layoutUnitToFontSize( int luSize, bool /*forPrint*/ ) const;
00096 
00097     // Note: For converting fontsizes from/to layout units and zoom-independent
00098     // pt sizes (like the one the user sees, e.g. 12pt),
00099     // use ptToLayoutUnit and layoutUnitToPt, not layoutToFontSize.
00100 
00101 
00102     // The conversions below convert between an internal text layout resolution of
00103     // ~1440 DPI (by default) and the point-size for the fonts (those known by the user).
00104     // Those conversions don't depend on the zoom level.
00105 
00108     static void setPtToLayoutUnitFactor( int factor ) { m_layoutUnitFactor = factor; }
00109 
00112     static double ptToLayoutUnitPt( double pt )
00113     { return pt * static_cast<double>( m_layoutUnitFactor ); }
00115     static int ptToLayoutUnitPt( int ptSize )
00116     { return ptSize * m_layoutUnitFactor; }
00117 
00118     static KoPoint ptToLayoutUnitPt( const KoPoint &p )
00119     { return KoPoint( ptToLayoutUnitPt( p.x() ),
00120                       ptToLayoutUnitPt( p.y() ) ); }
00121     static KoRect ptToLayoutUnitPt( const KoRect &r )
00122     { return KoRect( ptToLayoutUnitPt( r.topLeft() ),
00123                      ptToLayoutUnitPt( r.bottomRight() ) ); }
00124 
00125     static double layoutUnitPtToPt( double lupt )
00126     { return lupt / static_cast<double>( m_layoutUnitFactor ); }
00127     static KoPoint layoutUnitPtToPt( const KoPoint& p )
00128     { return KoPoint( layoutUnitPtToPt( p.x() ),
00129                       layoutUnitPtToPt( p.y() ) ); }
00130 
00131 protected:
00133     static int m_layoutUnitFactor;
00134 };
00135 
00136 #endif

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