summary refs log tree commit diff
path: root/src/MxcImageProvider.cpp
diff options
context:
space:
mode:
authorDeepBlueV7.X <nicolas.werner@hotmail.de>2021-12-27 22:25:51 +0000
committerGitHub <noreply@github.com>2021-12-27 22:25:51 +0000
commitbca7309e5f0f40f0f2f6a6748ea4f95c3d3bed7b (patch)
tree8fb64c3b44d71466ee5d3678d9d33ec8b15e36ca /src/MxcImageProvider.cpp
parentUse body in alt text of custom emoji (diff)
parentMake custom emoticons twice as high as the font. (diff)
downloadnheko-bca7309e5f0f40f0f2f6a6748ea4f95c3d3bed7b.tar.xz
Merge pull request #858 from tastytea/inline-img-aa
Request inline images in the right size and anti-alias them
Diffstat (limited to 'src/MxcImageProvider.cpp')
-rw-r--r--src/MxcImageProvider.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/MxcImageProvider.cpp b/src/MxcImageProvider.cpp

index 4834c2fc..74b4bedc 100644 --- a/src/MxcImageProvider.cpp +++ b/src/MxcImageProvider.cpp
@@ -27,6 +27,7 @@ MxcImageProvider::requestImageResponse(const QString &id, const QSize &requested auto id_ = id; bool crop = true; double radius = 0; + auto size = requestedSize; auto queryStart = id.lastIndexOf('?'); if (queryStart != -1) { @@ -39,11 +40,14 @@ MxcImageProvider::requestImageResponse(const QString &id, const QSize &requested crop = false; } else if (b.startsWith("radius=")) { radius = b.mid(7).toDouble(); + } else if (b.startsWith("height=")) { + size.setHeight(b.mid(7).toInt()); + size.setWidth(0); } } } - return new MxcImageResponse(id_, crop, radius, requestedSize); + return new MxcImageResponse(id_, crop, radius, size); } void @@ -120,7 +124,12 @@ MxcImageProvider::download(const QString &id, if (fileInfo.exists()) { QImage image = utils::readImageFromFile(fileInfo.absoluteFilePath()); if (!image.isNull()) { - image = image.scaled(requestedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); + if (requestedSize.width() <= 0) { + image = image.scaledToHeight(requestedSize.height(), Qt::SmoothTransformation); + } else { + image = + image.scaled(requestedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); + } if (radius != 0) { image = clipRadius(std::move(image), radius); @@ -151,8 +160,13 @@ MxcImageProvider::download(const QString &id, auto data = QByteArray(res.data(), (int)res.size()); QImage image = utils::readImage(data); if (!image.isNull()) { - image = - image.scaled(requestedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); + if (requestedSize.width() <= 0) { + image = + image.scaledToHeight(requestedSize.height(), Qt::SmoothTransformation); + } else { + image = + image.scaled(requestedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); + } if (radius != 0) { image = clipRadius(std::move(image), radius);