diff --git a/src/widgets/settingspages/KeyboardSettingsPage.cpp b/src/widgets/settingspages/KeyboardSettingsPage.cpp index 61c4e668e..d63c16029 100644 --- a/src/widgets/settingspages/KeyboardSettingsPage.cpp +++ b/src/widgets/settingspages/KeyboardSettingsPage.cpp @@ -1,4 +1,4 @@ -#include "KeyboardSettingsPage.hpp" +#include "widgets/settingspages/KeyboardSettingsPage.hpp" #include "Application.hpp" #include "common/QLogging.hpp" @@ -15,61 +15,12 @@ #include #include -namespace chatterino { +namespace { -KeyboardSettingsPage::KeyboardSettingsPage() -{ - LayoutCreator layoutCreator(this); - auto layout = layoutCreator.emplace(); +using namespace chatterino; - auto model = getApp()->hotkeys->createModel(nullptr); - EditableModelView *view = - layout.emplace(model).getElement(); - - view->setTitles({"Hotkey name", "Keybinding"}); - view->getTableView()->horizontalHeader()->setVisible(true); - view->getTableView()->horizontalHeader()->setStretchLastSection(false); - view->getTableView()->horizontalHeader()->setSectionResizeMode( - QHeaderView::ResizeToContents); - view->getTableView()->horizontalHeader()->setSectionResizeMode( - 1, QHeaderView::Stretch); - - // We can safely ignore this signal connection since we own the view - std::ignore = view->addButtonPressed.connect([view, model] { - EditHotkeyDialog dialog(nullptr); - bool wasAccepted = dialog.exec() == 1; - - if (wasAccepted) - { - auto newHotkey = dialog.data(); - int vectorIndex = getApp()->hotkeys->hotkeys_.append(newHotkey); - getApp()->hotkeys->save(); - } - }); - - QObject::connect(view->getTableView(), &QTableView::doubleClicked, - [this, view, model](const QModelIndex &clicked) { - this->tableCellClicked(clicked, view, model); - }); - - QPushButton *resetEverything = new QPushButton("Reset to defaults"); - QObject::connect(resetEverything, &QPushButton::clicked, [this]() { - auto reply = QMessageBox::question( - this, "Reset hotkeys", - "Are you sure you want to reset hotkeys to defaults?", - QMessageBox::Yes | QMessageBox::Cancel); - - if (reply == QMessageBox::Yes) - { - getApp()->hotkeys->resetToDefaults(); - } - }); - view->addCustomButton(resetEverything); -} - -void KeyboardSettingsPage::tableCellClicked(const QModelIndex &clicked, - EditableModelView *view, - HotkeyModel *model) +void tableCellClicked(const QModelIndex &clicked, EditableModelView *view, + HotkeyModel *model) { auto hotkey = getApp()->hotkeys->getHotkeyByName( clicked.siblingAtColumn(0).data(Qt::EditRole).toString()); @@ -89,4 +40,58 @@ void KeyboardSettingsPage::tableCellClicked(const QModelIndex &clicked, } } +} // namespace + +namespace chatterino { + +KeyboardSettingsPage::KeyboardSettingsPage() +{ + LayoutCreator layoutCreator(this); + auto layout = layoutCreator.emplace(); + + auto *model = getApp()->hotkeys->createModel(nullptr); + EditableModelView *view = + layout.emplace(model).getElement(); + + view->setTitles({"Hotkey name", "Keybinding"}); + view->getTableView()->horizontalHeader()->setVisible(true); + view->getTableView()->horizontalHeader()->setStretchLastSection(false); + view->getTableView()->horizontalHeader()->setSectionResizeMode( + QHeaderView::ResizeToContents); + view->getTableView()->horizontalHeader()->setSectionResizeMode( + 1, QHeaderView::Stretch); + + // We can safely ignore this signal connection since we own the view + std::ignore = view->addButtonPressed.connect([] { + EditHotkeyDialog dialog(nullptr); + bool wasAccepted = dialog.exec() == 1; + + if (wasAccepted) + { + auto newHotkey = dialog.data(); + int vectorIndex = getApp()->hotkeys->hotkeys_.append(newHotkey); + getApp()->hotkeys->save(); + } + }); + + QObject::connect(view->getTableView(), &QTableView::doubleClicked, + [view, model](const QModelIndex &clicked) { + tableCellClicked(clicked, view, model); + }); + + auto *resetEverything = new QPushButton("Reset to defaults"); + QObject::connect(resetEverything, &QPushButton::clicked, [this]() { + auto reply = QMessageBox::question( + this, "Reset hotkeys", + "Are you sure you want to reset hotkeys to defaults?", + QMessageBox::Yes | QMessageBox::Cancel); + + if (reply == QMessageBox::Yes) + { + getApp()->hotkeys->resetToDefaults(); + } + }); + view->addCustomButton(resetEverything); +} + } // namespace chatterino diff --git a/src/widgets/settingspages/KeyboardSettingsPage.hpp b/src/widgets/settingspages/KeyboardSettingsPage.hpp index 2a7d1dff9..fcd9eed61 100644 --- a/src/widgets/settingspages/KeyboardSettingsPage.hpp +++ b/src/widgets/settingspages/KeyboardSettingsPage.hpp @@ -11,10 +11,6 @@ class KeyboardSettingsPage : public SettingsPage { public: KeyboardSettingsPage(); - -private: - void tableCellClicked(const QModelIndex &clicked, EditableModelView *view, - HotkeyModel *model); }; } // namespace chatterino