~aleteoryx/muditaos

ref: f4bcc5ce6f0d66f6ee55949f9978ad0c0399fddb muditaos/module-apps/apps-common/widgets/ModesBox.cpp -rw-r--r-- 5.3 KiB
f4bcc5ce — Dawid Wojtas [BH-1758] Fix information about next alarm ring 2 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <i18n/i18n.hpp>
#include "ModesBox.hpp"

#include <gui/widgets/ImageBox.hpp>
#include <PhoneModes/Common.hpp>
#include <Utils.hpp>

namespace gui
{
    namespace img::dot
    {
        constexpr auto name = "dot_12px_hard_alpha_W_G";
    } // namespace img::dot

    ModesBox::ModesBox(Item *parent, uint32_t x, uint32_t y)
        : VBox(parent, x, y, style::window::modes::width, style::window::modes::height)
    {
        setEdges(RectangleEdge::None);
        addConnected();
        addNotDisturb();
        addOffline();
    }

    void ModesBox::update(const sys::phone_modes::PhoneMode &phoneMode, const bool flightMode)
    {
        using PhoneMode      = sys::phone_modes::PhoneMode;
        auto getUpdateValues = [&phoneMode](const PhoneMode &compare) -> std::pair<std::string, const bool> {
            return (phoneMode == compare) ? std::make_pair(style::window::font::largelight, true)
                                          : std::make_pair(style::window::font::medium, false);
        };
        connected->update(getUpdateValues(PhoneMode::Connected));
        notDisturb->update(getUpdateValues(PhoneMode::DoNotDisturb));
        offline->update(getUpdateValues(PhoneMode::Offline));
        if (phoneMode == PhoneMode::Offline && !flightMode) {
            messageOnly->setVisible(true);
        }
        else {
            messageOnly->setVisible(false);
        }
    }

    void ModesBox::addConnected()
    {
        connected = new ModeRow(this,
                                0,
                                0,
                                style::window::modes::width,
                                style::window::modes::height / style::window::modes::number_of_entries);
        connected->addText(utils::translate(style::window::modes::connected::title_key),
                           style::window::font::medium,
                           style::window::modes::text::width,
                           style::window::modes::height / style::window::modes::number_of_entries);

        connected->addImage(img::dot::name);
    }

    void ModesBox::addNotDisturb()
    {
        notDisturb = new ModeRow(this,
                                 0,
                                 0,
                                 style::window::modes::width,
                                 style::window::modes::height / style::window::modes::number_of_entries);

        notDisturb->addText(utils::translate(style::window::modes::notdisturb::title_key),
                            style::window::font::medium,
                            style::window::modes::text::width,
                            style::window::modes::height / style::window::modes::number_of_entries);
        notDisturb->addImage(img::dot::name);
    }

    void ModesBox::addOffline()
    {
        offline = new ModeRow(this,
                              0,
                              0,
                              style::window::modes::width,
                              style::window::modes::height / style::window::modes::number_of_entries);
        offline->addText(utils::translate(style::window::modes::offline::title_key),
                         style::window::font::medium,
                         style::window::modes::text::width,
                         style::window::modes::height / style::window::modes::number_of_entries);
        offline->addImage(img::dot::name);

        messageOnly = new ModeRow(this,
                                  0,
                                  0,
                                  style::window::modes::width,
                                  style::window::modes::height / style::window::modes::number_of_entries);

        messageOnly->addText(utils::translate(style::window::modes::offline::description_key),
                             style::window::font::verysmall,
                             style::window::modes::text::width,
                             style::window::modes::height / style::window::modes::number_of_entries);
    }

    ModeRow::ModeRow(Item *parent, uint32_t x, uint32_t y, uint32_t width, uint32_t height)
        : HBox(parent, x, y, width, height)
    {
        this->setEdges(RectangleEdge::None);
    }

    void ModeRow::addText(const std::string &text, const std::string &fontSize, uint32_t width, uint32_t height)
    {
        label = new Label(this, 0, 0, width, height, text);
        label->setEdges(gui::RectangleEdge::None);
        label->setAlignment(Alignment(gui::Alignment::Horizontal::Right, gui::Alignment::Vertical::Center));
        label->setFont(fontSize);
    }

    void ModeRow::update(std::pair<std::string, const bool> &&params)
    {
        const auto [font, imgVisibility] = params;
        img->setVisible(imgVisibility);
        label->setFont(font);
    }

    void ModeRow::addImage(const std::string &imageName)
    {
        img = new ImageBox(this,
                           0,
                           0,
                           style::window::modes::image::width,
                           style::window::modes::height / style::window::modes::number_of_entries,
                           new Image(imageName));

        img->setAlignment(Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
    }
} // namespace gui