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

0001 /* This file is part of the KDE project
0002  * SPDX-FileCopyrightText: 2010 Thomas Zander <zander@kde.org>
0003  * SPDX-FileCopyrightText: 2010 KO GmbH <boud@kogbmh.com>
0004  * SPDX-FileCopyrightText: 2010 Thorsten Zachmann <zachmann@kde.org>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.0-or-later
0007  */
0008 
0009 #ifndef KOTOSCONTAINER_H
0010 #define KOTOSCONTAINER_H
0011 
0012 #include "KoShapeContainer.h"
0013 
0014 #include "kritaflake_export.h"
0015 
0016 class KoDocumentResourceManager;
0017 
0018 
0019 /**
0020  * Container that is used to wrap a shape with a text on top.
0021  * Path shapes inherit from this class to make it possible to have text associated
0022  * with them.
0023  */
0024 class KRITAFLAKE_EXPORT KoTosContainer : public KoShapeContainer
0025 {
0026 public:
0027     KoTosContainer();
0028     ~KoTosContainer() override;
0029 
0030     // reimplemented
0031     void paintComponent(QPainter &painter) const override;
0032 
0033     // reimplemented
0034     virtual bool loadText(const QDomElement &element);
0035 
0036 
0037     /// different kinds of resizing behavior to determine how to treat text overflow
0038     enum ResizeBehavior {
0039         TextFollowsSize,  ///< Text area is same size as content, extra text will be clipped
0040         FollowTextSize,   ///< Content shape will get resized if text grows/shrinks
0041         IndependentSizes,  ///< The text can get bigger than the content
0042         TextFollowsPreferredTextRect ///< The size/position of the text area will follow the preferredTextRect property
0043     };
0044 
0045     /**
0046      * Set the behavior that is used to resize the text or content.
0047      * In order to determine what to do when there is too much text to fit or suddenly less
0048      * text the user can define the wanted behavior using the ResizeBehavior
0049      * @param resizeBehavior the new ResizeBehavior
0050      */
0051     void setResizeBehavior(ResizeBehavior resizeBehavior);
0052 
0053     /**
0054      * Returns the current ResizeBehavior.
0055      */
0056     ResizeBehavior resizeBehavior() const;
0057 
0058     /** Sets the alignment of the text. */
0059     void setTextAlignment(Qt::Alignment alignment);
0060 
0061     /** Returns the alignment of all text */
0062     Qt::Alignment textAlignment() const;
0063 
0064     /**
0065      * Set some plain text to be displayed on the shape.
0066      * @param text the full text.
0067      */
0068     void setPlainText(const QString &text);
0069 
0070     /**
0071      * Add text the current shape with the specified document resource manager.
0072      *
0073      * @param documentResources
0074      * @return The created text shape or 0 in case it failed
0075      */
0076     KoShape *createTextShape(KoDocumentResourceManager *documentResources = 0);
0077 
0078     void setRunThrough(short int runThrough) override;
0079 
0080 protected:
0081     KoTosContainer(const KoTosContainer &rhs);
0082 
0083         /**
0084      * Set the current preferred text rectangle. This rect contains the coordinates of
0085      * the embedded text shape relative to the content shape. This value is ignored if
0086      * resizeBehavior is not TextFollowsPreferredTextRect.
0087      * @param rect the new preferred text rectangle
0088      */
0089     void setPreferredTextRect(const QRectF &rect);
0090 
0091     /**
0092      * Returns the current preferred text rectangle.
0093      */
0094     QRectF preferredTextRect() const;
0095 
0096     /**
0097      * Returns the text shape
0098      *
0099      * @returns textshape if set or 0 in case it is not yet set
0100      */
0101     KoShape *textShape() const;
0102 
0103     void shapeChanged(ChangeType type, KoShape *shape = 0) override;
0104 
0105 private:
0106     class Private;
0107     QSharedDataPointer<Private> d;
0108 };
0109 
0110 #endif