From 71a784741f1be8d7dd0e04534b0f2f8f0885b6c6 Mon Sep 17 00:00:00 2001 From: Domenico Iezzi Date: Tue, 13 Feb 2024 21:57:17 +0100 Subject: [PATCH] LibGUI: Add Calendar property for mode If a user selects Year as the default view mode for Calendar app, then all apps using Calendar widget will default to this view if not manually overridden with a Calendar::toggle_mode call. This commit introduces a "mode" property that allows the selection of the default mode for the calendar widget in GML files. In this way there is no need to manually call toggle_mode when constructing UIs with Calendar widget. --- Userland/Libraries/LibGUI/Calendar.cpp | 11 +++++++++++ Userland/Libraries/LibGUI/Calendar.h | 1 + Userland/Libraries/LibGUI/DatePickerDialog.gml | 1 + 3 files changed, 13 insertions(+) diff --git a/Userland/Libraries/LibGUI/Calendar.cpp b/Userland/Libraries/LibGUI/Calendar.cpp index 696aba447e..7c5a8d1fd9 100644 --- a/Userland/Libraries/LibGUI/Calendar.cpp +++ b/Userland/Libraries/LibGUI/Calendar.cpp @@ -64,6 +64,10 @@ Calendar::Calendar(Core::DateTime date_time, Mode mode) } update_tiles(m_selected_date.year(), m_selected_date.month()); + + REGISTER_ENUM_PROPERTY("mode", this->mode, this->set_mode, Calendar::Mode, + { Calendar::Mode::Month, "Month" }, + { Calendar::Mode::Year, "Year" }); } void Calendar::set_grid(bool show) @@ -85,6 +89,13 @@ void Calendar::toggle_mode() invalidate_layout(); } +void Calendar::set_mode(Mode mode) +{ + if (mode != m_mode) { + toggle_mode(); + } +} + void Calendar::show_previous_date() { unsigned view_month = m_view_month; diff --git a/Userland/Libraries/LibGUI/Calendar.h b/Userland/Libraries/LibGUI/Calendar.h index c98bae6985..17675abd14 100644 --- a/Userland/Libraries/LibGUI/Calendar.h +++ b/Userland/Libraries/LibGUI/Calendar.h @@ -66,6 +66,7 @@ public: ErrorOr formatted_date(Format format = LongMonthYear); Mode mode() const { return m_mode; } + void set_mode(Mode); void toggle_mode(); void update_tiles(unsigned year, unsigned month); diff --git a/Userland/Libraries/LibGUI/DatePickerDialog.gml b/Userland/Libraries/LibGUI/DatePickerDialog.gml index 100aad5ede..681266efb3 100644 --- a/Userland/Libraries/LibGUI/DatePickerDialog.gml +++ b/Userland/Libraries/LibGUI/DatePickerDialog.gml @@ -30,6 +30,7 @@ @GUI::Calendar { name: "calendar_view" + mode: "Month" } }