/*!
 *
 * Copyright (c) 2019-2025 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    MonitorItem.qml
 * \author  (last)      Nico Ramirez
 * \date    (last)      27-Jun-2025
 * \author  (original)  Nico Ramirez
 * \date    (original)  27-Jun-2025
 *
 */

// Qt
import QtQuick 2.12

import "qrc:/globals"
import "qrc:/components"

TouchRect { id  : _icon
    property int    iconSize        : Variables.iconButtonSize
    property string iconImageSource : ""
    property int    extraSpace      : Variables.defaultMargin
    readonly property alias  icon   : _iconImage

    width       : iconSize + extraSpace
    height      : iconSize + extraSpace
    radius      : height
    border.color: "transparent"

    signal hold()

    onPressed   : _repeatTimer.start()
    onReleased  : _repeatTimer.stop()
    onCanceled  : _repeatTimer.stop()

    onActiveFocusChanged: if ( ! activeFocus ) _repeatTimer.stop()

    Image { id  : _iconImage
        anchors.centerIn: parent
        height  : iconSize
        width   : iconSize
        fillMode: Image.PreserveAspectFit
        source  : iconImageSource
        smooth: true
        mipmap: true
    }

    Timer { id: _repeatTimer
        interval    : 200
        repeat      : true

        onTriggered: {
            hold()
            interval = Math.max(50, interval - 10) // accelerate
        }

        onRunningChanged: {
            if ( ! running )
                interval = 200 // reset when released
        }
    }

}
