2017-01-18 01:04:54 +01:00
|
|
|
#define LOOKUP_COLOR_COUNT 360
|
|
|
|
|
2017-06-11 09:31:45 +02:00
|
|
|
#include "colorscheme.hpp"
|
|
|
|
#include "windowmanager.hpp"
|
2017-01-18 04:52:47 +01:00
|
|
|
|
|
|
|
#include <QColor>
|
2016-12-30 19:16:48 +01:00
|
|
|
|
2017-08-05 23:38:49 +02:00
|
|
|
#include <math.h>
|
|
|
|
|
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 {
|
|
|
|
|
|
|
|
double getMultiplierByTheme(const std::string &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
|
|
|
|
2017-06-26 16:41:20 +02:00
|
|
|
ColorScheme::ColorScheme(WindowManager &windowManager)
|
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
|
|
|
|
2017-12-17 03:37:46 +01:00
|
|
|
this->themeName.connectSimple([this](auto) { this->update(); });
|
|
|
|
this->themeHue.connectSimple([this](auto) { this->update(); });
|
2017-06-26 16:41:20 +02:00
|
|
|
|
|
|
|
this->updated.connect([&windowManager] {
|
|
|
|
windowManager.repaintVisibleChatWidgets(); //
|
|
|
|
});
|
2017-02-02 01:23:26 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void ColorScheme::update()
|
2017-02-02 01:23:26 +01:00
|
|
|
{
|
2017-07-02 12:36:50 +02:00
|
|
|
this->setColors(this->themeHue, detail::getMultiplierByTheme(this->themeName));
|
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
|
|
|
|
void ColorScheme::setColors(double hue, double multiplier)
|
2016-12-30 19:16:48 +01:00
|
|
|
{
|
2017-06-26 16:41:20 +02:00
|
|
|
lightTheme = multiplier > 0;
|
2017-04-12 17:46:44 +02:00
|
|
|
bool hasDarkBorder = false;
|
2016-12-30 19:16:48 +01:00
|
|
|
|
2017-01-05 16:07:20 +01:00
|
|
|
SystemMessageColor = QColor(140, 127, 127);
|
|
|
|
|
2017-06-26 16:41:20 +02:00
|
|
|
auto getColor = [multiplier](double h, double s, double l, double a = 1.0) {
|
2017-08-17 14:52:41 +02:00
|
|
|
return QColor::fromHslF(h, s, ((l - 0.5) * multiplier) + 0.5, a);
|
2016-12-30 19:20:04 +01:00
|
|
|
};
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
DropPreviewBackground = getColor(hue, 0.5, 0.5, 0.6);
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2017-06-26 16:41:20 +02:00
|
|
|
Text = TextCaret = lightTheme ? QColor(0, 0, 0) : QColor(255, 255, 255);
|
2017-08-12 12:09:26 +02:00
|
|
|
TextLink = lightTheme ? QColor(66, 134, 244) : QColor(66, 134, 244);
|
2016-12-30 19:20:04 +01:00
|
|
|
|
2017-01-01 02:30:42 +01:00
|
|
|
// tab
|
2017-08-17 14:52:41 +02:00
|
|
|
if (true) {
|
|
|
|
TabText = QColor(0, 0, 0);
|
2017-04-12 17:46:44 +02:00
|
|
|
TabBackground = QColor(255, 255, 255);
|
2017-08-17 14:52:41 +02:00
|
|
|
|
|
|
|
TabHoverText = QColor(0, 0, 0);
|
2017-04-12 17:46:44 +02:00
|
|
|
TabHoverBackground = getColor(hue, 0, 0.05);
|
2017-08-17 14:52:41 +02:00
|
|
|
} else {
|
|
|
|
// 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);
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
2017-08-17 14:52:41 +02:00
|
|
|
|
|
|
|
TabSelectedText = QColor(255, 255, 255);
|
2017-01-01 02:30:42 +01:00
|
|
|
TabSelectedBackground = getColor(hue, 0.5, 0.5);
|
2017-08-17 14:52:41 +02:00
|
|
|
|
2017-08-17 16:43:19 +02:00
|
|
|
TabSelectedUnfocusedText = QColor(255, 255, 255);
|
|
|
|
TabSelectedUnfocusedBackground = getColor(hue, 0, 0.5);
|
|
|
|
|
2017-08-17 14:52:41 +02:00
|
|
|
TabHighlightedText = QColor(0, 0, 0);
|
2017-01-01 02:30:42 +01:00
|
|
|
TabHighlightedBackground = getColor(hue, 0.5, 0.2);
|
2017-08-17 14:52:41 +02:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
TabNewMessageBackground = QBrush(getColor(hue, 0.5, 0.2), Qt::DiagCrossPattern);
|
2017-01-01 02:30:42 +01:00
|
|
|
|
|
|
|
// Chat
|
|
|
|
ChatBackground = getColor(0, 0.1, 1);
|
2017-09-12 19:06:16 +02:00
|
|
|
ChatBackgroundHighlighted = blendColors(TabSelectedBackground, ChatBackground, 0.8);
|
2017-01-01 02:30:42 +01:00
|
|
|
ChatHeaderBackground = getColor(0, 0.1, 0.9);
|
|
|
|
ChatHeaderBorder = getColor(0, 0.1, 0.85);
|
|
|
|
ChatInputBackground = getColor(0, 0.1, 0.95);
|
|
|
|
ChatInputBorder = getColor(0, 0.1, 0.9);
|
2017-08-17 14:52:41 +02:00
|
|
|
ChatSeperator = lightTheme ? QColor(127, 127, 127) : QColor(80, 80, 80);
|
2017-01-18 01:04:54 +01:00
|
|
|
|
2017-08-17 14:52:41 +02:00
|
|
|
// Scrollbar
|
2017-01-26 04:26:40 +01:00
|
|
|
ScrollbarBG = ChatBackground;
|
2017-08-12 12:09:26 +02:00
|
|
|
ScrollbarThumb = getColor(0, 0.1, 0.85);
|
|
|
|
ScrollbarThumbSelected = getColor(0, 0.1, 0.7);
|
2017-09-15 17:23:49 +02:00
|
|
|
ScrollbarArrow = getColor(0, 0.1, 0.9);
|
2017-01-26 04:26:40 +01:00
|
|
|
|
2017-01-21 05:42:59 +01:00
|
|
|
// stylesheet
|
2017-04-12 17:46:44 +02:00
|
|
|
InputStyleSheet = "background:" + ChatInputBackground.name() + ";" +
|
|
|
|
"border:" + TabSelectedBackground.name() + ";" + "color:" + Text.name() +
|
|
|
|
";" + "selection-background-color:" + TabSelectedBackground.name();
|
2017-02-02 01:23:26 +01:00
|
|
|
|
2017-07-02 14:28:37 +02:00
|
|
|
this->updated();
|
2017-01-18 01:04:54 +01:00
|
|
|
}
|
|
|
|
|
2017-09-12 19:06:16 +02:00
|
|
|
QColor ColorScheme::blendColors(const QColor &color1, const QColor &color2, qreal ratio)
|
|
|
|
{
|
|
|
|
int r = color1.red() * (1 - ratio) + color2.red() * ratio;
|
|
|
|
int g = color1.green() * (1 - ratio) + color2.green() * ratio;
|
|
|
|
int b = color1.blue() * (1 - ratio) + color2.blue() * ratio;
|
|
|
|
|
|
|
|
return QColor(r, g, b, 255);
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void ColorScheme::normalizeColor(QColor &color)
|
2017-01-18 01:04:54 +01:00
|
|
|
{
|
2017-08-12 12:09:26 +02:00
|
|
|
if (this->lightTheme) {
|
2017-08-17 14:52:41 +02:00
|
|
|
// TODO: write some codes
|
2017-08-12 12:09:26 +02:00
|
|
|
} else {
|
|
|
|
if (color.lightnessF() < 0.5f) {
|
|
|
|
color.setHslF(color.hueF(), color.saturationF(), 0.5f);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (color.lightnessF() < 0.6f && color.hueF() > 0.54444 && color.hueF() < 0.83333) {
|
2017-12-17 03:37:46 +01:00
|
|
|
color.setHslF(
|
|
|
|
color.hueF(), color.saturationF(),
|
|
|
|
color.lightnessF() + sin((color.hueF() - 0.54444) / (0.8333 - 0.54444) * 3.14159) *
|
|
|
|
color.saturationF() * 0.2);
|
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
|