mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-22 18:46:18 +00:00
Calendar: Add ability to view events
This commit is contained in:
parent
0d41f6cf89
commit
433fe3dc26
|
@ -5,6 +5,7 @@ serenity_component(
|
|||
|
||||
compile_gml(CalendarWidget.gml CalendarWidgetGML.cpp)
|
||||
compile_gml(AddEventDialog.gml AddEventDialogGML.cpp)
|
||||
compile_gml(ViewEventDialog.gml ViewEventDialogGML.cpp)
|
||||
|
||||
set(SOURCES
|
||||
AddEventDialog.cpp
|
||||
|
@ -15,6 +16,9 @@ set(SOURCES
|
|||
EventCalendar.cpp
|
||||
EventManager.cpp
|
||||
main.cpp
|
||||
ViewEventDialog.cpp
|
||||
ViewEventDialogGML.cpp
|
||||
ViewEventWidget.cpp
|
||||
)
|
||||
|
||||
serenity_app(Calendar ICON app-calendar)
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "CalendarWidget.h"
|
||||
#include "AddEventDialog.h"
|
||||
#include "ViewEventDialog.h"
|
||||
#include <AK/JsonParser.h>
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <LibConfig/Client.h>
|
||||
|
@ -298,8 +299,17 @@ ErrorOr<NonnullRefPtr<GUI::Action>> CalendarWidget::create_open_settings_action(
|
|||
void CalendarWidget::create_on_tile_doubleclick()
|
||||
{
|
||||
m_event_calendar->on_tile_doubleclick = [&] {
|
||||
for (const auto& event : m_event_calendar->event_manager().events()) {
|
||||
auto start = event.start;
|
||||
auto selected_date = m_event_calendar->selected_date();
|
||||
|
||||
if (start.year() == selected_date.year() && start.month() == selected_date.month() && start.day() == selected_date.day()) {
|
||||
ViewEventDialog::show(selected_date, m_event_calendar->event_manager(), window());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
AddEventDialog::show(m_event_calendar->selected_date(), m_event_calendar->event_manager(), window());
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
45
Userland/Applications/Calendar/ViewEventDialog.cpp
Normal file
45
Userland/Applications/Calendar/ViewEventDialog.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Sanil Gupta <sanilg566@gmail.com>.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "ViewEventDialog.h"
|
||||
#include "AddEventDialog.h"
|
||||
#include "ViewEventWidget.h"
|
||||
#include <LibGUI/Label.h>
|
||||
|
||||
namespace Calendar {
|
||||
|
||||
ViewEventDialog::ViewEventDialog(Core::DateTime date_time, EventManager& event_manager, GUI::Window* parent_window)
|
||||
: GUI::Dialog(parent_window)
|
||||
, m_event_manager(event_manager)
|
||||
, m_date_time(date_time)
|
||||
{
|
||||
set_title("Events");
|
||||
set_resizable(true);
|
||||
set_icon(parent_window->icon());
|
||||
|
||||
update_events();
|
||||
|
||||
auto main_widget = MUST(ViewEventWidget::create(this, m_events));
|
||||
set_main_widget(main_widget);
|
||||
}
|
||||
|
||||
void ViewEventDialog::update_events()
|
||||
{
|
||||
for (auto const& event : m_event_manager.events()) {
|
||||
auto start_date = event.start;
|
||||
if (start_date.year() == m_date_time.year() && start_date.month() == m_date_time.month() && start_date.day() == m_date_time.day()) {
|
||||
m_events.append(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ViewEventDialog::close_and_open_add_event_dialog()
|
||||
{
|
||||
close();
|
||||
AddEventDialog::show(m_date_time, m_event_manager, find_parent_window());
|
||||
}
|
||||
|
||||
}
|
18
Userland/Applications/Calendar/ViewEventDialog.gml
Normal file
18
Userland/Applications/Calendar/ViewEventDialog.gml
Normal file
|
@ -0,0 +1,18 @@
|
|||
@Calendar::ViewEventWidget {
|
||||
fill_with_background_color: true
|
||||
layout: @GUI::VerticalBoxLayout {
|
||||
margins: [4]
|
||||
}
|
||||
|
||||
@GUI::Widget {
|
||||
fill_with_background_color: true
|
||||
layout: @GUI::VerticalBoxLayout {}
|
||||
name: "events_list"
|
||||
min_width: 100
|
||||
}
|
||||
|
||||
@GUI::Button {
|
||||
name: "add_event_button"
|
||||
text: "Add Event"
|
||||
}
|
||||
}
|
38
Userland/Applications/Calendar/ViewEventDialog.h
Normal file
38
Userland/Applications/Calendar/ViewEventDialog.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Sanil Gupta <sanilg566@gmail.com>.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "EventManager.h"
|
||||
#include <LibGUI/Calendar.h>
|
||||
#include <LibGUI/Dialog.h>
|
||||
#include <LibGUI/Window.h>
|
||||
|
||||
namespace Calendar {
|
||||
|
||||
class ViewEventDialog final : public GUI::Dialog {
|
||||
C_OBJECT(ViewEventDialog)
|
||||
public:
|
||||
virtual ~ViewEventDialog() override = default;
|
||||
|
||||
static void show(Core::DateTime date, EventManager& event_manager, Window* parent_window = nullptr)
|
||||
{
|
||||
auto dialog = ViewEventDialog::construct(date, event_manager, parent_window);
|
||||
dialog->exec();
|
||||
}
|
||||
void close_and_open_add_event_dialog();
|
||||
|
||||
private:
|
||||
ViewEventDialog(Core::DateTime, EventManager&, Window*);
|
||||
void update_events();
|
||||
|
||||
EventManager& m_event_manager;
|
||||
Core::DateTime m_date_time;
|
||||
|
||||
Vector<Event> m_events;
|
||||
};
|
||||
|
||||
}
|
34
Userland/Applications/Calendar/ViewEventWidget.cpp
Normal file
34
Userland/Applications/Calendar/ViewEventWidget.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Sanil Gupta <sanilg566@gmail.com>.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "ViewEventWidget.h"
|
||||
#include <LibGUI/Button.h>
|
||||
#include <LibGUI/Label.h>
|
||||
|
||||
namespace Calendar {
|
||||
ErrorOr<NonnullRefPtr<ViewEventWidget>> ViewEventWidget::create(ViewEventDialog* parent_window, Vector<Event>& events)
|
||||
{
|
||||
auto widget = TRY(try_create());
|
||||
|
||||
auto* events_list = widget->find_descendant_of_type_named<GUI::Widget>("events_list");
|
||||
for (auto const& event : events) {
|
||||
String text = MUST(String::formatted("{} {}", event.start.to_byte_string("%H:%M"sv), event.summary));
|
||||
auto label = GUI::Label::construct(text);
|
||||
label->set_fill_with_background_color(true);
|
||||
label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
label->set_text_wrapping(Gfx::TextWrapping::DontWrap);
|
||||
events_list->add_child(label);
|
||||
}
|
||||
|
||||
auto* add_new_event_button = widget->find_descendant_of_type_named<GUI::Button>("add_event_button");
|
||||
add_new_event_button->on_click = [window = parent_window](auto) {
|
||||
window->close_and_open_add_event_dialog();
|
||||
};
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
}
|
29
Userland/Applications/Calendar/ViewEventWidget.h
Normal file
29
Userland/Applications/Calendar/ViewEventWidget.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Sanil Gupta <sanilg566@gmail.com>.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ViewEventDialog.h"
|
||||
#include <LibGUI/Calendar.h>
|
||||
#include <LibGUI/Dialog.h>
|
||||
#include <LibGUI/Model.h>
|
||||
#include <LibGUI/Window.h>
|
||||
|
||||
namespace Calendar {
|
||||
|
||||
class ViewEventWidget final : public GUI::Widget {
|
||||
C_OBJECT(ViewEventWidget);
|
||||
|
||||
public:
|
||||
static ErrorOr<NonnullRefPtr<ViewEventWidget>> create(ViewEventDialog*, Vector<Event>& events);
|
||||
virtual ~ViewEventWidget() override = default;
|
||||
|
||||
private:
|
||||
ViewEventWidget() = default;
|
||||
static ErrorOr<NonnullRefPtr<ViewEventWidget>> try_create();
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in a new issue