/* * Copyright (c) 2021, Andreas Kling * Copyright (c) 2021, Thomas Keppler * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ #include "FontSettingsWidget.h" #include #include #include #include #include namespace DisplaySettings { static void update_label_with_font(GUI::Label&, Gfx::Font const&); ErrorOr> FontSettingsWidget::try_create() { auto font_settings_widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) FontSettingsWidget())); TRY(font_settings_widget->setup_interface()); return font_settings_widget; } ErrorOr FontSettingsWidget::setup_interface() { TRY(load_from_gml(font_settings_gml)); auto& default_font = Gfx::FontDatabase::default_font(); m_default_font_label = *find_descendant_of_type_named("default_font_label"); update_label_with_font(*m_default_font_label, default_font); auto& default_font_button = *find_descendant_of_type_named("default_font_button"); default_font_button.on_click = [this](auto) { auto font_picker = GUI::FontPicker::construct(window(), &m_default_font_label->font(), false); if (font_picker->exec() == GUI::Dialog::ExecResult::OK) { update_label_with_font(*m_default_font_label, *font_picker->font()); set_modified(true); } }; auto& window_title_font = Gfx::FontDatabase::window_title_font(); m_window_title_font_label = *find_descendant_of_type_named("window_title_font_label"); update_label_with_font(*m_window_title_font_label, window_title_font); auto& window_title_font_button = *find_descendant_of_type_named("window_title_font_button"); window_title_font_button.on_click = [this](auto) { auto font_picker = GUI::FontPicker::construct(window(), &m_window_title_font_label->font(), false); if (font_picker->exec() == GUI::Dialog::ExecResult::OK) { update_label_with_font(*m_window_title_font_label, *font_picker->font()); set_modified(true); } }; auto& default_fixed_width_font = Gfx::FontDatabase::default_fixed_width_font(); m_fixed_width_font_label = *find_descendant_of_type_named("fixed_width_font_label"); update_label_with_font(*m_fixed_width_font_label, default_fixed_width_font); auto& fixed_width_font_button = *find_descendant_of_type_named("fixed_width_font_button"); fixed_width_font_button.on_click = [this](auto) { auto font_picker = GUI::FontPicker::construct(window(), &m_fixed_width_font_label->font(), true); if (font_picker->exec() == GUI::Dialog::ExecResult::OK) { update_label_with_font(*m_fixed_width_font_label, *font_picker->font()); set_modified(true); } }; return {}; } static void update_label_with_font(GUI::Label& label, Gfx::Font const& font) { label.set_text(font.human_readable_name()); label.set_font(font); } void FontSettingsWidget::apply_settings() { GUI::ConnectionToWindowServer::the().set_system_fonts( m_default_font_label->font().qualified_name(), m_fixed_width_font_label->font().qualified_name(), m_window_title_font_label->font().qualified_name()); } }