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-15 18:59:17 +02:00
|
|
|
if (this->emote_)
|
|
|
|
{
|
|
|
|
if (auto image = this->emote_->images.getImage(4))
|
|
|
|
{
|
|
|
|
if (auto pixmap = image->pixmapOrLoad())
|
|
|
|
{
|
|
|
|
painter->drawPixmap(QRect(rect.x(), rect.y(), ICON_SIZE.width(),
|
|
|
|
ICON_SIZE.height()),
|
|
|
|
*pixmap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect iconRect(rect.topLeft(), ICON_SIZE);
|
|
|
|
QRect textRect =
|
|
|
|
QRect(iconRect.topRight(),
|
|
|
|
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
|