Warning, file /office/calligra/libs/flake/KoShapeContainer.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) 2006-2010 Thomas Zander <zander@kde.org>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Library General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2 of the License, or (at your option) any later version.
0008  *
0009  * This library is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012  * Library General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Library General Public License
0015  * along with this library; see the file COPYING.LIB.  If not, write to
0016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018  */
0019 
0020 #ifndef KOSHAPECONTAINER_H
0021 #define KOSHAPECONTAINER_H
0022 
0023 #include "KoShape.h"
0024 #include "KoViewConverter.h"
0025 
0026 #include <QList>
0027 
0028 #include "flake_export.h"
0029 
0030 class QPainter;
0031 class KoShapeContainerModel;
0032 class KoShapeContainerPrivate;
0033 
0034 /**
0035  * This is the base class that all Flake group-shapes are based on.
0036  * Extending from this class allows you to have child-shapes.
0037  * Like the KoShape class, this shape is a visible class with
0038  * a position and a size. It can paint itself as well if you implement
0039  * the paintComponent() method.
0040  *
0041  * <p>The most important feature of this class is that you can make
0042  * other KoShape classes to be children of this container.
0043  *
0044  * <p>The effect of grouping those shapes is that their position
0045  * is relative to the position of the container. Move the container and
0046  * all children move with it.
0047  *
0048  * <p>Each child can optionally be said to be 'clipped' by the container.
0049  * This feature will give the effect that if the child has a size and
0050  * position outside the container, parts outside the container will not be shown.
0051  * This is especially useful
0052  * for showing cutouts of content, like images, without changing the actual content.
0053  *
0054  * <p>For so called clipped children any modification made to the container is
0055  * propagated to the child. This includes rotation as well as scaling
0056  * and shearing.
0057  *
0058  * <p>Maintaining the list of children can be done using the supplied methods
0059  * addChild() and removeChild(). However, they only forward their requests to the
0060  * data model KoShapeContainerModel and if you provide a custom implementation
0061  * of that model any means can be used to maintain a list of children, as long as
0062  * you will take care to register them with the appropriate shape manager.
0063  *
0064  * <p>An example usage where a custom model might be useful is when you have a
0065  * container for text areas which are split into columns.  If you resize the container
0066  * and the width of the individual columns gets too small, the model can choose to
0067  * remove a child or add one when the width allows another column.
0068  */
0069 class FLAKE_EXPORT KoShapeContainer : public KoShape
0070 {
0071 public:
0072 
0073     /**
0074      * Constructor with custom model to be used for maintaining the list of children.
0075      * For all the normal cases you don't need a custom model. Use the default constructor in this case.
0076      * Provide a custom model when you e.g. want to respond to moves of the container to do something special,
0077      * or disable one of the features the container normally has (like clipping).
0078      * @param model the custom model to be used for maintaining the list of children.
0079      */
0080     explicit KoShapeContainer(KoShapeContainerModel *model = 0);
0081 
0082     /**
0083      * Destructor for the shape container.
0084      * All children will be orphaned by calling a KoShape::setParent(0)
0085      */
0086     ~KoShapeContainer() override;
0087 
0088     /**
0089      * Add a child to this container.
0090      *
0091      * This container will NOT take over ownership of the shape. The caller or those creating
0092      * the shape is responsible to delete it if not needed any longer.
0093      *
0094      * @param shape the child to be managed in the container.
0095      */
0096     void addShape(KoShape *shape);
0097 
0098     /**
0099      * Remove a child to be completely separated from the container.
0100      *
0101      * The shape will only be removed from this container but not be deleted.
0102      *
0103      * @param shape the child to be removed.
0104      */
0105     void removeShape(KoShape *shape);
0106 
0107     /**
0108      * Remove all children to be completely separated from the container.
0109      *
0110      * All the shapes will only be removed from the container but not be deleted.
0111      */
0112     void removeAllShapes();
0113 
0114     /**
0115      * Return the current number of children registered.
0116      * @return the current number of children registered.
0117      */
0118     int shapeCount() const;
0119 
0120     /**
0121      * Set the argument child to have its 'clipping' property set.
0122      *
0123      * A shape that is clipped by the container will have its visible portion
0124      * limited to the area where it intersects with the container.
0125      * If a shape is positioned or sized such that it would be painted outside
0126      * of the KoShape::outline() of its parent container, setting this property
0127      * to true will clip the shape painting to the container outline.
0128      *
0129      * @param child the child for which the property will be changed.
0130      * @param clipping the property
0131      */
0132     void setClipped(const KoShape *child, bool clipping);
0133 
0134     /**
0135      * Returns if the argument child has its 'clipping' property set.
0136      *
0137      * A shape that is clipped by the container will have its visible portion
0138      * limited to the area where it intersects with the container.
0139      * If a shape is positioned or sized such that it would be painted outside
0140      * of the KoShape::outline() of its parent container, setting this property
0141      * to true will clip the shape painting to the container outline.
0142      *
0143      * @return if the argument child has its 'clipping' property set.
0144      * @param child the child for which the property will be returned.
0145      */
0146     bool isClipped(const KoShape *child) const;
0147 
0148     /**
0149      * Return whether the child has the effective state of being locked for user modifications.
0150      * This method is deferred to the model, which should call the KoShape::isGeometryProtected() on the child.
0151      * @param child the shape that the user wants to move.
0152      */
0153     bool isChildLocked(const KoShape *child) const;
0154 
0155     /**
0156      * Return the allowed interactions set for this container
0157      * If we (or our parent(s)) are not visible, no interaction is allowed.
0158      * If we have a model the model is called, else the childs interaction flags is returned.
0159      * 
0160      * @see KoShapeContainerModel::allowedInteractions()
0161      */
0162     KoShape::AllowedInteractions allowedInteractions(const KoShape *child) const;
0163     using KoShape::allowedInteractions;
0164 
0165     /**
0166      * Set the shape to inherit the container transform.
0167      *
0168      * A shape that inherits the transform of the parent container will have its
0169      * share / rotation / skew etc be calculated as being the product of both its
0170      * own local transformation and also that of its parent container.
0171      * If you set this to true and rotate the container, the shape will get that
0172      * rotation as well automatically.
0173      *
0174      * @param shape the shape for which the property will be changed.
0175      * @param inherit the new value
0176      */
0177     void setInheritsTransform(const KoShape *shape, bool inherit);
0178 
0179     /**
0180      * Returns if the shape inherits the container transform.
0181      *
0182      * A shape that inherits the transform of the parent container will have its
0183      * share / rotation / skew etc be calculated as being the product of both its
0184      * own local transformation and also that of its parent container.
0185      * If you set this to true and rotate the container, the shape will get that
0186      * rotation as well automatically.
0187      *
0188      * @return if the argument shape has its 'inherits transform' property set.
0189      * @param shape the shape for which the property will be returned.
0190      */
0191     bool inheritsTransform(const KoShape *shape) const;
0192 
0193 
0194     /// reimplemented
0195     void paint(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &paintcontext) override;
0196 
0197     /**
0198      * @brief Paint the component
0199      * Implement this method to allow the shape to paint itself, just like the KoShape::paint()
0200      * method does.
0201      *
0202      * @param painter used for painting the shape
0203      * @param converter to convert between internal and view coordinates.
0204      * @param paintcontext the painting context.
0205      * @see applyConversion()
0206      */
0207     virtual void paintComponent(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &paintcontext) = 0;
0208 
0209     using KoShape::update;
0210     /// reimplemented
0211     void update() const override;
0212 
0213     /**
0214      * Return the list of all child shapes.
0215      * @return the list of all child shapes
0216      */
0217     QList<KoShape*> shapes() const;
0218 
0219     /**
0220      * return the model for this container
0221      */
0222     KoShapeContainerModel *model() const;
0223 
0224 protected:
0225     /**
0226      * This hook is for inheriting classes that need to do something on adding/removing
0227      * of children.
0228      * This method will be called just after the child has been added/removed.
0229      * The default implementation is empty.
0230      */
0231     virtual void shapeCountChanged() { }
0232 
0233     void shapeChanged(ChangeType type, KoShape *shape = 0) override;
0234 
0235     /// constructor
0236     KoShapeContainer(KoShapeContainerPrivate &);
0237 
0238 private:
0239     Q_DECLARE_PRIVATE(KoShapeContainer)
0240 };
0241 
0242 #endif