File indexing completed on 2024-05-19 15:09:22

0001 /*
0002     SPDX-FileCopyrightText: 2010 BetterInbox <contact@betterinbox.com>
0003     SPDX-FileContributor: Gregory Schlomoff <greg@betterinbox.com>
0004 
0005     SPDX-License-Identifier: MIT
0006 */
0007 
0008 #ifndef DECLARATIVEMIMEDATA_H
0009 #define DECLARATIVEMIMEDATA_H
0010 
0011 #include <QColor>
0012 #include <QJsonArray>
0013 #include <QMimeData>
0014 #include <QQuickItem>
0015 #include <QUrl>
0016 
0017 class DeclarativeMimeData : public QMimeData
0018 {
0019     Q_OBJECT
0020 
0021     /**
0022      * A plain text (MIME type text/plain) representation of the data.
0023      */
0024     Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
0025 
0026     /**
0027      * A string if the data stored in the object is HTML (MIME type text/html); otherwise returns an empty string.
0028      */
0029     Q_PROPERTY(QString html READ html WRITE setHtml NOTIFY htmlChanged)
0030 
0031     /**
0032      * Url contained in the mimedata
0033      */
0034     Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
0035 
0036     /**
0037      * A list of URLs contained within the MIME data object.
0038      * URLs correspond to the MIME type text/uri-list.
0039      */
0040     Q_PROPERTY(QJsonArray urls READ urls WRITE setUrls NOTIFY urlsChanged)
0041 
0042     /**
0043      * A color if the data stored in the object represents a color (MIME type application/x-color); otherwise QColor().
0044      */
0045     Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
0046 
0047     /**
0048      * The graphical item on the scene that started the drag event. It may be null.
0049      */
0050     Q_PROPERTY(QQuickItem *source READ source WRITE setSource NOTIFY sourceChanged)
0051 
0052     /** @see QMimeData::hasUrls */
0053     Q_PROPERTY(bool hasUrls READ hasUrls NOTIFY urlsChanged)
0054     // TODO: Image property
0055 
0056     /**
0057      * @sa QMimeData::formats
0058      */
0059     Q_PROPERTY(QStringList formats READ formats)
0060 public:
0061     DeclarativeMimeData();
0062     DeclarativeMimeData(const QMimeData *copy);
0063 
0064     QUrl url() const;
0065     void setUrl(const QUrl &url);
0066 
0067     QJsonArray urls() const;
0068     void setUrls(const QJsonArray &urls);
0069 
0070     QColor color() const;
0071     void setColor(const QColor &color);
0072     Q_INVOKABLE bool hasColor() const;
0073 
0074     Q_INVOKABLE void setData(const QString &mimeType, const QVariant &data);
0075 
0076     QQuickItem *source() const;
0077     void setSource(QQuickItem *source);
0078 
0079     Q_INVOKABLE QByteArray getDataAsByteArray(const QString &format);
0080 
0081     /*
0082     QString text() const;                //TODO: Reimplement this to issue the onChanged signals
0083     void setText(const QString &text);
0084     QString html() const;
0085     void setHtml(const QString &html);
0086     */
0087 
0088 Q_SIGNALS:
0089     void textChanged(); // FIXME not being used
0090     void htmlChanged(); // FIXME not being used
0091     void urlChanged();
0092     void urlsChanged();
0093     void colorChanged();
0094     void sourceChanged();
0095 
0096 private:
0097     QQuickItem *m_source;
0098 };
0099 
0100 #endif // DECLARATIVEMIMEDATA_H