diff options
-rw-r--r-- | Libraries/LibGUI/ColorInput.cpp | 16 | ||||
-rw-r--r-- | Libraries/LibGUI/ColorInput.h | 2 | ||||
-rw-r--r-- | Libraries/LibGUI/ColorPicker.cpp | 4 | ||||
-rw-r--r-- | Libraries/LibGUI/ColorPicker.h | 3 |
4 files changed, 8 insertions, 17 deletions
diff --git a/Libraries/LibGUI/ColorInput.cpp b/Libraries/LibGUI/ColorInput.cpp index 291203f1a5..14c192e1cc 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 c1170c292c..d223ce7ff4 100644 --- a/Libraries/LibGUI/ColorInput.h +++ b/Libraries/LibGUI/ColorInput.h @@ -38,7 +38,7 @@ public: 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 2b4ee5ab2e..85cd780d3b 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<GUI::TextBox>(); 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 d9cf6d10b1..ef62ab84cf 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 @@ private: void create_color_button(Widget& container, unsigned rgb); Color m_color; + bool m_color_has_alpha_channel { true }; Vector<ColorButton*> m_color_widgets; RefPtr<CustomColorWidget> m_custom_color; |