PixelPaint: Use layer menu as context menu in LayerListWidget

This enables the layer menu as a context menu in LayerListWidget,
setting the clicked layer as active for now, but in the future it
would be nice to have custom menu applying to the clicked layer instead
of the active layer.
This commit is contained in:
Marcus Nilsson 2021-07-01 15:04:04 +02:00 committed by Andreas Kling
parent 9df3550e58
commit 8d205ae62e
Notes: sideshowbarker 2024-07-18 10:21:11 +09:00
3 changed files with 20 additions and 0 deletions

View file

@ -183,6 +183,20 @@ void LayerListWidget::mouseup_event(GUI::MouseEvent& event)
m_image->change_layer_index(old_index, new_index);
}
void LayerListWidget::context_menu_event(GUI::ContextMenuEvent& event)
{
Gfx::IntPoint translated_event_point = { 0, vertical_scrollbar().value() + event.position().y() };
auto gadget_index = gadget_at(translated_event_point);
if (gadget_index.has_value()) {
auto& layer = m_image->layer(gadget_index.value());
set_selected_layer(&layer);
}
if (on_context_menu_request)
on_context_menu_request(event);
}
void LayerListWidget::image_did_add_layer(size_t layer_index)
{
if (m_moving_gadget_index.has_value()) {

View file

@ -23,6 +23,7 @@ public:
void set_selected_layer(Layer*);
Function<void(Layer*)> on_layer_select;
Function<void(GUI::ContextMenuEvent&)> on_context_menu_request;
void select_bottom_layer();
void select_top_layer();
@ -35,6 +36,7 @@ private:
virtual void mousedown_event(GUI::MouseEvent&) override;
virtual void mousemove_event(GUI::MouseEvent&) override;
virtual void mouseup_event(GUI::MouseEvent&) override;
virtual void context_menu_event(GUI::ContextMenuEvent&) override;
virtual void resize_event(GUI::ResizeEvent&) override;
virtual void image_did_add_layer(size_t) override;

View file

@ -405,6 +405,10 @@ int main(int argc, char** argv)
},
window));
layer_list_widget.on_context_menu_request = [&](auto& event) {
layer_menu.popup(event.screen_position());
};
auto& filter_menu = menubar->add_menu("&Filter");
auto& spatial_filters_menu = filter_menu.add_submenu("&Spatial");