~aleteoryx/muditaos

ref: 9a7982f8efa4974f7f1396232fa2c09db0f6908e muditaos/module-apps/widgets/ModesBox.cpp -rw-r--r-- 3.5 KiB
9a7982f8 — Marcin Smoczyński changelog: update changelog for v0.48.1 (#1104) (#1106) 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
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <module-utils/i18/i18.hpp>
#include "ModesBox.hpp"

namespace gui
{
    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::addConnected()
    {
        connected = new ModeRow(this, 0, 0, style::window::modes::width, style::window::modes::connected::height);
        connected->addText(utils::localize.get(style::window::modes::connected::title_key),
                           style::window::font::medium,
                           Margins(style::window::modes::connected::margin::left, 0, 0, 0),
                           style::window::modes::connected::width,
                           style::window::modes::connected::height);
        connected->resizeItems();
    }

    void ModesBox::addNotDisturb()
    {
        notDisturb = new ModeRow(this, 0, 0, style::window::modes::width, style::window::modes::notdisturb::height);
        notDisturb->addText(
            utils::localize.get(style::window::modes::notdisturb::title_key),
            style::window::font::largelight,
            Margins(
                style::window::modes::notdisturb::margin::left, 0, style::window::modes::notdisturb::margin::right, 0),
            style::window::modes::notdisturb::width,
            style::window::modes::notdisturb::height);
        notDisturb->addImage("dot_12px_hard_alpha_W_G");
        notDisturb->setMargins(Margins(
            0, style::window::modes::notdisturb::margin::top, 0, style::window::modes::notdisturb::margin::bottom));
        notDisturb->resizeItems();
    }

    void ModesBox::addOffline()
    {
        offline = new ModeRow(this, 0, 0, style::window::modes::width, style::window::modes::offline::height);

        offline->addText(utils::localize.get(style::window::modes::offline::title_key),
                         style::window::font::medium,
                         Margins(style::window::modes::offline::margin::left, 0, 0, 0),
                         style::window::modes::offline::width,
                         style::window::modes::offline::height);
        offline->resizeItems();
    }

    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, const Margins &margin, uint32_t width, uint32_t height)
    {
        label = new Label(this, 0, 0, width, height);
        label->setMinimumSize(width, height);
        label->setEdges(gui::RectangleEdge::None);
        label->setAlignment(Alignment(gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Center));
        label->activeItem = false;
        label->setText(text);
        label->setFont(fontSize);
        label->setMargins(margin);
    }

    void ModeRow::addImage(const std::string &imageName)
    {
        img = new Image(this, 0, 0, 0, 0);
        img->setMinimumSize(style::window::modes::image::width, style::window::modes::image::height);
        img->setAlignment(Alignment(gui::Alignment::Horizontal::Right, gui::Alignment::Vertical::Center));
        img->set(imageName);
        img->setMargins(Margins(style::window::modes::image::margin::left, 0, 0, 0));
    }
} // namespace gui