~aleteoryx/muditaos

ref: 853b0787df3a08d401faea35c3f87634029bd6ac muditaos/module-apps/application-settings/windows/display-keypad/QuotesMainWindow.cpp -rw-r--r-- 2.6 KiB
853b0787 — wojtekrzepecki [EGD-8227] Refactor quotes db 3 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "QuotesMainWindow.hpp"

#include <application-settings/data/QuoteSwitchData.hpp>
#include <application-settings/windows/WindowNames.hpp>

#include <InputEvent.hpp>
#include <header/AddElementAction.hpp>

namespace style::quotes
{
    namespace list
    {
        constexpr auto X      = style::window::default_left_margin;
        constexpr auto Y      = style::window::default_vertical_pos;
        constexpr auto Width  = style::listview::body_width_with_scroll;
        constexpr auto Height = style::window_height - Y - style::nav_bar::height;
    } // namespace list
} // namespace style::quotes

namespace gui
{
    QuotesMainWindow::QuotesMainWindow(app::ApplicationCommon *app)
        : AppWindow(app, gui::window::name::quotes), quotesModel(std::make_shared<Quotes::QuotesModel>(app))
    {
        buildInterface();
    }

    void QuotesMainWindow::buildInterface()
    {
        AppWindow::buildInterface();

        setTitle(utils::translate("app_settings_display_wallpaper_quotes"));
        header->navigationIndicatorAdd(new gui::header::AddElementAction(), gui::header::BoxSelection::Left);

        navBar->setText(nav_bar::Side::Center, utils::translate(style::strings::common::check));
        navBar->setText(nav_bar::Side::Right, utils::translate(style::strings::common::back));
        navBar->setText(nav_bar::Side::Left, utils::translate(style::strings::common::options));

        list = new gui::ListView(this,
                                 style::quotes::list::X,
                                 style::quotes::list::Y,
                                 style::quotes::list::Width,
                                 style::quotes::list::Height,
                                 quotesModel,
                                 gui::listview::ScrollBarType::Fixed);

        setFocusItem(list);
    }

    auto QuotesMainWindow::onInput(const InputEvent &inputEvent) -> bool
    {
        // check if any of the lower inheritance onInput methods catch the event
        if (AppWindow::onInput(inputEvent)) {
            return true;
        }

        if (inputEvent.isShortRelease(gui::KeyCode::KEY_LEFT)) {
            application->switchWindow(gui::window::name::new_quote,
                                      std::make_unique<QuoteSwitchData>(QuoteAction::Add));
            return true;
        }

        return false;
    }

    void QuotesMainWindow::onBeforeShow(ShowMode mode, SwitchData *data)
    {
        list->rebuildList();
    }
} // namespace gui