Support pasting image/svg+xml format straight from supporting applications

pull/736/head
Thulinma 3 years ago
parent c4b788917f
commit 94441e68fd
  1. 7
      src/dialogs/PreviewUploadOverlay.cpp
  2. 13
      src/timeline/InputBar.cpp

@ -158,6 +158,8 @@ PreviewUploadOverlay::setPreview(const QImage &src, const QString &mime)
void
PreviewUploadOverlay::setPreview(const QByteArray data, const QString &mime)
{
nhlog::ui()->info("Pasting {} bytes of data, mimetype {}", data.size(), mime.toStdString());
auto const &split = mime.split('/');
auto const &type = split[1];
@ -166,6 +168,11 @@ PreviewUploadOverlay::setPreview(const QByteArray data, const QString &mime)
filePath_ = "clipboard." + type;
isImage_ = false;
if (mime == "image/svg+xml") {
isImage_ = true;
image_.loadFromData(data_, mediaType_.toStdString().c_str());
}
setLabels(type, mime, data_.size());
init();
}

@ -68,7 +68,11 @@ InputBar::insertMimeData(const QMimeData *md)
const auto video = formats.filter("video/", Qt::CaseInsensitive);
if (md->hasImage()) {
if (formats.contains("image/svg+xml", Qt::CaseInsensitive)) {
showPreview(*md, "", QStringList("image/svg+xml"));
} else {
showPreview(*md, "", image);
}
} else if (!audio.empty()) {
showPreview(*md, "", audio);
} else if (!video.empty()) {
@ -651,7 +655,8 @@ InputBar::showPreview(const QMimeData &source, QString path, const QStringList &
new dialogs::PreviewUploadOverlay(ChatPage::instance());
previewDialog_->setAttribute(Qt::WA_DeleteOnClose);
if (source.hasImage()) {
// Force SVG to _not_ be handled as an image, but as raw data
if (source.hasImage() && (!formats.size() || formats.front() != "image/svg+xml")) {
if (formats.size() && formats.front().startsWith("image/")) {
// known format, keep as-is
previewDialog_->setPreview(qvariant_cast<QImage>(source.imageData()), formats.front());
@ -679,6 +684,12 @@ InputBar::showPreview(const QMimeData &source, QString path, const QStringList &
&dialogs::PreviewUploadOverlay::confirmUpload,
this,
[this](const QByteArray data, const QString &mime, const QString &fn) {
if (!data.size()) {
nhlog::ui()->warn("Attempted to upload zero-byte file?! Mimetype {}, filename {}",
mime.toStdString(),
fn.toStdString());
return;
}
setUploading(true);
setText("");

Loading…
Cancel
Save