diff --git a/CHANGELOG.md b/CHANGELOG.md index 03c32a35b..404fa86d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -108,6 +108,7 @@ - Bugfix: Fixed channel-based popups from rewriting messages to file log (#4060) - Bugfix: Fixed invalid/dangling completion when cycling through previous messages or replying (#4072) - Bugfix: Fixed incorrect .desktop icon path. (#4078) +- Dev: Got rid of BaseTheme (#4132) - Dev: Removed official support for QMake. (#3839, #3883) - Dev: Rewrote LimitedQueue (#3798) - Dev: Overhauled highlight system by moving all checks into a Controller allowing for easier tests. (#3399, #3801, #3835) diff --git a/src/BaseTheme.cpp b/src/BaseTheme.cpp deleted file mode 100644 index 98f8a2df1..000000000 --- a/src/BaseTheme.cpp +++ /dev/null @@ -1,216 +0,0 @@ -#include "BaseTheme.hpp" - -namespace chatterino { -namespace { - double getMultiplierByTheme(const QString &themeName) - { - 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; - } - /* - else if (themeName == "Custom") - { - return getSettings()->customThemeMultiplier.getValue(); - } - */ - - return -0.8; - } -} // namespace - -bool AB_THEME_CLASS::isLightTheme() const -{ - return this->isLight_; -} - -void AB_THEME_CLASS::update() -{ - this->actuallyUpdate(this->themeHue, - getMultiplierByTheme(this->themeName.getValue())); - - this->updated.invoke(); -} - -void AB_THEME_CLASS::actuallyUpdate(double hue, double multiplier) -{ - this->isLight_ = multiplier > 0; - bool lightWin = isLight_; - - // QColor themeColor = QColor::fromHslF(hue, 0.43, 0.5); - QColor themeColor = QColor::fromHslF(hue, 0.8, 0.5); - QColor themeColorNoSat = QColor::fromHslF(hue, 0, 0.5); - - qreal sat = 0; - // 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); - }; - - /// WINDOW - { -#ifdef Q_OS_LINUX - this->window.background = lightWin ? "#fff" : QColor(61, 60, 56); -#else - this->window.background = lightWin ? "#fff" : "#111"; -#endif - - 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 = // - this->messages.textColors.regular = isLight_ ? "#000" : "#fff"; - - QColor highlighted = lightWin ? QColor("#ff0000") : QColor("#ee6166"); - - /// TABS - if (lightWin) - { - 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")}, - {this->accent, this->accent, this->accent}}; - } - else - { - 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")}, - {this->accent, this->accent, this->accent}}; - } - - // scrollbar - this->scrollbars.highlights.highlight = QColor("#ee6166"); - this->scrollbars.highlights.subscription = QColor("#C466FF"); - - // this->tabs.newMessage = { - // fg, - // {QBrush(blendColors(themeColor, "#ccc", 0.9), Qt::FDiagPattern), - // QBrush(blendColors(themeColor, "#ccc", 0.9), Qt::FDiagPattern), - // QBrush(blendColors(themeColorNoSat, "#ccc", 0.9), - // Qt::FDiagPattern)}}; - - // this->tabs.newMessage = { - // fg, - // {QBrush(blendColors(themeColor, "#666", 0.7), - // Qt::FDiagPattern), - // QBrush(blendColors(themeColor, "#666", 0.5), - // Qt::FDiagPattern), - // QBrush(blendColors(themeColorNoSat, "#666", 0.7), - // Qt::FDiagPattern)}}; - // this->tabs.highlighted = {fg, {QColor("#777"), - // QColor("#777"), QColor("#666")}}; - - this->tabs.dividerLine = - this->tabs.selected.backgrounds.regular.color(); - } - - // Message - this->messages.textColors.link = - isLight_ ? QColor(66, 134, 244) : QColor(66, 134, 244); - this->messages.textColors.system = QColor(140, 127, 127); - this->messages.textColors.chatPlaceholder = - isLight_ ? QColor(175, 159, 159) : QColor(93, 85, 85); - - this->messages.backgrounds.regular = getColor(0, sat, 1); - this->messages.backgrounds.alternate = getColor(0, sat, 0.96); - - // this->messages.backgrounds.resub - // this->messages.backgrounds.whisper - this->messages.disabled = getColor(0, sat, 1, 0.6); - // this->messages.seperator = - // this->messages.seperatorInner = - - int complementaryGray = this->isLightTheme() ? 20 : 230; - this->messages.highlightAnimationStart = - QColor(complementaryGray, complementaryGray, complementaryGray, 110); - this->messages.highlightAnimationEnd = - QColor(complementaryGray, complementaryGray, complementaryGray, 0); - - // Scrollbar - this->scrollbars.background = QColor(0, 0, 0, 0); - // this->scrollbars.background = splits.background; - // this->scrollbars.background.setAlphaF(qreal(0.2)); - this->scrollbars.thumb = getColor(0, sat, 0.70); - this->scrollbars.thumbSelected = getColor(0, sat, 0.65); - - // tooltip - this->tooltip.background = QColor(0, 0, 0); - this->tooltip.text = QColor(255, 255, 255); - - // Selection - this->messages.selection = - isLightTheme() ? QColor(0, 0, 0, 64) : QColor(255, 255, 255, 64); -} - -QColor AB_THEME_CLASS::blendColors(const QColor &color1, const QColor &color2, - qreal ratio) -{ - 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); - - return QColor(r, g, b, 255); -} - -#ifndef AB_CUSTOM_THEME -Theme *getTheme() -{ - static auto theme = [] { - auto theme = new Theme(); - theme->update(); - return theme; - }(); - - return theme; -} -#endif - -} // namespace chatterino diff --git a/src/BaseTheme.hpp b/src/BaseTheme.hpp deleted file mode 100644 index e04fce285..000000000 --- a/src/BaseTheme.hpp +++ /dev/null @@ -1,121 +0,0 @@ -#ifndef AB_THEME_H -#define AB_THEME_H - -#include -#include -#include - -#ifdef AB_CUSTOM_THEME -# define AB_THEME_CLASS BaseTheme -#else -# define AB_THEME_CLASS Theme -#endif - -namespace chatterino { - -class Theme; - -class AB_THEME_CLASS -{ -public: - bool isLightTheme() const; - - struct TabColors { - QColor text; - struct { - QBrush regular; - QBrush hover; - QBrush unfocused; - } backgrounds; - struct { - QColor regular; - QColor hover; - QColor unfocused; - } line; - }; - - QColor accent{"#00aeef"}; - - /// WINDOW - struct { - QColor background; - QColor text; - QColor borderUnfocused; - QColor borderFocused; - } window; - - /// TABS - struct { - TabColors regular; - TabColors newMessage; - TabColors highlighted; - TabColors selected; - QColor border; - QColor dividerLine; - } tabs; - - /// MESSAGES - struct { - struct { - QColor regular; - QColor caret; - QColor link; - QColor system; - QColor chatPlaceholder; - } textColors; - - struct { - QColor regular; - QColor alternate; - // QColor whisper; - } backgrounds; - - QColor disabled; - // QColor seperator; - // QColor seperatorInner; - QColor selection; - - QColor highlightAnimationStart; - QColor highlightAnimationEnd; - } messages; - - /// SCROLLBAR - struct { - QColor background; - QColor thumb; - QColor thumbSelected; - struct { - QColor highlight; - QColor subscription; - } highlights; - } scrollbars; - - /// TOOLTIP - struct { - QColor text; - QColor background; - } tooltip; - - void update(); - virtual void actuallyUpdate(double hue, double multiplier); - QColor blendColors(const QColor &color1, const QColor &color2, qreal ratio); - - pajlada::Signals::NoArgSignal updated; - - QStringSetting themeName{"/appearance/theme/name", "Dark"}; - DoubleSetting themeHue{"/appearance/theme/hue", 0.0}; - -private: - bool isLight_ = false; -}; - -// Implemented in parent project if AB_CUSTOM_THEME is set. -// Otherwise implemented in BaseThemecpp -Theme *getTheme(); - -} // namespace chatterino - -#ifdef CHATTERINO -# include "singletons/Theme.hpp" -#endif -#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0e976dd47..c24e7d35b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,8 +6,6 @@ set(SOURCE_FILES Application.hpp BaseSettings.cpp BaseSettings.hpp - BaseTheme.cpp - BaseTheme.hpp BrowserExtension.cpp BrowserExtension.hpp RunGui.cpp @@ -677,7 +675,6 @@ endif () target_compile_definitions(${LIBRARY_PROJECT} PUBLIC CHATTERINO UNICODE - AB_CUSTOM_THEME AB_CUSTOM_SETTINGS IRC_STATIC IRC_NAMESPACE=Communi diff --git a/src/singletons/Theme.cpp b/src/singletons/Theme.cpp index bc506f9a6..635f31b0b 100644 --- a/src/singletons/Theme.cpp +++ b/src/singletons/Theme.cpp @@ -10,8 +10,53 @@ #define LOOKUP_COLOR_COUNT 360 +namespace { +double getMultiplierByTheme(const QString &themeName) +{ + 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; + } + /* + else if (themeName == "Custom") + { + return getSettings()->customThemeMultiplier.getValue(); + } + */ + + return -0.8; +} +} // namespace + namespace chatterino { +bool Theme::isLightTheme() const +{ + return this->isLight_; +} + +QColor Theme::blendColors(const QColor &color1, const QColor &color2, + qreal ratio) +{ + 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); + + return QColor(r, g, b, 255); +} + Theme::Theme() { this->update(); @@ -28,19 +73,161 @@ Theme::Theme() false); } +void Theme::update() +{ + this->actuallyUpdate(this->themeHue, + getMultiplierByTheme(this->themeName.getValue())); + + this->updated.invoke(); +} + // hue: theme color (0 - 1) // multiplier: 1 = white, 0.8 = light, -0.8 dark, -1 black void Theme::actuallyUpdate(double hue, double multiplier) { - BaseTheme::actuallyUpdate(hue, multiplier); + this->isLight_ = multiplier > 0; + bool lightWin = isLight_; + + // QColor themeColor = QColor::fromHslF(hue, 0.43, 0.5); + QColor themeColor = QColor::fromHslF(hue, 0.8, 0.5); + QColor themeColorNoSat = QColor::fromHslF(hue, 0, 0.5); + + const auto sat = qreal(0); + const auto isLight = this->isLightTheme(); + const auto flat = isLight; 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; + /// WINDOW + { +#ifdef Q_OS_LINUX + this->window.background = lightWin ? "#fff" : QColor(61, 60, 56); +#else + this->window.background = lightWin ? "#fff" : "#111"; +#endif + + 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 = // + this->messages.textColors.regular = isLight_ ? "#000" : "#fff"; + + QColor highlighted = lightWin ? QColor("#ff0000") : QColor("#ee6166"); + + /// TABS + if (lightWin) + { + 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")}, + {this->accent, this->accent, this->accent}}; + } + else + { + 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")}, + {this->accent, this->accent, this->accent}}; + } + + // scrollbar + this->scrollbars.highlights.highlight = QColor("#ee6166"); + this->scrollbars.highlights.subscription = QColor("#C466FF"); + + // this->tabs.newMessage = { + // fg, + // {QBrush(blendColors(themeColor, "#ccc", 0.9), Qt::FDiagPattern), + // QBrush(blendColors(themeColor, "#ccc", 0.9), Qt::FDiagPattern), + // QBrush(blendColors(themeColorNoSat, "#ccc", 0.9), + // Qt::FDiagPattern)}}; + + // this->tabs.newMessage = { + // fg, + // {QBrush(blendColors(themeColor, "#666", 0.7), + // Qt::FDiagPattern), + // QBrush(blendColors(themeColor, "#666", 0.5), + // Qt::FDiagPattern), + // QBrush(blendColors(themeColorNoSat, "#666", 0.7), + // Qt::FDiagPattern)}}; + // this->tabs.highlighted = {fg, {QColor("#777"), + // QColor("#777"), QColor("#666")}}; + + this->tabs.dividerLine = + this->tabs.selected.backgrounds.regular.color(); + } + + // Message + this->messages.textColors.link = + isLight_ ? QColor(66, 134, 244) : QColor(66, 134, 244); + this->messages.textColors.system = QColor(140, 127, 127); + this->messages.textColors.chatPlaceholder = + isLight_ ? QColor(175, 159, 159) : QColor(93, 85, 85); + + this->messages.backgrounds.regular = getColor(0, sat, 1); + this->messages.backgrounds.alternate = getColor(0, sat, 0.96); + + // this->messages.backgrounds.resub + // this->messages.backgrounds.whisper + this->messages.disabled = getColor(0, sat, 1, 0.6); + // this->messages.seperator = + // this->messages.seperatorInner = + + int complementaryGray = this->isLightTheme() ? 20 : 230; + this->messages.highlightAnimationStart = + QColor(complementaryGray, complementaryGray, complementaryGray, 110); + this->messages.highlightAnimationEnd = + QColor(complementaryGray, complementaryGray, complementaryGray, 0); + + // Scrollbar + this->scrollbars.background = QColor(0, 0, 0, 0); + // this->scrollbars.background = splits.background; + // this->scrollbars.background.setAlphaF(qreal(0.2)); + this->scrollbars.thumb = getColor(0, sat, 0.70); + this->scrollbars.thumbSelected = getColor(0, sat, 0.65); + + // tooltip + this->tooltip.background = QColor(0, 0, 0); + this->tooltip.text = QColor(255, 255, 255); + + // Selection + this->messages.selection = + isLightTheme() ? QColor(0, 0, 0, 64) : QColor(255, 255, 255, 64); if (this->isLightTheme()) { diff --git a/src/singletons/Theme.hpp b/src/singletons/Theme.hpp index 9af05f543..ea49457e9 100644 --- a/src/singletons/Theme.hpp +++ b/src/singletons/Theme.hpp @@ -1,6 +1,5 @@ #pragma once -#include "BaseTheme.hpp" #include "common/Singleton.hpp" #include "util/RapidJsonSerializeQString.hpp" @@ -13,11 +12,89 @@ namespace chatterino { class WindowManager; -class Theme final : public Singleton, public BaseTheme +class Theme final : public Singleton { public: Theme(); + bool isLightTheme() const; + + struct TabColors { + QColor text; + struct { + QBrush regular; + QBrush hover; + QBrush unfocused; + } backgrounds; + struct { + QColor regular; + QColor hover; + QColor unfocused; + } line; + }; + + QColor accent{"#00aeef"}; + + /// WINDOW + struct { + QColor background; + QColor text; + QColor borderUnfocused; + QColor borderFocused; + } window; + + /// TABS + struct { + TabColors regular; + TabColors newMessage; + TabColors highlighted; + TabColors selected; + QColor border; + QColor dividerLine; + } tabs; + + /// MESSAGES + struct { + struct { + QColor regular; + QColor caret; + QColor link; + QColor system; + QColor chatPlaceholder; + } textColors; + + struct { + QColor regular; + QColor alternate; + // QColor whisper; + } backgrounds; + + QColor disabled; + // QColor seperator; + // QColor seperatorInner; + QColor selection; + + QColor highlightAnimationStart; + QColor highlightAnimationEnd; + } messages; + + /// SCROLLBAR + struct { + QColor background; + QColor thumb; + QColor thumbSelected; + struct { + QColor highlight; + QColor subscription; + } highlights; + } scrollbars; + + /// TOOLTIP + struct { + QColor text; + QColor background; + } tooltip; + /// SPLITS struct { QColor messageSeperator; @@ -55,13 +132,22 @@ public: } buttons; void normalizeColor(QColor &color); + void update(); + QColor blendColors(const QColor &color1, const QColor &color2, qreal ratio); + + pajlada::Signals::NoArgSignal updated; + + QStringSetting themeName{"/appearance/theme/name", "Dark"}; + DoubleSetting themeHue{"/appearance/theme/hue", 0.0}; private: - void actuallyUpdate(double hue, double multiplier) override; + bool isLight_ = false; + void actuallyUpdate(double hue, double multiplier); pajlada::Signals::NoArgSignal repaintVisibleChatWidgets_; friend class WindowManager; }; +Theme *getTheme(); } // namespace chatterino diff --git a/src/widgets/BaseWidget.cpp b/src/widgets/BaseWidget.cpp index 7a1654924..70aeb34e6 100644 --- a/src/widgets/BaseWidget.cpp +++ b/src/widgets/BaseWidget.cpp @@ -1,9 +1,9 @@ #include "widgets/BaseWidget.hpp" #include "BaseSettings.hpp" -#include "BaseTheme.hpp" #include "common/QLogging.hpp" #include "controllers/hotkeys/HotkeyController.hpp" +#include "singletons/Theme.hpp" #include "widgets/BaseWindow.hpp" #include diff --git a/src/widgets/BaseWindow.cpp b/src/widgets/BaseWindow.cpp index 008c55a69..0cbd80f0b 100644 --- a/src/widgets/BaseWindow.cpp +++ b/src/widgets/BaseWindow.cpp @@ -1,8 +1,8 @@ #include "BaseWindow.hpp" #include "BaseSettings.hpp" -#include "BaseTheme.hpp" #include "boost/algorithm/algorithm.hpp" +#include "singletons/Theme.hpp" #include "util/DebugCount.hpp" #include "util/PostToThread.hpp" #include "util/WindowsHelper.hpp" diff --git a/src/widgets/TooltipWidget.cpp b/src/widgets/TooltipWidget.cpp index 6aac584b5..ed82383e0 100644 --- a/src/widgets/TooltipWidget.cpp +++ b/src/widgets/TooltipWidget.cpp @@ -1,6 +1,5 @@ #include "TooltipWidget.hpp" -#include "BaseTheme.hpp" #include "singletons/Fonts.hpp" #include diff --git a/src/widgets/helper/Button.cpp b/src/widgets/helper/Button.cpp index 0d7067937..43c943665 100644 --- a/src/widgets/helper/Button.cpp +++ b/src/widgets/helper/Button.cpp @@ -5,7 +5,7 @@ #include #include -#include "BaseTheme.hpp" +#include "singletons/Theme.hpp" #include "util/FunctionEventFilter.hpp" namespace chatterino { diff --git a/src/widgets/helper/TitlebarButton.cpp b/src/widgets/helper/TitlebarButton.cpp index d946dae0b..1d9a2b81d 100644 --- a/src/widgets/helper/TitlebarButton.cpp +++ b/src/widgets/helper/TitlebarButton.cpp @@ -1,9 +1,9 @@ #include "TitlebarButton.hpp" -#include "BaseTheme.hpp" - #include +#include "singletons/Theme.hpp" + namespace chatterino { TitleBarButton::TitleBarButton()