mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:28:11 +00:00
LibGUI: Exit ColorPicker (successfully) when double-clicking a color
It feels natural that if I double click a color button, the dialog closes successfully and "returns" that color.
This commit is contained in:
parent
57fe4d19ac
commit
6a01827046
1 changed files with 13 additions and 4 deletions
|
@ -50,11 +50,13 @@ public:
|
|||
|
||||
protected:
|
||||
virtual void click() override;
|
||||
virtual void doubleclick_event(GUI::MouseEvent&) override;
|
||||
virtual void paint_event(PaintEvent&) override;
|
||||
|
||||
private:
|
||||
explicit ColorButton(Color color = {});
|
||||
explicit ColorButton(ColorPicker& picker, Color color = {});
|
||||
|
||||
ColorPicker& m_picker;
|
||||
Color m_color;
|
||||
bool m_selected { false };
|
||||
};
|
||||
|
@ -310,7 +312,7 @@ void ColorPicker::create_color_button(Widget& container, unsigned rgb)
|
|||
{
|
||||
Color color = Color::from_rgb(rgb);
|
||||
|
||||
auto& widget = container.add<ColorButton>(color);
|
||||
auto& widget = container.add<ColorButton>(*this, color);
|
||||
widget.set_size_policy(SizePolicy::Fill, SizePolicy::Fill);
|
||||
widget.on_click = [this](Color color) {
|
||||
for (auto& value : m_color_widgets) {
|
||||
|
@ -328,10 +330,10 @@ void ColorPicker::create_color_button(Widget& container, unsigned rgb)
|
|||
m_color_widgets.append(&widget);
|
||||
}
|
||||
|
||||
ColorButton::ColorButton(Color color)
|
||||
ColorButton::ColorButton(ColorPicker& picker, Color color)
|
||||
: m_picker(picker)
|
||||
{
|
||||
m_color = color;
|
||||
m_selected = false;
|
||||
}
|
||||
|
||||
ColorButton::~ColorButton()
|
||||
|
@ -343,6 +345,13 @@ void ColorButton::set_selected(bool selected)
|
|||
m_selected = selected;
|
||||
}
|
||||
|
||||
void ColorButton::doubleclick_event(GUI::MouseEvent&)
|
||||
{
|
||||
click();
|
||||
m_selected = true;
|
||||
m_picker.done(Dialog::ExecOK);
|
||||
}
|
||||
|
||||
void ColorButton::paint_event(PaintEvent& event)
|
||||
{
|
||||
Painter painter(*this);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue