mirror-chatterino2/src/singletons/Theme.cpp

128 lines
3.9 KiB
C++
Raw Normal View History

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"
2018-11-25 15:02:48 +01:00
#include "Application.hpp"
2017-01-18 04:52:47 +01:00
#include <QColor>
2016-12-30 19:16:48 +01:00
#include <cmath>
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()
{
this->update();
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)
// 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);
};
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;
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:" +
(isLight ? "#68B1FF"
: 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 =
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);
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);
}
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);
}
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
}
2018-11-25 15:02:48 +01:00
Theme *getTheme()
{
return getApp()->themes;
}
2017-04-14 17:52:22 +02:00
} // namespace chatterino