diff --git a/Userland/Applications/PixelPaint/PaletteWidget.cpp b/Userland/Applications/PixelPaint/PaletteWidget.cpp index 9c2c706bce..9395a3c04d 100644 --- a/Userland/Applications/PixelPaint/PaletteWidget.cpp +++ b/Userland/Applications/PixelPaint/PaletteWidget.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2021, Felix Rauch + * Copyright (c) 2021, Mustafa Quraish * * SPDX-License-Identifier: BSD-2-Clause */ @@ -61,6 +62,34 @@ private: Color m_color; }; +class SelectedColorWidget : public GUI::Frame { + C_OBJECT(SelectedColorWidget); + +public: + virtual ~SelectedColorWidget() override { } + + virtual void mousedown_event(GUI::MouseEvent& event) override + { + if (event.button() != GUI::MouseButton::Left || !on_color_change) + return; + + auto dialog = GUI::ColorPicker::construct(m_color, window()); + if (dialog->exec() == GUI::Dialog::ExecOK) + on_color_change(dialog->color()); + } + + void set_background_color(Color const& color) + { + auto pal = palette(); + pal.set_color(ColorRole::Background, color); + set_palette(pal); + update(); + } + + Function on_color_change; + Color m_color = Color::White; +}; + PaletteWidget::PaletteWidget() { set_frame_shape(Gfx::FrameShape::Panel); @@ -70,11 +99,17 @@ PaletteWidget::PaletteWidget() set_fixed_height(35); - m_secondary_color_widget = add(); + m_secondary_color_widget = add(); + m_secondary_color_widget->on_color_change = [&](auto& color) { + set_secondary_color(color); + }; m_secondary_color_widget->set_relative_rect({ 0, 2, 60, 33 }); m_secondary_color_widget->set_fill_with_background_color(true); - m_primary_color_widget = add(); + m_primary_color_widget = add(); + m_primary_color_widget->on_color_change = [&](auto& color) { + set_primary_color(color); + }; auto rect = Gfx::IntRect(0, 0, 35, 17).centered_within(m_secondary_color_widget->relative_rect()); m_primary_color_widget->set_relative_rect(rect); m_primary_color_widget->set_fill_with_background_color(true); @@ -127,19 +162,13 @@ PaletteWidget::~PaletteWidget() void PaletteWidget::set_primary_color(Color color) { m_editor->set_primary_color(color); - auto pal = m_primary_color_widget->palette(); - pal.set_color(ColorRole::Background, color); - m_primary_color_widget->set_palette(pal); - m_primary_color_widget->update(); + m_primary_color_widget->set_background_color(color); } void PaletteWidget::set_secondary_color(Color color) { m_editor->set_secondary_color(color); - auto pal = m_secondary_color_widget->palette(); - pal.set_color(ColorRole::Background, color); - m_secondary_color_widget->set_palette(pal); - m_secondary_color_widget->update(); + m_secondary_color_widget->set_background_color(color); } void PaletteWidget::display_color_list(Vector const& colors) diff --git a/Userland/Applications/PixelPaint/PaletteWidget.h b/Userland/Applications/PixelPaint/PaletteWidget.h index b90e5d8b42..4e8a48a9b0 100644 --- a/Userland/Applications/PixelPaint/PaletteWidget.h +++ b/Userland/Applications/PixelPaint/PaletteWidget.h @@ -1,6 +1,7 @@ /* * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2021, Felix Rauch + * Copyright (c) 2021, Mustafa Quraish * * SPDX-License-Identifier: BSD-2-Clause */ @@ -14,6 +15,7 @@ namespace PixelPaint { class ImageEditor; +class SelectedColorWidget; class PaletteWidget final : public GUI::Frame { C_OBJECT(PaletteWidget); @@ -41,8 +43,8 @@ private: explicit PaletteWidget(); ImageEditor* m_editor { nullptr }; - RefPtr m_primary_color_widget; - RefPtr m_secondary_color_widget; + RefPtr m_primary_color_widget; + RefPtr m_secondary_color_widget; RefPtr m_color_container; };