From 758fdc28eeae1b70514b7cbf195c97f1e007cf03 Mon Sep 17 00:00:00 2001 From: fourtf Date: Sat, 22 Aug 2020 12:19:20 +0200 Subject: [PATCH] added margin to emote input items --- src/widgets/splits/EmoteInputItem.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/widgets/splits/EmoteInputItem.cpp b/src/widgets/splits/EmoteInputItem.cpp index dc8a129c..5612b16c 100644 --- a/src/widgets/splits/EmoteInputItem.cpp +++ b/src/widgets/splits/EmoteInputItem.cpp @@ -19,23 +19,38 @@ void EmoteInputItem::action() void EmoteInputItem::paint(QPainter *painter, const QRect &rect) const { painter->setRenderHint(QPainter::SmoothPixmapTransform); + painter->setRenderHint(QPainter::Antialiasing); + + auto margin = 4; + auto imageHeight = ICON_SIZE.height() - margin * 2; + + QRect iconRect{ + rect.topLeft() + QPoint{margin, margin}, + QSize{imageHeight, imageHeight}, + }; if (this->emote_) { - if (auto image = this->emote_->images.getImage(4)) + if (auto image = this->emote_->images.getImage(2)) { if (auto pixmap = image->pixmapOrLoad()) { - painter->drawPixmap(QRect(rect.x(), rect.y(), ICON_SIZE.width(), - ICON_SIZE.height()), - *pixmap); + if (image->height() != 0) + { + auto aspectRatio = + double(image->width()) / double(image->height()); + + iconRect = { + rect.topLeft() + QPoint{margin, margin}, + QSize(int(imageHeight * aspectRatio), imageHeight)}; + painter->drawPixmap(iconRect, *pixmap); + } } } } - QRect iconRect(rect.topLeft(), ICON_SIZE); QRect textRect = - QRect(iconRect.topRight(), + QRect(iconRect.topRight() + QPoint{margin, 0}, QSize(rect.width() - iconRect.width(), iconRect.height())); painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, this->text_); }