File indexing completed on 2024-05-19 15:09:22
0001 /* 0002 SPDX-FileCopyrightText: 2015 Aleix Pol Gonzalez <aleixpol@kde.org> 0003 0004 SPDX-License-Identifier: MIT 0005 */ 0006 0007 #ifndef MIMEDATAWRAPPER_H 0008 #define MIMEDATAWRAPPER_H 0009 0010 #include <QJsonArray> 0011 #include <QObject> 0012 #include <QString> 0013 0014 class QMimeData; 0015 class QObject; 0016 /** 0017 * Exposes a const QMimeData instance 0018 * 0019 * In contrast to DeclarativeMimeData, doesn't create a copy of the QMimeData instance 0020 */ 0021 class MimeDataWrapper : public QObject 0022 { 0023 Q_OBJECT 0024 0025 /** 0026 * A plain text (MIME type text/plain) representation of the data. 0027 */ 0028 Q_PROPERTY(QString text READ text CONSTANT) 0029 0030 /** 0031 * A string if the data stored in the object is HTML (MIME type text/html); otherwise returns an empty string. 0032 */ 0033 Q_PROPERTY(QString html READ html CONSTANT) 0034 0035 /** 0036 * Url contained in the mimedata 0037 */ 0038 Q_PROPERTY(QUrl url READ url CONSTANT) 0039 0040 /** 0041 * A list of URLs contained within the MIME data object. 0042 * URLs correspond to the MIME type text/uri-list. 0043 */ 0044 Q_PROPERTY(QJsonArray urls READ urls CONSTANT) 0045 0046 /** 0047 * A color if the data stored in the object represents a color (MIME type application/x-color); otherwise QVariant(). 0048 */ 0049 Q_PROPERTY(QVariant color READ color CONSTANT) 0050 0051 /** 0052 * The graphical item on the scene that started the drag event. It may be null. 0053 */ 0054 Q_PROPERTY(QVariant source READ source CONSTANT) 0055 0056 /** 0057 * Mimetypes provided by the mime data instance 0058 * 0059 * @sa QMimeData::formats 0060 */ 0061 Q_PROPERTY(QStringList formats READ formats CONSTANT) 0062 0063 /** 0064 * @sa QMimeData::hasUrls 0065 */ 0066 Q_PROPERTY(bool hasUrls READ hasUrls CONSTANT) 0067 0068 /** 0069 * @returns the wrapped object 0070 */ 0071 Q_PROPERTY(QMimeData *mimeData READ mimeData CONSTANT) 0072 0073 public: 0074 MimeDataWrapper(const QMimeData *data, QObject *parent); 0075 0076 QString text() const; 0077 QString html() const; 0078 QUrl url() const; 0079 QJsonArray urls() const; 0080 bool hasUrls() const; 0081 QVariant color() const; 0082 QStringList formats() const; 0083 QVariant source() const; 0084 QMimeData *mimeData() const; 0085 0086 Q_INVOKABLE QByteArray getDataAsByteArray(const QString &format); 0087 0088 private: 0089 const QMimeData *m_data; 0090 }; 0091 0092 #endif