Improve clipboard types support
Try to be more accurate about the translations mimetype <-> variant.
This commit is contained in:
parent
7bdee8dbd7
commit
db3dd7a994
@ -57,10 +57,20 @@ QClipboard::Mode Clipboard::mode() const
|
|||||||
QVariant Clipboard::contentFormat(const QString &format) const
|
QVariant Clipboard::contentFormat(const QString &format) const
|
||||||
{
|
{
|
||||||
const QMimeData* data = m_clipboard->mimeData(m_mode);
|
const QMimeData* data = m_clipboard->mimeData(m_mode);
|
||||||
|
QVariant ret;
|
||||||
|
if(format == QStringLiteral("text/uri-list")) {
|
||||||
|
QVariantList retList;
|
||||||
|
foreach(const QUrl& url, data->urls())
|
||||||
|
retList += url;
|
||||||
|
ret = retList;
|
||||||
|
} else if(format.startsWith(QStringLiteral("text/"))) {
|
||||||
|
ret = data->text();
|
||||||
|
} else if(format.startsWith(QStringLiteral("image/"))) {
|
||||||
|
ret = data->imageData();
|
||||||
|
} else
|
||||||
|
ret = data->data(format.isEmpty() ? data->formats().first(): format);
|
||||||
|
|
||||||
QByteArray variant = data->data(format.isEmpty() ? data->formats().first(): format);
|
return ret;
|
||||||
|
|
||||||
return variant;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant Clipboard::content() const
|
QVariant Clipboard::content() const
|
||||||
@ -104,9 +114,8 @@ void Clipboard::setContent(const QVariant &content)
|
|||||||
if (content.canConvert(QVariant::String)) {
|
if (content.canConvert(QVariant::String)) {
|
||||||
mimeData->setText(content.toString());
|
mimeData->setText(content.toString());
|
||||||
} else {
|
} else {
|
||||||
delete mimeData;
|
mimeData->setData("application/octet-stream", content.toByteArray());
|
||||||
mimeData = nullptr;
|
qWarning() << "Couldn't figure out the content type, storing as application/octet-stream";
|
||||||
qWarning() << "Couldn't manage to set the content to the clipboard";
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user