1 | /* |
2 | SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #ifndef CLIPBOARD_H |
8 | #define CLIPBOARD_H |
9 | |
10 | #include <QClipboard> |
11 | #include <QVariant> |
12 | #include <qqmlregistration.h> |
13 | |
14 | class ClipboardPrivate; |
15 | |
16 | /*! |
17 | * \qmltype Clipboard |
18 | * \inqmlmodule org.kde.kquickcontrols.addons |
19 | * \brief Wrapper for QClipboard. |
20 | * |
21 | * Offers a simple wrapper to interact with QClipboard from QtQuick. |
22 | * |
23 | * \qml |
24 | * import QtQuick |
25 | * import org.kde.kquickcontrolsaddons as KQuickControlsAddons |
26 | * Text { |
27 | * text: "lorem ipsum" |
28 | * |
29 | * KQuickControlsAddons.Clipboard { id: clipboard } |
30 | * |
31 | * MouseArea { |
32 | * anchors.fill: parent |
33 | * acceptedButtons: Qt.LeftButton | Qt.RightButton |
34 | * onClicked: clipboard.content = parent.text |
35 | * } |
36 | * } |
37 | * \endqml |
38 | */ |
39 | class Clipboard : public QObject |
40 | { |
41 | Q_OBJECT |
42 | QML_ELEMENT |
43 | /*! |
44 | * \qmlproperty QClipboard::Mode Clipboard::mode |
45 | * \brief Controls the state this object will be monitoring and extracting its contents from. |
46 | */ |
47 | Q_PROPERTY(QClipboard::Mode mode READ mode WRITE setMode NOTIFY modeChanged) |
48 | |
49 | /*! |
50 | * \qmlproperty var Clipboard::content |
51 | * \brief Provides the contents currently in the clipboard and lets modify them. |
52 | */ |
53 | Q_PROPERTY(QVariant content READ content WRITE setContent NOTIFY contentChanged) |
54 | |
55 | /*! |
56 | * \qmlproperty list<string> Clipboard::formats |
57 | * \brief Figure out the nature of the contents in the clipboard as mimetype strings. |
58 | */ |
59 | Q_PROPERTY(QStringList formats READ formats NOTIFY contentChanged) |
60 | |
61 | public: |
62 | explicit Clipboard(QObject *parent = nullptr); |
63 | |
64 | QClipboard::Mode mode() const; |
65 | void setMode(QClipboard::Mode mode); |
66 | |
67 | /*! |
68 | * \qmlmethod variant Clipboard::contentFormat(string format) |
69 | * \brief Returns Output based on the mimetype. |
70 | * |
71 | * This may be a list of URLs, text, image data, or use QMimeData::data. |
72 | * |
73 | * \a format mimetype string |
74 | */ |
75 | Q_SCRIPTABLE QVariant contentFormat(const QString &format) const; |
76 | QVariant content() const; |
77 | void setContent(const QVariant &content); |
78 | |
79 | QStringList formats() const; |
80 | |
81 | /*! |
82 | * \qmlmethod void Clipboard::clear() |
83 | * \sa QClipboard::clear() |
84 | */ |
85 | Q_SCRIPTABLE void clear(); |
86 | |
87 | Q_SIGNALS: |
88 | /*! |
89 | * \qmlsignal Clipboard::modeChanged(QClipboard::Mode mode) |
90 | */ |
91 | void modeChanged(QClipboard::Mode mode); |
92 | /*! |
93 | * \qmlsignal Clipboard::contentChanged() |
94 | */ |
95 | void contentChanged(); |
96 | |
97 | private Q_SLOTS: |
98 | void clipboardChanged(QClipboard::Mode m); |
99 | |
100 | private: |
101 | QClipboard *m_clipboard; |
102 | QClipboard::Mode m_mode; |
103 | }; |
104 | |
105 | #endif |
106 | |