diff --git a/src/widgets/helper/Button.cpp b/src/widgets/helper/Button.cpp index cba385700..36748417e 100644 --- a/src/widgets/helper/Button.cpp +++ b/src/widgets/helper/Button.cpp @@ -9,6 +9,20 @@ #include "util/FunctionEventFilter.hpp" namespace chatterino { +namespace { + + // returns a new resized image or the old one if the size didn't change + auto resizePixmap(const QPixmap ¤t, const QPixmap resized, + const QSize &size) -> QPixmap + { + if (resized.size() == size) + return resized; + else + return current.scaled(size, Qt::IgnoreAspectRatio, + Qt::SmoothTransformation); + } + +} // namespace Button::Button(BaseWidget *parent) : BaseWidget(parent) @@ -30,6 +44,7 @@ void Button::setMouseEffectColor(boost::optional color) void Button::setPixmap(const QPixmap &_pixmap) { this->pixmap_ = _pixmap; + this->resizedPixmap_ = {}; this->update(); } @@ -123,6 +138,9 @@ void Button::paintEvent(QPaintEvent *) QRect rect = this->rect(); + this->resizedPixmap_ = + resizePixmap(this->pixmap_, this->resizedPixmap_, rect.size()); + int margin = this->height() < 22 * this->scale() ? 3 : 6; int s = this->enableMargin_ ? int(margin * this->scale()) : 0; @@ -132,7 +150,7 @@ void Button::paintEvent(QPaintEvent *) rect.moveTop(s); rect.setBottom(rect.bottom() - s - s); - painter.drawPixmap(rect, this->pixmap_); + painter.drawPixmap(rect, this->resizedPixmap_); painter.setOpacity(1); } diff --git a/src/widgets/helper/Button.hpp b/src/widgets/helper/Button.hpp index 7a3f64cb9..e0698b1ea 100644 --- a/src/widgets/helper/Button.hpp +++ b/src/widgets/helper/Button.hpp @@ -78,6 +78,7 @@ private: QColor borderColor_{}; QPixmap pixmap_{}; + QPixmap resizedPixmap_{}; Dim dimPixmap_{Dim::Some}; bool enableMargin_{true}; QPoint mousePos_{};