diff --git a/Userland/Applications/Calendar/AddEventDialog.cpp b/Userland/Applications/Calendar/AddEventDialog.cpp index ab688e9075..0609815cc8 100644 --- a/Userland/Applications/Calendar/AddEventDialog.cpp +++ b/Userland/Applications/Calendar/AddEventDialog.cpp @@ -60,6 +60,7 @@ AddEventDialog::AddEventDialog(Core::DateTime date_time, EventManager& event_man m_end_date_time.set_date(new_date.value()); update_end_date(); } + update_duration(); m_start_date_box->set_text(MUST(m_start_date_time.to_string(DATE_FORMAT))); } @@ -79,6 +80,7 @@ AddEventDialog::AddEventDialog(Core::DateTime date_time, EventManager& event_man m_start_date_time.set_date(new_date.value()); update_start_date(); } + update_duration(); m_end_date_box->set_text(MUST(m_end_date_time.to_string(DATE_FORMAT))); } @@ -87,6 +89,9 @@ AddEventDialog::AddEventDialog(Core::DateTime date_time, EventManager& event_man m_end_hour_box = *widget->find_descendant_of_type_named("end_hour"); m_end_minute_box = *widget->find_descendant_of_type_named("end_minute"); + m_duration_hour_box = *widget->find_descendant_of_type_named("duration_hour"); + m_duration_minute_box = *widget->find_descendant_of_type_named("duration_minute"); + auto& ok_button = *widget->find_descendant_of_type_named("ok_button"); ok_button.on_click = [&](auto) { auto successful = add_event_to_calendar().release_value_but_fixme_should_propagate_errors(); @@ -106,6 +111,7 @@ AddEventDialog::AddEventDialog(Core::DateTime date_time, EventManager& event_man m_end_date_time.set_time_only(hour, minute); update_end_date(); } + update_duration(); }; auto update_ending_input_values = [&, this]() { auto hour = m_end_hour_box->value(); @@ -115,15 +121,25 @@ AddEventDialog::AddEventDialog(Core::DateTime date_time, EventManager& event_man m_start_date_time.set_time_only(hour, minute); update_start_date(); } + update_duration(); + }; + auto update_duration_input_values = [&, this]() { + auto hour = m_duration_hour_box->value(); + auto minute = m_duration_minute_box->value(); + m_end_date_time = Core::DateTime::from_timestamp(m_start_date_time.timestamp() + (hour * 60 + minute) * 60); + update_end_date(); }; m_start_hour_box->on_change = [update_starting_input_values](auto) { update_starting_input_values(); }; m_start_minute_box->on_change = [update_starting_input_values](auto) { update_starting_input_values(); }; m_end_hour_box->on_change = [update_ending_input_values](auto) { update_ending_input_values(); }; m_end_minute_box->on_change = [update_ending_input_values](auto) { update_ending_input_values(); }; + m_duration_hour_box->on_change = [update_duration_input_values](auto) { update_duration_input_values(); }; + m_duration_minute_box->on_change = [update_duration_input_values](auto) { update_duration_input_values(); }; update_start_date(); update_end_date(); + update_duration(); } ErrorOr AddEventDialog::add_event_to_calendar() @@ -157,4 +173,14 @@ void AddEventDialog::update_end_date() m_end_minute_box->set_value(m_end_date_time.minute(), GUI::AllowCallback::No); } +void AddEventDialog::update_duration() +{ + auto difference_in_seconds = m_end_date_time.timestamp() - m_start_date_time.timestamp(); + auto hours = difference_in_seconds / (60 * 60); + auto minutes = (difference_in_seconds - hours * (60 * 60)) / 60; + + m_duration_hour_box->set_value(hours, GUI::AllowCallback::No); + m_duration_minute_box->set_value(minutes, GUI::AllowCallback::No); +} + } diff --git a/Userland/Applications/Calendar/AddEventDialog.gml b/Userland/Applications/Calendar/AddEventDialog.gml index 8a0c43e72c..13670d9cac 100644 --- a/Userland/Applications/Calendar/AddEventDialog.gml +++ b/Userland/Applications/Calendar/AddEventDialog.gml @@ -102,6 +102,35 @@ } } + @GUI::Widget { + fill_with_background_color: true + fixed_height: 25 + layout: @GUI::HorizontalBoxLayout { + spacing: 4 + } + + @GUI::Label { + text: "Duration:" + text_alignment: "CenterLeft" + fixed_height: 14 + font_weight: "Bold" + } + + @GUI::SpinBox { + name: "duration_hour" + fixed_size: [50, 20] + min: 0 + max: 999999 + } + + @GUI::SpinBox { + name: "duration_minute" + fixed_size: [40, 20] + min: 0 + max: 59 + } + } + @GUI::Layout::Spacer {} @GUI::Widget { diff --git a/Userland/Applications/Calendar/AddEventDialog.h b/Userland/Applications/Calendar/AddEventDialog.h index c42b28275b..2989471e1e 100644 --- a/Userland/Applications/Calendar/AddEventDialog.h +++ b/Userland/Applications/Calendar/AddEventDialog.h @@ -34,6 +34,7 @@ private: void update_start_date(); void update_end_date(); + void update_duration(); Core::DateTime m_start_date_time; Core::DateTime m_end_date_time; @@ -45,6 +46,8 @@ private: RefPtr m_start_minute_box; RefPtr m_end_hour_box; RefPtr m_end_minute_box; + RefPtr m_duration_hour_box; + RefPtr m_duration_minute_box; }; }