File indexing completed on 2024-05-19 04:28:54
0001 /* 0002 * kis_clipboard.h - part of Krayon 0003 * 0004 * SPDX-FileCopyrightText: 2004 Boudewijn Rempt <boud@valdyas.org> 0005 * SPDX-FileCopyrightText: 2019 Dmitrii Utkin <loentar@gmail.com> 0006 * SPDX-FileCopyrightText: 2022 L. E. Segovia <amy@amyspark.me> 0007 * 0008 * SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 #ifndef __KIS_CLIPBOARD_H_ 0011 #define __KIS_CLIPBOARD_H_ 0012 0013 #include <QObject> 0014 #include <QSize> 0015 0016 #include <kis_types.h> 0017 0018 #include <kritaui_export.h> 0019 0020 class QRect; 0021 class QMimeData; 0022 class KisTimeSpan; 0023 class KoColorSpace; 0024 0025 class KisClipboardPrivate; 0026 0027 /** 0028 * The Krita clipboard is a clipboard that can store paint devices 0029 * instead of just qimage's. 0030 */ 0031 class KRITAUI_EXPORT KisClipboard : public QObject 0032 { 0033 0034 Q_OBJECT 0035 Q_PROPERTY(bool clip READ hasClip NOTIFY clipChanged) 0036 0037 public: 0038 enum PasteBehaviour { PASTE_ASSUME_WEB = 0, PASTE_ASSUME_MONITOR, PASTE_ASK }; 0039 0040 enum PasteFormatBehaviour { PASTE_FORMAT_ASK = 0, PASTE_FORMAT_DOWNLOAD, PASTE_FORMAT_LOCAL, PASTE_FORMAT_CLIP }; 0041 0042 KisClipboard(); 0043 ~KisClipboard() override; 0044 0045 static KisClipboard* instance(); 0046 0047 /** 0048 * Sets the clipboard to the contents of the specified paint device; also 0049 * set the system clipboard to a QImage representation of the specified 0050 * paint device. 0051 * 0052 * @param dev The paint device that will be stored on the clipboard 0053 * @param topLeft a hint about the place where the clip should be pasted by default 0054 */ 0055 void setClip(KisPaintDeviceSP dev, const QPoint& topLeft); 0056 0057 void setClip(KisPaintDeviceSP dev, const QPoint& topLeft, const KisTimeSpan &range); 0058 0059 /** 0060 * Get the contents of the clipboard in the form of a paint device. 0061 */ 0062 KisPaintDeviceSP clip(const QRect &imageBounds, 0063 bool showPopup, 0064 int overridePasteBehaviour = -1, 0065 KisTimeSpan *clipRange = nullptr) const; 0066 0067 /** 0068 * Given the mimedata for a paste event, ask user which source 0069 * they'll want to use for the image. 0070 * 0071 * @return A pair of bool and PasteFormatBehaviour: 0072 * The boolean indicates acceptance of the paste event. 0073 * If set, the PasteFormatBehaviour member indicates the chosen source. 0074 */ 0075 QPair<bool, PasteFormatBehaviour> askUserForSource(const QMimeData *data, 0076 bool useClipboardFallback = false) const; 0077 0078 /** 0079 * Get the contents of the specified mimedata buffer in the form of a paint device. 0080 */ 0081 KisPaintDeviceSP clipFromMimeData(const QMimeData *data, 0082 const QRect &imageBounds, 0083 bool showPopup, 0084 int overridePasteBehaviour = -1, 0085 KisTimeSpan *clipRange = nullptr, 0086 bool useClipboardFallback = false) const; 0087 0088 KisPaintDeviceSP clipFromKritaLayers(const QRect &imageBounds, 0089 const KoColorSpace *cs) const; 0090 0091 KisPaintDeviceSP clipFromBoardContents(const QMimeData *data, 0092 const QRect &imageBounds, 0093 bool showPopup, 0094 int overridePasteBehaviour = -1, 0095 bool useClipboardFallback = false, 0096 QPair<bool, PasteFormatBehaviour> source = { 0097 false, 0098 PasteFormatBehaviour::PASTE_FORMAT_ASK}) const; 0099 0100 bool hasClip() const; 0101 0102 QSize clipSize() const; 0103 0104 void setLayers(KisNodeList nodes, KisImageSP image, bool forceCopy = false); 0105 bool hasLayers() const; 0106 bool hasLayerStyles() const; 0107 0108 const QMimeData* layersMimeData() const; 0109 0110 bool hasUrls() const; 0111 0112 Q_SIGNALS: 0113 void clipChanged(); 0114 0115 private Q_SLOTS: 0116 void clipboardDataChanged(); 0117 0118 private: 0119 Q_DISABLE_COPY(KisClipboard); 0120 0121 KisPaintDeviceSP 0122 clipFromKritaSelection(const QMimeData *data, const QRect &imageBounds, KisTimeSpan *clipRange) const; 0123 0124 KisPaintDeviceSP fetchImageByURL(const QUrl &originalUrl) const; 0125 0126 QImage getImageFromMimeData(const QMimeData *cbData) const; 0127 0128 KisClipboardPrivate *const d; 0129 }; 0130 0131 #endif // __KIS_CLIPBOARD_H_