File indexing completed on 2024-05-12 15:56:54

0001 /* This file is part of the KDE project
0002  * SPDX-FileCopyrightText: 2006 Thomas Zander <zander@kde.org>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #ifndef KOVIEWCONVERTER_H
0008 #define KOVIEWCONVERTER_H
0009 
0010 #include "kritaflake_export.h"
0011 
0012 #include <QtGlobal>
0013 
0014 class QPointF;
0015 class QRectF;
0016 class QSizeF;
0017 class QTransform;
0018 
0019 /**
0020  * The interface for view conversions.
0021  *
0022  * All KoShape based objects are using a postscript-point (pt) based measurement system
0023  * which requires a conversion to view coordinates (in pixel sizes) at the moment
0024  * we are painting, and a conversion to the normalized coordinate system if we
0025  * receive mouse events so we can figure out which KoShape object was touched.
0026  *
0027  * The zoom level is expressed on a scale of 0.0 to 1.0 to infinite, where 1.0 is
0028  * 100%
0029  */
0030 class KRITAFLAKE_EXPORT KoViewConverter
0031 {
0032 public:
0033     KoViewConverter();
0034     virtual ~KoViewConverter() {}
0035 
0036     /**
0037      * Convert a coordinate in pt to pixels.
0038      * @param documentPoint the point in the document coordinate system of a KoShape.
0039      */
0040     virtual QPointF documentToView(const QPointF &documentPoint) const;
0041 
0042     /**
0043      * Convert a coordinate in pixels to pt.
0044      * @param viewPoint the point in the coordinate system of the widget, or window.
0045      */
0046     virtual QPointF viewToDocument(const QPointF &viewPoint) const;
0047 
0048     /**
0049      * Convert a rectangle in pt to pixels.
0050      * @param documentRect the rect in the document coordinate system of a KoShape.
0051      */
0052     virtual QRectF documentToView(const QRectF &documentRect) const;
0053 
0054     /**
0055      * Convert a rectangle in pixels to pt.
0056      * @param viewRect the rect in the coordinate system of the widget, or window.
0057      */
0058     virtual QRectF viewToDocument(const QRectF &viewRect) const;
0059 
0060     /**
0061      * Convert a size in pt to pixels.
0062      * @param documentSize the size in pt.
0063      * @return the size in pixels.
0064      */
0065     virtual QSizeF documentToView(const QSizeF& documentSize) const;
0066 
0067     /**
0068      * Convert a size in pixels to pt.
0069      * @param viewSize the size in pixels.
0070      * @return the size in pt.
0071      */
0072     virtual QSizeF viewToDocument(const QSizeF& viewSize) const;
0073 
0074     /**
0075      * Convert a single x coordinate in pt to pixels.
0076      * @param documentX the x coordinate in pt.
0077      * @return the x coordinate in pixels.
0078      */
0079     virtual qreal documentToViewX(qreal documentX) const;
0080 
0081     /**
0082      * Convert a single y coordinate in pt to pixels.
0083      * @param documentY the y coordinate in pt.
0084      * @return the y coordinate in pixels.
0085      */
0086     virtual qreal documentToViewY(qreal documentY) const;
0087 
0088     /**
0089      * Convert a single x coordinate in pixels to pt.
0090      * @param viewX the x coordinate in pixels.
0091      * @return the x coordinate in pt.
0092      */
0093     virtual qreal viewToDocumentX(qreal viewX) const;
0094 
0095     /**
0096      * Convert a single y coordinate in pixels to pt.
0097      * @param viewY the y coordinate in pixels.
0098      * @return the y coordinate in pt.
0099      */
0100     virtual qreal viewToDocumentY(qreal viewY) const;
0101 
0102     /**
0103      * Retrieve the zoom levels of the individual x and y axes.
0104      * @param zoomX a pointer to a qreal which will be modified to the horizontal zoom.
0105      * @param zoomY a pointer to a qreal which will be modified to the vertical zoom.
0106      */
0107     virtual void zoom(qreal *zoomX, qreal *zoomY) const;
0108 
0109     /**
0110      * Set the zoom level. 1.0 is 100%.
0111      */
0112     virtual void setZoom(qreal zoom);
0113 
0114     /**
0115      * Return the current zoom level. 1.0 is 100%.
0116      */
0117     qreal zoom() const;
0118 
0119     QTransform documentToView() const;
0120     QTransform viewToDocument() const;
0121 
0122     virtual QTransform viewToWidget() const;
0123     virtual QTransform widgetToView() const;
0124 
0125 private:
0126     qreal m_zoomLevel; // 1.0 is 100%
0127 };
0128 
0129 #endif