~aleteoryx/muditaos

ref: 299be4daf6da880f495f4dc363e480d6ff0f0e9b muditaos/module-apps/application-calllog/widgets/CalllogItem.cpp -rw-r--r-- 2.6 KiB
299be4da — Piotr Tanski [EGD-4151] Application manager actions introduced. (#905) 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
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "CalllogItem.hpp"
#include "time/time_conversion.hpp"
#include "../data/CallLogInternals.hpp"
#include "gui/widgets/BoxLayout.hpp"

#include <Style.hpp>

using namespace calllog;

namespace gui
{

    CalllogItem::CalllogItem(CalllogModel *model, bool mode24H) : model{model}, mode24H{mode24H}
    {
        setMargins(Margins(0, style::margins::big, 0, 0));
        setMinimumSize(clItemStyle::w, clItemStyle::h);
        setMaximumSize(clItemStyle::w, clItemStyle::h);

        setRadius(0);
        setEdges(RectangleEdge::Bottom | RectangleEdge::Top);

        setPenFocusWidth(style::window::default_border_focus_w);
        setPenWidth(style::window::default_border_no_focus_w);

        timestamp = new gui::Label(this, 0, 0, 0, 0);
        style::window::decorate(timestamp);
        timestamp->setFont(style::window::font::big);
        timestamp->setAlignment(gui::Alignment{gui::Alignment::Horizontal::Right, gui::Alignment::Vertical::Center});

        auto newImg = [=](const UTF8 imageName) -> gui::Image * {
            auto img = new gui::Image(this, clItemStyle::img::x, clItemStyle::img::y, 0, 0, imageName);
            img->setVisible(false);
            return img;
        };
        imageCallType[calllog::CallLogCallType::IN]     = newImg("calllog_arrow_in");
        imageCallType[calllog::CallLogCallType::OUT]    = newImg("calllog_arrow_out");
        imageCallType[calllog::CallLogCallType::MISSED] = newImg("calllog_arrow_den");

        text = new gui::Label(this, 0, 0, 0, 0);
        style::window::decorate(text);
        text->setFont(style::window::font::big);
        text->setEllipsis(Ellipsis::Right);
    }

    bool CalllogItem::onDimensionChanged(const BoundingBox &oldDim, const BoundingBox &newDim)
    {
        text->setPosition(clItemStyle::text::x, 0);
        text->setSize(newDim.w, newDim.h);

        timestamp->setPosition(newDim.w - clItemStyle::timestamp::w, 0);
        timestamp->setSize(clItemStyle::timestamp::w, newDim.h);
        return true;
    }

    void CalllogItem::setCall(std::shared_ptr<CalllogRecord> &call)
    {
        this->call = call;
        text->setText(call->name);

        auto callType = calllog::toCallLogCallType(call->type);
        if (callType == calllog::CallLogCallType::MISSED)
            text->setFont(style::window::font::bigbold);

        imageCallType[static_cast<uint32_t>(callType)]->setVisible(true);

        timestamp->setText(utils::time::DateTime(call->date, false)); // TODO: alek: check for AM/PM and 24h
    }

} /* namespace gui */