File indexing completed on 2024-05-12 15:56:10
0001 /* 0002 * SPDX-FileCopyrightText: 1999 Matthias Elter <me@kde.org> 0003 * SPDX-FileCopyrightText: 2002 Patrick Julien <freak@codepimps.org> 0004 * SPDX-FileCopyrightText: 2004 Boudewijn Rempt <boud@valdyas.org> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 #ifndef KIS_GBR_BRUSH_ 0009 #define KIS_GBR_BRUSH_ 0010 0011 #include <QImage> 0012 #include <QVector> 0013 0014 #include "KisColorfulBrush.h" 0015 #include <kis_types.h> 0016 #include <kis_shared.h> 0017 #include <brushengine/kis_paint_information.h> 0018 0019 #include "kritabrush_export.h" 0020 0021 class KisQImagemask; 0022 typedef KisSharedPtr<KisQImagemask> KisQImagemaskSP; 0023 0024 class QString; 0025 class QIODevice; 0026 0027 class BRUSH_EXPORT KisGbrBrush : public KisColorfulBrush 0028 { 0029 0030 protected: 0031 0032 public: 0033 0034 /// Construct brush to load filename later as brush 0035 KisGbrBrush(const QString& filename); 0036 0037 /// Load brush from the specified data, at position dataPos, and set the filename 0038 KisGbrBrush(const QString& filename, 0039 const QByteArray & data, 0040 qint32 & dataPos); 0041 0042 /// Load brush from the specified paint device, in the specified region 0043 KisGbrBrush(KisPaintDeviceSP image, int x, int y, int w, int h); 0044 0045 /// Load brush as a copy from the specified QImage (handy when you need to copy a brush!) 0046 KisGbrBrush(const QImage& image, const QString& name = QString()); 0047 0048 ~KisGbrBrush() override; 0049 0050 KisGbrBrush(const KisGbrBrush& rhs); 0051 0052 KoResourceSP clone() const override; 0053 0054 KisGbrBrush &operator=(const KisGbrBrush &rhs); 0055 0056 bool loadFromDevice(QIODevice *dev, KisResourcesInterfaceSP resourcesInterface) override; 0057 bool saveToDevice(QIODevice* dev) const override; 0058 0059 QPair<QString, QString> resourceType() const override { 0060 return QPair<QString, QString>(ResourceType::Brushes, ResourceSubType::GbrBrushes); 0061 } 0062 0063 /** 0064 * Convert the mask to inverted gray scale, so it is alpha mask. 0065 * It can be used as MASK brush type. This operates on the data of the brush, 0066 * so it destruct the original brush data. 0067 * 0068 * @param preserveAlpha convert to grayscale, but save as full RGBA format, to allow 0069 * preserving lightness option 0070 */ 0071 virtual void makeMaskImage(bool preserveAlpha); 0072 0073 /** 0074 * @return default file extension for saving the brush 0075 */ 0076 QString defaultFileExtension() const override; 0077 0078 protected: 0079 /** 0080 * save the content of this brush to an IO device 0081 */ 0082 friend class KisImageBrushesPipe; 0083 friend class KisBrushExport; 0084 0085 void setBrushTipImage(const QImage& image) override; 0086 0087 void toXML(QDomDocument& d, QDomElement& e) const override; 0088 0089 private: 0090 0091 bool init(); 0092 bool initFromPaintDev(KisPaintDeviceSP image, int x, int y, int w, int h); 0093 0094 struct Private; 0095 Private* const d; 0096 }; 0097 0098 typedef QSharedPointer<KisGbrBrush> KisGbrBrushSP; 0099 0100 #endif // KIS_GBR_BRUSH_ 0101