~aleteoryx/muditaos

ref: d5de12f7cea071555de4058ebf62b160a86a36af muditaos/module-apps/application-desktop/windows/PinLockBaseWindow.cpp -rw-r--r-- 4.2 KiB
d5de12f7 — Radosław Wicik [EGD-3852] clean include in service (#928) 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
95
96
97
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "PinLockBaseWindow.hpp"
#include "application-desktop/data/AppDesktopStyle.hpp"
#include "application-desktop/widgets/PinLock.hpp"
#include <i18/i18.hpp>

namespace lock_style = style::window::pin_lock;
namespace gui
{

    void PinLockBaseWindow::build()
    {
        buildBottomBar();
        buildTopBar();
        buildTitleLabel();
    }
    void PinLockBaseWindow::buildBottomBar()
    {
        setBottomBarWidgetsActive(false, false, false);
        bottomBar->setText(BottomBar::Side::LEFT, utils::localize.get("app_desktop_emergency"));
        bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get(style::strings::common::confirm));
        bottomBar->setText(BottomBar::Side::RIGHT, utils::localize.get(style::strings::common::back));
    }
    void PinLockBaseWindow::buildTopBar()
    {
        topBar->setActive(TopBar::Elements::SIGNAL, true);
        topBar->setActive(TopBar::Elements::BATTERY, true);
        topBar->setActive(TopBar::Elements::LOCK, true);
    }
    void PinLockBaseWindow::buildTitleLabel()
    {
        titleLabel = new gui::Label(this, 0, lock_style::title_label_y, style::window_width, lock_style::title_label_h);
        titleLabel->setFilled(false);
        titleLabel->setVisible(false);
        titleLabel->setBorderColor(gui::ColorFullBlack);
        titleLabel->setFont(style::header::font::title);
        titleLabel->setText(utils::localize.get("app_desktop_pin_info1"));
        titleLabel->setEdges(RectangleEdge::None);
        titleLabel->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Bottom));
    }
    void PinLockBaseWindow::buildInfoText(unsigned int h)
    {
        infoText = new Text(this, 0, lock_style::info_text_y, style::window_width, h);
        infoText->setFont(style::window::font::medium);
        infoText->setVisible(true);
        infoText->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Top));
    }
    void PinLockBaseWindow::buildPinLabels(gui::Label *labelsBox, unsigned int pinSize, unsigned int singleLabelWidth)
    {
        if (pinSize * singleLabelWidth > labelsBox->getWidth()) {
            singleLabelWidth = labelsBox->getWidth() / pinSize;
        }
        const uint32_t pinLabelSpacing = (labelsBox->getWidth() - pinSize * singleLabelWidth) / (pinSize - 1);

        uint32_t pinLabelX = 0;
        for (uint32_t i = 0; i < pinSize; i++) {
            gui::Label *label = new gui::Label(labelsBox, pinLabelX, 0, singleLabelWidth, lock_style::label_size);
            label->setFilled(false);
            label->setBorderColor(gui::ColorFullBlack);
            label->setPenWidth(2);
            label->setFont(style::window::font::largelight);
            label->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Bottom));
            label->setVisible(true);
            this->pinLabels.push_back(label);
            pinLabelX += singleLabelWidth + pinLabelSpacing;
        }
    }
    void PinLockBaseWindow::buildImages(const std::string &lockImg, const std::string &infoImg)
    {
        lockImage = new gui::Image(this, lock_style::image_x, lock_style::image_y, 0, 0, lockImg);
        infoImage = new gui::Image(this, lock_style::image_x, lock_style::image_y, 0, 0, infoImg);
        infoImage->setVisible(false);
    }
    void PinLockBaseWindow::setBottomBarWidgetsActive(bool left, bool center, bool right)
    {
        bottomBar->setActive(BottomBar::Side::LEFT, left);
        bottomBar->setActive(BottomBar::Side::CENTER, center);
        bottomBar->setActive(BottomBar::Side::RIGHT, right);
    }
    void PinLockBaseWindow::setImagesVisible(bool lockImg, bool infoImg)
    {
        lockImage->setVisible(lockImg);
        infoImage->setVisible(infoImg);
    }
    void PinLockBaseWindow::setBottomBarWidgetText(BottomBar::Side side, const UTF8 &txt)
    {
        bottomBar->setText(side, txt, false);
    }
    void PinLockBaseWindow::clearPinLabels()
    {
        for (auto label : pinLabels) {
            label->clear();
        }
    }
} // namespace gui