File indexing completed on 2025-02-02 04:14:51

0001 /*
0002  *  SPDX-FileCopyrightText: 2018 Anna Medonosova <anna.medonosova@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef KOGAMUTMASK_H
0008 #define KOGAMUTMASK_H
0009 
0010 #include <QPainter>
0011 #include <QString>
0012 #include <QVector>
0013 #include <cmath>
0014 
0015 #include <FlakeDebug.h>
0016 #include <KoResource.h>
0017 #include <KoShape.h>
0018 
0019 //class KoViewConverter;
0020 class QTransform;
0021 
0022 class KoGamutMaskShape
0023 {
0024 public:
0025     KoGamutMaskShape(KoShape* shape);
0026     KoGamutMaskShape();
0027     ~KoGamutMaskShape();
0028 
0029     bool coordIsClear(const QPointF& coord) const;
0030     QPainterPath outline();
0031     void paint(QPainter &painter);
0032     void paintStroke(QPainter &painter);
0033     KoShape* koShape();
0034 
0035 private:
0036     KoShape* m_maskShape {nullptr};
0037 };
0038 
0039 
0040 /**
0041  * @brief The resource type for gamut masks used by the artistic color selector
0042  */
0043 class KRITAFLAKE_EXPORT KoGamutMask : public QObject, public KoResource
0044 {
0045     Q_OBJECT
0046 
0047 public:
0048     KoGamutMask(const QString &filename);
0049     KoGamutMask();
0050     KoGamutMask(KoGamutMask *rhs);
0051     KoGamutMask(const KoGamutMask &rhs);
0052     KoGamutMask &operator=(const KoGamutMask &rhs) = delete;
0053     KoResourceSP clone() const override;
0054     ~KoGamutMask() override;
0055 
0056     bool coordIsClear(const QPointF& coord, bool preview);
0057     bool loadFromDevice(QIODevice *dev, KisResourcesInterfaceSP resourcesInterface) override;
0058     bool saveToDevice(QIODevice* dev) const override;
0059 
0060     QPair<QString, QString> resourceType() const override
0061     {
0062         return QPair<QString, QString>(ResourceType::GamutMasks, "");
0063     }
0064 
0065     void paint(QPainter &painter, bool preview);
0066     void paintStroke(QPainter &painter, bool preview);
0067 
0068     QTransform maskToViewTransform(qreal viewSize);
0069     QTransform viewToMaskTransform(qreal viewSize);
0070 
0071     QString title() const;
0072     void setTitle(QString title);
0073 
0074     QString description() const;
0075     void setDescription(QString description);
0076 
0077     QString defaultFileExtension() const override;
0078 
0079     int rotation();
0080     void setRotation(int rotation);
0081 
0082     QSizeF maskSize();
0083 
0084     void setMaskShapes(QList<KoShape*> shapes);   
0085     void setPreviewMaskShapes(QList<KoShape*> shapes);
0086 
0087     QList<KoShape*> koShapes() const;
0088 
0089     void clearPreview();
0090 
0091 private:
0092     void setMaskShapesToVector(QList<KoShape*> shapes, QVector<KoGamutMaskShape*>& targetVector);
0093 
0094     struct Private;
0095     Private* const d;
0096 };
0097 
0098 typedef QSharedPointer<KoGamutMask> KoGamutMaskSP;
0099 
0100 #endif // KOGAMUTMASK_H