~aleteoryx/muditaos

ref: 1e70bd11e011c0159cc27b3f2d2590cd58a8bcdf muditaos/module-apps/application-calendar/windows/CalendarMainWindow.hpp -rw-r--r-- 2.8 KiB
1e70bd11 — Tomas Rogala [EGD-33307] Add unit test, functionality fix 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
84
85
86
87
88
89
90
91
92
93
94
#pragma once

#include "windows/AppWindow.hpp"
#include "Application.hpp"
#include "application-calendar/ApplicationCalendar.hpp"
#include "application-calendar/models/MonthModel.hpp"
#include "application-calendar/models/DayModel.hpp"
#include <gui/widgets/GridLayout.hpp>
#include <map>
#include <vector>
#include <string>

namespace gui
{
    class CalendarMainWindow;

    namespace coords
    {
        const uint8_t first_row        = 1;
        const uint8_t default_last_row = 5;

        const uint8_t first_column = 0;
        const uint8_t last_column  = 6;
    }; // namespace coords

    class DayLabel : public Label, public DayModel
    {
      public:
        DayLabel(gui::Item *parent,
                 std::string number,
                 const uint32_t &x,
                 const uint32_t &y,
                 const uint32_t &width,
                 const uint32_t &height);

        void setLabel(std::string number, std::function<bool(Item &)> activatedCallback);
        ~DayLabel() override = default;
    };

    class MonthBox : public GridLayout, public MonthModel
    {
        /// @param columns: defines number of columns, @param rows: defines number of rows
        uint32_t firstRow    = 0;
        uint32_t firstColumn = 0;
        uint32_t columns     = 0;
        uint32_t rows        = 0;
        std::map<std::pair<uint32_t, uint32_t>, DayLabel *> dayMap;

      public:
        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);

        ~MonthBox() override = default;

        void buildMap(app::Application *app);
    };

    class CalendarMainWindow : public gui::AppWindow
    {
        uint32_t offsetFromTop = 0;
        uint32_t monthWidth    = 0;
        uint32_t monthHeight   = 0;
        uint32_t dayWidth      = 0;
        uint32_t dayHeight     = 0;

      protected:
        MonthBox *month = nullptr;
        Label *dateLabel = nullptr;
        std::unique_ptr<MonthModel> monthModel;

      public:
        CalendarMainWindow(app::Application *app, std::string name);

        /// used only for testing
        bool getData(const uint32_t &date_time);

        ~CalendarMainWindow() override = default;
        void switchToNoEventsWindow();
        void rebuild() override;
        void refresh(const uint32_t &ID, std::string date);
        void buildMonth(const uint32_t &actualDateTimeID);
        void buildDateLabel(std::string actualDateTime);
        void buildInterface(const uint32_t &actualDateTimeID);
        void destroyInterface() override;
        bool onInput(const gui::InputEvent &inputEvent) override;
    };

} // namespace gui