~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to libs/flake/KoZoomHandler.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE project
2
 
   Copyright (C) 2001-2005 David Faure <faure@kde.org>
3
 
   Copyright (C) 2006, 2009 Thomas Zander <zander@kde.org>
4
 
 
5
 
   This library is free software; you can redistribute it and/or
6
 
   modify it under the terms of the GNU Library General Public
7
 
   License as published by the Free Software Foundation; either
8
 
   version 2 of the License, or (at your option) any later version.
9
 
 
10
 
   This library is distributed in the hope that it will be useful,
11
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
   Library General Public License for more details.
14
 
 
15
 
   You should have received a copy of the GNU Library General Public License
16
 
   along with this library; see the file COPYING.LIB.  If not, write to
17
 
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
 
   Boston, MA 02110-1301, USA.
19
 
*/
20
 
 
21
 
#ifndef KOZOOMHANDLER_H
22
 
#define KOZOOMHANDLER_H
23
 
 
24
 
#include "flake_export.h"
25
 
#include <KoZoomMode.h>
26
 
#include <KoViewConverter.h>
27
 
 
28
 
 
29
 
/**
30
 
 * This class handles the zooming and DPI stuff (conversions between
31
 
 * postscript pt values and pixels). If the internal data of your
32
 
 * document does not work with postscript points (for instance raster
33
 
 * image pixels), you need to some additional converting yourself.
34
 
 *
35
 
 * An instance of KoZoomHandler operates at a given zoom (see
36
 
 * setZoomAndResolution() and setZoom()) so there is usually one
37
 
 * instance of KoZoomHandler per view.
38
 
 */
39
 
class FLAKE_EXPORT KoZoomHandler : public KoViewConverter
40
 
