1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:37:35 +00:00

LibGUI: Remove copy-pasted auto-repeat logic from ColorInput

This was copy-pasted from button classes and not useful here.
This commit is contained in:
Andreas Kling 2020-04-29 14:38:19 +02:00
parent 40fe076e10
commit 033a4aee50
2 changed files with 5 additions and 19 deletions

View file

@ -36,11 +36,6 @@ ColorInput::ColorInput()
: TextEditor(TextEditor::SingleLine) : TextEditor(TextEditor::SingleLine)
{ {
set_readonly(true); set_readonly(true);
m_auto_repeat_timer = add<Core::Timer>();
m_auto_repeat_timer->on_timeout = [this] {
click();
};
} }
ColorInput::~ColorInput() ColorInput::~ColorInput()
@ -64,11 +59,6 @@ void ColorInput::mousedown_event(MouseEvent& event)
if (is_enabled()) { if (is_enabled()) {
m_being_pressed = true; m_being_pressed = true;
update(); update();
if (m_auto_repeat_interval) {
click();
m_auto_repeat_timer->start(m_auto_repeat_interval);
}
} }
} }
@ -78,13 +68,11 @@ void ColorInput::mousedown_event(MouseEvent& event)
void ColorInput::mouseup_event(MouseEvent& event) void ColorInput::mouseup_event(MouseEvent& event)
{ {
if (event.button() == MouseButton::Left) { if (event.button() == MouseButton::Left) {
bool was_auto_repeating = m_auto_repeat_timer->is_active();
m_auto_repeat_timer->stop();
if (is_enabled()) { if (is_enabled()) {
bool was_being_pressed = m_being_pressed; bool was_being_pressed = m_being_pressed;
m_being_pressed = false; m_being_pressed = false;
update(); update();
if (was_being_pressed && !was_auto_repeating) if (was_being_pressed)
click(); click();
} }
} }

View file

@ -31,14 +31,14 @@
namespace GUI { namespace GUI {
class ColorInput : public TextEditor { class ColorInput final : public TextEditor {
C_OBJECT(ColorInput) C_OBJECT(ColorInput);
public: public:
ColorInput(); ColorInput();
virtual ~ColorInput() override; virtual ~ColorInput() override;
void set_color(Color color); void set_color(Color);
Color color() { return m_color; } Color color() { return m_color; }
void set_color_picker_title(String title) { m_color_picker_title = title; } void set_color_picker_title(String title) { m_color_picker_title = title; }
@ -53,14 +53,12 @@ protected:
virtual void paint_event(PaintEvent&) override; virtual void paint_event(PaintEvent&) override;
private: private:
virtual void click(); void click();
Color m_color; Color m_color;
String m_color_picker_title { "Select Color" }; String m_color_picker_title { "Select Color" };
int m_auto_repeat_interval { 0 };
bool m_being_pressed { false }; bool m_being_pressed { false };
RefPtr<Core::Timer> m_auto_repeat_timer;
}; };
} }