summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaciej <sppmacd@pm.me>2021-11-14 14:26:10 +0100
committerAndreas Kling <kling@serenityos.org>2022-01-09 00:18:46 +0100
commit22b3c25f10f71c3eed6290fc72650827609325f8 (patch)
treea56adac739f5fe40a9d2c3dfce426193e21909d4
parent4d4764e0fb3eb177e20d5887c41ee04ae7f9dc60 (diff)
downloadserenity-22b3c25f10f71c3eed6290fc72650827609325f8.zip
FontEditor: Save scale to config file
-rw-r--r--Userland/Applications/FontEditor/FontEditor.cpp50
-rw-r--r--Userland/Applications/FontEditor/FontEditor.h10
-rw-r--r--Userland/Applications/FontEditor/GlyphEditorWidget.h2
-rw-r--r--Userland/Applications/FontEditor/main.cpp3
4 files changed, 51 insertions, 14 deletions
diff --git a/Userland/Applications/FontEditor/FontEditor.cpp b/Userland/Applications/FontEditor/FontEditor.cpp
index 21362b7caf..c962b97809 100644
--- a/Userland/Applications/FontEditor/FontEditor.cpp
+++ b/Userland/Applications/FontEditor/FontEditor.cpp
@@ -11,6 +11,7 @@
#include <AK/StringBuilder.h>
#include <AK/UnicodeUtils.h>
#include <Applications/FontEditor/FontEditorWindowGML.h>
+#include <LibConfig/Client.h>
#include <LibDesktop/Launcher.h>
#include <LibGUI/Action.h>
#include <LibGUI/Application.h>
@@ -296,23 +297,22 @@ FontEditorWidget::FontEditorWidget()
toolbar.add_action(*m_next_glyph_action);
toolbar.add_action(*m_go_to_glyph_action);
- m_scale_five_action = GUI::Action::create_checkable("500%", { Mod_Ctrl, Key_1 }, [&](auto&) {
- m_glyph_editor_widget->set_scale(5);
- did_resize_glyph_editor();
+ i32 scale = Config::read_i32("FontEditor", "GlyphEditor", "Scale", 10);
+
+ m_scale_five_action = GUI::Action::create_checkable("500%", { Mod_Ctrl, Key_1 }, [this](auto&) {
+ set_scale_and_save(5);
});
- m_scale_five_action->set_checked(false);
+ m_scale_five_action->set_checked(scale == 5);
m_scale_five_action->set_status_tip("Scale the editor in proportion to the current font");
- m_scale_ten_action = GUI::Action::create_checkable("1000%", { Mod_Ctrl, Key_2 }, [&](auto&) {
- m_glyph_editor_widget->set_scale(10);
- did_resize_glyph_editor();
+ m_scale_ten_action = GUI::Action::create_checkable("1000%", { Mod_Ctrl, Key_2 }, [this](auto&) {
+ set_scale_and_save(10);
});
- m_scale_ten_action->set_checked(true);
+ m_scale_ten_action->set_checked(scale == 10);
m_scale_ten_action->set_status_tip("Scale the editor in proportion to the current font");
- m_scale_fifteen_action = GUI::Action::create_checkable("1500%", { Mod_Ctrl, Key_3 }, [&](auto&) {
- m_glyph_editor_widget->set_scale(15);
- did_resize_glyph_editor();
+ m_scale_fifteen_action = GUI::Action::create_checkable("1500%", { Mod_Ctrl, Key_3 }, [this](auto&) {
+ set_scale_and_save(15);
});
- m_scale_fifteen_action->set_checked(false);
+ m_scale_fifteen_action->set_checked(scale == 15);
m_scale_fifteen_action->set_status_tip("Scale the editor in proportion to the current font");
m_glyph_editor_scale_actions.add_action(*m_scale_five_action);
@@ -483,6 +483,8 @@ FontEditorWidget::FontEditorWidget()
GUI::Application::the()->on_action_leave = [this](GUI::Action&) {
m_statusbar->set_override_text({});
};
+
+ set_scale(scale);
}
FontEditorWidget::~FontEditorWidget()
@@ -777,3 +779,27 @@ void FontEditorWidget::did_resize_glyph_editor()
m_glyph_editor_container->set_fixed_size(m_glyph_editor_widget->preferred_width(), m_glyph_editor_widget->preferred_height());
m_left_column_container->set_fixed_width(max(m_glyph_editor_widget->preferred_width(), glyph_toolbars_width));
}
+
+void FontEditorWidget::config_i32_did_change(String const& domain, String const& group, String const& key, i32 value)
+{
+ if (domain == "FontEditor"sv && group == "GlyphEditor"sv && key == "Scale"sv) {
+ set_scale(value);
+ }
+}
+
+void FontEditorWidget::config_string_did_change(String const& domain, String const& group, String const& key, String const& value)
+{
+ config_i32_did_change(domain, group, key, value.to_int().value_or(10));
+}
+
+void FontEditorWidget::set_scale(i32 scale)
+{
+ m_glyph_editor_widget->set_scale(scale);
+}
+
+void FontEditorWidget::set_scale_and_save(i32 scale)
+{
+ set_scale(scale);
+ Config::write_i32("FontEditor", "GlyphEditor", "Scale", scale);
+ did_resize_glyph_editor();
+}
diff --git a/Userland/Applications/FontEditor/FontEditor.h b/Userland/Applications/FontEditor/FontEditor.h
index 10d5e5994c..f6d5b7270d 100644
--- a/Userland/Applications/FontEditor/FontEditor.h
+++ b/Userland/Applications/FontEditor/FontEditor.h
@@ -7,6 +7,7 @@
#pragma once
#include "UndoGlyph.h"
+#include <LibConfig/Listener.h>
#include <LibGUI/ActionGroup.h>
#include <LibGUI/UndoStack.h>
#include <LibGUI/Widget.h>
@@ -15,7 +16,9 @@
class GlyphEditorWidget;
class GlyphMapWidget;
-class FontEditorWidget final : public GUI::Widget {
+class FontEditorWidget final
+ : public GUI::Widget
+ , public Config::Listener {
C_OBJECT(FontEditorWidget)
public:
virtual ~FontEditorWidget() override;
@@ -40,12 +43,17 @@ private:
virtual void drop_event(GUI::DropEvent&) override;
+ virtual void config_i32_did_change(String const& domain, String const& group, String const& key, i32 value) override;
+ virtual void config_string_did_change(String const& domain, String const& group, String const& key, String const& value) override;
+
void undo();
void redo();
void did_modify_font();
void did_resize_glyph_editor();
void update_statusbar();
void update_preview();
+ void set_scale(i32);
+ void set_scale_and_save(i32);
RefPtr<Gfx::BitmapFont> m_edited_font;
diff --git a/Userland/Applications/FontEditor/GlyphEditorWidget.h b/Userland/Applications/FontEditor/GlyphEditorWidget.h
index 8e5c868111..94f2925e6e 100644
--- a/Userland/Applications/FontEditor/GlyphEditorWidget.h
+++ b/Userland/Applications/FontEditor/GlyphEditorWidget.h
@@ -56,7 +56,7 @@ public:
Function<void()> on_undo_event;
private:
- GlyphEditorWidget() {};
+ GlyphEditorWidget() = default;
virtual void paint_event(GUI::PaintEvent&) override;
virtual void mousedown_event(GUI::MouseEvent&) override;
virtual void mousemove_event(GUI::MouseEvent&) override;
diff --git a/Userland/Applications/FontEditor/main.cpp b/Userland/Applications/FontEditor/main.cpp
index 1193761f3a..fefd531f94 100644
--- a/Userland/Applications/FontEditor/main.cpp
+++ b/Userland/Applications/FontEditor/main.cpp
@@ -6,6 +6,7 @@
#include "FontEditor.h"
#include <AK/URL.h>
+#include <LibConfig/Client.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/System.h>
#include <LibDesktop/Launcher.h>
@@ -27,6 +28,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_protocol("/usr/share/man/man1/FontEditor.md") }));
TRY(Desktop::Launcher::seal_allowlist());
+ Config::pledge_domains("FontEditor");
+ Config::monitor_domain("FontEditor");
TRY(Core::System::pledge("stdio recvfd sendfd thread rpath cpath wpath"));
char const* path = nullptr;