diff --git a/Documentation/FileFormats.md b/Documentation/FileFormats.md index c4b253da2a..763b24ec48 100644 --- a/Documentation/FileFormats.md +++ b/Documentation/FileFormats.md @@ -27,7 +27,7 @@ Requires the metadata-fields `count` (count of glyphs copied) and `first_glyph` The data contains codepoint (encoded as host-endian u32), width and height (as u8's) and glyph bitmap data. It is encoded in width times height many bytes, either 0 (clear) or 1 (set). -Implemented in `FontEditor::copy_selected_glyphs` and `FontEditor::paste_glyphs`, in [`Userland/Applications/FontEditor/FontEditor.cpp`](../Userland/Applications/FontEditor/FontEditor.cpp). +Implemented in `FontEditor::copy_selected_glyphs` and `FontEditor::paste_glyphs`, in [`Userland/Applications/FontEditor/MainWidget.cpp`](../Userland/Applications/FontEditor/MainWidget.cpp). ## image/x-serenityos (Clipboard-only) diff --git a/Userland/Applications/FontEditor/CMakeLists.txt b/Userland/Applications/FontEditor/CMakeLists.txt index 81174d221f..575538cc4d 100644 --- a/Userland/Applications/FontEditor/CMakeLists.txt +++ b/Userland/Applications/FontEditor/CMakeLists.txt @@ -11,7 +11,7 @@ compile_gml(NewFontDialogPage1.gml NewFontDialogPage1GML.h new_font_dialog_page_ compile_gml(NewFontDialogPage2.gml NewFontDialogPage2GML.h new_font_dialog_page_2_gml) set(SOURCES - FontEditor.cpp + MainWidget.cpp FontEditorWindowGML.h FontPreviewWindowGML.h GlyphEditorWidget.cpp diff --git a/Userland/Applications/FontEditor/FontEditor.cpp b/Userland/Applications/FontEditor/MainWidget.cpp similarity index 96% rename from Userland/Applications/FontEditor/FontEditor.cpp rename to Userland/Applications/FontEditor/MainWidget.cpp index af7c6317f2..63b34caa11 100644 --- a/Userland/Applications/FontEditor/FontEditor.cpp +++ b/Userland/Applications/FontEditor/MainWidget.cpp @@ -5,7 +5,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include "FontEditor.h" +#include "MainWidget.h" #include "GlyphEditorWidget.h" #include "NewFontDialog.h" #include @@ -57,7 +57,7 @@ static constexpr Array pangrams = { "lazy dog" }; -ErrorOr> FontEditorWidget::create_preview_window() +ErrorOr> MainWidget::create_preview_window() { auto window = TRY(GUI::Window::try_create(this)); window->set_window_type(GUI::WindowType::ToolWindow); @@ -90,7 +90,7 @@ ErrorOr> FontEditorWidget::create_preview_window() return window; } -ErrorOr FontEditorWidget::create_actions() +ErrorOr MainWidget::create_actions() { m_new_action = GUI::Action::create("&New Font...", { Mod_Ctrl, Key_N }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-font.png")), [&](auto&) { if (!request_close()) @@ -297,7 +297,7 @@ ErrorOr FontEditorWidget::create_actions() return {}; } -ErrorOr FontEditorWidget::create_toolbars() +ErrorOr MainWidget::create_toolbars() { auto& toolbar = *find_descendant_of_type_named("toolbar"); (void)TRY(toolbar.try_add_action(*m_new_action)); @@ -331,7 +331,7 @@ ErrorOr FontEditorWidget::create_toolbars() return {}; } -ErrorOr FontEditorWidget::create_models() +ErrorOr MainWidget::create_models() { for (auto& it : Gfx::font_slope_names) TRY(m_font_slope_list.try_append(it.name)); @@ -368,7 +368,7 @@ ErrorOr FontEditorWidget::create_models() return {}; } -ErrorOr FontEditorWidget::create_undo_stack() +ErrorOr MainWidget::create_undo_stack() { m_undo_stack = TRY(try_make()); m_undo_stack->on_state_change = [this] { @@ -381,7 +381,7 @@ ErrorOr FontEditorWidget::create_undo_stack() return {}; } -FontEditorWidget::FontEditorWidget() +MainWidget::MainWidget() { load_from_gml(font_editor_window_gml); @@ -542,7 +542,7 @@ FontEditorWidget::FontEditorWidget() }; } -ErrorOr FontEditorWidget::initialize(String const& path, RefPtr&& edited_font) +ErrorOr MainWidget::initialize(String const& path, RefPtr&& edited_font) { if (m_edited_font == edited_font) return {}; @@ -609,7 +609,7 @@ ErrorOr FontEditorWidget::initialize(String const& path, RefPtr FontEditorWidget::initialize_menubar(GUI::Window& window) +ErrorOr MainWidget::initialize_menubar(GUI::Window& window) { auto file_menu = TRY(window.try_add_menu("&File")); TRY(file_menu->try_add_action(*m_new_action)); @@ -663,7 +663,7 @@ ErrorOr FontEditorWidget::initialize_menubar(GUI::Window& window) return {}; } -bool FontEditorWidget::save_file(String const& path) +bool MainWidget::save_file(String const& path) { auto saved_font = m_edited_font->masked_character_set(); auto ret_val = saved_font->write_to_file(path); @@ -678,7 +678,7 @@ bool FontEditorWidget::save_file(String const& path) return true; } -void FontEditorWidget::set_show_font_metadata(bool show) +void MainWidget::set_show_font_metadata(bool show) { if (m_font_metadata == show) return; @@ -686,7 +686,7 @@ void FontEditorWidget::set_show_font_metadata(bool show) m_font_metadata_groupbox->set_visible(m_font_metadata); } -void FontEditorWidget::set_show_unicode_blocks(bool show) +void MainWidget::set_show_unicode_blocks(bool show) { if (m_unicode_blocks == show) return; @@ -694,7 +694,7 @@ void FontEditorWidget::set_show_unicode_blocks(bool show) m_unicode_block_container->set_visible(m_unicode_blocks); } -bool FontEditorWidget::open_file(String const& path) +bool MainWidget::open_file(String const& path) { auto bitmap_font = Gfx::BitmapFont::load_from_file(path); if (!bitmap_font) { @@ -708,7 +708,7 @@ bool FontEditorWidget::open_file(String const& path) return true; } -void FontEditorWidget::push_undo() +void MainWidget::push_undo() { auto maybe_state = m_undo_selection->save_state(); if (maybe_state.is_error()) { @@ -726,7 +726,7 @@ void FontEditorWidget::push_undo() warnln("Failed to push undo stack: {}", maybe_push.error()); } -void FontEditorWidget::reset_selection_and_push_undo() +void MainWidget::reset_selection_and_push_undo() { auto selection = m_glyph_map_widget->selection().normalized(); if (selection.size() != 1) { @@ -739,7 +739,7 @@ void FontEditorWidget::reset_selection_and_push_undo() push_undo(); } -void FontEditorWidget::undo() +void MainWidget::undo() { if (!m_undo_stack->can_undo()) return; @@ -769,7 +769,7 @@ void FontEditorWidget::undo() update_statusbar(); } -void FontEditorWidget::redo() +void MainWidget::redo() { if (!m_undo_stack->can_redo()) return; @@ -799,7 +799,7 @@ void FontEditorWidget::redo() update_statusbar(); } -bool FontEditorWidget::request_close() +bool MainWidget::request_close() { if (!window()->is_modified()) return true; @@ -814,7 +814,7 @@ bool FontEditorWidget::request_close() return false; } -void FontEditorWidget::update_title() +void MainWidget::update_title() { StringBuilder title; if (m_path.is_empty()) @@ -825,7 +825,7 @@ void FontEditorWidget::update_title() window()->set_title(title.to_string()); } -void FontEditorWidget::did_modify_font() +void MainWidget::did_modify_font() { if (!window() || window()->is_modified()) return; @@ -833,7 +833,7 @@ void FontEditorWidget::did_modify_font() update_title(); } -void FontEditorWidget::update_statusbar() +void MainWidget::update_statusbar() { auto glyph = m_glyph_map_widget->active_glyph(); StringBuilder builder; @@ -863,13 +863,13 @@ void FontEditorWidget::update_statusbar() m_statusbar->set_text(builder.to_string()); } -void FontEditorWidget::update_preview() +void MainWidget::update_preview() { if (m_font_preview_window) m_font_preview_window->update(); } -void FontEditorWidget::drop_event(GUI::DropEvent& event) +void MainWidget::drop_event(GUI::DropEvent& event) { event.accept(); @@ -886,19 +886,19 @@ void FontEditorWidget::drop_event(GUI::DropEvent& event) } } -void FontEditorWidget::set_scale(i32 scale) +void MainWidget::set_scale(i32 scale) { m_glyph_editor_widget->set_scale(scale); } -void FontEditorWidget::set_scale_and_save(i32 scale) +void MainWidget::set_scale_and_save(i32 scale) { set_scale(scale); Config::write_i32("FontEditor", "GlyphEditor", "Scale", scale); m_glyph_editor_widget->set_fixed_size(m_glyph_editor_widget->preferred_width(), m_glyph_editor_widget->preferred_height()); } -void FontEditorWidget::copy_selected_glyphs() +void MainWidget::copy_selected_glyphs() { size_t bytes_per_glyph = Gfx::GlyphBitmap::bytes_per_row() * edited_font().glyph_height(); auto selection = m_glyph_map_widget->selection().normalized(); @@ -917,13 +917,13 @@ void FontEditorWidget::copy_selected_glyphs() GUI::Clipboard::the().set_data(buffer.bytes(), "glyph/x-fonteditor", metadata); } -void FontEditorWidget::cut_selected_glyphs() +void MainWidget::cut_selected_glyphs() { copy_selected_glyphs(); delete_selected_glyphs(); } -void FontEditorWidget::paste_glyphs() +void MainWidget::paste_glyphs() { auto [data, mime_type, metadata] = GUI::Clipboard::the().fetch_data_and_type(); if (!mime_type.starts_with("glyph/")) @@ -968,7 +968,7 @@ void FontEditorWidget::paste_glyphs() update_statusbar(); } -void FontEditorWidget::delete_selected_glyphs() +void MainWidget::delete_selected_glyphs() { push_undo(); diff --git a/Userland/Applications/FontEditor/FontEditor.h b/Userland/Applications/FontEditor/MainWidget.h similarity index 93% rename from Userland/Applications/FontEditor/FontEditor.h rename to Userland/Applications/FontEditor/MainWidget.h index 3e3a0182f7..4b7af7c9df 100644 --- a/Userland/Applications/FontEditor/FontEditor.h +++ b/Userland/Applications/FontEditor/MainWidget.h @@ -19,12 +19,12 @@ namespace FontEditor { class GlyphEditorWidget; -class FontEditorWidget final : public GUI::Widget { - C_OBJECT(FontEditorWidget) +class MainWidget final : public GUI::Widget { + C_OBJECT(MainWidget) public: - static ErrorOr> try_create() + static ErrorOr> try_create() { - NonnullRefPtr font_editor = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) FontEditorWidget())); + NonnullRefPtr font_editor = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) MainWidget())); TRY(font_editor->create_actions()); TRY(font_editor->create_models()); TRY(font_editor->create_toolbars()); @@ -32,7 +32,7 @@ public: return font_editor; } - virtual ~FontEditorWidget() override = default; + virtual ~MainWidget() override = default; ErrorOr initialize(String const& path, RefPtr&&); ErrorOr initialize_menubar(GUI::Window&); @@ -52,7 +52,7 @@ public: void set_show_unicode_blocks(bool); private: - FontEditorWidget(); + MainWidget(); ErrorOr create_actions(); ErrorOr create_models(); diff --git a/Userland/Applications/FontEditor/main.cpp b/Userland/Applications/FontEditor/main.cpp index 96d5388959..baebc63864 100644 --- a/Userland/Applications/FontEditor/main.cpp +++ b/Userland/Applications/FontEditor/main.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include "FontEditor.h" +#include "MainWidget.h" #include #include #include @@ -42,7 +42,7 @@ ErrorOr serenity_main(Main::Arguments arguments) window->set_icon(app_icon.bitmap_for_size(16)); window->resize(640, 470); - auto font_editor = TRY(window->try_set_main_widget()); + auto font_editor = TRY(window->try_set_main_widget()); TRY(font_editor->initialize_menubar(*window)); if (path) {