<commit_before>#include "widgets/dialogs/SettingsDialog.hpp"

#include "Application.hpp"
#include "util/LayoutCreator.hpp"
#include "widgets/helper/SettingsDialogTab.hpp"
#include "widgets/settingspages/AboutPage.hpp"
#include "widgets/settingspages/AccountsPage.hpp"
#include "widgets/settingspages/AdvancedPage.hpp"
#include "widgets/settingspages/BrowserExtensionPage.hpp"
#include "widgets/settingspages/CommandPage.hpp"
#include "widgets/settingspages/EmotesPage.hpp"
#include "widgets/settingspages/ExternalToolsPage.hpp"
#include "widgets/settingspages/FeelPage.hpp"
#include "widgets/settingspages/GeneralPage.hpp"
#include "widgets/settingspages/HighlightingPage.hpp"
#include "widgets/settingspages/IgnoresPage.hpp"
#include "widgets/settingspages/KeyboardSettingsPage.hpp"
#include "widgets/settingspages/LogsPage.hpp"
#include "widgets/settingspages/LookPage.hpp"
#include "widgets/settingspages/ModerationPage.hpp"
#include "widgets/settingspages/NotificationPage.hpp"
#include "widgets/settingspages/SpecialChannelsPage.hpp"

#include <QDialogButtonBox>
#include <QLineEdit>

