kis_colorize_mask.h 5 KB
Newer Older
1
/*
2
 *  SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com>
3
 *
Samuel Gaist's avatar
Samuel Gaist committed
4
 *  SPDX-License-Identifier: GPL-2.0-or-later
5 6 7 8 9 10 11 12 13 14 15 16
 */

#ifndef __KIS_COLORIZE_MASK_H
#define __KIS_COLORIZE_MASK_H

#include <QScopedPointer>

#include "kis_types.h"
#include "kis_effect_mask.h"
#include "kritaimage_export.h"

class KoColor;
17 18 19 20 21 22
class KUndo2Command;

namespace KisLazyFillTools
{
    struct KeyStroke;
}
23 24 25 26 27


class KRITAIMAGE_EXPORT KisColorizeMask : public KisEffectMask
{
    Q_OBJECT
28 29 30
public:
    struct KeyStrokeColors {
        QVector<KoColor> colors;
31
        int transparentIndex = -1;
32 33
    };

34
public:
35
    KisColorizeMask(KisImageWSP image, const QString &name);
36
    ~KisColorizeMask() override;
37 38 39

    KisColorizeMask(const KisColorizeMask& rhs);

40
    void initializeCompositeOp();
41
    const KoColorSpace* colorSpace() const override;
42 43

    // assign color profile without conversion of pixel data
44
    void setProfile(const KoColorProfile *profile, KUndo2Command *parentCommand);
45

46 47 48
    KUndo2Command* setColorSpace(const KoColorSpace * dstColorSpace,
                                 KoColorConversionTransformation::Intent renderingIntent = KoColorConversionTransformation::internalRenderingIntent(),
                                 KoColorConversionTransformation::ConversionFlags conversionFlags = KoColorConversionTransformation::internalConversionFlags());
49

50
    KisPaintDeviceSP paintDevice() const override;
51
    KisPaintDeviceSP coloringProjection() const;
52

53
    KisPaintDeviceSP colorSampleSourceDevice() const override;
54

55
    KisNodeSP clone() const override {
56 57 58
        return KisNodeSP(new KisColorizeMask(*this));
    }

59
    QIcon icon() const override;
60

61
    void setImage(KisImageWSP image) override;
62 63
    bool accept(KisNodeVisitor &v) override;
    void accept(KisProcessingVisitor &visitor, KisUndoAdapter *undoAdapter) override;
64 65 66 67

    QRect decorateRect(KisPaintDeviceSP &src,
                       KisPaintDeviceSP &dst,
                       const QRect & rc,
68
                       PositionToFilthy maskPos) const override;
69

70 71 72
    void setCurrentColor(const KoColor &color) override;
    void mergeToLayer(KisNodeSP layer, KisPostExecutionUndoAdapter *undoAdapter, const KUndo2MagicString &transactionText,int timedID) override;
    void writeMergeData(KisPainter *painter, KisPaintDeviceSP src) override;
73
    bool supportsNonIndirectPainting() const override;
74

75 76
    QRect exactBounds() const override;
    QRect extent() const override;
77

78 79 80 81
    /**
     * Colorize mask has its own "projection", so it should report it
     * to the parent layer using non-dependent-extent property
     */
82
    QRect nonDependentExtent() const override;
83

84 85
    void setSectionModelProperties(const KisBaseNode::PropertyList &properties) override;
    KisBaseNode::PropertyList sectionModelProperties() const override;
86 87 88 89 90 91

    KeyStrokeColors keyStrokesColors() const;
    void setKeyStrokesColors(KeyStrokeColors colors);

    void removeKeyStroke(const KoColor &color);

92 93 94
    QVector<KisPaintDeviceSP> allPaintDevices() const;
    void resetCache();

95 96 97 98 99 100 101 102 103 104 105 106
    void setUseEdgeDetection(bool value);
    bool useEdgeDetection() const;

    void setEdgeDetectionSize(qreal value);
    qreal edgeDetectionSize() const;

    void setFuzzyRadius(qreal value);
    qreal fuzzyRadius() const;

    void setCleanUpAmount(qreal value);
    qreal cleanUpAmount() const;

107 108
    void setLimitToDeviceBounds(bool value);
    bool limitToDeviceBounds() const;
109

110 111 112
    void testingAddKeyStroke(KisPaintDeviceSP dev, const KoColor &color, bool isTransparent = false);
    void testingRegenerateMask();
    KisPaintDeviceSP testingFilteredSource() const;
113 114 115

    QList<KisLazyFillTools::KeyStroke> fetchKeyStrokesDirect() const;
    void setKeyStrokesDirect(const QList<KisLazyFillTools::KeyStroke> &strokes);
116

117 118 119 120
    qint32 x() const override;
    qint32 y() const override;
    void setX(qint32 x) override;
    void setY(qint32 y) override;
121

122
    KisPaintDeviceList getLodCapableDevices() const override;
123

124 125
    void regeneratePrefilteredDeviceIfNeeded();

126
private Q_SLOTS:
127
    void slotUpdateRegenerateFilling(bool prefilterOnly = false);
128 129
    void slotRegenerationFinished(bool prefilterOnly);
    void slotRegenerationCancelled();
130 131

    void slotUpdateOnDirtyParent();
132
    void slotRecalculatePrefilteredImage();
133 134 135

Q_SIGNALS:
    void sigKeyStrokesListChanged();
136
    void sigUpdateOnDirtyParent() const;
137 138 139 140

private:
    // NOTE: please access this methods using model properties only!

141 142 143 144 145 146 147 148 149 150
    bool needsUpdate() const;
    void setNeedsUpdate(bool value);

    bool showColoring() const;
    void setShowColoring(bool value);

    bool showKeyStrokes() const;
    void setShowKeyStrokes(bool value);

private:
151
    void rerenderFakePaintDevice();
152
    KisImageSP fetchImage() const;
153
    void moveAllInternalDevices(const QPoint &diff);
154

155 156 157
    template <class DeviceMetricPolicy>
    QRect calculateMaskBounds(DeviceMetricPolicy policy) const;

Halla Rempt's avatar
Halla Rempt committed
158 159 160
    friend struct SetKeyStrokesColorSpaceCommand;
    friend struct KeyStrokeAddRemoveCommand;
    friend struct SetKeyStrokeColorsCommand;
161

162 163 164 165 166 167
private:
    struct Private;
    const QScopedPointer<Private> m_d;
};

#endif /* __KIS_COLORIZE_MASK_H */