mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:17:34 +00:00
DisplaySettings: Add "Fonts" tab
This allows you to view, edit, and apply changes to the system fonts.
This commit is contained in:
parent
c778130d63
commit
8ac0d4abe1
5 changed files with 166 additions and 0 deletions
|
@ -1,9 +1,12 @@
|
||||||
compile_gml(MonitorSettings.gml MonitorSettingsGML.h monitor_settings_window_gml)
|
compile_gml(MonitorSettings.gml MonitorSettingsGML.h monitor_settings_window_gml)
|
||||||
compile_gml(BackgroundSettings.gml BackgroundSettingsGML.h background_settings_gml)
|
compile_gml(BackgroundSettings.gml BackgroundSettingsGML.h background_settings_gml)
|
||||||
|
compile_gml(FontSettings.gml FontSettingsGML.h font_settings_gml)
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
BackgroundSettingsGML.h
|
BackgroundSettingsGML.h
|
||||||
BackgroundSettingsWidget.cpp
|
BackgroundSettingsWidget.cpp
|
||||||
|
FontSettingsGML.h
|
||||||
|
FontSettingsWidget.cpp
|
||||||
MonitorSettingsWidget.cpp
|
MonitorSettingsWidget.cpp
|
||||||
MonitorSettingsGML.h
|
MonitorSettingsGML.h
|
||||||
MonitorWidget.cpp
|
MonitorWidget.cpp
|
||||||
|
|
77
Userland/Applications/DisplaySettings/FontSettings.gml
Normal file
77
Userland/Applications/DisplaySettings/FontSettings.gml
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
@GUI::Widget {
|
||||||
|
fill_with_background_color: true
|
||||||
|
|
||||||
|
layout: @GUI::VerticalBoxLayout {
|
||||||
|
margins: [8, 8, 8, 8]
|
||||||
|
spacing: 8
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Widget {
|
||||||
|
shrink_to_fit: true
|
||||||
|
|
||||||
|
layout: @GUI::HorizontalBoxLayout {
|
||||||
|
spacing: 6
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Label {
|
||||||
|
fixed_width: 100
|
||||||
|
text: "Default font:"
|
||||||
|
text_alignment: "CenterLeft"
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Frame {
|
||||||
|
background_color: "white"
|
||||||
|
fill_with_background_color: true
|
||||||
|
|
||||||
|
layout: @GUI::VerticalBoxLayout {
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Label {
|
||||||
|
name: "default_font_label"
|
||||||
|
text: "Katica 10 400"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Button {
|
||||||
|
text: "..."
|
||||||
|
name: "default_font_button"
|
||||||
|
fixed_width: 30
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Widget {
|
||||||
|
shrink_to_fit: true
|
||||||
|
|
||||||
|
layout: @GUI::HorizontalBoxLayout {
|
||||||
|
spacing: 6
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Label {
|
||||||
|
fixed_width: 100
|
||||||
|
text: "Fixed-width font:"
|
||||||
|
text_alignment: "CenterLeft"
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Frame {
|
||||||
|
background_color: "white"
|
||||||
|
fill_with_background_color: true
|
||||||
|
|
||||||
|
layout: @GUI::VerticalBoxLayout {
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Label {
|
||||||
|
name: "fixed_width_font_label"
|
||||||
|
text: "Csilla 10 400"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Button {
|
||||||
|
text: "..."
|
||||||
|
name: "fixed_width_font_button"
|
||||||
|
fixed_width: 30
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Widget {
|
||||||
|
}
|
||||||
|
}
|
57
Userland/Applications/DisplaySettings/FontSettingsWidget.cpp
Normal file
57
Userland/Applications/DisplaySettings/FontSettingsWidget.cpp
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
* 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");
|
||||||
|
|
||||||
|
default_font_label.set_font(Gfx::FontDatabase::default_font());
|
||||||
|
fixed_width_font_label.set_font(Gfx::FontDatabase::default_fixed_width_font());
|
||||||
|
|
||||||
|
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(), false);
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
25
Userland/Applications/DisplaySettings/FontSettingsWidget.h
Normal file
25
Userland/Applications/DisplaySettings/FontSettingsWidget.h
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibGUI/Widget.h>
|
||||||
|
|
||||||
|
namespace DisplaySettings {
|
||||||
|
|
||||||
|
class FontSettingsWidget : public GUI::Widget {
|
||||||
|
C_OBJECT(FontSettingsWidget);
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~FontSettingsWidget() override;
|
||||||
|
|
||||||
|
void apply_settings();
|
||||||
|
|
||||||
|
private:
|
||||||
|
FontSettingsWidget();
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "BackgroundSettingsWidget.h"
|
#include "BackgroundSettingsWidget.h"
|
||||||
|
#include "FontSettingsWidget.h"
|
||||||
#include "MonitorSettingsWidget.h"
|
#include "MonitorSettingsWidget.h"
|
||||||
#include <LibGUI/Action.h>
|
#include <LibGUI/Action.h>
|
||||||
#include <LibGUI/Application.h>
|
#include <LibGUI/Application.h>
|
||||||
|
@ -49,6 +50,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
auto& tab_widget = main_widget.add<GUI::TabWidget>();
|
auto& tab_widget = main_widget.add<GUI::TabWidget>();
|
||||||
auto& background_settings_widget = tab_widget.add_tab<DisplaySettings::BackgroundSettingsWidget>("Background");
|
auto& background_settings_widget = tab_widget.add_tab<DisplaySettings::BackgroundSettingsWidget>("Background");
|
||||||
|
auto& font_settings_widget = tab_widget.add_tab<DisplaySettings::FontSettingsWidget>("Fonts");
|
||||||
auto& monitor_settings_widget = tab_widget.add_tab<DisplaySettings::MonitorSettingsWidget>("Monitor");
|
auto& monitor_settings_widget = tab_widget.add_tab<DisplaySettings::MonitorSettingsWidget>("Monitor");
|
||||||
|
|
||||||
auto& button_container = main_widget.add<GUI::Widget>();
|
auto& button_container = main_widget.add<GUI::Widget>();
|
||||||
|
@ -62,6 +64,7 @@ int main(int argc, char** argv)
|
||||||
ok_button.on_click = [&] {
|
ok_button.on_click = [&] {
|
||||||
background_settings_widget.apply_settings();
|
background_settings_widget.apply_settings();
|
||||||
monitor_settings_widget.apply_settings();
|
monitor_settings_widget.apply_settings();
|
||||||
|
font_settings_widget.apply_settings();
|
||||||
app->quit();
|
app->quit();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -76,6 +79,7 @@ int main(int argc, char** argv)
|
||||||
apply_button.on_click = [&] {
|
apply_button.on_click = [&] {
|
||||||
background_settings_widget.apply_settings();
|
background_settings_widget.apply_settings();
|
||||||
monitor_settings_widget.apply_settings();
|
monitor_settings_widget.apply_settings();
|
||||||
|
font_settings_widget.apply_settings();
|
||||||
};
|
};
|
||||||
|
|
||||||
window->set_icon(app_icon.bitmap_for_size(16));
|
window->set_icon(app_icon.bitmap_for_size(16));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue