support url lists as well

TODO: the DeclarativeMimeData object shouldn't be a mimedata itself, but a container object. in this way it will be possible to reimplement all the methods, also non virtuals
This commit is contained in:
Marco Martin 2011-12-15 19:51:38 +01:00
parent 32b9547634
commit 2c7e559f04
2 changed files with 29 additions and 5 deletions

View File

@ -68,7 +68,7 @@ DeclarativeMimeData::DeclarativeMimeData(const QMimeData* copy)
QUrl DeclarativeMimeData::url() const
{
if ( this->hasUrls() && !this->urls().isEmpty()) {
return urls().first();
return QMimeData::urls().first();
}
return QUrl();
}
@ -79,10 +79,29 @@ void DeclarativeMimeData::setUrl(const QUrl &url)
QList<QUrl> urlList;
urlList.append(url);
setUrls(urlList);
QMimeData::setUrls(urlList);
emit urlChanged();
}
QVariantList DeclarativeMimeData::urls() const
{
QVariantList varUrls;
foreach (const QUrl &url, QMimeData::urls()) {
varUrls << url;
}
return varUrls;
}
void DeclarativeMimeData::setUrls(const QVariantList &urls)
{
QList<QUrl> urlList;
foreach (const QVariant &varUrl, urls) {
urlList << varUrl.value<QUrl>();
}
QMimeData::setUrls(urlList);
emit urlsChanged();
}
// color
QColor DeclarativeMimeData::color() const
{

View File

@ -35,7 +35,8 @@ class DeclarativeMimeData : public QMimeData
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
Q_PROPERTY(QString html READ html WRITE setHtml NOTIFY htmlChanged)
Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) //TODO: use QDeclarativeListProperty<QUrls> to return the whole list instead of only the first url
Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
Q_PROPERTY(QVariantList urls READ urls WRITE setUrls NOTIFY urlsChanged)
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
Q_PROPERTY(QDeclarativeItem* source READ source WRITE setSource NOTIFY sourceChanged)
//TODO: Image property
@ -47,12 +48,16 @@ public:
QUrl url() const;
void setUrl(const QUrl &url);
QVariantList urls() const;
void setUrls(const QVariantList &urls);
QColor color() const;
void setColor(const QColor &color);
QDeclarativeItem* source() const;
void setSource(QDeclarativeItem* source);
/*
QString text() const; //TODO: Reimplement this to issue the onChanged signals
void setText(const QString &text);
@ -64,12 +69,12 @@ signals:
void textChanged(); //FIXME not being used
void htmlChanged(); //FIXME not being used
void urlChanged();
void urlsChanged();
void colorChanged();
void sourceChanged();
private:
QDeclarativeItem* m_source;
QDeclarativeItem* m_source;
};
#endif // DECLARATIVEMIMEDATA_H