KDeclarative

clipboard.h
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{
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
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
Wrapper for QClipboard.
Definition clipboard.h:38
Q_SCRIPTABLE void clear()
Definition clipboard.cpp:34
QStringList formats
Figure out the nature of the contents in the clipboard as mimetype strings.
Definition clipboard.h:54
QVariant content
Provides the contents currently in the clipboard and lets modify them.
Definition clipboard.h:49
QML_ELEMENTQClipboard::Mode mode
Controls the state this object will be monitoring and extracting its contents from.
Definition clipboard.h:44
Q_SCRIPTABLE QVariant contentFormat(const QString &format) const
Definition clipboard.cpp:44
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:16:59 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.