2020-08-15 18:59:17 +02:00
|
|
|
#include "EmoteInputItem.hpp"
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
|
|
|
EmoteInputItem::EmoteInputItem(const EmotePtr &emote, const QString &text,
|
|
|
|
ActionCallback action)
|
|
|
|
: emote_(emote)
|
|
|
|
, text_(text)
|
|
|
|
, action_(action)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmoteInputItem::action()
|
|
|
|
{
|
|
|
|
if (this->action_ && this->emote_)
|
|
|
|
this->action_(this->emote_->name.string);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmoteInputItem::paint(QPainter *painter, const QRect &rect) const
|
|
|
|
{
|
2020-08-15 20:25:58 +02:00
|
|
|
painter->setRenderHint(QPainter::SmoothPixmapTransform);
|
2020-08-22 12:19:20 +02:00
|
|
|
painter->setRenderHint(QPainter::Antialiasing);
|
|
|
|
|
|
|
|
auto margin = 4;
|
|
|
|
auto imageHeight = ICON_SIZE.height() - margin * 2;
|
|
|
|
|
|
|
|
QRect iconRect{
|
|
|
|
rect.topLeft() + QPoint{margin, margin},
|
|
|
|
QSize{imageHeight, imageHeight},
|
|
|
|
};
|
2020-08-15 20:25:58 +02:00
|
|
|
|
2020-08-15 18:59:17 +02:00
|
|
|
if (this->emote_)
|
|
|
|
{
|
2020-08-22 12:19:20 +02:00
|
|
|
if (auto image = this->emote_->images.getImage(2))
|
2020-08-15 18:59:17 +02:00
|
|
|
{
|
|
|
|
if (auto pixmap = image->pixmapOrLoad())
|
|
|
|
{
|
2020-08-22 12:19:20 +02:00
|
|
|
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);
|
|
|
|
}
|
2020-08-15 18:59:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect textRect =
|
2020-08-22 12:19:20 +02:00
|
|
|
QRect(iconRect.topRight() + QPoint{margin, 0},
|
2020-08-15 18:59:17 +02:00
|
|
|
QSize(rect.width() - iconRect.width(), iconRect.height()));
|
|
|
|
painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, this->text_);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize EmoteInputItem::sizeHint(const QRect &rect) const
|
|
|
|
{
|
|
|
|
return QSize(rect.width(), ICON_SIZE.height());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|