From 8d205ae62ee1637168efa19b1166e92071c9ac89 Mon Sep 17 00:00:00 2001 From: Marcus Nilsson Date: Thu, 1 Jul 2021 15:04:04 +0200 Subject: [PATCH] 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. --- .../Applications/PixelPaint/LayerListWidget.cpp | 14 ++++++++++++++ Userland/Applications/PixelPaint/LayerListWidget.h | 2 ++ Userland/Applications/PixelPaint/main.cpp | 4 ++++ 3 files changed, 20 insertions(+) diff --git a/Userland/Applications/PixelPaint/LayerListWidget.cpp b/Userland/Applications/PixelPaint/LayerListWidget.cpp index 6bf6c00d27..5b31ab2cc4 100644 --- a/Userland/Applications/PixelPaint/LayerListWidget.cpp +++ b/Userland/Applications/PixelPaint/LayerListWidget.cpp @@ -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()) { diff --git a/Userland/Applications/PixelPaint/LayerListWidget.h b/Userland/Applications/PixelPaint/LayerListWidget.h index 5a904d9c0a..e1d2008c95 100644 --- a/Userland/Applications/PixelPaint/LayerListWidget.h +++ b/Userland/Applications/PixelPaint/LayerListWidget.h @@ -23,6 +23,7 @@ public: void set_selected_layer(Layer*); Function on_layer_select; + Function 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; diff --git a/Userland/Applications/PixelPaint/main.cpp b/Userland/Applications/PixelPaint/main.cpp index 27167d347c..78e6a910d3 100644 --- a/Userland/Applications/PixelPaint/main.cpp +++ b/Userland/Applications/PixelPaint/main.cpp @@ -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");