From 3792c91059f50e545ec35fa5c3c775fa097d7a10 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 18 Aug 2019 20:39:46 +0200 Subject: [PATCH] LibGUI: Implement save_to(JsonObject&) for GWindow and GWidget --- Libraries/LibGUI/GWidget.cpp | 16 ++++++++++++++++ Libraries/LibGUI/GWidget.h | 13 +++++++++++++ Libraries/LibGUI/GWindow.cpp | 14 ++++++++++++++ Libraries/LibGUI/GWindow.h | 2 ++ 4 files changed, 45 insertions(+) diff --git a/Libraries/LibGUI/GWidget.cpp b/Libraries/LibGUI/GWidget.cpp index 1a07c4865ba..7c2563d59eb 100644 --- a/Libraries/LibGUI/GWidget.cpp +++ b/Libraries/LibGUI/GWidget.cpp @@ -3,6 +3,7 @@ #include "GEventLoop.h" #include "GWindow.h" #include +#include #include #include #include @@ -585,3 +586,18 @@ void GWidget::set_forecolor(const StringView& color_string) return; set_foreground_color(color.value()); } + +void GWidget::save_to(AK::JsonObject& json) +{ + json.set("relative_rect", relative_rect().to_string()); + json.set("fill_with_background_color", fill_with_background_color()); + json.set("tooltip", tooltip()); + json.set("visible", is_visible()); + json.set("focused", is_focused()); + json.set("enabled", is_enabled()); + json.set("background_color", background_color().to_string()); + json.set("foreground_color", foreground_color().to_string()); + json.set("preferred_size", preferred_size().to_string()); + json.set("size_policy", String::format("[%s,%s]", to_string(horizontal_size_policy()), to_string(vertical_size_policy()))); + CObject::save_to(json); +} diff --git a/Libraries/LibGUI/GWidget.h b/Libraries/LibGUI/GWidget.h index 3c4af83d539..f600f86de81 100644 --- a/Libraries/LibGUI/GWidget.h +++ b/Libraries/LibGUI/GWidget.h @@ -22,6 +22,17 @@ enum class SizePolicy { Fixed, Fill }; +inline const char* to_string(SizePolicy policy) +{ + switch (policy) { + case SizePolicy::Fixed: + return "SizePolicy::Fixed"; + case SizePolicy::Fill: + return "SizePolicy::Fill"; + } + return "SizePolicy::(Invalid)"; +} + enum class HorizontalDirection { Left, Right @@ -206,6 +217,8 @@ public: virtual bool is_radio_button() const { return false; } virtual bool is_abstract_button() const { return false; } + virtual void save_to(AK::JsonObject&) override; + private: void handle_paint_event(GPaintEvent&); void handle_resize_event(GResizeEvent&); diff --git a/Libraries/LibGUI/GWindow.cpp b/Libraries/LibGUI/GWindow.cpp index b71b9d4dd47..3ab70d20c9a 100644 --- a/Libraries/LibGUI/GWindow.cpp +++ b/Libraries/LibGUI/GWindow.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -696,3 +697,16 @@ Vector GWindow::focusable_widgets() const collect_focusable_widgets(*m_main_widget); return collected_widgets; } + +void GWindow::save_to(AK::JsonObject& json) +{ + json.set("title", title()); + json.set("visible", is_visible()); + json.set("active", is_active()); + json.set("resizable", is_resizable()); + json.set("fullscreen", is_fullscreen()); + json.set("rect", rect().to_string()); + json.set("base_size", base_size().to_string()); + json.set("size_increment", size_increment().to_string()); + CObject::save_to(json); +} diff --git a/Libraries/LibGUI/GWindow.h b/Libraries/LibGUI/GWindow.h index b15e2449b53..5937a18f6fe 100644 --- a/Libraries/LibGUI/GWindow.h +++ b/Libraries/LibGUI/GWindow.h @@ -125,6 +125,8 @@ public: Vector focusable_widgets() const; + virtual void save_to(AK::JsonObject&) override; + protected: virtual void wm_event(GWMEvent&);