Added setting to colorize usernames who have not set own color.

This commit is contained in:
23rd 2019-08-11 15:01:47 +03:00
parent fbee24b78d
commit da039bfdfa
3 changed files with 44 additions and 3 deletions

View file

@ -23,8 +23,41 @@
#include <QDebug> #include <QDebug>
#include <QMediaPlayer> #include <QMediaPlayer>
#include <QStringRef> #include <QStringRef>
#include <QColor>
#include <boost/variant.hpp> #include <boost/variant.hpp>
namespace {
QColor getRandomColor(QVariant value)
{
static const std::vector<QColor> twitchUsernameColors = {
QColor(255, 0, 0), // Red
QColor(0, 0, 255), // Blue
QColor(0, 255, 0), // Green
QColor(178, 34, 34), // FireBrick
QColor(255, 127, 80), // Coral
QColor(154, 205, 50), // YellowGreen
QColor(255, 69, 0), // OrangeRed
QColor(46, 139, 87), // SeaGreen
QColor(218, 165, 32), // GoldenRod
QColor(210, 105, 30), // Chocolate
QColor(95, 158, 160), // CadetBlue
QColor(30, 144, 255), // DodgerBlue
QColor(255, 105, 180), // HotPink
QColor(138, 43, 226), // BlueViolet
QColor(0, 255, 127) // SpringGreen
};
// If someday Twitch will replace all the user-ids with strings
// then we just choose a random color.
const auto userId = value.toInt();
const auto index = (userId ? userId : std::rand())
% twitchUsernameColors.size();
return twitchUsernameColors[index];
}
}
namespace chatterino { namespace chatterino {
TwitchMessageBuilder::TwitchMessageBuilder( TwitchMessageBuilder::TwitchMessageBuilder(
@ -466,10 +499,15 @@ void TwitchMessageBuilder::appendChannelName()
void TwitchMessageBuilder::parseUsername() void TwitchMessageBuilder::parseUsername()
{ {
auto iterator = this->tags.find("color"); const auto iterator = this->tags.find("color");
if (iterator != this->tags.end()) if (const auto color = iterator.value().toString(); !color.isEmpty())
{ {
this->usernameColor_ = QColor(iterator.value().toString()); this->usernameColor_ = QColor(color);
}
else if (getSettings()->colorizeNicknames &&
this->tags.contains("user-id"))
{
this->usernameColor_ = getRandomColor(this->tags.value("user-id"));
} }
// username // username

View file

@ -42,6 +42,8 @@ public:
BoolSetting hideModerated = {"/appearance/messages/hideModerated", false}; BoolSetting hideModerated = {"/appearance/messages/hideModerated", false};
BoolSetting hideModerationActions = { BoolSetting hideModerationActions = {
"/appearance/messages/hideModerationActions", false}; "/appearance/messages/hideModerationActions", false};
BoolSetting colorizeNicknames = {
"/appearance/messages/colorizeNicknames", false};
// BoolSetting collapseLongMessages = // BoolSetting collapseLongMessages =
// {"/appearance/messages/collapseLongMessages", false}; // {"/appearance/messages/collapseLongMessages", false};

View file

@ -217,6 +217,7 @@ void GeneralPage::initLayout(SettingsLayout &layout)
// layout.addDropdown("Last read message style", {"Default"}); // layout.addDropdown("Last read message style", {"Default"});
layout.addCheckbox("Hide moderated messages", s.hideModerated); layout.addCheckbox("Hide moderated messages", s.hideModerated);
layout.addCheckbox("Hide moderation messages", s.hideModerationActions); layout.addCheckbox("Hide moderation messages", s.hideModerationActions);
layout.addCheckbox("Colorize gray nicknames", s.colorizeNicknames);
layout.addDropdown<int>( layout.addDropdown<int>(
"Timeout stacking style", {"Stack", "Stack sparingly"}, "Timeout stacking style", {"Stack", "Stack sparingly"},
s.timeoutStackStyle, [](int index) { return index; }, s.timeoutStackStyle, [](int index) { return index; },