/*!
 *
 * 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    ProgressRect.qml
 * \author  (last)      Vy
 * \date    (last)      15-Mar-2023
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  23-Jan-2020
 *
 */

// Qt
import QtQuick 2.12

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

/*!
 * \brief   Denali project Progress Rect
 * \details This rectangle fits into the rect area and will calculate its length
 *          in regards to the min, max, width, current value of the parent
 */
RangeRect { id: _root
    property real value   : 0
    property real margin  : Variables.progressbarRectMargin

    QtObject { id: _private
        property int length: if ( value < minimum ) {
                                 0
                             } else if ( value > maximum ) {
                                 width
                             } else {
                                 if (maximum > minimum) {
                                    ((parent.width * (value - minimum)) / (maximum - minimum) - (margin * 2))
                                 } else {
                                     0
                                 }
                             }
    }

    width   : _private.length

    // progress Rects require to show the current values as their maxText values
    maxText.text: value

    anchors {
        left    : parent.left
        top     : parent.top
        bottom  : parent.bottom
        margins : margin
    }
}
