mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Added setting to colorize usernames who have not set own color.
This commit is contained in:
parent
fbee24b78d
commit
da039bfdfa
|
@ -23,8 +23,41 @@
|
|||
#include <QDebug>
|
||||
#include <QMediaPlayer>
|
||||
#include <QStringRef>
|
||||
#include <QColor>
|
||||
#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 {
|
||||
|
||||
TwitchMessageBuilder::TwitchMessageBuilder(
|
||||
|
@ -466,10 +499,15 @@ void TwitchMessageBuilder::appendChannelName()
|
|||
|
||||
void TwitchMessageBuilder::parseUsername()
|
||||
{
|
||||
auto iterator = this->tags.find("color");
|
||||
if (iterator != this->tags.end())
|
||||
const auto iterator = this->tags.find("color");
|
||||
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
|
||||
|
|
|
@ -42,6 +42,8 @@ public:
|
|||
BoolSetting hideModerated = {"/appearance/messages/hideModerated", false};
|
||||
BoolSetting hideModerationActions = {
|
||||
"/appearance/messages/hideModerationActions", false};
|
||||
BoolSetting colorizeNicknames = {
|
||||
"/appearance/messages/colorizeNicknames", false};
|
||||
|
||||
// BoolSetting collapseLongMessages =
|
||||
// {"/appearance/messages/collapseLongMessages", false};
|
||||
|
|
|
@ -217,6 +217,7 @@ void GeneralPage::initLayout(SettingsLayout &layout)
|
|||
// layout.addDropdown("Last read message style", {"Default"});
|
||||
layout.addCheckbox("Hide moderated messages", s.hideModerated);
|
||||
layout.addCheckbox("Hide moderation messages", s.hideModerationActions);
|
||||
layout.addCheckbox("Colorize gray nicknames", s.colorizeNicknames);
|
||||
layout.addDropdown<int>(
|
||||
"Timeout stacking style", {"Stack", "Stack sparingly"},
|
||||
s.timeoutStackStyle, [](int index) { return index; },
|
||||
|
|
Loading…
Reference in a new issue