~aleteoryx/muditaos

ref: b5780f819344111407b48fbf2f6dbab3c831e13f muditaos/module-apps/application-calendar/widgets/MonthBox.cpp -rw-r--r-- 3.6 KiB
b5780f81 — Mateusz Grzegorzek [EGD-5287] Add Languages window 5 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "MonthBox.hpp"
#include "application-calendar/widgets/CalendarStyle.hpp"
#include "application-calendar/windows/CalendarMainWindow.hpp"
#include "application-calendar/widgets/DayLabel.hpp"

namespace gui
{
    MonthBox::MonthBox(app::Application *app,
                       gui::Item *parent,
                       const int &offsetTop,
                       const uint32_t &width,
                       const uint32_t &height,
                       const uint32_t &dayWidth,
                       const uint32_t &dayHeight,
                       const std::unique_ptr<MonthModel> &model,
                       bool *isDayEmpty)
        : GridLayout(parent, style::window::default_left_margin, offsetTop, width, height, {dayWidth, dayHeight})
    {
        LOG_DEBUG("Call MonthBox constructor");

        assert(parent);
        parent->addWidget(this);
        month            = model->getMonthText();
        monthFilterValue = model->getYear() / model->getMonth();
        grid.x           = dayWidth;
        grid.y           = dayHeight;

        uint32_t firstDayOffset = model->getFirstWeekOffset();
        uint32_t lastDay        = model->getLastDay();
        uint32_t iterations     = style::window::calendar::week_days_number + firstDayOffset + lastDay;

        uint32_t i;
        for (i = 0; i < iterations; ++i) {
            if (i < style::window::calendar::week_days_number + firstDayOffset) {
                auto day = new DayLabel(app,
                                        this,
                                        i,
                                        firstDayOffset,
                                        style::window::calendar::day_cell_width,
                                        style::window::calendar::day_cell_height,
                                        true);
                addWidget(day);
            }
            else {
                auto day = new DayLabel(app,
                                        this,
                                        i,
                                        firstDayOffset,
                                        style::window::calendar::day_cell_width,
                                        style::window::calendar::day_cell_height,
                                        isDayEmpty[i - (style::window::calendar::week_days_number + firstDayOffset)]);
                addWidget(day);
            }
        }
        auto mainWindow = dynamic_cast<CalendarMainWindow *>(parent);
        if (mainWindow->returnedFromWindow) {
            focusChangedCallback = [=](Item &item) {
                calendar::YearMonthDay date = monthFilterValue.year() / monthFilterValue.month() / date::last;
                if (unsigned(date.day()) < mainWindow->dayFocusedBefore) {
                    setFocusOnElement(unsigned(date.day()) - 1);
                }
                else {
                    setFocusOnElement(mainWindow->dayFocusedBefore - 1);
                }
                return true;
            };
        }
        else {
            date::year_month_day actualDate = TimePointToYearMonthDay(TimePointNow());
            if (model->getYear() == actualDate.year() && model->getMonth() == actualDate.month()) {
                focusChangedCallback = [=](Item &item) {
                    setFocusOnElement(unsigned(actualDate.day()) - 1);
                    return true;
                };
            }
        }

        LOG_DEBUG("MonthBox constructor Completed Successfully!");
    }
} /* namespace gui */