namespace chatterino {

SettingsDialog *SettingsDialog::handle = nullptr;

SettingsDialog::SettingsDialog()
    : BaseWindow(nullptr, BaseWindow::DisableCustomScaling)
{
    this->initUi();
    this->addTabs();

    this->scaleChangedEvent(this->scale());

    this->overrideBackgroundColor_ = QColor("#111111");
    this->themeChangedEvent();

    this->resize(815, 600);
}

void SettingsDialog::initUi()
{
    LayoutCreator<SettingsDialog> layoutCreator(this);

    // tab pages
    layoutCreator.setLayoutType<QHBoxLayout>()
        .withoutSpacing()
        .emplace<QWidget>()
        .assign(&this->ui_.tabContainerContainer)
        .emplace<QVBoxLayout>()
        .withoutMargin()
        .assign(&this->ui_.tabContainer);

    this->ui_.tabContainerContainer->layout()->setContentsMargins(8, 8, 0, 39);

    this->layout()->setSpacing(0);

    // right side layout
    auto right = layoutCreator.emplace<QVBoxLayout>().withoutMargin();
    {
        auto title = right.emplace<QHBoxLayout>().withoutMargin();

        auto edit = title.emplace<QLineEdit>().assign(&this->ui_.search);
        QTimer::singleShot(100, edit.getElement(),
                           [edit = edit.getElement()]() { edit->setFocus(); });
        QObject::connect(
            edit.getElement(), &QLineEdit::textChanged, this,
            [this](const QString &text) {
                // filter elements and hide pages
                for (auto &&page : this->pages_)
                {
                    // filterElements returns true if anything on the page matches the search query
                    page->tab()->setVisible(page->filterElements(text));
                }

                // TODO: add originally selected page

                // find next visible page
                if (!this->selectedTab_->isVisible())
                {
                    for (auto &&tab : this->tabs_)
                    {
                        if (tab->isVisible())
                        {
                            this->selectTab(tab);
                            break;
                        }
                    }
                }
            });

        right.emplace<QStackedLayout>()
            .assign(&this->ui_.pageStack)
            .withoutMargin();

        auto buttons = right.emplace<QDialogButtonBox>(Qt::Horizontal);
        {
            this->ui_.okButton =
                buttons->addButton("Ok", QDialogButtonBox::YesRole);
            this->ui_.cancelButton =
                buttons->addButton("Cancel", QDialogButtonBox::NoRole);
        }
    }

    this->ui_.pageStack->setMargin(0);

    // ---- misc<commit_msg>hide duplicate spaces in settings tab list<commit_after>#include "widgets/dialogs/SettingsDialog.hpp"

#include "Application.hpp"
#include "util/LayoutCreator.hpp"
#include "widgets/helper/SettingsDialogTab.hpp"
#include "widgets/settingspages/AboutPage.hpp"
#include "widgets/settingspages/AccountsPage.hpp"
#include "widgets/settingspages/AdvancedPage.hpp"
#include "widgets/settingspages/BrowserExtensionPage.hpp"
#include "widgets/settingspages/CommandPage.hpp"
#include "widgets/settingspages/EmotesPage.hpp"
#include "widgets/settingspages/ExternalToolsPage.hpp"
#include "widgets/settingspages/FeelPage.hpp"
#include "widgets/settingspages/GeneralPage.hpp"
#include "widgets/settingspages/HighlightingPage.hpp"
#include "widgets/settingspages/IgnoresPage.hpp"
#include "widgets/settingspages/KeyboardSettingsPage.hpp"
#include "widgets/settingspages/LogsPage.hpp"
#include "widgets/settingspages/LookPage.hpp"
#include "widgets/settingspages/ModerationPage.hpp"
#include "widgets/settingspages/NotificationPage.hpp"
#include "widgets/settingspages/SpecialChannelsPage.hpp"

#include <QDialogButtonBox>
#include <QLineEdit>

namespace chatterino {

SettingsDialog *SettingsDialog::handle = nullptr;

SettingsDialog::SettingsDialog()
    : BaseWindow(nullptr, BaseWindow::DisableCustomScaling)
{
    this->initUi();
    this->addTabs();

    this->scaleChangedEvent(this->scale());

    this->overrideBackgroundColor_ = QColor("#111111");
    this->themeChangedEvent();

    this->resize(815, 600);
}

void SettingsDialog::initUi()
{
    LayoutCreator<SettingsDialog> layoutCreator(this);

    // tab pages
    layoutCreator.setLayoutType<QHBoxLayout>()
        .withoutSpacing()
        .emplace<QWidget>()
        .assign(&this->ui_.tabContainerContainer)
        .emplace<QVBoxLayout>()
        .withoutMargin()
        .assign(&this->ui_.tabContainer);

    this->ui_.tabContainerContainer->layout()->setContentsMargins(8, 8, 0, 39);

    this->layout()->setSpacing(0);

    // right side layout
    auto right = layoutCreator.emplace<QVBoxLayout>().withoutMargin();
    {
        auto title = right.emplace<QHBoxLayout>().withoutMargin();

        auto edit = title.emplace<QLineEdit>().assign(&this->ui_.search);
        QTimer::singleShot(100, edit.getElement(),
                           [edit = edit.getElement()]() { edit->setFocus(); });
        QObject::connect(
            edit.getElement(), &QLineEdit::textChanged, this,
            [this](const QString &text) {
                // filter elements and hide pages
                for (auto &&page : this->pages_)
                {
                    // filterElements returns true if anything on the page matches the search query
                    page->tab()->setVisible(page->filterElements(text));
                }

                // TODO: add originally selected page

                // find next visible page
                if (!this->selectedTab_->isVisible())
                {
                    for (auto &&tab : this->tabs_)
                    {
                        if (tab->isVisible())
                        {
                            this->selectTab(tab);
                            break;
                        }
                    }
                }

                // remove duplicate spaces
                bool shouldShowSpace = true;

                for (int i = 0; i < this->ui_.tabContainer->count(); i++)
                {
                    auto item = this->ui_.tabContainer->itemAt(i);
                    if (auto x = dynamic_cast<QSpacerItem *>(item); x)
                    {
                        x->changeSize(
                            10, shouldShowSpace ? int(16 * this->scale()) : 0);
                        shouldShowSpace = false;
                    }
                    else if (item->widget())
                    {
                        shouldShowSpace |= item->widget()->isVisible();
                    }
                }
            });

        right.emplace<QStackedLayout>()
            .assign(&this->ui_.pageStack)
            .withoutMargin();

        auto buttons = right.emplace<QDialogButtonBox>(Qt::Horizontal);
        {
            this->ui_.okButton =
                buttons->addButton("Ok", QDialogButtonBox::YesRole);
            this->ui_.cancelButton =
                buttons->addButton("Cancel", QDialogButtonBox::NoRole);
        }
    }

    this->ui_.pageStack->setMargin(0);

    // ---- misc
{'fraction_non_alphanumeric': 0.1263427734375, 'fraction_numerical': 0.006103515625, 'mean_word_length': 2.271964856230032, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 99, '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': '5511412', 'n_tokens_mistral': 2294, 'n_tokens_neox': 2138, 'n_words': 358}