~aleteoryx/muditaos

ref: 05847f09d10bef7c7579b55de45f22a462ccb4b4 muditaos/module-apps/application-clock/windows/ClockMainWindow.cpp -rw-r--r-- 3.1 KiB
05847f09 — Paweł Joński [BH-743] Fix alarm deletion from DB 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
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

// module-gui
#include "application-clock/windows/ClockMainWindow.hpp"
#include "gui/widgets/Window.hpp"
#include "gui/widgets/Item.hpp"
#include "gui/widgets/Image.hpp"
#include "gui/widgets/Label.hpp"
#include "gui/widgets/ProgressBar.hpp"
#include "gui/widgets/BoxLayout.hpp"
#include "gui/core/ImageManager.hpp"
#include "../ClockData.hpp"
#include <Style.hpp>

namespace gui
{

    ClockMainWindow::ClockMainWindow(app::Application *app, const std::string &name) : gui::AppWindow(app, name)
    {
        uint32_t xOffset = 0;
        uint32_t yOffset = 0;

        hourLabel = new gui::Label(this, 100 + xOffset, 300 - 160 + yOffset, 280, 150);
        hourLabel->setFilled(false);
        hourLabel->setBorderColor(gui::ColorNoColor);
        hourLabel->setFont(style::window::font::largelight);
        hourLabel->setText("00");
        hourLabel->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));

        minuteLabel = new gui::Label(this, 100 + xOffset, 310 + yOffset, 280, 150);
        minuteLabel->setFilled(false);
        minuteLabel->setBorderColor(gui::ColorFullBlack);
        minuteLabel->setFont(style::window::font::largelight);
        minuteLabel->setText("00");
        minuteLabel->setRadius(20);
        minuteLabel->setPenWidth(1);
        minuteLabel->setFillColor(gui::Color(10, 0));
        minuteLabel->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));

        uint32_t x = 480 / 2 - 90 + xOffset, y = 300 - 6 + yOffset, w = 180, h = 12;
        progressBar = new ProgressBar(this, x, y, w, h);
        progressBar->setMaximum(59);
        progressBar->setValue(0);
    }

    bool ClockMainWindow::handleSwitchData(SwitchData *data)
    {
        ClockData *clockData = reinterpret_cast<ClockData *>(data);

        if (clockData) {
            hour   = clockData->hour % 24;
            minute = clockData->minute % 60;
        }

        return true;
    }

    void ClockMainWindow::updateLabels()
    {
        std::string h;
        if (hour < 10) {
            h += "0";
        }
        h += std::to_string(hour);
        hourLabel->setText(h);

        std::string m;
        if (minute < 10) {
            m += "0";
        }
        m += std::to_string(minute);
        minuteLabel->setText(m);
    }

    bool ClockMainWindow::incrementHour()
    {
        hour++;
        if (hour > 23) {
            hour = 0;
            return true;
        }
        return false;
    }
    bool ClockMainWindow::incrementMinute()
    {
        minute++;
        if (minute > 59) {
            incrementHour();
            minute = 0;
            return true;
        }
        return false;
    }

    bool ClockMainWindow::incrementSecond()
    {
        bool ret = false;
        seconds++;
        if (seconds > 59) {
            incrementMinute();
            seconds = 0;
            ret     = true;
        }
        progressBar->setValue(seconds);

        return ret;
    }

} /* namespace gui */