Skip to content

Commit

Permalink
Add keyboardsettings page tables to global search
Browse files Browse the repository at this point in the history
  • Loading branch information
apa420 committed Feb 2, 2025
1 parent 5fc6141 commit 9869085
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
50 changes: 37 additions & 13 deletions src/widgets/settingspages/KeyboardSettingsPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@

#include <QFormLayout>
#include <QHeaderView>
#include <QKeySequenceEdit>
#include <QLabel>
#include <QMessageBox>
#include <QTableView>

#include <array>

namespace {

using namespace chatterino;
Expand Down Expand Up @@ -49,19 +52,19 @@ KeyboardSettingsPage::KeyboardSettingsPage()
auto layout = layoutCreator.emplace<QVBoxLayout>();

auto *model = getApp()->getHotkeys()->createModel(nullptr);
EditableModelView *view =
layout.emplace<EditableModelView>(model).getElement();
this->view_ = layout.emplace<EditableModelView>(model).getElement();

view->setTitles({"Hotkey name", "Keybinding"});
view->getTableView()->horizontalHeader()->setVisible(true);
view->getTableView()->horizontalHeader()->setStretchLastSection(false);
view->getTableView()->horizontalHeader()->setSectionResizeMode(
this->view_->setTitles({"Hotkey name", "Keybinding"});
this->view_->getTableView()->horizontalHeader()->setVisible(true);
this->view_->getTableView()->horizontalHeader()->setStretchLastSection(
false);
this->view_->getTableView()->horizontalHeader()->setSectionResizeMode(
QHeaderView::ResizeToContents);
view->getTableView()->horizontalHeader()->setSectionResizeMode(
this->view_->getTableView()->horizontalHeader()->setSectionResizeMode(
1, QHeaderView::Stretch);

// We can safely ignore this signal connection since we own the view
std::ignore = view->addButtonPressed.connect([] {
// We can safely ignore this signal connection since we own the this->view_
std::ignore = this->view_->addButtonPressed.connect([] {
EditHotkeyDialog dialog(nullptr);
bool wasAccepted = dialog.exec() == 1;

Expand All @@ -73,10 +76,24 @@ KeyboardSettingsPage::KeyboardSettingsPage()
}
});

QObject::connect(view->getTableView(), &QTableView::doubleClicked,
[view, model](const QModelIndex &clicked) {
tableCellClicked(clicked, view, model);
QObject::connect(view_->getTableView(), &QTableView::doubleClicked,
[this, model](const QModelIndex &clicked) {
tableCellClicked(clicked, this->view_, model);
});

auto *keySequenceInput = new QKeySequenceEdit(this);

#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)
keySequenceInput->setClearButtonEnabled(true);
#endif
auto *searchText = new QLabel("Search keybind:", this);

QObject::connect(keySequenceInput, &QKeySequenceEdit::keySequenceChanged,
[this](const QKeySequence &keySequence) {
this->view_->filterSearchResultsHotkey(keySequence);
});
this->view_->addCustomButton(searchText);
this->view_->addCustomButton(keySequenceInput);

auto *resetEverything = new QPushButton("Reset to defaults");
QObject::connect(resetEverything, &QPushButton::clicked, [this]() {
Expand All @@ -90,7 +107,7 @@ KeyboardSettingsPage::KeyboardSettingsPage()
getApp()->getHotkeys()->resetToDefaults();
}
});
view->addCustomButton(resetEverything);
this->view_->addCustomButton(resetEverything);

// We only check this once since a user *should* not have the ability to create a new hotkey with a deprecated or removed action
// However, we also don't update this after the user has deleted a hotkey. This is a big lift that should probably be solved on the model level rather
Expand Down Expand Up @@ -129,4 +146,11 @@ KeyboardSettingsPage::KeyboardSettingsPage()
}
}

bool KeyboardSettingsPage::filterElements(const QString &query)
{
std::array fields{0, 1};

return this->view_->filterSearchResults(query, fields);
}

} // namespace chatterino
4 changes: 4 additions & 0 deletions src/widgets/settingspages/KeyboardSettingsPage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class KeyboardSettingsPage : public SettingsPage
{
public:
KeyboardSettingsPage();
bool filterElements(const QString &query) override;

private:
EditableModelView *view_;
};

} // namespace chatterino

0 comments on commit 9869085

Please sign in to comment.