working on something

This commit is contained in:
Rasmus Karlsson
2017-07-02 12:36:50 +02:00
parent f2ef14422b
commit 3c2ee99731
9 changed files with 116 additions and 99 deletions
+5 -6
View File
@@ -1,7 +1,6 @@
#define LOOKUP_COLOR_COUNT 360 #define LOOKUP_COLOR_COUNT 360
#include "colorscheme.hpp" #include "colorscheme.hpp"
#include "settingsmanager.hpp"
#include "windowmanager.hpp" #include "windowmanager.hpp"
#include <QColor> #include <QColor>
@@ -28,14 +27,16 @@ double getMultiplierByTheme(const std::string &themeName)
} // namespace detail } // namespace detail
ColorScheme::ColorScheme(WindowManager &windowManager) ColorScheme::ColorScheme(WindowManager &windowManager)
: themeName("/appearance/theme/name", "Dark")
, themeHue("/appearance/theme/hue", 0.0)
{ {
this->update(); this->update();
SettingsManager::getInstance().themeName.getValueChangedSignal().connect([=](const auto &) { this->themeName.getValueChangedSignal().connect([=](const auto &) {
this->update(); // this->update(); //
}); });
SettingsManager::getInstance().themeHue.getValueChangedSignal().connect([=](const auto &) { this->themeHue.getValueChangedSignal().connect([=](const auto &) {
this->update(); // this->update(); //
}); });
@@ -46,9 +47,7 @@ ColorScheme::ColorScheme(WindowManager &windowManager)
void ColorScheme::update() void ColorScheme::update()
{ {
SettingsManager &settings = SettingsManager::getInstance(); this->setColors(this->themeHue, detail::getMultiplierByTheme(this->themeName));
this->setColors(settings.themeHue, detail::getMultiplierByTheme(settings.themeName));
} }
// hue: theme color (0 - 1) // hue: theme color (0 - 1)
+5 -1
View File
@@ -3,6 +3,7 @@
#include <QBrush> #include <QBrush>
#include <QColor> #include <QColor>
#include <boost/signals2.hpp> #include <boost/signals2.hpp>
#include <pajlada/settings/setting.hpp>
namespace chatterino { namespace chatterino {
@@ -75,6 +76,9 @@ public:
boost::signals2::signal<void()> updated; boost::signals2::signal<void()> updated;
private: private:
pajlada::Settings::Setting<std::string> themeName;
pajlada::Settings::Setting<double> themeHue;
void setColors(double hue, double multiplier); void setColors(double hue, double multiplier);
double middleLookupTable[360] = {}; double middleLookupTable[360] = {};
@@ -83,7 +87,7 @@ private:
void fillLookupTableValues(double (&array)[360], double from, double to, double fromValue, void fillLookupTableValues(double (&array)[360], double from, double to, double fromValue,
double toValue); double toValue);
bool lightTheme; bool lightTheme = false;
}; };
} // namespace chatterino } // namespace chatterino
-2
View File
@@ -14,8 +14,6 @@ SettingsManager::SettingsManager()
, showTimestamps("/appearance/messages/showTimestamps", true) , showTimestamps("/appearance/messages/showTimestamps", true)
, showTimestampSeconds("/appearance/messages/showTimestampSeconds", true) , showTimestampSeconds("/appearance/messages/showTimestampSeconds", true)
, showBadges("/appearance/messages/showBadges", true) , showBadges("/appearance/messages/showBadges", true)
, themeName("/appearance/theme/name", "Dark")
, themeHue("/appearance/theme/hue", 0.0)
, selectedUser(_settingsItems, "selectedUser", "") , selectedUser(_settingsItems, "selectedUser", "")
, emoteScale(_settingsItems, "emoteScale", 1.0) , emoteScale(_settingsItems, "emoteScale", 1.0)
, mouseScrollMultiplier(_settingsItems, "mouseScrollMultiplier", 1.0) , mouseScrollMultiplier(_settingsItems, "mouseScrollMultiplier", 1.0)
-2
View File
@@ -42,8 +42,6 @@ public:
pajlada::Settings::Setting<bool> showTimestamps; pajlada::Settings::Setting<bool> showTimestamps;
pajlada::Settings::Setting<bool> showTimestampSeconds; pajlada::Settings::Setting<bool> showTimestampSeconds;
pajlada::Settings::Setting<bool> showBadges; pajlada::Settings::Setting<bool> showBadges;
pajlada::Settings::Setting<std::string> themeName;
pajlada::Settings::Setting<double> themeHue;
// Settings // Settings
Setting<QString> selectedUser; Setting<QString> selectedUser;
+63 -46
View File
@@ -19,47 +19,48 @@ namespace chatterino {
namespace widgets { namespace widgets {
SettingsDialog::SettingsDialog() SettingsDialog::SettingsDialog()
: _snapshot(SettingsManager::getInstance().createSnapshot()) : snapshot(SettingsManager::getInstance().createSnapshot())
{ {
QFile file(":/qss/settings.qss"); QFile file(":/qss/settings.qss");
file.open(QFile::ReadOnly); file.open(QFile::ReadOnly);
QString styleSheet = QLatin1String(file.readAll()); QString styleSheet = QLatin1String(file.readAll());
setStyleSheet(styleSheet); this->setStyleSheet(styleSheet);
QPalette palette; QPalette palette;
palette.setColor(QPalette::Background, QColor("#444")); palette.setColor(QPalette::Background, QColor("#444"));
setPalette(palette); this->setPalette(palette);
_pageStack.setObjectName("pages"); this->ui.pageStack.setObjectName("pages");
setLayout(&_vbox); this->setLayout(&this->ui.vbox);
_vbox.addLayout(&_hbox); this->ui.vbox.addLayout(&this->ui.hbox);
_vbox.addWidget(&_buttonBox); this->ui.vbox.addWidget(&this->ui.buttonBox);
auto tabWidget = new QWidget(); auto tabWidget = new QWidget();
tabWidget->setObjectName("tabWidget"); tabWidget->setObjectName("tabWidget");
tabWidget->setLayout(&_tabs); tabWidget->setLayout(&this->ui.tabs);
tabWidget->setFixedWidth(200); tabWidget->setFixedWidth(200);
_hbox.addWidget(tabWidget); this->ui.hbox.addWidget(tabWidget);
_hbox.addLayout(&_pageStack); this->ui.hbox.addLayout(&this->ui.pageStack);
_buttonBox.addButton(&_okButton, QDialogButtonBox::ButtonRole::AcceptRole); this->ui.buttonBox.addButton(&this->ui.okButton, QDialogButtonBox::ButtonRole::AcceptRole);
_buttonBox.addButton(&_cancelButton, QDialogButtonBox::ButtonRole::RejectRole); this->ui.buttonBox.addButton(&this->ui.cancelButton, QDialogButtonBox::ButtonRole::RejectRole);
QObject::connect(&_okButton, &QPushButton::clicked, this, &SettingsDialog::okButtonClicked); QObject::connect(&this->ui.okButton, &QPushButton::clicked, this,
QObject::connect(&_cancelButton, &QPushButton::clicked, this, &SettingsDialog::okButtonClicked);
QObject::connect(&this->ui.cancelButton, &QPushButton::clicked, this,
&SettingsDialog::cancelButtonClicked); &SettingsDialog::cancelButtonClicked);
_okButton.setText("OK"); this->ui.okButton.setText("OK");
_cancelButton.setText("Cancel"); this->ui.cancelButton.setText("Cancel");
resize(600, 500); this->resize(600, 500);
addTabs(); this->addTabs();
} }
void SettingsDialog::addTabs() void SettingsDialog::addTabs()
@@ -161,7 +162,9 @@ void SettingsDialog::addTabs()
slider->setMinimum(0); slider->setMinimum(0);
slider->setMaximum(1000); slider->setMaximum(1000);
slider->setValue(std::min(std::max(settings.themeHue.getValue(), 0.0), 1.0) * 1000); pajlada::Settings::Setting<double> themeHue("/appearance/theme/hue");
slider->setValue(std::min(std::max(themeHue.getValue(), 0.0), 1.0) * 1000);
hbox->addWidget(slider); hbox->addWidget(slider);
@@ -172,12 +175,15 @@ void SettingsDialog::addTabs()
form->addRow("Theme color:", hbox); form->addRow("Theme color:", hbox);
QObject::connect(slider, &QSlider::valueChanged, this, [&settings, button](int value) { QObject::connect(slider, &QSlider::valueChanged, this, [button](int value) mutable {
settings.themeHue.setValue(value / 1000.0); double newValue = value / 1000.0;
pajlada::Settings::Setting<double> themeHue("/appearance/theme/hue");
themeHue.setValue(newValue);
QPalette pal = button->palette(); QPalette pal = button->palette();
QColor color; QColor color;
color.setHsvF(settings.themeHue.getValue(), 1.0, 1.0, 1.0); color.setHsvF(newValue, 1.0, 1.0, 1.0);
pal.setColor(QPalette::Button, color); pal.setColor(QPalette::Button, color);
button->setAutoFillBackground(true); button->setAutoFillBackground(true);
button->setPalette(pal); button->setPalette(pal);
@@ -193,20 +199,29 @@ void SettingsDialog::addTabs()
form->addRow("", hidePreferencesButton); form->addRow("", hidePreferencesButton);
form->addRow("", hideUserButton); form->addRow("", hideUserButton);
// Theme name {
combo->addItem("White"); // Theme name
combo->addItem("Light"); combo->addItems({
combo->addItem("Dark"); "White", //
combo->addItem("Black"); "Light", //
"Dark", //
"Black", //
});
// combo->addItem("White");
// combo->addItem("Light");
// combo->addItem("Dark");
// combo->addItem("Black");
auto xD = QString::fromStdString(settings.themeName); QString currentComboText = QString::fromStdString(
pajlada::Settings::Setting<std::string>::get("/appearance/theme/name"));
combo->setCurrentText(xD); combo->setCurrentText(currentComboText);
QObject::connect(combo, &QComboBox::currentTextChanged, this, QObject::connect(combo, &QComboBox::currentTextChanged, this, [](const QString &value) {
[&settings](const QString &value) { pajlada::Settings::Setting<std::string>::set("/appearance/theme/name",
settings.themeName.setValue(value.toStdString()); // value.toStdString());
}); });
}
group->setLayout(form); group->setLayout(form);
@@ -317,7 +332,7 @@ void SettingsDialog::addTabs()
addTab(vbox, "Whispers", ":/images/Message_16xLG.png"); addTab(vbox, "Whispers", ":/images/Message_16xLG.png");
// Add stretch // Add stretch
_tabs.addStretch(1); this->ui.tabs.addStretch(1);
} }
void SettingsDialog::addTab(QLayout *layout, QString title, QString imageRes) void SettingsDialog::addTab(QLayout *layout, QString title, QString imageRes)
@@ -330,27 +345,27 @@ void SettingsDialog::addTab(QLayout *layout, QString title, QString imageRes)
tab->setWidget(widget); tab->setWidget(widget);
_tabs.addWidget(tab, 0, Qt::AlignTop); this->ui.tabs.addWidget(tab, 0, Qt::AlignTop);
_pageStack.addWidget(widget); this->ui.pageStack.addWidget(widget);
if (_tabs.count() == 1) { if (this->ui.tabs.count() == 1) {
select(tab); this->select(tab);
} }
} }
void SettingsDialog::select(SettingsDialogTab *tab) void SettingsDialog::select(SettingsDialogTab *tab)
{ {
_pageStack.setCurrentWidget(tab->getWidget()); this->ui.pageStack.setCurrentWidget(tab->getWidget());
if (_selectedTab != nullptr) { if (this->selectedTab != nullptr) {
_selectedTab->setSelected(false); this->selectedTab->setSelected(false);
_selectedTab->setStyleSheet("color: #FFF"); this->selectedTab->setStyleSheet("color: #FFF");
} }
tab->setSelected(true); tab->setSelected(true);
tab->setStyleSheet("background: #555; color: #FFF"); tab->setStyleSheet("background: #555; color: #FFF");
_selectedTab = tab; this->selectedTab = tab;
} }
void SettingsDialog::showDialog() void SettingsDialog::showDialog()
@@ -371,8 +386,9 @@ QCheckBox *SettingsDialog::createCheckbox(const QString &title, Setting<bool> &s
// Set checkbox initial state // Set checkbox initial state
checkbox->setChecked(setting.get()); checkbox->setChecked(setting.get());
QObject::connect(checkbox, &QCheckBox::toggled, this, QObject::connect(checkbox, &QCheckBox::toggled, this, [&setting](bool state) {
[&setting](bool state) { setting.set(state); }); setting.set(state); //
});
return checkbox; return checkbox;
} }
@@ -400,7 +416,8 @@ void SettingsDialog::okButtonClicked()
void SettingsDialog::cancelButtonClicked() void SettingsDialog::cancelButtonClicked()
{ {
_snapshot.apply(); // TODO: Re-implement the snapshot feature properly
this->snapshot.apply();
this->close(); this->close();
} }
+11 -9
View File
@@ -30,21 +30,23 @@ public:
static void showDialog(); static void showDialog();
private: private:
SettingsSnapshot _snapshot; SettingsSnapshot snapshot;
QVBoxLayout _tabs; struct {
QVBoxLayout _vbox; QVBoxLayout tabs;
QHBoxLayout _hbox; QVBoxLayout vbox;
QStackedLayout _pageStack; QHBoxLayout hbox;
QDialogButtonBox _buttonBox; QStackedLayout pageStack;
QPushButton _okButton; QDialogButtonBox buttonBox;
QPushButton _cancelButton; QPushButton okButton;
QPushButton cancelButton;
} ui;
void addTab(QLayout *layout, QString title, QString imageRes); void addTab(QLayout *layout, QString title, QString imageRes);
void addTabs(); void addTabs();
SettingsDialogTab *_selectedTab = nullptr; SettingsDialogTab *selectedTab = nullptr;
/// Widget creation helpers /// Widget creation helpers
QCheckBox *createCheckbox(const QString &title, Setting<bool> &setting); QCheckBox *createCheckbox(const QString &title, Setting<bool> &setting);
+22 -24
View File
@@ -7,41 +7,39 @@
namespace chatterino { namespace chatterino {
namespace widgets { namespace widgets {
SettingsDialogTab::SettingsDialogTab(SettingsDialog *dialog, QString label, QString imageRes) SettingsDialogTab::SettingsDialogTab(SettingsDialog *_dialog, QString _labelText,
: _label(label) QString imageFileName)
, _image(QImage(imageRes)) : dialog(_dialog)
, _dialog(dialog)
, _selected(false)
{ {
setFixedHeight(32); this->ui.labelText = _labelText;
this->ui.image.load(imageFileName);
setCursor(QCursor(Qt::PointingHandCursor)); // XXX: DPI (not sure if this is auto-adjusted with custom DPI)
this->setFixedHeight(32);
setStyleSheet("color: #FFF"); this->setCursor(QCursor(Qt::PointingHandCursor));
this->setStyleSheet("color: #FFF");
} }
void SettingsDialogTab::setSelected(bool selected) void SettingsDialogTab::setSelected(bool _selected)
{ {
if (_selected == selected) if (this->selected == _selected) {
return; return;
}
_selected = selected; this->selected = _selected;
emit selectedChanged(selected); emit selectedChanged(selected);
} }
bool SettingsDialogTab::getSelected() const
{
return _selected;
}
QWidget *SettingsDialogTab::getWidget() QWidget *SettingsDialogTab::getWidget()
{ {
return _widget; return this->ui.widget;
} }
void SettingsDialogTab::setWidget(QWidget *widget) void SettingsDialogTab::setWidget(QWidget *widget)
{ {
_widget = widget; this->ui.widget = widget;
} }
void SettingsDialogTab::paintEvent(QPaintEvent *) void SettingsDialogTab::paintEvent(QPaintEvent *)
@@ -51,15 +49,15 @@ void SettingsDialogTab::paintEvent(QPaintEvent *)
QStyleOption opt; QStyleOption opt;
opt.init(this); opt.init(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); this->style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
int a = (height() - _image.width()) / 2; int a = (this->height() - this->ui.image.width()) / 2;
painter.drawImage(a, a, _image); painter.drawImage(a, a, this->ui.image);
a = a + a + _image.width(); a = a + a + this->ui.image.width();
painter.drawText(QRect(a, 0, width() - a, height()), _label, painter.drawText(QRect(a, 0, width() - a, height()), this->ui.labelText,
QTextOption(Qt::AlignLeft | Qt::AlignVCenter)); QTextOption(Qt::AlignLeft | Qt::AlignVCenter));
} }
@@ -69,7 +67,7 @@ void SettingsDialogTab::mousePressEvent(QMouseEvent *event)
return; return;
} }
_dialog->select(this); this->dialog->select(this);
} }
} // namespace widgets } // namespace widgets
+9 -8
View File
@@ -11,13 +11,11 @@ class SettingsDialog;
class SettingsDialogTab : public QWidget class SettingsDialogTab : public QWidget
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool getSelected READ getSelected WRITE setSelected NOTIFY selectedChanged)
public: public:
SettingsDialogTab(SettingsDialog *_dialog, QString _label, QString imageRes); SettingsDialogTab(SettingsDialog *dialog, QString _label, QString imageFileName);
void setSelected(bool selected); void setSelected(bool selected);
bool getSelected() const;
QWidget *getWidget(); QWidget *getWidget();
void setWidget(QWidget *widget); void setWidget(QWidget *widget);
@@ -28,13 +26,16 @@ private:
void paintEvent(QPaintEvent *); void paintEvent(QPaintEvent *);
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event);
QWidget *_widget; struct {
QString _label; QWidget *widget;
QImage _image; QString labelText;
QImage image;
} ui;
SettingsDialog *_dialog; // Parent settings dialog
SettingsDialog *dialog;
bool _selected; bool selected = false;
}; };
} // namespace widgets } // namespace widgets