File indexing completed on 2024-05-19 04:28:57
0001 /* 0002 * SPDX-FileCopyrightText: 2013 Boudewijn Rempt <boud@valdyas.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #ifndef KIS_FILE_LAYER_H 0007 #define KIS_FILE_LAYER_H 0008 0009 #include "kritaui_export.h" 0010 0011 #include "kis_external_layer_iface.h" 0012 #include "kis_safe_document_loader.h" 0013 0014 /** 0015 * @brief The KisFileLayer class loads a particular file as a layer into the layer stack. 0016 */ 0017 class KRITAUI_EXPORT KisFileLayer : public KisExternalLayer 0018 { 0019 Q_OBJECT 0020 public: 0021 0022 enum ScalingMethod { 0023 None, 0024 ToImageSize, 0025 ToImagePPI 0026 }; 0027 0028 KisFileLayer(KisImageWSP image, const QString &name, quint8 opacity); 0029 /** 0030 * @brief KisFileLayer create a new file layer with the given file 0031 * @param image the image the file layer will belong to 0032 * @param basePath the path to the image, if it has been saved before. 0033 * @param filename the path to the file, relative to the basePath 0034 * @param scalingMethod @see ScalingMethod 0035 * @param scalingFilter the ID of the KisFilterStrategy to be used if scaling 0036 * @param name the name of the layer 0037 * @param opacity the opacity of the layer 0038 */ 0039 KisFileLayer(KisImageWSP image, const QString& basePath, const QString &filename, ScalingMethod scalingMethod, QString scalingFilter, const QString &name, quint8 opacity, const KoColorSpace *fallbackColorSpace = 0); 0040 ~KisFileLayer() override; 0041 KisFileLayer(const KisFileLayer& rhs); 0042 0043 QIcon icon() const override; 0044 0045 void resetCache() override; 0046 0047 KisPaintDeviceSP original() const override; 0048 KisPaintDeviceSP paintDevice() const override; 0049 void setSectionModelProperties(const KisBaseNode::PropertyList &properties) override; 0050 KisBaseNode::PropertyList sectionModelProperties() const override; 0051 0052 /** 0053 * @brief setFileName replace the existing file with a new one 0054 * @param basePath the path to the image, if it has been saved before. 0055 * @param filename the path to the file, relative to the basePath 0056 */ 0057 void setFileName(const QString &basePath, const QString &filename); 0058 QString fileName() const; 0059 QString path() const; 0060 0061 0062 ScalingMethod scalingMethod() const; 0063 void setScalingMethod(ScalingMethod method); 0064 0065 QString scalingFilter() const; 0066 void setScalingFilter(QString method); 0067 0068 KisNodeSP clone() const override; 0069 bool allowAsChild(KisNodeSP) const override; 0070 0071 bool accept(KisNodeVisitor&) override; 0072 void accept(KisProcessingVisitor &visitor, KisUndoAdapter *undoAdapter) override; 0073 0074 KUndo2Command* crop(const QRect & rect) override; 0075 KUndo2Command* transform(const QTransform &transform) override; 0076 0077 void setImage(KisImageWSP image) override; 0078 0079 private Q_SLOTS: 0080 void slotLoadingFinished(KisPaintDeviceSP projection, qreal xRes, qreal yRes, const QSize &size); 0081 void slotLoadingFailed(); 0082 void slotFileExistsStateChanged(bool exists); 0083 void openFile() const; 0084 0085 Q_SIGNALS: 0086 void sigRequestOpenFile(); 0087 0088 private: 0089 enum State { 0090 FileLoaded, 0091 FileNotFound, 0092 FileLoadingFailed 0093 }; 0094 0095 void changeState(State newState); 0096 0097 private: 0098 QString m_basePath; 0099 QString m_filename; 0100 ScalingMethod m_scalingMethod {None}; 0101 QString m_scalingFilter; 0102 0103 KisPaintDeviceSP m_paintDevice; 0104 KisSafeDocumentLoader m_loader; 0105 QSize m_generatedForImageSize; 0106 qreal m_generatedForXRes = 0.0; 0107 qreal m_generatedForYRes = 0.0; 0108 0109 State m_state = FileNotFound; 0110 }; 0111 0112 #endif // KIS_FILE_LAYER_H