File indexing completed on 2024-05-12 15:58:12
0001 /* 0002 * SPDX-FileCopyrightText: 2007 Boudewijn Rempt <boud@valdyas.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #ifndef KIS_CLONE_LAYER_H_ 0007 #define KIS_CLONE_LAYER_H_ 0008 0009 #include <QObject> 0010 #include "kis_types.h" 0011 #include "kis_layer.h" 0012 0013 #include <kritaimage_export.h> 0014 #include "kis_node_uuid_info.h" 0015 0016 class KisNodeVisitor; 0017 0018 enum CopyLayerType { 0019 COPY_PROJECTION, 0020 COPY_ORIGINAL 0021 }; 0022 0023 0024 /** 0025 * A copy layer adds the contents of another layer in another place in 0026 * the layer stack. It is possible to add more effect masks to the 0027 * copy. You can either copy the original data or the projection data 0028 * produced by the original layer + original effect masks. There is no 0029 * physical copy of the data; if the original changes, the copy 0030 * changes too. The copy layer can be positioned differently from the 0031 * original layer. 0032 **/ 0033 class KRITAIMAGE_EXPORT KisCloneLayer : public KisLayer 0034 { 0035 0036 Q_OBJECT 0037 0038 public: 0039 0040 KisCloneLayer(KisLayerSP from, KisImageWSP image, const QString &name, quint8 opacity); 0041 KisCloneLayer(const KisCloneLayer& rhs); 0042 ~KisCloneLayer() override; 0043 0044 KisNodeSP clone() const override { 0045 return KisNodeSP(new KisCloneLayer(*this)); 0046 } 0047 0048 /** 0049 * When the source layer of the clone is removed from the stack 0050 * we should substitute the clone with a usual paint layer, 0051 * because the source might become unreachable quite soon. This 0052 * method builds a paint layer representation of this clone. 0053 */ 0054 KisLayerSP reincarnateAsPaintLayer() const; 0055 0056 void setImage(KisImageWSP image) override; 0057 bool allowAsChild(KisNodeSP) const override; 0058 0059 KisPaintDeviceSP original() const override; 0060 KisPaintDeviceSP paintDevice() const override; 0061 bool needProjection() const override; 0062 0063 const KoColorSpace* colorSpace() const override; 0064 0065 QIcon icon() const override; 0066 KisBaseNode::PropertyList sectionModelProperties() const override; 0067 0068 qint32 x() const override; 0069 qint32 y() const override; 0070 0071 void setX(qint32) override; 0072 void setY(qint32) override; 0073 0074 /// Returns an approximation of where the bounds on actual data are in this layer 0075 QRect extent() const override; 0076 0077 /// Returns the exact bounds of where the actual data resides in this layer 0078 QRect exactBounds() const override; 0079 0080 bool accept(KisNodeVisitor &) override; 0081 void accept(KisProcessingVisitor &visitor, KisUndoAdapter *undoAdapter) override; 0082 0083 /** 0084 * Used when loading: loading is done in two passes, and the copy 0085 * from layer is set when all layers have been created, not during 0086 * loading. 0087 */ 0088 void setCopyFromInfo(KisNodeUuidInfo info); 0089 KisNodeUuidInfo copyFromInfo() const; 0090 0091 void setCopyFrom(KisLayerSP layer); 0092 KisLayerSP copyFrom() const; 0093 0094 void setCopyType(CopyLayerType type); 0095 CopyLayerType copyType() const; 0096 0097 /** 0098 * This function is called by the original to notify 0099 * us that it is dirty 0100 */ 0101 void setDirtyOriginal(const QRect &rect); 0102 0103 QRect needRectOnSourceForMasks(const QRect &rc) const; 0104 0105 void syncLodCache() override; 0106 0107 protected: 0108 // override from KisNode 0109 QRect accessRect(const QRect &rect, PositionToFilthy pos) const override; 0110 0111 // override from KisLayer 0112 void copyOriginalToProjection(const KisPaintDeviceSP original, 0113 KisPaintDeviceSP projection, 0114 const QRect& rect) const override; 0115 0116 void notifyParentVisibilityChanged(bool value) override; 0117 QRect outgoingChangeRect(const QRect &rect) const override; 0118 private: 0119 0120 struct Private; 0121 Private * const m_d {nullptr}; 0122 0123 }; 0124 0125 #endif // KIS_CLONE_LAYER_H_ 0126