Warning, file /office/calligra/libs/flake/KoTosContainer.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2010 Thomas Zander <zander@kde.org>
0003  * Copyright (C) 2010 KO GmbH <boud@kogbmh.com>
0004  * Copyright (C) 2010 Thorsten Zachmann <zachmann@kde.org>
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 KOTOSCONTAINER_H
0023 #define KOTOSCONTAINER_H
0024 
0025 #include "KoShapeContainer.h"
0026 
0027 #include "flake_export.h"
0028 
0029 class KoTosContainerPrivate;
0030 class KoDocumentResourceManager;
0031 
0032 
0033 /**
0034  * Container that is used to wrap a shape with a text on top.
0035  * Path shapes inherit from this class to make it possible to have text associated
0036  * with them.
0037  */
0038 class FLAKE_EXPORT KoTosContainer : public KoShapeContainer
0039 {
0040 public:
0041     KoTosContainer();
0042     ~KoTosContainer() override;
0043 
0044     // reimplemented
0045     void paintComponent(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &paintcontext) override;
0046 
0047     // reimplemented
0048     virtual bool loadText(const KoXmlElement &element, KoShapeLoadingContext &context);
0049 
0050     // reimplemented
0051     virtual void saveText(KoShapeSavingContext &context) const;
0052 
0053     /// different kinds of resizing behavior to determine how to treat text overflow
0054     enum ResizeBehavior {
0055         TextFollowsSize,  ///< Text area is same size as content, extra text will be clipped
0056         FollowTextSize,   ///< Content shape will get resized if text grows/shrinks
0057         IndependentSizes,  ///< The text can get bigger than the content
0058         TextFollowsPreferredTextRect ///< The size/position of the text area will follow the preferredTextRect property
0059     };
0060 
0061     /**
0062      * Set the behavior that is used to resize the text or content.
0063      * In order to determine what to do when there is too much text to fit or suddenly less
0064      * text the user can define the wanted behavior using the ResizeBehavior
0065      * @param resizeBehavior the new ResizeBehavior
0066      */
0067     void setResizeBehavior(ResizeBehavior resizeBehavior);
0068 
0069     /**
0070      * Returns the current ResizeBehavior.
0071      */
0072     ResizeBehavior resizeBehavior() const;
0073 
0074     /** Sets the alignment of the text. */
0075     void setTextAlignment(Qt::Alignment alignment);
0076 
0077     /** Returns the alignment of all text */
0078     Qt::Alignment textAlignment() const;
0079 
0080     /**
0081      * Set some plain text to be displayed on the shape.
0082      * @param text the full text.
0083      */
0084     void setPlainText(const QString &text);
0085 
0086     /**
0087      * Add text the current shape with the specified document resource manager.
0088      *
0089      * @param documentResources
0090      * @return The created text shape or 0 in case it failed
0091      */
0092     KoShape *createTextShape(KoDocumentResourceManager *documentResources = 0);
0093 
0094     void setRunThrough(short int runThrough) override;
0095 
0096 protected:
0097     /// constructor
0098     KoTosContainer(KoTosContainerPrivate &);
0099 
0100     //reimplemented
0101     void loadStyle(const KoXmlElement &element, KoShapeLoadingContext &context) override;
0102 
0103     //reimplemented
0104     QString saveStyle(KoGenStyle &style, KoShapeSavingContext &context) const override;
0105 
0106     /**
0107      * Set the current preferred text rectangle. This rect contains the coordinates of
0108      * the embedded text shape relative to the content shape. This value is ignored if
0109      * resizeBehavior is not TextFollowsPreferredTextRect.
0110      * @param rect the new preferred text rectangle
0111      */
0112     void setPreferredTextRect(const QRectF &rect);
0113 
0114     /**
0115      * Returns the current preferred text rectangle.
0116      */
0117     QRectF preferredTextRect() const;
0118 
0119     /**
0120      * Returns the text shape
0121      *
0122      * @returns textshape if set or 0 in case it is not yet set
0123      */
0124     KoShape *textShape() const;
0125 
0126     void shapeChanged(ChangeType type, KoShape *shape = 0) override;
0127 
0128 private:
0129     Q_DECLARE_PRIVATE(KoTosContainer)
0130 };
0131 
0132 #endif