~aleteoryx/muditaos

ref: 2276ceed679b93a3a891e4f5739ade9e13991c5a muditaos/module-apps/application-messages/widgets/BaseThreadItem.cpp -rw-r--r-- 4.3 KiB
2276ceed — Radoslaw Wicik [EGD-3743] Update copyrights in fies 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
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "BaseThreadItem.hpp"
#include "application-messages/data/MessagesStyle.hpp"

namespace gui
{
    namespace
    {
        constexpr auto NumberImportancePrefix = '#';
    } // namespace

    BaseThreadItem::BaseThreadItem()
    {
        using namespace style;
        setMargins(Margins(0, style::margins::small, 0, style::margins::small));
        setMinimumSize(window::default_body_width, style::messages::threadItem::sms_thread_item_h);
        setMaximumSize(window::default_body_width, style::messages::threadItem::sms_thread_item_h);

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

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

        contact = new gui::Label(this, 0, 0, 0, 0);
        contact->setPenFocusWidth(window::default_border_no_focus_w);
        contact->setPenWidth(window::default_border_no_focus_w);
        contact->setFont(style::window::font::big);
        contact->setEllipsis(Ellipsis::Right);
        contact->setAlignment(gui::Alignment{gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Center});

        numberImportance = new gui::Label(this, 0, 0, 0, 0);
        numberImportance->setPenFocusWidth(window::default_border_no_focus_w);
        numberImportance->setPenWidth(window::default_border_no_focus_w);
        numberImportance->setFont(style::window::font::small);
        numberImportance->setAlignment(
            gui::Alignment{gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Center});

        timestamp = new gui::Label(this, 0, 0, 0, 0);
        timestamp->setPenFocusWidth(window::default_border_no_focus_w);
        timestamp->setPenWidth(window::default_border_no_focus_w);
        timestamp->setFont(style::window::font::small);
        timestamp->setEllipsis(Ellipsis::Right);
        timestamp->setAlignment(gui::Alignment{gui::Alignment::Horizontal::Right, gui::Alignment::Vertical::Center});

        preview = new gui::Label(this, 0, 0, 0, 0);
        preview->setPenFocusWidth(window::default_border_no_focus_w);
        preview->setPenWidth(window::default_border_no_focus_w);
        preview->setFont(style::window::font::small);
        preview->setEllipsis(Ellipsis::Right);
        preview->setAlignment(gui::Alignment{gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Center});
    }

    void BaseThreadItem::onDimensionChangedTop(const BoundingBox & /*oldDim*/, const BoundingBox &newDim)
    {
        namespace msgStyle = style::messages::threadItem;

        contact->setPosition(msgStyle::leftMargin, msgStyle::topMargin);
        contact->setSize(newDim.w - msgStyle::cotactWidthOffset, newDim.h / 2 - msgStyle::topMargin);

        const auto isNumberImportanceSet = !numberImportance->getText().empty();
        if (isNumberImportanceSet) {
            contact->setSize(contact->getWidth() - msgStyle::numberImportanceWidth, Axis::X);
            numberImportance->setPosition(msgStyle::leftMargin + contact->getTextWidth() +
                                              msgStyle::numberImportanceLeftMargin,
                                          msgStyle::topMargin);
            numberImportance->setSize(msgStyle::numberImportanceWidth, newDim.h / 2 - msgStyle::topMargin);
        }

        timestamp->setPosition(newDim.w - msgStyle::timestampWidth, msgStyle::topMargin);
        timestamp->setSize(msgStyle::timestampWidth, newDim.h / 2 - msgStyle::topMargin);
    }

    void BaseThreadItem::onDimensionChangedBottom(const BoundingBox & /*oldDim*/, const BoundingBox &newDim)
    {
        namespace msgStyle = style::messages::threadItem;

        preview->setPosition(msgStyle::leftMargin, newDim.h / 2);
        preview->setSize(newDim.w - msgStyle::previewWidthOffset, newDim.h / 2 - msgStyle::bottomMargin);
    }

    bool BaseThreadItem::onDimensionChanged(const BoundingBox &oldDim, const BoundingBox &newDim)
    {
        onDimensionChangedTop(oldDim, newDim);
        onDimensionChangedBottom(oldDim, newDim);

        return true;
    }

    void BaseThreadItem::displayNumberImportance(long int id)
    {
        numberImportance->setText(NumberImportancePrefix + std::to_string(id));
    }
} // namespace gui