File indexing completed on 2024-05-12 16:34:59

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2006-2010 Thomas Zander <zander@kde.org>
0003  * Copyright (C) 2008 Thorsten Zachmann <zachmann@kde.org>
0004  * Copyright (C) 2008 Pierre Stirnweiss \pierre.stirnweiss_calligra@gadz.org>
0005  * Copyright (C) 2010 KO GmbH <cbo@kogmbh.com>
0006  *
0007  * This library is free software; you can redistribute it and/or
0008  * modify it under the terms of the GNU Library General Public
0009  * License as published by the Free Software Foundation; either
0010  * version 2 of the License, or (at your option) any later version.
0011  *
0012  * This library is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  * Library General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Library General Public License
0018  * along with this library; see the file COPYING.LIB.  If not, write to
0019  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020  * Boston, MA 02110-1301, USA.
0021  */
0022 
0023 #ifndef KOTEXTSHAPE_H
0024 #define KOTEXTSHAPE_H
0025 
0026 #include <KoShapeContainer.h>
0027 #include <KoFrameShape.h>
0028 #include <KoTextShapeData.h>
0029 #include <KoTextDocument.h>
0030 
0031 #include <QTextDocument>
0032 #include <QPainter>
0033 
0034 #define TextShape_SHAPEID "TextShapeID"
0035 
0036 class KoInlineTextObjectManager;
0037 class KoTextRangeManager;
0038 class KoPageProvider;
0039 class KoImageCollection;
0040 class KoTextDocument;
0041 class TextShape;
0042 class KoTextDocumentLayout;
0043 class KoParagraphStyle;
0044 
0045 /**
0046  * A text shape.
0047  * The Text shape is capable of drawing structured text.
0048  * @see KoTextShapeData
0049  */
0050 class TextShape : public KoShapeContainer, public KoFrameShape
0051 {
0052 public:
0053     TextShape(KoInlineTextObjectManager *inlineTextObjectManager, KoTextRangeManager *textRangeManager);
0054     ~TextShape() override;
0055 
0056     /// reimplemented
0057     void paintComponent(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &paintcontext) override;
0058     /// reimplemented
0059     void waitUntilReady(const KoViewConverter &converter, bool asynchronous) const override;
0060 
0061     /// helper method.
0062     QPointF convertScreenPos(const QPointF &point) const;
0063 
0064     /// reimplemented
0065     QPainterPath outline() const override;
0066 
0067     /// reimplemented
0068     QRectF outlineRect() const override;
0069 
0070     ///reimplemented
0071     ChildZOrderPolicy childZOrderPolicy() override {return KoShape::ChildZPassThrough;}
0072 
0073     /// set the image collection which is needed to draw bullet from images
0074     void setImageCollection(KoImageCollection *collection) { m_imageCollection = collection; }
0075 
0076     KoImageCollection *imageCollection();
0077 
0078     /**
0079      * From KoShape reimplemented method to load the TextShape from ODF.
0080      *
0081      * This method redirects the call to the KoTextShapeData::loadOdf() method which
0082      * in turn will call the KoTextLoader::loadBody() method that reads the element
0083      * into a QTextCursor.
0084      *
0085      * @param context the KoShapeLoadingContext used for loading.
0086      * @param element element which represents the shape in odf.
0087      * @return false if loading failed.
0088      */
0089     bool loadOdf(const KoXmlElement &element, KoShapeLoadingContext &context) override;
0090 
0091     /**
0092      * From KoShape reimplemented method to store the TextShape data as ODF.
0093      *
0094      * @param context the KoShapeSavingContext used for saving.
0095      */
0096     void saveOdf(KoShapeSavingContext &context) const override;
0097 
0098     KoTextShapeData *textShapeData() {
0099         return m_textShapeData;
0100     }
0101 
0102     void updateDocumentData();
0103 
0104     void update() const override;
0105     void update(const QRectF &shape) const override;
0106 
0107     // required for Stage hack
0108     void setPageProvider(KoPageProvider *provider) { m_pageProvider = provider; }
0109 
0110     /// reimplemented
0111     bool loadOdfFrame(const KoXmlElement &element, KoShapeLoadingContext &context) override;
0112 
0113 protected:
0114     bool loadOdfFrameElement(const KoXmlElement &element, KoShapeLoadingContext &context) override;
0115 
0116     /// reimplemented
0117     void loadStyle(const KoXmlElement &element, KoShapeLoadingContext &context) override;
0118 
0119     /// reimplemented
0120     QString saveStyle(KoGenStyle &style, KoShapeSavingContext &context) const override;
0121 
0122 private:
0123     void shapeChanged(ChangeType type, KoShape *shape = 0) override;
0124 
0125     KoTextShapeData *m_textShapeData;
0126     KoPageProvider *m_pageProvider;
0127     KoImageCollection *m_imageCollection;
0128     QRegion m_paintRegion;
0129     KoParagraphStyle * m_paragraphStyle;
0130     bool m_clip;
0131     KoTextDocumentLayout *m_layout;
0132 };
0133 
0134 #endif