mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 04:08:11 +00:00
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.
This commit is contained in:
parent
8159f45f6e
commit
cdbc252190
2 changed files with 16 additions and 4 deletions
|
@ -71,9 +71,21 @@ void ColorInput::set_color(Color color)
|
||||||
};
|
};
|
||||||
|
|
||||||
void ColorInput::mousedown_event(MouseEvent& event)
|
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 (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);
|
auto dialog = GUI::ColorPicker::construct(m_color, window(), m_color_picker_title);
|
||||||
dialog->set_color_has_alpha_channel(m_color_has_alpha_channel);
|
dialog->set_color_has_alpha_channel(m_color_has_alpha_channel);
|
||||||
if (dialog->exec() == GUI::Dialog::ExecOK)
|
if (dialog->exec() == GUI::Dialog::ExecOK)
|
||||||
|
@ -82,8 +94,7 @@ void ColorInput::mousedown_event(MouseEvent& event)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
TextEditor::mouseup_event(event);
|
||||||
TextEditor::mousedown_event(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorInput::mousemove_event(MouseEvent& 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.fill_rect(color_rect(), m_color);
|
||||||
painter.draw_rect(color_rect(), Color::Black);
|
painter.draw_rect(color_rect(), Color::Black);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void mousedown_event(MouseEvent&) override;
|
virtual void mousedown_event(MouseEvent&) override;
|
||||||
|
virtual void mouseup_event(MouseEvent&) override;
|
||||||
virtual void mousemove_event(MouseEvent&) override;
|
virtual void mousemove_event(MouseEvent&) override;
|
||||||
virtual void paint_event(PaintEvent&) override;
|
virtual void paint_event(PaintEvent&) override;
|
||||||
|
|
||||||
|
@ -62,6 +63,7 @@ private:
|
||||||
Color m_color;
|
Color m_color;
|
||||||
String m_color_picker_title { "Select color" };
|
String m_color_picker_title { "Select color" };
|
||||||
bool m_color_has_alpha_channel { true };
|
bool m_color_has_alpha_channel { true };
|
||||||
|
bool m_may_be_color_rect_click { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue