File indexing completed on 2024-05-12 16:01:28
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> 0076 askUserForSource(const QMimeData *data, 0077 bool useClipboardFallback = false) const; 0078 0079 /** 0080 * Get the contents of the specified mimedata buffer in the form of a paint device. 0081 */ 0082 KisPaintDeviceSP clipFromMimeData(const QMimeData *data, 0083 const QRect &imageBounds, 0084 bool showPopup, 0085 int overridePasteBehaviour = -1, 0086 KisTimeSpan *clipRange = nullptr, 0087 bool useClipboardFallback = false) const; 0088 0089 KisPaintDeviceSP clipFromKritaLayers(const QRect &imageBounds, 0090 const KoColorSpace *cs) const; 0091 0092 KisPaintDeviceSP 0093 clipFromBoardContents(const QMimeData *data, 0094 const QRect &imageBounds, 0095 bool showPopup, 0096 int overridePasteBehaviour = -1, 0097 bool useClipboardFallback = false, 0098 QPair<bool, PasteFormatBehaviour> source = { 0099 false, 0100 PasteFormatBehaviour::PASTE_FORMAT_ASK}) const; 0101 0102 bool hasClip() const; 0103 0104 QSize clipSize() const; 0105 0106 void setLayers(KisNodeList nodes, KisImageSP image, bool forceCopy = false); 0107 bool hasLayers() const; 0108 bool hasLayerStyles() const; 0109 0110 const QMimeData* layersMimeData() const; 0111 0112 bool hasUrls() const; 0113 0114 Q_SIGNALS: 0115 void clipChanged(); 0116 0117 private Q_SLOTS: 0118 void clipboardDataChanged(); 0119 0120 private: 0121 Q_DISABLE_COPY(KisClipboard); 0122 0123 KisPaintDeviceSP 0124 clipFromKritaSelection(const QMimeData *data, const QRect &imageBounds, KisTimeSpan *clipRange) const; 0125 0126 KisPaintDeviceSP fetchImageByURL(const QUrl &originalUrl) const; 0127 0128 QImage getImageFromMimeData(const QMimeData *cbData) const; 0129 0130 KisClipboardPrivate *const d; 0131 }; 0132 0133 #endif // __KIS_CLIPBOARD_H_