#include "IgnoresPage.hpp" #include "Application.hpp" #include "controllers/accounts/AccountController.hpp" #include "controllers/ignores/IgnoreController.hpp" #include "controllers/ignores/IgnoreModel.hpp" #include "providers/twitch/TwitchAccount.hpp" #include "singletons/Settings.hpp" #include "util/LayoutCreator.hpp" #include "widgets/helper/EditableModelView.hpp" #include #include #include #include #include #include #include #include // clang-format off #define INFO "/ignore in chat ignores a user\n/unignore in chat unignores a user" // clang-format on namespace chatterino { static void addPhrasesTab(LayoutCreator box); static void addUsersTab(IgnoresPage &page, LayoutCreator box, QStringListModel &model); IgnoresPage::IgnoresPage() : SettingsPage("Ignores", "") { LayoutCreator layoutCreator(this); auto layout = layoutCreator.setLayoutType(); auto tabs = layout.emplace(); addPhrasesTab(tabs.appendTab(new QVBoxLayout, "Phrases")); addUsersTab(*this, tabs.appendTab(new QVBoxLayout, "Users"), this->userListModel_); auto label = layout.emplace(INFO); label->setWordWrap(true); label->setStyleSheet("color: #BBB"); } void addPhrasesTab(LayoutCreator layout) { EditableModelView *view = layout .emplace(getApp()->ignores->createModel(nullptr)) .getElement(); view->setTitles({"Pattern", "Regex"}); view->getTableView()->horizontalHeader()->setSectionResizeMode( QHeaderView::Fixed); view->getTableView()->horizontalHeader()->setSectionResizeMode( 0, QHeaderView::Stretch); QTimer::singleShot(1, [view] { view->getTableView()->resizeColumnsToContents(); view->getTableView()->setColumnWidth(0, 200); }); view->addButtonPressed.connect([] { getApp()->ignores->phrases.appendItem(IgnorePhrase{"my phrase", false}); }); } void addUsersTab(IgnoresPage &page, LayoutCreator users, QStringListModel &userModel) { users.append(page.createCheckBox("Enable twitch ignored users", getSettings()->enableTwitchIgnoredUsers)); auto anyways = users.emplace().withoutMargin(); { anyways.emplace("Show anyways if:"); anyways.emplace(); anyways->addStretch(1); } /*auto addremove = users.emplace().withoutMargin(); { auto add = addremove.emplace("Ignore user"); auto remove = addremove.emplace("Unignore User"); addremove->addStretch(1); }*/ users.emplace()->setModel(&userModel); } void IgnoresPage::onShow() { auto app = getApp(); auto user = app->accounts->twitch.getCurrent(); if (user->isAnon()) { return; } QStringList users; for (const auto &ignoredUser : user->getIgnores()) { users << ignoredUser.name; } this->userListModel_.setStringList(users); } } // namespace chatterino