Files
MuditaOS/module-apps/application-calendar/widgets/CalendarTimeItem.cpp
Mateusz Grzegorzek 8f0797218f [EGD-5312] Add Time selection window
- add ChangeDateAndTimeWindow,
- extract EventTimeItem to common widgets folder
  and rename it to TimeWidget,
- extract EventDateItem to common widgets folder
  and rename it to DateWidget,
- replace timeWidget with common TimeWidget
  in NightshiftWindow,
- refactor time setting in
  DesktopMainWindow and TopBar,
- Remove dead code from EventManager
  (GetNextAlarmTimestamp and HandleAlarmTrigger)
2021-02-23 15:59:51 +01:00

57 lines
2.4 KiB
C++

// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "CalendarDateItem.hpp"
#include "CalendarTimeItem.hpp"
#include <module-apps/widgets/DateAndTimeStyle.hpp>
#include <module-apps/widgets/WidgetsUtils.hpp>
#include <module-gui/gui/input/InputEvent.hpp>
namespace date_and_time = style::window::date_and_time;
namespace gui
{
CalendarTimeItem::CalendarTimeItem(const std::string &description,
TimeWidget::Type type,
const std::function<void(const UTF8 &text)> &bottomBarTemporaryMode,
const std::function<void()> &bottomBarRestoreFromTemporaryMode)
{
setMinimumSize(style::window::default_body_width, date_and_time::height);
setEdges(RectangleEdge::None);
setMargins(gui::Margins(date_and_time::leftMargin, date_and_time::topMargin, 0, 0));
vBox = new VBox(this, 0, 0, 0, 0);
vBox->setEdges(RectangleEdge::None);
timeWidget = new TimeWidget(vBox, description, type, bottomBarTemporaryMode, bottomBarRestoreFromTemporaryMode);
onLoadCallback = [&](std::shared_ptr<EventsRecord> event) {
timeWidget->loadData(std::chrono::hours(TimePointToHour24H(event->date_from)),
std::chrono::minutes(TimePointToMin(event->date_from)),
std::chrono::hours(TimePointToHour24H(event->date_till)),
std::chrono::minutes(TimePointToMin(event->date_till)));
};
onSaveCallback = [&](std::shared_ptr<EventsRecord> record) -> bool {
auto fromTillDate = std::make_shared<utils::time::FromTillDate>(record->date_from, record->date_till);
if (timeWidget->saveData(fromTillDate)) {
record->date_from = fromTillDate->from;
record->date_till = fromTillDate->till;
return true;
}
return false;
};
passDefaultCallbacksFromListItem(this, vBox);
}
void CalendarTimeItem::setConnectionToSecondItem(CalendarTimeItem *item)
{
timeWidget->setConnectionToSecondItem(item->timeWidget);
}
void CalendarTimeItem::setConnectionToDateItem(CalendarDateItem *item)
{
timeWidget->setConnectionToDateItem(item->getDateWidget());
}
} /* namespace gui */