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

// Qt
import QtQuick 2.12

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

/*!
 * \brief   Denali project RangeRect
 */
Rectangle { id: _root
    signal clicked(var vMouseEvent)
    signal dragged(var vMouseEvent)
    signal released(var vMouseEvent)
    signal pressed(var vMouseEvent)

    property int    decimal : 0
    property real   minimum : 0 ///< minimum value of the range
    property real   maximum : 0 ///< maximum value of the range

    property alias  minText : _textMinimum
    property alias  maxText : _textMaximum

    property bool   minTextHorizontalCenter: false
    property bool   maxTextHorizontalCenter: false

    property string unit    : ""

    property real   touchMargin: 0
    property bool   isRoundedEnds       : true
    property bool   hasBorder           : true

    color   : Colors.backgroundRangeRect
    radius  : isRoundedEnds ? (height/2) : Variables.rangeRectRadius

    border.width: hasBorder ? Variables.rangeRectBorderWidth : 0
    border.color: Colors.rangeRectBorderColor

    Text { id: _textMinimum
        visible :  false

        font.pixelSize  : Fonts.fontPixelRangeRectText
        font.bold       : true

        color   : Colors.textProgressBar
        text    : minimum.toFixed(decimal) + unit

        anchors {
            left        : parent.left
            top         : parent.bottom
            topMargin   : Variables.rangeRectTextMargin
            leftMargin  : minTextHorizontalCenter ? -minText.width / 2 : 0
        }
    }

    Text { id: _textMaximum
        visible :  false

        font.pixelSize  : Fonts.fontPixelRangeRectText
        font.bold       : true

        color   : Colors.textProgressBar
        text    : maximum.toFixed(decimal) + unit

        anchors {
            right       : parent.right
            top         : parent.bottom
            topMargin   : Variables.rangeRectTextMargin
            rightMargin : maxTextHorizontalCenter ? -maxText.width / 2 : 0
        }
    }

    MouseArea { id: _mouseArea
        anchors.topMargin   : -touchMargin
        anchors.bottomMargin: -touchMargin
        anchors.fill: parent
        onPositionChanged: {
            _root.dragged(mouse)
        }
        onClicked: {
            _root.clicked(mouse)
        }
        onReleased: {
            _root.released(mouse)
        }
        onPressed: {
            _root.pressed(mouse)
        }
    }
}
