From 868be680c2ea9b27630f246a38de28c0aa79172b Mon Sep 17 00:00:00 2001 From: Marcus Nilsson Date: Thu, 5 Aug 2021 19:36:38 +0200 Subject: [PATCH] PixelPaint: Use the ValueSlider widget for Tool properties Use the new ValueSlider and get rid of the temporary solution with tooltips :^) --- Userland/Applications/PixelPaint/BrushTool.cpp | 12 +++--------- Userland/Applications/PixelPaint/BucketTool.cpp | 7 ++----- Userland/Applications/PixelPaint/EllipseTool.cpp | 7 ++----- Userland/Applications/PixelPaint/EraseTool.cpp | 11 ++++------- Userland/Applications/PixelPaint/EraseTool.h | 1 - Userland/Applications/PixelPaint/LineTool.cpp | 7 ++----- Userland/Applications/PixelPaint/PenTool.cpp | 7 ++----- .../Applications/PixelPaint/RectangleSelectTool.cpp | 9 +++------ Userland/Applications/PixelPaint/SprayTool.cpp | 12 +++--------- Userland/Applications/PixelPaint/ZoomTool.cpp | 7 ++----- 10 files changed, 23 insertions(+), 57 deletions(-) diff --git a/Userland/Applications/PixelPaint/BrushTool.cpp b/Userland/Applications/PixelPaint/BrushTool.cpp index f5ee2179db..dad399c880 100644 --- a/Userland/Applications/PixelPaint/BrushTool.cpp +++ b/Userland/Applications/PixelPaint/BrushTool.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include @@ -126,15 +126,12 @@ GUI::Widget* BrushTool::get_properties_widget() size_label.set_text_alignment(Gfx::TextAlignment::CenterLeft); size_label.set_fixed_size(80, 20); - auto& size_slider = size_container.add(); - size_slider.set_fixed_height(20); + auto& size_slider = size_container.add(Orientation::Horizontal, "px"); size_slider.set_range(1, 100); size_slider.set_value(m_size); - size_slider.set_tooltip(String::formatted("{}px", m_size)); size_slider.on_change = [&](int value) { m_size = value; - size_slider.set_tooltip(String::formatted("{}px", value)); }; auto& hardness_container = m_properties_widget->add(); @@ -145,15 +142,12 @@ GUI::Widget* BrushTool::get_properties_widget() hardness_label.set_text_alignment(Gfx::TextAlignment::CenterLeft); hardness_label.set_fixed_size(80, 20); - auto& hardness_slider = hardness_container.add(); - hardness_slider.set_fixed_height(20); + auto& hardness_slider = hardness_container.add(Orientation::Horizontal, "%"); hardness_slider.set_range(1, 99); hardness_slider.set_value(m_hardness); - hardness_slider.set_tooltip(String::formatted("{}%", m_hardness)); hardness_slider.on_change = [&](int value) { m_hardness = value; - hardness_slider.set_tooltip(String::formatted("{}%", value)); }; } diff --git a/Userland/Applications/PixelPaint/BucketTool.cpp b/Userland/Applications/PixelPaint/BucketTool.cpp index 6a0e35c691..2801260a9b 100644 --- a/Userland/Applications/PixelPaint/BucketTool.cpp +++ b/Userland/Applications/PixelPaint/BucketTool.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include @@ -98,15 +98,12 @@ GUI::Widget* BucketTool::get_properties_widget() threshold_label.set_text_alignment(Gfx::TextAlignment::CenterLeft); threshold_label.set_fixed_size(80, 20); - auto& threshold_slider = threshold_container.add(); - threshold_slider.set_fixed_height(20); + auto& threshold_slider = threshold_container.add(Orientation::Horizontal, "%"); threshold_slider.set_range(0, 100); threshold_slider.set_value(m_threshold); - threshold_slider.set_tooltip(String::formatted("{}%", m_threshold)); threshold_slider.on_change = [&](int value) { m_threshold = value; - threshold_slider.set_tooltip(String::formatted("{}%", value)); }; } diff --git a/Userland/Applications/PixelPaint/EllipseTool.cpp b/Userland/Applications/PixelPaint/EllipseTool.cpp index b996d497d4..05bcac5a9d 100644 --- a/Userland/Applications/PixelPaint/EllipseTool.cpp +++ b/Userland/Applications/PixelPaint/EllipseTool.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include namespace PixelPaint { @@ -109,15 +109,12 @@ GUI::Widget* EllipseTool::get_properties_widget() thickness_label.set_text_alignment(Gfx::TextAlignment::CenterLeft); thickness_label.set_fixed_size(80, 20); - auto& thickness_slider = thickness_container.add(); - thickness_slider.set_fixed_height(20); + auto& thickness_slider = thickness_container.add(Orientation::Horizontal, "px"); thickness_slider.set_range(1, 10); thickness_slider.set_value(m_thickness); - thickness_slider.set_tooltip(String::formatted("{}px", m_thickness)); thickness_slider.on_change = [&](int value) { m_thickness = value; - thickness_slider.set_tooltip(String::formatted("{}px", value)); }; auto& mode_container = m_properties_widget->add(); diff --git a/Userland/Applications/PixelPaint/EraseTool.cpp b/Userland/Applications/PixelPaint/EraseTool.cpp index df32f177f5..90a6292d4b 100644 --- a/Userland/Applications/PixelPaint/EraseTool.cpp +++ b/Userland/Applications/PixelPaint/EraseTool.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include namespace PixelPaint { @@ -28,7 +28,7 @@ EraseTool::~EraseTool() Gfx::IntRect EraseTool::build_rect(Gfx::IntPoint const& pos, Gfx::IntRect const& widget_rect) { - const int eraser_size = (m_base_eraser_size * m_thickness); + const int eraser_size = m_thickness; const int eraser_radius = eraser_size / 2; const auto ex = pos.x(); const auto ey = pos.y(); @@ -83,15 +83,12 @@ GUI::Widget* EraseTool::get_properties_widget() thickness_label.set_text_alignment(Gfx::TextAlignment::CenterLeft); thickness_label.set_fixed_size(80, 20); - auto& thickness_slider = thickness_container.add(); - thickness_slider.set_fixed_height(20); - thickness_slider.set_range(1, 5); + auto& thickness_slider = thickness_container.add(Orientation::Horizontal, "px"); + thickness_slider.set_range(1, 50); thickness_slider.set_value(m_thickness); - thickness_slider.set_tooltip(String::formatted("{}px", m_base_eraser_size * m_thickness)); thickness_slider.on_change = [&](int value) { m_thickness = value; - thickness_slider.set_tooltip(String::formatted("{}px", m_base_eraser_size * value)); }; auto& checkbox_container = m_properties_widget->add(); diff --git a/Userland/Applications/PixelPaint/EraseTool.h b/Userland/Applications/PixelPaint/EraseTool.h index 7c9e1dc849..3251a45ed1 100644 --- a/Userland/Applications/PixelPaint/EraseTool.h +++ b/Userland/Applications/PixelPaint/EraseTool.h @@ -30,7 +30,6 @@ private: bool m_use_secondary_color { false }; int m_thickness { 1 }; - const int m_base_eraser_size { 10 }; }; } diff --git a/Userland/Applications/PixelPaint/LineTool.cpp b/Userland/Applications/PixelPaint/LineTool.cpp index 52bc3baaa8..dfe2da0165 100644 --- a/Userland/Applications/PixelPaint/LineTool.cpp +++ b/Userland/Applications/PixelPaint/LineTool.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include namespace PixelPaint { @@ -114,15 +114,12 @@ GUI::Widget* LineTool::get_properties_widget() thickness_label.set_text_alignment(Gfx::TextAlignment::CenterLeft); thickness_label.set_fixed_size(80, 20); - auto& thickness_slider = thickness_container.add(); - thickness_slider.set_fixed_height(20); + auto& thickness_slider = thickness_container.add(Orientation::Horizontal, "px"); thickness_slider.set_range(1, 10); thickness_slider.set_value(m_thickness); - thickness_slider.set_tooltip(String::formatted("{}px", m_thickness)); thickness_slider.on_change = [&](int value) { m_thickness = value; - thickness_slider.set_tooltip(String::formatted("{}px", value)); }; } diff --git a/Userland/Applications/PixelPaint/PenTool.cpp b/Userland/Applications/PixelPaint/PenTool.cpp index 1a8fb9bfe8..3ab370a5f7 100644 --- a/Userland/Applications/PixelPaint/PenTool.cpp +++ b/Userland/Applications/PixelPaint/PenTool.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include namespace PixelPaint { @@ -77,15 +77,12 @@ GUI::Widget* PenTool::get_properties_widget() thickness_label.set_text_alignment(Gfx::TextAlignment::CenterLeft); thickness_label.set_fixed_size(80, 20); - auto& thickness_slider = thickness_container.add(); - thickness_slider.set_fixed_height(20); + auto& thickness_slider = thickness_container.add(Orientation::Horizontal, "px"); thickness_slider.set_range(1, 20); thickness_slider.set_value(m_thickness); - thickness_slider.set_tooltip(String::formatted("{}px", m_thickness)); thickness_slider.on_change = [&](int value) { m_thickness = value; - thickness_slider.set_tooltip(String::formatted("{}px", value)); }; } diff --git a/Userland/Applications/PixelPaint/RectangleSelectTool.cpp b/Userland/Applications/PixelPaint/RectangleSelectTool.cpp index b84d4ec8d9..8155311c2e 100644 --- a/Userland/Applications/PixelPaint/RectangleSelectTool.cpp +++ b/Userland/Applications/PixelPaint/RectangleSelectTool.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include namespace PixelPaint { @@ -153,16 +153,13 @@ GUI::Widget* RectangleSelectTool::get_properties_widget() feather_label.set_text_alignment(Gfx::TextAlignment::CenterLeft); feather_label.set_fixed_size(80, 20); - const int feather_slider_max = 10000; - auto& feather_slider = feather_container.add(); - feather_slider.set_fixed_height(20); + const int feather_slider_max = 100; + auto& feather_slider = feather_container.add(Orientation::Horizontal, "%"); feather_slider.set_range(0, feather_slider_max); feather_slider.set_value((int)floorf(m_edge_feathering * (float)feather_slider_max)); - feather_slider.set_tooltip(String::formatted("{:.2}", (float)m_edge_feathering / (float)feather_slider_max)); feather_slider.on_change = [&](int value) { m_edge_feathering = (float)value / (float)feather_slider_max; - feather_slider.set_tooltip(String::formatted("{:.2}", (float)value / (float)feather_slider_max)); }; auto& mode_container = m_properties_widget->add(); diff --git a/Userland/Applications/PixelPaint/SprayTool.cpp b/Userland/Applications/PixelPaint/SprayTool.cpp index 8fc2b7baa7..b28a9ec8ec 100644 --- a/Userland/Applications/PixelPaint/SprayTool.cpp +++ b/Userland/Applications/PixelPaint/SprayTool.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include namespace PixelPaint { @@ -102,15 +102,12 @@ GUI::Widget* SprayTool::get_properties_widget() size_label.set_text_alignment(Gfx::TextAlignment::CenterLeft); size_label.set_fixed_size(80, 20); - auto& size_slider = size_container.add(); - size_slider.set_fixed_height(20); + auto& size_slider = size_container.add(Orientation::Horizontal, "px"); size_slider.set_range(1, 20); size_slider.set_value(m_thickness); - size_slider.set_tooltip(String::formatted("{}", m_thickness)); size_slider.on_change = [&](int value) { m_thickness = value; - size_slider.set_tooltip(String::formatted("{}", value)); }; auto& density_container = m_properties_widget->add(); @@ -121,15 +118,12 @@ GUI::Widget* SprayTool::get_properties_widget() density_label.set_text_alignment(Gfx::TextAlignment::CenterLeft); density_label.set_fixed_size(80, 20); - auto& density_slider = density_container.add(); - density_slider.set_fixed_height(30); + auto& density_slider = density_container.add(Orientation::Horizontal, "%"); density_slider.set_range(1, 100); density_slider.set_value(m_density); - density_slider.set_tooltip(String::formatted("{}%", m_density)); density_slider.on_change = [&](int value) { m_density = value; - density_slider.set_tooltip(String::formatted("{}%", value)); }; } diff --git a/Userland/Applications/PixelPaint/ZoomTool.cpp b/Userland/Applications/PixelPaint/ZoomTool.cpp index 318443699b..81022550d4 100644 --- a/Userland/Applications/PixelPaint/ZoomTool.cpp +++ b/Userland/Applications/PixelPaint/ZoomTool.cpp @@ -8,7 +8,7 @@ #include "ImageEditor.h" #include #include -#include +#include namespace PixelPaint { @@ -43,15 +43,12 @@ GUI::Widget* ZoomTool::get_properties_widget() sensitivity_label.set_text_alignment(Gfx::TextAlignment::CenterLeft); sensitivity_label.set_fixed_size(80, 20); - auto& sensitivity_slider = sensitivity_container.add(); - sensitivity_slider.set_fixed_height(20); + auto& sensitivity_slider = sensitivity_container.add(Orientation::Horizontal, "%"); sensitivity_slider.set_range(1, 100); sensitivity_slider.set_value(100 * m_sensitivity); - sensitivity_slider.set_tooltip(String::formatted("{:.2}", (double)m_sensitivity / 100.0)); sensitivity_slider.on_change = [&](int value) { m_sensitivity = (double)value / 100.0; - sensitivity_slider.set_tooltip(String::formatted("{:.2}", (double)value / 100.0)); }; }