mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-26 04:58:49 +03:00
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.
This commit is contained in:
parent
512db8c6ff
commit
cefe5fe719
4 changed files with 27 additions and 6 deletions
|
@ -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<QImage>(source->imageData());
|
||||
previewDialog_.setPreview(img, image.front());
|
||||
} else if (!audio.empty()) {
|
||||
showPreview(source, audio);
|
||||
} else if (!video.empty()) {
|
||||
|
|
|
@ -34,10 +34,6 @@
|
|||
#include "popups/ReplyPopup.h"
|
||||
#include "popups/SuggestionsPopup.h"
|
||||
|
||||
namespace dialogs {
|
||||
class PreviewUploadOverlay;
|
||||
}
|
||||
|
||||
struct SearchResult;
|
||||
|
||||
class FlatButton;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <QImage>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QPixmap>
|
||||
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue