File indexing completed on 2024-05-19 16:10:01
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2001 David Faure <faure@kde.org> 0003 * Copyright (C) 2006 Thomas Zander <zander@kde.org> 0004 * Copyright (C) 2010-2011 Boudewijn Rempt <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 #ifndef KWVIEWMODE_H 0023 #define KWVIEWMODE_H 0024 0025 class KWPageManager; 0026 class KoViewConverter; 0027 class KWDocument; 0028 0029 #include "KWPage.h" 0030 #include "words_export.h" 0031 0032 #include <QPointF> 0033 #include <QRectF> 0034 #include <QSizeF> 0035 #include <QObject> 0036 #include <QRect> 0037 0038 /** 0039 * Abstract base class for KWCanvas's view modes. 0040 * A viewMode is a strategy inserted between the canvas and the document. A document 0041 * normally is nothing but a very tall area for drawing with some artificial limitations 0042 * imposed by the pages (KWPage). A viewmode can, for example, choose to paint page 0043 * outlines and translate the document coordinates so the pages get painted correctly 0044 * and mouseclicks on the canvas get converted into real document coordinates. 0045 * 0046 * On the implementation side the viewMode will not have the notion of zoom; its using 0047 * the viewconverter for that. This means that to the user of this API zooming 0048 * is applied just like translation is. 0049 * 0050 * This class provides a layer on top of the KoViewConverter and Words should not use that 0051 * interface directly. 0052 */ 0053 class WORDS_EXPORT KWViewMode : public QObject 0054 { 0055 Q_OBJECT 0056 public: 0057 KWViewMode(); 0058 ~KWViewMode() override {} 0059 0060 /// a two value return type for mapExposedRects() 0061 struct ViewMap { 0062 QRect clipRect; ///< the rectangle in the view coordinates showing (part of) the clip 0063 QPointF distance; ///< the displacement between the document and the view in view coordinates. 0064 KWPage page; ///< The page that this section represents. 0065 }; 0066 0067 /** Document coord -> view coord */ 0068 virtual QPointF documentToView(const QPointF &point, KoViewConverter *viewConverter) const = 0; 0069 0070 /** Document coord -> view coord */ 0071 QRectF documentToView(const QRectF &rect, KoViewConverter *viewConverter) const; 0072 0073 /** View coord -> Document coord */ 0074 virtual QPointF viewToDocument(const QPointF &point, KoViewConverter *viewConverter) const = 0; 0075 0076 /** View coord -> Document coord */ 0077 QRectF viewToDocument(const QRectF &rect, KoViewConverter *viewConverter) const; 0078 0079 /** Size of the contents area, in pixels */ 0080 virtual QSizeF contentsSize() const = 0; 0081 0082 /** Does this viewmode know anything about pages? */ 0083 virtual bool hasPages() { 0084 return true; 0085 } 0086 0087 /** Return the name of the viewmode, used for loading/saving. */ 0088 virtual const QString type() const = 0; 0089 0090 /** 0091 * Create a new ViewMode based on the type string of that viewmode. 0092 * To create a specific viewMode you can use this; 0093 * @code 0094 * QString type = KWViewModeNormal::viewMode(); 0095 * KWViewMode *vm = KWViewMode::create(type, myCanvas); 0096 * @endcode 0097 * @param viewModeType the type of viewMode 0098 * @param document 0099 */ 0100 static KWViewMode *create(const QString& viewModeType, KWDocument *document); 0101 0102 /** 0103 * This method converts a clip-rect of the view to a set of cliprects as they are 0104 * mirrored on the document space. 0105 * For a cliprect that overlaps various pages that same amount of arguments will 0106 * be created in the return value in the form of a ViewMap struct. 0107 * For example; 0108 * Imagine a viewmode that shows two pages side by side. And a @p clipRect parameter 0109 * covering the top half of both pages. To repaint this correctly in the Canvas 0110 * this needs to be split into two clip rects since the document internally does not 0111 * have those two pages next to each other, but below one another. 0112 * Note that just like everything in the viewMode; the input and output will be in the 0113 * same zoom-level. This means that adding all the output rects should have the same repaint 0114 * area as the input rect. 0115 * @param clipRect the clipping-rect as it was on the Canvas. 0116 * @param viewConverter An optional viewconverter to override the viewconverter set on the viewmode. 0117 * @return a list of clipping-rects as it maps to the internal document. 0118 */ 0119 virtual QVector<ViewMap> mapExposedRects(const QRectF &clipRect, KoViewConverter *viewConverter) const = 0; 0120 0121 public Q_SLOTS: 0122 /** 0123 * Notification that the page setup has changed expected when a page has been 0124 * added or removed or just resized. 0125 */ 0126 void pageSetupChanged(); 0127 void setPageManager(KWPageManager *pageManager) { m_pageManager = pageManager; updatePageCache(); } 0128 0129 protected: 0130 /** 0131 * Will be called when the pageSetupChanged() has been notified. 0132 */ 0133 virtual void updatePageCache() = 0; 0134 0135 KWPageManager *m_pageManager; 0136 }; 0137 0138 Q_DECLARE_TYPEINFO(KWViewMode::ViewMap, Q_MOVABLE_TYPE); 0139 0140 #endif