From 512db8c6ff55819e421761c4001f4a91ff117946 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 22 Jul 2019 00:03:12 +0200 Subject: [PATCH 1/2] Actually set attributes before starting the app fixes "Attribute Qt::AA_EnableHighDpiScaling must be set before QCoreApplication is created." --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index bd7560da..60bb6c76 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -118,12 +118,12 @@ main(int argc, char *argv[]) } #endif - QApplication app(argc, argv); QCoreApplication::setApplicationName("nheko"); QCoreApplication::setApplicationVersion(nheko::version); QCoreApplication::setOrganizationName("nheko"); QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QApplication app(argc, argv); QCommandLineParser parser; parser.addHelpOption(); From cefe5fe71945c89b7b65c6ed2cb127a404cf62f5 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 22 Jul 2019 02:38:44 +0200 Subject: [PATCH 2/2] Fix copy and pasting image from clipboard If the QMimeData contains an image, it actually has a mime type of application/x-qt-image. At least in some cases accessing the image/* data returns a 0 length array. Accessing the data via ->imageData works however. So we use that as our accessor and pass it to the preview dialog. --- src/TextInputWidget.cpp | 5 +++-- src/TextInputWidget.h | 4 ---- src/dialogs/PreviewUploadOverlay.cpp | 22 ++++++++++++++++++++++ src/dialogs/PreviewUploadOverlay.h | 2 ++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/TextInputWidget.cpp b/src/TextInputWidget.cpp index 1ae26c2d..f723c01a 100644 --- a/src/TextInputWidget.cpp +++ b/src/TextInputWidget.cpp @@ -306,8 +306,9 @@ FilteredTextEdit::insertFromMimeData(const QMimeData *source) const auto audio = formats.filter("audio/", Qt::CaseInsensitive); const auto video = formats.filter("video/", Qt::CaseInsensitive); - if (!image.empty()) { - showPreview(source, image); + if (source->hasImage()) { + QImage img = qvariant_cast(source->imageData()); + previewDialog_.setPreview(img, image.front()); } else if (!audio.empty()) { showPreview(source, audio); } else if (!video.empty()) { diff --git a/src/TextInputWidget.h b/src/TextInputWidget.h index 4a726364..71f794d1 100644 --- a/src/TextInputWidget.h +++ b/src/TextInputWidget.h @@ -34,10 +34,6 @@ #include "popups/ReplyPopup.h" #include "popups/SuggestionsPopup.h" -namespace dialogs { -class PreviewUploadOverlay; -} - struct SearchResult; class FlatButton; diff --git a/src/dialogs/PreviewUploadOverlay.cpp b/src/dialogs/PreviewUploadOverlay.cpp index c404799e..31d01214 100644 --- a/src/dialogs/PreviewUploadOverlay.cpp +++ b/src/dialogs/PreviewUploadOverlay.cpp @@ -134,6 +134,28 @@ PreviewUploadOverlay::setLabels(const QString &type, const QString &mime, uint64 } } +void +PreviewUploadOverlay::setPreview(const QImage &src, const QString &mime) +{ + auto const &split = mime.split('/'); + auto const &type = split[1]; + + QBuffer buffer(&data_); + buffer.open(QIODevice::WriteOnly); + if (src.save(&buffer, type.toStdString().c_str())) + titleLabel_.setText(QString{tr(DEFAULT)}.arg("image")); + else + titleLabel_.setText(QString{tr(ERR_MSG)}.arg(type)); + + mediaType_ = split[0]; + filePath_ = "clipboard." + type; + image_.convertFromImage(src); + isImage_ = true; + + titleLabel_.setText(QString{tr(DEFAULT)}.arg("image")); + init(); +} + void PreviewUploadOverlay::setPreview(const QByteArray data, const QString &mime) { diff --git a/src/dialogs/PreviewUploadOverlay.h b/src/dialogs/PreviewUploadOverlay.h index 8099d9c2..11cd49bc 100644 --- a/src/dialogs/PreviewUploadOverlay.h +++ b/src/dialogs/PreviewUploadOverlay.h @@ -17,6 +17,7 @@ #pragma once +#include #include #include #include @@ -33,6 +34,7 @@ class PreviewUploadOverlay : public QWidget public: PreviewUploadOverlay(QWidget *parent = nullptr); + void setPreview(const QImage &src, const QString &mime); void setPreview(const QByteArray data, const QString &mime); void setPreview(const QString &path);