~aleteoryx/muditaos

ref: 9a7982f8efa4974f7f1396232fa2c09db0f6908e muditaos/module-apps/windows/Dialog.cpp -rw-r--r-- 6.2 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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "Dialog.hpp"
#include "DialogMetadataMessage.hpp"
#include <service-appmgr/model/ApplicationManager.hpp>
#include <i18/i18.hpp>

using namespace gui;

namespace style
{
    namespace image
    {
        constexpr uint32_t x = 176;
        constexpr uint32_t y = 132;
    } // namespace image
    namespace text
    {
        constexpr uint32_t x = 40;
        constexpr uint32_t y = 290;
        constexpr uint32_t w = 400;
        constexpr uint32_t h = 132;
    } // namespace text
    namespace no
    {
        constexpr uint32_t x = 75;
        constexpr uint32_t y = 415;
        constexpr uint32_t w = 150;
        constexpr uint32_t h = 75;
    } // namespace no
    namespace yes
    {
        constexpr uint32_t x = 255;
        constexpr uint32_t y = 415;
        constexpr uint32_t w = 150;
        constexpr uint32_t h = 75;
    } // namespace yes
    namespace icontext
    {
        constexpr uint32_t x = image::x;
        constexpr uint32_t y = image::y + 40;
        constexpr uint32_t w = 130;
        constexpr uint32_t h = 100;
    } // namespace icontext

} // namespace style

Dialog::Dialog(app::Application *app, const std::string &name) : gui::AppWindow(app, name)
{
    AppWindow::buildInterface();

    topBar->setActive(TopBar::Elements::TIME, true);
    bottomBar->setText(BottomBar::Side::RIGHT, utils::localize.get(style::strings::common::back));

    setTitle("");

    icon = new Image(this, style::image::x, style::image::y, "");

    text = new Text(this, style::text::x, style::text::y, style::text::w, style::text::h);
    text->setRichText("lol");
    text->setTextType(TextType::MULTI_LINE);
    text->setEditMode(EditMode::BROWSE);
    text->setEdges(RectangleEdge::None);
    text->setFont(style::window::font::medium);
    text->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
}

void Dialog::onBeforeShow(ShowMode mode, SwitchData *data)
{
    if (auto metadata = dynamic_cast<DialogMetadataMessage *>(data); metadata != nullptr) {
        setTitle(metadata->get().title);
        text->setRichText(metadata->get().text);
        icon->set(metadata->get().icon);
    }
}

DialogConfirm::DialogConfirm(app::Application *app, const std::string &name) : Dialog(app, name)
{
    topBar->setActive(TopBar::Elements::BATTERY, true);
    topBar->setActive(TopBar::Elements::SIGNAL, true);

    bottomBar->setActive(BottomBar::Side::RIGHT, false);
    bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get(style::strings::common::ok));
    setFocusItem(icon);
    icon->inputCallback = [=](Item &, const InputEvent &inputEvent) -> bool {
        if (inputEvent.state == InputEvent::State::keyReleasedShort && inputEvent.keyCode == gui::KeyCode::KEY_RF) {
            return true;
        }
        return false;
    };
    setTitle("");
}

void DialogConfirm::onBeforeShow(ShowMode mode, SwitchData *data)
{
    if (auto metadata = dynamic_cast<DialogMetadataMessage *>(data); metadata != nullptr) {
        Dialog::onBeforeShow(mode, metadata);
        auto foo                = metadata->get().action;
        icon->activatedCallback = [foo](Item &) -> bool { return foo(); };
    }
}

DialogYesNo::DialogYesNo(app::Application *app, const std::string &name) : Dialog(app, name)
{
    no = new Label(
        this, style::no::x, style::no::y, style::no::w, style::no::h, utils::localize.get(style::strings::common::no));
    no->setPenWidth(0);
    no->setPenFocusWidth(3);
    no->setFilled(false);
    no->setBorderColor(ColorFullBlack);
    no->setEdges(RectangleEdge::Bottom | RectangleEdge::Top);
    no->setFont(style::window::font::big);
    no->setAlignment(Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
    no->activatedCallback = [=](Item &) -> bool {
        application->returnToPreviousWindow();
        return true;
    };

    yes = new Label(this,
                    style::yes::x,
                    style::yes::y,
                    style::yes::w,
                    style::yes::h,
                    utils::localize.get(style::strings::common::yes));
    yes->setPenWidth(0);
    yes->setPenFocusWidth(3);
    yes->setFilled(false);
    yes->setBorderColor(ColorFullBlack);
    yes->setEdges(RectangleEdge::Bottom | RectangleEdge::Top);
    yes->setFont(style::window::font::big);
    yes->setAlignment(Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
    yes->activatedCallback = [=](Item &) -> bool { return false; };

    no->setNavigationItem(NavigationDirection::RIGHT, yes);
    yes->setNavigationItem(NavigationDirection::LEFT, no);
    no->setNavigationItem(NavigationDirection::LEFT, yes);
    yes->setNavigationItem(NavigationDirection::RIGHT, no);

    bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get("common_confirm"));

    setFocusItem(no);
}

void DialogYesNo::onBeforeShow(ShowMode mode, SwitchData *data)
{
    if (auto metadata = dynamic_cast<DialogMetadataMessage *>(data); metadata != nullptr) {
        Dialog::onBeforeShow(mode, metadata);
        auto foo               = metadata->get().action;
        yes->activatedCallback = [=](Item &) -> bool { return foo(); };
        setFocusItem(no);
    }
}

DialogYesNoIconTxt::DialogYesNoIconTxt(app::Application *app, const std::string &name) : DialogYesNo(app, name)
{
    iconText = new Text(this, style::icontext::x, style::icontext::y, style::icontext::w, style::icontext::h);
    iconText->setText("");
    iconText->setTextType(TextType::SINGLE_LINE);
    iconText->setEditMode(EditMode::BROWSE);
    iconText->setEdges(RectangleEdge::None);
    iconText->setFont(style::window::font::largelight);
    iconText->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::None));
    setFocusItem(no);
}

void DialogYesNoIconTxt::onBeforeShow(ShowMode mode, SwitchData *data)
{
    if (auto metadata = dynamic_cast<DialogMetadataMessage *>(data); metadata != nullptr) {
        DialogYesNo::onBeforeShow(mode, metadata);
        iconText->setText(metadata->get().iconText);
        topBar->setActive(TopBar::Elements::BATTERY, false);
        topBar->setActive(TopBar::Elements::SIM, false);
        setFocusItem(no);
    }
}