[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:
@@ -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
|
||||
|
||||
@@ -107,7 +107,6 @@ protected:
|
||||
int getMouseOverIndex(const QPoint &abs) const override;
|
||||
int getXFromIndex(int index) override;
|
||||
|
||||
private:
|
||||
QColor color_;
|
||||
FontStyle style_;
|
||||
float scale_;
|
||||
@@ -138,4 +137,25 @@ private:
|
||||
QString line2;
|
||||
};
|
||||
|
||||
struct PajSegment {
|
||||
QString text;
|
||||
QColor color;
|
||||
};
|
||||
|
||||
// TEXT
|
||||
class MultiColorTextLayoutElement : public TextLayoutElement
|
||||
{
|
||||
public:
|
||||
MultiColorTextLayoutElement(MessageElement &creator_, QString &text,
|
||||
const QSize &size,
|
||||
std::vector<PajSegment> segments,
|
||||
FontStyle style_, float scale_);
|
||||
|
||||
protected:
|
||||
void paint(QPainter &painter) override;
|
||||
|
||||
private:
|
||||
std::vector<PajSegment> segments_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
Reference in New Issue
Block a user