From 269886fc4e40a8da94c89bcf031f3bb0fd70d968 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 12 Apr 2019 02:51:16 +0200 Subject: [PATCH] GWidget: Add "enabled" state for widgets. There's nothing magical that happens for painting, each widget needs to handle it manually in their painting code. --- LibGUI/GWidget.cpp | 8 ++++++++ LibGUI/GWidget.h | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/LibGUI/GWidget.cpp b/LibGUI/GWidget.cpp index c1d2d272d4..7bb8bd08de 100644 --- a/LibGUI/GWidget.cpp +++ b/LibGUI/GWidget.cpp @@ -408,3 +408,11 @@ bool GWidget::spans_entire_window_horizontally() const auto wrr = window_relative_rect(); return wrr.left() == main_widget->rect().left() && wrr.right() == main_widget->rect().right(); } + +void GWidget::set_enabled(bool enabled) +{ + if (m_enabled == enabled) + return; + m_enabled = enabled; + update(); +} diff --git a/LibGUI/GWidget.h b/LibGUI/GWidget.h index 45e12535d2..a7edf79982 100644 --- a/LibGUI/GWidget.h +++ b/LibGUI/GWidget.h @@ -38,6 +38,9 @@ public: String tooltip() const { return m_tooltip; } void set_tooltip(const String& tooltip) { m_tooltip = tooltip; } + bool is_enabled() const { return m_enabled; } + void set_enabled(bool); + virtual void event(CEvent&) override; virtual void paint_event(GPaintEvent&); virtual void resize_event(GResizeEvent&); @@ -180,6 +183,7 @@ private: bool m_fill_with_background_color { false }; bool m_visible { true }; bool m_greedy_for_hits { false }; + bool m_enabled { true }; CElapsedTimer m_click_clock; };