~aleteoryx/muditaos

ref: f4bcc5ce6f0d66f6ee55949f9978ad0c0399fddb muditaos/module-apps/apps-common/widgets/BellBaseLayout.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
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "BellBaseLayout.hpp"
#include "Style.hpp"

namespace gui
{
    BellBaseLayout::BellBaseLayout(Item *parent, Position x, Position y, Length w, Length h, bool withSideArrows)
        : VThreeBox(parent, x, y, w, h)
    {
        setMinimumSize(style::bell_base_layout::w, style::bell_base_layout::h);
        setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center));
        setEdges(RectangleEdge::None);

        firstBox = new VBox(this);
        firstBox->setMinimumSize(style::bell_base_layout::first_layout_w, style::bell_base_layout::first_layout_min_h);
        firstBox->setMargins(Margins(0U, style::bell_base_layout::first_top_margin, 0U, 0U));
        firstBox->setMaximumHeight(style::bell_base_layout::first_layout_h);
        firstBox->setAlignment(Alignment(gui::Alignment::Horizontal::Center));
        firstBox->setEdges(RectangleEdge::None);
        firstBox->activeItem = false;

        centerBox = new VBox(this);
        centerBox->setEdges(RectangleEdge::None);
        centerBox->setAlignment(Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
        centerBox->setMinimumSize(style::bell_base_layout::center_layout_w, style::bell_base_layout::center_layout_h);

        lastBox = new VBox(this);
        lastBox->setMinimumSize(style::bell_base_layout::last_layout_w, style::bell_base_layout::last_layout_h);
        lastBox->setAlignment(Alignment(gui::Alignment::Horizontal::Center));
        lastBox->setEdges(RectangleEdge::None);
        lastBox->activeItem = false;

        resizeItems();

        if (withSideArrows) {
            addSideArrows();
        }
    }

    Item *BellBaseLayout::getCenterBox() const noexcept
    {
        if (arrowsThreeBox != nullptr) {
            return arrowsThreeBox->centerBox;
        }
        return centerBox;
    }

    void BellBaseLayout::resizeCenter()
    {
        centerBox->resizeItems();
        if (arrowsThreeBox != nullptr) {
            arrowsThreeBox->resizeItems();
        }
    }

    void BellBaseLayout::resize()
    {
        resizeItems();
        firstBox->resizeItems();
        resizeCenter();
        lastBox->resizeItems();
    }

    void BellBaseLayout::addSideArrows()
    {
        arrowsThreeBox = new HThreeBox<HBox, HBox, HBox>(centerBox);
        arrowsThreeBox->setMinimumSize(style::bell_base_layout::arrows_layout_w,
                                       style::bell_base_layout::center_layout_h);
        arrowsThreeBox->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center));
        arrowsThreeBox->setEdges(RectangleEdge::None);

        arrowsThreeBox->firstBox = new HBox(arrowsThreeBox);
        arrowsThreeBox->firstBox->setAlignment(Alignment(Alignment::Vertical::Center));
        arrowsThreeBox->firstBox->setEdges(RectangleEdge::None);
        arrowsThreeBox->firstBox->activeItem = false;

        leftArrow = new ImageBox(arrowsThreeBox->firstBox, new Image("bell_arrow_left_W_M"));
        leftArrow->setAlignment(Alignment(Alignment::Horizontal::Right, Alignment::Vertical::Center));
        leftArrow->setMinimumSizeToFitImage();
        leftArrow->setVisible(true);
        leftArrow->setEdges(RectangleEdge::None);
        arrowsThreeBox->firstBox->setMinimumSize(leftArrow->widgetMinimumArea.w, leftArrow->widgetMinimumArea.h);

        arrowsThreeBox->centerBox = new HBox(arrowsThreeBox);
        arrowsThreeBox->centerBox->setEdges(RectangleEdge::None);
        arrowsThreeBox->centerBox->setAlignment(Alignment(gui::Alignment::Horizontal::Center));
        arrowsThreeBox->centerBox->setMaximumSize(style::bell_base_layout::center_layout_w,
                                                  style::bell_base_layout::center_layout_h);

        arrowsThreeBox->lastBox = new HBox(arrowsThreeBox);
        arrowsThreeBox->lastBox->setAlignment(Alignment(Alignment::Vertical::Center));
        arrowsThreeBox->lastBox->setEdges(RectangleEdge::None);
        arrowsThreeBox->lastBox->activeItem = false;

        rightArrow = new ImageBox(arrowsThreeBox->lastBox, new Image("bell_arrow_right_W_M"));
        rightArrow->setAlignment(Alignment(Alignment::Horizontal::Left, Alignment::Vertical::Center));
        rightArrow->setMinimumSizeToFitImage();
        rightArrow->setVisible(true);
        rightArrow->setEdges(RectangleEdge::None);
        arrowsThreeBox->lastBox->setMinimumSize(rightArrow->widgetMinimumArea.w, rightArrow->widgetMinimumArea.h);
    }

    void BellBaseLayout::setArrowVisible(Arrow arrow, bool isVisible)
    {
        auto item = arrow == Arrow::Left ? leftArrow : rightArrow;
        if (item != nullptr) {
            item->setVisible(isVisible);
        }
    }

    void BellBaseLayout::setMinMaxArrowsVisibility(bool minCondition, bool maxCondition)
    {
        setArrowVisible(BellBaseLayout::Arrow::Left, !minCondition);
        setArrowVisible(BellBaseLayout::Arrow::Right, !maxCondition);
        if (arrowsThreeBox != nullptr) {
            if (arrowsThreeBox->firstBox != nullptr) {
                arrowsThreeBox->firstBox->resizeItems();
            }
            if (arrowsThreeBox->lastBox != nullptr) {
                arrowsThreeBox->lastBox->resizeItems();
            }
        }
    }
} // namespace gui