import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14
import QtQml 2.14
import QtQml.Models 2.14
import QtGraphicalEffects 1.0
import QtQuick.Dialogs 1.3

Row {
    Rectangle {
        id: trackHead
        clip: true
        width: headWidth
        height: trackHeight
        color: activePalette.dark
        border.color: activePalette.midlight
        border.width: 1
        Label {
            id: headerText
            x: 5
            text: modelData.controlSelected
                    ? modelData.lidarName + " Port:" + modelData.port
                    : "*" + modelData.lidarName + " Port:" + modelData.port
            color: activePalette.text
            anchors.verticalCenter: parent.verticalCenter
            font.bold: true
            font.pointSize: 6.5
            style: Text.Outline
            styleColor: activePalette.dark
            MouseArea {
                id: checkBoxSelectControl
                anchors.fill: parent
                acceptedButtons: Qt.LeftButton
                property bool toolbar: false
                onClicked: {
                    modelData.setControlSelected(!modelData.controlSelected)
                }
            }
        }
        MouseArea {
            id: forClick
            anchors.fill: parent
            acceptedButtons: Qt.RightButton
            propagateComposedEvents: true
            property bool toolbar: false
            onClicked: {
                trackMenu.popup()         
            }
            onWheel: {
                // console.log("wheel.angleDelta.y:" + wheel.angleDelta.y)
                // console.log("headerText.x:" + headerText.x)
                if (wheel.angleDelta.y > 0) {
                    if (headerText.x < 0)
                        headerText.x += 30
                }
                else {
                    if (headerText.x + headerText.width > headWidth * 0.25 )
                        headerText.x -= 30
                }
            }
        }
        DefaultMenu {
            id : trackMenu
            title: "Track Menu"
            DefaultMenuItem {
                text:"setOffset"
                TimeOffsetWindow {
                    id: setTimeOffset
                }
                onClicked: {
                    setTimeOffset.show()
                }
            }
            DefaultMenuItem {
                text: "Delete Track"
                
                onClicked: {
                    modelData.deleteTrack();
                }
            }
            DefaultMenuItem {
                text: "Cancel"
                
            }
        }
    }
    // DefaultTrackBodyPointXYZI {}
    Loader {
        id: trackBodyLoader 
        source: (modelData.trackBody == "")? "DefaultTrackBodyPointXYZI.qml" : modelData.trackBody
    }
}