added settings for theme and theme hue

This commit is contained in:
fourtf 2017-02-02 01:23:26 +01:00
parent 0343371443
commit 43cf7620ae
10 changed files with 105 additions and 5 deletions

View file

@ -1,11 +1,50 @@
#define LOOKUP_COLOR_COUNT 360 #define LOOKUP_COLOR_COUNT 360
#include "colorscheme.h" #include "colorscheme.h"
#include "settings.h"
#include "windows.h"
#include <QColor> #include <QColor>
namespace chatterino { 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) // hue: theme color (0 - 1)
// multiplyer: 1 = white, 0.8 = light, -0.8 dark, -1 black // multiplyer: 1 = white, 0.8 = light, -0.8 dark, -1 black
void void
@ -69,6 +108,8 @@ ColorScheme::setColors(float hue, float multiplyer)
"border:" + TabSelectedBackground.name() + ";" + "border:" + TabSelectedBackground.name() + ";" +
"color:" + Text.name() + ";" + "color:" + Text.name() + ";" +
"selection-background-color:" + TabSelectedBackground.name(); "selection-background-color:" + TabSelectedBackground.name();
updated();
} }
void ColorScheme::fillLookupTableValues(qreal (&array)[360], qreal from, void ColorScheme::fillLookupTableValues(qreal (&array)[360], qreal from,

View file

@ -3,6 +3,7 @@
#include <QBrush> #include <QBrush>
#include <QColor> #include <QColor>
#include <boost/signals2.hpp>
namespace chatterino { namespace chatterino {
@ -68,15 +69,21 @@ public:
return instance; return instance;
} }
void init();
void normalizeColor(QColor &color); void normalizeColor(QColor &color);
void setColors(float hue, float multiplyer); void update();
boost::signals2::signal<void()> updated;
private: private:
ColorScheme() ColorScheme()
: updated()
{ {
} }
void setColors(float hue, float multiplyer);
qreal middleLookupTable[360] = {}; qreal middleLookupTable[360] = {};
qreal minLookupTable[360] = {}; qreal minLookupTable[360] = {};

View file

@ -10,6 +10,7 @@
#include <QApplication> #include <QApplication>
#include <QClipboard> #include <QClipboard>
#include <boost/signals2.hpp>
using namespace chatterino; using namespace chatterino;
using namespace chatterino::widgets; using namespace chatterino::widgets;
@ -24,7 +25,7 @@ main(int argc, char *argv[])
Emojis::loadEmojis(); Emojis::loadEmojis();
Emotes::loadGlobalEmotes(); Emotes::loadGlobalEmotes();
ColorScheme::getInstance().setColors(0, -0.8); ColorScheme::getInstance().init();
Windows::load(); Windows::load();

View file

@ -16,6 +16,7 @@ Settings::Settings()
, portable(false) , portable(false)
, wordTypeMask(messages::Word::Default) , wordTypeMask(messages::Word::Default)
, theme(this->settingsItems, "theme", "dark") , theme(this->settingsItems, "theme", "dark")
, themeHue(this->settingsItems, "themeHue", 0)
, selectedUser(this->settingsItems, "selectedUser", "") , selectedUser(this->settingsItems, "selectedUser", "")
, emoteScale(this->settingsItems, "emoteScale", 1.0) , emoteScale(this->settingsItems, "emoteScale", 1.0)
, mouseScrollMultiplier(this->settingsItems, "mouseScrollMultiplier", 1.0) , mouseScrollMultiplier(this->settingsItems, "mouseScrollMultiplier", 1.0)
@ -45,7 +46,7 @@ Settings::Settings()
, enableGifAnimations(this->settingsItems, "enableGifAnimations", true) , enableGifAnimations(this->settingsItems, "enableGifAnimations", true)
, enableGifs(this->settingsItems, "enableGifs", true) , enableGifs(this->settingsItems, "enableGifs", true)
, inlineWhispers(this->settingsItems, "inlineWhispers", true) , inlineWhispers(this->settingsItems, "inlineWhispers", true)
, windowTopMost(this->settingsItems, "windowTopMost", true) , windowTopMost(this->settingsItems, "windowTopMost", false)
, hideTabX(this->settingsItems, "hideTabX", false) , hideTabX(this->settingsItems, "hideTabX", false)
{ {
this->showTimestamps.valueChanged.connect( this->showTimestamps.valueChanged.connect(

View file

@ -80,6 +80,7 @@ private:
public: public:
Setting<QString> theme; Setting<QString> theme;
Setting<float> themeHue;
Setting<QString> selectedUser; Setting<QString> selectedUser;
Setting<float> emoteScale; Setting<float> emoteScale;
Setting<float> mouseScrollMultiplier; Setting<float> mouseScrollMultiplier;

View file

@ -21,7 +21,7 @@ NotebookButton::paintEvent(QPaintEvent *)
QColor background; QColor background;
QColor foreground; QColor foreground;
auto colorScheme = ColorScheme::getInstance(); auto &colorScheme = ColorScheme::getInstance();
if (mouseDown) { if (mouseDown) {
background = colorScheme.TabSelectedBackground; background = colorScheme.TabSelectedBackground;

View file

@ -91,7 +91,7 @@ NotebookTab::paintEvent(QPaintEvent *)
QColor fg = QColor(0, 0, 0); QColor fg = QColor(0, 0, 0);
auto colorScheme = ColorScheme::getInstance(); auto &colorScheme = ColorScheme::getInstance();
if (this->selected) { if (this->selected) {
painter.fillRect(rect(), colorScheme.TabSelectedBackground); painter.fillRect(rect(), colorScheme.TabSelectedBackground);

View file

@ -1,5 +1,6 @@
#include "widgets/settingsdialog.h" #include "widgets/settingsdialog.h"
#include "widgets/settingsdialogtab.h" #include "widgets/settingsdialogtab.h"
#include "windows.h"
#include <QComboBox> #include <QComboBox>
#include <QFile> #include <QFile>
@ -80,6 +81,45 @@ SettingsDialog::addTabs()
form->addRow("Theme color:", slider); form->addRow("Theme color:", slider);
form->addRow("Font:", font); 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); group->setLayout(form);
vbox->addWidget(group); vbox->addWidget(group);

View file

@ -38,6 +38,14 @@ Windows::repaintVisibleChatWidgets(Channel *channel)
} }
} }
void
Windows::updateAll()
{
if (Windows::mainWindow != nullptr) {
Windows::mainWindow->update();
}
}
void void
Windows::load() Windows::load()
{ {

View file

@ -12,6 +12,7 @@ class Windows
public: public:
static void layoutVisibleChatWidgets(Channel *channel = NULL); static void layoutVisibleChatWidgets(Channel *channel = NULL);
static void repaintVisibleChatWidgets(Channel *channel = NULL); static void repaintVisibleChatWidgets(Channel *channel = NULL);
static void updateAll();
static widgets::MainWindow & static widgets::MainWindow &
getMainWindow() getMainWindow()