summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorMarcus Nilsson <brainbomb@gmail.com>2021-08-02 19:30:50 +0200
committerAndreas Kling <kling@serenityos.org>2021-08-03 09:04:57 +0200
commite342bef854488d91b8f4cac244c5e8bce9ba12f2 (patch)
tree7642f53ff7885efb7b8a1994118ce0c3c8889e93 /Userland
parentf58891ed428e236815415ff280c4a7d508326c3b (diff)
downloadserenity-e342bef854488d91b8f4cac244c5e8bce9ba12f2.zip
PixelPaint: Move properties for EraserTool to ToolPropertiesWidget
Removes the context menu for EraserTool and instead use the tool properties widget for options.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/PixelPaint/EraseTool.cpp72
-rw-r--r--Userland/Applications/PixelPaint/EraseTool.h5
2 files changed, 43 insertions, 34 deletions
diff --git a/Userland/Applications/PixelPaint/EraseTool.cpp b/Userland/Applications/PixelPaint/EraseTool.cpp
index 82f2ab0c87..8b8a93da38 100644
--- a/Userland/Applications/PixelPaint/EraseTool.cpp
+++ b/Userland/Applications/PixelPaint/EraseTool.cpp
@@ -8,8 +8,12 @@
#include "ImageEditor.h"
#include "Layer.h"
#include <LibGUI/Action.h>
+#include <LibGUI/BoxLayout.h>
+#include <LibGUI/CheckBox.h>
+#include <LibGUI/Label.h>
#include <LibGUI/Menu.h>
#include <LibGUI/Painter.h>
+#include <LibGUI/Slider.h>
#include <LibGfx/Bitmap.h>
namespace PixelPaint {
@@ -59,37 +63,6 @@ void EraseTool::on_mouseup(Layer&, GUI::MouseEvent& event, GUI::MouseEvent&)
m_editor->did_complete_action();
}
-void EraseTool::on_tool_button_contextmenu(GUI::ContextMenuEvent& event)
-{
- if (!m_context_menu) {
- m_context_menu = GUI::Menu::construct();
-
- auto eraser_color_toggler = GUI::Action::create_checkable("Use secondary color", [&](auto& action) {
- m_use_secondary_color = action.is_checked();
- });
- eraser_color_toggler->set_checked(m_use_secondary_color);
-
- m_context_menu->add_action(eraser_color_toggler);
- m_context_menu->add_separator();
-
- m_thickness_actions.set_exclusive(true);
- auto insert_action = [&](int size, bool checked = false) {
- auto action = GUI::Action::create_checkable(String::number(size), [this, size](auto&) {
- m_thickness = size;
- });
- action->set_checked(checked);
- m_thickness_actions.add_action(*action);
- m_context_menu->add_action(move(action));
- };
- insert_action(1, true);
- insert_action(2);
- insert_action(3);
- insert_action(4);
- }
-
- m_context_menu->popup(event.screen_position());
-}
-
Color EraseTool::get_color() const
{
if (m_use_secondary_color)
@@ -97,4 +70,41 @@ Color EraseTool::get_color() const
return Color(255, 255, 255, 0);
}
+GUI::Widget* EraseTool::get_properties_widget()
+{
+ if (!m_properties_widget) {
+ m_properties_widget = GUI::Widget::construct();
+ m_properties_widget->set_layout<GUI::VerticalBoxLayout>();
+
+ auto& thickness_container = m_properties_widget->add<GUI::Widget>();
+ thickness_container.set_fixed_height(20);
+ thickness_container.set_layout<GUI::HorizontalBoxLayout>();
+
+ auto& thickness_label = thickness_container.add<GUI::Label>("Size:");
+ thickness_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
+ thickness_label.set_fixed_size(80, 20);
+
+ auto& thickness_slider = thickness_container.add<GUI::HorizontalSlider>();
+ thickness_slider.set_fixed_height(20);
+ thickness_slider.set_range(1, 5);
+ thickness_slider.set_value(m_thickness);
+ thickness_slider.on_change = [&](int value) {
+ m_thickness = value;
+ };
+
+ auto& checkbox_container = m_properties_widget->add<GUI::Widget>();
+ checkbox_container.set_fixed_height(20);
+ checkbox_container.set_layout<GUI::HorizontalBoxLayout>();
+
+ auto& use_secondary_color_checkbox = checkbox_container.add<GUI::CheckBox>();
+ use_secondary_color_checkbox.set_checked(m_use_secondary_color);
+ use_secondary_color_checkbox.set_text("Use secondary color");
+ use_secondary_color_checkbox.on_checked = [&](bool checked) {
+ m_use_secondary_color = checked;
+ };
+ }
+
+ return m_properties_widget.ptr();
+}
+
}
diff --git a/Userland/Applications/PixelPaint/EraseTool.h b/Userland/Applications/PixelPaint/EraseTool.h
index 80472ddf65..3251a45ed1 100644
--- a/Userland/Applications/PixelPaint/EraseTool.h
+++ b/Userland/Applications/PixelPaint/EraseTool.h
@@ -21,16 +21,15 @@ public:
virtual void on_mousedown(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& image_event) override;
virtual void on_mousemove(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& image_event) override;
virtual void on_mouseup(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& image_event) override;
- virtual void on_tool_button_contextmenu(GUI::ContextMenuEvent&) override;
+ virtual GUI::Widget* get_properties_widget() override;
private:
Gfx::Color get_color() const;
Gfx::IntRect build_rect(Gfx::IntPoint const& pos, Gfx::IntRect const& widget_rect);
- RefPtr<GUI::Menu> m_context_menu;
+ RefPtr<GUI::Widget> m_properties_widget;
bool m_use_secondary_color { false };
int m_thickness { 1 };
- GUI::ActionGroup m_thickness_actions;
};
}