summary refs log tree commit diff
path: root/src/ui
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2020-02-28 03:20:27 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2020-02-28 03:20:27 +0100
commit9efa001bcfefe1dcd285a5a60dcdbf9ddd79a066 (patch)
tree188e6fdc2e1d1081c6167aced87f40b9111d43fa /src/ui
parentRevert change from TextEdit to TextArea (diff)
downloadnheko-9efa001bcfefe1dcd285a5a60dcdbf9ddd79a066.tar.xz
Fix high dpi scaling of avatars
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/Avatar.cpp40
-rw-r--r--src/ui/Avatar.h1
2 files changed, 31 insertions, 10 deletions
diff --git a/src/ui/Avatar.cpp b/src/ui/Avatar.cpp

index e4a90f81..3589fce5 100644 --- a/src/ui/Avatar.cpp +++ b/src/ui/Avatar.cpp
@@ -73,21 +73,31 @@ Avatar::setLetter(const QString &letter) void Avatar::setImage(const QString &avatar_url) { - AvatarProvider::resolve(avatar_url, size_, this, [this](QPixmap pm) { - type_ = ui::AvatarType::Image; - pixmap_ = pm; - update(); - }); + avatar_url_ = avatar_url; + AvatarProvider::resolve(avatar_url, + static_cast<int>(size_ * pixmap_.devicePixelRatio()), + this, + [this](QPixmap pm) { + type_ = ui::AvatarType::Image; + pixmap_ = pm; + update(); + }); } void Avatar::setImage(const QString &room, const QString &user) { - AvatarProvider::resolve(room, user, size_, this, [this](QPixmap pm) { - type_ = ui::AvatarType::Image; - pixmap_ = pm; - update(); - }); + room_ = room; + user_ = user; + AvatarProvider::resolve(room, + user, + static_cast<int>(size_ * pixmap_.devicePixelRatio()), + this, + [this](QPixmap pm) { + type_ = ui::AvatarType::Image; + pixmap_ = pm; + update(); + }); } void @@ -118,6 +128,16 @@ Avatar::paintEvent(QPaintEvent *) painter.setBrush(brush); rounded ? painter.drawEllipse(r.center(), hs, hs) : painter.drawRoundedRect(r, 3, 3); + } else if (painter.isActive() && + abs(pixmap_.devicePixelRatio() - painter.device()->devicePixelRatioF()) > 0.01) { + pixmap_ = + pixmap_.scaled(QSize(size_, size_) * painter.device()->devicePixelRatioF()); + pixmap_.setDevicePixelRatio(painter.device()->devicePixelRatioF()); + + if (!avatar_url_.isEmpty()) + setImage(avatar_url_); + else + setImage(room_, user_); } switch (type_) { diff --git a/src/ui/Avatar.h b/src/ui/Avatar.h
index d6d0b5c7..aea7d3e6 100644 --- a/src/ui/Avatar.h +++ b/src/ui/Avatar.h
@@ -38,6 +38,7 @@ private: ui::AvatarType type_; QString letter_; + QString avatar_url_, room_, user_; QColor background_color_; QColor text_color_; QIcon icon_;