/*!
 *
 * 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    TimeText.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      30-Aug-2022
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  04-Feb-2020
 *
 */

// 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 int    secondsLeftMargin : 0

    property bool   hourZero        : true
    property bool   minuteZero      : true
    property bool   secondZero      : true

    property color  textColor       : Colors.textMain
    property int    textPixelSize   : 90
    property int    textWeight      : Font.ExtraLight
    property int    secsPixelSize   : 16

    readonly property string time   : _private.time

    color : Colors.transparent
    width : _hourText.contentWidth + _timeSeparator.contentWidth + _minuteText.contentWidth + _timeSeparator.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 ? ( _root.hourZero   ? "0" : "") + hour   : hour  )
        property string minuteText  : (minute < 10 ? ( _root.minuteZero ? "0" : "") + minute : minute)
        property string secondText  : (second < 10 ? ( _root.secondZero ? "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.leftMargin  : _root.secondsLeftMargin
        anchors.baseline    : _timeSeparator.baseline
    }
}

