<commit_before>#include "appearancepage.hpp"

#include <QFontDialog>
#include <QFormLayout>
#include <QGroupBox>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>

#include "util/layoutcreator.hpp"

#define THEME_ITEMS "White", "Light", "Dark", "Black"

#define TAB_X "Hide tab x"
#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"

// 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

namespace chatterino {
namespace widgets {
namespace settingspages {

AppearancePage::AppearancePage()
    : SettingsPage("Appearance", ":/images/theme.svg")
{
    singletons::SettingManager &settings = singletons::SettingManager::getInstance();
    util::LayoutCreator<AppearancePage> layoutCreator(this);
    auto layout = layoutCreator.emplace<QVBoxLayout>().withoutMargin();

    auto application =
        layout.emplace<QGroupBox>("Application").emplace<QVBoxLayout>().withoutMargin();
    {
        auto form = application.emplace<QFormLayout>();

        // clang-format off
        form->addRow("Theme:",       this->createComboBox({THEME_ITEMS}, singletons::ThemeManager::getInstance().themeName));
        form->addRow("Theme color:", this->createThemeColorChanger());
        form->addRow("Font:",        this->createFontChanger());

        form->addRow("Tab bar:",     this->createCheckBox(TAB_X,         settings.hideTabX));
        form->addRow("",             this->createCheckBox(TAB_PREF,      settings.hidePreferencesButton));
        form->addRow("",             this->createCheckBox(TAB_USER,      settings.hideUserButton));

        form->addRow("Scrolling:",   this->createCheckBox(SCROLL_SMOOTH, settings.enableSmoothScrolling));
        form->addRow("",             this->createCheckBox(SCROLL_NEWMSG, settings.enableSmoothScrollingNewMessages));
        // clang-format on
    }

    auto messages = layout.emplace<QGroupBox>("Messages").emplace<QVBoxLayout>().withoutMargin();
    {
        messages.append(this->createCheckBox("Show timestamp", settings.showTimestamps));
        auto tbox = messages.emplace<QHBoxLayout>();
        {
            tbox.emplace<QLabel>("timestamp format (a = am/pm):");
            tbox.append(this->createComboBox({TIMESTAMP_FORMATS}, settings.timestampFormat));
        }
        messages.append(this->createCheckBox("Show badges", settings.showBadges));
        messages.append(this->createCheckBox("Seperate messages", settings.seperateMessages));
        messages.append(this->createCheckBox("Show message length", settings.showMessageLength));
    }

    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) * 1000);

    // BUTTON
    QPushButton *button = new QPushButton;
    layout->addWidget(button);
    button->setFlat(true);
    button->setFixedWidth(64);

    // SIGNALS
    QObject::connect(slider, &QSlider::valueChanged, this, [button, &themeHue](int value) mutable {
        double newValue = value / 1000.0;

        themeHue.setValue(newValue);

        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();

        // TODO(pajlada): re-implement
        // this->windowManager.updateAll();
    });

    return layout;
}

QLayout *AppearancePage::createFontChanger()
{
    QHBoxLayout *layout = new QHBoxLayout;
<commit_msg>Changed some multiplier from 1000 to 100<commit_after>#include "appearancepage.hpp"

#include <QFontDialog>
#include <QFormLayout>
#include <QGroupBox>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>

#include "util/layoutcreator.hpp"

#define THEME_ITEMS "White", "Light", "Dark", "Black"

#define TAB_X "Hide tab x"
#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"

// 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

namespace chatterino {
namespace widgets {
namespace settingspages {

AppearancePage::AppearancePage()
    : SettingsPage("Appearance", ":/images/theme.svg")
{
    singletons::SettingManager &settings = singletons::SettingManager::getInstance();
    util::LayoutCreator<AppearancePage> layoutCreator(this);
    auto layout = layoutCreator.emplace<QVBoxLayout>().withoutMargin();

    auto application =
        layout.emplace<QGroupBox>("Application").emplace<QVBoxLayout>().withoutMargin();
    {
        auto form = application.emplace<QFormLayout>();

        // clang-format off
        form->addRow("Theme:",       this->createComboBox({THEME_ITEMS}, singletons::ThemeManager::getInstance().themeName));
        form->addRow("Theme color:", this->createThemeColorChanger());
        form->addRow("Font:",        this->createFontChanger());

        form->addRow("Tab bar:",     this->createCheckBox(TAB_X,         settings.hideTabX));
        form->addRow("",             this->createCheckBox(TAB_PREF,      settings.hidePreferencesButton));
        form->addRow("",             this->createCheckBox(TAB_USER,      settings.hideUserButton));

        form->addRow("Scrolling:",   this->createCheckBox(SCROLL_SMOOTH, settings.enableSmoothScrolling));
        form->addRow("",             this->createCheckBox(SCROLL_NEWMSG, settings.enableSmoothScrollingNewMessages));
        // clang-format on
    }

    auto messages = layout.emplace<QGroupBox>("Messages").emplace<QVBoxLayout>().withoutMargin();
    {
        messages.append(this->createCheckBox("Show timestamp", settings.showTimestamps));
        auto tbox = messages.emplace<QHBoxLayout>();
        {
            tbox.emplace<QLabel>("timestamp format (a = am/pm):");
            tbox.append(this->createComboBox({TIMESTAMP_FORMATS}, settings.timestampFormat));
        }
        messages.append(this->createCheckBox("Show badges", settings.showBadges));
        messages.append(this->createCheckBox("Seperate messages", settings.seperateMessages));
        messages.append(this->createCheckBox("Show message length", settings.showMessageLength));
    }

    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);

    // BUTTON
    QPushButton *button = new QPushButton;
    layout->addWidget(button);
    button->setFlat(true);
    button->setFixedWidth(64);

    // SIGNALS
    QObject::connect(slider, &QSlider::valueChanged, this, [button, &themeHue](int value) mutable {
        double newValue = value / 100.0;

        themeHue.setValue(newValue);

        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();

        // TODO(pajlada): re-implement
        // this->windowManager.updateAll();
    });

    return layout;
}

QLayout *AppearancePage::createFontChanger()
{
    QHBoxLayout *layout = new QHBoxLayout;

{'fraction_non_alphanumeric': 0.14466591450419958, 'fraction_numerical': 0.006142660147925285, 'mean_word_length': 3.808921036769138, 'pattern_counts': {'":': 2, '<': 33, '<?xml version=': 0, '>': 97, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6977364', 'n_tokens_mistral': 2511, 'n_tokens_neox': 2440, 'n_words': 432}