~aleteoryx/muditaos

ref: eda92600a7df852e18bdb44388966248a4af3c77 muditaos/module-gui/gui/widgets/status-bar/BatteryBar.cpp -rw-r--r-- 2.4 KiB
eda92600 — Maciej Gibowicz [BH-2095] Add quote interval setting 10 months 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
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#include "BatteryBar.hpp"
#include "Style.hpp"
#include <Image.hpp>

namespace gui::status_bar
{
    namespace
    {
        constexpr auto batteryLow           = "battery_low";
        constexpr auto batteryCharging      = "battery_charging";
        constexpr auto batteryChargingReady = "battery_charging_ready";
        constexpr auto battery1             = "battery_1";
        constexpr auto battery2             = "battery_2";
        constexpr auto battery3             = "battery_3";
        constexpr auto battery4             = "battery_4";
        constexpr auto battery5             = "battery_5";

        constexpr auto level1Threshold = 15;
        constexpr auto level2Threshold = 35;
        constexpr auto level3Threshold = 55;
        constexpr auto level4Threshold = 75;
        constexpr auto level5Threshold = 95;
    } // namespace

    BatteryBar::BatteryBar(Item *parent, uint32_t x, uint32_t y, uint32_t w, uint32_t h)
        : BatteryBase(parent, x, y, w, h)
    {
        img = new Image(this, battery1, style::status_bar::imageTypeSpecifier);

        setMinimumSize(img->getWidth(), style::status_bar::height);
    }

    void BatteryBar::showBatteryLevel(std::uint32_t percentage)
    {
        if (percentage < level1Threshold) {
            img->set(batteryLow, style::status_bar::imageTypeSpecifier);
        }
        else if (percentage < level2Threshold) {
            img->set(battery1, style::status_bar::imageTypeSpecifier);
        }
        else if (percentage < level3Threshold) {
            img->set(battery2, style::status_bar::imageTypeSpecifier);
        }
        else if (percentage < level4Threshold) {
            img->set(battery3, style::status_bar::imageTypeSpecifier);
        }
        else if (percentage < level5Threshold) {
            img->set(battery4, style::status_bar::imageTypeSpecifier);
        }
        else {
            img->set(battery5, style::status_bar::imageTypeSpecifier);
        }
    }

    void BatteryBar::showBatteryCharging()
    {
        img->set(batteryCharging, style::status_bar::imageTypeSpecifier);
    }

    void BatteryBar::showBatteryChargingDone()
    {
        img->set(batteryChargingReady, style::status_bar::imageTypeSpecifier);
    }

} // namespace gui::status_bar