[irc] Partially fix IRC colors (#1594)

Doesn't fix #1379 but it is a big step forward.

Needs some "real life" testing, but should be good.
This commit is contained in:
pajlada
2020-07-04 09:15:59 -04:00
committed by GitHub
parent 0f9a612c55
commit e4af009fda
16 changed files with 1033 additions and 403 deletions
@@ -395,4 +395,41 @@ int TextIconLayoutElement::getXFromIndex(int index)
}
}
//
// TEXT
//
MultiColorTextLayoutElement::MultiColorTextLayoutElement(
MessageElement &_creator, QString &_text, const QSize &_size,
std::vector<PajSegment> segments, FontStyle _style, float _scale)
: TextLayoutElement(_creator, _text, _size, QColor{}, _style, _scale)
, segments_(segments)
{
this->setText(_text);
}
void MultiColorTextLayoutElement::paint(QPainter &painter)
{
auto app = getApp();
painter.setPen(this->color_);
painter.setFont(app->fonts->getFont(this->style_, this->scale_));
int xOffset = 0;
auto metrics = app->fonts->getFontMetrics(this->style_, this->scale_);
for (const auto &segment : this->segments_)
{
// qDebug() << "Draw segment:" << segment.text;
painter.setPen(segment.color);
painter.drawText(QRectF(this->getRect().x() + xOffset,
this->getRect().y(), 10000, 10000),
segment.text,
QTextOption(Qt::AlignLeft | Qt::AlignTop));
xOffset += metrics.width(segment.text);
}
}
} // namespace chatterino