1 /* 2 * Copyright (c) 2022 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 #include "bridge/declarative_frontend/jsview/models/text_clock_model_impl.h" 17 18 #include "bridge/declarative_frontend/view_stack_processor.h" 19 20 namespace OHOS::Ace::Framework { Create()21RefPtr<TextClockController> TextClockModelImpl::Create() 22 { 23 auto clockComponent = AceType::MakeRefPtr<TextClockComponent>(std::string("")); 24 CHECK_NULL_RETURN(clockComponent, nullptr); 25 clockComponent->SetTextClockController(AceType::MakeRefPtr<TextClockController>()); 26 ViewStackProcessor::GetInstance()->Push(clockComponent); 27 return clockComponent->GetTextClockController(); 28 } 29 SetFormat(const std::string & format)30void TextClockModelImpl::SetFormat(const std::string& format) 31 { 32 auto component = GetComponent(); 33 CHECK_NULL_VOID(component); 34 component->SetFormat(format); 35 } 36 SetHoursWest(float hoursWest)37void TextClockModelImpl::SetHoursWest(float hoursWest) 38 { 39 auto component = GetComponent(); 40 CHECK_NULL_VOID(component); 41 component->SetHoursWest(hoursWest); 42 } 43 SetOnDateChange(std::function<void (const std::string)> && onChange)44void TextClockModelImpl::SetOnDateChange(std::function<void(const std::string)>&& onChange) 45 { 46 auto component = GetComponent(); 47 CHECK_NULL_VOID(component); 48 component->SetOnDateChange(std::move(onChange)); 49 } 50 SetFontSize(const Dimension & value)51void TextClockModelImpl::SetFontSize(const Dimension& value) 52 { 53 auto component = GetComponent(); 54 CHECK_NULL_VOID(component); 55 56 auto textStyle = component->GetTextStyle(); 57 textStyle.SetFontSize(value); 58 component->SetTextStyle(textStyle); 59 } 60 SetTextColor(const Color & value)61void TextClockModelImpl::SetTextColor(const Color& value) 62 { 63 auto component = GetComponent(); 64 CHECK_NULL_VOID(component); 65 66 auto textStyle = component->GetTextStyle(); 67 textStyle.SetTextColor(value); 68 component->SetTextStyle(textStyle); 69 } 70 SetItalicFontStyle(Ace::FontStyle value)71void TextClockModelImpl::SetItalicFontStyle(Ace::FontStyle value) 72 { 73 auto component = GetComponent(); 74 CHECK_NULL_VOID(component); 75 76 auto textStyle = component->GetTextStyle(); 77 textStyle.SetFontStyle(value); 78 component->SetTextStyle(textStyle); 79 } 80 SetFontWeight(FontWeight value)81void TextClockModelImpl::SetFontWeight(FontWeight value) 82 { 83 auto component = GetComponent(); 84 CHECK_NULL_VOID(component); 85 86 auto textStyle = component->GetTextStyle(); 87 textStyle.SetFontWeight(value); 88 component->SetTextStyle(textStyle); 89 } 90 SetFontFamily(const std::vector<std::string> & value)91void TextClockModelImpl::SetFontFamily(const std::vector<std::string>& value) 92 { 93 auto component = GetComponent(); 94 CHECK_NULL_VOID(component); 95 96 auto textStyle = component->GetTextStyle(); 97 textStyle.SetFontFamilies(value); 98 component->SetTextStyle(textStyle); 99 } 100 InitFontDefault(const TextStyle & textStyle)101void TextClockModelImpl::InitFontDefault(const TextStyle& textStyle) 102 { 103 auto component = GetComponent(); 104 CHECK_NULL_VOID(component); 105 106 component->SetTextStyle(textStyle); 107 } 108 GetComponent()109RefPtr<TextClockComponent> TextClockModelImpl::GetComponent() 110 { 111 auto* stack = ViewStackProcessor::GetInstance(); 112 if (!stack) { 113 return nullptr; 114 } 115 auto component = AceType::DynamicCast<TextClockComponent>(stack->GetMainComponent()); 116 return component; 117 } 118 } // namespace OHOS::Ace::Framework