/*!
 *
 * Copyright (c) 2023-2024 Diality Inc. - All Rights Reserved.
 * \copyright
 * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN
 * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER.
 *
 * \file    QRCode.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      20-Nov-2023
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  20-Nov-2023
 *
 */

// Qt
import QtQuick 2.12

// Project
//  Qml imports
import "qrc:/globals"

/*!
 * \brief   Denali project QRCode [ Currently for TxCode ]
 */
Item { id : _root
    property string qrcode: ""
    property bool   clear : false

    visible         : qrcode && !clear
    width           : 75
    height          : 75


    function reset() {
        _GuiView.qrImageSource = ""
    }

    onClearChanged : {
        if ( _root.clear ) {
            reset()
            _root.clear = false // make sure it won't stay true, and act as a set once bool flag.
        }
    }

    onQrcodeChanged: {
        if ( qrcode == "" ) {
            reset()
        }
        else {
            _GuiView.doGenerateQRImage(qrcode)
        }
    }

    Image { id: _qrCode
        width           : _root.width
        height          : _root.height
        smooth          : false
        source          : _GuiView.qrImageSource
    }
}
