mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:28:12 +00:00

Previously, the font was applied to the Labels but the name wasn't updated on initial startup. This meant that the Label's content was only correct in the default state but not if the user changed the defaults.
62 lines
2.4 KiB
C++
62 lines
2.4 KiB
C++
/*
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include "FontSettingsWidget.h"
|
|
#include <Applications/DisplaySettings/FontSettingsGML.h>
|
|
#include <LibGUI/Button.h>
|
|
#include <LibGUI/FontPicker.h>
|
|
#include <LibGUI/Label.h>
|
|
#include <LibGUI/WindowServerConnection.h>
|
|
#include <LibGfx/FontDatabase.h>
|
|
|
|
namespace DisplaySettings {
|
|
|
|
FontSettingsWidget::FontSettingsWidget()
|
|
{
|
|
load_from_gml(font_settings_gml);
|
|
|
|
auto& default_font_label = *find_descendant_of_type_named<GUI::Label>("default_font_label");
|
|
auto& default_font_button = *find_descendant_of_type_named<GUI::Button>("default_font_button");
|
|
auto& fixed_width_font_label = *find_descendant_of_type_named<GUI::Label>("fixed_width_font_label");
|
|
auto& fixed_width_font_button = *find_descendant_of_type_named<GUI::Button>("fixed_width_font_button");
|
|
|
|
auto& default_font = Gfx::FontDatabase::default_font();
|
|
default_font_label.set_font(default_font);
|
|
default_font_label.set_text(default_font.qualified_name());
|
|
|
|
auto& default_fixed_width_font = Gfx::FontDatabase::default_fixed_width_font();
|
|
fixed_width_font_label.set_font(default_fixed_width_font);
|
|
fixed_width_font_label.set_text(default_fixed_width_font.qualified_name());
|
|
|
|
default_font_button.on_click = [this, &default_font_label] {
|
|
auto font_picker = GUI::FontPicker::construct(window(), &default_font_label.font(), false);
|
|
if (font_picker->exec() == GUI::Dialog::ExecOK) {
|
|
default_font_label.set_font(font_picker->font());
|
|
default_font_label.set_text(font_picker->font()->qualified_name());
|
|
}
|
|
};
|
|
|
|
fixed_width_font_button.on_click = [this, &fixed_width_font_label] {
|
|
auto font_picker = GUI::FontPicker::construct(window(), &fixed_width_font_label.font(), true);
|
|
if (font_picker->exec() == GUI::Dialog::ExecOK) {
|
|
fixed_width_font_label.set_font(font_picker->font());
|
|
fixed_width_font_label.set_text(font_picker->font()->qualified_name());
|
|
}
|
|
};
|
|
}
|
|
|
|
FontSettingsWidget::~FontSettingsWidget()
|
|
{
|
|
}
|
|
|
|
void FontSettingsWidget::apply_settings()
|
|
{
|
|
auto& default_font_label = *find_descendant_of_type_named<GUI::Label>("default_font_label");
|
|
auto& fixed_width_font_label = *find_descendant_of_type_named<GUI::Label>("fixed_width_font_label");
|
|
GUI::WindowServerConnection::the().set_system_fonts(default_font_label.text(), fixed_width_font_label.text());
|
|
}
|
|
|
|
}
|