• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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_DATE_PICKER_DATE_PICKER_ROW_LAYOUT_PROPERTY_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_DATE_PICKER_DATE_PICKER_ROW_LAYOUT_PROPERTY_H
18 
19 #include <string>
20 #include <vector>
21 #include "base/geometry/dimension.h"
22 #include "base/i18n/localization.h"
23 #include "base/json/json_util.h"
24 #include "core/components/common/layout/constants.h"
25 #include "core/components_ng/base/inspector_filter.h"
26 #include "core/components_ng/layout/layout_property.h"
27 #include "core/components_ng/pattern/linear_layout/linear_layout_property.h"
28 #include "core/components_ng/pattern/text/text_styles.h"
29 #include "core/components_ng/property/property.h"
30 #include "core/components_v2/inspector/utils.h"
31 
32 namespace OHOS::Ace::NG {
33 class ACE_EXPORT DataPickerRowLayoutProperty : public LinearLayoutProperty {
34     DECLARE_ACE_TYPE(DataPickerRowLayoutProperty, LinearLayoutProperty);
35 
36 public:
DataPickerRowLayoutProperty()37     DataPickerRowLayoutProperty() : LinearLayoutProperty(false) {};
38     ~DataPickerRowLayoutProperty() override = default;
39 
Clone()40     RefPtr<LayoutProperty> Clone() const override
41     {
42         auto value = MakeRefPtr<DataPickerRowLayoutProperty>();
43         value->LayoutProperty::UpdateLayoutProperty(DynamicCast<LayoutProperty>(this));
44         value->propSelectedDate_ = CloneSelectedDate();
45         value->propLunar_ = CloneLunar();
46         value->propStartDate_ = CloneStartDate();
47         value->propEndDate_ = CloneEndDate();
48         value->propMode_ = CloneMode();
49         value->propDisappearTextStyle_ = CloneDisappearTextStyle();
50         value->propTextStyle_ = CloneTextStyle();
51         value->propSelectedTextStyle_ = CloneSelectedTextStyle();
52         value->propDigitalCrownSensitivity_ = CloneDigitalCrownSensitivity();
53         return value;
54     }
55 
Reset()56     void Reset() override
57     {
58         LinearLayoutProperty::Reset();
59         ResetSelectedDate();
60         ResetStartDate();
61         ResetEndDate();
62         ResetMode();
63         ResetLunar();
64         ResetDisappearTextStyle();
65         ResetTextStyle();
66         ResetSelectedTextStyle();
67         ResetDigitalCrownSensitivity();
68     }
69 
ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)70     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override
71     {
72         LayoutProperty::ToJsonValue(json, filter);
73         /* no fixed attr below, just return */
74         if (filter.IsFastFilter()) {
75             return;
76         }
77         json->PutExtAttr("lunar", V2::ConvertBoolToString(GetLunar().value_or(false)).c_str(), filter);
78         Color defaultDisappearColor = Color::BLACK;
79         Color defaultNormalColor = Color::BLACK;
80         Color defaultSelectColor = Color::BLACK;
81         auto pipeline = PipelineBase::GetCurrentContext();
82         auto frameNode = GetHost();
83         if (pipeline && frameNode) {
84             auto pickerTheme = pipeline->GetTheme<PickerTheme>(frameNode->GetThemeScopeId());
85             if (pickerTheme) {
86                 defaultDisappearColor = pickerTheme->GetDisappearOptionStyle().GetTextColor();
87                 defaultNormalColor = pickerTheme->GetOptionStyle(false, false).GetTextColor();
88                 defaultSelectColor = pickerTheme->GetOptionStyle(true, false).GetTextColor();
89             }
90         }
91         auto disappearFont = JsonUtil::Create(true);
92         disappearFont->Put("size", GetDisappearFontSizeValue(Dimension(0)).ToString().c_str());
93         disappearFont->Put("weight", V2::ConvertWrapFontWeightToStirng(
94             GetDisappearWeight().value_or(FontWeight::NORMAL)).c_str());
95         auto disappearTextStyle = JsonUtil::Create(true);
96         disappearTextStyle->Put("color", GetDisappearColor().value_or(defaultDisappearColor).ColorToString().c_str());
97         disappearTextStyle->Put("font", disappearFont);
98         json->PutExtAttr("disappearTextStyle", disappearTextStyle, filter);
99 
100         auto normalFont = JsonUtil::Create(true);
101         normalFont->Put("size", GetFontSizeValue(Dimension(0)).ToString().c_str());
102         normalFont->Put("weight", V2::ConvertWrapFontWeightToStirng(GetWeight().value_or(FontWeight::NORMAL)).c_str());
103         auto normalTextStyle = JsonUtil::Create(true);
104         normalTextStyle->Put("color", GetColor().value_or(defaultNormalColor).ColorToString().c_str());
105         normalTextStyle->Put("font", normalFont);
106         json->PutExtAttr("textStyle", normalTextStyle, filter);
107 
108         auto selectedFont = JsonUtil::Create(true);
109         selectedFont->Put("size", GetSelectedFontSizeValue(Dimension(0)).ToString().c_str());
110         selectedFont->Put("weight", V2::ConvertWrapFontWeightToStirng(
111             GetSelectedWeight().value_or(FontWeight::NORMAL)).c_str());
112         auto selectedTextStyle = JsonUtil::Create(true);
113         selectedTextStyle->Put("color", GetSelectedColor().value_or(defaultSelectColor).ColorToString().c_str());
114         selectedTextStyle->Put("font", selectedFont);
115         json->PutExtAttr("selectedTextStyle", selectedTextStyle, filter);
116         auto crownSensitivity = GetDigitalCrownSensitivity();
117         json->PutExtAttr("digitalCrownSensitivity",
118             std::to_string(crownSensitivity.value_or(DEFAULT_CROWNSENSITIVITY)).c_str(), filter);
119     }
120 
GetDateStart()121     std::string GetDateStart() const
122     {
123         if (HasStartDate()) {
124             std::string startDate;
125             startDate += std::to_string(GetStartDate()->year);
126             startDate += "-";
127             startDate += std::to_string(GetStartDate()->month);
128             startDate += "-";
129             startDate += std::to_string(GetStartDate()->day);
130             return startDate;
131         }
132         return "1970-1-1";
133     }
134 
GetDateEnd()135     std::string GetDateEnd() const
136     {
137         if (HasEndDate()) {
138             std::string endDate;
139             endDate += std::to_string(GetEndDate()->year);
140             endDate += "-";
141             endDate += std::to_string(GetEndDate()->month);
142             endDate += "-";
143             endDate += std::to_string(GetEndDate()->day);
144             return endDate;
145         }
146         return "2100-12-31";
147     }
148 
GetDateSelected()149     std::string GetDateSelected() const
150     {
151         if (HasSelectedDate()) {
152             std::string selectedDate;
153             selectedDate += std::to_string(GetSelectedDate()->year);
154             selectedDate += "-";
155             selectedDate += std::to_string(GetSelectedDate()->month);
156             selectedDate += "-";
157             selectedDate += std::to_string(GetSelectedDate()->day);
158             return selectedDate;
159         }
160         return "";
161     }
162 
GetDatePickerMode()163     std::string GetDatePickerMode() const
164     {
165         std::string mode = "";
166         if (HasMode()) {
167             if (GetMode() == DatePickerMode::DATE) {
168                 mode = "DatePickerMode.DATE";
169             } else if (GetMode() == DatePickerMode::YEAR_AND_MONTH) {
170                 mode = "DatePickerMode.YEAR_AND_MONTH";
171             } else if (GetMode() == DatePickerMode::MONTH_AND_DAY) {
172                 mode = "DatePickerMode.MONTH_AND_DAY";
173             }
174         }
175         return mode;
176     }
177 
178     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(SelectedDate, LunarDate, PROPERTY_UPDATE_RENDER);
179     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Lunar, bool, PROPERTY_UPDATE_RENDER);
180     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(StartDate, LunarDate, PROPERTY_UPDATE_RENDER);
181     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(EndDate, LunarDate, PROPERTY_UPDATE_RENDER);
182     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Mode, DatePickerMode, PROPERTY_UPDATE_RENDER);
183 
184     ACE_DEFINE_PROPERTY_GROUP(DisappearTextStyle, FontStyle);
185     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
186         DisappearTextStyle, FontSize, DisappearFontSize, Dimension, PROPERTY_UPDATE_MEASURE);
187     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
188         DisappearTextStyle, TextColor, DisappearColor, Color, PROPERTY_UPDATE_MEASURE_SELF);
189     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
190         DisappearTextStyle, FontWeight, DisappearWeight, FontWeight, PROPERTY_UPDATE_MEASURE);
191     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
192         DisappearTextStyle, FontFamily, DisappearFontFamily, std::vector<std::string>, PROPERTY_UPDATE_MEASURE);
193     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
194         DisappearTextStyle, ItalicFontStyle, DisappearFontStyle, Ace::FontStyle, PROPERTY_UPDATE_MEASURE);
195 
196     ACE_DEFINE_PROPERTY_GROUP(TextStyle, FontStyle);
197     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
198         TextStyle, FontSize, FontSize, Dimension, PROPERTY_UPDATE_MEASURE);
199     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
200         TextStyle, TextColor, Color, Color, PROPERTY_UPDATE_MEASURE_SELF);
201     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
202         TextStyle, FontWeight, Weight, FontWeight, PROPERTY_UPDATE_MEASURE);
203     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
204         TextStyle, FontFamily, FontFamily, std::vector<std::string>, PROPERTY_UPDATE_MEASURE);
205     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
206         TextStyle, ItalicFontStyle, FontStyle, Ace::FontStyle, PROPERTY_UPDATE_MEASURE);
207 
208     ACE_DEFINE_PROPERTY_GROUP(SelectedTextStyle, FontStyle);
209     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
210         SelectedTextStyle, FontSize, SelectedFontSize, Dimension, PROPERTY_UPDATE_MEASURE);
211     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
212         SelectedTextStyle, TextColor, SelectedColor, Color, PROPERTY_UPDATE_MEASURE_SELF);
213     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
214         SelectedTextStyle, FontWeight, SelectedWeight, FontWeight, PROPERTY_UPDATE_MEASURE);
215     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
216         SelectedTextStyle, FontFamily, SelectedFontFamily, std::vector<std::string>, PROPERTY_UPDATE_MEASURE);
217     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(
218         SelectedTextStyle, ItalicFontStyle, SelectedFontStyle, Ace::FontStyle, PROPERTY_UPDATE_MEASURE);
219     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(DigitalCrownSensitivity, int32_t, PROPERTY_UPDATE_MEASURE);
220 private:
221     ACE_DISALLOW_COPY_AND_MOVE(DataPickerRowLayoutProperty);
222 };
223 } // namespace OHOS::Ace::NG
224 
225 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_DATE_PICKER_DATE_PICKER_ROW_LAYOUT_PROPERTY_H
226