diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2019-07-22 02:38:44 +0200 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2019-07-22 02:38:44 +0200 |
commit | cefe5fe71945c89b7b65c6ed2cb127a404cf62f5 (patch) | |
tree | 64bb6b26deb0a65777e53ae04a52152a9cae9e33 /src/dialogs/PreviewUploadOverlay.cpp | |
parent | Actually set attributes before starting the app (diff) | |
download | nheko-cefe5fe71945c89b7b65c6ed2cb127a404cf62f5.tar.xz |
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.
Diffstat (limited to 'src/dialogs/PreviewUploadOverlay.cpp')
-rw-r--r-- | src/dialogs/PreviewUploadOverlay.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
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 @@ -135,6 +135,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) { auto const &split = mime.split('/'); |