lib

KoZoomHandler.h
1/* This file is part of the KDE project
2 Copyright (C) 2001-2005 David Faure <faure@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#ifndef kozoomhandler_h
21#define kozoomhandler_h
22
23#include <KoRect.h>
24#include <koffice_export.h>
25#include <KoZoomMode.h>
26
32class KOFFICEUI_EXPORT KoZoomHandler
33{
34public:
35 KoZoomHandler();
36 virtual ~KoZoomHandler() {}
37
45 virtual void setZoomAndResolution( int zoom, int dpiX, int dpiY );
46
52 double zoomedResolutionX() const { return m_zoomedResolutionX; }
53 double zoomedResolutionY() const { return m_zoomedResolutionY; }
54
55 double resolutionX() const { return m_resolutionX; }
56 double resolutionY() const { return m_resolutionY; }
57
61 double zoomFactorX() const { return m_zoomedResolutionX / m_resolutionX; }
65 double zoomFactorY() const { return m_zoomedResolutionY / m_resolutionY; }
66
67
74 void setResolution( double resolutionX, double resolutionY );
75
81 virtual void setZoomedResolution( double zoomedResolutionX, double zoomedResolutionY );
82
87 void setZoom( int zoom );
97 int zoom() const { return m_zoom; }
102 KoZoomMode::Mode zoomMode() const { return m_zoomMode; }
103
104 // Input: pt. Output: pixels. Resolution and zoom are applied.
105 int zoomItX( double z ) const {
106 return tqRound( m_zoomedResolutionX * z );
107 }
108 int zoomItY( double z ) const {
109 return tqRound( m_zoomedResolutionY * z );
110 }
111
112 TQPoint zoomPoint( const KoPoint & p ) const {
113 return TQPoint( zoomItX( p.x() ), zoomItY( p.y() ) );
114 }
115 TQRect zoomRect( const KoRect & r ) const {
116 TQRect _r;
117 _r.setCoords( zoomItX( r.left() ), zoomItY( r.top() ),
118 zoomItX( r.right() ), zoomItY( r.bottom() ) );
119 return _r;
120 }
131 TQSize zoomSize( const KoSize & s ) const {
132 return TQSize( zoomItX( s.width() ), zoomItY( s.height() ) );
133 }
134
135 // Input: pixels. Output: pt.
136 double unzoomItX( int x ) const {
137 return static_cast<double>( x ) / m_zoomedResolutionX;
138 }
139 double unzoomItY( int y ) const {
140 return static_cast<double>( y ) / m_zoomedResolutionY;
141 }
142 KoPoint unzoomPoint( const TQPoint & p ) const {
143 return KoPoint( unzoomItX( p.x() ), unzoomItY( p.y() ) );
144 }
145 KoRect unzoomRect( const TQRect & r ) const {
146 KoRect _r;
147 _r.setCoords( unzoomItX( r.left() ), unzoomItY( r.top() ),
148 unzoomItX( r.right() ), unzoomItY( r.bottom() ) );
149 return _r;
150 }
151
152
153protected:
154 int m_zoom;
155 KoZoomMode::Mode m_zoomMode;
156
157 double m_resolutionX;
158 double m_resolutionY;
159 double m_zoomedResolutionX;
160 double m_zoomedResolutionY;
161};
162
163#endif
A size whose coordinates are floating-point values ( "double"s ).
Definition KoSize.h:34
double zoomFactorY() const
Zoom factor for Y.
KoZoomMode::Mode zoomMode() const
int zoom() const
void setZoomMode(KoZoomMode::Mode zoomMode)
Change the zoom mode.
virtual void setZoomAndResolution(int zoom, int dpiX, int dpiY)
Change the zoom factor to z (e.g.
double zoomFactorX() const
Zoom factor for X.
TQSize zoomSize(const KoSize &s) const
Returns the size in pixels for a input size in points.
double zoomedResolutionX() const