File indexing completed on 2024-05-12 15:56:48
0001 /* This file is part of the KDE project 0002 * SPDX-FileCopyrightText: 2006 Thomas Zander <zander@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KOSHAPEGROUP_H 0008 #define KOSHAPEGROUP_H 0009 0010 #include "KoShapeContainer.h" 0011 0012 #include <QList> 0013 0014 #include "kritaflake_export.h" 0015 0016 class KoShapeSavingContext; 0017 class KoShapeLoadingContext; 0018 class KoShapeGroupPrivate; 0019 0020 /** 0021 * Provide grouping for shapes. 0022 * The group shape allows you to add children which will then be grouped in selections 0023 * and actions. 0024 * <p>If you have a set of shapes that together make up a bigger shape it is often 0025 * useful to group them together so the user will perceive the different shapes as 0026 * actually being one. This means that if the user clicks on one shape, all shapes 0027 * in the group will be selected at once, making the tools that works on 0028 * selections alter all of them at the same time. 0029 * 0030 * <p>Note that while this object is also a shape, it is not actually visible and the user 0031 * can't interact with it. 0032 * 0033 * <p>WARNING: this class is NOT threadsafe, it caches the size in an unsafe way 0034 */ 0035 class KRITAFLAKE_EXPORT KoShapeGroup : public KoShapeContainer 0036 { 0037 public: 0038 /// Constructor 0039 KoShapeGroup(); 0040 /// destructor 0041 ~KoShapeGroup() override; 0042 0043 KoShape* cloneShape() const override; 0044 0045 /// This implementation is empty since a group is itself not visible. 0046 void paintComponent(QPainter &painter) const override; 0047 /// always returns false since the group itself can't be selected or hit 0048 bool hitTest(const QPointF &position) const override; 0049 QSizeF size() const override; 0050 void setSize(const QSizeF &size) override; 0051 QRectF outlineRect() const override; 0052 /// a group's boundingRect 0053 QRectF boundingRect() const override; 0054 0055 private: 0056 friend class ShapeGroupContainerModel; 0057 0058 /** 0059 * @brief Invalidate the size cache of the group 0060 * 0061 * The group shape caches the size of itself as it can be quite expensive to recalculate 0062 * the size if there are a lot of subshapes. This function is called when the cache needs 0063 * to be invalidated. 0064 */ 0065 void invalidateSizeCache(); 0066 0067 private: 0068 KoShapeGroup(const KoShapeGroup &rhs); 0069 0070 private: 0071 void tryUpdateCachedSize() const; 0072 0073 void shapeChanged(ChangeType type, KoShape *shape = 0) override; 0074 0075 class Private; 0076 QScopedPointer<Private> d; 0077 }; 0078 0079 #endif