1 /* 2 * Copyright (c) 2020-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 /** 17 * @addtogroup UI_Components 18 * @{ 19 * 20 * @brief Defines UI components such as buttons, texts, images, lists, and progress bars. 21 * 22 * @since 1.0 23 * @version 1.0 24 */ 25 26 /** 27 * @file ui_qrcode.h 28 * 29 * @brief Declares the attributes and functions of the <b>UIQrcode</b> class. 30 * 31 * @since 3.0 32 * @version 5.0 33 */ 34 35 #ifndef GRAPHIC_LITE_UI_QRCODE_H 36 #define GRAPHIC_LITE_UI_QRCODE_H 37 38 #include "components/ui_image_view.h" 39 40 namespace qrcodegen { 41 class QrCode; 42 } 43 44 namespace OHOS { 45 /** 46 * @brief Provides functions related to quick response (QR) codes. 47 * 48 * @since 3.0 49 * @version 5.0 50 */ 51 class UIQrcode : public UIImageView { 52 public: 53 /** 54 * @brief A default constructor used to create a <b>UIQrcode</b> instance. 55 * 56 * @since 3.0 57 * @version 5.0 58 */ 59 UIQrcode(); 60 61 /** 62 * @brief A destructor used to delete the <b>UIQrcode</b> instance. 63 * 64 * @since 3.0 65 * @version 5.0 66 */ 67 virtual ~UIQrcode(); 68 69 /** 70 * @brief Sets the QR code information. 71 * 72 * @param val Indicates the pointer to the content used to generate the QR code. 73 * @param backgroundColor Indicates the background color of the QR code. It is white by default. 74 * @param qrColor Indicates the QR code color. It is black by default. 75 * @since 3.0 76 * @version 5.0 77 */ 78 void SetQrcodeInfo(const char* val, ColorType backgroundColor = Color::White(), ColorType qrColor = Color::Black()); 79 80 /** 81 * @brief Obtains the view type. 82 * 83 * @return Returns the view type. For details, see {@link UIViewType}. 84 * @since 1.0 85 * @version 1.0 86 */ GetViewType()87 UIViewType GetViewType() const override 88 { 89 return UI_QRCODE; 90 } 91 92 /** 93 * @brief Sets the QR code width. 94 * 95 * @param width Indicates the width to set. 96 * @since 1.0 97 * @version 1.0 98 */ 99 void SetWidth(int16_t width) override; 100 101 /** 102 * @brief Sets the QR code height. 103 * 104 * @param height Indicates the height to set. 105 * @since 1.0 106 * @version 1.0 107 */ 108 void SetHeight(int16_t height) override; 109 110 private: 111 void ReMeasure() override; 112 void RefreshQrcode(); 113 void SetImageInfo(qrcodegen::QrCode& qrcode); 114 void GenerateQrCode(qrcodegen::QrCode& qrcode); 115 void FillQrCodeColor(qrcodegen::QrCode& qrcode); 116 void FillQrCodeBackgroundColor(); 117 void SetQrcodeVal(const char* val, uint32_t length); 118 void GetDestData(uint8_t* destData, int32_t outFilePixelPrescaler); 119 120 static constexpr uint8_t QRCODE_FACTOR_NUM = 4; 121 ImageInfo imageInfo_; 122 int16_t width_; 123 bool needDraw_; 124 ColorType backgroundColor_; 125 ColorType qrColor_; 126 char* qrcodeVal_; 127 }; 128 } // namespace OHOS 129 #endif // GRAPHIC_LITE_UI_QRCODE_H 130