File indexing completed on 2024-05-12 16:34:58
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2010 Thomas Zander <zander@kde.org> 0003 * Copyright (C) 2010 Sebastian Sauer <sebsauer@kdab.com> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Library General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Library General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Library General Public License 0016 * along with this library; see the file COPYING.LIB. If not, write to 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #ifndef SHRINKTOFITSHAPECONTAINER_H 0022 #define SHRINKTOFITSHAPECONTAINER_H 0023 0024 #include <KoShape.h> 0025 #include <KoShapeContainer.h> 0026 #include <SimpleShapeContainerModel.h> 0027 #include <KoXmlNS.h> 0028 #include <KoXmlReader.h> 0029 #include <KoOdfLoadingContext.h> 0030 #include <KoTextShapeData.h> 0031 #include <QObject> 0032 #include <QPainter> 0033 0034 #include <KoShapeContainer_p.h> 0035 #include <KoTextDocumentLayout.h> 0036 #include <KoShapeLoadingContext.h> 0037 #include <KoDocumentResourceManager.h> 0038 0039 /** 0040 * \internal d-pointer class for the \a ShrinkToFitShapeContainer class. 0041 */ 0042 class ShrinkToFitShapeContainerPrivate : public KoShapeContainerPrivate 0043 { 0044 public: 0045 explicit ShrinkToFitShapeContainerPrivate(KoShapeContainer *q, KoShape *childShape) : KoShapeContainerPrivate(q), childShape(childShape) {} 0046 ~ShrinkToFitShapeContainerPrivate() override {} 0047 KoShape *childShape; // the original shape not owned by us 0048 }; 0049 0050 /** 0051 * Container that is used to wrap a shape and shrink a text-shape to fit the content. 0052 */ 0053 class ShrinkToFitShapeContainer : public KoShapeContainer 0054 { 0055 public: 0056 explicit ShrinkToFitShapeContainer(KoShape *childShape, KoDocumentResourceManager *documentResources = 0); 0057 ~ShrinkToFitShapeContainer() override; 0058 0059 // reimplemented 0060 void paintComponent(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &paintcontext) override; 0061 // reimplemented 0062 bool loadOdf(const KoXmlElement &element, KoShapeLoadingContext &context) override; 0063 // reimplemented 0064 void saveOdf(KoShapeSavingContext &context) const override; 0065 0066 /** 0067 * Factory function to create and return a ShrinkToFitShapeContainer instance that wraps the \a shape with it. 0068 */ 0069 static ShrinkToFitShapeContainer* wrapShape(KoShape *shape, KoDocumentResourceManager *documentResourceManager = 0); 0070 0071 /** 0072 * Try to load text-on-shape from \a element and wrap \a shape with it. 0073 */ 0074 static void tryWrapShape(KoShape *shape, const KoXmlElement &element, KoShapeLoadingContext &context); 0075 0076 /** 0077 * Undo the wrapping done in the \a wrapShape method. 0078 */ 0079 void unwrapShape(KoShape *shape); 0080 0081 private: 0082 Q_DECLARE_PRIVATE(ShrinkToFitShapeContainer) 0083 }; 0084 0085 /** 0086 * The container-model class implements \a KoShapeContainerModel for the \a ShrinkToFitShapeContainer to 0087 * to stuff once our container changes. 0088 */ 0089 class ShrinkToFitShapeContainerModel : public QObject, public SimpleShapeContainerModel 0090 { 0091 Q_OBJECT 0092 friend class ShrinkToFitShapeContainer; 0093 public: 0094 ShrinkToFitShapeContainerModel(ShrinkToFitShapeContainer *q, ShrinkToFitShapeContainerPrivate *d); 0095 0096 // reimplemented 0097 void containerChanged(KoShapeContainer *container, KoShape::ChangeType type) override; 0098 // reimplemented 0099 bool inheritsTransform(const KoShape *child) const override; 0100 // reimplemented 0101 bool isChildLocked(const KoShape *child) const override; 0102 // reimplemented 0103 bool isClipped(const KoShape *child) const override; 0104 0105 private Q_SLOTS: 0106 void finishedLayout(); 0107 0108 private: 0109 ShrinkToFitShapeContainer *q; 0110 ShrinkToFitShapeContainerPrivate *d; 0111 qreal m_scale; 0112 QSizeF m_shapeSize, m_documentSize; 0113 int m_dirty; 0114 bool m_maybeUpdate; 0115 }; 0116 0117 #endif