From c4b788917f9db8674fabf23b3972179b745b7700 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Mon, 27 Sep 2021 23:19:43 +0200 Subject: [PATCH] Fixes for pasting images, especially under windows where the image mime type detection doesn't work as expected --- src/timeline/InputBar.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index f0c38c84..c83bb19c 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -45,10 +45,8 @@ InputBar::paste(bool fromMouse) { const QMimeData *md = nullptr; - if (fromMouse) { - if (QGuiApplication::clipboard()->supportsSelection()) { - md = QGuiApplication::clipboard()->mimeData(QClipboard::Selection); - } + if (fromMouse && QGuiApplication::clipboard()->supportsSelection()) { + md = QGuiApplication::clipboard()->mimeData(QClipboard::Selection); } else { md = QGuiApplication::clipboard()->mimeData(QClipboard::Clipboard); } @@ -69,7 +67,7 @@ InputBar::insertMimeData(const QMimeData *md) const auto audio = formats.filter("audio/", Qt::CaseInsensitive); const auto video = formats.filter("video/", Qt::CaseInsensitive); - if (!image.empty() && md->hasImage()) { + if (md->hasImage()) { showPreview(*md, "", image); } else if (!audio.empty()) { showPreview(*md, "", audio); @@ -653,9 +651,15 @@ InputBar::showPreview(const QMimeData &source, QString path, const QStringList & new dialogs::PreviewUploadOverlay(ChatPage::instance()); previewDialog_->setAttribute(Qt::WA_DeleteOnClose); - if (source.hasImage()) - previewDialog_->setPreview(qvariant_cast(source.imageData()), formats.front()); - else if (!path.isEmpty()) + if (source.hasImage()) { + if (formats.size() && formats.front().startsWith("image/")) { + // known format, keep as-is + previewDialog_->setPreview(qvariant_cast(source.imageData()), formats.front()); + } else { + // unknown image format, default to image/png + previewDialog_->setPreview(qvariant_cast(source.imageData()), "image/png"); + } + } else if (!path.isEmpty()) previewDialog_->setPreview(path); else if (!formats.isEmpty()) { auto mime = formats.first();