~aleteoryx/muditaos

ref: c611e3c011c336ca55733ad96af698657df034c5 muditaos/module-apps/application-calendar/widgets/NewEventCheckBoxWithLabel.cpp -rw-r--r-- 2.5 KiB
c611e3c0 — DariuszSabala [BH-376] Utils time turned to separate library 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "NewEventCheckBoxWithLabel.hpp"
#include "AppWindow.hpp"
#include "InputEvent.hpp"

namespace gui
{

    NewEventCheckBoxWithLabel::NewEventCheckBoxWithLabel(app::Application *application,
                                                         const std::string &description,
                                                         OnCheckCallback onCheck)
        : CheckBoxWithLabelItem(application, description, nullptr), onCheck(std::move(onCheck))
    {
        app = application;
        assert(app != nullptr);

        setMargins(gui::Margins(style::margins::small,
                                style::window::calendar::item::checkBox::margin_top,
                                0,
                                style::window::calendar::leftMargin));
        applyCallbacks();
    }

    void NewEventCheckBoxWithLabel::applyCallbacks()
    {
        inputCallback = [this](gui::Item &item, const gui::InputEvent &event) {
            if (event.isShortRelease(gui::KeyCode::KEY_LF)) {
                onCheck(checkBox->isChecked());
            }
            return checkBox->onInput(event);
        };

        onLoadCallback = [this](std::shared_ptr<EventsRecord> event) {
            if (allDayEvents::isAllDayEvent(event->date_from, event->date_till)) {
                checkBox->setImageVisible(true);
            }
        };
        onSaveCallback = [this](std::shared_ptr<EventsRecord> event) {
            if (checkBox->isChecked()) {
                event->date_from = TimePointFromYearMonthDay(dateItem->getChosenDate());
                event->date_till = event->date_from + std::chrono::hours(utils::time::Locale::max_hour_24H_mode) +
                                   std::chrono::minutes(utils::time::Locale::max_minutes);
            }
        };
    }

    void NewEventCheckBoxWithLabel::setConnectionToDateItem(gui::DateWidget *item)
    {
        dateItem = item;
    }

    bool allDayEvents::isAllDayEvent(TimePoint start, TimePoint end)
    {
        auto startTime = TimePointToHourMinSec(start);
        auto endTime   = TimePointToHourMinSec(end);
        return startTime.hours().count() == 0 && startTime.minutes().count() == 0 &&
               endTime.hours().count() == utils::time::Locale::max_hour_24H_mode &&
               endTime.minutes().count() == utils::time::Locale::max_minutes;
    }

} /* namespace gui */