1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:17:45 +00:00

PixelPaint: Move properties for LineTool to ToolPropertiesWidget

Remove the context menu for LineTool and use the tool properties
widget for options instead.
This commit is contained in:
Marcus Nilsson 2021-08-02 23:07:39 +02:00 committed by Andreas Kling
parent 201b901cb1
commit 0c4977161f
2 changed files with 27 additions and 20 deletions

View file

@ -9,8 +9,11 @@
#include "Layer.h"
#include <AK/Math.h>
#include <LibGUI/Action.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Label.h>
#include <LibGUI/Menu.h>
#include <LibGUI/Painter.h>
#include <LibGUI/Slider.h>
namespace PixelPaint {
@ -97,25 +100,30 @@ void LineTool::on_keydown(GUI::KeyEvent& event)
}
}
void LineTool::on_tool_button_contextmenu(GUI::ContextMenuEvent& event)
GUI::Widget* LineTool::get_properties_widget()
{
if (!m_context_menu) {
m_context_menu = GUI::Menu::construct();
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));
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>("Thickness:");
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, 10);
thickness_slider.set_value(m_thickness);
thickness_slider.on_change = [&](int value) {
m_thickness = value;
};
insert_action(1, true);
insert_action(2);
insert_action(3);
insert_action(4);
}
m_context_menu->popup(event.screen_position());
return m_properties_widget.ptr();
}
}