diff --git a/Userland/Applications/Calendar/AddEventDialog.cpp b/Userland/Applications/Calendar/AddEventDialog.cpp index aa8d8bdfac..d97f5d1d6c 100644 --- a/Userland/Applications/Calendar/AddEventDialog.cpp +++ b/Userland/Applications/Calendar/AddEventDialog.cpp @@ -6,6 +6,7 @@ */ #include "AddEventDialog.h" +#include #include #include #include @@ -34,103 +35,61 @@ AddEventDialog::AddEventDialog(Core::DateTime date_time, EventManager& event_man m_date_time = Core::DateTime::create(m_date_time.year(), m_date_time.month(), m_date_time.day(), 12, 0); auto widget = set_main_widget(); - widget->set_fill_with_background_color(true); - widget->set_layout(); + widget->load_from_gml(add_event_dialog_gml).release_value_but_fixme_should_propagate_errors(); - auto& top_container = widget->add(); - top_container.set_layout(4); - top_container.set_fixed_height(45); + auto event_title_textbox = widget->find_descendant_of_type_named("event_title_textbox"); + event_title_textbox->set_focus(true); - auto& add_label = top_container.add("Add title & date:"_string); - add_label.set_text_alignment(Gfx::TextAlignment::CenterLeft); - add_label.set_fixed_height(14); - add_label.set_font(Gfx::FontDatabase::default_font().bold_variant()); + auto starting_month_combo = widget->find_descendant_of_type_named("start_month"); + starting_month_combo->set_model(MonthListModel::create()); + starting_month_combo->set_selected_index(m_date_time.month() - 1); - auto& event_title_textbox = top_container.add(); - event_title_textbox.set_name("event_title_textbox"); - event_title_textbox.set_fixed_height(20); + auto starting_day_combo = widget->find_descendant_of_type_named("start_day"); + starting_day_combo->set_value(m_date_time.day()); - auto& middle_container = widget->add(); - middle_container.set_layout(4); - middle_container.set_fixed_height(25); + auto starting_year_combo = widget->find_descendant_of_type_named("start_year"); + starting_year_combo->set_value(m_date_time.year()); - auto& time_container = widget->add(); - time_container.set_layout(4); - time_container.set_fixed_height(25); + auto starting_hour_combo = widget->find_descendant_of_type_named("start_hour"); + starting_hour_combo->set_value(m_date_time.hour()); - auto& starting_month_combo = middle_container.add(); - starting_month_combo.set_only_allow_values_from_model(true); - starting_month_combo.set_fixed_size(50, 20); - starting_month_combo.set_model(MonthListModel::create()); - starting_month_combo.set_selected_index(m_date_time.month() - 1); + auto starting_minute_combo = widget->find_descendant_of_type_named("start_minute"); + starting_minute_combo->set_value(m_date_time.minute()); - auto& starting_day_combo = middle_container.add(); - starting_day_combo.set_fixed_size(40, 20); - starting_day_combo.set_range(1, m_date_time.days_in_month()); - starting_day_combo.set_value(m_date_time.day()); + auto starting_meridiem_combo = widget->find_descendant_of_type_named("start_meridiem"); + starting_meridiem_combo->set_model(MeridiemListModel::create()); + starting_meridiem_combo->set_selected_index(0); - auto& starting_year_combo = middle_container.add(); - starting_year_combo.set_fixed_size(55, 20); - starting_year_combo.set_range(0, 9999); - starting_year_combo.set_value(m_date_time.year()); - - auto& starting_hour_combo = time_container.add(); - starting_hour_combo.set_fixed_size(50, 20); - starting_hour_combo.set_range(1, 12); - starting_hour_combo.set_value(m_date_time.hour()); - - auto& starting_minute_combo = time_container.add(); - starting_minute_combo.set_fixed_size(40, 20); - starting_minute_combo.set_range(0, 59); - starting_minute_combo.set_value(m_date_time.minute()); - - auto& starting_meridiem_combo = time_container.add(); - starting_meridiem_combo.set_only_allow_values_from_model(true); - starting_meridiem_combo.set_fixed_size(55, 20); - starting_meridiem_combo.set_model(MeridiemListModel::create()); - starting_meridiem_combo.set_selected_index(0); - - widget->add_spacer(); - - auto& button_container = widget->add(); - button_container.set_fixed_height(20); - button_container.set_layout(); - button_container.add_spacer(); - auto& ok_button = button_container.add("OK"_string); - ok_button.set_fixed_size(80, 20); - ok_button.on_click = [&](auto) { + auto ok_button = widget->find_descendant_of_type_named("ok_button"); + ok_button->on_click = [&](auto) { add_event_to_calendar().release_value_but_fixme_should_propagate_errors(); done(ExecResult::OK); }; auto update_starting_day_range = [&starting_day_combo, &starting_year_combo, &starting_month_combo]() { - auto year = starting_year_combo.value(); - auto month = starting_month_combo.selected_index(); + auto year = starting_year_combo->value(); + auto month = starting_month_combo->selected_index(); - starting_day_combo.set_range(1, days_in_month(year, month + 1)); + starting_day_combo->set_range(1, days_in_month(year, month + 1)); }; - - starting_year_combo.on_change = [update_starting_day_range](auto) { update_starting_day_range(); }; - starting_month_combo.on_change = [update_starting_day_range](auto, auto) { update_starting_day_range(); }; + starting_year_combo->on_change = [update_starting_day_range](auto) { update_starting_day_range(); }; + starting_month_combo->on_change = [update_starting_day_range](auto, auto) { update_starting_day_range(); }; auto update_combo_values = [&]() { - auto year = starting_year_combo.value(); - auto month = starting_month_combo.selected_index() + 1; - auto day = starting_day_combo.value(); - auto hour = starting_hour_combo.value(); - auto minute = starting_minute_combo.value(); + auto year = starting_year_combo->value(); + auto month = starting_month_combo->selected_index() + 1; + auto day = starting_day_combo->value(); + auto hour = starting_hour_combo->value(); + auto minute = starting_minute_combo->value(); m_date_time = Core::DateTime::create(year, month, day, hour, minute); }; - - starting_year_combo.on_change = [update_combo_values](auto) { update_combo_values(); }; - starting_month_combo.on_change = [update_combo_values](auto, auto) { update_combo_values(); }; - starting_day_combo.on_change = [update_combo_values](auto) { update_combo_values(); }; - starting_hour_combo.on_change = [update_combo_values](auto) { update_combo_values(); }; - starting_minute_combo.on_change = [update_combo_values](auto) { update_combo_values(); }; - - event_title_textbox.set_focus(true); + starting_year_combo->on_change = [update_combo_values](auto) { update_combo_values(); }; + starting_month_combo->on_change = [update_combo_values](auto, auto) { update_combo_values(); }; + starting_day_combo->on_change = [update_combo_values](auto) { update_combo_values(); }; + starting_hour_combo->on_change = [update_combo_values](auto) { update_combo_values(); }; + starting_minute_combo->on_change = [update_combo_values](auto) { update_combo_values(); }; } ErrorOr AddEventDialog::add_event_to_calendar() diff --git a/Userland/Applications/Calendar/AddEventDialog.gml b/Userland/Applications/Calendar/AddEventDialog.gml new file mode 100644 index 0000000000..49a6195e05 --- /dev/null +++ b/Userland/Applications/Calendar/AddEventDialog.gml @@ -0,0 +1,97 @@ +@GUI::Widget { + fill_with_background_color: true + layout: @GUI::VerticalBoxLayout { + margins: [4] + } + + @GUI::Widget { + fill_with_background_color: true + fixed_height: 45 + layout: @GUI::VerticalBoxLayout { + spacing: 4 + } + + @GUI::Label { + text: "Add title & date:" + text_alignment: "CenterLeft" + fixed_height: 14 + font_weight: "Bold" + } + + @GUI::TextBox { + name: "event_title_textbox" + fixed_height: 20 + } + } + + @GUI::Widget { + fill_with_background_color: true + fixed_height: 25 + layout: @GUI::HorizontalBoxLayout { + spacing: 4 + } + + @GUI::ComboBox { + name: "start_month" + model_only: true + fixed_size: [50, 20] + } + + @GUI::SpinBox { + name: "start_day" + fixed_size: [40, 20] + min: 1 + } + + @GUI::SpinBox { + name: "start_year" + fixed_size: [55, 20] + min: 0 + max: 9999 + } + } + + @GUI::Widget { + fill_with_background_color: true + fixed_height: 25 + layout: @GUI::HorizontalBoxLayout { + spacing: 4 + } + + @GUI::SpinBox { + name: "start_hour" + fixed_size: [50, 20] + min: 1 + max: 12 + } + + @GUI::SpinBox { + name: "start_minute" + fixed_size: [40, 20] + min: 1 + max: 59 + } + + @GUI::ComboBox { + name: "start_meridiem" + model_only: true + fixed_size: [55, 20] + } + } + + @GUI::Layout::Spacer {} + + @GUI::Widget { + fill_with_background_color: true + fixed_height: 20 + layout: @GUI::HorizontalBoxLayout {} + + @GUI::Layout::Spacer {} + + @GUI::Button { + name: "ok_button" + text: "OK" + fixed_size: [80, 20] + } + } +} diff --git a/Userland/Applications/Calendar/CMakeLists.txt b/Userland/Applications/Calendar/CMakeLists.txt index 618901fb21..0d43f6f19f 100644 --- a/Userland/Applications/Calendar/CMakeLists.txt +++ b/Userland/Applications/Calendar/CMakeLists.txt @@ -4,6 +4,7 @@ serenity_component( ) stringify_gml(CalendarWindow.gml CalendarWindowGML.h calendar_window_gml) +stringify_gml(AddEventDialog.gml AddEventDialogGML.h add_event_dialog_gml) set(SOURCES AddEventDialog.cpp @@ -14,7 +15,7 @@ set(SOURCES ) set(GENERATED_SOURCES - CalendarWindowGML.h + CalendarWindowGML.h AddEventDialogGML.h ) serenity_app(Calendar ICON app-calendar)