Skip to content

Commit

Permalink
fix: don't render paints in system messages
Browse files Browse the repository at this point in the history
Fixes #111
  • Loading branch information
Nerixyz committed Sep 14, 2024
1 parent 218a486 commit b55e723
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/messages/MessageColor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ namespace chatterino {
class Theme;

struct MessageColor {
enum Type { Custom, Text, Link, System };
enum Type : uint8_t { Custom, Text, Link, System };

MessageColor(const QColor &color);
MessageColor(Type type_ = Text);

Type type() const
{
return this->type_;
}

const QColor &getColor(Theme &themeManager) const;

private:
Expand Down
4 changes: 2 additions & 2 deletions src/messages/MessageElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ void TextElement::addToContainer(MessageLayoutContainer &container,

auto *e = new TextLayoutElement(
*this, text, QSize(width, metrics.height()), color,
this->style_, container.getScale());
this->style_, this->color_.type(), container.getScale());
e->setTrailingSpace(hasTrailingSpace);
e->setText(text);
e->setWordId(wordId);
Expand Down Expand Up @@ -690,7 +690,7 @@ void SingleLineTextElement::addToContainer(MessageLayoutContainer &container,

auto *e = new TextLayoutElement(
*this, text, QSize(width, metrics.height()), color,
this->style_, container.getScale());
this->style_, this->color_.type(), container.getScale());
e->setTrailingSpace(hasTrailingSpace);
e->setText(text);

Expand Down
3 changes: 2 additions & 1 deletion src/messages/layouts/MessageLayoutContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ void MessageLayoutContainer::endLayout()
auto *element = new TextLayoutElement(
dotdotdot, dotdotdotText,
QSize(this->dotdotdotWidth_, this->textLineHeight_),
QColor("#00D80A"), FontStyle::ChatMediumBold, this->scale_);
QColor("#00D80A"), FontStyle::ChatMediumBold, MessageColor::Text,
this->scale_);

if (this->isRTL())
{
Expand Down
8 changes: 6 additions & 2 deletions src/messages/layouts/MessageLayoutElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,13 @@ void ImageWithCircleBackgroundLayoutElement::paint(

TextLayoutElement::TextLayoutElement(MessageElement &_creator, QString &_text,
const QSize &_size, QColor _color,
FontStyle _style, float _scale)
FontStyle _style,
MessageColor::Type messageColor,
float _scale)
: MessageLayoutElement(_creator, _size)
, color_(_color)
, style_(_style)
, messageColor_(messageColor)
, scale_(_scale)
{
this->setText(_text);
Expand Down Expand Up @@ -458,7 +461,8 @@ void TextLayoutElement::paint(QPainter &painter,

bool isNametag = this->getLink().type == chatterino::Link::UserInfo ||
this->getLink().type == chatterino::Link::UserWhisper;
bool drawPaint = isNametag && getSettings()->displaySevenTVPaints;
bool drawPaint = isNametag && this->messageColor_ != MessageColor::System &&
getSettings()->displaySevenTVPaints;
auto seventvPaint =
app->getSeventvPaints()->getPaint(this->getLink().value.toLower());
if (drawPaint && seventvPaint.has_value())
Expand Down
6 changes: 5 additions & 1 deletion src/messages/layouts/MessageLayoutElement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "common/FlagsEnum.hpp"
#include "messages/Link.hpp"
#include "messages/MessageColor.hpp"

#include <pajlada/signals/signalholder.hpp>
#include <QPen>
Expand Down Expand Up @@ -170,7 +171,7 @@ class TextLayoutElement : public MessageLayoutElement
public:
TextLayoutElement(MessageElement &creator_, QString &text,
const QSize &size, QColor color_, FontStyle style_,
float scale_);
MessageColor::Type messageColor, float scale_);

protected:
void addCopyTextToString(QString &str, uint32_t from = 0,
Expand All @@ -183,6 +184,9 @@ class TextLayoutElement : public MessageLayoutElement

QColor color_;
FontStyle style_;
// 7tv: this is used to check for system messages - it doesn't take extra
// space (fits in the padding of `style_`)
MessageColor::Type messageColor_;
float scale_;
};

Expand Down

0 comments on commit b55e723

Please sign in to comment.