mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:17:34 +00:00
Calendar/AddEventDialog: Use the DatePicker to pick dates
This commit is contained in:
parent
985db495be
commit
2c68554629
2 changed files with 39 additions and 83 deletions
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2019-2020, Ryan Grieb <ryan.m.grieb@gmail.com>
|
* Copyright (c) 2019-2020, Ryan Grieb <ryan.m.grieb@gmail.com>
|
||||||
* Copyright (c) 2022-2023, the SerenityOS developers.
|
* Copyright (c) 2022-2023, the SerenityOS developers.
|
||||||
|
* Copyright (c) 2023, David Ganz <david.g.ganz@gmail.com>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -11,6 +12,7 @@
|
||||||
#include <LibGUI/BoxLayout.h>
|
#include <LibGUI/BoxLayout.h>
|
||||||
#include <LibGUI/Button.h>
|
#include <LibGUI/Button.h>
|
||||||
#include <LibGUI/ComboBox.h>
|
#include <LibGUI/ComboBox.h>
|
||||||
|
#include <LibGUI/DatePicker.h>
|
||||||
#include <LibGUI/Label.h>
|
#include <LibGUI/Label.h>
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
#include <LibGUI/SpinBox.h>
|
#include <LibGUI/SpinBox.h>
|
||||||
|
@ -44,15 +46,19 @@ AddEventDialog::AddEventDialog(Core::DateTime date_time, EventManager& event_man
|
||||||
auto event_title_textbox = widget->find_descendant_of_type_named<GUI::TextBox>("event_title_textbox");
|
auto event_title_textbox = widget->find_descendant_of_type_named<GUI::TextBox>("event_title_textbox");
|
||||||
event_title_textbox->set_focus(true);
|
event_title_textbox->set_focus(true);
|
||||||
|
|
||||||
auto starting_month_input = widget->find_descendant_of_type_named<GUI::ComboBox>("start_month");
|
auto start_date_box = widget->find_descendant_of_type_named<GUI::TextBox>("start_date");
|
||||||
starting_month_input->set_model(GUI::MonthListModel::create());
|
start_date_box->set_text(MUST(m_start_date_time.to_string("%Y-%m-%d"sv)));
|
||||||
starting_month_input->set_selected_index(m_start_date_time.month() - 1);
|
|
||||||
|
|
||||||
auto starting_day_input = widget->find_descendant_of_type_named<GUI::SpinBox>("start_day");
|
auto calendar_date_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/calendar-date.png"sv).release_value_but_fixme_should_propagate_errors();
|
||||||
starting_day_input->set_value(m_start_date_time.day());
|
|
||||||
|
|
||||||
auto starting_year_input = widget->find_descendant_of_type_named<GUI::SpinBox>("start_year");
|
auto& pick_start_date_button = *widget->find_descendant_of_type_named<GUI::Button>("pick_start_date");
|
||||||
starting_year_input->set_value(m_start_date_time.year());
|
pick_start_date_button.set_icon(calendar_date_icon);
|
||||||
|
pick_start_date_button.on_click = [&](auto) {
|
||||||
|
if (auto new_date = GUI::DatePicker::show(this, "Pick Start Date"_string, m_start_date_time); new_date.has_value()) {
|
||||||
|
m_start_date_time.set_date(new_date.release_value());
|
||||||
|
start_date_box->set_text(MUST(m_start_date_time.to_string("%Y-%m-%d"sv)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
auto starting_hour_input = widget->find_descendant_of_type_named<GUI::SpinBox>("start_hour");
|
auto starting_hour_input = widget->find_descendant_of_type_named<GUI::SpinBox>("start_hour");
|
||||||
starting_hour_input->set_value(m_start_date_time.hour());
|
starting_hour_input->set_value(m_start_date_time.hour());
|
||||||
|
@ -64,15 +70,17 @@ AddEventDialog::AddEventDialog(Core::DateTime date_time, EventManager& event_man
|
||||||
starting_meridiem_input->set_model(MeridiemListModel::create());
|
starting_meridiem_input->set_model(MeridiemListModel::create());
|
||||||
starting_meridiem_input->set_selected_index(0);
|
starting_meridiem_input->set_selected_index(0);
|
||||||
|
|
||||||
auto ending_month_input = widget->find_descendant_of_type_named<GUI::ComboBox>("end_month");
|
auto end_date_box = widget->find_descendant_of_type_named<GUI::TextBox>("end_date");
|
||||||
ending_month_input->set_model(GUI::MonthListModel::create());
|
end_date_box->set_text(MUST(m_start_date_time.to_string("%Y-%m-%d"sv)));
|
||||||
ending_month_input->set_selected_index(m_end_date_time.month() - 1);
|
|
||||||
|
|
||||||
auto ending_day_input = widget->find_descendant_of_type_named<GUI::SpinBox>("end_day");
|
auto& pick_end_date_button = *widget->find_descendant_of_type_named<GUI::Button>("pick_end_date");
|
||||||
ending_day_input->set_value(m_end_date_time.day());
|
pick_end_date_button.set_icon(calendar_date_icon);
|
||||||
|
pick_end_date_button.on_click = [&](auto) {
|
||||||
auto ending_year_input = widget->find_descendant_of_type_named<GUI::SpinBox>("end_year");
|
if (auto new_date = GUI::DatePicker::show(this, "Pick End Date"_string, m_end_date_time); new_date.has_value()) {
|
||||||
ending_year_input->set_value(m_end_date_time.year());
|
m_end_date_time.set_date(new_date.release_value());
|
||||||
|
end_date_box->set_text(MUST(m_end_date_time.to_string("%Y-%m-%d"sv)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
auto ending_hour_input = widget->find_descendant_of_type_named<GUI::SpinBox>("end_hour");
|
auto ending_hour_input = widget->find_descendant_of_type_named<GUI::SpinBox>("end_hour");
|
||||||
ending_hour_input->set_value(m_end_date_time.hour());
|
ending_hour_input->set_value(m_end_date_time.hour());
|
||||||
|
@ -91,57 +99,21 @@ AddEventDialog::AddEventDialog(Core::DateTime date_time, EventManager& event_man
|
||||||
done(ExecResult::OK);
|
done(ExecResult::OK);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto update_starting_day_range = [=]() {
|
|
||||||
auto year = starting_year_input->value();
|
|
||||||
auto month = starting_month_input->selected_index();
|
|
||||||
|
|
||||||
starting_day_input->set_range(1, days_in_month(year, month + 1));
|
|
||||||
};
|
|
||||||
auto update_ending_day_range = [=]() {
|
|
||||||
auto year = ending_year_input->value();
|
|
||||||
auto month = ending_month_input->selected_index();
|
|
||||||
|
|
||||||
ending_day_input->set_range(1, days_in_month(year, month + 1));
|
|
||||||
};
|
|
||||||
auto update_starting_input_values = [=, this]() {
|
auto update_starting_input_values = [=, this]() {
|
||||||
auto year = starting_year_input->value();
|
|
||||||
auto month = starting_month_input->selected_index() + 1;
|
|
||||||
auto day = starting_day_input->value();
|
|
||||||
auto hour = starting_hour_input->value();
|
auto hour = starting_hour_input->value();
|
||||||
auto minute = starting_minute_input->value();
|
auto minute = starting_minute_input->value();
|
||||||
|
|
||||||
m_start_date_time = Core::DateTime::create(year, month, day, hour, minute);
|
m_start_date_time.set_time_only(hour, minute);
|
||||||
};
|
};
|
||||||
auto update_ending_input_values = [=, this]() {
|
auto update_ending_input_values = [=, this]() {
|
||||||
auto year = ending_year_input->value();
|
|
||||||
auto month = ending_month_input->selected_index() + 1;
|
|
||||||
auto day = ending_day_input->value();
|
|
||||||
auto hour = ending_hour_input->value();
|
auto hour = ending_hour_input->value();
|
||||||
auto minute = ending_minute_input->value();
|
auto minute = ending_minute_input->value();
|
||||||
|
|
||||||
m_end_date_time = Core::DateTime::create(year, month, day, hour, minute);
|
m_end_date_time.set_time_only(hour, minute);
|
||||||
};
|
};
|
||||||
starting_year_input->on_change = [update_starting_input_values, update_starting_day_range](auto) {
|
|
||||||
update_starting_input_values();
|
|
||||||
update_starting_day_range();
|
|
||||||
};
|
|
||||||
starting_month_input->on_change = [update_starting_input_values, update_starting_day_range](auto, auto) {
|
|
||||||
update_starting_input_values();
|
|
||||||
update_starting_day_range();
|
|
||||||
};
|
|
||||||
starting_day_input->on_change = [update_starting_input_values](auto) { update_starting_input_values(); };
|
|
||||||
starting_hour_input->on_change = [update_starting_input_values](auto) { update_starting_input_values(); };
|
starting_hour_input->on_change = [update_starting_input_values](auto) { update_starting_input_values(); };
|
||||||
starting_minute_input->on_change = [update_starting_input_values](auto) { update_starting_input_values(); };
|
starting_minute_input->on_change = [update_starting_input_values](auto) { update_starting_input_values(); };
|
||||||
|
|
||||||
ending_year_input->on_change = [update_ending_input_values, update_ending_day_range](auto) {
|
|
||||||
update_ending_input_values();
|
|
||||||
update_ending_day_range();
|
|
||||||
};
|
|
||||||
ending_month_input->on_change = [update_ending_input_values, update_ending_day_range](auto, auto) {
|
|
||||||
update_ending_input_values();
|
|
||||||
update_ending_day_range();
|
|
||||||
};
|
|
||||||
ending_day_input->on_change = [update_ending_input_values](auto) { update_ending_input_values(); };
|
|
||||||
ending_hour_input->on_change = [update_ending_input_values](auto) { update_ending_input_values(); };
|
ending_hour_input->on_change = [update_ending_input_values](auto) { update_ending_input_values(); };
|
||||||
ending_minute_input->on_change = [update_ending_input_values](auto) { update_ending_input_values(); };
|
ending_minute_input->on_change = [update_ending_input_values](auto) { update_ending_input_values(); };
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,23 +36,15 @@
|
||||||
font_weight: "Bold"
|
font_weight: "Bold"
|
||||||
}
|
}
|
||||||
|
|
||||||
@GUI::ComboBox {
|
@GUI::TextBox {
|
||||||
name: "start_month"
|
name: "start_date"
|
||||||
model_only: true
|
mode: "ReadOnly"
|
||||||
fixed_size: [50, 20]
|
fixed_width: 80
|
||||||
}
|
}
|
||||||
|
|
||||||
@GUI::SpinBox {
|
@GUI::Button {
|
||||||
name: "start_day"
|
name: "pick_start_date"
|
||||||
fixed_size: [40, 20]
|
fixed_width: 20
|
||||||
min: 1
|
|
||||||
}
|
|
||||||
|
|
||||||
@GUI::SpinBox {
|
|
||||||
name: "start_year"
|
|
||||||
fixed_size: [55, 20]
|
|
||||||
min: 0
|
|
||||||
max: 9999
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GUI::SpinBox {
|
@GUI::SpinBox {
|
||||||
|
@ -90,23 +82,15 @@
|
||||||
font_weight: "Bold"
|
font_weight: "Bold"
|
||||||
}
|
}
|
||||||
|
|
||||||
@GUI::ComboBox {
|
@GUI::TextBox {
|
||||||
name: "end_month"
|
name: "end_date"
|
||||||
model_only: true
|
mode: "ReadOnly"
|
||||||
fixed_size: [50, 20]
|
fixed_width: 80
|
||||||
}
|
}
|
||||||
|
|
||||||
@GUI::SpinBox {
|
@GUI::Button {
|
||||||
name: "end_day"
|
name: "pick_end_date"
|
||||||
fixed_size: [40, 20]
|
fixed_width: 20
|
||||||
min: 1
|
|
||||||
}
|
|
||||||
|
|
||||||
@GUI::SpinBox {
|
|
||||||
name: "end_year"
|
|
||||||
fixed_size: [55, 20]
|
|
||||||
min: 0
|
|
||||||
max: 9999
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GUI::SpinBox {
|
@GUI::SpinBox {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue