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

0001 /*
0002  * Copyright (C) 2006, 2008-2009 Thomas Zander <zander@kde.org>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Library General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2 of the License, or (at your option) any later version.
0008  *
0009  * This library is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012  * Library General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Library General Public License
0015  * along with this library; see the file COPYING.LIB.  If not, write to
0016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018  */
0019 #include "KoViewConverter.h"
0020 
0021 #include <QPointF>
0022 #include <QRectF>
0023 
0024 KoViewConverter::KoViewConverter()
0025     : m_zoomLevel(1.0)
0026 {
0027 }
0028 
0029 QPointF KoViewConverter::documentToView(const QPointF &documentPoint) const
0030 {
0031     if (qFuzzyCompare(m_zoomLevel, 1))
0032         return documentPoint;
0033     return QPointF(documentToViewX(documentPoint.x()), documentToViewY(documentPoint.y()));
0034 }
0035 
0036 QPointF KoViewConverter::viewToDocument(const QPointF &viewPoint) const
0037 {
0038     if (qFuzzyCompare(m_zoomLevel, 1))
0039         return viewPoint;
0040     return QPointF(viewToDocumentX(viewPoint.x()), viewToDocumentY(viewPoint.y()));
0041 }
0042 
0043 QRectF KoViewConverter::documentToView(const QRectF &documentRect) const
0044 {
0045     if (qFuzzyCompare(m_zoomLevel, 1))
0046         return documentRect;
0047     return QRectF(documentToView(documentRect.topLeft()), documentToView(documentRect.size()));
0048 }
0049 
0050 QRectF KoViewConverter::viewToDocument(const QRectF &viewRect) const
0051 {
0052     if (qFuzzyCompare(m_zoomLevel, 1))
0053         return viewRect;
0054     return QRectF(viewToDocument(viewRect.topLeft()), viewToDocument(viewRect.size()));
0055 }
0056 
0057 QSizeF KoViewConverter::documentToView(const QSizeF &documentSize) const
0058 {
0059     if (qFuzzyCompare(m_zoomLevel, 1))
0060         return documentSize;
0061     return QSizeF(documentToViewX(documentSize.width()), documentToViewY(documentSize.height()));
0062 }
0063 
0064 QSizeF KoViewConverter::viewToDocument(const QSizeF &viewSize) const
0065 {
0066     if (qFuzzyCompare(m_zoomLevel, 1))
0067         return viewSize;
0068     return QSizeF(viewToDocumentX(viewSize.width()), viewToDocumentY(viewSize.height()));
0069 }
0070 
0071 void KoViewConverter::zoom(qreal *zoomX, qreal *zoomY) const
0072 {
0073     *zoomX = m_zoomLevel;
0074     *zoomY = m_zoomLevel;
0075 }
0076 
0077 qreal KoViewConverter::documentToViewX(qreal documentX) const
0078 {
0079     return documentX * m_zoomLevel;
0080 }
0081 
0082 qreal KoViewConverter::documentToViewY(qreal documentY) const
0083 {
0084     return documentY * m_zoomLevel;
0085 }
0086 
0087 qreal KoViewConverter::viewToDocumentX(qreal viewX) const
0088 {
0089     return viewX / m_zoomLevel;
0090 }
0091 
0092 qreal KoViewConverter::viewToDocumentY(qreal viewY) const
0093 {
0094     return viewY / m_zoomLevel;
0095 }
0096 
0097 void KoViewConverter::setZoom(qreal zoom)
0098 {
0099     if (qFuzzyCompare(zoom, qreal(0.0)) || qFuzzyCompare(zoom, qreal(1.0))) {
0100         zoom = 1;
0101     }
0102     m_zoomLevel = zoom;
0103 }
0104 
0105 qreal KoViewConverter::zoom() const
0106 {
0107     return m_zoomLevel;
0108 }