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