• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TIME_PICKER_TIME_PICKER_LAYOUT_PROPERTY_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TIME_PICKER_TIME_PICKER_LAYOUT_PROPERTY_H
18 
19 #include <string>
20 #include <vector>
21 #include "base/geometry/dimension.h"
22 #include "core/components/common/layout/constants.h"
23 #include "core/components_ng/base/inspector_filter.h"
24 #include "core/components_ng/layout/layout_property.h"
25 #include "core/components_ng/pattern/linear_layout/linear_layout_property.h"
26 #include "core/components_ng/pattern/text/text_styles.h"
27 #include "core/components_ng/pattern/time_picker/timepicker_model_ng.h"
28 #include "core/components_ng/property/property.h"
29 
30 namespace OHOS::Ace::NG {
31 class ACE_EXPORT TimePickerLayoutProperty : public LinearLayoutProperty {
32     DECLARE_ACE_TYPE(TimePickerLayoutProperty, LinearLayoutProperty);
33 
34 public:
TimePickerLayoutProperty()35     TimePickerLayoutProperty() : LinearLayoutProperty(false) {};
36     ~TimePickerLayoutProperty() override = default;
37 
Clone()38     RefPtr<LayoutProperty> Clone() const override
39     {
40         auto value = MakeRefPtr<TimePickerLayoutProperty>();
41         value->LayoutProperty::UpdateLayoutProperty(DynamicCast<LayoutProperty>(this));
42         value->propLoop_ = CloneLoop();
43         value->propDisappearTextStyle_ = CloneDisappearTextStyle();
44         value->propTextStyle_ = CloneTextStyle();
45         value->propSelectedTextStyle_ = CloneSelectedTextStyle();
46         value->propDigitalCrownSensitivity_ = CloneDigitalCrownSensitivity();
47         return value;
48     }
49 
Reset()50     void Reset() override
51     {
52         LinearLayoutProperty::Reset();
53         ResetLoop();
54         ResetDisappearTextStyle();
55         ResetTextStyle();
56         ResetSelectedTextStyle();
57         ResetDigitalCrownSensitivity();
58     }
59 
FontAddJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)60     void FontAddJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const
61     {
62         Color defaultDisappearColor = Color::BLACK;
63         Color defaultNormalColor = Color::BLACK;
64         Color defaultSelectColor = Color::BLACK;
65         auto pipeline = PipelineBase::GetCurrentContext();
66         auto frameNode = GetHost();
67         if (pipeline && frameNode) {
68             auto pickerTheme = pipeline->GetTheme<PickerTheme>(frameNode->GetThemeScopeId());
69             if (pickerTheme) {
70                 defaultDisappearColor = pickerTheme->GetDisappearOptionStyle().GetTextColor();
71                 defaultNormalColor = pickerTheme->GetOptionStyle(false, false).GetTextColor();
72                 defaultSelectColor = pickerTheme->GetOptionStyle(true, false).GetTextColor();
73             }
74         }
75 
76         auto disappearFont = JsonUtil::Create(true);
77         disappearFont->Put("size", GetDisappearFontSizeValue(Dimension(0)).ToString().c_str());
78         disappearFont->Put(
79             "weight", V2::ConvertWrapFontWeightToStirng(GetDisappearWeight().value_or(FontWeight::NORMAL)).c_str());
80 
81         auto disappearTextStyle = JsonUtil::Create(true);
82         disappearTextStyle->Put("color", GetDisappearColor().value_or(defaultDisappearColor).ColorToString().c_str());
83         disappearTextStyle->Put("font", disappearFont);
84         json->PutExtAttr("disappearTextStyle", disappearTextStyle, filter);
85 
86         auto normalFont = JsonUtil::Create(true);
87         normalFont->Put("size", GetFontSizeValue(Dimension(0)).ToString().c_str());
88         normalFont->Put("weight", V2::ConvertWrapFontWeightToStirng(GetWeight().value_or(FontWeight::NORMAL)).c_str());
89         auto normalTextStyle = JsonUtil::Create(true);
90         normalTextStyle->Put("color", GetColor().value_or(defaultNormalColor).ColorToString().c_str());
91         normalTextStyle->Put("font", normalFont);
92         json->PutExtAttr("textStyle", normalTextStyle, filter);
93 
94         auto selectedFont = JsonUtil::Create(true);
95         selectedFont->Put("size", GetSelectedFontSizeValue(Dimension(0)).ToString().c_str());
96         selectedFont->Put(
97             "weight", V2::ConvertWrapFontWeightToStirng(GetSelectedWeight().value_or(FontWeight::NORMAL)).c_str());
98         auto selectedTextStyle = JsonUtil::Create(true);
99         selectedTextStyle->Put("color", GetSelectedColor().value_or(defaultSelectColor).ColorToString().c_str());
100         selectedTextStyle->Put("font", selectedFont);
101         json->PutExtAttr("selectedTextStyle", selectedTextStyle, filter);
102     }
103 
ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)104     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override
105     {
106         LayoutProperty::ToJsonValue(json, filter);
107         /* no fixed attr below, just return */
108         if (filter.IsFastFilter()) {
109             return;
110         }
111         json->PutExtAttr("useMilitaryTime",
112             V2::ConvertBoolToString(GetIsUseMilitaryTimeValue(false)).c_str(), filter);
113         json->PutExtAttr("loop", V2::ConvertBoolToString(GetLoopValue(true)).c_str(), filter);
114 
115         FontAddJsonValue(json, filter);
116         json->PutExtAttr("enableCascade",
117             V2::ConvertBoolToString(GetIsEnableCascade().value_or(false)).c_str(), filter);
118 
119         auto options = JsonUtil::Create(true);
120         options->Put("hour", TimeFormat::GetHourFormat(
121             GetPrefixHourValue(0), GetIsUseMilitaryTimeValue(false)).c_str());
122         options->Put("minute", TimeFormat::GetMinuteFormat(GetPrefixMinuteValue(0)).c_str());
123         if (GetPrefixSecondValue(0) != static_cast<int32_t>(ZeroPrefixType::OFF)) {
124             options->Put("second", TimeFormat::GetSecondFormat(GetPrefixSecondValue(0)).c_str());
125         }
126         json->PutExtAttr("dateTimeOptions", options, filter);
127         auto crownSensitivity = GetDigitalCrownSensitivity();
128         json->PutExtAttr("digitalCrownSensitivity",
129             std::to_string(crownSensitivity.value_or(DEFAULT_CROWNSENSITIVITY)).c_str(), filter);
130     }
131 
132     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(IsUseMilitaryTime, bool, PROPERTY_UPDATE_MEASURE);
133     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Loop, bool, PROPERTY_UPDATE_MEASURE);
134     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PrefixHour, int32_t, PROPERTY_UPDATE_MEASURE);
135     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PrefixMinute, int32_t, PROPERTY_UPDATE_MEASURE);
136     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PrefixSecond, int32_t, PROPERTY_UPDATE_MEASURE);
137     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(IsEnableCascade, bool, PROPERTY_UPDATE_MEASURE);
138     ACE_DEFINE_PROPERTY_GROUP(DisappearTextStyle, FontStyle);
139     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
140         DisappearTextStyle, FontSize, DisappearFontSize, Dimension, PROPERTY_UPDATE_MEASURE);
141     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
142         DisappearTextStyle, TextColor, DisappearColor, Color, PROPERTY_UPDATE_MEASURE_SELF);
143     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
144         DisappearTextStyle, FontWeight, DisappearWeight, FontWeight, PROPERTY_UPDATE_MEASURE);
145     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
146         DisappearTextStyle, FontFamily, DisappearFontFamily, std::vector<std::string>, PROPERTY_UPDATE_MEASURE);
147     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
148         DisappearTextStyle, ItalicFontStyle, DisappearFontStyle, Ace::FontStyle, PROPERTY_UPDATE_MEASURE);
149 
150     ACE_DEFINE_PROPERTY_GROUP(TextStyle, FontStyle);
151     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(TextStyle, FontSize, FontSize, Dimension, PROPERTY_UPDATE_MEASURE);
152     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(TextStyle, TextColor, Color, Color, PROPERTY_UPDATE_MEASURE_SELF);
153     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(TextStyle, FontWeight, Weight, FontWeight, PROPERTY_UPDATE_MEASURE);
154     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
155         TextStyle, FontFamily, FontFamily, std::vector<std::string>, PROPERTY_UPDATE_MEASURE);
156     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
157         TextStyle, ItalicFontStyle, FontStyle, Ace::FontStyle, PROPERTY_UPDATE_MEASURE);
158 
159     ACE_DEFINE_PROPERTY_GROUP(SelectedTextStyle, FontStyle);
160     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
161         SelectedTextStyle, FontSize, SelectedFontSize, Dimension, PROPERTY_UPDATE_MEASURE);
162     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
163         SelectedTextStyle, TextColor, SelectedColor, Color, PROPERTY_UPDATE_MEASURE_SELF);
164     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
165         SelectedTextStyle, FontWeight, SelectedWeight, FontWeight, PROPERTY_UPDATE_MEASURE);
166     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
167         SelectedTextStyle, FontFamily, SelectedFontFamily, std::vector<std::string>, PROPERTY_UPDATE_MEASURE);
168     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
169         SelectedTextStyle, ItalicFontStyle, SelectedFontStyle, Ace::FontStyle, PROPERTY_UPDATE_MEASURE);
170     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(DigitalCrownSensitivity, int32_t, PROPERTY_UPDATE_MEASURE);
171 private:
172     ACE_DISALLOW_COPY_AND_MOVE(TimePickerLayoutProperty);
173 };
174 } // namespace OHOS::Ace::NG
175 
176 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TIME_PICKER_TIME_PICKER_LAYOUT_PROPERTY_H
177