1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:37:35 +00:00

Calendar: Fix using OwnPtr<> with RefCounted types

This commit is contained in:
Sergey Bugaev 2020-06-12 16:26:12 +03:00 committed by Andreas Kling
parent 5624f8d8ee
commit eb3700c565
3 changed files with 8 additions and 9 deletions

View file

@ -37,7 +37,7 @@
CalendarWidget::CalendarWidget()
{
m_calendar = make<Calendar>(Core::DateTime::now());
m_calendar = adopt(*new Calendar(Core::DateTime::now()));
set_fill_with_background_color(true);
set_layout<GUI::VerticalBoxLayout>();
@ -196,7 +196,7 @@ void CalendarWidget::update_calendar_tiles(int target_year, int target_month)
void CalendarWidget::show_add_event_window()
{
AddEventDialog::show(*move(m_calendar), Core::DateTime::now(), window());
AddEventDialog::show(m_calendar, Core::DateTime::now(), window());
}
CalendarWidget::CalendarTile::CalendarTile(Calendar& calendar, int index, Core::DateTime date_time)
@ -230,7 +230,7 @@ void CalendarWidget::CalendarTile::doubleclick_event(GUI::MouseEvent& event)
{
GUI::Widget::doubleclick_event(event);
//TOOD: Should be calling show_add_event_window. Would we just replace m_calender /w m_calender_widget?
AddEventDialog::show(&m_calendar, m_date_time, window());
AddEventDialog::show(m_calendar, m_date_time, window());
}
void CalendarWidget::CalendarTile::paint_event(GUI::PaintEvent& event)
@ -265,7 +265,7 @@ void CalendarWidget::CalendarTile::paint_event(GUI::PaintEvent& event)
int highlight_rect_width = (font().glyph_width('0') * (m_display_date.length() + 1)) + 2;
auto display_date = (m_date_time.day() == 1 && frame_inner_rect().width() > highlight_rect_width) ? m_display_date : String::number(m_date_time.day());
if (m_calendar.is_today(m_date_time)) {
if (m_calendar->is_today(m_date_time)) {
auto highlight_rect = Gfx::IntRect(day_rect.width() / 2 - (highlight_rect_width / 2), day_rect.y(), highlight_rect_width, font().glyph_height() + 4);
painter.draw_rect(highlight_rect, palette().base_text());
painter.draw_text(day_rect, display_date, Gfx::Font::default_bold_font(), Gfx::TextAlignment::Center, palette().base_text());

View file

@ -45,7 +45,7 @@ private:
void update_calendar_tiles(int target_year, int target_month);
OwnPtr<Calendar> m_calendar;
RefPtr<Calendar> m_calendar;
RefPtr<GUI::Widget> m_top_container;
RefPtr<GUI::Widget> m_bottom_container;
RefPtr<GUI::Label> m_selected_date_label;
@ -70,7 +70,7 @@ private:
String m_weekday_name;
String m_display_date;
Core::DateTime m_date_time;
Calendar& m_calendar;
RefPtr<Calendar> m_calendar;
};
RefPtr<CalendarTile> m_calendar_tiles[35];

View file

@ -60,8 +60,7 @@ int main(int argc, char** argv)
window->set_title("Calendar");
window->set_rect(20, 200, 596, 475);
auto calendar_widget = make<CalendarWidget>();
window->set_main_widget(calendar_widget);
auto& calendar_widget = window->set_main_widget<CalendarWidget>();
window->show();
window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-calendar.png"));
@ -70,7 +69,7 @@ int main(int argc, char** argv)
app_menu.add_action(GUI::Action::create("Add Event", { Mod_Ctrl | Mod_Shift, Key_E },
[&](const GUI::Action&) {
calendar_widget->show_add_event_window();
calendar_widget.show_add_event_window();
return;
}));