~aleteoryx/muditaos

ref: 42ca53a732487f7dabf5e06ee4c03f73c329882b muditaos/module-apps/apps-common/widgets/TimeWidget.hpp -rw-r--r-- 2.8 KiB
42ca53a7 — Maciej-Mudita [MOS-686] Fix the accessibility of user files by MTP 3 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
// 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 <Label.hpp>
#include <Text.hpp>
#include <BoxLayout.hpp>
#include "widgets/DateWidget.hpp"
#include <time/FromTillDate.hpp>

namespace gui
{
    namespace timeConstants
    {
        inline constexpr auto before_noon = "AM";
        inline constexpr auto after_noon  = "PM";
    } // namespace timeConstants

    class TimeWidget : public VBox
    {
      public:
        enum class Type
        {
            Start,
            End
        };

        TimeWidget(Item *parent,
                   const std::string &description,
                   Type type,
                   std::function<void(const UTF8 &text)> navBarTemporaryMode = nullptr,
                   std::function<void()> navBarRestoreFromTemporaryMode      = nullptr);
        void loadData(const std::chrono::hours &hoursFrom,
                      const std::chrono::minutes &minutesFrom,
                      const std::chrono::hours &hoursTill,
                      const std::chrono::minutes &minutesTill);
        bool saveData(std::shared_ptr<utils::time::FromTillDate> fromTillDate) const;
        virtual ~TimeWidget() override = default;

        void setConnectionToSecondItem(TimeWidget *item);
        void setConnectionToDateItem(DateWidget *item);

      private:
        VBox *vBox              = nullptr;
        HBox *hBox              = nullptr;
        Label *colonLabel       = nullptr;
        Label *descriptionLabel = nullptr;
        Label *hourInput        = nullptr;
        Label *minuteInput      = nullptr;
        Label *mode12hInput     = nullptr;
        bool mode24H            = false;
        TimeWidget *secondItem  = nullptr;
        DateWidget *dateItem    = nullptr;

        Type type;
        std::function<void(const UTF8 &text)> navBarTemporaryMode = nullptr;
        std::function<void()> navBarRestoreFromTemporaryMode      = nullptr;

        void applyInputCallbacks();
        void prepareForTimeMode();
        void prepareMode12HInputLabel();
        void setTime(int keyValue, Label &item);
        void onInputCallback(Label &timeInput);
        void clearInput(Label &timeInput);
        inline bool isPm(const std::string &text) const;
        bool validateHour() const;
        void validateHourFor12hMode(std::chrono::hours start_hour,
                                    std::chrono::minutes end_hour,
                                    uint32_t start_minutes,
                                    uint32_t end_minutes) const;
        void validateHourFor24hMode(std::chrono::hours start_hour,
                                    std::chrono::minutes end_hour,
                                    uint32_t start_minutes,
                                    uint32_t end_minutes) const;
    };
} /* namespace gui */