File indexing completed on 2024-05-12 15:58:32

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_PAINT_LAYER_H_
0008 #define KIS_PAINT_LAYER_H_
0009 
0010 #include "kis_types.h"
0011 #include "kis_layer.h"
0012 #include "kis_indirect_painting_support.h"
0013 #include "KisDecoratedNodeInterface.h"
0014 
0015 #include <QBitArray>
0016 
0017 class KoColorSpace;
0018 
0019 /**
0020  * This layer is of a type that can be drawn on. A paint layer can
0021  * have any number of effect masks, a transparency mask, a local
0022  * selection and a protection mask.
0023  *
0024  * The protection mask can be read/write, read-only or write-only.
0025  * The transparency mask has two rendering forms: as a selection mask
0026  * and by changing the transparency of the paint layer's pixels.
0027  */
0028 class KRITAIMAGE_EXPORT KisPaintLayer : public KisLayer, public KisIndirectPaintingSupport, public KisDecoratedNodeInterface
0029 {
0030 
0031     Q_OBJECT
0032 
0033 public:
0034     /**
0035      * Construct a paint layer with the given parameters. The default bounds of the paintdevice are overwritten.
0036      * @param image this layer belongs to, or null, if it shouldn't belong to any image
0037      * @param name of the layer
0038      * @param opacity in the range between OPACITY_TRANSPARENT_U8 and OPACITY_OPAQUE_U8
0039      * @param dev is the paint device, that should be used
0040      */
0041     KisPaintLayer(KisImageWSP image, const QString& name, quint8 opacity, KisPaintDeviceSP dev);
0042 
0043     /**
0044      * Construct a paint layer with the given parameters
0045      * @param image this layer belongs to. it must not be null and it must have a valid color space.
0046      * @param name of the layer
0047      * @param opacity in the range between OPACITY_TRANSPARENT_U8 and OPACITY_OPAQUE_U8
0048      */
0049     KisPaintLayer(KisImageWSP image, const QString& name, quint8 opacity);
0050 
0051     /**
0052      * Construct a paint layer with the given parameters
0053      * @param image this layer belongs to, or null, if it shouldn't belong to any image. image must not be null, if colorSpace is null
0054      * @param name of the layer
0055      * @param opacity in the range between OPACITY_TRANSPARENT_U8 and OPACITY_OPAQUE_U8
0056      * @param colorSpace is the color space, that should be used to construct the paint device. it can be null, if the image is valid.
0057      */
0058     KisPaintLayer(KisImageWSP image, const QString& name, quint8 opacity, const KoColorSpace * colorSpace);
0059     /**
0060      * Copy Constructor
0061      */
0062     KisPaintLayer(const KisPaintLayer& rhs);
0063     ~KisPaintLayer() override;
0064 
0065     KisNodeSP clone() const override {
0066         return KisNodeSP(new KisPaintLayer(*this));
0067     }
0068 
0069     bool allowAsChild(KisNodeSP) const override;
0070 
0071     bool needProjection() const override;
0072 
0073     QIcon icon() const override;
0074     void setImage(KisImageWSP image) override;
0075 
0076     KisBaseNode::PropertyList sectionModelProperties() const override;
0077     void setSectionModelProperties(const KisBaseNode::PropertyList &properties) override;
0078 
0079 public:
0080 
0081     QRect extent() const override;
0082     QRect exactBounds() const override;
0083 
0084     bool accept(KisNodeVisitor &v) override;
0085     void accept(KisProcessingVisitor &visitor, KisUndoAdapter *undoAdapter) override;
0086 
0087     /**
0088      * set the channelflags for locking certain channels (used by painting tools)
0089      * for this layer to the specified bit array.
0090      * The bit array must have exactly the same number of channels as
0091      * the colorspace this layer is in, or be empty, in which case all
0092      * channels are active.
0093      */
0094     void setChannelLockFlags(const QBitArray& channelFlags);
0095     
0096     /**
0097      * Return a bit array where each bit indicates whether a
0098      * particular channel is locked or not (used by painting tools).
0099      * If the channelflags bit array is empty, all channels are active.
0100      */
0101     const QBitArray& channelLockFlags() const;
0102 
0103     /**
0104      * Returns the paintDevice that accompanies this layer
0105      */
0106     KisPaintDeviceSP paintDevice() const override;
0107 
0108     /**
0109      * Returns the original pixels before masks have been applied.
0110      */
0111     KisPaintDeviceSP original() const override;
0112 
0113     /**
0114      * @returns true when painting should not affect the alpha channel
0115      */
0116     bool alphaLocked() const;
0117 
0118     /**
0119      * @param l if true, the alpha channel will be protected from modification
0120      */
0121     void setAlphaLocked(bool lock);
0122 
0123     /**
0124      * @return true if onion skins should be rendered on this layer
0125      */
0126     bool onionSkinEnabled() const;
0127 
0128     /**
0129      * @param state whether onion skins should be rendered
0130      */
0131     void setOnionSkinEnabled(bool state);
0132 
0133     /**
0134      * Reset the onion skin cache to initial state. Useful for
0135      * ensuring that old and invalid onion skin projections
0136      * are no longer used.
0137      */
0138     void flushOnionSkinCache();
0139 
0140     KisPaintDeviceList getLodCapableDevices() const override;
0141 
0142     bool decorationsVisible() const override;
0143     void setDecorationsVisible(bool value, bool update) override;
0144     using KisDecoratedNodeInterface::setDecorationsVisible;
0145 
0146 public Q_SLOTS:
0147     void slotExternalUpdateOnionSkins();
0148 
0149 
0150 public:
0151 
0152     // KisIndirectPaintingSupport
0153     KisLayer* layer() {
0154         return this;
0155     }
0156 
0157 protected:
0158     // override from KisLayer
0159     void copyOriginalToProjection(const KisPaintDeviceSP original,
0160                                   KisPaintDeviceSP projection,
0161                                   const QRect& rect) const override;
0162 
0163     KisKeyframeChannel *requestKeyframeChannel(const QString &id) override;
0164     bool supportsKeyframeChannel(const QString &id) override;
0165 
0166 private:
0167     void init(KisPaintDeviceSP paintDevice, const QBitArray &paintChannelFlags = QBitArray());
0168 
0169     struct Private;
0170     Private * const m_d;
0171 };
0172 
0173 typedef KisSharedPtr<KisPaintLayer> KisPaintLayerSP;
0174 
0175 #endif // KIS_PAINT_LAYER_H_
0176