~aleteoryx/muditaos

ref: 465159ed15006a8e36c1782a39076a7f896ec08d muditaos/module-gui/gui/widgets/TopBar.hpp -rw-r--r-- 3.9 KiB
465159ed — Wojtek Rzepecki [EGD-5805] Fix not charging icon 4 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "Image.hpp"
#include "Label.hpp"
#include "Rect.hpp"
#include "TopBar/SIM.hpp"
#include <common_data/EventStore.hpp>

#include <vector>
#include <map>

namespace gui
{
    class SignalStrengthWidgetBase;
    class BatteryWidgetBase;
} // namespace gui
namespace gui::top_bar
{
    enum class Indicator
    {
        Signal,
        Time,
        Lock,
        Battery,
        SimCard,
        NetworkAccessTechnology
    };
    using Indicators        = std::vector<Indicator>;
    using IndicatorStatuses = std::map<Indicator, bool>;

    /**
     * Carries the top bar configuration.
     */
    class Configuration
    {
      public:
        void enable(Indicator indicator);
        void enable(const Indicators &indicators);
        void disable(Indicator indicator);
        void set(Indicator indicator, bool enabled);
        [[nodiscard]] auto isEnabled(Indicator indicator) const -> bool;
        [[nodiscard]] auto getIndicatorsConfiguration() const noexcept -> const IndicatorStatuses &;

      private:
        IndicatorStatuses indicatorStatuses = {{Indicator::Signal, false},
                                               {Indicator::Time, false},
                                               {Indicator::Lock, false},
                                               {Indicator::Battery, false},
                                               {Indicator::SimCard, false},
                                               {Indicator::NetworkAccessTechnology, false}};
    };

    /// Header of most of design Windows
    ///
    /// Provides way to show:
    ///    0. Window title
    ///    1. battery state
    ///    2. signal
    ///    3. time
    ///    4. sim state
    /// in separate areas, when enabled
    ///
    ///              [time]
    /// [signal]    [title ] [sim] [battery]
    class TopBar : public Rect
    {
        static constexpr uint32_t batteryBarsCount = 6;
        static constexpr uint32_t signalImgCount   = 6;

      public:
        enum class TimeMode
        {
            TIME_12H,
            TIME_24H
        };
        static uint32_t time;

      protected:
        Label *timeLabel                       = nullptr;
        Label *networkAccessTechnologyLabel    = nullptr;
        SignalStrengthWidgetBase *signalWidget = nullptr;
        Image *lock;
        gui::SIM *sim                    = nullptr;
        BatteryWidgetBase *batteryWidget = nullptr;
        Configuration configuration;
        static TimeMode timeMode;

        void prepareWidget();

        void showSim(bool enabled);

        /**
         * Sets the status of the top bar indicator.
         * @param indicator     Indicator
         */
        void setIndicatorStatus(Indicator indicator, bool enabled);

      public:
        TopBar(Item *parent, uint32_t x, uint32_t y, uint32_t w, uint32_t h);

        /**
         * Configures the top bar.
         * @param configuration     Top bar configuration
         */
        void configure(Configuration &&config);
        [[nodiscard]] auto getConfiguration() const noexcept -> const Configuration &;

        /**
         * @brief Sets charge level of the battery. This will cause appropriate image to be
         * displayed.
         * @return if display should be refreshed or not
         */
        bool updateBattery();

        /**
         * @brief updates signal strength. This will cause appropriate image to be displayed.
         */
        bool updateSignalStrength();

        bool updateNetworkAccessTechnology();

        void simSet();

        void setTime(const UTF8 &value);
        void setTime(uint32_t value, bool mode24H);

        UTF8 getTimeString();
        uint32_t getTime() const noexcept;

        void accept(GuiVisitor &visitor) override;
    };

} // namespace gui::top_bar