GamesSettings: Use on_change callback for resetting chess defaults

This commit is contained in:
Kyle Lanmon 2024-03-14 15:54:18 -05:00 committed by Andrew Kaster
parent 8b4e2e2099
commit 1d243ef3e3

View file

@ -69,6 +69,23 @@ public:
return s_board_themes.at(index.row()).name;
}
virtual Vector<GUI::ModelIndex> matches(StringView needle, unsigned flags = MatchesFlag::AllMatching, GUI::ModelIndex const& parent = GUI::ModelIndex()) override
{
Vector<GUI::ModelIndex> found = {};
for (size_t i = 0; i < s_board_themes.size(); ++i) {
auto theme = s_board_themes[i];
if (!string_matches(theme.name, needle, flags))
continue;
found.append(index(i, 0, parent));
if (flags & FirstMatchOnly)
break;
}
return found;
}
private:
BoardThemeModel()
{
@ -294,14 +311,8 @@ void ChessSettingsWidget::apply_settings()
void ChessSettingsWidget::reset_default_values()
{
// FIXME: `set_text()` on a combobox doesn't trigger the `on_change` callback, but it probably should!
// Until then, we have to manually tell the preview to update.
m_piece_set_combobox->set_text("Classic");
m_preview->set_piece_set_name("Classic"_string);
auto& board_theme = get_board_theme("Beige"sv);
m_board_theme_combobox->set_text(board_theme.name);
m_preview->set_dark_square_color(board_theme.dark_square_color);
m_preview->set_light_square_color(board_theme.light_square_color);
m_piece_set_combobox->set_text("Classic"sv);
m_board_theme_combobox->set_text("Beige"sv);
m_show_coordinates_checkbox->set_checked(true);
m_highlight_checks_checkbox->set_checked(true);
}