mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-26 21:18:48 +03:00
Fixes for pasting images, especially under windows where the image mime type detection doesn't work as expected
This commit is contained in:
parent
6941c3d3d7
commit
c4b788917f
1 changed files with 12 additions and 8 deletions
|
@ -45,10 +45,8 @@ InputBar::paste(bool fromMouse)
|
||||||
{
|
{
|
||||||
const QMimeData *md = nullptr;
|
const QMimeData *md = nullptr;
|
||||||
|
|
||||||
if (fromMouse) {
|
if (fromMouse && QGuiApplication::clipboard()->supportsSelection()) {
|
||||||
if (QGuiApplication::clipboard()->supportsSelection()) {
|
|
||||||
md = QGuiApplication::clipboard()->mimeData(QClipboard::Selection);
|
md = QGuiApplication::clipboard()->mimeData(QClipboard::Selection);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
md = QGuiApplication::clipboard()->mimeData(QClipboard::Clipboard);
|
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 audio = formats.filter("audio/", Qt::CaseInsensitive);
|
||||||
const auto video = formats.filter("video/", Qt::CaseInsensitive);
|
const auto video = formats.filter("video/", Qt::CaseInsensitive);
|
||||||
|
|
||||||
if (!image.empty() && md->hasImage()) {
|
if (md->hasImage()) {
|
||||||
showPreview(*md, "", image);
|
showPreview(*md, "", image);
|
||||||
} else if (!audio.empty()) {
|
} else if (!audio.empty()) {
|
||||||
showPreview(*md, "", audio);
|
showPreview(*md, "", audio);
|
||||||
|
@ -653,9 +651,15 @@ InputBar::showPreview(const QMimeData &source, QString path, const QStringList &
|
||||||
new dialogs::PreviewUploadOverlay(ChatPage::instance());
|
new dialogs::PreviewUploadOverlay(ChatPage::instance());
|
||||||
previewDialog_->setAttribute(Qt::WA_DeleteOnClose);
|
previewDialog_->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
if (source.hasImage())
|
if (source.hasImage()) {
|
||||||
|
if (formats.size() && formats.front().startsWith("image/")) {
|
||||||
|
// known format, keep as-is
|
||||||
previewDialog_->setPreview(qvariant_cast<QImage>(source.imageData()), formats.front());
|
previewDialog_->setPreview(qvariant_cast<QImage>(source.imageData()), formats.front());
|
||||||
else if (!path.isEmpty())
|
} else {
|
||||||
|
// unknown image format, default to image/png
|
||||||
|
previewDialog_->setPreview(qvariant_cast<QImage>(source.imageData()), "image/png");
|
||||||
|
}
|
||||||
|
} else if (!path.isEmpty())
|
||||||
previewDialog_->setPreview(path);
|
previewDialog_->setPreview(path);
|
||||||
else if (!formats.isEmpty()) {
|
else if (!formats.isEmpty()) {
|
||||||
auto mime = formats.first();
|
auto mime = formats.first();
|
||||||
|
|
Loading…
Reference in a new issue