LibGUI: Extend mimic pressed across keyboard shortcuts for buttons

Primary motivation for this was to get a visual indication in the
browser for Ctrl-R refresh. This extends what ForLoveOfCats had done
for calculator button shortcuts across all buttons with shortcuts.

When an action is triggered without an activator each associated button
will be set as mimic pressed.
This commit is contained in:
Rob Ryan 2022-04-03 15:50:32 +10:00 committed by Andreas Kling
parent 7af87e8e6b
commit 554709fec6
Notes: sideshowbarker 2024-07-17 14:34:17 +09:00
3 changed files with 25 additions and 2 deletions

View file

@ -131,6 +131,12 @@ void Action::activate(Core::Object* activator)
}
}
if (activator == nullptr) {
for_each_toolbar_button([](auto& button) {
button.set_mimic_pressed(true);
});
}
on_activation(*this);
m_activator = nullptr;
}

View file

@ -224,8 +224,23 @@ void Button::set_default(bool default_button)
void Button::set_mimic_pressed(bool mimic_pressed)
{
m_mimic_pressed = mimic_pressed;
update();
if (!is_being_pressed()) {
m_mimic_pressed = mimic_pressed;
stop_timer();
start_timer(80, Core::TimerShouldFireWhenNotVisible::Yes);
update();
}
}
void Button::timer_event(Core::TimerEvent&)
{
if (is_mimic_pressed()) {
m_mimic_pressed = false;
update();
}
}
}

View file

@ -64,6 +64,8 @@ protected:
virtual void paint_event(PaintEvent&) override;
private:
virtual void timer_event(Core::TimerEvent&) override;
RefPtr<Gfx::Bitmap> m_icon;
RefPtr<GUI::Menu> m_menu;
Gfx::ButtonStyle m_button_style { Gfx::ButtonStyle::Normal };