File indexing completed on 2024-05-12 16:01:54
0001 /* 0002 * SPDX-FileCopyrightText: 2017 Boudewijn Rempt <boud@valdyas.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KISREFERENCEIMAGE_H 0008 #define KISREFERENCEIMAGE_H 0009 0010 #include <QSharedDataPointer> 0011 0012 #include <KoColor.h> 0013 #include <KoTosContainer.h> 0014 #include <kis_types.h> 0015 #include <kritaui_export.h> 0016 #include <kundo2command.h> 0017 0018 class QImage; 0019 class QPointF; 0020 class QPainter; 0021 class QRectF; 0022 class KoStore; 0023 class KisCoordinatesConverter; 0024 class KisCanvas2; 0025 0026 /** 0027 * @brief The KisReferenceImage class represents a single reference image 0028 */ 0029 class KRITAUI_EXPORT KisReferenceImage : public KoTosContainer 0030 { 0031 public: 0032 struct KRITAUI_EXPORT SetSaturationCommand : public KUndo2Command { 0033 QVector<KisReferenceImage*> images; 0034 QVector<qreal> oldSaturations; 0035 qreal newSaturation; 0036 0037 explicit SetSaturationCommand(const QList<KoShape *> &images, qreal newSaturation, KUndo2Command *parent = 0); 0038 void undo() override; 0039 void redo() override; 0040 }; 0041 0042 KisReferenceImage(); 0043 KisReferenceImage(const KisReferenceImage &rhs); 0044 ~KisReferenceImage(); 0045 0046 KoShape *cloneShape() const override; 0047 0048 /** 0049 * Load a reference image from specified file. 0050 * If parent is provided and the image cannot be loaded, a warning message will be displayed to user. 0051 * @return reference image or null if one could not be loaded 0052 */ 0053 static KisReferenceImage * fromFile(const QString &filename, const KisCoordinatesConverter &converter, QWidget *parent /*= nullptr*/); 0054 static KisReferenceImage * fromClipboard(const KisCoordinatesConverter &converter); 0055 0056 /** 0057 * Load a reference image from specified paint device. 0058 * @return reference image or null if one could not be loaded 0059 */ 0060 static KisReferenceImage * 0061 fromPaintDevice(KisPaintDeviceSP src, const KisCoordinatesConverter &converter, QWidget *parent); 0062 0063 void setSaturation(qreal saturation); 0064 qreal saturation() const; 0065 0066 void setEmbed(bool embed); 0067 bool embed(); 0068 bool hasLocalFile(); 0069 0070 void setFilename(const QString &filename); 0071 QString filename() const; 0072 QString internalFile() const; 0073 0074 void paint(QPainter &gc) const override; 0075 0076 QColor getPixel(QPointF position); 0077 0078 void saveXml(QDomDocument &document, QDomElement &parentElement, int id); 0079 bool saveImage(KoStore *store) const; 0080 0081 static KisReferenceImage * fromXml(const QDomElement &elem); 0082 bool loadImage(KoStore *store); 0083 0084 QImage getImage(); 0085 0086 private: 0087 struct Private; 0088 QSharedDataPointer<Private> d; 0089 }; 0090 0091 #endif // KISREFERENCEIMAGE_H