From 43cf7620aedb49783afacd6a0a0b3c088b3d26f1 Mon Sep 17 00:00:00 2001 From: fourtf Date: Thu, 2 Feb 2017 01:23:26 +0100 Subject: [PATCH] added settings for theme and theme hue --- colorscheme.cpp | 41 ++++++++++++++++++++++++++++++++++++++ colorscheme.h | 9 ++++++++- main.cpp | 3 ++- settings.cpp | 3 ++- settings.h | 1 + widgets/notebookbutton.cpp | 2 +- widgets/notebooktab.cpp | 2 +- widgets/settingsdialog.cpp | 40 +++++++++++++++++++++++++++++++++++++ windows.cpp | 8 ++++++++ windows.h | 1 + 10 files changed, 105 insertions(+), 5 deletions(-) diff --git a/colorscheme.cpp b/colorscheme.cpp index c7ca32d09..8487fa4b0 100644 --- a/colorscheme.cpp +++ b/colorscheme.cpp @@ -1,11 +1,50 @@ #define LOOKUP_COLOR_COUNT 360 #include "colorscheme.h" +#include "settings.h" +#include "windows.h" #include namespace chatterino { +void +ColorScheme::init() +{ + static bool initiated = false; + + if (!initiated) { + initiated = true; + ColorScheme::getInstance().update(); + Settings::getInstance().theme.valueChanged.connect( + [](const QString &) { ColorScheme::getInstance().update(); }); + Settings::getInstance().themeHue.valueChanged.connect( + [](const float &) { ColorScheme::getInstance().update(); }); + + ColorScheme::getInstance().updated.connect( + [] { Windows::repaintVisibleChatWidgets(); }); + } +} + +void +ColorScheme::update() +{ + QString theme = Settings::getInstance().theme.get(); + theme = theme.toLower(); + + qreal hue = Settings::getInstance().themeHue.get(); + + if (theme == "light") { + setColors(hue, 0.8); + } else if (theme == "white") { + setColors(hue, 1); + } else if (theme == "black") { + setColors(hue, -1); + } else { + setColors(hue, -0.8); + } +} + // hue: theme color (0 - 1) // multiplyer: 1 = white, 0.8 = light, -0.8 dark, -1 black void @@ -69,6 +108,8 @@ ColorScheme::setColors(float hue, float multiplyer) "border:" + TabSelectedBackground.name() + ";" + "color:" + Text.name() + ";" + "selection-background-color:" + TabSelectedBackground.name(); + + updated(); } void ColorScheme::fillLookupTableValues(qreal (&array)[360], qreal from, diff --git a/colorscheme.h b/colorscheme.h index 9d82b94cb..0711978ba 100644 --- a/colorscheme.h +++ b/colorscheme.h @@ -3,6 +3,7 @@ #include #include +#include namespace chatterino { @@ -68,15 +69,21 @@ public: return instance; } + void init(); void normalizeColor(QColor &color); - void setColors(float hue, float multiplyer); + void update(); + + boost::signals2::signal updated; private: ColorScheme() + : updated() { } + void setColors(float hue, float multiplyer); + qreal middleLookupTable[360] = {}; qreal minLookupTable[360] = {}; diff --git a/main.cpp b/main.cpp index 35f1861b9..72ea0727f 100644 --- a/main.cpp +++ b/main.cpp @@ -10,6 +10,7 @@ #include #include +#include using namespace chatterino; using namespace chatterino::widgets; @@ -24,7 +25,7 @@ main(int argc, char *argv[]) Emojis::loadEmojis(); Emotes::loadGlobalEmotes(); - ColorScheme::getInstance().setColors(0, -0.8); + ColorScheme::getInstance().init(); Windows::load(); diff --git a/settings.cpp b/settings.cpp index e93a97ab4..874c655d7 100644 --- a/settings.cpp +++ b/settings.cpp @@ -16,6 +16,7 @@ Settings::Settings() , portable(false) , wordTypeMask(messages::Word::Default) , theme(this->settingsItems, "theme", "dark") + , themeHue(this->settingsItems, "themeHue", 0) , selectedUser(this->settingsItems, "selectedUser", "") , emoteScale(this->settingsItems, "emoteScale", 1.0) , mouseScrollMultiplier(this->settingsItems, "mouseScrollMultiplier", 1.0) @@ -45,7 +46,7 @@ Settings::Settings() , enableGifAnimations(this->settingsItems, "enableGifAnimations", true) , enableGifs(this->settingsItems, "enableGifs", true) , inlineWhispers(this->settingsItems, "inlineWhispers", true) - , windowTopMost(this->settingsItems, "windowTopMost", true) + , windowTopMost(this->settingsItems, "windowTopMost", false) , hideTabX(this->settingsItems, "hideTabX", false) { this->showTimestamps.valueChanged.connect( diff --git a/settings.h b/settings.h index 9085046dc..f147dfd35 100644 --- a/settings.h +++ b/settings.h @@ -80,6 +80,7 @@ private: public: Setting theme; + Setting themeHue; Setting selectedUser; Setting emoteScale; Setting mouseScrollMultiplier; diff --git a/widgets/notebookbutton.cpp b/widgets/notebookbutton.cpp index d4742f6f4..c37fb7954 100644 --- a/widgets/notebookbutton.cpp +++ b/widgets/notebookbutton.cpp @@ -21,7 +21,7 @@ NotebookButton::paintEvent(QPaintEvent *) QColor background; QColor foreground; - auto colorScheme = ColorScheme::getInstance(); + auto &colorScheme = ColorScheme::getInstance(); if (mouseDown) { background = colorScheme.TabSelectedBackground; diff --git a/widgets/notebooktab.cpp b/widgets/notebooktab.cpp index fca50fd40..2ba6d5693 100644 --- a/widgets/notebooktab.cpp +++ b/widgets/notebooktab.cpp @@ -91,7 +91,7 @@ NotebookTab::paintEvent(QPaintEvent *) QColor fg = QColor(0, 0, 0); - auto colorScheme = ColorScheme::getInstance(); + auto &colorScheme = ColorScheme::getInstance(); if (this->selected) { painter.fillRect(rect(), colorScheme.TabSelectedBackground); diff --git a/widgets/settingsdialog.cpp b/widgets/settingsdialog.cpp index b5f59f170..a23844f5f 100644 --- a/widgets/settingsdialog.cpp +++ b/widgets/settingsdialog.cpp @@ -1,5 +1,6 @@ #include "widgets/settingsdialog.h" #include "widgets/settingsdialogtab.h" +#include "windows.h" #include #include @@ -80,6 +81,45 @@ SettingsDialog::addTabs() form->addRow("Theme color:", slider); form->addRow("Font:", font); + // theme + combo->addItem("White"); + combo->addItem("Light"); + combo->addItem("Dark"); + combo->addItem("Black"); + + QString theme = settings.theme.get(); + theme = theme.toLower(); + + if (theme == "light") { + combo->setCurrentIndex(0); + } else if (theme == "white") { + combo->setCurrentIndex(1); + } else if (theme == "black") { + combo->setCurrentIndex(3); + } else { + combo->setCurrentIndex(2); + } + + QObject::connect(combo, &QComboBox::currentTextChanged, this, + [this, &settings](const QString &value) { + settings.theme.set(value); + }); + + // theme hue + slider->setMinimum(0); + slider->setMaximum(1000); + + float hue = settings.themeHue.get(); + + slider->setValue(std::min(std::max(hue, (float)0.0), (float)1.0) * + 1000); + + QObject::connect(slider, &QSlider::valueChanged, this, + [this, &settings](int value) { + settings.themeHue.set(value / 1000.0); + Windows::updateAll(); + }); + group->setLayout(form); vbox->addWidget(group); diff --git a/windows.cpp b/windows.cpp index 518cb124a..317deedb5 100644 --- a/windows.cpp +++ b/windows.cpp @@ -38,6 +38,14 @@ Windows::repaintVisibleChatWidgets(Channel *channel) } } +void +Windows::updateAll() +{ + if (Windows::mainWindow != nullptr) { + Windows::mainWindow->update(); + } +} + void Windows::load() { diff --git a/windows.h b/windows.h index c13fca399..0265815dc 100644 --- a/windows.h +++ b/windows.h @@ -12,6 +12,7 @@ class Windows public: static void layoutVisibleChatWidgets(Channel *channel = NULL); static void repaintVisibleChatWidgets(Channel *channel = NULL); + static void updateAll(); static widgets::MainWindow & getMainWindow()