~aleteoryx/muditaos

ref: db4b41c56eba5ec898bbbdc23d6fbb7222653922 muditaos/module-apps/application-calendar/widgets/CalendarTimeItem.cpp -rw-r--r-- 2.4 KiB
db4b41c5 — Jakub Pyszczak [EGD-5712] Volume popup added 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
// 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 */