1 | /* |
2 | SPDX-FileCopyrightText: 2015 Aleix Pol Gonzalez <aleixpol@kde.org> |
3 | |
4 | SPDX-License-Identifier: MIT |
5 | */ |
6 | |
7 | #ifndef MIMEDATAWRAPPER_H |
8 | #define MIMEDATAWRAPPER_H |
9 | |
10 | #include <QJsonArray> |
11 | #include <QObject> |
12 | #include <QString> |
13 | |
14 | class QMimeData; |
15 | class QObject; |
16 | /** |
17 | * Exposes a const QMimeData instance |
18 | * |
19 | * In contrast to DeclarativeMimeData, doesn't create a copy of the QMimeData instance |
20 | */ |
21 | class MimeDataWrapper : public QObject |
22 | { |
23 | Q_OBJECT |
24 | |
25 | /** |
26 | * A plain text (MIME type text/plain) representation of the data. |
27 | */ |
28 | Q_PROPERTY(QString text READ text CONSTANT) |
29 | |
30 | /** |
31 | * A string if the data stored in the object is HTML (MIME type text/html); otherwise returns an empty string. |
32 | */ |
33 | Q_PROPERTY(QString html READ html CONSTANT) |
34 | |
35 | /** |
36 | * Url contained in the mimedata |
37 | */ |
38 | Q_PROPERTY(QUrl url READ url CONSTANT) |
39 | |
40 | /** |
41 | * A list of URLs contained within the MIME data object. |
42 | * URLs correspond to the MIME type text/uri-list. |
43 | */ |
44 | Q_PROPERTY(QJsonArray urls READ urls CONSTANT) |
45 | |
46 | /** |
47 | * A color if the data stored in the object represents a color (MIME type application/x-color); otherwise QVariant(). |
48 | */ |
49 | Q_PROPERTY(QVariant color READ color CONSTANT) |
50 | |
51 | /** |
52 | * The graphical item on the scene that started the drag event. It may be null. |
53 | */ |
54 | Q_PROPERTY(QVariant source READ source CONSTANT) |
55 | |
56 | /** |
57 | * Mimetypes provided by the mime data instance |
58 | * |
59 | * @sa QMimeData::formats |
60 | */ |
61 | Q_PROPERTY(QStringList formats READ formats CONSTANT) |
62 | |
63 | /** |
64 | * @sa QMimeData::hasUrls |
65 | */ |
66 | Q_PROPERTY(bool hasUrls READ hasUrls CONSTANT) |
67 | |
68 | /** |
69 | * @returns the wrapped object |
70 | */ |
71 | Q_PROPERTY(QMimeData *mimeData READ mimeData CONSTANT) |
72 | |
73 | public: |
74 | MimeDataWrapper(const QMimeData *data, QObject *parent); |
75 | |
76 | QString text() const; |
77 | QString html() const; |
78 | QUrl url() const; |
79 | QJsonArray urls() const; |
80 | bool hasUrls() const; |
81 | QVariant color() const; |
82 | QStringList formats() const; |
83 | QVariant source() const; |
84 | QMimeData *mimeData() const; |
85 | |
86 | Q_INVOKABLE QByteArray getDataAsByteArray(const QString &format); |
87 | |
88 | private: |
89 | const QMimeData *m_data; |
90 | }; |
91 | |
92 | #endif |
93 | |