1 /* 2 * Copyright (c) 2021 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_DECLARATION_QRCODE_QRCODE_DECLARATION_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_QRCODE_QRCODE_DECLARATION_H 18 19 #include "core/components/declaration/common/declaration.h" 20 #include "frameworks/bridge/common/dom/dom_type.h" 21 22 namespace OHOS::Ace { 23 24 struct QrcodeAttribute : Attribute { 25 std::string value; 26 QrcodeType qrcodeType { QrcodeType::RECT }; 27 }; 28 29 struct QrcodeStyle : Style { 30 Color backgroundColor; 31 Color qrcodeColor; 32 Dimension qrcodeWidth; 33 Dimension qrcodeHeight; 34 bool isWidthDefined = false; 35 bool isHeightDefined = false; 36 }; 37 38 class QrcodeDeclaration : public Declaration { 39 DECLARE_ACE_TYPE(QrcodeDeclaration, Declaration); 40 41 public: 42 QrcodeDeclaration() = default; 43 ~QrcodeDeclaration() override = default; 44 45 void InitializeStyle() override; 46 GetValue()47 const std::string& GetValue() const 48 { 49 auto& attribute = static_cast<QrcodeAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 50 return attribute.value; 51 } 52 GetType()53 QrcodeType GetType() const 54 { 55 auto& attribute = static_cast<QrcodeAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 56 return attribute.qrcodeType; 57 } 58 GetBackgroundColor()59 const Color& GetBackgroundColor() const 60 { 61 auto& style = static_cast<QrcodeStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 62 return style.backgroundColor; 63 } 64 GetQrcodeColor()65 const Color& GetQrcodeColor() const 66 { 67 auto& style = static_cast<QrcodeStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 68 return style.qrcodeColor; 69 } 70 GetQrcodeWidth()71 const Dimension& GetQrcodeWidth() const 72 { 73 auto& style = static_cast<QrcodeStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 74 return style.qrcodeWidth; 75 } 76 GetQrcodeHeight()77 const Dimension& GetQrcodeHeight() const 78 { 79 auto& style = static_cast<QrcodeStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 80 return style.qrcodeHeight; 81 } 82 IsWidthDefined()83 bool IsWidthDefined() const 84 { 85 auto& style = static_cast<QrcodeStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 86 return style.isWidthDefined; 87 } 88 IsHeightDefined()89 bool IsHeightDefined() const 90 { 91 auto& style = static_cast<QrcodeStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 92 return style.isHeightDefined; 93 } 94 SetValue(const std::string & value)95 void SetValue(const std::string& value) 96 { 97 auto& attribute = MaybeResetAttribute<QrcodeAttribute>(AttributeTag::SPECIALIZED_ATTR); 98 attribute.value = value; 99 } 100 SetQrcodeType(QrcodeType qrcodeType)101 void SetQrcodeType(QrcodeType qrcodeType) 102 { 103 auto& attribute = MaybeResetAttribute<QrcodeAttribute>(AttributeTag::SPECIALIZED_ATTR); 104 attribute.qrcodeType = qrcodeType; 105 } 106 SetBackgroundColor(const Color & backgroundColor)107 void SetBackgroundColor(const Color& backgroundColor) 108 { 109 auto& style = MaybeResetStyle<QrcodeStyle>(StyleTag::SPECIALIZED_STYLE); 110 style.backgroundColor = backgroundColor; 111 } 112 SetQrcodeColor(const Color & qrcodeColor)113 void SetQrcodeColor(const Color& qrcodeColor) 114 { 115 auto& style = MaybeResetStyle<QrcodeStyle>(StyleTag::SPECIALIZED_STYLE); 116 style.qrcodeColor = qrcodeColor; 117 } 118 SetQrcodeWidth(const Dimension & qrcodeWidth)119 void SetQrcodeWidth(const Dimension& qrcodeWidth) 120 { 121 auto& style = MaybeResetStyle<QrcodeStyle>(StyleTag::SPECIALIZED_STYLE); 122 style.qrcodeWidth = qrcodeWidth; 123 style.isWidthDefined = true; 124 } 125 SetQrcodeHeight(const Dimension & qrcodeHeight)126 void SetQrcodeHeight(const Dimension& qrcodeHeight) 127 { 128 auto& style = MaybeResetStyle<QrcodeStyle>(StyleTag::SPECIALIZED_STYLE); 129 style.qrcodeHeight = qrcodeHeight; 130 style.isHeightDefined = true; 131 } 132 SetWidthDefined(bool isWidthDefined)133 void SetWidthDefined(bool isWidthDefined) 134 { 135 auto& style = MaybeResetStyle<QrcodeStyle>(StyleTag::SPECIALIZED_STYLE); 136 style.isWidthDefined = isWidthDefined; 137 } 138 SetHeightDefined(bool isHeightDefined)139 void SetHeightDefined(bool isHeightDefined) 140 { 141 auto& style = MaybeResetStyle<QrcodeStyle>(StyleTag::SPECIALIZED_STYLE); 142 style.isHeightDefined = isHeightDefined; 143 } 144 145 protected: 146 void InitSpecialized() override; 147 bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override; 148 bool SetSpecializedStyle(const std::pair<std::string, std::string>& style) override; 149 }; 150 151 } // namespace OHOS::Ace 152 153 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_QRCODE_QRCODE_DECLARATION_H 154