Warning, file /office/calligra/libs/widgets/KoZoomHandler.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002    Copyright (C) 2001-2005 David Faure <faure@kde.org>
0003    Copyright (C) 2006 Thomas Zander <zander@kde.org>
0004    Copyright (C) 2010 KO GmbH <boud@kogmbh.com>
0005 
0006    This library is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU Library General Public
0008    License as published by the Free Software Foundation; either
0009    version 2 of the License, or (at your option) any later version.
0010 
0011    This library is distributed in the hope that it will be useful,
0012    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014    Library General Public License for more details.
0015 
0016    You should have received a copy of the GNU Library General Public License
0017    along with this library; see the file COPYING.LIB.  If not, write to
0018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019    Boston, MA 02110-1301, USA.
0020 */
0021 
0022 #include "KoZoomHandler.h"
0023 #include <WidgetsDebug.h>
0024 #include <KoUnit.h> // for POINT_TO_INCH
0025 #include <KoDpi.h>
0026 #include <QPointF>
0027 #include <QRectF>
0028 
0029 KoZoomHandler::KoZoomHandler()
0030     : KoViewConverter()
0031     , m_zoomMode(KoZoomMode::ZOOM_CONSTANT)
0032     , m_resolutionX(0)
0033     , m_resolutionY(0)
0034     , m_zoomedResolutionX(0)
0035     , m_zoomedResolutionY(0)
0036 {
0037     setZoom(1.0);
0038     setZoomMode( KoZoomMode::ZOOM_CONSTANT );
0039     setDpi(KoDpi::dpiX(), KoDpi::dpiY());
0040 }
0041 
0042 void KoZoomHandler::setResolutionToStandard()
0043 {
0044     setDpi(KoDpi::dpiX(), KoDpi::dpiY());
0045 }
0046 
0047 void KoZoomHandler::setDpi(int dpiX, int dpiY)
0048 {
0049     setResolution(POINT_TO_INCH(static_cast<qreal>(dpiX)),
0050                   POINT_TO_INCH(static_cast<qreal>(dpiY)));
0051 }
0052 
0053 void KoZoomHandler::setResolution( qreal resolutionX, qreal resolutionY )
0054 {
0055 
0056     m_resolutionX = resolutionX;
0057     m_resolutionY = resolutionY;
0058 
0059     if (qFuzzyCompare(m_resolutionX, 1))
0060         m_resolutionX = 1;
0061     if (qFuzzyCompare(m_resolutionY, 1))
0062         m_resolutionY = 1;
0063 
0064     m_zoomedResolutionX = zoom() * resolutionX;
0065     m_zoomedResolutionY = zoom() * resolutionY;
0066 }
0067 
0068 void KoZoomHandler::setZoomedResolution( qreal zoomedResolutionX, qreal zoomedResolutionY )
0069 {
0070     // zoom() doesn't matter, it's only used in setZoom() to calculated the zoomed resolutions
0071     // Here we know them. The whole point of this method is to allow a different zoom factor
0072     // for X and for Y, as can be useful for e.g. fullscreen Stage presentations.
0073     m_zoomedResolutionX = zoomedResolutionX;
0074     m_zoomedResolutionY = zoomedResolutionY;
0075 }
0076 
0077 void KoZoomHandler::setZoom( qreal zoom )
0078 {
0079     if (qFuzzyCompare(zoom, qreal(1.0))) {
0080         zoom = 1.0;
0081     }
0082 
0083     KoViewConverter::setZoom(zoom);
0084     if( zoom == 1.0 ) {
0085         m_zoomedResolutionX = m_resolutionX;
0086         m_zoomedResolutionY = m_resolutionY;
0087     } else {
0088         m_zoomedResolutionX = zoom * m_resolutionX;
0089         m_zoomedResolutionY = zoom * m_resolutionY;
0090     }
0091 }
0092 
0093 QPointF KoZoomHandler::documentToView( const QPointF &documentPoint )  const
0094 {
0095     return QPointF( zoomItX( documentPoint.x() ),
0096                     zoomItY( documentPoint.y() ));
0097 }
0098 
0099 QPointF KoZoomHandler::viewToDocument( const QPointF &viewPoint )  const
0100 {
0101     return QPointF( unzoomItX( viewPoint.x() ),
0102                     unzoomItY( viewPoint.y() ) );
0103 }
0104 
0105 QRectF KoZoomHandler::documentToView( const QRectF &documentRect )  const
0106 {
0107     QRectF r (zoomItX( documentRect.x() ),
0108               zoomItY( documentRect.y() ),
0109               zoomItX( documentRect.width() ),
0110               zoomItY( documentRect.height() ) );
0111     return r;
0112 }
0113 
0114 QRectF KoZoomHandler::viewToDocument( const QRectF &viewRect )  const
0115 {
0116     QRectF r (  unzoomItX( viewRect.x() ),
0117                 unzoomItY( viewRect.y()),
0118                 unzoomItX( viewRect.width() ),
0119                 unzoomItY( viewRect.height() ) );
0120     return r;
0121 }
0122 
0123 QSizeF KoZoomHandler::documentToView( const QSizeF &documentSize ) const
0124 {
0125     return QSizeF( zoomItX( documentSize.width() ),
0126                    zoomItY( documentSize.height() ) );
0127 }
0128 
0129 QSizeF KoZoomHandler::viewToDocument( const QSizeF &viewSize ) const
0130 {
0131     return QSizeF( unzoomItX( viewSize.width() ),
0132                    unzoomItY( viewSize.height() ) );
0133 }
0134 
0135 qreal KoZoomHandler::documentToViewX( qreal documentX ) const
0136 {
0137     return zoomItX( documentX );
0138 }
0139 
0140 qreal KoZoomHandler::documentToViewY( qreal documentY ) const
0141 {
0142     return zoomItY( documentY );
0143 }
0144 
0145 qreal KoZoomHandler::viewToDocumentX( qreal viewX ) const
0146 {
0147     return unzoomItX( viewX );
0148 }
0149 
0150 qreal KoZoomHandler::viewToDocumentY( qreal viewY ) const
0151 {
0152     return unzoomItY( viewY );
0153 }
0154 
0155 void KoZoomHandler::zoom(qreal *zoomX, qreal *zoomY) const
0156 {
0157     *zoomX = zoomItX(100.0) / 100.0;
0158     *zoomY = zoomItY(100.0) / 100.0;
0159 }