File indexing completed on 2024-05-19 15:09:23
0001 /* 0002 SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef CLIPBOARD_H 0008 #define CLIPBOARD_H 0009 0010 #include <QClipboard> 0011 #include <QVariant> 0012 0013 class ClipboardPrivate; 0014 0015 /** 0016 * @brief Wrapper for QClipboard 0017 * 0018 * Offers a simple wrapper to interact with QClipboard from QtQuick. 0019 * 0020 * ``` 0021 * import QtQuick 2.5 0022 * import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddons 0023 * Text { 0024 * text: "lorem ipsum" 0025 * 0026 * KQuickControlsAddons.Clipboard { id: clipboard } 0027 * 0028 * MouseArea { 0029 * anchors.fill: parent 0030 * acceptedButtons: Qt.LeftButton | Qt.RightButton 0031 * onClicked: clipboard.content = parent.text 0032 * } 0033 * } 0034 * ``` 0035 */ 0036 class Clipboard : public QObject 0037 { 0038 Q_OBJECT 0039 /** 0040 * Controls the state this object will be monitoring and extracting its contents from. 0041 */ 0042 Q_PROPERTY(QClipboard::Mode mode READ mode WRITE setMode NOTIFY modeChanged) 0043 0044 /** 0045 * Provides the contents currently in the clipboard and lets modify them. 0046 */ 0047 Q_PROPERTY(QVariant content READ content WRITE setContent NOTIFY contentChanged) 0048 0049 /** 0050 * Figure out the nature of the contents in the clipboard as mimetype strings. 0051 */ 0052 Q_PROPERTY(QStringList formats READ formats NOTIFY contentChanged) 0053 0054 public: 0055 explicit Clipboard(QObject *parent = nullptr); 0056 0057 QClipboard::Mode mode() const; 0058 void setMode(QClipboard::Mode mode); 0059 0060 /** 0061 * @param format mimetype string 0062 * @return Output based on the mimetype. This may be a list of URLs, text, image data, or use QMimeData::data 0063 */ 0064 Q_SCRIPTABLE QVariant contentFormat(const QString &format) const; 0065 QVariant content() const; 0066 void setContent(const QVariant &content); 0067 0068 QStringList formats() const; 0069 0070 /** @see QClipboard::clear() */ 0071 Q_SCRIPTABLE void clear(); 0072 0073 Q_SIGNALS: 0074 void modeChanged(QClipboard::Mode mode); 0075 void contentChanged(); 0076 0077 private Q_SLOTS: 0078 void clipboardChanged(QClipboard::Mode m); 0079 0080 private: 0081 QClipboard *m_clipboard; 0082 QClipboard::Mode m_mode; 0083 }; 0084 0085 #endif