File indexing completed on 2024-05-12 15:56:47
0001 /* This file is part of the KDE project 0002 * SPDX-FileCopyrightText: 2006-2007, 2010 Thomas Zander <zander@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KOSHAPECONTAINERMODEL_H 0008 #define KOSHAPECONTAINERMODEL_H 0009 0010 #include "kritaflake_export.h" 0011 0012 #include <KoShape.h> 0013 0014 #include <QList> 0015 #include <QPointF> 0016 0017 class KoShapeContainer; 0018 0019 /** 0020 * The interface for the container model. 0021 * This class has no implementation, but only pure virtual methods. You can find a 0022 * fully implemented model using KoShapeContainerDefaultModel. Extending this 0023 * class and implementing all methods allows you to implement a custom data-backend 0024 * for the KoShapeContainer. 0025 * @see KoShapeContainer, KoShapeContainerDefaultModel 0026 */ 0027 class KRITAFLAKE_EXPORT KoShapeContainerModel 0028 { 0029 public: 0030 /// default constructor 0031 KoShapeContainerModel(); 0032 0033 /// destructor 0034 virtual ~KoShapeContainerModel(); 0035 0036 void deleteOwnedShapes(); 0037 0038 /** 0039 * Add a shape to this models store. 0040 * @param shape the shape to be managed in the container. 0041 */ 0042 virtual void add(KoShape *shape) = 0; 0043 0044 /** 0045 * Remove a shape to be completely separated from the model. 0046 * @param shape the shape to be removed. 0047 */ 0048 virtual void remove(KoShape *shape) = 0; 0049 0050 /** 0051 * Set the argument shape to have its 'clipping' property set. 0052 * 0053 * A shape that is clipped by the container will have its visible portion 0054 * limited to the area where it intersects with the container. 0055 * If a shape is positioned or sized such that it would be painted outside 0056 * of the KoShape::outline() of its parent container, setting this property 0057 * to true will clip the shape painting to the container outline. 0058 * 0059 * @param shape the shape for which the property will be changed. 0060 * @param clipping the new value 0061 */ 0062 virtual void setClipped(const KoShape *shape, bool clipping) = 0; 0063 0064 /** 0065 * Returns if the argument shape has its 'clipping' property set. 0066 * 0067 * A shape that is clipped by the container will have its visible portion 0068 * limited to the area where it intersects with the container. 0069 * If a shape is positioned or sized such that it would be painted outside 0070 * of the KoShape::outline() of its parent container, setting this property 0071 * to true will clip the shape painting to the container outline. 0072 * 0073 * @return if the argument shape has its 'clipping' property set. 0074 * @param shape the shape for which the property will be returned. 0075 */ 0076 virtual bool isClipped(const KoShape *shape) const = 0; 0077 0078 /** 0079 * Set the shape to inherit the container transform. 0080 * 0081 * A shape that inherits the transform of the parent container will have its 0082 * share / rotation / skew etc be calculated as being the product of both its 0083 * own local transformation and also that of its parent container. 0084 * If you set this to true and rotate the container, the shape will get that 0085 * rotation as well automatically. 0086 * 0087 * @param shape the shape for which the property will be changed. 0088 * @param inherit the new value 0089 */ 0090 virtual void setInheritsTransform(const KoShape *shape, bool inherit) = 0; 0091 0092 /** 0093 * Returns if the shape inherits the container transform. 0094 * 0095 * A shape that inherits the transform of the parent container will have its 0096 * share / rotation / skew etc be calculated as being the product of both its 0097 * own local transformation and also that of its parent container. 0098 * If you set this to true and rotate the container, the shape will get that 0099 * rotation as well automatically. 0100 * 0101 * @return if the argument shape has its 'inherits transform' property set. 0102 * @param shape the shape for which the property will be returned. 0103 */ 0104 virtual bool inheritsTransform(const KoShape *shape) const = 0; 0105 0106 /** 0107 * Return the current number of children registered. 0108 * @return the current number of children registered. 0109 */ 0110 virtual int count() const = 0; 0111 0112 /** 0113 * Return the list of all shapes of this model 0114 * @return the list of all shapes 0115 */ 0116 virtual QList<KoShape*> shapes() const = 0; 0117 0118 /** 0119 * This method is called as a notification that one of the properties of the 0120 * container changed. This can be one of size, position, rotation and skew. 0121 * Note that clipped children will automatically get all these changes, the model 0122 * does not have to do anything for that. 0123 * @param container the actual container that changed. 0124 * @param type this enum shows which change the container has had. 0125 */ 0126 virtual void containerChanged(KoShapeContainer *container, KoShape::ChangeType type) = 0; 0127 0128 /** 0129 * This method is called when the user tries to move a shape that is a shape of the 0130 * container this model represents. 0131 * The shape itself is not yet moved; it is proposed to be moved over the param move distance. 0132 * You can alter the value of the move to affect the actual distance moved. 0133 * The default implementation does nothing. 0134 * @param shape the shape of this container that the user is trying to move. 0135 * @param move the distance that the user proposes to move shape from the current position. 0136 */ 0137 virtual void proposeMove(KoShape *shape, QPointF &move); 0138 0139 /** 0140 * This method is called when one of the shape shapes has been modified. 0141 * When a shape shape is rotated, moved or scaled/skewed this method will be called 0142 * to inform the container of such a change. The change has already happened at the 0143 * time this method is called. 0144 * The base implementation notifies the grand parent of the shape that there was a 0145 * change in a shape. A reimplementation if this function should call this method when 0146 * overriding the function. 0147 * 0148 * @param shape the shape that has been changed 0149 * @param type this enum shows which change the shape has had. 0150 */ 0151 virtual void childChanged(KoShape *shape, KoShape::ChangeType type); 0152 0153 virtual void shapeHasBeenAddedToHierarchy(KoShape *shape, KoShapeContainer *addedToSubtree); 0154 virtual void shapeToBeRemovedFromHierarchy(KoShape *shape, KoShapeContainer *removedFromSubtree); 0155 0156 protected: 0157 KoShapeContainerModel(const KoShapeContainerModel &rhs); 0158 }; 0159 0160 #endif