summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-07-23 20:48:28 +0200
committerAndreas Kling <kling@serenityos.org>2020-07-23 20:48:28 +0200
commit65ec655b0dd206426af106fae3843e59ca475e94 (patch)
tree50db5925c2383e1ffb00d0b2e5472218d947ff21
parent955d3c22c703d25c872aedd4f4b56fa34ff8597a (diff)
downloadserenity-65ec655b0dd206426af106fae3843e59ca475e94.zip
PixelPaint: Add GUI for editing layer names :^)
-rw-r--r--Applications/PixelPaint/Layer.cpp8
-rw-r--r--Applications/PixelPaint/Layer.h2
-rw-r--r--Applications/PixelPaint/LayerPropertiesWidget.cpp20
-rw-r--r--Applications/PixelPaint/LayerPropertiesWidget.h1
4 files changed, 30 insertions, 1 deletions
diff --git a/Applications/PixelPaint/Layer.cpp b/Applications/PixelPaint/Layer.cpp
index 6b91daf31e..9de9ff41de 100644
--- a/Applications/PixelPaint/Layer.cpp
+++ b/Applications/PixelPaint/Layer.cpp
@@ -69,4 +69,12 @@ void Layer::set_opacity_percent(int opacity_percent)
m_image.layer_did_modify_properties({}, *this);
}
+void Layer::set_name(const String& name)
+{
+ if (m_name == name)
+ return;
+ m_name = name;
+ m_image.layer_did_modify_properties({}, *this);
+}
+
}
diff --git a/Applications/PixelPaint/Layer.h b/Applications/PixelPaint/Layer.h
index e8ea62d887..a9aeb75c8f 100644
--- a/Applications/PixelPaint/Layer.h
+++ b/Applications/PixelPaint/Layer.h
@@ -59,7 +59,7 @@ public:
Gfx::IntRect rect() const { return { {}, size() }; }
const String& name() const { return m_name; }
- void set_name(const String& name) { m_name = name; }
+ void set_name(const String&);
void did_modify_bitmap(Image&);
diff --git a/Applications/PixelPaint/LayerPropertiesWidget.cpp b/Applications/PixelPaint/LayerPropertiesWidget.cpp
index 811508da8d..fccc607a21 100644
--- a/Applications/PixelPaint/LayerPropertiesWidget.cpp
+++ b/Applications/PixelPaint/LayerPropertiesWidget.cpp
@@ -31,6 +31,7 @@
#include <LibGUI/GroupBox.h>
#include <LibGUI/Label.h>
#include <LibGUI/Slider.h>
+#include <LibGUI/TextBox.h>
#include <LibGfx/Font.h>
namespace PixelPaint {
@@ -44,6 +45,24 @@ LayerPropertiesWidget::LayerPropertiesWidget()
layout.set_margins({ 10, 20, 10, 10 });
+ auto& name_container = group_box.add<GUI::Widget>();
+ name_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
+ name_container.set_preferred_size(0, 20);
+ name_container.set_layout<GUI::HorizontalBoxLayout>();
+
+ auto& name_label = name_container.add<GUI::Label>("Name:");
+ name_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
+ name_label.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
+ name_label.set_preferred_size(80, 20);
+
+ m_name_textbox = name_container.add<GUI::TextBox>();
+ m_name_textbox->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
+ m_name_textbox->set_preferred_size(0, 20);
+ m_name_textbox->on_change = [this] {
+ if (m_layer)
+ m_layer->set_name(m_name_textbox->text());
+ };
+
auto& opacity_container = group_box.add<GUI::Widget>();
opacity_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
opacity_container.set_preferred_size(0, 20);
@@ -83,6 +102,7 @@ void LayerPropertiesWidget::set_layer(Layer* layer)
if (layer) {
m_layer = layer->make_weak_ptr();
+ m_name_textbox->set_text(layer->name());
m_opacity_slider->set_value(layer->opacity_percent());
m_visibility_checkbox->set_checked(layer->is_visible());
set_enabled(true);
diff --git a/Applications/PixelPaint/LayerPropertiesWidget.h b/Applications/PixelPaint/LayerPropertiesWidget.h
index b4b59c2696..ce2d65dc43 100644
--- a/Applications/PixelPaint/LayerPropertiesWidget.h
+++ b/Applications/PixelPaint/LayerPropertiesWidget.h
@@ -45,6 +45,7 @@ private:
RefPtr<GUI::CheckBox> m_visibility_checkbox;
RefPtr<GUI::HorizontalSlider> m_opacity_slider;
+ RefPtr<GUI::TextBox> m_name_textbox;
WeakPtr<Layer> m_layer;
};