From db99e0917cec45aa0a1cc1fd371b0b60bf422f4f Mon Sep 17 00:00:00 2001 From: LepkoQQ Date: Mon, 14 Jun 2021 22:26:15 +0200 Subject: [PATCH] PixelPaint: Add menu items for Select All and Clear Selection We also need to update the image editor when clearing selection otherwise the last state of the selection will be displayed until an update happens. --- Userland/Applications/PixelPaint/Selection.cpp | 6 ++++++ Userland/Applications/PixelPaint/Selection.h | 2 +- Userland/Applications/PixelPaint/main.cpp | 13 +++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Userland/Applications/PixelPaint/Selection.cpp b/Userland/Applications/PixelPaint/Selection.cpp index 7bdef9d97d..cd5d32f235 100644 --- a/Userland/Applications/PixelPaint/Selection.cpp +++ b/Userland/Applications/PixelPaint/Selection.cpp @@ -56,4 +56,10 @@ void Selection::draw_marching_ants(Gfx::Painter& painter, Gfx::IntRect const& re draw_pixel(rect.left(), y); } +void Selection::clear() +{ + m_rect = {}; + m_editor.update(); +} + } diff --git a/Userland/Applications/PixelPaint/Selection.h b/Userland/Applications/PixelPaint/Selection.h index 443e85d515..bdcf299d12 100644 --- a/Userland/Applications/PixelPaint/Selection.h +++ b/Userland/Applications/PixelPaint/Selection.h @@ -19,7 +19,7 @@ public: explicit Selection(ImageEditor&); bool is_empty() const { return m_rect.is_empty(); } - void clear() { m_rect = {}; } + void clear(); void set(Gfx::IntRect const& rect) { m_rect = rect; } Gfx::IntRect bounding_rect() const { return m_rect; } diff --git a/Userland/Applications/PixelPaint/main.cpp b/Userland/Applications/PixelPaint/main.cpp index 797ba26300..a8f3c44622 100644 --- a/Userland/Applications/PixelPaint/main.cpp +++ b/Userland/Applications/PixelPaint/main.cpp @@ -207,6 +207,19 @@ int main(int argc, char** argv) }); edit_menu.add_action(redo_action); + edit_menu.add_separator(); + edit_menu.add_action(GUI::CommonActions::make_select_all_action([&](auto&) { + VERIFY(image_editor.image()); + if (!image_editor.active_layer()) + return; + image_editor.selection().set(image_editor.active_layer()->relative_rect()); + })); + edit_menu.add_action(GUI::Action::create( + "Clear &Selection", { Mod_Ctrl | Mod_Shift, Key_A }, [&](auto&) { + image_editor.selection().clear(); + }, + window)); + auto& view_menu = menubar->add_menu("&View"); auto zoom_in_action = GUI::CommonActions::make_zoom_in_action(