kozoomhandler.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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
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
00164 { return qRound( static_cast<double>( x * m_layoutUnitFactor * 100 ) / static_cast<double>(m_zoom) ); }
00165 int pixelToLayoutUnitY( int y ) const
00166
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
00178
00179 { return int( static_cast<double>( lupix * m_zoom ) / static_cast<double>( m_layoutUnitFactor * 100 ) ); }
00180 int layoutUnitToPixelY( int lupix ) const
00181
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 ) const;
00230
00231
00232
00233
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
This file is part of the documentation for lib Library Version 1.3.5.