mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibGUI+Calendar: Move date control logic to the calendar widget
This commit is contained in:
parent
c625ba34fe
commit
9a1018389c
Notes:
sideshowbarker
2024-07-17 12:02:22 +09:00
Author: https://github.com/implicitfield Commit: https://github.com/SerenityOS/serenity/commit/9a1018389c Pull-request: https://github.com/SerenityOS/serenity/pull/19513 Reviewed-by: https://github.com/alimpfard
4 changed files with 39 additions and 48 deletions
|
@ -49,33 +49,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto calendar = main_widget->find_descendant_of_type_named<GUI::Calendar>("calendar");
|
||||
|
||||
auto prev_date_action = GUI::Action::create({}, TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/go-back.png"sv)), [&](const GUI::Action&) {
|
||||
unsigned view_month = calendar->view_month();
|
||||
unsigned view_year = calendar->view_year();
|
||||
if (calendar->mode() == GUI::Calendar::Month) {
|
||||
view_month--;
|
||||
if (calendar->view_month() == 1) {
|
||||
view_month = 12;
|
||||
view_year--;
|
||||
}
|
||||
} else {
|
||||
view_year--;
|
||||
}
|
||||
calendar->update_tiles(view_year, view_month);
|
||||
calendar->show_previous_date();
|
||||
});
|
||||
|
||||
auto next_date_action = GUI::Action::create({}, TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/go-forward.png"sv)), [&](const GUI::Action&) {
|
||||
unsigned view_month = calendar->view_month();
|
||||
unsigned view_year = calendar->view_year();
|
||||
if (calendar->mode() == GUI::Calendar::Month) {
|
||||
view_month++;
|
||||
if (calendar->view_month() == 12) {
|
||||
view_month = 1;
|
||||
view_year++;
|
||||
}
|
||||
} else {
|
||||
view_year++;
|
||||
}
|
||||
calendar->update_tiles(view_year, view_month);
|
||||
calendar->show_next_date();
|
||||
});
|
||||
|
||||
auto add_event_action = GUI::Action::create("&Add Event", {}, TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/add-event.png"sv)), [&](const GUI::Action&) {
|
||||
|
|
|
@ -82,6 +82,38 @@ void Calendar::toggle_mode()
|
|||
invalidate_layout();
|
||||
}
|
||||
|
||||
void Calendar::show_previous_date()
|
||||
{
|
||||
unsigned view_month = m_view_month;
|
||||
unsigned view_year = m_view_year;
|
||||
if (m_mode == GUI::Calendar::Month) {
|
||||
--view_month;
|
||||
if (view_month == 0) {
|
||||
view_month = 12;
|
||||
--view_year;
|
||||
}
|
||||
} else {
|
||||
--view_year;
|
||||
}
|
||||
update_tiles(view_year, view_month);
|
||||
}
|
||||
|
||||
void Calendar::show_next_date()
|
||||
{
|
||||
unsigned view_month = m_view_month;
|
||||
unsigned view_year = m_view_year;
|
||||
if (m_mode == GUI::Calendar::Month) {
|
||||
++view_month;
|
||||
if (view_month == 13) {
|
||||
view_month = 1;
|
||||
++view_year;
|
||||
}
|
||||
} else {
|
||||
++view_year;
|
||||
}
|
||||
update_tiles(view_year, view_month);
|
||||
}
|
||||
|
||||
void Calendar::resize_event(GUI::ResizeEvent& event)
|
||||
{
|
||||
m_event_size.set_width(event.size().width() - (frame_thickness() * 2));
|
||||
|
|
|
@ -64,6 +64,9 @@ public:
|
|||
void set_show_days_of_the_week(bool b) { m_show_days = b; }
|
||||
bool is_showing_days_of_the_week() const { return m_show_days; }
|
||||
|
||||
void show_previous_date();
|
||||
void show_next_date();
|
||||
|
||||
Gfx::IntSize unadjusted_tile_size() const { return m_unadjusted_tile_size; }
|
||||
void set_unadjusted_tile_size(int width, int height)
|
||||
{
|
||||
|
|
|
@ -53,18 +53,7 @@ ClockWidget::ClockWidget()
|
|||
m_prev_date->set_fixed_size(24, 24);
|
||||
m_prev_date->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/go-back.png"sv).release_value_but_fixme_should_propagate_errors());
|
||||
m_prev_date->on_click = [&](auto) {
|
||||
unsigned view_month = m_calendar->view_month();
|
||||
unsigned view_year = m_calendar->view_year();
|
||||
if (m_calendar->mode() == GUI::Calendar::Month) {
|
||||
view_month--;
|
||||
if (m_calendar->view_month() == 1) {
|
||||
view_month = 12;
|
||||
view_year--;
|
||||
}
|
||||
} else {
|
||||
view_year--;
|
||||
}
|
||||
m_calendar->update_tiles(view_year, view_month);
|
||||
m_calendar->show_previous_date();
|
||||
if (m_calendar->mode() == GUI::Calendar::Year)
|
||||
m_selected_calendar_button->set_text(m_calendar->formatted_date(GUI::Calendar::YearOnly).release_value_but_fixme_should_propagate_errors());
|
||||
else
|
||||
|
@ -87,18 +76,7 @@ ClockWidget::ClockWidget()
|
|||
m_next_date->set_fixed_size(24, 24);
|
||||
m_next_date->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/go-forward.png"sv).release_value_but_fixme_should_propagate_errors());
|
||||
m_next_date->on_click = [&](auto) {
|
||||
unsigned view_month = m_calendar->view_month();
|
||||
unsigned view_year = m_calendar->view_year();
|
||||
if (m_calendar->mode() == GUI::Calendar::Month) {
|
||||
view_month++;
|
||||
if (m_calendar->view_month() == 12) {
|
||||
view_month = 1;
|
||||
view_year++;
|
||||
}
|
||||
} else {
|
||||
view_year++;
|
||||
}
|
||||
m_calendar->update_tiles(view_year, view_month);
|
||||
m_calendar->show_next_date();
|
||||
if (m_calendar->mode() == GUI::Calendar::Year)
|
||||
m_selected_calendar_button->set_text(m_calendar->formatted_date(GUI::Calendar::YearOnly).release_value_but_fixme_should_propagate_errors());
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue