diff options
author | Andrew Dykema <atdykema@gmail.com> | 2022-06-10 07:40:41 -0700 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2022-06-29 03:27:59 +0000 |
commit | 2a7b3ca4b8dfcc320aea4d51fe9980f4d69aaf35 (patch) | |
tree | 3aadd12018c0ecc67c7d7bef9177e7f109e8f61c /Userland/Applications/Calendar | |
parent | cc4bb59a7e551788a6af6ea89ddb9af8391b186e (diff) | |
download | serenity-2a7b3ca4b8dfcc320aea4d51fe9980f4d69aaf35.zip |
Calender: Add ability to set the time of day for an event
Diffstat (limited to 'Userland/Applications/Calendar')
-rw-r--r-- | Userland/Applications/Calendar/AddEventDialog.cpp | 56 | ||||
-rw-r--r-- | Userland/Applications/Calendar/AddEventDialog.h | 19 |
2 files changed, 74 insertions, 1 deletions
diff --git a/Userland/Applications/Calendar/AddEventDialog.cpp b/Userland/Applications/Calendar/AddEventDialog.cpp index 6c092cc3e0..73a567f8bc 100644 --- a/Userland/Applications/Calendar/AddEventDialog.cpp +++ b/Userland/Applications/Calendar/AddEventDialog.cpp @@ -23,7 +23,7 @@ AddEventDialog::AddEventDialog(Core::DateTime date_time, Window* parent_window) : Dialog(parent_window) , m_date_time(date_time) { - resize(158, 100); + resize(158, 130); set_title("Add Event"); set_resizable(false); set_icon(parent_window->icon()); @@ -50,6 +50,11 @@ AddEventDialog::AddEventDialog(Core::DateTime date_time, Window* parent_window) middle_container.set_fixed_height(25); middle_container.layout()->set_margins(4); + auto& time_container = widget.add<GUI::Widget>(); + time_container.set_layout<GUI::HorizontalBoxLayout>(); + time_container.set_fixed_height(25); + time_container.layout()->set_margins(4); + auto& starting_month_combo = middle_container.add<GUI::ComboBox>(); starting_month_combo.set_only_allow_values_from_model(true); starting_month_combo.set_fixed_size(50, 20); @@ -66,6 +71,22 @@ AddEventDialog::AddEventDialog(Core::DateTime date_time, Window* parent_window) starting_year_combo.set_range(0, 9999); starting_year_combo.set_value(m_date_time.year()); + auto& starting_hour_combo = time_container.add<GUI::SpinBox>(); + starting_hour_combo.set_fixed_size(50, 20); + starting_hour_combo.set_range(1, 12); + starting_hour_combo.set_value(12); + + auto& starting_minute_combo = time_container.add<GUI::SpinBox>(); + starting_minute_combo.set_fixed_size(40, 20); + starting_minute_combo.set_range(0, 59); + starting_minute_combo.set_value(0); + + auto& starting_meridiem_combo = time_container.add<GUI::ComboBox>(); + 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.layout()->add_spacer(); auto& button_container = widget.add<GUI::Widget>(); @@ -87,6 +108,11 @@ int AddEventDialog::MonthListModel::row_count(const GUI::ModelIndex&) const return 12; } +int AddEventDialog::MeridiemListModel::row_count(const GUI::ModelIndex&) const +{ + return 2; +} + String AddEventDialog::MonthListModel::column_name(int column) const { switch (column) { @@ -97,6 +123,16 @@ String AddEventDialog::MonthListModel::column_name(int column) const } } +String AddEventDialog::MeridiemListModel::column_name(int column) const +{ + switch (column) { + case Column::Meridiem: + return "Meridiem"; + default: + VERIFY_NOT_REACHED(); + } +} + GUI::Variant AddEventDialog::MonthListModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const { constexpr Array short_month_names = { @@ -115,3 +151,21 @@ GUI::Variant AddEventDialog::MonthListModel::data(const GUI::ModelIndex& index, } return {}; } + +GUI::Variant AddEventDialog::MeridiemListModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const +{ + constexpr Array meridiem_names = { + "AM", "PM" + }; + + auto& meridiem = meridiem_names[index.row()]; + if (role == GUI::ModelRole::Display) { + switch (index.column()) { + case Column::Meridiem: + return meridiem; + default: + VERIFY_NOT_REACHED(); + } + } + return {}; +} diff --git a/Userland/Applications/Calendar/AddEventDialog.h b/Userland/Applications/Calendar/AddEventDialog.h index 49e84dde67..4f0aa162e8 100644 --- a/Userland/Applications/Calendar/AddEventDialog.h +++ b/Userland/Applications/Calendar/AddEventDialog.h @@ -45,5 +45,24 @@ private: MonthListModel() = default; }; + class MeridiemListModel final : public GUI::Model { + public: + enum Column { + Meridiem, + __Count, + }; + + static NonnullRefPtr<MeridiemListModel> create() { return adopt_ref(*new MeridiemListModel); } + virtual ~MeridiemListModel() override = default; + + virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override; + virtual int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return Column::__Count; } + virtual String column_name(int) const override; + virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override; + + private: + MeridiemListModel() = default; + }; + Core::DateTime m_date_time; }; |