mirror-chatterino2/src/widgets/settingspages/appearancepage.cpp

182 lines
6.6 KiB
C++
Raw Normal View History

2018-01-12 23:09:05 +01:00
#include "appearancepage.hpp"
#include <QFontDialog>
#include <QFormLayout>
#include <QGroupBox>
#include <QLabel>
#include <QPushButton>
2018-04-25 20:35:32 +02:00
#include <QScrollArea>
#include <QSlider>
2018-01-12 23:09:05 +01:00
#include <QVBoxLayout>
2018-01-16 00:26:04 +01:00
#include "util/layoutcreator.hpp"
2018-04-25 20:35:32 +02:00
#include "util/removescrollareabackground.hpp"
2018-01-12 23:09:05 +01:00
#define THEME_ITEMS "White", "Light", "Dark", "Black"
2018-04-25 20:35:32 +02:00
#define TAB_X "Show close button"
2018-01-12 23:09:05 +01:00
#define TAB_PREF "Hide preferences button (ctrl+p to show)"
#define TAB_USER "Hide user button"
#define SCROLL_SMOOTH "Enable smooth scrolling"
#define SCROLL_NEWMSG "Enable smooth scrolling for new messages"
2018-04-25 20:35:32 +02:00
#define LAST_MSG "Mark the last message you read (dotted line)"
2018-01-17 18:36:12 +01:00
// clang-format off
#define TIMESTAMP_FORMATS "hh:mm a", "h:mm a", "hh:mm:ss a", "h:mm:ss a", "HH:mm", "H:mm", "HH:mm:ss", "H:mm:ss"
// clang-format on
2018-01-12 23:09:05 +01:00
namespace chatterino {
namespace widgets {
namespace settingspages {
AppearancePage::AppearancePage()
2018-04-25 20:35:32 +02:00
: SettingsPage("Look", ":/images/theme.svg")
2018-01-12 23:09:05 +01:00
{
singletons::SettingManager &settings = singletons::SettingManager::getInstance();
util::LayoutCreator<AppearancePage> layoutCreator(this);
2018-04-25 20:35:32 +02:00
auto scroll = layoutCreator.emplace<QScrollArea>();
auto widget = scroll.emplaceScrollAreaWidget();
util::removeScrollAreaBackground(*scroll, *widget);
auto layout = widget.setLayoutType<QVBoxLayout>();
2018-01-12 23:09:05 +01:00
auto application =
layout.emplace<QGroupBox>("Application").emplace<QVBoxLayout>().withoutMargin();
{
auto form = application.emplace<QFormLayout>();
// clang-format off
2018-04-25 20:35:32 +02:00
form->addRow("Theme:", this->createComboBox({THEME_ITEMS}, singletons::ThemeManager::getInstance().themeName));
form->addRow("Theme color:", this->createThemeColorChanger());
form->addRow("Font:", this->createFontChanger());
form->addRow("Tabs:", this->createCheckBox(TAB_X, settings.hideTabX));
#ifndef USEWINSDK
form->addRow("", this->createCheckBox(TAB_PREF, settings.hidePreferencesButton));
form->addRow("", this->createCheckBox(TAB_USER, settings.hideUserButton));
#endif
form->addRow("Scrolling:", this->createCheckBox(SCROLL_SMOOTH, settings.enableSmoothScrolling));
form->addRow("", this->createCheckBox(SCROLL_NEWMSG, settings.enableSmoothScrollingNewMessages));
2018-01-12 23:09:05 +01:00
// clang-format on
}
2018-04-25 20:35:32 +02:00
auto messages = layout.emplace<QGroupBox>("Messages").emplace<QVBoxLayout>();
2018-01-12 23:09:05 +01:00
{
messages.append(this->createCheckBox("Show timestamp", settings.showTimestamps));
2018-04-25 20:35:32 +02:00
auto tbox = messages.emplace<QHBoxLayout>().withoutMargin();
2018-01-12 23:09:05 +01:00
{
2018-01-17 18:36:12 +01:00
tbox.emplace<QLabel>("timestamp format (a = am/pm):");
2018-01-12 23:09:05 +01:00
tbox.append(this->createComboBox({TIMESTAMP_FORMATS}, settings.timestampFormat));
2018-01-24 15:08:22 +01:00
tbox->addStretch(1);
2018-01-12 23:09:05 +01:00
}
2018-04-25 20:35:32 +02:00
messages.append(this->createCheckBox("Show badges", settings.showBadges));
auto checkbox = this->createCheckBox("Seperate messages", settings.seperateMessages);
checkbox->setEnabled(false);
messages.append(checkbox);
messages.append(
this->createCheckBox("Show message length while typing", settings.showMessageLength));
2018-04-25 20:35:32 +02:00
messages.append(this->createCheckBox(LAST_MSG, settings.showLastMessageIndicator));
}
auto emotes = layout.emplace<QGroupBox>("Emotes").setLayoutType<QVBoxLayout>();
{
emotes.append(this->createCheckBox("Enable Twitch emotes", settings.enableTwitchEmotes));
emotes.append(
this->createCheckBox("Enable BetterTTV emotes for Twitch", settings.enableBttvEmotes));
emotes.append(this->createCheckBox("Enable FrankerFaceZ emotes for Twitch",
settings.enableFfzEmotes));
emotes.append(this->createCheckBox("Enable emojis", settings.enableEmojis));
emotes.append(this->createCheckBox("Enable animations", settings.enableGifAnimations));
2018-01-12 23:09:05 +01:00
}
layout->addStretch(1);
}
QLayout *AppearancePage::createThemeColorChanger()
{
QHBoxLayout *layout = new QHBoxLayout;
auto &themeHue = singletons::ThemeManager::getInstance().themeHue;
// SLIDER
QSlider *slider = new QSlider(Qt::Horizontal);
layout->addWidget(slider);
slider->setValue(std::min(std::max(themeHue.getValue(), 0.0), 1.0) * 100);
2018-01-12 23:09:05 +01:00
// BUTTON
QPushButton *button = new QPushButton;
layout->addWidget(button);
button->setFlat(true);
button->setFixedWidth(64);
2018-02-06 00:10:30 +01:00
auto setButtonColor = [button](int value) mutable {
double newValue = value / 100.0;
2018-02-06 00:10:30 +01:00
singletons::ThemeManager::getInstance().themeHue.setValue(newValue);
2018-01-12 23:09:05 +01:00
QPalette pal = button->palette();
QColor color;
color.setHsvF(newValue, 1.0, 1.0, 1.0);
pal.setColor(QPalette::Button, color);
button->setAutoFillBackground(true);
button->setPalette(pal);
button->update();
2018-02-06 00:10:30 +01:00
};
// SIGNALS
QObject::connect(slider, &QSlider::valueChanged, this, setButtonColor);
2018-01-12 23:09:05 +01:00
2018-02-06 00:10:30 +01:00
setButtonColor(themeHue * 100);
2018-01-12 23:09:05 +01:00
return layout;
}
QLayout *AppearancePage::createFontChanger()
{
QHBoxLayout *layout = new QHBoxLayout;
auto &fontManager = singletons::FontManager::getInstance();
// LABEL
QLabel *label = new QLabel();
layout->addWidget(label);
auto updateFontFamilyLabel = [label, &fontManager](auto) {
label->setText(QString::fromStdString(fontManager.currentFontFamily.getValue()) + ", " +
QString::number(fontManager.currentFontSize) + "pt");
};
fontManager.currentFontFamily.connectSimple(updateFontFamilyLabel, this->managedConnections);
fontManager.currentFontSize.connectSimple(updateFontFamilyLabel, this->managedConnections);
// BUTTON
QPushButton *button = new QPushButton("Select");
layout->addWidget(button);
button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Policy::Fixed);
QObject::connect(button, &QPushButton::clicked, []() {
auto &fontManager = singletons::FontManager::getInstance();
QFontDialog dialog(fontManager.getFont(singletons::FontManager::Medium, 1.));
dialog.connect(&dialog, &QFontDialog::fontSelected, [](const QFont &font) {
auto &fontManager = singletons::FontManager::getInstance();
fontManager.currentFontFamily = font.family().toStdString();
fontManager.currentFontSize = font.pointSize();
});
dialog.show();
dialog.exec();
});
return layout;
}
2018-01-12 23:09:05 +01:00
} // namespace settingspages
} // namespace widgets
} // namespace chatterino