2021-05-21 19:55:30 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
2021-05-23 19:53:45 +03:00
|
|
|
* Copyright (c) 2021, Thomas Keppler <winfr34k@gmail.com>
|
2021-05-21 19:55:30 +03:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "FontSettingsWidget.h"
|
|
|
|
#include <Applications/DisplaySettings/FontSettingsGML.h>
|
|
|
|
#include <LibGUI/Button.h>
|
|
|
|
#include <LibGUI/FontPicker.h>
|
|
|
|
#include <LibGUI/WindowServerConnection.h>
|
|
|
|
#include <LibGfx/FontDatabase.h>
|
|
|
|
|
|
|
|
namespace DisplaySettings {
|
|
|
|
|
2021-05-23 19:53:45 +03:00
|
|
|
static void update_label_with_font(GUI::Label&, Gfx::Font const&);
|
|
|
|
|
2021-05-21 19:55:30 +03:00
|
|
|
FontSettingsWidget::FontSettingsWidget()
|
|
|
|
{
|
|
|
|
load_from_gml(font_settings_gml);
|
|
|
|
|
2021-05-23 18:07:38 +03:00
|
|
|
auto& default_font = Gfx::FontDatabase::default_font();
|
2021-05-23 18:14:22 +03:00
|
|
|
m_default_font_label = *find_descendant_of_type_named<GUI::Label>("default_font_label");
|
2021-05-23 19:53:45 +03:00
|
|
|
update_label_with_font(*m_default_font_label, default_font);
|
2021-05-21 19:55:30 +03:00
|
|
|
|
2021-05-23 18:14:22 +03:00
|
|
|
auto& default_font_button = *find_descendant_of_type_named<GUI::Button>("default_font_button");
|
|
|
|
default_font_button.on_click = [this] {
|
|
|
|
auto font_picker = GUI::FontPicker::construct(window(), &m_default_font_label->font(), false);
|
2021-05-21 19:55:30 +03:00
|
|
|
if (font_picker->exec() == GUI::Dialog::ExecOK) {
|
2021-05-23 19:53:45 +03:00
|
|
|
update_label_with_font(*m_default_font_label, *font_picker->font());
|
2021-05-21 19:55:30 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-05-23 18:14:22 +03:00
|
|
|
auto& default_fixed_width_font = Gfx::FontDatabase::default_fixed_width_font();
|
|
|
|
m_fixed_width_font_label = *find_descendant_of_type_named<GUI::Label>("fixed_width_font_label");
|
2021-05-23 19:53:45 +03:00
|
|
|
update_label_with_font(*m_fixed_width_font_label, default_fixed_width_font);
|
2021-05-23 18:14:22 +03:00
|
|
|
|
|
|
|
auto& fixed_width_font_button = *find_descendant_of_type_named<GUI::Button>("fixed_width_font_button");
|
|
|
|
fixed_width_font_button.on_click = [this] {
|
|
|
|
auto font_picker = GUI::FontPicker::construct(window(), &m_fixed_width_font_label->font(), true);
|
2021-05-21 19:55:30 +03:00
|
|
|
if (font_picker->exec() == GUI::Dialog::ExecOK) {
|
2021-05-23 19:53:45 +03:00
|
|
|
update_label_with_font(*m_fixed_width_font_label, *font_picker->font());
|
2021-05-21 19:55:30 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
FontSettingsWidget::~FontSettingsWidget()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-05-23 19:53:45 +03:00
|
|
|
static void update_label_with_font(GUI::Label& label, Gfx::Font const& font)
|
|
|
|
{
|
|
|
|
label.set_text(font.qualified_name());
|
|
|
|
label.set_font(font);
|
|
|
|
}
|
|
|
|
|
2021-05-21 19:55:30 +03:00
|
|
|
void FontSettingsWidget::apply_settings()
|
|
|
|
{
|
2021-05-23 18:14:22 +03:00
|
|
|
GUI::WindowServerConnection::the().set_system_fonts(m_default_font_label->text(), m_fixed_width_font_label->text());
|
2021-05-21 19:55:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|