1 /*
2  * Copyright (C) 2017 Boudewijn Rempt <boud@valdyas.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifndef KISREFERENCEIMAGE_H
21 #define KISREFERENCEIMAGE_H
22 
23 #include <QSharedDataPointer>
24 
25 #include <kundo2command.h>
26 #include <kritaui_export.h>
27 #include <KoTosContainer.h>
28 #include <KoColor.h>
29 
30 class QImage;
31 class QPointF;
32 class QPainter;
33 class QRectF;
34 class KoStore;
35 class KisCoordinatesConverter;
36 class KisCanvas2;
37 
38 /**
39  * @brief The KisReferenceImage class represents a single reference image
40  */
41 class KRITAUI_EXPORT KisReferenceImage : public KoTosContainer
42 {
43 public:
44     struct KRITAUI_EXPORT SetSaturationCommand : public KUndo2Command {
45         QVector<KisReferenceImage*> images;
46         QVector<qreal> oldSaturations;
47         qreal newSaturation;
48 
49         explicit SetSaturationCommand(const QList<KoShape *> &images, qreal newSaturation, KUndo2Command *parent = 0);
50         void undo() override;
51         void redo() override;
52     };
53 
54     KisReferenceImage();
55     KisReferenceImage(const KisReferenceImage &rhs);
56     ~KisReferenceImage();
57 
58     KoShape *cloneShape() const override;
59 
60     /**
61      * Load a reference image from specified file.
62      * If parent is provided and the image cannot be loaded, a warning message will be displayed to user.
63      * @return reference image or null if one could not be loaded
64      */
65     static KisReferenceImage * fromFile(const QString &filename, const KisCoordinatesConverter &converter, QWidget *parent /*= nullptr*/);
66     static KisReferenceImage * fromClipboard(const KisCoordinatesConverter &converter);
67 
68     void setSaturation(qreal saturation);
69     qreal saturation() const;
70 
71     void setEmbed(bool embed);
72     bool embed();
73     bool hasLocalFile();
74 
75     void setFilename(const QString &filename);
76     QString filename() const;
77     QString internalFile() const;
78 
79     void paint(QPainter &gc, KoShapePaintingContext &paintcontext) const override;
80 
loadOdf(const KoXmlElement &,KoShapeLoadingContext &)81     bool loadOdf(const KoXmlElement &/*element*/, KoShapeLoadingContext &/*context*/) override { return false; }
saveOdf(KoShapeSavingContext &)82     void saveOdf(KoShapeSavingContext &/*context*/) const override {}
83 
84     QColor getPixel(QPointF position);
85 
86     void saveXml(QDomDocument &document, QDomElement &parentElement, int id);
87     bool saveImage(KoStore *store) const;
88 
89     static KisReferenceImage * fromXml(const QDomElement &elem);
90     bool loadImage(KoStore *store);
91 
92 private:
93     struct Private;
94     QSharedDataPointer<Private> d;
95 };
96 
97 #endif // KISREFERENCEIMAGE_H
98