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/qrcode_model_impl.h"
17 
18 #include "base/log/ace_trace.h"
19 #include "bridge/declarative_frontend/view_stack_processor.h"
20 #include "core/components/qrcode/qrcode_component.h"
21 
22 namespace OHOS::Ace::Framework {
Create(const std::string & value)23 void QRCodeModelImpl::Create(const std::string& value)
24 {
25     RefPtr<QrcodeComponent> qrcode = AceType::MakeRefPtr<OHOS::Ace::QrcodeComponent>();
26     qrcode->SetValue(value);
27     qrcode->SetQrcodeColor(Color::BLACK);
28     qrcode->SetBackgroundColor(Color::WHITE);
29     ViewStackProcessor::GetInstance()->ClaimElementId(qrcode);
30     ViewStackProcessor::GetInstance()->Push(qrcode);
31 }
32 
SetQRCodeColor(const Color & color)33 void QRCodeModelImpl::SetQRCodeColor(const Color& color)
34 {
35     auto qrcode = AceType::DynamicCast<QrcodeComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
36     if (qrcode) {
37         qrcode->SetQrcodeColor(color);
38     }
39 }
40 
SetQRBackgroundColor(const Color & color)41 void QRCodeModelImpl::SetQRBackgroundColor(const Color& color)
42 {
43     auto qrcode = AceType::DynamicCast<QrcodeComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
44     if (qrcode) {
45         qrcode->SetBackgroundColor(color);
46     }
47 }
48 } // namespace OHOS::Ace::Framework