1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3#include "qplatformclipboard.h"
4
5#ifndef QT_NO_CLIPBOARD
6
7#include <QtGui/private/qguiapplication_p.h>
8#include <QtCore/qmimedata.h>
9
10QT_BEGIN_NAMESPACE
11
12class QClipboardData
13{
14public:
15 QClipboardData();
16 ~QClipboardData();
17
18 void setSource(QMimeData* s)
19 {
20 if (s == src)
21 return;
22 delete src;
23 src = s;
24 }
25 QMimeData* source()
26 { return src; }
27
28private:
29 QMimeData* src;
30};
31
32QClipboardData::QClipboardData()
33{
34 src = nullptr;
35}
36
37QClipboardData::~QClipboardData()
38{
39 delete src;
40}
41
42Q_GLOBAL_STATIC(QClipboardData,q_clipboardData);
43
44/*!
45 \class QPlatformClipboard
46 \since 5.0
47 \internal
48 \preliminary
49 \ingroup qpa
50
51 \brief The QPlatformClipboard class provides an abstraction for the system clipboard.
52 */
53
54QPlatformClipboard::~QPlatformClipboard()
55{
56
57}
58
59QMimeData *QPlatformClipboard::mimeData(QClipboard::Mode mode)
60{
61 //we know its clipboard
62 Q_UNUSED(mode);
63 return q_clipboardData()->source();
64}
65
66void QPlatformClipboard::setMimeData(QMimeData *data, QClipboard::Mode mode)
67{
68 //we know its clipboard
69 Q_UNUSED(mode);
70 q_clipboardData()->setSource(data);
71
72 emitChanged(mode);
73}
74
75bool QPlatformClipboard::supportsMode(QClipboard::Mode mode) const
76{
77 return mode == QClipboard::Clipboard;
78}
79
80bool QPlatformClipboard::ownsMode(QClipboard::Mode mode) const
81{
82 Q_UNUSED(mode);
83 return false;
84}
85
86void QPlatformClipboard::emitChanged(QClipboard::Mode mode)
87{
88 if (!QGuiApplicationPrivate::is_app_closing) // QTBUG-39317, prevent emission when closing down.
89 QGuiApplication::clipboard()->emitChanged(mode);
90}
91
92QT_END_NAMESPACE
93
94#endif //QT_NO_CLIPBOARD
95

source code of qtbase/src/gui/kernel/qplatformclipboard.cpp