1/*
2 SPDX-FileCopyrightText: 2015 Aleix Pol Gonzalez <aleixpol@kde.org>
3
4 SPDX-License-Identifier: MIT
5*/
6
7#include "MimeDataWrapper.h"
8#include <QMimeData>
9#include <QUrl>
10
11MimeDataWrapper::MimeDataWrapper(const QMimeData *data, QObject *parent)
12 : QObject(parent)
13 , m_data(data)
14{
15}
16
17QString MimeDataWrapper::text() const
18{
19 return m_data->text();
20}
21
22QString MimeDataWrapper::html() const
23{
24 return m_data->html();
25}
26
27QUrl MimeDataWrapper::url() const
28{
29 if (m_data->hasUrls() && !m_data->urls().isEmpty()) {
30 return m_data->urls().constFirst();
31 }
32 return QUrl();
33}
34
35bool MimeDataWrapper::hasUrls() const
36{
37 return m_data->hasUrls();
38}
39
40QJsonArray MimeDataWrapper::urls() const
41{
42 QJsonArray varUrls;
43 const auto urls = m_data->urls();
44 for (const QUrl &url : urls) {
45 varUrls.append(value: url.toString());
46 }
47 return varUrls;
48}
49
50QVariant MimeDataWrapper::color() const
51{
52 if (m_data->hasColor()) {
53 return m_data->colorData();
54 } else {
55 return QVariant();
56 }
57}
58
59QStringList MimeDataWrapper::formats() const
60{
61 return m_data->formats();
62}
63
64QByteArray MimeDataWrapper::getDataAsByteArray(const QString &format)
65{
66 return m_data->data(mimetype: format);
67}
68
69QVariant MimeDataWrapper::source() const
70{
71 // In case it comes from a DeclarativeMimeData
72 return m_data->property(name: "source");
73}
74
75QMimeData *MimeDataWrapper::mimeData() const
76{
77 return const_cast<QMimeData *>(m_data);
78}
79
80#include "moc_MimeDataWrapper.cpp"
81

source code of kdeclarative/src/qmlcontrols/draganddrop/MimeDataWrapper.cpp