2017-01-18 01:04:54 +01:00
|
|
|
|
2018-07-15 14:03:41 +02:00
|
|
|
#include "singletons/Theme.hpp"
|
2021-07-25 13:15:38 +02:00
|
|
|
|
2018-11-25 15:02:48 +01:00
|
|
|
#include "Application.hpp"
|
2021-07-25 13:15:38 +02:00
|
|
|
#include "singletons/Resources.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
|
|
|
|
2021-07-25 13:15:38 +02:00
|
|
|
#define LOOKUP_COLOR_COUNT 360
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2018-06-28 20:03:04 +02:00
|
|
|
Theme::Theme()
|
2017-06-26 16:41:20 +02:00
|
|
|
{
|
|
|
|
this->update();
|
2017-06-13 21:13:58 +02:00
|
|
|
|
2020-11-08 12:02:19 +01: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
|
|
|
}
|
|
|
|
|
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-12-02 19:20:14 +01:00
|
|
|
BaseTheme::actuallyUpdate(hue, multiplier);
|
2018-01-27 21:13:22 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2019-05-08 08:51:14 +02:00
|
|
|
const auto sat = qreal(0);
|
|
|
|
const auto isLight = this->isLightTheme();
|
|
|
|
const auto flat = isLight;
|
2018-05-26 17:11:09 +02:00
|
|
|
|
2018-11-25 15:02:48 +01:00
|
|
|
if (this->isLightTheme())
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
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);
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-06-07 17:43:21 +02:00
|
|
|
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;
|
2022-01-22 16:23:02 +01:00
|
|
|
this->splits.header.focusedBackground =
|
|
|
|
getColor(0, sat, isLight ? 0.95 : 0.79);
|
|
|
|
this->splits.header.focusedBorder = getColor(0, sat, isLight ? 0.90 : 0.78);
|
|
|
|
this->splits.header.focusedText = QColor::fromHsvF(
|
|
|
|
0.58388, isLight ? 1.0 : 0.482, isLight ? 0.6375 : 1.0);
|
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() +
|
2020-11-08 12:02:19 +01:00
|
|
|
";" + "color:" + this->messages.textColors.regular.name() + ";" +
|
2018-06-07 17:43:21 +02:00
|
|
|
"selection-background-color:" +
|
2019-05-08 08:51:14 +02:00
|
|
|
(isLight ? "#68B1FF"
|
2019-05-10 23:31:10 +02:00
|
|
|
: this->tabs.selected.backgrounds.regular.color().name());
|
2018-01-02 02:15:11 +01:00
|
|
|
|
2018-11-25 15:02:48 +01:00
|
|
|
this->splits.input.focusedLine = this->tabs.highlighted.line.regular;
|
2017-09-12 19:06:16 +02:00
|
|
|
|
2018-11-25 15:02:48 +01:00
|
|
|
this->splits.messageSeperator =
|
2019-05-08 08:51:14 +02:00
|
|
|
isLight ? QColor(127, 127, 127) : QColor(60, 60, 60);
|
2018-11-25 15:02:48 +01:00
|
|
|
this->splits.background = getColor(0, sat, 1);
|
|
|
|
this->splits.dropPreview = QColor(0, 148, 255, 0x30);
|
|
|
|
this->splits.dropPreviewBorder = QColor(0, 148, 255, 0xff);
|
2021-07-25 13:15:38 +02:00
|
|
|
|
|
|
|
// Copy button
|
|
|
|
if (this->isLightTheme())
|
|
|
|
{
|
|
|
|
this->buttons.copy = getResources().buttons.copyDark;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->buttons.copy = getResources().buttons.copyLight;
|
|
|
|
}
|
2017-09-12 19:06:16 +02:00
|
|
|
}
|
|
|
|
|
2018-06-28 20:03:04 +02:00
|
|
|
void Theme::normalizeColor(QColor &color)
|
2017-01-18 01:04:54 +01:00
|
|
|
{
|
2018-11-25 15:02:48 +01:00
|
|
|
if (this->isLightTheme())
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
|
|
|
if (color.lightnessF() > 0.5)
|
|
|
|
{
|
2018-06-01 14:20:46 +02:00
|
|
|
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 &&
|
2018-10-21 13:43:02 +02:00
|
|
|
color.hueF() < 0.33333)
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
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
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (color.lightnessF() < 0.5)
|
|
|
|
{
|
2018-06-01 14:20:46 +02:00
|
|
|
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 &&
|
2018-10-21 13:43:02 +02:00
|
|
|
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
|
|
|
|
2018-11-25 15:02:48 +01:00
|
|
|
Theme *getTheme()
|
|
|
|
{
|
|
|
|
return getApp()->themes;
|
|
|
|
}
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace chatterino
|