/*!
 *
 * 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    TimeText.qml
 * \date    2020/02/03
 * \author  Behrouz NematiPour
 *
 */

// Qt
import QtQuick 2.12

// Project

//  Qml imports
import "qrc:/globals"

/*!
 * \brief   Time Text Component converts seconds into hour:minute.second
 */
Rectangle { id: _root
    objectName: "_TimeText" //SquishQt testability
    property int    seconds         : 0
    property bool   secondsVisible  : true
    property color  textColor       : "white"
    property int    textPixelSize   : 90
    property int    textWeight      : Font.ExtraLight
    property int    secsPixelSize   : 16

    readonly property string time   : _private.time

    color : "transparent"
    width : _hourText.contentWidth + _timeSeparator.contentWidth + _minuteText.contentWidth
    height: _timeSeparator.height

    QtObject { id: _private
        property int    hour        : Math.floor( seconds / 3600 )
        property int    minute      : Math.floor((seconds % 3600) / 60)
        property int    second      : seconds % 60

        property string separator   : ":"
        property string hourText    : (hour   < 10 ? "0" + hour   : hour  )
        property string minuteText  : (minute < 10 ? "0" + minute : minute)
        property string secondText  : (second < 10 ? "0" + second : second)

        property string time        : hourText + separator + minuteText + (_root.secondsVisible ? (separator + secondText) : "")
    }

    Text { id: _timeSeparator
        objectName: "_TimeText_timeSeparator" //SquishQt testability

        text: _private.separator

        font.pixelSize: _root.textPixelSize
        font.weight: _root.textWeight
        color: _root.textColor

        anchors.centerIn: _root
    }
    Text { id: _hourText
        objectName: "_TimeText_hour" //SquishQt testability

        text: _private.hourText
        font.pixelSize: _root.textPixelSize
        font.weight: _root.textWeight
        color: _root.textColor

        horizontalAlignment: Text.AlignRight
        anchors.right   : _timeSeparator.left
        anchors.baseline: _timeSeparator.baseline

    }
    Text { id: _minuteText
        objectName: "_TimeText_minute" //SquishQt testability

        text: _private.minuteText
        font.pixelSize: _root.textPixelSize
        font.weight: _root.textWeight
        color: _root.textColor
        horizontalAlignment: Text.AlignLeft
        anchors.left: _timeSeparator.right
        anchors.baseline: _timeSeparator.baseline
    }
    Text { id: _secondText
        objectName: "_TimeText_second" //SquishQt testability

        visible: _root.secondsVisible

        text: _private.secondText
        font.pixelSize: _root.secsPixelSize
        color: _root.textColor
        horizontalAlignment: Text.AlignLeft
        anchors.left: _minuteText.right
        anchors.baseline: _timeSeparator.baseline
    }
}

