From 2c5f0283e2f8569b4326118268519fba3c807b15 Mon Sep 17 00:00:00 2001 From: blank X Date: Sat, 29 Jan 2022 10:46:06 +0000 Subject: [PATCH] Fix profile picture rounding inconsistencies (#304) * Respect round settings in invite link info box Fixes #297 * Respect round settings in the call window --- Telegram/SourceFiles/api/api_chat_invite.cpp | 13 +++++++-- Telegram/SourceFiles/calls/calls_userpic.cpp | 30 +++++++++++++++----- Telegram/SourceFiles/ui/image/image.cpp | 6 ++-- Telegram/SourceFiles/ui/image/image.h | 4 ++- 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/Telegram/SourceFiles/api/api_chat_invite.cpp b/Telegram/SourceFiles/api/api_chat_invite.cpp index 90a5a5175..b06bab478 100644 --- a/Telegram/SourceFiles/api/api_chat_invite.cpp +++ b/Telegram/SourceFiles/api/api_chat_invite.cpp @@ -252,12 +252,19 @@ void ConfirmInviteBox::paintEvent(QPaintEvent *e) { if (_photo) { if (const auto image = _photo->image(Data::PhotoSize::Small)) { + auto source = [=] { + const auto size = st::confirmInvitePhotoSize; + switch (cUserpicCornersType()) { + case 0: return image->pixRounded(size, size, ImageRoundRadius::None); + case 1: return image->pixRounded(size, size, ImageRoundRadius::Small); + case 2: return image->pixRounded(size, size, ImageRoundRadius::Large); + default: return image->pixCircled(size, size); + } + }(); p.drawPixmap( (width() - st::confirmInvitePhotoSize) / 2, st::confirmInvitePhotoTop, - image->pixCircled( - st::confirmInvitePhotoSize, - st::confirmInvitePhotoSize)); + source); } } else if (_photoEmpty) { _photoEmpty->paint( diff --git a/Telegram/SourceFiles/calls/calls_userpic.cpp b/Telegram/SourceFiles/calls/calls_userpic.cpp index dd1d71a3a..7a9b466ab 100644 --- a/Telegram/SourceFiles/calls/calls_userpic.cpp +++ b/Telegram/SourceFiles/calls/calls_userpic.cpp @@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_photo_media.h" #include "data/data_file_origin.h" #include "ui/empty_userpic.h" +#include "ui/rect_part.h" #include "apiwrap.h" // requestFullPeer. #include "styles/style_calls.h" #include "styles/style_widgets.h" @@ -193,13 +194,28 @@ void Userpic::createCache(Image *image) { height = qMax((height * real) / width, 1); width = real; } - _userPhoto = image->pixNoCache( - width, - height, - options, - size, - size); - _userPhoto.setDevicePixelRatio(cRetinaFactor()); + const auto callRounded = [=](const ImageRoundRadius radius) { + return image->pixRounded(width, height, radius, RectPart::AllCorners, size, size); + }; + switch (cUserpicCornersType()) { + case 0: + _userPhoto = callRounded(ImageRoundRadius::None); + break; + case 1: + _userPhoto = callRounded(ImageRoundRadius::Small); + break; + case 2: + _userPhoto = callRounded(ImageRoundRadius::Large); + break; + default: + _userPhoto = image->pixNoCache( + width, + height, + options, + size, + size); + _userPhoto.setDevicePixelRatio(cRetinaFactor()); + } } else { auto filled = QImage(QSize(real, real), QImage::Format_ARGB32_Premultiplied); filled.setDevicePixelRatio(cRetinaFactor()); diff --git a/Telegram/SourceFiles/ui/image/image.cpp b/Telegram/SourceFiles/ui/image/image.cpp index ab1c6664b..9747fae9f 100644 --- a/Telegram/SourceFiles/ui/image/image.cpp +++ b/Telegram/SourceFiles/ui/image/image.cpp @@ -352,7 +352,9 @@ const QPixmap &Image::pixRounded( int w, int h, ImageRoundRadius radius, - RectParts corners) const { + RectParts corners, + int outerw, + int outerh) const { if (w <= 0 || !width() || !height()) { w = width(); } else { @@ -376,7 +378,7 @@ const QPixmap &Image::pixRounded( auto k = PixKey(w, h, options); auto i = _cache.find(k); if (i == _cache.cend()) { - auto p = pixNoCache(w, h, options); + auto p = pixNoCache(w, h, options, outerw, outerh); p.setDevicePixelRatio(cRetinaFactor()); i = _cache.emplace_or_assign(k, p).first; } diff --git a/Telegram/SourceFiles/ui/image/image.h b/Telegram/SourceFiles/ui/image/image.h index 725d69e1a..6b66e641d 100644 --- a/Telegram/SourceFiles/ui/image/image.h +++ b/Telegram/SourceFiles/ui/image/image.h @@ -49,7 +49,9 @@ public: int w = 0, int h = 0, ImageRoundRadius radius = ImageRoundRadius::None, - RectParts corners = RectPart::AllCorners) const; + RectParts corners = RectPart::AllCorners, + int outerw = -1, + int outerh = -1) const; [[nodiscard]] const QPixmap &pixBlurred(int w = 0, int h = 0) const; [[nodiscard]] const QPixmap &pixColored(style::color add, int w = 0, int h = 0) const; [[nodiscard]] const QPixmap &pixBlurredColored(