1 /*
2  *  Copyright (c) 2013 Boudewijn Rempt <boud@valdyas.org>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program 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
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 #ifndef KIS_FILE_LAYER_H
19 #define KIS_FILE_LAYER_H
20 
21 #include "kritaui_export.h"
22 
23 #include "kis_external_layer_iface.h"
24 #include "kis_safe_document_loader.h"
25 
26 /**
27  * @brief The KisFileLayer class loads a particular file as a layer into the layer stack.
28  */
29 class KRITAUI_EXPORT KisFileLayer : public KisExternalLayer
30 {
31     Q_OBJECT
32 public:
33 
34     enum ScalingMethod {
35         None,
36         ToImageSize,
37         ToImagePPI
38     };
39 
40     KisFileLayer(KisImageWSP image, const QString &name, quint8 opacity);
41     /**
42      * @brief KisFileLayer create a new file layer with the given file
43      * @param image the image the file layer will belong to
44      * @param basePath the path to the image, if it has been saved before.
45      * @param filename the path to the file, relative to the basePath
46      * @param scalingMethod @see ScalingMethod
47      * @param name the name of the layer
48      * @param opacity the opacity of the layer
49      */
50     KisFileLayer(KisImageWSP image, const QString& basePath, const QString &filename, ScalingMethod scalingMethod, const QString &name, quint8 opacity);
51     ~KisFileLayer() override;
52     KisFileLayer(const KisFileLayer& rhs);
53 
54     QIcon icon() const override;
55 
56     void resetCache() override;
57 
58     const KoColorSpace *colorSpace() const override;
59 
60     KisPaintDeviceSP original() const override;
61     KisPaintDeviceSP paintDevice() const override;
62     void setSectionModelProperties(const KisBaseNode::PropertyList &properties) override;
63     KisBaseNode::PropertyList sectionModelProperties() const override;
64 
65     /**
66      * @brief setFileName replace the existing file with a new one
67      * @param basePath the path to the image, if it has been saved before.
68      * @param filename the path to the file, relative to the basePath
69      */
70     void setFileName(const QString &basePath, const QString &filename);
71     QString fileName() const;
72     QString path() const;
73     void openFile() const;
74 
75     ScalingMethod scalingMethod() const;
76     void setScalingMethod(ScalingMethod method);
77 
78     KisNodeSP clone() const override;
79     bool allowAsChild(KisNodeSP) const override;
80 
81     bool accept(KisNodeVisitor&) override;
82     void accept(KisProcessingVisitor &visitor, KisUndoAdapter *undoAdapter) override;
83 
84     KUndo2Command* crop(const QRect & rect) override;
85     KUndo2Command* transform(const QTransform &transform) override;
86 
87     void setImage(KisImageWSP image) override;
88 
89 public Q_SLOTS:
90     void slotLoadingFinished(KisPaintDeviceSP projection, qreal xRes, qreal yRes, const QSize &size);
91 
92 private:
93     QString m_basePath;
94     QString m_filename;
95     ScalingMethod m_scalingMethod;
96 
97     KisPaintDeviceSP m_paintDevice;
98     KisSafeDocumentLoader m_loader;
99 };
100 
101 #endif // KIS_FILE_LAYER_H
102