diff --git a/Libraries/LibGUI/ColorInput.cpp b/Libraries/LibGUI/ColorInput.cpp index 291203f1a55acb..14c192e1ccd28f 100644 --- a/Libraries/LibGUI/ColorInput.cpp +++ b/Libraries/LibGUI/ColorInput.cpp @@ -67,27 +67,15 @@ void ColorInput::set_color(Color color) { if (m_color == color) return; - set_text(color.to_string()); + set_text(m_color_has_alpha_channel ? color.to_string() : color.to_string_without_alpha()); }; -void ColorInput::set_color_has_alpha_channel(bool has_alpha) -{ - if (m_color_has_alpha_channel == has_alpha) - return; - - m_color_has_alpha_channel = has_alpha; - m_color.set_alpha(0xff); - if (!has_alpha) - set_text(m_color.to_string_without_alpha()); - else - set_text(m_color.to_string()); -} - void ColorInput::mousedown_event(MouseEvent& event) { if (event.button() == MouseButton::Left) { if (is_enabled() && color_rect().contains(event.position())) { auto dialog = GUI::ColorPicker::construct(m_color, window(), m_color_picker_title); + dialog->set_color_has_alpha_channel(m_color_has_alpha_channel); if (dialog->exec() == GUI::Dialog::ExecOK) set_color(dialog->color()); event.accept(); diff --git a/Libraries/LibGUI/ColorInput.h b/Libraries/LibGUI/ColorInput.h index c1170c292c841e..d223ce7ff4cc29 100644 --- a/Libraries/LibGUI/ColorInput.h +++ b/Libraries/LibGUI/ColorInput.h @@ -38,7 +38,7 @@ class ColorInput final : public TextEditor { virtual ~ColorInput() override; bool has_alpha_channel() const { return m_color_has_alpha_channel; } - void set_color_has_alpha_channel(bool); + void set_color_has_alpha_channel(bool has_alpha) { m_color_has_alpha_channel = has_alpha; } void set_color(Color); Color color() { return m_color; } diff --git a/Libraries/LibGUI/ColorPicker.cpp b/Libraries/LibGUI/ColorPicker.cpp index 2b4ee5ab2e420a..85cd780d3bc727 100644 --- a/Libraries/LibGUI/ColorPicker.cpp +++ b/Libraries/LibGUI/ColorPicker.cpp @@ -223,7 +223,7 @@ void ColorPicker::build_ui_custom(Widget& root_container) m_html_text = html_container.add(); m_html_text->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill); - m_html_text->set_text(m_color.to_string()); + m_html_text->set_text(m_color_has_alpha_channel ? m_color.to_string() : m_color.to_string_without_alpha()); m_html_text->on_change = [this]() { auto color_name = this->m_html_text->text(); auto optional_color = Color::from_string(color_name); @@ -299,7 +299,7 @@ void ColorPicker::update_color_widgets() m_preview_widget->set_palette(pal); m_preview_widget->update(); - m_html_text->set_text(m_color.to_string()); + m_html_text->set_text(m_color_has_alpha_channel ? m_color.to_string() : m_color.to_string_without_alpha()); m_red_spinbox->set_value(m_color.red()); m_green_spinbox->set_value(m_color.green()); diff --git a/Libraries/LibGUI/ColorPicker.h b/Libraries/LibGUI/ColorPicker.h index d9cf6d10b1696e..ef62ab84cf661c 100644 --- a/Libraries/LibGUI/ColorPicker.h +++ b/Libraries/LibGUI/ColorPicker.h @@ -40,6 +40,8 @@ class ColorPicker final : public Dialog { public: virtual ~ColorPicker() override; + bool color_has_alpha_channel() const { return m_color_has_alpha_channel; } + void set_color_has_alpha_channel(bool has_alpha) { m_color_has_alpha_channel = has_alpha; } Color color() const { return m_color; } private: @@ -52,6 +54,7 @@ class ColorPicker final : public Dialog { void create_color_button(Widget& container, unsigned rgb); Color m_color; + bool m_color_has_alpha_channel { true }; Vector m_color_widgets; RefPtr m_custom_color;