From cdbc252190a44a06c3914dc14d74afd0b52ea864 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 29 Apr 2020 19:02:00 +0200 Subject: [PATCH] LibGUI: Require a full click on ColorInput's color rect to open picker Let's not open the ColorPicker on mousedown, that was too jarring. --- Libraries/LibGUI/ColorInput.cpp | 18 ++++++++++++++---- Libraries/LibGUI/ColorInput.h | 2 ++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Libraries/LibGUI/ColorInput.cpp b/Libraries/LibGUI/ColorInput.cpp index 14c192e1cc..f4a289aedb 100644 --- a/Libraries/LibGUI/ColorInput.cpp +++ b/Libraries/LibGUI/ColorInput.cpp @@ -71,9 +71,21 @@ void ColorInput::set_color(Color color) }; void ColorInput::mousedown_event(MouseEvent& event) +{ + if (event.button() == MouseButton::Left && color_rect().contains(event.position())) { + m_may_be_color_rect_click = true; + return; + } + + TextEditor::mousedown_event(event); +} + +void ColorInput::mouseup_event(MouseEvent& event) { if (event.button() == MouseButton::Left) { - if (is_enabled() && color_rect().contains(event.position())) { + bool is_color_rect_click = m_may_be_color_rect_click && color_rect().contains(event.position()); + m_may_be_color_rect_click = false; + if (is_color_rect_click) { 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) @@ -82,8 +94,7 @@ void ColorInput::mousedown_event(MouseEvent& event) return; } } - - TextEditor::mousedown_event(event); + TextEditor::mouseup_event(event); } void ColorInput::mousemove_event(MouseEvent& event) @@ -109,5 +120,4 @@ void ColorInput::paint_event(PaintEvent& event) painter.fill_rect(color_rect(), m_color); painter.draw_rect(color_rect(), Color::Black); } - } diff --git a/Libraries/LibGUI/ColorInput.h b/Libraries/LibGUI/ColorInput.h index d223ce7ff4..cebefbe0dc 100644 --- a/Libraries/LibGUI/ColorInput.h +++ b/Libraries/LibGUI/ColorInput.h @@ -50,6 +50,7 @@ public: protected: virtual void mousedown_event(MouseEvent&) override; + virtual void mouseup_event(MouseEvent&) override; virtual void mousemove_event(MouseEvent&) override; virtual void paint_event(PaintEvent&) override; @@ -62,6 +63,7 @@ private: Color m_color; String m_color_picker_title { "Select color" }; bool m_color_has_alpha_channel { true }; + bool m_may_be_color_rect_click { false }; }; }