mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-04-21 07:28:21 -04:00
Introduced the new logic. From now on, every button can be tri-state, that is, OFF/ON/Transiting whereas the Transiting state is marked with the 'cheking...' caption written on the button.
73 lines
3.3 KiB
C++
73 lines
3.3 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 "AlarmItem.hpp"
|
|
#include "AlarmClockStyle.hpp"
|
|
#include "application-alarm-clock/data/AlarmsData.hpp"
|
|
#include <InputEvent.hpp>
|
|
#include <time/dateCommon.hpp>
|
|
#include <time/time_conversion.hpp>
|
|
|
|
namespace gui
|
|
{
|
|
AlarmItem::AlarmItem(std::shared_ptr<app::alarmClock::AlarmRRulePresenter> presenter)
|
|
: AlarmRRuleItem(std::move(presenter))
|
|
{
|
|
setMinimumSize(style::window::default_body_width, style::alarmClock::window::item::height);
|
|
setMargins(gui::Margins(0, style::margins::small, 0, style::alarmClock::window::item::botMargin));
|
|
|
|
hBox = new gui::HBox(this, 0, 0, 0, 0);
|
|
hBox->setEdges(gui::RectangleEdge::None);
|
|
|
|
vBox = new gui::VBox(hBox, 0, 0, 0, 0);
|
|
vBox->setEdges(gui::RectangleEdge::None);
|
|
vBox->setMaximumSize(style::window::default_body_width, style::alarmClock::window::item::height);
|
|
vBox->setMargins(gui::Margins(style::widgets::leftMargin, 0, 0, 0));
|
|
|
|
timeLabel = new gui::Label(vBox, 0, 0, 0, 0);
|
|
timeLabel->setEdges(gui::RectangleEdge::None);
|
|
timeLabel->setMaximumSize(style::window::default_body_width, style::alarmClock::window::item::timeHeight);
|
|
timeLabel->setMargins(gui::Margins(0, style::margins::small, 0, 0));
|
|
timeLabel->setAlignment(gui::Alignment{gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Center});
|
|
timeLabel->setFont(style::window::font::largelight);
|
|
|
|
periodLabel = new gui::Label(vBox, 0, 0, 0, 0);
|
|
periodLabel->setEdges(gui::RectangleEdge::None);
|
|
periodLabel->setMaximumSize(style::window::default_body_width, style::alarmClock::window::item::periodHeight);
|
|
periodLabel->setAlignment(gui::Alignment{gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Top});
|
|
periodLabel->setFont(style::window::font::small);
|
|
|
|
onOffImage = new gui::ButtonTriState(hBox, ButtonTriState::State::On);
|
|
onOffImage->setMargins(gui::Margins(0, 0, style::widgets::rightMargin, 0));
|
|
|
|
setAlarm();
|
|
|
|
dimensionChangedCallback = [&](gui::Item &, const BoundingBox &newDim) -> bool {
|
|
hBox->setArea({0, 0, newDim.w, newDim.h});
|
|
return true;
|
|
};
|
|
}
|
|
|
|
void AlarmItem::setAlarm()
|
|
{
|
|
auto time = HHMMToLocalizedString(getPresenter()->getAlarm()->alarmTime.hourOfDay,
|
|
getPresenter()->getAlarm()->alarmTime.minuteOfHour,
|
|
utils::time::TimestampType::Time);
|
|
timeLabel->setText(time);
|
|
onOffImage->switchState(getPresenter()->getAlarm()->enabled ? ButtonTriState::State::On
|
|
: ButtonTriState::State::Off);
|
|
|
|
if (getPresenter()->hasRecurrence()) {
|
|
periodLabel->setText(getPresenter()->getDescription());
|
|
}
|
|
|
|
if (periodLabel->getText().empty()) {
|
|
periodLabel->setMaximumSize(0, 0);
|
|
timeLabel->setMaximumSize(style::window::default_body_width,
|
|
style::alarmClock::window::item::timeHeight +
|
|
style::alarmClock::window::item::periodHeight);
|
|
vBox->resizeItems();
|
|
}
|
|
}
|
|
} // namespace gui
|