From 13c3f52f9b5027d5b1ead5f8b828da3bebd50937 Mon Sep 17 00:00:00 2001 From: ConfuSomu Date: Sun, 24 Mar 2024 20:40:51 -0400 Subject: Scale header image to nicely fill username label This is similar to what the Mastodon web interface (and other clients, such as SubwayTooter) does with header images, only in an empty zone above the display name label. We could evidently change this with ease in the future. --- src/widgets/tab_actor_info.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/widgets/tab_actor_info.cpp b/src/widgets/tab_actor_info.cpp index 7a01980..282d093 100644 --- a/src/widgets/tab_actor_info.cpp +++ b/src/widgets/tab_actor_info.cpp @@ -54,12 +54,19 @@ void TabActorInfo::paintEvent(QPaintEvent* event) { if (actor and actor->header) { painter.setOpacity(0.75); - QPixmap pixmap = actor->header->get_pixmap(ui->displayNameText->width()); + auto &widget = *(ui->displayNameText); - painter.translate(widget.pos()); + QPixmap pixmap = actor->header->get_pixmap(widget.width()); + QPoint centre(widget.width() / 2 - pixmap.width() / 2, widget.height() / 2 - pixmap.height() / 2); - painter.drawPixmap(centre, pixmap); + + QRect source( + QPoint(0, abs(widget.height() - pixmap.height()) / 2), + QPoint(pixmap.width(), abs(widget.height() - pixmap.height()) / 2 + widget.height()) + ); + + painter.drawPixmap(widget.pos(), pixmap, source); painter.setOpacity(1.0); } } -- cgit v1.2.3-54-g00ecf