clipboard.cpp 1.29 KB
Newer Older
Rodney's avatar
Rodney committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
 * Copyright 2012 Canonical Ltd.
 * Copyright 2018 Rodney Dawes
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include "clipboard.h"

#include <QGuiApplication>
#include <QMimeData>
#include <QMimeDatabase>


namespace ergo
{

Rodney's avatar
Rodney committed
27
//! @cond
Rodney's avatar
Rodney committed
28
29
30
31
32
Clipboard::Clipboard(QObject *parent):
    QObject(parent)
{
    m_clipboard = QGuiApplication::clipboard();
}
Rodney's avatar
Rodney committed
33
//! @endcond
Rodney's avatar
Rodney committed
34

Rodney's avatar
Rodney committed
35
36
37
/*! Post some data to the system clipboard
 *
 */
Rodney's avatar
Rodney committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
void Clipboard::pushData(const QVariant& data)
{
    if (!data.isValid()) {
        return;
    }

    QMimeDatabase mime;
    auto bytes = data.toByteArray();
    auto type = mime.mimeTypeForData(bytes);
    auto mimeData = new QMimeData;
    mimeData->setData(type.name(), bytes);
    m_clipboard->setMimeData(mimeData);
}

} // namespace ergo