2017-01-18 01:04:54 +01:00
|
|
|
#define LOOKUP_COLOR_COUNT 360
|
|
|
|
|
2018-07-15 14:03:41 +02:00
|
|
|
#include "singletons/Theme.hpp"
|
2017-01-18 04:52:47 +01:00
|
|
|
|
|
|
|
#include <QColor>
|
2016-12-30 19:16:48 +01:00
|
|
|
|
2018-04-03 02:55:32 +02:00
|
|
|
#include <cmath>
|
2017-08-05 23:38:49 +02:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2017-06-26 16:41:20 +02:00
|
|
|
namespace detail {
|
|
|
|
|
2018-01-12 23:09:05 +01:00
|
|
|
double getMultiplierByTheme(const QString &themeName)
|
2017-02-02 01:23:26 +01:00
|
|
|
{
|
2017-06-26 16:41:20 +02:00
|
|
|
if (themeName == "Light") {
|
|
|
|
return 0.8;
|
|
|
|
} else if (themeName == "White") {
|
|
|
|
return 1.0;
|
|
|
|
} else if (themeName == "Black") {
|
|
|
|
return -1.0;
|
|
|
|
} else if (themeName == "Dark") {
|
|
|
|
return -0.8;
|
|
|
|
}
|
2017-02-02 01:23:26 +01:00
|
|
|
|
2017-06-26 16:41:20 +02:00
|
|
|
return -0.8;
|
|
|
|
}
|
2017-02-02 01:23:26 +01:00
|
|
|
|
2017-06-26 16:41:20 +02:00
|
|
|
} // namespace detail
|
2017-06-13 21:13:58 +02:00
|
|
|
|
2018-06-28 20:03:04 +02:00
|
|
|
Theme::Theme()
|
2017-07-02 12:36:50 +02:00
|
|
|
: themeName("/appearance/theme/name", "Dark")
|
|
|
|
, themeHue("/appearance/theme/hue", 0.0)
|
2017-06-26 16:41:20 +02:00
|
|
|
{
|
|
|
|
this->update();
|
2017-06-13 21:13:58 +02:00
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
this->themeName.connectSimple([this](auto) { this->update(); }, false);
|
|
|
|
this->themeHue.connectSimple([this](auto) { this->update(); }, false);
|
2017-02-02 01:23:26 +01:00
|
|
|
}
|
|
|
|
|
2018-06-28 20:03:04 +02:00
|
|
|
void Theme::update()
|
2017-02-02 01:23:26 +01:00
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
this->actuallyUpdate(this->themeHue, detail::getMultiplierByTheme(
|
|
|
|
this->themeName.getValue()));
|
2017-02-02 01:23:26 +01:00
|
|
|
}
|
|
|
|
|
2016-12-30 19:20:04 +01:00
|
|
|
// hue: theme color (0 - 1)
|
2017-06-26 16:41:20 +02:00
|
|
|
// multiplier: 1 = white, 0.8 = light, -0.8 dark, -1 black
|
2018-06-28 20:03:04 +02:00
|
|
|
void Theme::actuallyUpdate(double hue, double multiplier)
|
2016-12-30 19:16:48 +01:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
isLight_ = multiplier > 0;
|
|
|
|
bool lightWin = isLight_;
|
2018-01-15 01:35:35 +01:00
|
|
|
|
2018-06-07 17:43:21 +02:00
|
|
|
// QColor themeColor = QColor::fromHslF(hue, 0.43, 0.5);
|
|
|
|
QColor themeColor = QColor::fromHslF(hue, 0.8, 0.5);
|
2018-01-15 01:38:21 +01:00
|
|
|
QColor themeColorNoSat = QColor::fromHslF(hue, 0, 0.5);
|
2018-01-15 01:35:35 +01:00
|
|
|
|
2018-02-09 15:47:11 +01:00
|
|
|
qreal sat = 0;
|
2018-01-27 21:13:22 +01:00
|
|
|
// 0.05;
|
|
|
|
|
|
|
|
auto getColor = [multiplier](double h, double s, double l, double a = 1.0) {
|
|
|
|
return QColor::fromHslF(h, s, ((l - 0.5) * multiplier) + 0.5, a);
|
|
|
|
};
|
|
|
|
|
2018-04-05 23:44:46 +02:00
|
|
|
/// WINDOW
|
|
|
|
{
|
2018-04-13 22:50:19 +02:00
|
|
|
QColor bg =
|
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
this->window.background = lightWin ? "#fff" : QColor(61, 60, 56);
|
|
|
|
#else
|
2018-05-23 04:22:17 +02:00
|
|
|
this->window.background = lightWin ? "#fff" : "#111";
|
2018-04-13 22:50:19 +02:00
|
|
|
#endif
|
|
|
|
|
2018-04-05 23:44:46 +02:00
|
|
|
QColor fg = this->window.text = lightWin ? "#000" : "#eee";
|
|
|
|
this->window.borderFocused = lightWin ? "#ccc" : themeColor;
|
|
|
|
this->window.borderUnfocused = lightWin ? "#ccc" : themeColorNoSat;
|
|
|
|
|
|
|
|
// Ubuntu style
|
|
|
|
// TODO: add setting for this
|
|
|
|
// TabText = QColor(210, 210, 210);
|
|
|
|
// TabBackground = QColor(61, 60, 56);
|
|
|
|
// TabHoverText = QColor(210, 210, 210);
|
|
|
|
// TabHoverBackground = QColor(73, 72, 68);
|
|
|
|
|
|
|
|
// message (referenced later)
|
|
|
|
this->messages.textColors.caret = //
|
2018-07-06 19:23:47 +02:00
|
|
|
this->messages.textColors.regular = isLight_ ? "#000" : "#fff";
|
2018-04-05 23:44:46 +02:00
|
|
|
|
2018-06-07 17:43:21 +02:00
|
|
|
QColor highlighted = lightWin ? QColor("#ff0000") : QColor("#ee6166");
|
2018-06-06 13:35:06 +02:00
|
|
|
|
2018-04-05 23:44:46 +02:00
|
|
|
/// TABS
|
|
|
|
if (lightWin) {
|
2018-08-06 21:17:03 +02:00
|
|
|
this->tabs.regular = {
|
|
|
|
QColor("#444"),
|
|
|
|
{QColor("#fff"), QColor("#eee"), QColor("#fff")},
|
|
|
|
{QColor("#fff"), QColor("#fff"), QColor("#fff")}};
|
|
|
|
this->tabs.newMessage = {
|
|
|
|
QColor("#222"),
|
|
|
|
{QColor("#fff"), QColor("#eee"), QColor("#fff")},
|
|
|
|
{QColor("#bbb"), QColor("#bbb"), QColor("#bbb")}};
|
|
|
|
this->tabs.highlighted = {
|
|
|
|
fg,
|
|
|
|
{QColor("#fff"), QColor("#eee"), QColor("#fff")},
|
|
|
|
{highlighted, highlighted, highlighted}};
|
|
|
|
this->tabs.selected = {
|
|
|
|
QColor("#000"),
|
|
|
|
{QColor("#b4d7ff"), QColor("#b4d7ff"), QColor("#b4d7ff")},
|
|
|
|
{QColor("#00aeef"), QColor("#00aeef"), QColor("#00aeef")}};
|
2018-05-23 04:22:17 +02:00
|
|
|
} else {
|
2018-08-06 21:17:03 +02:00
|
|
|
this->tabs.regular = {
|
|
|
|
QColor("#aaa"),
|
|
|
|
{QColor("#252525"), QColor("#252525"), QColor("#252525")},
|
|
|
|
{QColor("#444"), QColor("#444"), QColor("#444")}};
|
|
|
|
this->tabs.newMessage = {
|
|
|
|
fg,
|
|
|
|
{QColor("#252525"), QColor("#252525"), QColor("#252525")},
|
|
|
|
{QColor("#888"), QColor("#888"), QColor("#888")}};
|
|
|
|
this->tabs.highlighted = {
|
|
|
|
fg,
|
|
|
|
{QColor("#252525"), QColor("#252525"), QColor("#252525")},
|
|
|
|
{highlighted, highlighted, highlighted}};
|
|
|
|
|
|
|
|
this->tabs.selected = {
|
|
|
|
QColor("#fff"),
|
|
|
|
{QColor("#555555"), QColor("#555555"), QColor("#555555")},
|
|
|
|
{QColor("#00aeef"), QColor("#00aeef"), QColor("#00aeef")}};
|
2018-04-05 23:44:46 +02:00
|
|
|
}
|
2018-04-18 09:12:29 +02:00
|
|
|
|
2018-06-06 13:35:06 +02:00
|
|
|
this->splits.input.focusedLine = highlighted;
|
|
|
|
|
2018-05-26 17:11:09 +02:00
|
|
|
// scrollbar
|
|
|
|
this->scrollbars.highlights.highlight = QColor("#ee6166");
|
2018-06-04 12:23:23 +02:00
|
|
|
this->scrollbars.highlights.subscription = QColor("#C466FF");
|
2018-05-26 17:11:09 +02:00
|
|
|
|
2018-05-23 04:22:17 +02:00
|
|
|
// this->tabs.newMessage = {
|
|
|
|
// fg,
|
|
|
|
// {QBrush(blendColors(themeColor, "#ccc", 0.9), Qt::FDiagPattern),
|
|
|
|
// QBrush(blendColors(themeColor, "#ccc", 0.9), Qt::FDiagPattern),
|
2018-08-06 21:17:03 +02:00
|
|
|
// QBrush(blendColors(themeColorNoSat, "#ccc", 0.9),
|
|
|
|
// Qt::FDiagPattern)}};
|
2018-05-23 04:22:17 +02:00
|
|
|
|
|
|
|
// this->tabs.newMessage = {
|
|
|
|
// fg,
|
2018-08-06 21:17:03 +02:00
|
|
|
// {QBrush(blendColors(themeColor, "#666", 0.7),
|
|
|
|
// Qt::FDiagPattern),
|
|
|
|
// QBrush(blendColors(themeColor, "#666", 0.5),
|
|
|
|
// Qt::FDiagPattern),
|
2018-05-23 04:22:17 +02:00
|
|
|
// QBrush(blendColors(themeColorNoSat, "#666", 0.7),
|
|
|
|
// Qt::FDiagPattern)}};
|
2018-08-06 21:17:03 +02:00
|
|
|
// this->tabs.highlighted = {fg, {QColor("#777"),
|
|
|
|
// QColor("#777"), QColor("#666")}};
|
2018-05-23 04:22:17 +02:00
|
|
|
|
2018-04-18 09:12:29 +02:00
|
|
|
this->tabs.bottomLine = this->tabs.selected.backgrounds.regular.color();
|
2018-04-05 23:44:46 +02:00
|
|
|
}
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2018-01-02 02:15:11 +01:00
|
|
|
// Split
|
2018-07-06 19:23:47 +02:00
|
|
|
bool flat = isLight_;
|
2017-12-26 16:54:39 +01:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
this->splits.messageSeperator =
|
|
|
|
isLight_ ? QColor(127, 127, 127) : QColor(60, 60, 60);
|
2018-01-02 02:15:11 +01:00
|
|
|
this->splits.background = getColor(0, sat, 1);
|
2018-05-08 20:35:31 +02:00
|
|
|
this->splits.dropPreview = QColor(0, 148, 255, 0x30);
|
2018-06-01 14:20:46 +02:00
|
|
|
this->splits.dropPreviewBorder = QColor(0, 148, 255, 0xff);
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
if (isLight_) {
|
2018-06-07 17:43:21 +02:00
|
|
|
this->splits.dropTargetRect = QColor(255, 255, 255, 0x00);
|
|
|
|
this->splits.dropTargetRectBorder = QColor(0, 148, 255, 0x00);
|
|
|
|
|
|
|
|
this->splits.resizeHandle = QColor(0, 148, 255, 0xff);
|
|
|
|
this->splits.resizeHandleBackground = QColor(0, 148, 255, 0x50);
|
|
|
|
} else {
|
|
|
|
this->splits.dropTargetRect = QColor(0, 148, 255, 0x00);
|
|
|
|
this->splits.dropTargetRectBorder = QColor(0, 148, 255, 0x00);
|
|
|
|
|
|
|
|
this->splits.resizeHandle = QColor(0, 148, 255, 0x70);
|
|
|
|
this->splits.resizeHandleBackground = QColor(0, 148, 255, 0x20);
|
|
|
|
}
|
2018-01-02 02:15:11 +01:00
|
|
|
|
|
|
|
this->splits.header.background = getColor(0, sat, flat ? 1 : 0.9);
|
|
|
|
this->splits.header.border = getColor(0, sat, flat ? 1 : 0.85);
|
|
|
|
this->splits.header.text = this->messages.textColors.regular;
|
2018-08-06 21:17:03 +02:00
|
|
|
this->splits.header.focusedText =
|
|
|
|
isLight_ ? QColor("#198CFF") : QColor("#84C1FF");
|
2018-01-02 02:15:11 +01:00
|
|
|
|
|
|
|
this->splits.input.background = getColor(0, sat, flat ? 0.95 : 0.95);
|
|
|
|
this->splits.input.border = getColor(0, sat, flat ? 1 : 1);
|
|
|
|
this->splits.input.text = this->messages.textColors.regular;
|
|
|
|
this->splits.input.styleSheet =
|
|
|
|
"background:" + this->splits.input.background.name() + ";" +
|
2018-08-06 21:17:03 +02:00
|
|
|
"border:" + this->tabs.selected.backgrounds.regular.color().name() +
|
|
|
|
";" + "color:" + this->messages.textColors.regular.name() + ";" + //
|
2018-06-07 17:43:21 +02:00
|
|
|
"selection-background-color:" +
|
2018-08-06 21:17:03 +02:00
|
|
|
(isLight_ ? "#68B1FF"
|
|
|
|
: this->tabs.selected.backgrounds.regular.color().name());
|
2018-01-02 02:15:11 +01:00
|
|
|
|
|
|
|
// Message
|
2018-08-06 21:17:03 +02:00
|
|
|
this->messages.textColors.link =
|
|
|
|
isLight_ ? QColor(66, 134, 244) : QColor(66, 134, 244);
|
2018-01-02 02:15:11 +01:00
|
|
|
this->messages.textColors.system = QColor(140, 127, 127);
|
|
|
|
|
|
|
|
this->messages.backgrounds.regular = splits.background;
|
2018-05-06 14:57:57 +02:00
|
|
|
this->messages.backgrounds.alternate = getColor(0, sat, 0.93);
|
2018-06-19 20:48:57 +02:00
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
if (isLight_) {
|
2018-06-19 20:48:57 +02:00
|
|
|
this->messages.backgrounds.highlighted =
|
|
|
|
blendColors(themeColor, this->messages.backgrounds.regular, 0.8);
|
|
|
|
} else {
|
|
|
|
this->messages.backgrounds.highlighted = QColor(75, 40, 44);
|
|
|
|
}
|
|
|
|
|
2018-06-04 12:23:23 +02:00
|
|
|
this->messages.backgrounds.subscription =
|
|
|
|
blendColors(QColor("#C466FF"), this->messages.backgrounds.regular, 0.7);
|
|
|
|
|
2018-01-02 02:15:11 +01:00
|
|
|
// this->messages.backgrounds.resub
|
|
|
|
// this->messages.backgrounds.whisper
|
|
|
|
this->messages.disabled = getColor(0, sat, 1, 0.6);
|
|
|
|
// this->messages.seperator =
|
|
|
|
// this->messages.seperatorInner =
|
2017-01-18 01:04:54 +01:00
|
|
|
|
2017-08-17 14:52:41 +02:00
|
|
|
// Scrollbar
|
2018-06-05 00:14:20 +02:00
|
|
|
this->scrollbars.background = QColor(0, 0, 0, 0);
|
|
|
|
// this->scrollbars.background = splits.background;
|
|
|
|
// this->scrollbars.background.setAlphaF(qreal(0.2));
|
2018-01-02 02:15:11 +01:00
|
|
|
this->scrollbars.thumb = getColor(0, sat, 0.80);
|
|
|
|
this->scrollbars.thumbSelected = getColor(0, sat, 0.7);
|
2017-01-26 04:26:40 +01:00
|
|
|
|
2018-01-02 02:15:11 +01:00
|
|
|
// tooltip
|
|
|
|
this->tooltip.background = QColor(0, 0, 0);
|
|
|
|
this->tooltip.text = QColor(255, 255, 255);
|
2017-02-02 01:23:26 +01:00
|
|
|
|
2017-12-19 02:37:58 +01:00
|
|
|
// Selection
|
2018-08-06 21:17:03 +02:00
|
|
|
this->messages.selection =
|
|
|
|
isLightTheme() ? QColor(0, 0, 0, 64) : QColor(255, 255, 255, 64);
|
2017-12-19 02:37:58 +01:00
|
|
|
|
2018-04-03 02:55:32 +02:00
|
|
|
this->updated.invoke();
|
2018-06-07 17:43:21 +02:00
|
|
|
}
|
2017-01-18 01:04:54 +01:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
QColor Theme::blendColors(const QColor &color1, const QColor &color2,
|
|
|
|
qreal ratio)
|
2017-09-12 19:06:16 +02:00
|
|
|
{
|
2018-06-01 14:20:46 +02:00
|
|
|
int r = int(color1.red() * (1 - ratio) + color2.red() * ratio);
|
|
|
|
int g = int(color1.green() * (1 - ratio) + color2.green() * ratio);
|
|
|
|
int b = int(color1.blue() * (1 - ratio) + color2.blue() * ratio);
|
2017-09-12 19:06:16 +02:00
|
|
|
|
|
|
|
return QColor(r, g, b, 255);
|
|
|
|
}
|
|
|
|
|
2018-06-28 20:03:04 +02:00
|
|
|
void Theme::normalizeColor(QColor &color)
|
2017-01-18 01:04:54 +01:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
if (this->isLight_) {
|
2018-06-01 14:20:46 +02:00
|
|
|
if (color.lightnessF() > 0.5) {
|
|
|
|
color.setHslF(color.hueF(), color.saturationF(), 0.5);
|
2017-12-19 02:23:17 +01:00
|
|
|
}
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
if (color.lightnessF() > 0.4 && color.hueF() > 0.1 &&
|
|
|
|
color.hueF() < 0.33333) {
|
|
|
|
color.setHslF(color.hueF(), color.saturationF(),
|
|
|
|
color.lightnessF() - sin((color.hueF() - 0.1) /
|
|
|
|
(0.3333 - 0.1) * 3.14159) *
|
|
|
|
color.saturationF() * 0.4);
|
2017-12-19 02:23:17 +01:00
|
|
|
}
|
2017-08-12 12:09:26 +02:00
|
|
|
} else {
|
2018-06-01 14:20:46 +02:00
|
|
|
if (color.lightnessF() < 0.5) {
|
|
|
|
color.setHslF(color.hueF(), color.saturationF(), 0.5);
|
2017-08-12 12:09:26 +02:00
|
|
|
}
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
if (color.lightnessF() < 0.6 && color.hueF() > 0.54444 &&
|
|
|
|
color.hueF() < 0.83333) {
|
2018-01-12 23:09:05 +01:00
|
|
|
color.setHslF(
|
|
|
|
color.hueF(), color.saturationF(),
|
2018-08-06 21:17:03 +02:00
|
|
|
color.lightnessF() + sin((color.hueF() - 0.54444) /
|
|
|
|
(0.8333 - 0.54444) * 3.14159) *
|
2018-01-12 23:09:05 +01:00
|
|
|
color.saturationF() * 0.4);
|
2017-08-12 12:09:26 +02:00
|
|
|
}
|
|
|
|
}
|
2016-12-30 19:16:48 +01:00
|
|
|
}
|
2017-06-07 10:09:24 +02:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace chatterino
|