mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:57:35 +00:00
FontSettingsWidget: Promote Labels as instance members
In order to not resolve the widgets twice, we capture them in ivars.
This commit is contained in:
parent
883d0d2466
commit
a1f8c10fe5
2 changed files with 23 additions and 23 deletions
|
@ -8,7 +8,6 @@
|
|||
#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>
|
||||
|
||||
|
@ -18,32 +17,31 @@ 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());
|
||||
m_default_font_label = *find_descendant_of_type_named<GUI::Label>("default_font_label");
|
||||
m_default_font_label->set_font(default_font);
|
||||
m_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);
|
||||
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);
|
||||
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());
|
||||
m_default_font_label->set_font(font_picker->font());
|
||||
m_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);
|
||||
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");
|
||||
m_fixed_width_font_label->set_font(default_fixed_width_font);
|
||||
m_fixed_width_font_label->set_text(default_fixed_width_font.qualified_name());
|
||||
|
||||
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);
|
||||
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());
|
||||
m_fixed_width_font_label->set_font(font_picker->font());
|
||||
m_fixed_width_font_label->set_text(font_picker->font()->qualified_name());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -54,9 +52,7 @@ 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());
|
||||
GUI::WindowServerConnection::the().set_system_fonts(m_default_font_label->text(), m_fixed_width_font_label->text());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue