/*!
 *
 * Copyright (c) 2020-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    TextRect.qml
 * \author  (last)      Vy
 * \date    (last)      20-Mar-2023
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  11-Jan-2020
 *
 */

// Qt
import QtQuick 2.12

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

/*!
 * \brief   The TextRect Component
 * which is a static text rectangle area containing title and a text blow it
 * with and extra text next to it which can be used for example for unit texts.
 */
Item { id : _root
    property string title               : ""
    property string titleColor          : Colors.textTextRectTitle

    property string label               : ""
    property string labelColor          : Colors.textTextRectLabel
    property bool   labelAutoSize       : false
    property int    labelWidth          : 80 // text:3 Digit "000" & pixel: 46 => width: 80
    property alias  labelHeight         : _labelText.height
    property alias  labelFont           : _labelText.font

    property alias extraLabelPixelSize  : _extraText.font.pixelSize

    property string extra               : ""
    property string extraColor          : Colors.textTextRectExtra

    readonly property int titleVSpacing : 0
    readonly property int textHSpacing  : 5

    width : _column.width
    height: _column.height

    clip: false

    Column { id: _column
        width : Math.max(_titleText.width  , _row.width )
        height:          _titleText.height + _row.height + spacing
        anchors.fill: parent
        spacing: _root.title ? titleVSpacing : 0
        Text { id: _titleText
            width : _root.title ? contentWidth  : 0
            height: _root.title ? contentHeight : 0
            text: _root.title
            color: titleColor
            font.pixelSize: Fonts.fontPixelTextRectTitle
            verticalAlignment: Text.AlignBottom
        }
        Row { id: _row
            width : _labelText.width  + _extraText.width  + spacing
            height: _labelText.height + _extraText.height
            spacing: textHSpacing
            Text { id: _labelText
                width : labelAutoSize ? contentWidth : labelWidth
                height: contentHeight
                text: _root.label
                color: labelColor
                font.pixelSize: Fonts.fontPixelTextRectLabel
                verticalAlignment: Text.AlignBottom
                horizontalAlignment: Text.AlignRight
            }
            Text { id: _extraText
                width : contentWidth
                height: contentHeight
                text: _root.extra
                color: extraColor
                font.pixelSize: Fonts.fontPixelTextRectExtra
                verticalAlignment: Text.AlignBottom
                anchors.baseline: _labelText.baseline
            }
        }
    }

    Component.onCompleted: {
    }
}
