/*!
 *
 * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved.
 * \copyright                                                       \n
 *          THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM,  \n
 *          IN PART OR IN WHOLE,                                    \n
 *          WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. \n
 *
 * \file    RangeRect.qml
 * \date    2020/01/24
 * \author  Behrouz NematiPour
 *
 */

// 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)


    property int    decimal : 0
    property real   minimum : 0
    property real   maximum : 0

    property alias  minText : _textMinimum
    property alias  maxText : _textMaximum

    property string unit    : ""

    property real   touchMargin: 0

    width   : parent.width
    height  : parent.height

    color   : Colors.backgroundRangeRect
    radius  : Variables.rangeRectRadius

    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
        }
    }

    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
        }
    }

    MouseArea { id: _mouseArea
        anchors.topMargin   : -touchMargin
        anchors.bottomMargin: -touchMargin
        anchors.fill: parent
        onPositionChanged: {
            _root.dragged(mouse)
        }

        onClicked: {
            _root.clicked(mouse)
        }
    }
}
