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
14class ClipboardPrivate;
15
16/**
17 * @brief Wrapper for QClipboard
18 *
19 * Offers a simple wrapper to interact with QClipboard from QtQuick.
20 *
21 * ```
22 * import QtQuick
23 * import org.kde.kquickcontrolsaddons as KQuickControlsAddons
24 * Text {
25 * text: "lorem ipsum"
26 *
27 * KQuickControlsAddons.Clipboard { id: clipboard }
28 *
29 * MouseArea {
30 * anchors.fill: parent
31 * acceptedButtons: Qt.LeftButton | Qt.RightButton
32 * onClicked: clipboard.content = parent.text
33 * }
34 * }
35 * ```
36 */
37class Clipboard : public QObject
38{
39 Q_OBJECT
40 QML_ELEMENT
41 /**
42 * Controls the state this object will be monitoring and extracting its contents from.
43 */
44 Q_PROPERTY(QClipboard::Mode mode READ mode WRITE setMode NOTIFY modeChanged)
45
46 /**
47 * Provides the contents currently in the clipboard and lets modify them.
48 */
49 Q_PROPERTY(QVariant content READ content WRITE setContent NOTIFY contentChanged)
50
51 /**
52 * Figure out the nature of the contents in the clipboard as mimetype strings.
53 */
54 Q_PROPERTY(QStringList formats READ formats NOTIFY contentChanged)
55
56public:
57 explicit Clipboard(QObject *parent = nullptr);
58
59 QClipboard::Mode mode() const;
60 void setMode(QClipboard::Mode mode);
61
62 /**
63 * @param format mimetype string
64 * @return Output based on the mimetype. This may be a list of URLs, text, image data, or use QMimeData::data
65 */
66 Q_SCRIPTABLE QVariant contentFormat(const QString &format) const;
67 QVariant content() const;
68 void setContent(const QVariant &content);
69
70 QStringList formats() const;
71
72 /** @see QClipboard::clear() */
73 Q_SCRIPTABLE void clear();
74
75Q_SIGNALS:
76 void modeChanged(QClipboard::Mode mode);
77 void contentChanged();
78
79private Q_SLOTS:
80 void clipboardChanged(QClipboard::Mode m);
81
82private:
83 QClipboard *m_clipboard;
84 QClipboard::Mode m_mode;
85};
86
87#endif
88

source code of kdeclarative/src/qmlcontrols/kquickcontrolsaddons/clipboard.h