From 347e5aa7b588f3f2f21f11cd5f2b07f80a7819a1 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 3 Jan 2021 17:21:12 +0100 Subject: [PATCH] LibGUI: Hide the tooltip if widget with open tooltip unsets it If you call set_tooltip({}) on a widget currently showing a tooltip, we will now remove the tooltip window from screen. --- Libraries/LibGUI/Widget.cpp | 10 ++++++---- Libraries/LibGUI/Widget.h | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Libraries/LibGUI/Widget.cpp b/Libraries/LibGUI/Widget.cpp index 4b95039d1f..83458fb7c2 100644 --- a/Libraries/LibGUI/Widget.cpp +++ b/Libraries/LibGUI/Widget.cpp @@ -387,7 +387,7 @@ void Widget::handle_enter_event(Core::Event& event) { if (auto* window = this->window()) window->update_cursor({}); - show_tooltip(); + show_or_hide_tooltip(); enter_event(event); } @@ -905,14 +905,16 @@ Gfx::IntRect Widget::content_rect() const void Widget::set_tooltip(const StringView& tooltip) { m_tooltip = tooltip; - if (GUI::Application::the()->tooltip_source_widget() == this) - show_tooltip(); + if (Application::the()->tooltip_source_widget() == this) + show_or_hide_tooltip(); } -void Widget::show_tooltip() +void Widget::show_or_hide_tooltip() { if (has_tooltip()) Application::the()->show_tooltip(m_tooltip, this); + else + Application::the()->hide_tooltip(); } Gfx::IntRect Widget::children_clip_rect() const diff --git a/Libraries/LibGUI/Widget.h b/Libraries/LibGUI/Widget.h index 786eb8c371..fa6ec121f5 100644 --- a/Libraries/LibGUI/Widget.h +++ b/Libraries/LibGUI/Widget.h @@ -328,6 +328,8 @@ protected: virtual void did_begin_inspection() override; virtual void did_end_inspection() override; + void show_or_hide_tooltip(); + private: void handle_paint_event(PaintEvent&); void handle_resize_event(ResizeEvent&); @@ -339,8 +341,6 @@ private: void focus_previous_widget(FocusSource, bool siblings_only); void focus_next_widget(FocusSource, bool siblings_only); - void show_tooltip(); - bool load_from_json(const JsonObject&); // HACK: These are used as property getters for the fixed_* size property aliases.