File indexing completed on 2024-05-12 15:58:18
0001 /* 0002 * SPDX-FileCopyrightText: 2005 C. Boemann <cbo@boemann.dk> 0003 * SPDX-FileCopyrightText: 2007 Boudewijn Rempt <boud@valdyas.org> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 #ifndef KIS_GROUP_LAYER_H_ 0008 #define KIS_GROUP_LAYER_H_ 0009 0010 #include "kis_layer.h" 0011 #include "kis_types.h" 0012 0013 class KoColorSpace; 0014 0015 /** 0016 * A KisLayer that bundles child layers into a single layer. 0017 * The top layer is firstChild(), with index 0; the bottommost lastChild() with index childCount() - 1. 0018 * KisLayer::nextSibling() moves towards higher indices, from the top to the bottom layer; prevSibling() the reverse. 0019 * (Implementation detail: internally, the indices are reversed, for speed.) 0020 **/ 0021 class KRITAIMAGE_EXPORT KisGroupLayer : public KisLayer 0022 { 0023 Q_OBJECT 0024 0025 public: 0026 KisGroupLayer(KisImageWSP image, const QString &name, quint8 opacity); 0027 KisGroupLayer(const KisGroupLayer& rhs); 0028 ~KisGroupLayer() override; 0029 0030 KisNodeSP clone() const override { 0031 return KisNodeSP(new KisGroupLayer(*this)); 0032 } 0033 0034 bool allowAsChild(KisNodeSP) const override; 0035 0036 QIcon icon() const override; 0037 0038 KisBaseNode::PropertyList sectionModelProperties() const override; 0039 void setSectionModelProperties(const KisBaseNode::PropertyList &properties) override; 0040 0041 void setImage(KisImageWSP image) override; 0042 0043 KisLayerSP createMergedLayerTemplate(KisLayerSP prevLayer) override; 0044 void fillMergedLayerTemplate(KisLayerSP dstLayer, KisLayerSP prevLayer) override; 0045 0046 /** 0047 * Clear the projection 0048 */ 0049 void resetCache(const KoColorSpace *colorSpace = 0); 0050 0051 /** 0052 * XXX: make the colorspace of a layergroup user-settable: we want 0053 * to be able to have, for instance, a group of grayscale layers 0054 * resulting in a grayscale projection that is then merged with an 0055 * rgb image stack. 0056 */ 0057 const KoColorSpace * colorSpace() const override; 0058 0059 /// @return the projection of the layers in the group before the masks are applied. 0060 KisPaintDeviceSP original() const override; 0061 0062 /** 0063 * Returns own original device when tryOblidgeChild() mechanism is not triggered. 0064 * When tryOblidgeChild() mechanism is in action, returns null (therefor 0065 * threre is no need to do subtree composition). 0066 */ 0067 KisPaintDeviceSP lazyDestinationForSubtreeComposition() const; 0068 0069 qint32 x() const override; 0070 qint32 y() const override; 0071 void setX(qint32 x) override; 0072 void setY(qint32 y) override; 0073 0074 /// Group layers don't have a paint device, so return 0 0075 KisPaintDeviceSP paintDevice() const override; 0076 0077 /** 0078 Accept the specified visitor. 0079 @return true if the operation succeeded, false if it failed. 0080 */ 0081 bool accept(KisNodeVisitor &v) override; 0082 void accept(KisProcessingVisitor &visitor, KisUndoAdapter *undoAdapter) override; 0083 0084 /** 0085 * A special method that changes the default color of the 0086 * projection merged onto this group layer. Please note, that you 0087 * cannot use original()->setDefaultPixel(), because original() 0088 * device can be switched by tryOblidgeChild() mechanism randomly. 0089 */ 0090 void setDefaultProjectionColor(KoColor color); 0091 0092 /** 0093 * \see setDefaultProjectionColor() 0094 */ 0095 KoColor defaultProjectionColor() const; 0096 0097 bool passThroughMode() const; 0098 void setPassThroughMode(bool value); 0099 0100 QRect extent() const override; 0101 QRect exactBounds() const override; 0102 0103 bool projectionIsValid() const; 0104 0105 protected: 0106 KisLayer* onlyMeaningfulChild() const; 0107 KisPaintDeviceSP tryObligeChild() const; 0108 std::tuple<KisPaintDeviceSP, bool> originalImpl() const; 0109 0110 QRect amortizedProjectionRectForCleanupInChangePass() const override; 0111 private: 0112 bool checkCloneLayer(KisCloneLayerSP clone) const; 0113 bool checkNodeRecursively(KisNodeSP node) const; 0114 0115 private: 0116 struct Private; 0117 Private * const m_d; 0118 }; 0119 0120 #endif // KIS_GROUP_LAYER_H_ 0121