summaryrefslogtreecommitdiff
path: root/Userland/Applications/CharacterMap
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-01-11 20:24:11 +0000
committerAndreas Kling <kling@serenityos.org>2022-01-16 11:17:03 +0100
commit9ca8428238cdb08a60bf1e09798e284fe2bd6285 (patch)
tree9d3aabd33ff9450d5aca3607dfdebba9c17da53c /Userland/Applications/CharacterMap
parentff500ffcc4f7dbb866bad36132e16169a50059b4 (diff)
downloadserenity-9ca8428238cdb08a60bf1e09798e284fe2bd6285.zip
CharacterMap: Add output box for copying arbitrary character sequences
This adds a TextBox along the bottom of the window. Double-clicking on a character will append it to this box, which you can edit as any other TextBox, or click the copy button to copy the output to the clipboard.
Diffstat (limited to 'Userland/Applications/CharacterMap')
-rw-r--r--Userland/Applications/CharacterMap/CharacterMapWidget.cpp15
-rw-r--r--Userland/Applications/CharacterMap/CharacterMapWidget.h2
-rw-r--r--Userland/Applications/CharacterMap/CharacterMapWindow.gml19
3 files changed, 36 insertions, 0 deletions
diff --git a/Userland/Applications/CharacterMap/CharacterMapWidget.cpp b/Userland/Applications/CharacterMap/CharacterMapWidget.cpp
index 9c60da89cd..c35e9162f2 100644
--- a/Userland/Applications/CharacterMap/CharacterMapWidget.cpp
+++ b/Userland/Applications/CharacterMap/CharacterMapWidget.cpp
@@ -14,6 +14,7 @@
#include <LibGUI/Icon.h>
#include <LibGUI/Label.h>
#include <LibGUI/Menu.h>
+#include <LibGUI/TextBox.h>
#include <LibGUI/Toolbar.h>
#include <LibUnicode/CharacterTypes.h>
@@ -24,6 +25,8 @@ CharacterMapWidget::CharacterMapWidget()
m_toolbar = find_descendant_of_type_named<GUI::Toolbar>("toolbar");
m_font_name_label = find_descendant_of_type_named<GUI::Label>("font_name");
m_glyph_map = find_descendant_of_type_named<GUI::GlyphMapWidget>("glyph_map");
+ m_output_box = find_descendant_of_type_named<GUI::TextBox>("output_box");
+ m_copy_output_button = find_descendant_of_type_named<GUI::Button>("copy_output_button");
m_statusbar = find_descendant_of_type_named<GUI::Statusbar>("statusbar");
m_choose_font_action = GUI::Action::create("Choose Font...", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-font-editor.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
@@ -54,6 +57,17 @@ CharacterMapWidget::CharacterMapWidget()
update_statusbar();
};
+ m_glyph_map->on_glyph_double_clicked = [&](int code_point) {
+ StringBuilder builder;
+ builder.append(m_output_box->text());
+ builder.append_code_point(code_point);
+ m_output_box->set_text(builder.string_view());
+ };
+
+ m_copy_output_button->on_click = [&](auto) {
+ GUI::Clipboard::the().set_plain_text(m_output_box->text());
+ };
+
did_change_font();
update_statusbar();
}
@@ -77,6 +91,7 @@ void CharacterMapWidget::did_change_font()
{
m_glyph_map->set_font(font());
m_font_name_label->set_text(font().qualified_name());
+ m_output_box->set_font(font());
}
void CharacterMapWidget::update_statusbar()
diff --git a/Userland/Applications/CharacterMap/CharacterMapWidget.h b/Userland/Applications/CharacterMap/CharacterMapWidget.h
index bf4e881017..2af5f93c5d 100644
--- a/Userland/Applications/CharacterMap/CharacterMapWidget.h
+++ b/Userland/Applications/CharacterMap/CharacterMapWidget.h
@@ -27,6 +27,8 @@ private:
RefPtr<GUI::Toolbar> m_toolbar;
RefPtr<GUI::Label> m_font_name_label;
RefPtr<GUI::GlyphMapWidget> m_glyph_map;
+ RefPtr<GUI::TextBox> m_output_box;
+ RefPtr<GUI::Button> m_copy_output_button;
RefPtr<GUI::Statusbar> m_statusbar;
RefPtr<GUI::Action> m_choose_font_action;
diff --git a/Userland/Applications/CharacterMap/CharacterMapWindow.gml b/Userland/Applications/CharacterMap/CharacterMapWindow.gml
index 3824614848..0b4b211af1 100644
--- a/Userland/Applications/CharacterMap/CharacterMapWindow.gml
+++ b/Userland/Applications/CharacterMap/CharacterMapWindow.gml
@@ -38,6 +38,25 @@
name: "glyph_map"
}
+ @GUI::Widget {
+ shrink_to_fit: true
+
+ layout: @GUI::HorizontalBoxLayout {
+ spacing: 4
+ margins: [0, 2, 0, 2]
+ }
+
+ @GUI::TextBox {
+ name: "output_box"
+ }
+
+ @GUI::Button {
+ name: "copy_output_button"
+ icon: "/res/icons/16x16/edit-copy.png"
+ fixed_width: 22
+ }
+ }
+
@GUI::Statusbar {
name: "statusbar"
}