{
41
 
public:
42
 
 
43
 
    KoZoomHandler();
44
 
    virtual ~KoZoomHandler();
45
 
 
46
 
    /**
47
 
     * Change the zoom factor to @p zoom (e.g. 150 for 150%)
48
 
     * and/or change the resolution of the output device, given in DPI.
49
 
     * This is done on startup and when zooming.
50
 
     * The same call combines both so that all the updating done behind
51
 
     * the scenes is done only once, even if both zoom and DPI must be changed.
52
 
     */
53
 
    virtual void setZoomAndResolution(int zoom, int dpiX, int dpiY);
54
 
 
55
 
    /**
56
 
     * @return the conversion factor between document and view, that
57
 
     * includes the zoom and also the DPI setting.
58
 
     */
59
 
    inline qreal zoomedResolutionX() const { return m_zoomedResolutionX; }
60
 
 
61
 
    /**
62
 
     * @return the conversion factor between document and view, that
63
 
     * includes the zoom and also the DPI setting.
64
 
     */
65
 
    inline qreal zoomedResolutionY() const { return m_zoomedResolutionY; }
66
 
 
67
 
    inline qreal resolutionX() const { return m_resolutionX; }
68
 
    inline qreal resolutionY() const { return m_resolutionY; }
69
 
 
70
 
    /**
71
 
     * Zoom factor for X. Equivalent to zoomedResolutionX()/resolutionX()
72
 
     */
73
 
    inline qreal zoomFactorX() const { return m_zoomedResolutionX / m_resolutionX; }
74
 
 
75
 
    /**
76
 
     * Zoom factor for Y. Equivalent to zoomedResolutionY()/resolutionY()
77
 
     */
78
 
    inline qreal zoomFactorY() const { return m_zoomedResolutionY / m_resolutionY; }
79
 
 
80
 
    /**
81
 
     * Set a resolution for X and Y of the output device.
82
 
     * The zoom factor is not changed.
83
 
     *
84
 
     * XXX: Is this also in dots per inch?
85
 
     */
86
 
    void setResolution(qreal resolutionX, qreal resolutionY);
87
 
 
88
 
    /**
89
 
     * Set the resolution for X and Y to the display values reported by KGlobal.
90
 
     * The zoom factor is not changed.
91
 
     */
92
 
    void setResolutionToStandard( );
93
 
 
94
 
    /**
95
 
     * Set the zoomed resolution for X and Y.
96
 
     * Compared to the setZoom... methods, this allows to set a different
97
 
     * zoom factor for X and for Y.
98
 
     */
99
 
    virtual void setZoomedResolution(qreal zoomedResolutionX, qreal zoomedResolutionY);
100
 
 
101
 
    /**
102
 
     * Change the zoom level, keeping the resolution unchanged.
103
 
     * @param zoom the zoom factor (e.g. 1.0 for 100%)
104
 
     */
105
 
    void setZoom(qreal zoom);
106
 
 
107
 
    inline qreal zoom() const { return m_zoom; }
108
 
 
109
 
    /**
110
 
     * Change the zoom mode
111
 
     * @param zoomMode the zoom mode.
112
 
     */
113
 
    inline void setZoomMode(KoZoomMode::Mode zoomMode) { m_zoomMode = zoomMode; }
114
 
    /**
115
 
     * @return the global zoom factor (e.g. 100 for 100%).
116
 
     * Only use this to display to the user, don't use in calculations
117
 
     */
118
 
    inline int zoomInPercent() const { return qRound(m_zoom * 100); }
119
 
    /**
120
 
     * @return the global zoom mode (e.g. KoZoomMode::ZOOM_WIDTH).
121
 
     * use this to determine how to zoom
122
 
     */
123
 
    KoZoomMode::Mode zoomMode() const { return m_zoomMode; }
124
 
 
125
 
    // Input: pt. Output: pixels. Resolution and zoom are applied.
126
 
 
127
 
    inline qreal zoomItX(qreal z) const
128
 
        {
129
 
            return m_zoomedResolutionX * z;
130
 
        }
131
 
 
132
 
    inline qreal zoomItY(qreal z) const
133
 
        {
134
 
            return m_zoomedResolutionY * z ;
135
 
        }
136
 
 
137
 
    // Input: pixels. Output: pt.
138
 
    inline qreal unzoomItX(qreal x) const
139
 
        {
140
 
            return  x / m_zoomedResolutionX;
141
 
        }
142
 
 
143
 
    inline qreal unzoomItY(qreal y) const
144
 
        {
145
 
            return  y / m_zoomedResolutionY;
146
 
        }
147
 
 
148
 
    // KoViewConverter-interface methods
149
 
 
150
 
    /**
151
 
     * Convert a coordinate in pt to pixels.
152
 
     * @param documentPoint the point in the document coordinate system of a KoShape.
153
 
     */
154
 
    virtual QPointF documentToView(const QPointF &documentPoint) const;
155
 
 
156
 
    /**
157
 
     * Convert a coordinate in pixels to pt.
158
 
     * @param viewPoint the point in the coordinate system of the widget, or window.
159
 
     */
160
 
    virtual QPointF viewToDocument(const QPointF &viewPoint) const;
161
 
 
162
 
    /**
163
 
     * Convert a rectangle in pt to pixels.
164
 
     * @param documentRect the rect in the document coordinate system of a KoShape.
165
 
     */
166
 
    virtual QRectF documentToView(const QRectF &documentRect) const;
167
 
 
168
 
    /**
169
 
     * Convert a rectangle in pixels to pt.
170
 
     * @param viewRect the rect in the coordinate system of the widget, or window.
171
 
     */
172
 
    virtual QRectF viewToDocument(const QRectF &viewRect) const;
173
 
 
174
 
    /**
175
 
     * Convert a size in pt to pixels.
176
 
     * @param documentSize the size in pt.
177
 
     * @return the size in pixels.
178
 
     */
179
 
    virtual QSizeF documentToView(const QSizeF &documentSize) const;
180
 
 
181
 
    /**
182
 
     * Convert a size in pixels to pt.
183
 
     * @param viewSize the size in pixels.
184
 
     * @return the size in pt.
185
 
     */
186
 
    virtual QSizeF viewToDocument(const QSizeF &viewSize) const;
187
 
 
188
 
    /**
189
 
     * Convert a single x coordinate in pt to pixels.
190
 
     * @param documentX the x coordinate in pt.
191
 
     * @return the x coordinate in pixels.
192
 
     */
193
 
    virtual qreal documentToViewX(qreal documentX) const;
194
 
 
195
 
    /**
196
 
     * Convert a single y coordinate in pt to pixels.
197
 
     * @param documentY the y coordinate in pt.
198
 
     * @return the y coordinate in pixels.
199
 
     */
200
 
    virtual qreal documentToViewY(qreal documentY) const;
201
 
 
202
 
    /**
203
 
     * Convert a single x coordinate in pixels to pt.
204
 
     * @param viewX the x coordinate in pixels.
205
 
     * @return the x coordinate in pt.
206
 
     */
207
 
    virtual qreal viewToDocumentX(qreal viewX) const;
208
 
 
209
 
    /**
210
 
     * Convert a single y coordinate in pixels to pt.
211
 
     * @param viewY the y coordinate in pixels.
212
 
     * @return the y coordinate in pt.
213
 
     */
214
 
    virtual qreal viewToDocumentY(qreal viewY) const;
215
 
 
216
 
    /**
217
 
     * Get the zoom levels of the individual x and y axis. Copy them to the pointer parameters.
218
 
     * @param zoomX a pointer to a qreal which will be modified to set the horizontal zoom.
219
 
     * @param zoomY a pointer to a qreal which will be modified to set the vertical zoom.
220
 
     */
221
 
    virtual void zoom(qreal *zoomX, qreal *zoomY) const;
222
 
 
223
 
protected:
224
 
    qreal m_zoom;
225
 
    KoZoomMode::Mode m_zoomMode;
226
 
 
227
 
    qreal m_resolutionX;
228
 
    qreal m_resolutionY;
229
 
    qreal m_zoomedResolutionX;
230
 
    qreal m_zoomedResolutionY;
231
 
};
232
 
 
233
 
#endif