mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
downscale images in button
This commit is contained in:
parent
d13b7d9768
commit
06cb88f6c2
2 changed files with 20 additions and 1 deletions
|
@ -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<QColor> 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);
|
||||
}
|
||||
|
|
|
@ -78,6 +78,7 @@ private:
|
|||
|
||||
QColor borderColor_{};
|
||||
QPixmap pixmap_{};
|
||||
QPixmap resizedPixmap_{};
|
||||
Dim dimPixmap_{Dim::Some};
|
||||
bool enableMargin_{true};
|
||||
QPoint mousePos_{};
|
||||
|
|
Loading…
Reference in a new issue