/*!
 *
 * 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
import QtQuick.Controls 2.12

// Project

//  Qml imports
import "qrc:/globals"

/*!
 * \brief   Time Text Component converts seconds into hour:minute.second
 */
Item { id: _root
    property int    seconds         : 0
    property color  color           : "white"
    property int    textPixelSize   : 90
    property int    secsPixelSize   : 16

    width : _timeHour.contentWidth + _timeSeparator.contentWidth + _timeMinute.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
    }

    Text { id: _timeSeparator
        text: ":"

        font.pixelSize: _root.textPixelSize
        font.weight: Font.ExtraLight
        color: _root.color

        anchors.centerIn: _root
    }
    Text { id: _timeHour
        property alias hour: _private.hour
        font.pixelSize: _root.textPixelSize
        font.weight: Font.ExtraLight
        color: _root.color

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

        text: (hour < 10 ? "0"+hour : hour)
    }
    Text { id: _timeMinute
        property alias minute: _private.minute
        text:  (minute < 10 ? "0" + minute : minute)
        font.pixelSize: _root.textPixelSize
        font.weight: Font.ExtraLight
        color: _root.color
        horizontalAlignment: Text.AlignLeft
        anchors.left: _timeSeparator.right
        anchors.baseline: _timeSeparator.baseline
    }
    Text { id: _timeSecond
        property alias second: _private.second
        text:  (second < 10 ? "0" + second : second)
        font.pixelSize: _root.secsPixelSize
        color: _root.color
        horizontalAlignment: Text.AlignLeft
        anchors.left: _timeMinute.right
        anchors.baseline: _timeSeparator.baseline
    }
}

