File indexing completed on 2024-05-19 04:28:59
0001 /* 0002 * SPDX-FileCopyrightText: 2011 Boudewijn Rempt <boud@valdyas.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #ifndef KIS_MIMEDATA_H 0008 #define KIS_MIMEDATA_H 0009 0010 #include <QMimeData> 0011 #include <QRect> 0012 0013 #include <kis_types.h> 0014 #include <kritaui_export.h> 0015 0016 class KisShapeController; 0017 class KisNodeDummy; 0018 class KisNodeInsertionAdapter; 0019 class KisNodeGraphListener; 0020 0021 /** 0022 * KisMimeData implements delayed retrieval of nodes for d&d and copy/paste. 0023 * 0024 * TODO: implement support for the ora format. 0025 */ 0026 class KRITAUI_EXPORT KisMimeData : public QMimeData 0027 { 0028 Q_OBJECT 0029 public: 0030 KisMimeData(QList<KisNodeSP> nodes, KisImageSP image, bool forceCopy = false); 0031 0032 /// return the node set on this mimedata object -- for internal use 0033 QList<KisNodeSP> nodes() const; 0034 0035 /** 0036 * For Cut/Copy/Paste operations we should detach the contents of 0037 * the mime data from the actual image because the user can modify 0038 * our image between the Copy/Cut and Paste calls. So we just copy 0039 * all our nodes into the internal array. 0040 * 0041 * It also fixes the problem of Cutting group layers. If we don't copy 0042 * the node and all its children, it'll be deleted by the Cut operation 0043 * and we will not be able to paste it correctly later. 0044 */ 0045 void deepCopyNodes(); 0046 0047 /** 0048 * KisMimeData provides the following formats if a node has been set: 0049 * <ul> 0050 * <li>application/x-krita-node-internal-pointer: requests a pointer to a Krita node. 0051 * <li>application/x-qt-image: fallback for other applications, returns a QImage of the 0052 * current node's paintdevice 0053 * <li>application/zip: allows drop targets that can handle zip files to open the data 0054 * </ul> 0055 */ 0056 QStringList formats() const override; 0057 0058 static KisNodeList loadNodesFast( 0059 const QMimeData *data, 0060 KisImageSP image, 0061 KisShapeController *shapeController, 0062 bool ©Node); 0063 0064 static KisNodeList loadNodesFastAndRecenter(const QPoint &preferredCenter, 0065 const QMimeData *data, 0066 KisImageSP image, 0067 KisShapeController *shapeController, 0068 bool ©Node); 0069 0070 private: 0071 /** 0072 * Loads a node from a mime container 0073 * Supports image and color types. 0074 */ 0075 static KisNodeList loadNonNativeNodes(const QMimeData *data, 0076 KisImageWSP image); 0077 0078 /** 0079 * Try load the node, which belongs to the same Krita instance, 0080 * that is can be fetched without serialization 0081 */ 0082 static KisNodeList tryLoadInternalNodes(const QMimeData *data, 0083 KisImageSP image, 0084 KisShapeController *shapeController, 0085 bool /* IN-OUT */ ©Node); 0086 0087 public: 0088 static QMimeData* mimeForLayers(const KisNodeList &nodes, KisImageSP image, bool forceCopy = false); 0089 static QMimeData* mimeForLayersDeepCopy(const KisNodeList &nodes, KisImageSP image, bool forceCopy); 0090 static bool insertMimeLayers(const QMimeData *data, 0091 KisImageSP image, 0092 KisShapeController *shapeController, 0093 KisNodeDummy *parentDummy, 0094 KisNodeDummy *aboveThisDummy, 0095 bool copyNode, 0096 KisNodeInsertionAdapter *nodeInsertionAdapter, 0097 bool changeOffset = false, 0098 QPointF offset = QPointF()); 0099 0100 protected: 0101 0102 QVariant retrieveData(const QString &mimetype, QVariant::Type preferredType) const override; 0103 0104 private: 0105 static void initializeExternalNode(KisNodeSP *nodes, 0106 KisImageSP srcImage, KisImageSP dstImage, 0107 KisShapeController *shapeController); 0108 0109 private: 0110 0111 QList<KisNodeSP> m_nodes; 0112 bool m_forceCopy; 0113 KisImageSP m_image; 0114 QRect m_copiedBounds; 0115 }; 0116 0117 #endif // KIS_MIMEDATA_H